BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
periph.h
Go to the documentation of this file.
1 /* Copyright 2012-2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
82 #ifndef BSP430_PERIPH_H
83 #define BSP430_PERIPH_H
84 
85 #include <bsp430/core.h>
86 #include <msp430.h>
87 
107 
109 #define BSP430_PERIPH_NONE ((tBSP430periphHandle)0)
110 
116 #define BSP430_PERIPH_LFXT1 ((tBSP430periphHandle)0x4001)
117 
125 #ifndef configBSP430_PERIPH_XT2
126 #define configBSP430_PERIPH_XT2 0
127 #endif /* configBSP430_PERIPH_XT2 */
128 
138 #if defined(BSP430_DOXYGEN) || (configBSP430_PERIPH_XT2 - 0)
139 #define BSP430_PERIPH_XT2 ((tBSP430periphHandle)0x4003)
140 #endif /* configBSP430_PERIPH_XT2 */
141 
149 #ifndef configBSP430_PERIPH_EXPOSED_CLOCKS
150 #define configBSP430_PERIPH_EXPOSED_CLOCKS 0
151 #endif /* configBSP430_PERIPH_EXPOSED_CLOCKS */
152 
161 #if defined(BSP430_DOXYGEN) || (configBSP430_PERIPH_EXPOSED_CLOCKS - 0)
162 #define BSP430_PERIPH_EXPOSED_CLOCKS ((tBSP430periphHandle)0x4005)
163 #endif /* configBSP430_PERIPH_EXPOSED_CLOCKS */
164 
169 #define BSP430_PERIPH_BUTTON0 ((tBSP430periphHandle)0x4101)
170 
174 #define BSP430_PERIPH_BUTTON1 ((tBSP430periphHandle)0x4103)
175 
179 #define BSP430_PERIPH_BUTTON2 ((tBSP430periphHandle)0x4105)
180 
184 #define BSP430_PERIPH_BUTTON3 ((tBSP430periphHandle)0x4107)
185 
187 #define BSP430_PERIPHCFG_DEFAULT 0
188 
193 #define BSP430_PERIPHCFG_SERIAL_UART 1
194 
200 #define BSP430_PERIPHCFG_SERIAL_I2C 2
201 
208 #define BSP430_PERIPHCFG_SERIAL_SPI3 3
209 
215 #define BSP430_PERIPHCFG_SERIAL_SPI4 4
216 
218 #define BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT_UNKNOWN 0
219 
222 #define BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT_MASK_ 0x0F
223 
229 #define BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT(_p) (BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT_MASK_ & (_p)->hal_state.cflags)
230 
246 #define BSP430_PERIPH_HAL_STATE_CFLAGS_ISR 0x80
247 
265 #define BSP430_PERIPH_HAL_STATE_CFLAGS_ISR2 0x40
266 
272 typedef struct sBSP430hplHALStatePrefix {
278  const unsigned char cflags;
279 
285  volatile unsigned char flags;
287 
304 static BSP430_CORE_INLINE
306 xBSP430periphFromHPL (volatile void * hpl)
307 {
308  return (tBSP430periphHandle)(uintptr_t)hpl;
309 }
310 
311 /* Forward declarations */
314 
315 /* BSP430_HAL_ISR bits must not use 0x00F8 which are SCG1, SCG0,
316  * OSCOFF, CPUOFF, and GIE.
317  *
318  * 0x0001 -- SR C, used for #BSP430_HAL_ISR_CALLBACK_BREAK_CHAIN
319  * 0x0002 -- SR Z, used for #BSP430_HAL_ISR_CALLBACK_EXIT_LPM
320  * 0x0004 -- SR N, available
321  * 0x00F8 -- SR bits used for their SR purpose
322  * 0x0100 -- SR V, available
323  * 0x0E00 -- Reserved, available
324  * 0x1000 -- Reserved, used for #BSP430_HAL_ISR_CALLBACK_YIELD
325  * 0x2000 -- Reserved, used for #BSP430_HAL_ISR_CALLBACK_DISABLE_INTERRUPT
326  * 0x4000 -- Reserved, available
327  * 0x8000 -- Reserved, available (use this last)
328  */
329 
345 #define BSP430_HAL_ISR_CALLBACK_BREAK_CHAIN 0x0001
346 
361 #define BSP430_HAL_ISR_CALLBACK_EXIT_LPM 0x0002
362 
369 #define BSP430_HAL_ISR_CALLBACK_YIELD 0x1000
370 
388 #define BSP430_HAL_ISR_CALLBACK_DISABLE_INTERRUPT 0x2000
389 
403 typedef int (* iBSP430halISRCallbackVoid_ni) (const struct sBSP430halISRVoidChainNode * cb,
404  void * context);
405 
421  void * context,
422  int idx);
423 
430  const struct sBSP430halISRVoidChainNode * volatile next_ni;
431 
435 
442  const struct sBSP430halISRIndexedChainNode * volatile next_ni;
443 
447 
461 static BSP430_CORE_INLINE
462 int
463 iBSP430callbackInvokeISRVoid_ni (const struct sBSP430halISRVoidChainNode * volatile const * cbpp,
464  void * context,
465  int basis)
466 {
467  while (*cbpp && ! (basis & BSP430_HAL_ISR_CALLBACK_BREAK_CHAIN)) {
468  basis |= (*cbpp)->callback_ni(*cbpp, context);
469  cbpp = &(*cbpp)->next_ni;
470  }
471  return basis;
472 }
473 
484 static BSP430_CORE_INLINE
485 int
487  void * context,
488  int idx,
489  int basis)
490 {
491  while (*cbpp && ! (basis & BSP430_HAL_ISR_CALLBACK_BREAK_CHAIN)) {
492  basis |= (*cbpp)->callback_ni(*cbpp, context, idx);
493  cbpp = &(*cbpp)->next_ni;
494  }
495  return basis;
496 }
497 
506 #define BSP430_HAL_ISR_CALLBACK_TAIL_NI(return_flags_) do { \
507  unsigned int rf = (return_flags_); \
508  if (rf & BSP430_HAL_ISR_CALLBACK_EXIT_LPM) { \
509  rf |= BSP430_CORE_LPM_EXIT_MASK; \
510  } \
511  BSP430_CORE_LPM_EXIT_FROM_ISR(rf); \
512  if (rf & BSP430_HAL_ISR_CALLBACK_YIELD) { \
513  BSP430_RTOS_YIELD_FROM_ISR(); \
514  } \
515  } while (0)
516 
533 #define BSP430_HAL_ISR_CALLBACK_LINK_NI(type_,root_,node_,next_) do { \
534  (node_).next_ = root_; \
535  root_ = &(node_); \
536  } while (0)
537 
558 #define BSP430_HAL_ISR_CALLBACK_UNLINK_NI(type_,root_,node_,next_) do { \
559  typedef type_ tNode_; \
560  const tNode_ * volatile * curp_ = &(root_); \
561  while ((NULL != *curp_) && (&(node_) != *curp_)) { \
562  curp_ = &(((tNode_*)*curp_)->next_); \
563  } \
564  if (&(node_) == *curp_) { \
565  *curp_ = (node_).next_; \
566  (node_).next_ = NULL; \
567  } \
568  } while (0)
569 
570 #endif /* BSP430_PERIPH_H */
Stripped header supporting Doxygen links.
int(* iBSP430halISRCallbackIndexed_ni)(const struct sBSP430halISRIndexedChainNode *cb, void *context, int idx)
Definition: periph.h:420
Common header included by all BSP430 leaf headers.
const unsigned char cflags
Definition: periph.h:278
Definition: periph.h:425
struct sBSP430hplHALStatePrefix sBSP430hplHALStatePrefix
static BSP430_CORE_INLINE tBSP430periphHandle xBSP430periphFromHPL(volatile void *hpl)
Definition: periph.h:306
const struct sBSP430halISRIndexedChainNode *volatile next_ni
Definition: periph.h:442
static BSP430_CORE_INLINE int iBSP430callbackInvokeISRVoid_ni(const struct sBSP430halISRVoidChainNode *volatile const *cbpp, void *context, int basis)
Definition: periph.h:463
#define BSP430_CORE_INLINE
Definition: core.h:439
struct sBSP430halISRVoidChainNode sBSP430halISRVoidChainNode
Definition: periph.h:437
volatile unsigned char flags
Definition: periph.h:285
#define BSP430_HAL_ISR_CALLBACK_BREAK_CHAIN
Definition: periph.h:345
iBSP430halISRCallbackVoid_ni callback_ni
Definition: periph.h:433
int(* iBSP430halISRCallbackVoid_ni)(const struct sBSP430halISRVoidChainNode *cb, void *context)
Definition: periph.h:403
static BSP430_CORE_INLINE int iBSP430callbackInvokeISRIndexed_ni(const struct sBSP430halISRIndexedChainNode *volatile const *cbpp, void *context, int idx, int basis)
Definition: periph.h:486
struct sBSP430halISRIndexedChainNode sBSP430halISRIndexedChainNode
int tBSP430periphHandle
Definition: periph.h:106
Definition: periph.h:272
iBSP430halISRCallbackIndexed_ni callback_ni
Definition: periph.h:445
const struct sBSP430halISRVoidChainNode *volatile next_ni
Definition: periph.h:430