eRPC API Reference  Rev. 1.12.0
NXP Semiconductors
erpc_endianness_agnostic_example.h
1 /*
2  * This is example file for endianness agnostic communication based on byteswap.h.
3  * Other approach can be done with htons(), htonl(), ntohs(), ntohl() and such.
4  */
5 
6 #ifndef _ERPC_ENDIANNESS_AGNOSTIC_EXAMPLE_H_
7 #define _ERPC_ENDIANNESS_AGNOSTIC_EXAMPLE_H_
8 
9 #if ERPC_PROCESSOR_ENDIANNESS_LITTLE != ERPC_COMMUNICATION_LITTLE
10 #include <byteswap.h>
11 
12 #define ERPC_WRITE_AGNOSTIC_16(value) (value) = __bswap_16(value);
13 #define ERPC_WRITE_AGNOSTIC_32(value) (value) = __bswap_32(value);
14 #define ERPC_WRITE_AGNOSTIC_64(value) (value) = __bswap_64(value);
15 
16 #define ERPC_READ_AGNOSTIC_16(value) (value) = __bswap_16(value);
17 #define ERPC_READ_AGNOSTIC_32(value) (value) = __bswap_32(value);
18 #define ERPC_READ_AGNOSTIC_64(value) (value) = __bswap_64(value);
19 
20 #if ERPC_POINTER_SIZE_16
21 #define ERPC_WRITE_AGNOSTIC_PTR(value) ERPC_WRITE_AGNOSTIC_16(value)
22 #define ERPC_READ_AGNOSTIC_PTR(value) ERPC_READ_AGNOSTIC_16(value)
23 #elif ERPC_POINTER_SIZE_32
24 #define ERPC_WRITE_AGNOSTIC_PTR(value) ERPC_WRITE_AGNOSTIC_32(value)
25 #define ERPC_READ_AGNOSTIC_PTR(value) ERPC_READ_AGNOSTIC_32(value)
26 #elif ERPC_POINTER_SIZE_64
27 #define ERPC_WRITE_AGNOSTIC_PTR(value) ERPC_WRITE_AGNOSTIC_64(value)
28 #define ERPC_READ_AGNOSTIC_PTR(value) ERPC_READ_AGNOSTIC_64(value)
29 #else
30 #error unknown pointer size
31 #endif
32 
33 #else
34 
35 #define ERPC_WRITE_AGNOSTIC_16(value)
36 #define ERPC_WRITE_AGNOSTIC_32(value)
37 #define ERPC_WRITE_AGNOSTIC_64(value)
38 #define ERPC_WRITE_AGNOSTIC_PTR(value)
39 
40 #define ERPC_READ_AGNOSTIC_16(value)
41 #define ERPC_READ_AGNOSTIC_32(value)
42 #define ERPC_READ_AGNOSTIC_64(value)
43 #define ERPC_READ_AGNOSTIC_PTR(value)
44 #endif
45 
46 #define ERPC_WRITE_AGNOSTIC_FLOAT(value) erpc_assert(0);
47 #define ERPC_WRITE_AGNOSTIC_DOUBLE(value) erpc_assert(0);
48 #define ERPC_READ_AGNOSTIC_FLOAT(value) erpc_assert(0);
49 #define ERPC_READ_AGNOSTIC_DOUBLE(value) erpc_assert(0);
50 
51 #endif