TI BLE5-Stack API Documentation
9.14.00
.build.ble5.cc23xx
api-sources
ble-core
source
ti
ble
stack_util
comdef.h
Go to the documentation of this file.
1
/******************************************************************************
2
3
@file comdef.h
4
5
@brief This file contains useful macros and data types
6
7
Group: WCS, LPC, BTS
8
$Target Device: DEVICES $
9
10
******************************************************************************
11
$License: BSD3 2004 $
12
******************************************************************************
13
$Release Name: PACKAGE NAME $
14
$Release Date: PACKAGE RELEASE DATE $
15
*****************************************************************************/
16
22
#ifndef COMDEF_H
23
#define COMDEF_H
24
25
#ifdef __cplusplus
26
extern
"C"
27
{
28
#endif
29
30
31
/*********************************************************************
32
* INCLUDES
33
*/
34
35
#include <stdint.h>
36
#include <stdbool.h>
37
39
40
/*********************************************************************
41
* Lint Keywords
42
*/
43
#define VOID (void)
44
45
/*********************************************************************
46
* CONSTANTS
47
*/
48
49
#ifndef false
50
#define false 0
51
#endif
52
53
#ifndef true
54
#define true 1
55
#endif
56
57
#ifndef GENERIC
58
#define GENERIC
59
#endif
60
61
#ifndef TRUE
62
#define TRUE 1
63
#endif
64
65
#ifndef UTRUE
66
#define UTRUE 1U
67
#endif
68
69
#ifndef FALSE
70
#define FALSE 0
71
#endif
72
73
#ifndef UFALSE
74
#define UFALSE 0U
75
#endif
76
77
// Fix to stdint.h definitions
78
#ifdef UINT8_MAX
79
#undef UINT8_MAX
80
#define UINT8_MAX 255U
81
#endif
82
83
#ifdef UINT16_MAX
84
#undef UINT16_MAX
85
#define UINT16_MAX 65535U
86
#endif
87
89
90
/*** Generic Status Return Values ***/
91
#define SUCCESS 0x00
92
#define USUCCESS 0U
93
#define FAILURE 0x01
94
#define UFAILURE 1U
95
#define INVALIDPARAMETER 0x02
96
#define UINVALIDPARAMETER 2U
97
#define INVALID_TASK 0x03
98
#define MSG_BUFFER_NOT_AVAIL 0x04
99
#define INVALID_MSG_POINTER 0x05
100
#define INVALID_EVENT_ID 0x06
101
#define INVALID_INTERRUPT_ID 0x07
102
#define NO_TIMER_AVAIL 0x08
103
#define NV_ITEM_UNINIT 0x09
104
#define NV_OPER_FAILED 0x0A
105
#define INVALID_MEM_SIZE 0x0B
106
#define NV_BAD_ITEM_LEN 0x0C
107
108
/*********************************************************************
109
* TYPEDEFS
110
*/
111
113
114
// Generic Status return
115
typedef
uint8_t Status_t;
116
117
// Data types
118
typedef
signed
char
int8;
119
typedef
unsigned
char
uint8;
120
121
typedef
signed
short
int16;
122
typedef
unsigned
short
uint16;
123
124
typedef
signed
long
int32;
125
typedef
unsigned
long
uint32;
126
127
typedef
uint32_t halDataAlign_t;
128
130
131
/*********************************************************************
132
* MACROS
133
*/
134
135
#ifndef BV
136
#define BV(n) (1 << (n))
137
#endif
138
139
#ifndef BF
140
#define BF(x,b,s) (((x) & (b)) >> (s))
141
#endif
142
143
#ifndef ABS
144
#define ABS(n) (((n) < 0) ? -(n) : (n))
145
#endif
146
147
// Break a uint32_t variable into a specific byte
148
#define BREAK_UINT32(var, ByteNum) \
149
((((var) >> ((ByteNum) * 8)) & 0x00FF))
150
151
// Build a uint32_t from four bytes
152
#define BUILD_UINT32(Byte0, Byte1, Byte2, Byte3) ( (((Byte3) & 0xFF) << 24) | \
153
(((Byte2) & 0xFF) << 16) | \
154
(((Byte1) & 0xFF) << 8) | \
155
((Byte0) & 0xFF) )
156
157
// Build a uint16_t from two bytes
158
#define BUILD_UINT16(loByte, hiByte) ( ((loByte) & 0xFF) | (((hiByte) & 0xFF) << 8) )
159
160
// Get the high byte of a uint16_t
161
#define HI_UINT16(a) (((a) >> 8) & 0xFF)
162
163
// Get the low byte of a uint16_t
164
#define LO_UINT16(a) ((a) & 0xFF)
165
166
// Get a uint16_t from a pointer to a byte array
167
#define GET_UINT16(a) ((uint16_t)((*((uint8_t *)a)) + (((uint16_t)(*(((uint8_t *)a) + 1))) << 8)))
168
169
// Build a uint8_t from two nibbles
170
#define BUILD_UINT8(hiByte, loByte) \
171
(((loByte) & 0x0F) + (((hiByte) & 0x0F) << 4))
172
173
// Get the high nibble of a uint8_t
174
#define HI_UINT8(a) (((a) >> 4) & 0x0F)
175
176
// Get the low nibble of a uint8_t
177
#define LO_UINT8(a) ((a) & 0x0F)
178
179
// Write the 32bit value of 'val' in little endian format to the buffer pointed
180
// to by pBuf, and increment pBuf by 4
181
#define UINT32_TO_BUF_LITTLE_ENDIAN(pBuf, val) \
182
do { \
183
*(pBuf)++ = ((val >> 0) & 0xFF); \
184
*(pBuf)++ = ((val >> 8) & 0xFF); \
185
*(pBuf)++ = ((val >> 16) & 0xFF); \
186
*(pBuf)++ = ((val >> 24) & 0xFF); \
187
} while (0)
188
189
// Return the 32bit little-endian formatted value pointed to by pBuf, and increment pBuf by 4
190
#define BUF_TO_UINT32_LITTLE_ENDIAN(pBuf) (((pBuf) += 4), BUILD_UINT32((pBuf)[-1], (pBuf)[-2], (pBuf)[-3], (pBuf)[-4]))
191
192
#ifndef GET_BIT
193
// Macro to get the value of a specific bit in a byte array
194
#define GET_BIT(DISCS, IDX) (((DISCS)[((IDX) / 8)] & BV((IDX) % 8)) ? TRUE : FALSE)
195
#endif
196
197
#ifndef SET_BIT
198
// Macro to set a specific bit in a byte array
199
#define SET_BIT(DISCS, IDX) (((DISCS)[((IDX) / 8)] |= BV((IDX) % 8)))
200
#endif
201
202
#ifndef CLR_BIT
203
// Macro to clear a specific bit in a byte array
204
#define CLR_BIT(DISCS, IDX) (((DISCS)[((IDX) / 8)] &= (BV((IDX) % 8) ^ 0xFF)))
205
#endif
206
207
/*
208
* This macro is for use by other macros to form a fully valid C statement.
209
* Without this, the if/else conditionals could show unexpected behavior.
210
*
211
* For example, use...
212
* #define SET_REGS() st( ioreg1 = 0; ioreg2 = 0; )
213
* instead of ...
214
* #define SET_REGS() { ioreg1 = 0; ioreg2 = 0; }
215
* or
216
* #define SET_REGS() ioreg1 = 0; ioreg2 = 0;
217
* The last macro would not behave as expected in the if/else construct.
218
* The second to last macro will cause a compiler error in certain uses
219
* of if/else construct
220
*
221
* It is not necessary, or recommended, to use this macro where there is
222
* already a valid C statement. For example, the following is redundant...
223
* #define CALL_FUNC() st( func(); )
224
* This should simply be...
225
* #define CALL_FUNC() func()
226
*
227
* (The while condition below evaluates false without generating a
228
* constant-controlling-loop type of warning on most compilers.)
229
*/
230
#define st(x) do { x } while (__LINE__ == -1)
231
232
/*
233
* The offsetof macro is a standard macro defined in the C standard library header <stddef.h>
234
* It is used to determine the byte offset of a member within a structure type.
235
*/
236
#ifndef offsetof
237
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
238
#endif
239
/*********************************************************************
240
* MEMORY ATTRIBUTES
241
*/
242
243
#if defined (__IAR_SYSTEMS_ICC__)
244
#define XDATA
245
#define CODE
246
#define DATA_ALIGN(x) _Pragma data_alignment=(x)
247
#define ALIGNED
248
#define PACKED __packed
249
#define PACKED_STRUCT PACKED struct
250
#define PACKED_TYPEDEF_STRUCT PACKED typedef struct
251
#define PACKED_TYPEDEF_CONST_STRUCT PACKED typedef const struct
252
#define PACKED_TYPEDEF_UNION PACKED typedef union
253
#define PACKED_ALIGNED PACKED
254
#define PACKED_ALIGNED_TYPEDEF_STRUCT PACKED_TYPEDEF_STRUCT
255
256
#elif defined __TI_COMPILER_VERSION || defined __TI_COMPILER_VERSION__
257
#define XDATA
258
#define CODE
259
#define DATA
260
#define NEARFUNC
261
#define ALIGNED
262
#define PACKED __attribute__((packed))
263
#define PACKED_STRUCT struct PACKED
264
#define PACKED_TYPEDEF_STRUCT typedef struct PACKED
265
#define PACKED_TYPEDEF_CONST_STRUCT typedef const struct PACKED
266
#define PACKED_TYPEDEF_UNION typedef union PACKED
267
#define PACKED_ALIGNED __attribute__((packed,aligned(4)))
268
#define PACKED_ALIGNED_TYPEDEF_STRUCT typedef struct PACKED_ALIGNED
269
270
#elif defined (__GNUC__)
271
#define ALIGNED __attribute__((aligned(4)))
272
#ifdef CC33xx
273
#define PACKED __attribute__((aligned(1))) __attribute__((packed))
274
#else
275
#define PACKED __attribute__((__packed__))
276
#endif
277
#define PACKED_STRUCT struct PACKED
278
#define PACKED_TYPEDEF_STRUCT typedef struct PACKED
279
#define PACKED_TYPEDEF_CONST_STRUCT typedef const struct PACKED
280
#define PACKED_TYPEDEF_UNION typedef union PACKED
281
#define PACKED_ALIGNED __attribute__((packed,aligned(4)))
282
#define PACKED_ALIGNED_TYPEDEF_STRUCT typedef struct PACKED_ALIGNED
283
#endif
284
285
/*********************************************************************
286
* COMPILER MACROS
287
*/
288
289
/* ----------- IAR Compiler ----------- */
290
#ifdef __IAR_SYSTEMS_ICC__
291
#define ASM_NOP asm("NOP")
292
#define NO_INIT __no_init
293
#define WEAK_FUNC __weak
294
295
/* ----------- KEIL Compiler ----------- */
296
#elif defined __KEIL__
297
#define ASM_NOP __nop()
298
299
/* ----------- CCS Compiler ----------- */
300
#elif defined __TI_COMPILER_VERSION || defined __TI_COMPILER_VERSION__
301
#define ASM_NOP asm(" NOP")
302
#define NO_INIT __attribute__((noinit))
303
304
/* ----------- GNU Compiler ----------- */
305
#elif defined __GNUC__
306
#define ASM_NOP __asm__ __volatile__ ("nop")
307
#define WEAK_FUNC __attribute__((__weak__))
308
309
/* ---------- MSVC compiler ---------- */
310
#elif _MSC_VER
311
#define ASM_NOP __asm NOP
312
313
/* ----------- Unrecognized Compiler ----------- */
314
#else
315
#error "ERROR: Unknown compiler."
316
#endif
317
318
/*********************************************************************
319
* GLOBAL VARIABLES
320
*/
321
322
/*********************************************************************
323
* FUNCTIONS
324
*/
325
326
/*********************************************************************
327
*********************************************************************/
328
329
#ifdef __cplusplus
330
}
331
#endif
332
333
#endif
/* COMDEF_H */
© Copyright 1995-2025
, Texas Instruments Incorporated. All rights reserved.
Trademarks
|
Privacy policy
|
Terms of use
|
Terms of sale