blob: 16262cd98a72db68b63311b56a25ed94ba33384f [file] [log] [blame]
nxf24591c1cbeab2018-02-21 17:32:26 +05301/******************************************************************************
2 *
3 * Copyright (C) 2012-2014 Broadcom 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/******************************************************************************
19 *
20 * The original Work has been changed by NXP.
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 *
34 * Copyright 2018 NXP
35 *
36 ******************************************************************************/
37#ifndef NFC_TYPES_H
38#define NFC_TYPES_H
39#if (NXP_EXTNS == TRUE)
40#include "Nxp_Features.h"
41#endif
42/****************************************************************************
43** NFC_HDR header definition for NFC messages
44*****************************************************************************/
45typedef struct {
46 uint16_t event;
47 uint16_t len;
48 uint16_t offset;
49 uint16_t layer_specific;
50} NFC_HDR;
51#define NFC_HDR_SIZE (sizeof(NFC_HDR))
52
53/* Mask for NFC_HDR event field */
54#define NFC_EVT_MASK 0xFF00
55
56/****************************************************************************
57** NFC_HAL_TASK definitions
58*****************************************************************************/
59
60/* NCI message for hci persistency data */
61#define NFC_HAL_EVT_HCI 0x0400
62
63/* NCI message for sending to host stack */
64#define NFC_EVT_TO_NFC_NCI 0x4000
65
66/*****************************************************************************
67** Macros to get and put bytes to and from a stream (Little Endian format).
68*****************************************************************************/
69
70#define UINT32_TO_STREAM(p, u32) \
71 { \
72 *(p)++ = (uint8_t)(u32); \
73 *(p)++ = (uint8_t)((u32) >> 8); \
74 *(p)++ = (uint8_t)((u32) >> 16); \
75 *(p)++ = (uint8_t)((u32) >> 24); \
76 }
77#define UINT16_TO_STREAM(p, u16) \
78 { \
79 *(p)++ = (uint8_t)(u16); \
80 *(p)++ = (uint8_t)((u16) >> 8); \
81 }
82#define UINT8_TO_STREAM(p, u8) \
83 { *(p)++ = (uint8_t)(u8); }
84#define INT8_TO_STREAM(p, u8) \
85 { *(p)++ = (int8_t)(u8); }
86#define ARRAY8_TO_STREAM(p, a) \
87 { \
88 int ijk; \
89 for (ijk = 0; ijk < 8; ijk++) *(p)++ = (uint8_t)(a)[7 - ijk]; \
90 }
91#define ARRAY_TO_STREAM(p, a, len) \
92 { \
93 int ijk; \
94 for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \
95 }
96#define STREAM_TO_UINT8(u8, p) \
97 { \
98 (u8) = (uint8_t)(*(p)); \
99 (p) += 1; \
100 }
101#define STREAM_TO_UINT16(u16, p) \
102 { \
103 (u16) = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \
104 (p) += 2; \
105 }
106#define STREAM_TO_UINT32(u32, p) \
107 { \
108 (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + \
109 ((((uint32_t)(*((p) + 2)))) << 16) + \
110 ((((uint32_t)(*((p) + 3)))) << 24)); \
111 (p) += 4; \
112 }
113#define STREAM_TO_ARRAY8(a, p) \
114 { \
115 int ijk; \
116 uint8_t* _pa = (uint8_t*)(a) + 7; \
117 for (ijk = 0; ijk < 8; ijk++) *_pa-- = *(p)++; \
118 }
119#define STREAM_TO_ARRAY(a, p, len) \
120 { \
121 int ijk; \
122 for (ijk = 0; ijk < (len); ijk++) ((uint8_t*)(a))[ijk] = *(p)++; \
123 }
124
125/*****************************************************************************
126** Macros to get and put bytes to and from a stream (Big Endian format)
127*****************************************************************************/
128
129#define UINT32_TO_BE_STREAM(p, u32) \
130 { \
131 *(p)++ = (uint8_t)((u32) >> 24); \
132 *(p)++ = (uint8_t)((u32) >> 16); \
133 *(p)++ = (uint8_t)((u32) >> 8); \
134 *(p)++ = (uint8_t)(u32); \
135 }
136#define UINT24_TO_BE_STREAM(p, u24) \
137 { \
138 *(p)++ = (uint8_t)((u24) >> 16); \
139 *(p)++ = (uint8_t)((u24) >> 8); \
140 *(p)++ = (uint8_t)(u24); \
141 }
142#define UINT16_TO_BE_STREAM(p, u16) \
143 { \
144 *(p)++ = (uint8_t)((u16) >> 8); \
145 *(p)++ = (uint8_t)(u16); \
146 }
147#define UINT8_TO_BE_STREAM(p, u8) \
148 { *(p)++ = (uint8_t)(u8); }
149#define ARRAY_TO_BE_STREAM(p, a, len) \
150 { \
151 int ijk; \
152 for (ijk = 0; ijk < (len); ijk++) *(p)++ = (uint8_t)(a)[ijk]; \
153 }
154
155#define BE_STREAM_TO_UINT8(u8, p) \
156 { \
157 (u8) = (uint8_t)(*(p)); \
158 (p) += 1; \
159 }
160#define BE_STREAM_TO_UINT16(u16, p) \
161 { \
162 (u16) = (uint16_t)(((uint16_t)(*(p)) << 8) + (uint16_t)(*((p) + 1))); \
163 (p) += 2; \
164 }
165#define BE_STREAM_TO_UINT32(u32, p) \
166 { \
167 (u32) = ((uint32_t)(*((p) + 3)) + ((uint32_t)(*((p) + 2)) << 8) + \
168 ((uint32_t)(*((p) + 1)) << 16) + ((uint32_t)(*(p)) << 24)); \
169 (p) += 4; \
170 }
171
172/*****************************************************************************
173** Macros to get and put bytes to and from a field (Big Endian format).
174** These are the same as to stream, except the pointer is not incremented.
175*****************************************************************************/
176
177#define UINT8_TO_BE_FIELD(p, u8) \
178 { *(uint8_t*)(p) = (uint8_t)(u8); }
179
180#endif /* NFC_TYPES_H */