1 /*! *********************************************************************************
2 * \defgroup PhyTypes PHY Data Types
3 * @{
4 ********************************************************************************** */
5 /*! *********************************************************************************
6 * Copyright (c) 2015, Freescale Semiconductor, Inc.
7 * Copyright 2016-2024 NXP
8 * All rights reserved.
9 *
10 * \file
11 *
12 * SPDX-License-Identifier: BSD-3-Clause
13 ********************************************************************************** */
14 
15 #ifndef _PHY_TYPES_H
16 #define _PHY_TYPES_H
17 
18 #if defined(__ARMCC_VERSION)
19 #pragma push
20 #pragma anon_unions
21 #elif defined(__GNUC__)
22 #pragma GCC diagnostic push
23 #pragma GCC diagnostic ignored "-Wpedantic"
24 #elif defined(__IAR_SYSTEMS_ICC__)
25 #pragma language=extended
26 #else
27 #error Not supported compiler type
28 #endif
29 
30 /************************************************************************************
31 *************************************************************************************
32 * Include
33 *************************************************************************************
34 ************************************************************************************/
35 #include "EmbeddedTypes.h"
36 
37 /************************************************************************************
38 *************************************************************************************
39 * Public macros
40 *************************************************************************************
41 ************************************************************************************/
42 
43 /*! This define is used to set the number of symbols per octet for the current PHY. */
44 #define gPhySymbolsPerOctet_c     (2u)
45 /*! The duration of the Clear Channel Assessment (in symbols) */
46 #define gCCATime_c                8u
47 /*! RX-to-TX or TX-to-RX maximum turnaround time (in symbols) */
48 #define gPhyTurnaroundTime_c      12u
49 /*! Maximum number of bytes that the PHY can transmit or receive */
50 #define gMaxPHYPacketSize_c       (127u)
51 /*! This define is used to set the duration of the synchronization header [symbols] */
52 #define gPhySHRDuration_c         (10u)
53 /*! This define is used to set the duration of the PHY header (PHR) (in symbols) */
54 #define gPhyPHRDuration_c         (1u * gPhySymbolsPerOctet_c)
55 /*! Number of bytes forming the CRC field */
56 #define gPhyFCSSize_c             (2u)
57 /*! The maximum over-the-air duration of a frame (in symbols) */
58 #define gPhyMaxFrameDuration_c    (gPhySHRDuration_c + (gMaxPHYPacketSize_c + 1) * gPhySymbolsPerOctet_c)
59 /*! The duration of a Back-off period (in symbols) */
60 #define gUnitBackoffPeriod_c      (20u)
61 
62 /*! PHY flag that reflects the state of the RxOnWhenIdle function */
63 #define gPhyFlagRxOnWhenIdle_c  (1u << 0)
64 /*! PHY flag that indicate that an automatic RX sequence is ongoing */
65 #define gPhyFlagIdleRx_c        (1u << 1)
66 /*! PHY flag that reflects the state of the FP bit of the last ACK frame received */
67 #define gPhyFlagRxFP_c          (1u << 2)
68 /*! PHY flag that reflects the state of the FP bit of the last ACK frame transmitted */
69 #define gPhyFlagTxAckFP_c       (1u << 3)
70 /*! If set, a TX operation may be postponed if a packet reception is in progress */
71 #define gPhyFlagDeferTx_c       (1u << 4)
72 /*! PHY flag that indicate that the requested TX has been postponed */
73 #define gPhyFlaqReqPostponed_c  (1u << 5)
74 /*! PHY flag that indicate CSL RX: allow multipurpose frames, send Enh-ACKs */
75 #define gPhyFlagCslRx_c         (1u << 6)
76 /*! PHY flag that indicates FP was set as result of no neighbour table entry found */
77 #define gPhyFlagNbTblRxAckFP_c  (1u << 7)
78 
79 
80 /*! This constant defines the identification value of an invalid timer. */
81 #define gInvalidTimerId_c (0xFF)
82 
83 #define gPhyTimeShift_c   (24)          /* 24bit hw timer */
84 #define gPhyTimeMask_c    (0x00FFFFFF)
85 
86 /* Security defines */
87 #ifndef gSmacUseInlineDecrypt
88 #define gSmacUseInlineDecrypt       (0)
89 #else
90 #define gSmacUseSecurity_c          (1)
91 #endif
92 
93 #ifndef gSmacUseSecurity_c
94 #define gSmacUseSecurity_c         (0)
95 #endif
96 
97 /************************************************************************************
98 *************************************************************************************
99 * Public prototypes
100 *************************************************************************************
101 ************************************************************************************/
102 
103 /************************************************************************************
104 *************************************************************************************
105 * Public type definitions
106 *************************************************************************************
107 ************************************************************************************/
108 
109 /*! This type enumerates all the possible statuses of primitives that require passing a status to the MAC Layer. */
110 typedef enum
111 {
112     gPhyChannelBusy_c          = 0x00,    /*!< The CCA attempt has detected a busy channel.*/
113     gPhyBusyRx_c               = 0x01,    /*!< The transceiver is asked to change its state while receiving.*/
114     gPhyBusyTx_c               = 0x02,    /*!< The transceiver is asked to change its state while transmitting.*/
115     gPhyChannelIdle_c          = 0x04,    /*!< The CCA attempt has detected an idle channel.*/
116     gPhyInvalidParameter_c     = 0x05,    /*!< A SET request was issued with a parameter in the primitive that is out of the valid range.*/
117     gPhyRxOn_c                 = 0x06,    /*!< The transceiver is in the receiver enabled state.*/
118     gPhySuccess_c              = 0x07,    /*!< A SET/GET, an ED operation, a data request, an indirect queue insert, or a transceiver state change was successful.*/
119     gPhyTRxOff_c               = 0x08,    /*!< The transceiver is in the transceiver disabled state.*/
120     gPhyTxOn_c                 = 0x09,    /*!< The transceiver is in the transmitter enabled state.*/
121     gPhyUnsupportedAttribute_c = 0x0a,    /*!< A SET/GET request was issued with the identifier of an attribute that is not supported.*/
122     gPhyReadOnly_c             = 0x0b,    /*!< A SET request was issued with the identifier of an attribute that is read-only.*/
123     gPhyIndexUsed_c            = 0x11,    /*!< The indirect queue insert operation has detected an used index.*/
124     gPhyNoAck_c                = 0x14,    /*!< No ACK was received for the last transmission.*/
125     gPhyFramePending_c         = 0x15,    /*!< The ACK of a Data Request frame indicates a pending frame in the coordinator's indirect TX queue.*/
126     gPhyBusy_c                 = 0xF1,    /*!< The current request cannot be handled, because the PHY is busy. */
127     gPhyInvalidPrimitive_c     = 0xF2,    /*!< The set was not completed, because the primitive is not in the valid range. */
128     gPhyPendingOp                         /* dual PAN scheduler state */
129 } phyStatus_t;
130 
131 /*! This type enumerates the possible transmission modes in respect to slotted or unslotted modes. */
132 typedef enum
133 {
134     gPhySlottedMode_c      = 0x0c,
135     gPhyUnslottedMode_c    = 0x0d
136 }phySlottedMode_t;
137 
138 /*! This type is used to indicate, whether the CCA type operations are required before the transmissions, and together with phySlottedTx_t to determine, whether there are more than one needed. */
139 typedef enum
140 {
141     gPhyEnergyDetectMode_c = 0x00,
142     gPhyCCAMode1_c         = 0x01, /*!< Energy above a threshold */
143     gPhyCCAMode2_c         = 0x02, /*!< Carrier sense only */
144     gPhyCCAMode3_c         = 0x03, /*!< CCA mode 1 + CCA mode 2 */
145     gPhyNoCCABeforeTx_c    = 0x04
146 }phyCCAType_t;
147 
148 /*! This type is used to indicate, whether the CCA3 mode operations are required before the transmissions. */
149 typedef enum
150 {
151     gPhyCCAMode3_OR_c      = 0x00, /*!< CCA mode 1 OR CCA mode 2 */
152     gPhyCCAMode3_AND_c     = 0x01  /*!< CCA mode 1 AND CCA mode 2 */
153 }phyCCA3Mode_t;
154 
155 typedef enum
156 {
157     gPhyContCcaEnabled     = 0x00,
158     gPhyContCcaDisabled
159 }phyContCCAMode_t;
160 
161 /*! This type is used to enumerate the possible states to set the transceiver to. \
162     Setting the transceiver into any Tx state is done by issuing pdDataReq_t that does not use this type for any member. */
163 typedef enum
164 {
165     gPhyForceTRxOff_c = 0x03,              /*!< The transceiver is to be switched off immediately.*/
166     gPhySetRxOn_c     = 0x12,              /*!< The transceiver is to be configured into the receiver enabled state.*/
167 } phyState_t;
168 
169 /*! This type is used to filter the next received frames, and to accept only Ack frames. */
170 typedef enum
171 {
172     gPhyRxAckRqd_c     = 0x00,             /*!< A receive Ack frame is expected to follow the transmit frame (non-Ack frames are rejected)*/
173     gPhyNoAckRqd_c     = 0x01,             /*!< An ordinary receive frame (any type of frame) follows the transmit frame*/
174     gPhyEnhancedAckReq = 0x02
175 }phyAckRequired_t;
176 
177 typedef enum
178 {
179     gPhyEncFrame = 0x1,     /* encrypt frame */
180     gPhyUpdHDr   = 0x2      /* updated header with frame counter */
181 } phyTxFlags;
182 
183 typedef enum {
184     gPhyRxAckFpIndirect    = 0x0, /* ACK FP was set due to entries being in SAP, indirect packet available. */
185     gPhyRxAckFpNoNeighbour = 0x1  /* ACK FP was set due to entries not being in SAA, no neighbours. */
186 } phyRxAckFpReason_t;
187 
188 /*! This type enumerates all PHY PIB IDs.
189     The PIBs can be read and written to by the upper layer, and are used to configure certain parameters and modes of operation for the PHY Layer.
190     The PIBs that refer to physical parameters, such as carrier frequency or transmission power, are usually mirrored in hardware, but in case the
191     IEEE 802.15.4 hardware acceleration is used, there are protocol-oriented PIBs also stored in hardware, such as addresses, PAN ID, promiscuous mode setting, and so on. */
192 typedef enum
193 {
194     gPhyPibCurrentChannel_c  = 0x00,       /*!< The channel currently used.*/
195     gPhyPibCurrentPage_c     = 0x01,       /*!< The channel page currently used.*/
196     gPhyPibTransmitPower_c   = 0x02,       /*!< The power used for TX operations.*/
197     gPhyPibLongAddress_c     = 0x03,       /*!< The MAC long address to be used by the PHY's source address matching feature.*/
198     gPhyPibShortAddress_c    = 0x04,       /*!< The MAC short address to be used by the PHY's source address matching feature.*/
199     gPhyPibPanId_c           = 0x05,       /*!< The MAC PAN ID to be used by the PHY's source address matching feature.*/
200     gPhyPibPanCoordinator_c  = 0x06,       /*!< Indicates if the device is a PAN coordinator or not.*/
201     gPhyPibSrcAddrEnable_c   = 0x07,       /*!< Enables or disables the PHY's source address matching feature.*/
202     gPhyPibPromiscuousMode_c = 0x08,       /*!< Selects between normal, promiscuous and active promiscuous mode.*/
203     gPhyPibAutoAckEnable_c   = 0x09,       /*!< Enables or disables automatic transmission of ACK frames.*/
204     gPhyPibFrameVersion_c    = 0x0A,       /*!< Used in checking for allowed frame versions (0x00 - any version accepted, 0x01 - accept Frame Version 0 packets (2003 compliant), 0x02 - accept Frame Version 1 packets (2006 compliant), 0x03 - accept Frame Version 0 and 1 packets).*/
205     gPhyPibFrameEnable_c     = 0x0B,       /*!< Used for enabling or disabling reception of MAC frames.*/
206     gPhyPibAckFramePending_c = 0x0C,       /*!< Used to copy its contents to the outgoing ACK frame's Frame Pending field as a response to a received Data Request frame with Source Address Matching disabled.*/
207     gPhyPibRxOnWhenIdle      = 0x0D,       /*!< Enable RX when the radio is IDLE*/
208     gPhyPibFrameWaitTime_c   = 0x0E,       /*!< The number of symbols the RX should be on after receiving an ACK with FP=1 */
209     gPhyPibDeferTxIfRxBusy_c = 0x0F,       /*!< If a packet is being received, transmission is deferred */
210     gPhyPibLastTxAckFP_c     = 0x10,       /*!< Indicates, whether the last ACK sent to the MAC Data Request had the frame pending flag set. */
211     gPhyPibCCAType_c         = 0x11,       /*!< Set the CCA3 Type */
212     gPhyPibCCA3Mode_c        = 0x12,       /*!< Determines the way CCA3 is required to be detected, "CCA1 and CCA2" or "CCA1 or CCA2". */
213     gPhyPibCcaConfig_c       = 0x13,       /*!< Used to configure the CCA dynamically. */
214     gPhyPibCSLRxEnabled_c    = 0x24,       /*!< Enable or disable the CSL mode for the RX sequences.  */
215 
216     gPhyGetRSSILevel_c,
217 
218     gPhyGetCtxId
219 } phyPibId_t;
220 
221 typedef union phyFlags_tag
222 {
223     uint32_t mask;
224     struct{
225         uint32_t     rxOnWhenIdle            :1;
226         uint32_t     rxFramePending          :1;
227         uint32_t     idleRx                  :1;
228         uint32_t     phyState                :3;
229         uint32_t     reserved                :26;
230     };
231 }phyFlags_t;
232 
233 /*!< PHY Time event Id */
234 typedef uint8_t  phyTimeTimerId_t;
235 /*!< PHY Time time-stamp */
236 typedef uint64_t phyTime_t;
237 /*!< PHY Time event callback type */
238 typedef void (*phyTimeCallback_t) ( uint32_t param );
239 
240 typedef enum
241 {
242     gPhyTimeOk_c               = 0x00, /*!< The request was performed successfully */
243     gPhyTimeAlreadyPassed_c    = 0x01, /*!< Requested time for event trigger has already passed */
244     gPhyTimeTooClose_c         = 0x02, /*!< Requested time for event trigger is too close to the current time to be processed */
245     gPhyTimeTooMany_c          = 0x03, /*!< Too many requests have been addressed */
246     gPhyTimeInvalidParameter_c = 0x04, /*!< The request was performed with an invalid parameter */
247     gPhyTimeNotFound_c         = 0x05, /*!< The requested timer was not found */
248     gPhyTimeError_c            = 0x06  /*!< The request encountered a hardware error */
249 }phyTimeStatus_t;
250 
251 
252 #if defined(__ARMCC_VERSION)
253 #pragma pop
254 #elif defined(__GNUC__)
255 #pragma GCC diagnostic pop
256 #elif defined(__IAR_SYSTEMS_ICC__)
257 #pragma language=default
258 #else
259 #error Not supported compiler type
260 #endif
261 
262 #endif  /* _PHY_TYPES_H */
263 /*! *********************************************************************************
264 * @}
265 ********************************************************************************** */
266