embkernel
 All Classes Functions Variables Typedefs Groups Pages
LibEndian.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef LIB_ENDIAN_HPP_
7 #define LIB_ENDIAN_HPP_
8 
9 #include "LibCfg.hpp"
10 #include <stdint.h>
11 
12 class LibEndian {
13 public:
14 #if LIB_CFG_LITTLE_ENDIAN
15  inline static uint16_t leToHw(uint16_t value) {
16  return value;
17  }
18  inline static uint32_t leToHw(uint32_t value) {
19  return value;
20  }
21  inline static uint16_t hwToLe(uint16_t value) {
22  return value;
23  }
24  inline static uint32_t hwToLe(uint32_t value) {
25  return value;
26  }
27 
28  static uint16_t beToHw(uint16_t value);
29  static uint32_t beToHw(uint32_t value);
30  static uint16_t hwToBe(uint16_t value);
31  static uint32_t hwToBe(uint32_t value);
32 
33 #else
34  static uint16_t leToHw(uint16_t value);
35  static uint32_t leToHw(uint32_t value);
36  static uint16_t hwToLe(uint16_t value);
37  static uint32_t hwToLe(uint32_t value);
38 
39  inline static uint16_t beToHw(uint16_t value) {
40  return value;
41  }
42  inline static uint32_t beToHw(uint32_t value) {
43  return value;
44  }
45  inline static uint16_t hwToBe(uint16_t value) {
46  return value;
47  }
48  inline static uint32_t hwToBe(uint32_t value) {
49  return value;
50  }
51 
52 #endif
53 
54 };
55 
56 #endif /* LIB_ENDIAN_HPP_ */