Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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  // uint32_t foo = 0;
36  // uint32_t bar = __builtin_bswap32(*(uint32_t*)&foo);
37 
38  // uint16_t foo = 12345;
39  // uint16_t bar = foo >> 8 | foo << 8;
40 
41  // uint16_t foo = 12345;
42  // uint16_t bar = ByteSwap(foo);
43 
44  uint16_t foo = 12345;
45  uint16_t bar = MyByteSwap16(foo);
46  MyByteSwap16_1(foo,bar);
47  bar = __REV16(foo);
48 
49 
50 
51  uint32_t a = 23456;
52  uint32_t b = MyByteSwap32(a);
53  MyByteSwap32_1(a,b);
54 
55  return 0;
56 }
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:54
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