Paparazzi UAS
v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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
}
uint16_t
unsigned short uint16_t
Definition:
types.h:16
MyByteSwap32
#define MyByteSwap32(n)
Definition:
test_bswap.c:10
MyByteSwap16_1
#define MyByteSwap16_1(in, out)
Definition:
test_bswap.c:24
uint32_t
unsigned long uint32_t
Definition:
types.h:18
foo
uint16_t foo
Definition:
main_demo5.c:59
inttypes.h
main
int main(void)
Definition:
test_bswap.c:33
MyByteSwap32_1
#define MyByteSwap32_1(in, out)
Definition:
test_bswap.c:16
mcu.h
Arch independent mcu ( Micro Controller Unit ) utilities.
MyByteSwap16
#define MyByteSwap16(n)
Definition:
test_bswap.c:6
sw
airborne
arch
stm32
test_bswap.c
Generated on Wed Aug 28 2019 16:28:55 for Paparazzi UAS by
1.8.8