Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
test_bswap.c
Go to the documentation of this file.
1 
2 #include <inttypes.h>
3 #include "mcu.h"
4 
5 
6 #define MyByteSwap16(n) \
7  ( ((((uint16_t) n) << 8) & 0xFF00) | \
8  ((((uint16_t) n) >> 8) & 0x00FF) )
9 
10 #define MyByteSwap32(n) \
11  ( ((((uint32_t) n) << 24) & 0xFF000000) | \
12  ((((uint32_t) n) << 8) & 0x00FF0000) | \
13  ((((uint32_t) n) >> 8) & 0x0000FF00) | \
14  ((((uint32_t) n) >> 24) & 0x000000FF) )
15 
16 #define MyByteSwap32_1(in, out) \
17  asm volatile ( \
18  "rev %0, %1\n\t" \
19  : "=r" (out) \
20  : "r"(in) \
21  );
22 
23 
24 #define MyByteSwap16_1(in, out) \
25  asm volatile ( \
26  "rev16 %0, %1\n\t" \
27  : "=r" (out) \
28  : "r"(in) \
29  );
30 
31 
32 
33 int main(void)
34 {
35 
36  // uint32_t foo = 0;
37  // uint32_t bar = __builtin_bswap32(*(uint32_t*)&foo);
38 
39  // uint16_t foo = 12345;
40  // uint16_t bar = foo >> 8 | foo << 8;
41 
42  // uint16_t foo = 12345;
43  // uint16_t bar = ByteSwap(foo);
44 
45  uint16_t foo = 12345;
46  uint16_t bar = MyByteSwap16(foo);
47  MyByteSwap16_1(foo, bar);
48  bar = __REV16(foo);
49 
50 
51 
52  uint32_t a = 23456;
53  uint32_t b = MyByteSwap32(a);
54  MyByteSwap32_1(a, b);
55 
56  return 0;
57 }
unsigned short uint16_t
Definition: types.h:16
#define MyByteSwap32(n)
Definition: test_bswap.c:10
#define MyByteSwap16_1(in, out)
Definition: test_bswap.c:24
unsigned long uint32_t
Definition: types.h:18
uint16_t foo
Definition: main_demo5.c:59
int main(void)
Definition: test_bswap.c:33
#define MyByteSwap32_1(in, out)
Definition: test_bswap.c:16
Arch independent mcu ( Micro Controller Unit ) utilities.
#define MyByteSwap16(n)
Definition: test_bswap.c:6