Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 }
uint16_t foo
Definition: main_demo5.c:58
Arch independent mcu ( Micro Controller Unit ) utilities.
#define MyByteSwap16(n)
Definition: test_bswap.c:6
#define MyByteSwap32(n)
Definition: test_bswap.c:10
int main(void)
Definition: test_bswap.c:33
#define MyByteSwap16_1(in, out)
Definition: test_bswap.c:24
#define MyByteSwap32_1(in, out)
Definition: test_bswap.c:16
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
float b
Definition: wedgebug.c:202