1 /* ieee802154_nrf5.h - nRF5 802.15.4 driver */
2 
3 /*
4  * Copyright (c) 2017 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 #ifndef ZEPHYR_DRIVERS_IEEE802154_IEEE802154_NRF5_H_
9 #define ZEPHYR_DRIVERS_IEEE802154_IEEE802154_NRF5_H_
10 
11 #include <net/ieee802154_radio.h>
12 
13 #define NRF5_FCS_LENGTH   (2)
14 #define NRF5_PSDU_LENGTH  (125)
15 #define NRF5_PHR_LENGTH   (1)
16 
17 struct nrf5_802154_rx_frame {
18 	void *fifo_reserved; /* 1st word reserved for use by fifo. */
19 	uint8_t *psdu; /* Pointer to a received frame. */
20 	uint32_t time; /* RX timestamp. */
21 	uint8_t lqi; /* Last received frame LQI value. */
22 	int8_t rssi; /* Last received frame RSSI value. */
23 	bool ack_fpb; /* FPB value in ACK sent for the received frame. */
24 };
25 
26 struct nrf5_802154_data {
27 	/* Pointer to the network interface. */
28 	struct net_if *iface;
29 
30 	/* 802.15.4 HW address. */
31 	uint8_t mac[8];
32 
33 	/* RX thread stack. */
34 	K_KERNEL_STACK_MEMBER(rx_stack, CONFIG_IEEE802154_NRF5_RX_STACK_SIZE);
35 
36 	/* RX thread control block. */
37 	struct k_thread rx_thread;
38 
39 	/* RX fifo queue. */
40 	struct k_fifo rx_fifo;
41 
42 	/* Buffers for passing received frame pointers and data to the
43 	 * RX thread via rx_fifo object.
44 	 */
45 	struct nrf5_802154_rx_frame rx_frames[CONFIG_NRF_802154_RX_BUFFERS];
46 
47 	/* Frame pending bit value in ACK sent for the last received frame. */
48 	bool last_frame_ack_fpb;
49 
50 	/* CCA complete sempahore. Unlocked when CCA is complete. */
51 	struct k_sem cca_wait;
52 
53 	/* CCA result. Holds information whether channel is free or not. */
54 	bool channel_free;
55 
56 	/* TX synchronization semaphore. Unlocked when frame has been
57 	 * sent or send procedure failed.
58 	 */
59 	struct k_sem tx_wait;
60 
61 	/* TX buffer. First byte is PHR (length), remaining bytes are
62 	 * MPDU data.
63 	 */
64 	uint8_t tx_psdu[NRF5_PHR_LENGTH + NRF5_PSDU_LENGTH + NRF5_FCS_LENGTH];
65 
66 	/* TX result, updated in radio transmit callbacks. */
67 	uint8_t tx_result;
68 
69 	/* A buffer for the received ACK frame. psdu pointer be NULL if no
70 	 * ACK was requested/received.
71 	 */
72 	struct nrf5_802154_rx_frame ack_frame;
73 
74 	/* Callback handler of the currently ongoing energy scan.
75 	 * It shall be NULL if energy scan is not in progress.
76 	 */
77 	energy_scan_done_cb_t energy_scan_done;
78 
79 	/* Callback handler to notify of any important radio events.
80 	 * Can be NULL if event notification is not needed.
81 	 */
82 	ieee802154_event_cb_t event_handler;
83 
84 	/* Capabilities of the network interface. */
85 	enum ieee802154_hw_caps capabilities;
86 
87 	/* Next CSL receive time */
88 	uint32_t csl_rx_time;
89 
90 	/* Indicates if currently processed TX frame is secured. */
91 	bool tx_frame_is_secured;
92 
93 	/* Indicates if currently processed TX frame has dynamic data updated. */
94 	bool tx_frame_mac_hdr_rdy;
95 };
96 
97 #endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_NRF5_H_ */
98