compiler.h
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #ifndef UTILS_COMPILER_H
38 #define UTILS_COMPILER_H
39 
48 #include <stddef.h>
49 
50 #if (defined __ICCARM__)
51 # include <intrinsics.h>
52 #endif
53 
54 #include <parts.h>
55 #include "preprocessor.h"
56 
57 #include <io.h>
58 
59 //_____ D E C L A R A T I O N S ____________________________________________
60 
61 #ifndef __ASSEMBLY__ // Not defined for assembling.
62 
63 #include <stdio.h>
64 #include <stdbool.h>
65 #include <stdint.h>
66 #include <stdlib.h>
67 
68 #ifdef __ICCARM__
69 
73 #define __asm__ asm
75 #define __inline__ inline
76 #define __volatile__
77 
79 #endif
80 
81 #define FUNC_PTR void *
82 
86 #define UNUSED(v) (void)(v)
87 
92 #define unused(v) do { (void)(v); } while(0)
93 
98 #define barrier() __DMB()
99 
106 #define COMPILER_PRAGMA(arg) _Pragma(#arg)
107 
113 #define COMPILER_PACK_SET(alignment) COMPILER_PRAGMA(pack(alignment))
114 
120 #define COMPILER_PACK_RESET() COMPILER_PRAGMA(pack())
121 
122 
126 #if (defined __GNUC__) || (defined __CC_ARM)
127 # define COMPILER_ALIGNED(a) __attribute__((__aligned__(a)))
128 #elif (defined __ICCARM__)
129 # define COMPILER_ALIGNED(a) COMPILER_PRAGMA(data_alignment = a)
130 #endif
131 
135 #if (defined __GNUC__) || defined(__CC_ARM)
136 #define COMPILER_WORD_ALIGNED __attribute__((__aligned__(4)))
137 #elif (defined __ICCARM__)
138 #define COMPILER_WORD_ALIGNED COMPILER_PRAGMA(data_alignment = 4)
139 #endif
140 
149 #if defined(__CC_ARM)
150 # define __always_inline __forceinline
151 #elif (defined __GNUC__)
152 #ifdef __always_inline
153 # undef __always_inline
154 #endif
155 # define __always_inline inline __attribute__((__always_inline__))
156 #elif (defined __ICCARM__)
157 # define __always_inline _Pragma("inline=forced")
158 #endif
159 
167 #if defined(__CC_ARM)
168 # define __no_inline __attribute__((noinline))
169 #elif (defined __GNUC__)
170 # define __no_inline __attribute__((__noinline__))
171 #elif (defined __ICCARM__)
172 # define __no_inline _Pragma("inline=never")
173 #endif
174 
184 #if defined(_ASSERT_ENABLE_)
185 # if defined(TEST_SUITE_DEFINE_ASSERT_MACRO)
186  // Assert() is defined in unit_test/suite.h
187 # include "unit_test/suite.h"
188 # else
189 #undef TEST_SUITE_DEFINE_ASSERT_MACRO
190 # define Assert(expr) \
191  {\
192  if (!(expr)) while (true);\
193  }
194 # endif
195 #else
196 # define Assert(expr) ((void) 0)
197 #endif
198 
199 /* Define WEAK attribute */
200 #if defined ( __CC_ARM ) /* Keil µVision 4 */
201 # define WEAK __attribute__ ((weak))
202 #elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
203 # define WEAK __weak
204 #elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
205 # define WEAK __attribute__ ((weak))
206 #endif
207 
208 /* Define NO_INIT attribute */
209 #if defined ( __CC_ARM )
210 # define NO_INIT __attribute__((zero_init))
211 #elif defined ( __ICCARM__ )
212 # define NO_INIT __no_init
213 #elif defined ( __GNUC__ )
214 # define NO_INIT __attribute__((section(".no_init")))
215 #endif
216 
217 /* Define RAMFUNC attribute */
218 #if defined ( __CC_ARM ) /* Keil µVision 4 */
219 # define RAMFUNC __attribute__ ((section(".ramfunc")))
220 #elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
221 # define RAMFUNC __ramfunc
222 #elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
223 # define RAMFUNC __attribute__ ((section(".ramfunc")))
224 #endif
225 
226 /* Define OPTIMIZE_HIGH attribute */
227 #if defined ( __CC_ARM ) /* Keil µVision 4 */
228 # define OPTIMIZE_HIGH _Pragma("O3")
229 #elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
230 # define OPTIMIZE_HIGH _Pragma("optimize=high")
231 #elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */
232 # define OPTIMIZE_HIGH __attribute__((optimize("s")))
233 #endif
234 
235 #include "interrupt.h"
236 
239 typedef unsigned char Bool;
241 #ifndef __cplusplus
242 #if !defined(__bool_true_false_are_defined)
243 typedef unsigned char bool;
244 #endif
245 #endif
246 typedef int8_t S8 ;
247 typedef uint8_t U8 ;
248 typedef int16_t S16;
249 typedef uint16_t U16;
250 typedef uint16_t le16_t;
251 typedef uint16_t be16_t;
252 typedef int32_t S32;
253 typedef uint32_t U32;
254 typedef uint32_t le32_t;
255 typedef uint32_t be32_t;
256 typedef int64_t S64;
257 typedef uint64_t U64;
258 typedef float F32;
259 typedef double F64;
260 typedef uint32_t iram_size_t;
262 
263 
266 typedef bool Status_bool_t;
268 typedef U8 Status_t;
269 
271 
274 
277 typedef union
278 {
281  S8 s8 [2];
282  U8 u8 [2];
283 } Union16;
284 
286 typedef union
287 {
290  S16 s16[2];
291  U16 u16[2];
292  S8 s8 [4];
293  U8 u8 [4];
294 } Union32;
295 
297 typedef union
298 {
301  S32 s32[2];
302  U32 u32[2];
303  S16 s16[4];
304  U16 u16[4];
305  S8 s8 [8];
306  U8 u8 [8];
307 } Union64;
308 
310 typedef union
311 {
320 } UnionPtr;
321 
323 typedef union
324 {
325  volatile S64 *s64ptr;
326  volatile U64 *u64ptr;
327  volatile S32 *s32ptr;
328  volatile U32 *u32ptr;
329  volatile S16 *s16ptr;
330  volatile U16 *u16ptr;
331  volatile S8 *s8ptr ;
332  volatile U8 *u8ptr ;
333 } UnionVPtr;
334 
336 typedef union
337 {
338  const S64 *s64ptr;
339  const U64 *u64ptr;
340  const S32 *s32ptr;
341  const U32 *u32ptr;
342  const S16 *s16ptr;
343  const U16 *u16ptr;
344  const S8 *s8ptr ;
345  const U8 *u8ptr ;
346 } UnionCPtr;
347 
349 typedef union
350 {
351  const volatile S64 *s64ptr;
352  const volatile U64 *u64ptr;
353  const volatile S32 *s32ptr;
354  const volatile U32 *u32ptr;
355  const volatile S16 *s16ptr;
356  const volatile U16 *u16ptr;
357  const volatile S8 *s8ptr ;
358  const volatile U8 *u8ptr ;
359 } UnionCVPtr;
360 
362 typedef struct
363 {
372 } StructPtr;
373 
375 typedef struct
376 {
377  volatile S64 *s64ptr;
378  volatile U64 *u64ptr;
379  volatile S32 *s32ptr;
380  volatile U32 *u32ptr;
381  volatile S16 *s16ptr;
382  volatile U16 *u16ptr;
383  volatile S8 *s8ptr ;
384  volatile U8 *u8ptr ;
385 } StructVPtr;
386 
388 typedef struct
389 {
390  const S64 *s64ptr;
391  const U64 *u64ptr;
392  const S32 *s32ptr;
393  const U32 *u32ptr;
394  const S16 *s16ptr;
395  const U16 *u16ptr;
396  const S8 *s8ptr ;
397  const U8 *u8ptr ;
398 } StructCPtr;
399 
401 typedef struct
402 {
403  const volatile S64 *s64ptr;
404  const volatile U64 *u64ptr;
405  const volatile S32 *s32ptr;
406  const volatile U32 *u32ptr;
407  const volatile S16 *s16ptr;
408  const volatile U16 *u16ptr;
409  const volatile S8 *s8ptr ;
410  const volatile U8 *u8ptr ;
411 } StructCVPtr;
412 
414 
415 #endif // #ifndef __ASSEMBLY__
416 
419 #define DISABLE 0
421 #define ENABLE 1
422 #ifndef __cplusplus
423 #if !defined(__bool_true_false_are_defined)
424 #define false 0
425 #define true 1
426 #endif
427 #endif
428 #define PASS 0
429 #define FAIL 1
430 #define LOW 0
431 #define HIGH 1
432 
434 
435 #ifndef __ASSEMBLY__ // not for assembling.
436 
438 
439 
444 #ifndef likely
445 # define likely(exp) (exp)
446 #endif
447 
452 #ifndef unlikely
453 # define unlikely(exp) (exp)
454 #endif
455 
464 #if (defined __GNUC__) || (defined __CC_ARM)
465 # define is_constant(exp) __builtin_constant_p(exp)
466 #else
467 # define is_constant(exp) (0)
468 #endif
469 
471 
474 
483 #define Rd_bits( value, mask) ((value) & (mask))
484 
493 #define Wr_bits(lvalue, mask, bits) ((lvalue) = ((lvalue) & ~(mask)) |\
494  ((bits ) & (mask)))
495 
503 #define Tst_bits( value, mask) (Rd_bits(value, mask) != 0)
504 
512 #define Clr_bits(lvalue, mask) ((lvalue) &= ~(mask))
513 
521 #define Set_bits(lvalue, mask) ((lvalue) |= (mask))
522 
530 #define Tgl_bits(lvalue, mask) ((lvalue) ^= (mask))
531 
539 #define Rd_bitfield( value, mask) (Rd_bits( value, mask) >> ctz(mask))
540 
549 #define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (U32)(bitfield) << ctz(mask)))
550 
552 
553 
566 
574 #if (defined __GNUC__) || (defined __CC_ARM)
575 # define clz(u) ((u) ? __builtin_clz(u) : 32)
576 #elif (defined __ICCARM__)
577 # define clz(u) ((u) ? __CLZ(u) : 32)
578 #else
579 # define clz(u) (((u) == 0) ? 32 : \
580  ((u) & (1ul << 31)) ? 0 : \
581  ((u) & (1ul << 30)) ? 1 : \
582  ((u) & (1ul << 29)) ? 2 : \
583  ((u) & (1ul << 28)) ? 3 : \
584  ((u) & (1ul << 27)) ? 4 : \
585  ((u) & (1ul << 26)) ? 5 : \
586  ((u) & (1ul << 25)) ? 6 : \
587  ((u) & (1ul << 24)) ? 7 : \
588  ((u) & (1ul << 23)) ? 8 : \
589  ((u) & (1ul << 22)) ? 9 : \
590  ((u) & (1ul << 21)) ? 10 : \
591  ((u) & (1ul << 20)) ? 11 : \
592  ((u) & (1ul << 19)) ? 12 : \
593  ((u) & (1ul << 18)) ? 13 : \
594  ((u) & (1ul << 17)) ? 14 : \
595  ((u) & (1ul << 16)) ? 15 : \
596  ((u) & (1ul << 15)) ? 16 : \
597  ((u) & (1ul << 14)) ? 17 : \
598  ((u) & (1ul << 13)) ? 18 : \
599  ((u) & (1ul << 12)) ? 19 : \
600  ((u) & (1ul << 11)) ? 20 : \
601  ((u) & (1ul << 10)) ? 21 : \
602  ((u) & (1ul << 9)) ? 22 : \
603  ((u) & (1ul << 8)) ? 23 : \
604  ((u) & (1ul << 7)) ? 24 : \
605  ((u) & (1ul << 6)) ? 25 : \
606  ((u) & (1ul << 5)) ? 26 : \
607  ((u) & (1ul << 4)) ? 27 : \
608  ((u) & (1ul << 3)) ? 28 : \
609  ((u) & (1ul << 2)) ? 29 : \
610  ((u) & (1ul << 1)) ? 30 : \
611  31)
612 #endif
613 
620 #if (defined __GNUC__) || (defined __CC_ARM)
621 # define ctz(u) ((u) ? __builtin_ctz(u) : 32)
622 #else
623 # define ctz(u) ((u) & (1ul << 0) ? 0 : \
624  (u) & (1ul << 1) ? 1 : \
625  (u) & (1ul << 2) ? 2 : \
626  (u) & (1ul << 3) ? 3 : \
627  (u) & (1ul << 4) ? 4 : \
628  (u) & (1ul << 5) ? 5 : \
629  (u) & (1ul << 6) ? 6 : \
630  (u) & (1ul << 7) ? 7 : \
631  (u) & (1ul << 8) ? 8 : \
632  (u) & (1ul << 9) ? 9 : \
633  (u) & (1ul << 10) ? 10 : \
634  (u) & (1ul << 11) ? 11 : \
635  (u) & (1ul << 12) ? 12 : \
636  (u) & (1ul << 13) ? 13 : \
637  (u) & (1ul << 14) ? 14 : \
638  (u) & (1ul << 15) ? 15 : \
639  (u) & (1ul << 16) ? 16 : \
640  (u) & (1ul << 17) ? 17 : \
641  (u) & (1ul << 18) ? 18 : \
642  (u) & (1ul << 19) ? 19 : \
643  (u) & (1ul << 20) ? 20 : \
644  (u) & (1ul << 21) ? 21 : \
645  (u) & (1ul << 22) ? 22 : \
646  (u) & (1ul << 23) ? 23 : \
647  (u) & (1ul << 24) ? 24 : \
648  (u) & (1ul << 25) ? 25 : \
649  (u) & (1ul << 26) ? 26 : \
650  (u) & (1ul << 27) ? 27 : \
651  (u) & (1ul << 28) ? 28 : \
652  (u) & (1ul << 29) ? 29 : \
653  (u) & (1ul << 30) ? 30 : \
654  (u) & (1ul << 31) ? 31 : \
655  32)
656 #endif
657 
659 
660 
663 
671 #define bit_reverse8(u8) ((U8)(bit_reverse32((U8)(u8)) >> 24))
672 
679 #define bit_reverse16(u16) ((U16)(bit_reverse32((U16)(u16)) >> 16))
680 
687 #define bit_reverse32(u32) __RBIT(u32)
688 
695 #define bit_reverse64(u64) ((U64)(((U64)bit_reverse32((U64)(u64) >> 32)) |\
696  ((U64)bit_reverse32((U64)(u64)) << 32)))
697 
699 
700 
703 
712 #define Test_align(val, n ) (!Tst_bits( val, (n) - 1 ) )
713 
721 #define Get_align( val, n ) ( Rd_bits( val, (n) - 1 ) )
722 
731 #define Set_align(lval, n, alg) ( Wr_bits(lval, (n) - 1, alg) )
732 
740 #define Align_up( val, n ) (((val) + ((n) - 1)) & ~((n) - 1))
741 
749 #define Align_down(val, n ) ( (val) & ~((n) - 1))
750 
752 
753 
765 
775 #define Abs(a) (((a) < 0 ) ? -(a) : (a))
776 
786 #define Min(a, b) (((a) < (b)) ? (a) : (b))
787 
797 #define Max(a, b) (((a) > (b)) ? (a) : (b))
798 
799 #if !defined(__cplusplus)
800 
801 // abs() is already defined by stdlib.h
802 
812 #define min(a, b) Min(a, b)
813 
823 #define max(a, b) Max(a, b)
824 
825 #endif
826 
828 
829 
841 #define Long_call(addr) ((*(void (*)(void))(addr))())
842 
843 
847 #define MSB(u16) (((U8 *)&(u16))[1])
849 #define LSB(u16) (((U8 *)&(u16))[0])
850 
851 #define MSH(u32) (((U16 *)&(u32))[1])
852 #define LSH(u32) (((U16 *)&(u32))[0])
853 #define MSB0W(u32) (((U8 *)&(u32))[3])
854 #define MSB1W(u32) (((U8 *)&(u32))[2])
855 #define MSB2W(u32) (((U8 *)&(u32))[1])
856 #define MSB3W(u32) (((U8 *)&(u32))[0])
857 #define LSB3W(u32) MSB0W(u32)
858 #define LSB2W(u32) MSB1W(u32)
859 #define LSB1W(u32) MSB2W(u32)
860 #define LSB0W(u32) MSB3W(u32)
861 
862 #define MSW(u64) (((U32 *)&(u64))[1])
863 #define LSW(u64) (((U32 *)&(u64))[0])
864 #define MSH0(u64) (((U16 *)&(u64))[3])
865 #define MSH1(u64) (((U16 *)&(u64))[2])
866 #define MSH2(u64) (((U16 *)&(u64))[1])
867 #define MSH3(u64) (((U16 *)&(u64))[0])
868 #define LSH3(u64) MSH0(u64)
869 #define LSH2(u64) MSH1(u64)
870 #define LSH1(u64) MSH2(u64)
871 #define LSH0(u64) MSH3(u64)
872 #define MSB0D(u64) (((U8 *)&(u64))[7])
873 #define MSB1D(u64) (((U8 *)&(u64))[6])
874 #define MSB2D(u64) (((U8 *)&(u64))[5])
875 #define MSB3D(u64) (((U8 *)&(u64))[4])
876 #define MSB4D(u64) (((U8 *)&(u64))[3])
877 #define MSB5D(u64) (((U8 *)&(u64))[2])
878 #define MSB6D(u64) (((U8 *)&(u64))[1])
879 #define MSB7D(u64) (((U8 *)&(u64))[0])
880 #define LSB7D(u64) MSB0D(u64)
881 #define LSB6D(u64) MSB1D(u64)
882 #define LSB5D(u64) MSB2D(u64)
883 #define LSB4D(u64) MSB3D(u64)
884 #define LSB3D(u64) MSB4D(u64)
885 #define LSB2D(u64) MSB5D(u64)
886 #define LSB1D(u64) MSB6D(u64)
887 #define LSB0D(u64) MSB7D(u64)
888 
889 #define BE16(x) swap16(x)
890 #define LE16(x) (x)
891 
892 #define le16_to_cpu(x) (x)
893 #define cpu_to_le16(x) (x)
894 #define LE16_TO_CPU(x) (x)
895 #define CPU_TO_LE16(x) (x)
896 
897 #define be16_to_cpu(x) swap16(x)
898 #define cpu_to_be16(x) swap16(x)
899 #define BE16_TO_CPU(x) swap16(x)
900 #define CPU_TO_BE16(x) swap16(x)
901 
902 #define le32_to_cpu(x) (x)
903 #define cpu_to_le32(x) (x)
904 #define LE32_TO_CPU(x) (x)
905 #define CPU_TO_LE32(x) (x)
906 
907 #define be32_to_cpu(x) swap32(x)
908 #define cpu_to_be32(x) swap32(x)
909 #define BE32_TO_CPU(x) swap32(x)
910 #define CPU_TO_BE32(x) swap32(x)
911 
913 
924 
934 #define Swap16(u16) ((U16)(((U16)(u16) >> 8) |\
935  ((U16)(u16) << 8)))
936 
945 #define Swap32(u32) ((U32)(((U32)Swap16((U32)(u32) >> 16)) |\
946  ((U32)Swap16((U32)(u32)) << 16)))
947 
956 #define Swap64(u64) ((U64)(((U64)Swap32((U64)(u64) >> 32)) |\
957  ((U64)Swap32((U64)(u64)) << 32)))
958 
967 #define swap16(u16) Swap16(u16)
968 
977 #if (defined __GNUC__)
978 # define swap32(u32) ((U32)__builtin_bswap32((U32)(u32)))
979 #else
980 # define swap32(u32) Swap32(u32)
981 #endif
982 
991 #if (defined __GNUC__)
992 # define swap64(u64) ((U64)__builtin_bswap64((U64)(u64)))
993 #else
994 # define swap64(u64) ((U64)(((U64)swap32((U64)(u64) >> 32)) |\
995  ((U64)swap32((U64)(u64)) << 32)))
996 #endif
997 
999 
1000 
1003 
1005 #define _GLOBEXT_ extern
1006 #define _CONST_TYPE_ const
1007 #define _MEM_TYPE_SLOW_
1008 #define _MEM_TYPE_MEDFAST_
1009 #define _MEM_TYPE_FAST_
1010 
1011 typedef U8 Byte;
1012 
1013 #define memcmp_ram2ram memcmp
1014 #define memcmp_code2ram memcmp
1015 #define memcpy_ram2ram memcpy
1016 #define memcpy_code2ram memcpy
1017 
1018 #define LSB0(u32) LSB0W(u32)
1019 #define LSB1(u32) LSB1W(u32)
1020 #define LSB2(u32) LSB2W(u32)
1021 #define LSB3(u32) LSB3W(u32)
1022 #define MSB3(u32) MSB3W(u32)
1023 #define MSB2(u32) MSB2W(u32)
1024 #define MSB1(u32) MSB1W(u32)
1025 #define MSB0(u32) MSB0W(u32)
1026 
1027 
1038 #define div_ceil(a, b) (((a) + (b) - 1) / (b))
1039 
1040 #endif // #ifndef __ASSEMBLY__
1041 
1042 
1043 #if defined(__ICCARM__)
1044 #define SHORTENUM __packed
1045 #elif defined(__GNUC__)
1046 #define SHORTENUM __attribute__((packed))
1047 #endif
1048 
1049 /* No operation */
1050 #if defined(__ICCARM__)
1051 #define nop() __no_operation()
1052 #elif defined(__GNUC__)
1053 #define nop() (__NOP())
1054 #endif
1055 
1056 #define FLASH_DECLARE(x) const x
1057 #define FLASH_EXTERN(x) extern const x
1058 #define PGM_READ_BYTE(x) *(x)
1059 #define PGM_READ_WORD(x) *(x)
1060 #define PGM_READ_DWORD(x) *(x)
1061 #define MEMCPY_ENDIAN memcpy
1062 #define PGM_READ_BLOCK(dst, src, len) memcpy((dst), (src), (len))
1063 
1064 /*Defines the Flash Storage for the request and response of MAC*/
1065 #define CMD_ID_OCTET (0)
1066 
1067 /* Converting of values from CPU endian to little endian. */
1068 #define CPU_ENDIAN_TO_LE16(x) (x)
1069 #define CPU_ENDIAN_TO_LE32(x) (x)
1070 #define CPU_ENDIAN_TO_LE64(x) (x)
1071 
1072 /* Converting of values from little endian to CPU endian. */
1073 #define LE16_TO_CPU_ENDIAN(x) (x)
1074 #define LE32_TO_CPU_ENDIAN(x) (x)
1075 #define LE64_TO_CPU_ENDIAN(x) (x)
1076 
1077 /* Converting of constants from little endian to CPU endian. */
1078 #define CLE16_TO_CPU_ENDIAN(x) (x)
1079 #define CLE32_TO_CPU_ENDIAN(x) (x)
1080 #define CLE64_TO_CPU_ENDIAN(x) (x)
1081 
1082 /* Converting of constants from CPU endian to little endian. */
1083 #define CCPU_ENDIAN_TO_LE16(x) (x)
1084 #define CCPU_ENDIAN_TO_LE32(x) (x)
1085 #define CCPU_ENDIAN_TO_LE64(x) (x)
1086 
1087 #define ADDR_COPY_DST_SRC_16(dst, src) ((dst) = (src))
1088 #define ADDR_COPY_DST_SRC_64(dst, src) ((dst) = (src))
1089 
1097 static inline void convert_64_bit_to_byte_array(uint64_t value, uint8_t *data)
1098 {
1099  uint8_t val_index = 0;
1100 
1101  while (val_index < 8)
1102  {
1103  data[val_index++] = value & 0xFF;
1104  value = value >> 8;
1105  }
1106 }
1107 
1115 static inline void convert_16_bit_to_byte_array(uint16_t value, uint8_t *data)
1116 {
1117  data[0] = value & 0xFF;
1118  data[1] = (value >> 8) & 0xFF;
1119 }
1120 
1121 /* Converts a 16-Bit value into a 2 Byte array */
1122 static inline void convert_spec_16_bit_to_byte_array(uint16_t value, uint8_t *data)
1123 {
1124  data[0] = value & 0xFF;
1125  data[1] = (value >> 8) & 0xFF;
1126 }
1127 
1128 /* Converts a 16-Bit value into a 2 Byte array */
1129 static inline void convert_16_bit_to_byte_address(uint16_t value, uint8_t *data)
1130 {
1131  data[0] = value & 0xFF;
1132  data[1] = (value >> 8) & 0xFF;
1133 }
1134 
1135 /*
1136  * @brief Converts a 2 Byte array into a 16-Bit value
1137  *
1138  * @param data Specifies the pointer to the 2 Byte array
1139  *
1140  * @return 16-Bit value
1141  * @ingroup apiPalApi
1142  */
1143 static inline uint16_t convert_byte_array_to_16_bit(uint8_t *data)
1144 {
1145  return (data[0] | ((uint16_t)data[1] << 8));
1146 }
1147 
1148 /* Converts a 8 Byte array into a 32-Bit value */
1149 static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data)
1150 {
1151  union
1152  {
1153  uint32_t u32;
1154  uint8_t u8[8];
1155  }long_addr;
1156  uint8_t index;
1157  for (index = 0; index < 4; index++)
1158  {
1159  long_addr.u8[index] = *data++;
1160  }
1161  return long_addr.u32;
1162 }
1163 
1172 static inline uint64_t convert_byte_array_to_64_bit(uint8_t *data)
1173 {
1174  union
1175  {
1176  uint64_t u64;
1177  uint8_t u8[8];
1178  } long_addr;
1179 
1180  uint8_t val_index;
1181 
1182  for (val_index = 0; val_index < 8; val_index++)
1183  {
1184  long_addr.u8[val_index] = *data++;
1185  }
1186 
1187  return long_addr.u64;
1188 }
1193 #endif /* UTILS_COMPILER_H */
int8_t S8
8-bit signed integer.
Definition: compiler.h:246
const volatile U64 * u64ptr
Definition: compiler.h:404
uint64_t U64
64-bit unsigned integer.
Definition: compiler.h:257
volatile U64 * u64ptr
Definition: compiler.h:326
const S8 * s8ptr
Definition: compiler.h:344
Union of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers.
Definition: compiler.h:336
volatile S16 * s16ptr
Definition: compiler.h:329
const U8 * u8ptr
Definition: compiler.h:345
U16 * u16ptr
Definition: compiler.h:369
uint16_t be16_t
Definition: compiler.h:251
const U16 * u16ptr
Definition: compiler.h:395
S64 * s64ptr
Definition: compiler.h:364
Union of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers. ...
Definition: compiler.h:349
volatile U16 * u16ptr
Definition: compiler.h:382
const S16 * s16ptr
Definition: compiler.h:342
const volatile S16 * s16ptr
Definition: compiler.h:355
U32 * u32ptr
Definition: compiler.h:367
U32 u32
Definition: compiler.h:289
uint16_t U16
16-bit unsigned integer.
Definition: compiler.h:249
U64 * u64ptr
Definition: compiler.h:365
S8 * s8ptr
Definition: compiler.h:318
const S8 * s8ptr
Definition: compiler.h:396
U8 Status_t
Definition: compiler.h:268
volatile S16 * s16ptr
Definition: compiler.h:381
const U64 * u64ptr
Definition: compiler.h:339
GeneratorWrapper< T > value(T &&value)
Definition: catch.hpp:3589
const volatile S32 * s32ptr
Definition: compiler.h:405
volatile U32 * u32ptr
Definition: compiler.h:328
const volatile S8 * s8ptr
Definition: compiler.h:357
double F64
64-bit floating-point number.
Definition: compiler.h:259
uint32_t le32_t
Definition: compiler.h:254
volatile S64 * s64ptr
Definition: compiler.h:325
U8 * u8ptr
Definition: compiler.h:319
const volatile U8 * u8ptr
Definition: compiler.h:358
const volatile U8 * u8ptr
Definition: compiler.h:410
const U32 * u32ptr
Definition: compiler.h:393
U64 u64
Definition: compiler.h:300
static uint16_t convert_byte_array_to_16_bit(uint8_t *data)
Definition: compiler.h:1143
const volatile U64 * u64ptr
Definition: compiler.h:352
int32_t S32
32-bit signed integer.
Definition: compiler.h:252
Structure of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers.
Definition: compiler.h:375
volatile U32 * u32ptr
Definition: compiler.h:380
const volatile U16 * u16ptr
Definition: compiler.h:356
const U8 * u8ptr
Definition: compiler.h:397
Atmel part identification macros.
uint32_t be32_t
Definition: compiler.h:255
float F32
32-bit floating-point number.
Definition: compiler.h:258
16-bit union.
Definition: compiler.h:277
const volatile U16 * u16ptr
Definition: compiler.h:408
volatile U64 * u64ptr
Definition: compiler.h:378
signed int S32
const volatile S8 * s8ptr
Definition: compiler.h:409
const U16 * u16ptr
Definition: compiler.h:343
uint32_t U32
32-bit unsigned integer.
Definition: compiler.h:253
32-bit union.
Definition: compiler.h:286
S16 s16
Definition: compiler.h:279
S32 s32
Definition: compiler.h:288
64-bit union.
Definition: compiler.h:297
const volatile S32 * s32ptr
Definition: compiler.h:353
const volatile S64 * s64ptr
Definition: compiler.h:403
Structure of pointers to 64-, 32-, 16- and 8-bit unsigned integers.
Definition: compiler.h:362
const U32 * u32ptr
Definition: compiler.h:341
static void convert_16_bit_to_byte_array(uint16_t value, uint8_t *data)
Converts a 16-Bit value into a 2 Byte array.
Definition: compiler.h:1115
static void convert_64_bit_to_byte_array(uint64_t value, uint8_t *data)
Converts a 64-Bit value into a 8 Byte array.
Definition: compiler.h:1097
volatile U16 * u16ptr
Definition: compiler.h:330
const U64 * u64ptr
Definition: compiler.h:391
Union of pointers to 64-, 32-, 16- and 8-bit unsigned integers.
Definition: compiler.h:310
uint16_t le16_t
Definition: compiler.h:250
volatile U8 * u8ptr
Definition: compiler.h:384
Global interrupt management for 8- and 32-bit AVR.
USBInterfaceDescriptor data
Union of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers.
Definition: compiler.h:323
volatile S32 * s32ptr
Definition: compiler.h:379
static uint32_t convert_byte_array_to_32_bit(uint8_t *data)
Definition: compiler.h:1149
U16 u16
Definition: compiler.h:280
unsigned short U16
uint32_t iram_size_t
Definition: compiler.h:260
unsigned char bool
Boolean.
Definition: compiler.h:243
Preprocessor utils.
volatile S8 * s8ptr
Definition: compiler.h:383
const volatile U32 * u32ptr
Definition: compiler.h:354
unsigned long long U64
static void convert_16_bit_to_byte_address(uint16_t value, uint8_t *data)
Definition: compiler.h:1129
uint8_t U8
8-bit unsigned integer.
Definition: compiler.h:247
volatile U8 * u8ptr
Definition: compiler.h:332
volatile S8 * s8ptr
Definition: compiler.h:331
static uint64_t convert_byte_array_to_64_bit(uint8_t *data)
Converts a 8 Byte array into a 64-Bit value.
Definition: compiler.h:1172
const S32 * s32ptr
Definition: compiler.h:392
int16_t S16
16-bit signed integer.
Definition: compiler.h:248
U8 Byte
8-bit unsigned integer.
Definition: compiler.h:1011
S16 * s16ptr
Definition: compiler.h:368
Structure of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers.
Definition: compiler.h:388
const S32 * s32ptr
Definition: compiler.h:340
S8 * s8ptr
Definition: compiler.h:370
U64 * u64ptr
Definition: compiler.h:313
static void convert_spec_16_bit_to_byte_array(uint16_t value, uint8_t *data)
Definition: compiler.h:1122
U8 * u8ptr
Definition: compiler.h:371
Structure of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers.
Definition: compiler.h:401
bool Status_bool_t
Boolean status.
Definition: compiler.h:267
S32 * s32ptr
Definition: compiler.h:366
S64 s64
Definition: compiler.h:299
volatile S32 * s32ptr
Definition: compiler.h:327
const volatile U32 * u32ptr
Definition: compiler.h:406
S16 * s16ptr
Definition: compiler.h:316
const volatile S64 * s64ptr
Definition: compiler.h:351
const S16 * s16ptr
Definition: compiler.h:394
U16 * u16ptr
Definition: compiler.h:317
U32 * u32ptr
Definition: compiler.h:315
unsigned int U32
S64 * s64ptr
Definition: compiler.h:312
unsigned char Bool
Boolean.
Definition: compiler.h:240
S32 * s32ptr
Definition: compiler.h:314
volatile S64 * s64ptr
Definition: compiler.h:377
const S64 * s64ptr
Definition: compiler.h:338
const volatile S16 * s16ptr
Definition: compiler.h:407
int64_t S64
64-bit signed integer.
Definition: compiler.h:256
const S64 * s64ptr
Definition: compiler.h:390


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57