-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmac_util.h
247 lines (211 loc) · 6.18 KB
/
mac_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/******************************************************************************
@file mac_util.h
@brief Declaration of utility functions common to TIMAC Applications.
Group: WCS LPC
$Target Device: DEVICES $
******************************************************************************
$License: BSD3 2016 $
******************************************************************************
$Release Name: PACKAGE NAME $
$Release Date: PACKAGE RELEASE DATE $
*****************************************************************************/
#ifndef UTIL_H
#define UTIL_H
/******************************************************************************
Includes
*****************************************************************************/
#include <stdint.h>
#ifndef COPROCESSOR
#include "ti_154stack_config.h"
#endif
#ifdef __cplusplus
extern "C"
{
#endif
/*!
\defgroup UtilMisc Utility and Miscellaneous
<BR>
Miscellaneous conversion functions.
<BR>
*/
/******************************************************************************
Constants and definitions
*****************************************************************************/
/* aBaseSuperFrame Duration in slots */
#define BASE_SUPER_FRAME_DURATION 960
/* symbol duration for 50 kbps mode in micro seconds*/
#define SYMBOL_DURATION_50_kbps 20
/* symbol duration for 200 kbps mode in micro seconds*/
#define SYMBOL_DURATION_200_kbps 5
/* symbol duration for 250 kbps mode in micro seconds*/
#define SYMBOL_DURATION_250_kbps 16
/* symbol duration for LRM mode in micro seconds*/
#define SYMBOL_DURATION_LRM 50
#ifdef POWER_MEAS
/* POLL only profile */
#define POLL_ACK 1
/* sensor data only profile */
#define DATA_ACK 2
/* Poll + Data */
#define POLL_DATA 3
/* SLEEP */
#define SLEEP 4
#endif
#if !defined(STATIC)
#if defined(UNIT_TEST)
/*! Allow access to the local variables to test code by making them public*/
#define STATIC
#else
/*! Define STATIC as static for local variables */
#define STATIC static
#endif
#endif
#if !defined(CONST)
#if defined(UNIT_TEST)
/*! Allow constant to be used in different context*/
#define CONST
#else
/*! Define CONST as const for local variables */
#define CONST const
#endif
#endif
/*!
* \ingroup UtilMisc
* @{
*/
/******************************************************************************
Function Prototypes
*****************************************************************************/
/*!
* @brief Converts from a uint16 to ascii hex string.
* The # will be exactly 4 hex digits (e.g. 0x0000 or 0x1E3F).
* NULL terminates the string.
*
* @param u - Number to be converted
* @param string - pointer to coverted string
*/
extern void Util_uint16toa(uint16_t u, char *string);
/*!
* @brief Convert a 16bit number to ASCII
*
* @param num - number to convert
* @param buf - buffer to write ASCII
* @param radix - base to convert to (ie. 10 or 16)
*/
extern void Util_itoa(uint16_t num, uint8_t *buf, uint8_t radix);
/*!
* @brief Convert a long unsigned int to a string.
*
* @param l - long to convert
* @param buf - buffer to convert to
* @param radix - 10 dec, 16 hex
*
* @return pointer to buffer
*/
extern unsigned char *Util_ltoa(uint32_t l, uint8_t *buf, uint8_t radix);
/*!
* @brief Get the high byte of a uint16_t variable
*
* @param a - uint16_t variable
*
* @return high byte
*/
extern uint8_t Util_hiUint16(uint16_t a);
/*!
* @brief Get the low byte of a uint16_t variable
*
* @param a - uint16_t variable
*
* @return low byte
*/
extern uint8_t Util_loUint16(uint16_t a);
/*!
* @brief Build a uint16_t out of 2 uint8_t variables
*
* @param loByte - low byte
* @param hiByte - high byte
*
* @return combined uint16_t
*/
extern uint16_t Util_buildUint16(uint8_t loByte, uint8_t hiByte);
/*!
* @brief Build a uint32_t out of 4 uint8_t variables
*
* @param byte0 - byte - 0
* @param byte1 - byte - 1
* @param byte2 - byte - 2
* @param byte3 - byte - 3
*
* @return combined uint32_t
*/
extern uint32_t Util_buildUint32(uint8_t byte0, uint8_t byte1, uint8_t byte2,
uint8_t byte3);
/*!
* @brief Pulls 1 uint8_t out of a uint32_t
*
* @param var - uint32_t variable
* @param byteNum - what byte to pull out (0-3)
*
* @return uint8_t
*/
extern uint8_t Util_breakUint32(uint32_t var, int byteNum);
/*!
* @brief Build a uint16_t from a uint8_t array
*
* @param pArray - pointer to uint8_t array
*
* @return combined uint16_t
*/
extern uint16_t Util_parseUint16(uint8_t *pArray);
/*!
* @brief Build a uint32_t from a uint8_t array
*
* @param pArray - pointer to uint8_t array
*
* @return combined uint32_t
*/
extern uint32_t Util_parseUint32(uint8_t *pArray);
/*!
* @brief Break and buffer a uint16 value - LSB first
*
* @param pBuf - ptr to next available buffer location
* @param val - 16-bit value to break/buffer
*
* @return pBuf - ptr to next available buffer location
*/
extern uint8_t *Util_bufferUint16(uint8_t *pBuf, uint16_t val);
/*!
* @brief Break and buffer a uint32 value - LSB first
*
* @param pBuf - ptr to next available buffer location
* @param val - 32-bit value to break/buffer
*
* @return pBuf - ptr to next available buffer location
*/
extern uint8_t *Util_bufferUint32(uint8_t *pBuf, uint32_t val);
/*!
* @brief Utility function to clear an event
*
* @param pEvent - pointer to event variable
* @param event - event(s) to clear
*/
extern void Util_clearEvent(uint16_t *pEvent, uint16_t event);
/*!
* @brief Utility function to set an event
*
* @param pEvent - pointer to event variable
* @param event - event(s) to clear
*/
extern void Util_setEvent(uint16_t *pEvent, uint16_t event);
/*!
* @brief Utility function to copy the extended address
*
* @param pSrcAddr - pointer to source from which to be copied
* @param pDstAddr - pointer to destination to copy to
*/
extern void Util_copyExtAddr(void *pSrcAddr, void *pDstAddr);
/*! @} end group UtilMisc */
#ifdef __cplusplus
}
#endif
#endif /* UTIL_H */