Go to the documentation of this file.00001 #ifndef _TMR_UTILS_H
00002 #define _TMR_UTILS_H
00003
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <stdint.h>
00034 #include <stddef.h>
00035
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039
00040
00041
00042 #define GETU8AT(msg, i) ( \
00043 ((msg)[(i)]) )
00044
00045 #define GETU16AT(msg, i) ( \
00046 ((uint16_t)((msg)[(i) ]) << 8) | \
00047 ((msg)[(i)+1] << 0) )
00048
00049 #define GETS16AT(msg, i) ( \
00050 ((int16_t)((msg)[(i) ]) << 8) | \
00051 ((int16_t)((msg)[(i)+1]) << 0) )
00052
00053 #define GETU24AT(msg, i) ( \
00054 ((uint32_t)((msg)[(i) ]) << 16) | \
00055 ((uint32_t)((msg)[(i)+1]) << 8) | \
00056 ((msg)[(i)+2] << 0) )
00057
00058 #define GETU32AT(msg, i) ( \
00059 ((uint32_t)((msg)[(i) ]) << 24) | \
00060 ((uint32_t)((msg)[(i)+1]) << 16) | \
00061 ((uint32_t)((msg)[(i)+2]) << 8) | \
00062 ((msg)[(i)+3] << 0) )
00063
00064
00065 #define GETU8(msg, i) ((msg)[(i)++])
00066 #define GETU16(msg, i) (i+=2, GETU16AT((msg), i-2))
00067 #define GETU24(msg, i) (i+=3, GETU24AT((msg), i-3))
00068 #define GETU32(msg, i) (i+=4, GETU32AT((msg), i-4))
00069
00070
00071 #define SETU8(msg, i, u8val) do { \
00072 (msg)[(i)++] = (u8val) & 0xff; \
00073 } while (0)
00074
00075 #define SETU16(msg, i, u16val) do { \
00076 uint16_t _tmp = (u16val); \
00077 (msg)[(i)++] =(uint8_t) (_tmp >> 8) & 0xff; \
00078 (msg)[(i)++] =(uint8_t)(_tmp >> 0) & 0xff; \
00079 } while (0)
00080
00081 #define SETS16(msg, i, s16val) do { \
00082 int16_t _tmp = (s16val); \
00083 (msg)[(i)++] =(int8_t) (_tmp >> 8) & 0xff; \
00084 (msg)[(i)++] =(int8_t)(_tmp >> 0) & 0xff; \
00085 } while (0)
00086
00087 #define SETU32(msg, i, u32val) do { \
00088 uint32_t _tmp = (u32val); \
00089 (msg)[(i)++] = (uint8_t)(_tmp >> 24) & 0xff; \
00090 (msg)[(i)++] = (uint8_t)(_tmp >> 16) & 0xff; \
00091 (msg)[(i)++] = (uint8_t)(_tmp >> 8) & 0xff; \
00092 (msg)[(i)++] = (uint8_t)(_tmp >> 0) & 0xff; \
00093 } while (0)
00094
00095 #define SETS32(msg, i, s32val) do { \
00096 int32_t _tmp = (s32val); \
00097 (msg)[(i)++] = (int8_t)(_tmp >> 24) & 0xff; \
00098 (msg)[(i)++] = (int8_t)(_tmp >> 16) & 0xff; \
00099 (msg)[(i)++] = (int8_t)(_tmp >> 8) & 0xff; \
00100 (msg)[(i)++] = (int8_t)(_tmp >> 0) & 0xff; \
00101 } while (0)
00102
00103
00104
00105
00106
00107
00108
00109 #define LISTAPPEND(l, value) do { \
00110 (l)->len++; \
00111 if ((l)->len <= (l)->max) \
00112 (l)->list[(l)->len - 1] = (value); \
00113 } while (0)
00114
00115
00116
00117 #define BITGET(array, number) (((array)[(number)/32] >> ((number)&31)) & 1)
00118 #define BITSET(array, number) ((array)[(number)/32] |= ((uint32_t)1 << ((number)&31)))
00119 #define BITCLR(array, number) ((array)[(number)/32] &= ~((uint32_t)1 << ((number)&31)))
00120
00121 #define numberof(x) (sizeof((x))/sizeof((x)[0]))
00122
00123 #ifndef TMR_USE_HOST_C_LIBRARY
00124 void *tm_memcpy(void *dest, const void *src, size_t n);
00125 char *tm_strcpy(char *dest, const char *src);
00126 char *tm_strchr(const char *s, int c);
00127
00128 #undef memcpy
00129 #undef strcpy
00130 #undef strchr
00131
00132 #define memcpy tm_memcpy
00133 #define strcpy tm_strcpy
00134 #define strchr tm_strchr
00135 #endif
00136
00137 int tm_strcasecmp(const char *s1, const char *s2);
00138 #define strcasecmp tm_strcasecmp
00139
00140 void tm_gettime_consistent(uint32_t *high, uint32_t *low);
00141 uint32_t tm_time_subtract(uint32_t end, uint32_t start);
00142 int tm_u8s_per_bits(int bitCount);
00143 void TMR_stringCopy(TMR_String *dest, const char *src, int len);
00144 uint64_t TMR_makeBitMask(int offset, int lenght);
00145 uint32_t TMR_byteArrayToInt(uint8_t data[], int offset);
00146 uint16_t TMR_byteArrayToShort(uint8_t data[], int offset);
00147 uint64_t TMR_byteArrayToLong(uint8_t data[], int offset);
00148 #ifdef __cplusplus
00149 }
00150 #endif
00151
00152 #endif