1 /* ieee802154_nrf5.h - nRF5 802.15.4 driver */
2 
3 /*
4  * Copyright (c) 2017-2023 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 <zephyr/net/ieee802154_radio.h>
12 
13 #define NRF5_PHR_LENGTH   (1)
14 
15 struct nrf5_802154_rx_frame {
16 	void *fifo_reserved; /* 1st word reserved for use by fifo. */
17 	uint8_t *psdu; /* Pointer to a received frame. */
18 	uint64_t time; /* RX timestamp. */
19 	uint8_t lqi; /* Last received frame LQI value. */
20 	int8_t rssi; /* Last received frame RSSI value. */
21 	bool ack_fpb; /* FPB value in ACK sent for the received frame. */
22 	bool ack_seb; /* SEB value in ACK sent for the received frame. */
23 };
24 
25 struct nrf5_802154_data {
26 	/* Pointer to the network interface. */
27 	struct net_if *iface;
28 
29 	/* 802.15.4 HW address. */
30 	uint8_t mac[8];
31 
32 	/* RX thread stack. */
33 	K_KERNEL_STACK_MEMBER(rx_stack, CONFIG_IEEE802154_NRF5_RX_STACK_SIZE);
34 
35 	/* RX thread control block. */
36 	struct k_thread rx_thread;
37 
38 	/* RX fifo queue. */
39 	struct k_fifo rx_fifo;
40 
41 	/* Buffers for passing received frame pointers and data to the
42 	 * RX thread via rx_fifo object.
43 	 */
44 	struct nrf5_802154_rx_frame rx_frames[CONFIG_NRF_802154_RX_BUFFERS];
45 
46 	/* Frame pending bit value in ACK sent for the last received frame. */
47 	bool last_frame_ack_fpb;
48 
49 	/* Security Enabled bit value in ACK sent for the last received frame. */
50 	bool last_frame_ack_seb;
51 
52 	/* CCA complete semaphore. Unlocked when CCA is complete. */
53 	struct k_sem cca_wait;
54 
55 	/* CCA result. Holds information whether channel is free or not. */
56 	bool channel_free;
57 
58 	/* TX synchronization semaphore. Unlocked when frame has been
59 	 * sent or send procedure failed.
60 	 */
61 	struct k_sem tx_wait;
62 
63 	/* TX buffer. First byte is PHR (length), remaining bytes are
64 	 * MPDU data.
65 	 */
66 	uint8_t tx_psdu[NRF5_PHR_LENGTH + IEEE802154_MAX_PHY_PACKET_SIZE];
67 
68 	/* TX result, updated in radio transmit callbacks. */
69 	uint8_t tx_result;
70 
71 	/* A buffer for the received ACK frame. psdu pointer be NULL if no
72 	 * ACK was requested/received.
73 	 */
74 	struct nrf5_802154_rx_frame ack_frame;
75 
76 	/* Callback handler of the currently ongoing energy scan.
77 	 * It shall be NULL if energy scan is not in progress.
78 	 */
79 	energy_scan_done_cb_t energy_scan_done;
80 
81 	/* Callback handler to notify of any important radio events.
82 	 * Can be NULL if event notification is not needed.
83 	 */
84 	ieee802154_event_cb_t event_handler;
85 
86 	/* Capabilities of the network interface. */
87 	enum ieee802154_hw_caps capabilities;
88 
89 	/* Indicates if currently processed TX frame is secured. */
90 	bool tx_frame_is_secured;
91 
92 	/* Indicates if currently processed TX frame has dynamic data updated. */
93 	bool tx_frame_mac_hdr_rdy;
94 
95 #if defined(CONFIG_IEEE802154_NRF5_MULTIPLE_CCA)
96 	/* The maximum number of extra CCA attempts to be performed before transmission. */
97 	uint8_t max_extra_cca_attempts;
98 #endif
99 
100 	/* The TX power in dBm. */
101 	int8_t txpwr;
102 
103 #if defined(CONFIG_NRF_802154_SER_HOST) && defined(CONFIG_IEEE802154_CSL_ENDPOINT)
104 	/* The last configured value of CSL period in units of 10 symbols. */
105 	uint32_t csl_period;
106 
107 	/* The last configured value of CSL phase time in nanoseconds. */
108 	net_time_t csl_rx_time;
109 #endif /* CONFIG_NRF_802154_SER_HOST && CONFIG_IEEE802154_CSL_ENDPOINT */
110 
111 	/* Indicates if RxOnWhenIdle mode is enabled. */
112 	bool rx_on_when_idle;
113 };
114 
115 #endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_NRF5_H_ */
116