@@ -122,94 +122,102 @@ static void nrf5_get_eui64(uint8_t *mac)
122
122
memcpy (mac + index , & factoryAddress , sizeof (factoryAddress ) - index );
123
123
}
124
124
125
- static void nrf5_rx_thread (void * arg1 , void * arg2 , void * arg3 )
125
+ static void nrf5_rx_frame_process (struct nrf5_802154_data * nrf5_radio ,
126
+ struct nrf5_802154_rx_frame * rx_frame )
126
127
{
127
- struct nrf5_802154_data * nrf5_radio = (struct nrf5_802154_data * )arg1 ;
128
- struct net_pkt * pkt ;
129
- struct nrf5_802154_rx_frame * rx_frame ;
128
+ struct net_pkt * pkt = NULL ;
130
129
uint8_t pkt_len ;
131
130
uint8_t * psdu ;
132
131
133
- ARG_UNUSED (arg2 );
134
- ARG_UNUSED (arg3 );
135
-
136
- while (1 ) {
137
- pkt = NULL ;
138
- rx_frame = NULL ;
139
-
140
- LOG_DBG ("Waiting for frame" );
141
-
142
- rx_frame = k_fifo_get (& nrf5_radio -> rx_fifo , K_FOREVER );
143
-
144
- __ASSERT_NO_MSG (rx_frame -> psdu );
132
+ __ASSERT_NO_MSG (rx_frame -> psdu );
145
133
146
- /* rx_mpdu contains length, psdu, fcs|lqi
147
- * The last 2 bytes contain LQI or FCS, depending if
148
- * automatic CRC handling is enabled or not, respectively.
149
- */
150
- if (IS_ENABLED (CONFIG_IEEE802154_NRF5_FCS_IN_LENGTH )) {
151
- pkt_len = rx_frame -> psdu [0 ];
152
- } else {
153
- pkt_len = rx_frame -> psdu [0 ] - NRF5_FCS_LENGTH ;
154
- }
134
+ /* rx_mpdu contains length, psdu, fcs|lqi
135
+ * The last 2 bytes contain LQI or FCS, depending if
136
+ * automatic CRC handling is enabled or not, respectively.
137
+ */
138
+ if (IS_ENABLED (CONFIG_IEEE802154_NRF5_FCS_IN_LENGTH )) {
139
+ pkt_len = rx_frame -> psdu [0 ];
140
+ } else {
141
+ pkt_len = rx_frame -> psdu [0 ] - NRF5_FCS_LENGTH ;
142
+ }
155
143
156
144
#if defined(CONFIG_NET_BUF_DATA_SIZE )
157
- __ASSERT_NO_MSG (pkt_len <= CONFIG_NET_BUF_DATA_SIZE );
145
+ __ASSERT_NO_MSG (pkt_len <= CONFIG_NET_BUF_DATA_SIZE );
158
146
#endif
159
147
160
- LOG_DBG ("Frame received" );
148
+ LOG_DBG ("Frame received" );
161
149
162
- /* Block the RX thread until net_pkt is available, so that we
163
- * don't drop already ACKed frame in case of temporary net_pkt
164
- * scarcity. The nRF 802154 radio driver will accumulate any
165
- * incoming frames until it runs out of internal buffers (and
166
- * thus stops acknowledging consecutive frames).
167
- */
168
- pkt = net_pkt_rx_alloc_with_buffer (nrf5_radio -> iface , pkt_len ,
169
- AF_UNSPEC , 0 , K_FOREVER );
150
+ /* Block the RX thread until net_pkt is available, so that we
151
+ * don't drop already ACKed frame in case of temporary net_pkt
152
+ * scarcity. The nRF 802154 radio driver will accumulate any
153
+ * incoming frames until it runs out of internal buffers (and
154
+ * thus stops acknowledging consecutive frames).
155
+ */
156
+ pkt = net_pkt_rx_alloc_with_buffer (nrf5_radio -> iface , pkt_len ,
157
+ AF_UNSPEC , 0 , K_FOREVER );
170
158
171
- if (net_pkt_write (pkt , rx_frame -> psdu + 1 , pkt_len )) {
172
- goto drop ;
173
- }
159
+ if (net_pkt_write (pkt , rx_frame -> psdu + 1 , pkt_len )) {
160
+ goto drop ;
161
+ }
174
162
175
- net_pkt_set_ieee802154_lqi (pkt , rx_frame -> lqi );
176
- net_pkt_set_ieee802154_rssi (pkt , rx_frame -> rssi );
177
- net_pkt_set_ieee802154_ack_fpb (pkt , rx_frame -> ack_fpb );
163
+ net_pkt_set_ieee802154_lqi (pkt , rx_frame -> lqi );
164
+ net_pkt_set_ieee802154_rssi (pkt , rx_frame -> rssi );
165
+ net_pkt_set_ieee802154_ack_fpb (pkt , rx_frame -> ack_fpb );
178
166
179
167
#if defined(CONFIG_NET_PKT_TIMESTAMP )
180
- struct net_ptp_time timestamp = {
181
- .second = rx_frame -> time / USEC_PER_SEC ,
182
- .nanosecond =
183
- (rx_frame -> time % USEC_PER_SEC ) * NSEC_PER_USEC
184
- };
168
+ struct net_ptp_time timestamp = {
169
+ .second = rx_frame -> time / USEC_PER_SEC ,
170
+ .nanosecond =
171
+ (rx_frame -> time % USEC_PER_SEC ) * NSEC_PER_USEC
172
+ };
185
173
186
- net_pkt_set_timestamp (pkt , & timestamp );
174
+ net_pkt_set_timestamp (pkt , & timestamp );
187
175
#endif
188
176
189
- LOG_DBG ("Caught a packet (%u) (LQI: %u)" ,
190
- pkt_len , rx_frame -> lqi );
177
+ LOG_DBG ("Caught a packet (%u) (LQI: %u)" ,
178
+ pkt_len , rx_frame -> lqi );
191
179
192
- if (net_recv_data (nrf5_radio -> iface , pkt ) < 0 ) {
193
- LOG_ERR ("Packet dropped by NET stack" );
194
- goto drop ;
195
- }
180
+ if (net_recv_data (nrf5_radio -> iface , pkt ) < 0 ) {
181
+ LOG_ERR ("Packet dropped by NET stack" );
182
+ goto drop ;
183
+ }
196
184
197
- psdu = rx_frame -> psdu ;
198
- rx_frame -> psdu = NULL ;
199
- nrf_802154_buffer_free_raw (psdu );
185
+ psdu = rx_frame -> psdu ;
186
+ rx_frame -> psdu = NULL ;
187
+ nrf_802154_buffer_free_raw (psdu );
200
188
201
- if (LOG_LEVEL >= LOG_LEVEL_DBG ) {
202
- log_stack_usage (& nrf5_radio -> rx_thread );
203
- }
189
+ if (LOG_LEVEL >= LOG_LEVEL_DBG ) {
190
+ log_stack_usage (& nrf5_radio -> rx_thread );
191
+ }
204
192
205
- continue ;
193
+ return ;
206
194
207
195
drop :
208
- psdu = rx_frame -> psdu ;
209
- rx_frame -> psdu = NULL ;
210
- nrf_802154_buffer_free_raw (psdu );
196
+ psdu = rx_frame -> psdu ;
197
+ rx_frame -> psdu = NULL ;
198
+ nrf_802154_buffer_free_raw (psdu );
199
+
200
+ net_pkt_unref (pkt );
201
+ }
202
+
203
+ static void nrf5_rx_thread (void * arg1 , void * arg2 , void * arg3 )
204
+ {
205
+ struct nrf5_802154_data * nrf5_radio = (struct nrf5_802154_data * )arg1 ;
206
+ struct nrf5_802154_rx_frame * rx_frame ;
207
+
208
+ ARG_UNUSED (arg2 );
209
+ ARG_UNUSED (arg3 );
210
+
211
+ while (1 ) {
212
+ rx_frame = NULL ;
213
+
214
+ LOG_DBG ("Waiting for frame" );
211
215
212
- net_pkt_unref (pkt );
216
+ rx_frame = k_fifo_get (& nrf5_radio -> rx_fifo , K_FOREVER );
217
+
218
+ if (rx_frame != NULL ) {
219
+ nrf5_rx_frame_process (nrf5_radio , rx_frame );
220
+ }
213
221
}
214
222
}
215
223
0 commit comments