[apps/tidep0084.git] / tutorials / generic_sensor_tutorial / final / SensorToCloud / example / collector / util.h
1 /******************************************************************************
3 @file util.h
5 @brief Declaration of utility functions common to TIMAC Applications.
7 Group: WCS LPC
8 $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350$
10 ******************************************************************************
11 $License: BSD3 2016 $
13 Copyright (c) 2015, Texas Instruments Incorporated
14 All rights reserved.
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
20 * Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
27 * Neither the name of Texas Instruments Incorporated nor the names of
28 its contributors may be used to endorse or promote products derived
29 from this software without specific prior written permission.
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ******************************************************************************
43 $Release Name: TI-15.4Stack Linux x64 SDK$
44 $Release Date: Jun 28, 2017 (2.02.00.03)$
45 *****************************************************************************/
46 #ifndef UTIL_H
47 #define UTIL_H
49 /******************************************************************************
50 Includes
51 *****************************************************************************/
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
58 /*!
59 \defgroup UtilMisc Utility and Miscellaneous
60 <BR>
61 Miscellaneous conversion functions.
62 <BR>
63 */
65 /******************************************************************************
66 Constants and definitions
67 *****************************************************************************/
69 #if !defined(STATIC)
70 #if defined(UNIT_TEST)
71 /*! Allow access to the local variables to test code by making them public*/
72 #define STATIC
73 #else
74 /*! Define STATIC as static for local variables */
75 #define STATIC static
76 #endif
77 #endif
79 #if !defined(CONST)
80 #if defined(UNIT_TEST)
81 /*! Allow constant to be used in different context*/
82 #define CONST
83 #else
84 /*! Define CONST as const for local variables */
85 #define CONST const
86 #endif
87 #endif
88 /*!
89 * \ingroup UtilMisc
90 * @{
91 */
93 /******************************************************************************
94 Function Prototypes
95 *****************************************************************************/
97 /*!
98 * @brief Converts from a uint16 to ascii hex string.
99 * The # will be exactly 4 hex digits (e.g. 0x0000 or 0x1E3F).
100 * NULL terminates the string.
101 *
102 * @param u - Number to be converted
103 * @param string - pointer to coverted string
104 */
105 extern void Util_uint16toa(uint16_t u, char *string);
107 /*!
108 * @brief Convert a 16bit number to ASCII
109 *
110 * @param num - number to convert
111 * @param buf - buffer to write ASCII
112 * @param radix - base to convert to (ie. 10 or 16)
113 */
114 extern void Util_itoa(uint16_t num, uint8_t *buf, uint8_t radix);
116 /*!
117 * @brief Convert a long unsigned int to a string.
118 *
119 * @param l - long to convert
120 * @param buf - buffer to convert to
121 * @param radix - 10 dec, 16 hex
122 *
123 * @return pointer to buffer
124 */
125 extern unsigned char *Util_ltoa(uint32_t l, uint8_t *buf, uint8_t radix);
127 /*!
128 * @brief Get the high byte of a uint16_t variable
129 *
130 * @param a - uint16_t variable
131 *
132 * @return high byte
133 */
134 extern uint8_t Util_hiUint16(uint16_t a);
136 /*!
137 * @brief Get the low byte of a uint16_t variable
138 *
139 * @param a - uint16_t variable
140 *
141 * @return low byte
142 */
143 extern uint8_t Util_loUint16(uint16_t a);
145 /*!
146 * @brief Build a uint16_t out of 2 uint8_t variables
147 *
148 * @param loByte - low byte
149 * @param hiByte - high byte
150 *
151 * @return combined uint16_t
152 */
153 extern uint16_t Util_buildUint16(uint8_t loByte, uint8_t hiByte);
155 /*!
156 * @brief Build a uint32_t out of 4 uint8_t variables
157 *
158 * @param byte0 - byte - 0
159 * @param byte1 - byte - 1
160 * @param byte2 - byte - 2
161 * @param byte3 - byte - 3
162 *
163 * @return combined uint32_t
164 */
165 extern uint32_t Util_buildUint32(uint8_t byte0, uint8_t byte1, uint8_t byte2,
166 uint8_t byte3);
168 /*!
169 * @brief Pulls 1 uint8_t out of a uint32_t
170 *
171 * @param var - uint32_t variable
172 * @param byteNum - what byte to pull out (0-3)
173 *
174 * @return uint8_t
175 */
176 extern uint8_t Util_breakUint32(uint32_t var, int byteNum);
178 /*!
179 * @brief Build a uint16_t from a uint8_t array
180 *
181 * @param pArray - pointer to uint8_t array
182 *
183 * @return combined uint16_t
184 */
186 extern uint16_t Util_parseUint16(uint8_t *pArray);
188 /*!
189 * @brief Build a uint32_t from a uint8_t array
190 *
191 * @param pArray - pointer to uint8_t array
192 *
193 * @return combined uint32_t
194 */
195 extern uint32_t Util_parseUint32(uint8_t *pArray);
197 /*!
198 * @brief Break and buffer a uint16 value - LSB first
199 *
200 * @param pBuf - ptr to next available buffer location
201 * @param val - 16-bit value to break/buffer
202 *
203 * @return pBuf - ptr to next available buffer location
204 */
205 extern uint8_t *Util_bufferUint16(uint8_t *pBuf, uint16_t val);
207 /*!
208 * @brief Break and buffer a uint32 value - LSB first
209 *
210 * @param pBuf - ptr to next available buffer location
211 * @param val - 32-bit value to break/buffer
212 *
213 * @return pBuf - ptr to next available buffer location
214 */
215 extern uint8_t *Util_bufferUint32(uint8_t *pBuf, uint32_t val);
217 /*!
218 * @brief Utility function to clear an event
219 *
220 * @param pEvent - pointer to event variable
221 * @param event - event(s) to clear
222 */
223 extern void Util_clearEvent(uint16_t *pEvent, uint16_t event);
225 /*!
226 * @brief Utility function to set an event
227 *
228 * @param pEvent - pointer to event variable
229 * @param event - event(s) to clear
230 */
231 extern void Util_setEvent(uint16_t *pEvent, uint16_t event);
233 /*!
234 * @brief Utility function to copy the extended address
235 *
236 * @param pSrcAddr - pointer to source from which to be copied
237 * @param pDstAddr - pointer to destination to copy to
238 */
239 extern void Util_copyExtAddr(void *pSrcAddr, void *pDstAddr);
241 /*! @} end group UtilMisc */
243 #ifdef __cplusplus
244 }
245 #endif
247 #endif /* UTIL_H */
249 /*
250 * ========================================
251 * Texas Instruments Micro Controller Style
252 * ========================================
253 * Local Variables:
254 * mode: c
255 * c-file-style: "bsd"
256 * tab-width: 4
257 * c-basic-offset: 4
258 * indent-tabs-mode: nil
259 * End:
260 * vim:set filetype=c tabstop=4 shiftwidth=4 expandtab=true
261 */