Robotics Library  0.6.2
endian.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef _RL_HAL_ENDIAN_H_
28 #define _RL_HAL_ENDIAN_H_
29 
30 #include "types.h"
31 
32 namespace rl
33 {
34  namespace hal
35  {
36  uint32_t bigEndianDoubleWord(const uint16_t& highWord, const uint16_t& lowWord);
37 
38  void bigEndianToHostEndian(uint16_t& word);
39 
40  void bigEndianToHostEndian(uint32_t& doubleWord);
41 
42  uint16_t bigEndianWord(const uint8_t& highByte, const uint8_t& lowByte);
43 
44  uint8_t highByteFromBigEndian(const uint16_t& word);
45 
46  inline uint8_t highByteFromHostEndian(const uint16_t& word)
47  {
48  return (word >> 8);
49  }
50 
51  uint8_t highByteFromLittleEndian(const uint16_t& word);
52 
53  uint16_t highWordFromBigEndian(const uint32_t& doubleWord);
54 
55  inline uint16_t highWordFromHostEndian(const uint32_t& doubleWord)
56  {
57  return (doubleWord >> 16);
58  }
59 
60  uint16_t highWordFromLittleEndian(const uint32_t& doubleWord);
61 
62  inline uint32_t hostEndianDoubleWord(const uint16_t& highWord, const uint16_t& lowWord)
63  {
64  return (highWord << 16) | lowWord;
65  }
66 
67  void hostEndianToBigEndian(uint16_t& word);
68 
69  void hostEndianToBigEndian(uint32_t& doubleWord);
70 
71  void hostEndianToLittleEndian(uint16_t& word);
72 
73  void hostEndianToLittleEndian(uint32_t& doubleWord);
74 
75  inline uint16_t hostEndianWord(const uint8_t& highByte, const uint8_t& lowByte)
76  {
77  return (highByte << 8) | lowByte;
78  }
79 
80  uint32_t littleEndianDoubleWord(const uint16_t& highWord, const uint16_t& lowWord);
81 
82  void littleEndianToHostEndian(uint16_t& word);
83 
84  void littleEndianToHostEndian(uint32_t& doubleWord);
85 
86  uint16_t littleEndianWord(const uint8_t& highByte, const uint8_t& lowByte);
87 
88  uint8_t lowByteFromBigEndian(const uint16_t& word);
89 
90  inline uint8_t lowByteFromHostEndian(const uint16_t& word)
91  {
92  return (word & 0xFF);
93  }
94 
95  uint8_t lowByteFromLittleEndian(const uint16_t& word);
96 
97  uint16_t lowWordFromBigEndian(const uint32_t& doubleWord);
98 
99  inline uint16_t lowWordFromHostEndian(const uint32_t& doubleWord)
100  {
101  return (doubleWord & 0xFFFF);
102  }
103 
104  uint16_t lowWordFromLittleEndian(const uint32_t& doubleWord);
105 
106  inline void swapByteOrder(uint16_t& word)
107  {
108  word = (word >> 8) | (word << 8); // TODO
109  }
110 
111  inline void swapByteOrder(uint32_t& doubleWord)
112  {
113  doubleWord = ((doubleWord & 0x000000FF) << 24) | ((doubleWord & 0x0000FF00) << 8) | ((doubleWord & 0x00FF0000) >> 8) | ((doubleWord & 0xFF000000) >> 24); // TODO
114  }
115  }
116 }
117 
118 #endif // _RL_HAL_ENDIAN_H_
rl::hal::bigEndianDoubleWord
uint32_t bigEndianDoubleWord(const uint16_t &highWord, const uint16_t &lowWord)
Definition: endian.cpp:37
rl::hal::lowByteFromBigEndian
uint8_t lowByteFromBigEndian(const uint16_t &word)
Definition: endian.cpp:165
rl::hal::highWordFromBigEndian
uint16_t highWordFromBigEndian(const uint32_t &doubleWord)
Definition: endian.cpp:87
types.h
rl::hal::lowWordFromLittleEndian
uint16_t lowWordFromLittleEndian(const uint32_t &doubleWord)
Definition: endian.cpp:192
rl::hal::bigEndianWord
uint16_t bigEndianWord(const uint8_t &highByte, const uint8_t &lowByte)
Definition: endian.cpp:60
rl::hal::littleEndianDoubleWord
uint32_t littleEndianDoubleWord(const uint16_t &highWord, const uint16_t &lowWord)
Definition: endian.cpp:133
rl::hal::hostEndianToLittleEndian
void hostEndianToLittleEndian(uint16_t &word)
Definition: endian.cpp:119
rl::hal::lowByteFromLittleEndian
uint8_t lowByteFromLittleEndian(const uint16_t &word)
Definition: endian.cpp:174
rl::hal::hostEndianToBigEndian
void hostEndianToBigEndian(uint16_t &word)
Definition: endian.cpp:105
rl::hal::highByteFromHostEndian
uint8_t highByteFromHostEndian(const uint16_t &word)
Definition: endian.h:46
rl::hal::swapByteOrder
void swapByteOrder(uint16_t &word)
Definition: endian.h:106
rl::hal::highByteFromLittleEndian
uint8_t highByteFromLittleEndian(const uint16_t &word)
Definition: endian.cpp:78
rl::hal::highWordFromLittleEndian
uint16_t highWordFromLittleEndian(const uint32_t &doubleWord)
Definition: endian.cpp:96
rl::hal::littleEndianWord
uint16_t littleEndianWord(const uint8_t &highByte, const uint8_t &lowByte)
Definition: endian.cpp:156
rl::hal::highByteFromBigEndian
uint8_t highByteFromBigEndian(const uint16_t &word)
Definition: endian.cpp:69
rl::hal::highWordFromHostEndian
uint16_t highWordFromHostEndian(const uint32_t &doubleWord)
Definition: endian.h:55
rl::hal::hostEndianWord
uint16_t hostEndianWord(const uint8_t &highByte, const uint8_t &lowByte)
Definition: endian.h:75
rl::hal::lowByteFromHostEndian
uint8_t lowByteFromHostEndian(const uint16_t &word)
Definition: endian.h:90
rl::hal::littleEndianToHostEndian
void littleEndianToHostEndian(uint16_t &word)
Definition: endian.cpp:142
rl::hal::bigEndianToHostEndian
void bigEndianToHostEndian(uint16_t &word)
Definition: endian.cpp:46
rl::hal::lowWordFromBigEndian
uint16_t lowWordFromBigEndian(const uint32_t &doubleWord)
Definition: endian.cpp:183
rl::hal::lowWordFromHostEndian
uint16_t lowWordFromHostEndian(const uint32_t &doubleWord)
Definition: endian.h:99
rl::hal::hostEndianDoubleWord
uint32_t hostEndianDoubleWord(const uint16_t &highWord, const uint16_t &lowWord)
Definition: endian.h:62
rl
Definition: Ati.cpp:35