1 /**
2   ******************************************************************************
3   * @file    stm32wb0x_hal_radio.h
4   * @author  GPM WBL Application Team
5   * @brief   Header file of RADIO module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2024 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32WB0x_HAL_RADIO_H
21 #define STM32WB0x_HAL_RADIO_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wb0x_hal_def.h"
29 #include "stm32wb0x_ll_radio.h"
30 
31 /** @addtogroup STM32WB0x_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup RADIO
36   * @{
37   */
38 
39 /** @defgroup RADIO_Exported_Types RADIO Exported Types
40   * @{
41   */
42 
43 /**
44   * @brief  RADIO Handle Structure definition
45   */
46 typedef struct
47 {
48   BLUE_TypeDef                 *Instance;  /*!< Register base address    */
49 } RADIO_HandleTypeDef;
50 
51 
52 #if USE_RADIO_PROPRIETARY_DRIVER
53 
54 typedef struct ActionPacket ActionPacket;
55 
56 struct ActionPacket
57 {
58   uint8_t StateMachineNo;       /* This parameter indicates the state machine number for this action. From 0 to 7. */
59   uint8_t ActionTag;            /* The action tags are: PLL_TRIG TXRX TIMER_WAKEUP
60                                     WHITENING_DISABLE INC_CHAN TIMESTAMP_POSITION RELATIVE */
61   uint8_t MaxReceiveLength;     /* Maximum size of received payload. Applicable only for RX actions. */
62   uint32_t WakeupTime;          /* Contains the wakeup time in microsecond if it is relative.
63                                  * If it is absolute it must be expressed in System Time (STU). */
64   uint8_t *data;                /* Pointer to the array with the data to send (header, length and data field), for TX.
65                                  * Pointer to the array where the data received are copied, for RX.
66                                  * In case of RX, the array must have the max size MAX_PACKET_LENGTH. */
67   uint32_t status;              /* The Status Register with the information on the action. */
68   uint32_t timestamp_receive;   /* This field contains the timestamp when a packet is received.
69                                  * Intended to be used in the dataRoutine() callback routine. RX only. */
70   int32_t rssi;                 /* The rssi of the packet was received with. RX only. */
71   BlueTransStruct trans_packet; /* This is a linked list, which is going to be used by Hardware.
72                                   * User does not need to do anything. */
73   ActionPacket *next_true;      /* Pointer to next ActionPacket if condRoutine() returns TRUE */
74   ActionPacket *next_false;     /* Pointer to next ActionPacket if condRoutine() returns FALSE */
75   uint8_t (*condRoutine)(ActionPacket *);        /* User callback that decide the next ActionPacket to use.
76                                                  * It is time critical. Routine must end within 45 us. */
77   uint8_t (*dataRoutine)(ActionPacket *, ActionPacket *); /* User callback for managing data. */
78   uint8_t trans_config;         /* To configure the device for TX or RX. User does not need to do anything. */
79 };
80 
81 
82 typedef struct
83 {
84   uint32_t back2backTime;
85   uint8_t tone_start_stop_flag;
86   ActionPacket *current_action_packet;
87 } RadioGlobalParameters_t;
88 
89 
90 typedef struct
91 {
92   int32_t rssi;
93   uint32_t timestamp_receive;
94 } RxStats_t;
95 
96 #endif /* USE_RADIO_PROPRIETARY_DRIVER */
97 
98 
99 /**
100   * @}
101   */
102 
103 
104 /** @defgroup RADIO_Exported_Functions RADIO Exported Functions
105   * @{
106   */
107 
108 void HAL_RADIO_Init(RADIO_HandleTypeDef *hradio);
109 
110 void HAL_RADIO_TXRX_IRQHandler(void);
111 
112 void HAL_RADIO_TXRX_SEQ_IRQHandler(void);
113 
114 void HAL_RADIO_TxRxCallback(uint32_t flags);
115 
116 void HAL_RADIO_TxRxSeqCallback(void);
117 
118 int8_t HAL_RADIO_ReadRSSI(void);
119 
120 void HAL_RADIO_MspInit(RADIO_HandleTypeDef *hradio);
121 void HAL_RADIO_MspDeInit(RADIO_HandleTypeDef *hradio);
122 
123 #if USE_RADIO_PROPRIETARY_DRIVER
124 
125 uint8_t HAL_RADIO_GetStatus(uint32_t *time);
126 void HAL_RADIO_SetChannelMap(uint8_t StateMachineNo, uint8_t *chan_remap);
127 void HAL_RADIO_SetChannel(uint8_t StateMachineNo, uint8_t channel, uint8_t channel_increment);
128 void HAL_RADIO_SetTxAttributes(uint8_t StateMachineNo, uint32_t NetworkID, uint32_t crc_init);
129 void HAL_RADIO_SetMaxReceivedLength(uint8_t StateMachineNo, uint8_t MaxReceivedLength);
130 void HAL_RADIO_SetBackToBackTime(uint32_t back_to_back_time);
131 void HAL_RADIO_SetPhy(uint8_t StateMachineNo, uint8_t phy);
132 void HAL_RADIO_SetTxPower(uint8_t PowerLevel);
133 uint8_t HAL_RADIO_StopActivity(void);
134 void HAL_RADIO_SetGlobalReceiveTimeout(uint32_t ReceiveTimeout);
135 void HAL_RADIO_SetReservedArea(ActionPacket *p);
136 uint8_t HAL_RADIO_MakeActionPacketPending(ActionPacket *p);
137 uint8_t HAL_RADIO_StartTone(uint8_t RF_channel, uint8_t powerLevel, uint8_t freq_offset);
138 uint8_t HAL_RADIO_StopTone(void);
139 void HAL_RADIO_SetEncryptionCount(uint8_t StateMachineNo, uint8_t *count_tx, uint8_t *count_rcv);
140 void HAL_RADIO_SetEncryptionAttributes(uint8_t StateMachineNo, uint8_t *enc_iv, uint8_t *enc_key);
141 void HAL_RADIO_SetEncryptFlags(uint8_t StateMachineNo, FunctionalState EncryptFlagTx, FunctionalState EncryptFlagRcv);
142 void HAL_RADIO_EncryptPlainData(uint8_t *Key, uint8_t *plainData, uint8_t *cypherData);
143 void HAL_RADIO_SetDefaultPreambleLen(uint8_t StateMachineNo);
144 void HAL_RADIO_SetPreambleRep(uint8_t StateMachineNo, uint8_t PreaLen);
145 void HAL_RADIO_DisableCRC(uint8_t StateMachineNo, FunctionalState hwCRC);
146 uint8_t HAL_RADIO_SetNetworkID(uint32_t ID);
147 uint8_t HAL_RADIO_CarrierSense(uint8_t channel, int8_t *rssi);
148 uint8_t HAL_RADIO_Callback(ActionPacket *p, ActionPacket *next);
149 
150 void HAL_RADIO_CallbackRcvError(RxStats_t *rxPacketStats);
151 void HAL_RADIO_CallbackRcvTimeout(RxStats_t *rxPacketStats);
152 void HAL_RADIO_CallbackRcvEncryptErr(RxStats_t *rxPacketStats);
153 void HAL_RADIO_CallbackRcvOk(RxStats_t *rxPacketStats);
154 void HAL_RADIO_CallbackTxDone(void);
155 
156 uint8_t HAL_RADIO_SendPacket(uint8_t channel, uint32_t wakeup_time, uint8_t *txBuffer,
157                              uint8_t (*Callback)(ActionPacket *, ActionPacket *));
158 
159 uint8_t HAL_RADIO_SendPacketWithAck(uint8_t channel, uint32_t wakeup_time, uint8_t *txBuffer, uint8_t *rxBuffer,
160                                     uint32_t receive_timeout, uint8_t receive_length,
161                                     uint8_t (*Callback)(ActionPacket *, ActionPacket *));
162 
163 uint8_t HAL_RADIO_ReceivePacket(uint8_t channel, uint32_t wakeup_time, uint8_t *rxBuffer, uint32_t receive_timeout,
164                                 uint8_t receive_length,
165                                 uint8_t (*Callback)(ActionPacket *, ActionPacket *));
166 
167 uint8_t HAL_RADIO_ReceivePacketWithAck(uint8_t channel, uint32_t wakeup_time, uint8_t *rxBuffer, uint8_t *txBuffer,
168                                        uint32_t receive_timeout, uint8_t receive_length,
169                                        uint8_t (*Callback)(ActionPacket *, ActionPacket *));
170 
171 #endif /* USE_RADIO_PROPRIETARY_DRIVER */
172 
173 /**
174   * @}
175   */
176 
177 /**
178   * @}
179   */
180 
181 /**
182   * @}
183   */
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif /* STM32WB0x_HAL_RADIO_H */
190