BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
event.h
Go to the documentation of this file.
1 /* Copyright 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 
72 #ifndef BSP430_UTILITY_EVENT_H
73 #define BSP430_UTILITY_EVENT_H
74 
75 #include <bsp430/periph/timer.h>
76 
81 typedef union uBSP430eventAnyType {
82  char c;
83  unsigned char uc;
84  int i;
85  unsigned int ui;
86  long l;
87  unsigned long ul;
88  uint8_t u8;
89  int8_t i8;
90  uint16_t u16;
91  int16_t i16;
92  uint32_t u32;
93  int32_t i32;
94  size_t sz;
95  void * p;
96  void (* fp)();
98 
102 typedef struct sBSP430eventTagConfig {
104  const char * id;
106  volatile unsigned int seqno;
108 
109 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_EVENT_TAG_NUM_SUPPORTED)
110 
113 #define BSP430_EVENT_TAG_NUM_SUPPORTED 8
114 #endif /* BSP430_EVENT_TAG_NUM_SUPPORTED */
115 
116 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_EVENT_RECORD_NUM_SUPPORTED)
117 
121 #define BSP430_EVENT_RECORD_NUM_SUPPORTED 16
122 #endif /* BSP430_EVENT_RECORD_NUM_SUPPORTED */
123 
128 static const unsigned char ucBSP430eventTag_LostEventRecord = 0;
129 
132 static const unsigned int uiBSP430eventFlag_EventRecord = 0x01;
133 
135 typedef struct sBSP430eventTagRecord {
139 
142  unsigned long timestamp_utt;
143 
145  unsigned int seqno;
146 
150  unsigned char tag;
151 
154  unsigned char flags;
156 
157 /* Forward declaration */
158 struct sBSP430eventPeriodic;
159 
167  struct sBSP430eventPeriodic * ap);
168 
184 
193  unsigned long interval_tck;
194 
197  unsigned char tag;
198 
201  unsigned char flags;
203 
206 
224  unsigned long setting_tck);
225 
239 
241 /* Not public API: the number of tags currently allocated */
242 extern unsigned char nBSP430eventTagConfig_;
243 /* Not public API: the configuration data for all tags */
244 extern sBSP430eventTagConfig xBSP430eventTagConfig_[];
245 /* Not public API: the event flag state */
246 extern volatile unsigned int uiBSP430eventFlags_v_;
256 static BSP430_CORE_INLINE
257 const sBSP430eventTagConfig *
258 hBSP430eventTagLookup (unsigned char tag)
259 {
260  if (tag < nBSP430eventTagConfig_) {
261  return xBSP430eventTagConfig_ + tag;
262  }
263  return NULL;
264 }
265 
284 unsigned char ucBSP430eventTagAllocate (const char * id);
285 
298 unsigned int uiBSP430eventFlagAllocate ();
299 
304 static BSP430_CORE_INLINE
306 {
307  return !uiBSP430eventFlags_v_;
308 }
309 
311 static BSP430_CORE_INLINE
313 {
314  int rv;
317  do {
319  } while (0);
321  return rv;
322 }
323 
330 static BSP430_CORE_INLINE
332 {
333  unsigned int rv = uiBSP430eventFlags_v_;
334  uiBSP430eventFlags_v_ = 0;
335  return rv;
336 }
337 
339 static BSP430_CORE_INLINE
340 unsigned int uiBSP430eventFlagsGet ()
341 {
342  unsigned int rv;
345  do {
347  } while (0);
349  return rv;
350 }
351 
359 static BSP430_CORE_INLINE
360 void vBSP430eventFlagsSet_ni (unsigned int flags)
361 {
362  uiBSP430eventFlags_v_ |= flags;
363 }
364 
366 static BSP430_CORE_INLINE
367 void vBSP430eventFlagsSet (unsigned int flags)
368 {
371  do {
373  } while (0);
375 }
376 
389 const volatile sBSP430eventTagRecord *
390 xBSP430eventRecordEvent_ni (unsigned char tag,
391  unsigned char flags,
392  const uBSP430eventAnyType * up);
393 
395 static BSP430_CORE_INLINE
396 void vBSP430eventRecordEvent (unsigned char tag,
397  unsigned char flags,
398  const uBSP430eventAnyType * up)
399 {
402  do {
403  xBSP430eventRecordEvent_ni(tag, flags, up);
404  } while (0);
406 }
407 
421  int len);
422 
423 #endif /* BSP430_UTILITY_EVENT_H */
void(* vBSP430eventPeriodicProcess)(const sBSP430eventTagRecord *ep, struct sBSP430eventPeriodic *ap)
Definition: event.h:166
unsigned long timestamp_utt
Definition: event.h:142
int iBSP430eventPeriodicRemove_ni(hBSP430timerMuxSharedAlarm shared, hBSP430eventPeriodicConfig cfg)
unsigned int uiBSP430eventFlagAllocate()
#define BSP430_CORE_RESTORE_INTERRUPT_STATE(state_)
Definition: core.h:731
int iBSP430eventPeriodicAdd_ni(hBSP430timerMuxSharedAlarm shared, hBSP430eventPeriodicConfig cfg, unsigned long setting_tck)
static BSP430_CORE_INLINE void vBSP430eventRecordEvent(unsigned char tag, unsigned char flags, const uBSP430eventAnyType *up)
Definition: event.h:396
unsigned long interval_tck
Definition: event.h:193
struct sBSP430eventTagRecord sBSP430eventTagRecord
volatile unsigned int seqno
Definition: event.h:106
Definition: event.h:135
Definition: event.h:81
unsigned char tag
Definition: event.h:150
static BSP430_CORE_INLINE unsigned int uiBSP430eventFlagsGet()
Definition: event.h:340
const volatile sBSP430eventTagRecord * xBSP430eventRecordEvent_ni(unsigned char tag, unsigned char flags, const uBSP430eventAnyType *up)
static const unsigned char ucBSP430eventTag_LostEventRecord
Definition: event.h:128
Definition: timer.h:1786
Hardware presentation/abstraction for generic timers (Timer_A/Timer_B)
static BSP430_CORE_INLINE void vBSP430eventFlagsSet_ni(unsigned int flags)
Definition: event.h:360
unsigned char ucBSP430eventTagAllocate(const char *id)
#define BSP430_CORE_INLINE
Definition: core.h:439
Definition: timer.h:1762
#define BSP430_CORE_SAVED_INTERRUPT_STATE(var_)
Definition: core.h:719
unsigned char tag
Definition: event.h:197
static BSP430_CORE_INLINE int iBSP430eventFlagsEmpty()
Definition: event.h:312
static BSP430_CORE_INLINE unsigned int uiBSP430eventFlagsGet_ni()
Definition: event.h:331
sBSP430timerMuxAlarm alarm_
Definition: event.h:183
unsigned char flags
Definition: event.h:201
sBSP430eventPeriodicConfig * hBSP430eventPeriodicConfig
Definition: event.h:205
uBSP430eventAnyType u
Definition: event.h:138
#define BSP430_CORE_DISABLE_INTERRUPT()
Definition: core.h:762
static BSP430_CORE_INLINE const sBSP430eventTagConfig * hBSP430eventTagLookup(unsigned char tag)
Definition: event.h:258
struct sBSP430eventPeriodicConfig sBSP430eventPeriodicConfig
static const unsigned int uiBSP430eventFlag_EventRecord
Definition: event.h:132
Definition: event.h:102
static BSP430_CORE_INLINE void vBSP430eventFlagsSet(unsigned int flags)
Definition: event.h:367
unsigned int seqno
Definition: event.h:145
const char * id
Definition: event.h:104
int iBSP430eventTagGetRecords(sBSP430eventTagRecord *evts, int len)
static BSP430_CORE_INLINE int iBSP430eventFlagsEmpty_ni()
Definition: event.h:305
Definition: event.h:179
struct sBSP430eventTagConfig sBSP430eventTagConfig
union uBSP430eventAnyType uBSP430eventAnyType
unsigned char flags
Definition: event.h:154