• 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     do {                                                                                                               \
25         u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8));                                                    \
26         (p) += 2;                                                                                                      \
27     } while (0)
28 #define UINT16_TO_STREAM(p, u16)                                                                                       \
29     do {                                                                                                               \
30         *(p)++ = (uint8_t)(u16);                                                                                       \
31         *(p)++ = (uint8_t)((u16) >> 8);                                                                                \
32     } while (0)
33 #define UINT32_TO_STREAM(p, u32)                                                                                       \
34     do {                                                                                                               \
35         *(p)++ = (uint8_t)(u32);                                                                                       \
36         *(p)++ = (uint8_t)((u32) >> 8);                                                                                \
37         *(p)++ = (uint8_t)((u32) >> 16);                                                                               \
38         *(p)++ = (uint8_t)((u32) >> 24);                                                                               \
39     } while (0)
40 #define STREAM_TO_UINT32(u32, p)                                                                                       \
41     do {                                                                                                               \
42         u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) +                                                \
43         ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24));                                      \
44         (p) += 4;                                                                                                      \
45     } while (0)
46 #define UINT8_TO_STREAM(p, u8)                                                                                         \
47     do {                                                                                                               \
48         *(p)++ = (uint8_t)(u8);                                                                                        \
49     } while (0)
50 #define STREAM_TO_UINT8(u8, p)                                                                                         \
51     do {                                                                                                               \
52         u8 = (uint8_t)(*(p));                                                                                          \
53         (p) += 1;                                                                                                      \
54     } while (0)
55 
56 #define STREAM_SKIP_UINT8(p)                                                                                           \
57     do {                                                                                                               \
58         (p) += 1;                                                                                                      \
59     } while (0)
60 #define STREAM_SKIP_UINT16(p)                                                                                          \
61     do {                                                                                                               \
62         (p) += 2;                                                                                                      \
63     } while (0)
64 
65 #endif
66