• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2018 Realtek Corporation.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #ifndef RTK_COMMON_H
19 #define RTK_COMMON_H
20 
21 #define RTK_UNUSED(x) (void)(x)
22 
23 #define STREAM_TO_UINT16(u16, p)                                \
24   {                                                             \
25     u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \
26     (p) += 2;                                                   \
27   }
28 #define UINT16_TO_STREAM(p, u16)    \
29   {                                 \
30     *(p)++ = (uint8_t)(u16);        \
31     *(p)++ = (uint8_t)((u16) >> 8); \
32   }
33 #define UINT32_TO_STREAM(p, u32)     \
34   {                                  \
35     *(p)++ = (uint8_t)(u32);         \
36     *(p)++ = (uint8_t)((u32) >> 8);  \
37     *(p)++ = (uint8_t)((u32) >> 16); \
38     *(p)++ = (uint8_t)((u32) >> 24); \
39   }
40 #define STREAM_TO_UINT32(u32, p)                                                                                                              \
41   {                                                                                                                                           \
42     u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24)); \
43     (p) += 4;                                                                                                                                 \
44   }
45 #define UINT8_TO_STREAM(p, u8) \
46   {                            \
47     *(p)++ = (uint8_t)(u8);    \
48   }
49 #define STREAM_TO_UINT8(u8, p) \
50   {                            \
51     u8 = (uint8_t)(*(p));      \
52     (p) += 1;                  \
53   }
54 
55 #define STREAM_SKIP_UINT8(p) \
56   do                         \
57   {                          \
58     (p) += 1;                \
59   } while (0)
60 #define STREAM_SKIP_UINT16(p) \
61   do                          \
62   {                           \
63     (p) += 2;                 \
64   } while (0)
65 
66 #endif
67