1 /*
2  * Copyright (c) 2019 Brett Witherspoon
3  * Copyright (c) 2020 Friedt Professional Engineering Services, Inc
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef ZEPHYR_DRIVERS_IEEE802154_IEEE802154_CC13XX_CC26XX_SUBG_H_
9 #define ZEPHYR_DRIVERS_IEEE802154_IEEE802154_CC13XX_CC26XX_SUBG_H_
10 
11 #include <zephyr/kernel.h>
12 #include <zephyr/net/net_if.h>
13 #include <zephyr/net/ieee802154.h>
14 
15 #include <ti/drivers/rf/RF.h>
16 
17 #include <driverlib/rf_common_cmd.h>
18 #include <driverlib/rf_data_entry.h>
19 #include <driverlib/rf_ieee_cmd.h>
20 #include <driverlib/rf_prop_cmd.h>
21 #include <driverlib/rf_mailbox.h>
22 
23 /* See IEEE 802.15.4-2015 20.2.2 */
24 #define IEEE802154_SUN_PHY_FSK_PHR_LEN 2
25 
26 /* IEEE 802.15.4-2015 915 MHz 2FSK PHY symbol rate (20.6.3) */
27 #define IEEE802154_SUN_PHY_2FSK_200K_SYMBOLS_PER_SECOND 200000
28 
29 /* IEEE 802.15.4-2006 PHY constants (6.4.1) */
30 #define IEEE802154_TURNAROUND_TIME 12
31 
32 /* IEEE 802.15.4-2006 PHY PIB attributes (6.4.2) */
33 #define IEEE802154_PHY_CCA_MODE 1
34 #define IEEE802154_PHY_SHR_DURATION 2
35 #define IEEE802154_PHY_SYMBOLS_PER_OCTET 8
36 
37 /* IEEE 802.15.4-2006 MAC constants (7.4.1) */
38 #define IEEE802154_UNIT_BACKOFF_PERIOD 20
39 
40 /* ACK is 2 bytes for PHY header + 2 bytes MAC header + 2 bytes MAC footer */
41 #define IEEE802154_ACK_FRAME_OCTETS 6
42 
43 /* IEEE 802.15.4-2006 MAC PIB attributes (7.4.2)
44  *
45  * The macAckWaitDuration attribute does not include aUnitBackoffPeriod for
46  * non-beacon enabled PANs (See IEEE 802.15.4-2006 7.5.6.4.2)
47  */
48 #define IEEE802154_MAC_ACK_WAIT_DURATION			    \
49 	(IEEE802154_TURNAROUND_TIME + IEEE802154_PHY_SHR_DURATION + \
50 	 IEEE802154_ACK_FRAME_OCTETS * IEEE802154_PHY_SYMBOLS_PER_OCTET)
51 
52 #define CC13XX_CC26XX_RAT_CYCLES_PER_SECOND 4000000
53 
54 #define CC13XX_CC26XX_NUM_RX_BUF \
55 	CONFIG_IEEE802154_CC13XX_CC26XX_SUB_GHZ_NUM_RX_BUF
56 
57 /* Three additional bytes for length, RSSI and status values from CPE */
58 #define CC13XX_CC26XX_RX_BUF_SIZE (IEEE802154_MAX_PHY_PACKET_SIZE + 3)
59 
60 /*
61  * Two additional bytes for the SUN FSK PHY HDR
62  * (See IEEE 802.15.4-2015 20.2.2)
63  */
64 #define CC13XX_CC26XX_TX_BUF_SIZE \
65 	(IEEE802154_MAX_PHY_PACKET_SIZE + IEEE802154_SUN_PHY_FSK_PHR_LEN)
66 
67 #define CC13XX_CC26XX_RECEIVER_SENSITIVITY -100
68 #define CC13XX_CC26XX_RSSI_DYNAMIC_RANGE 95
69 
70 struct ieee802154_cc13xx_cc26xx_subg_data {
71 	RF_Handle rf_handle;
72 	RF_Object rf_object;
73 
74 	struct net_if *iface;
75 	uint8_t mac[8];
76 
77 	struct k_mutex tx_mutex;
78 
79 	dataQueue_t rx_queue;
80 	rfc_dataEntryPointer_t rx_entry[CC13XX_CC26XX_NUM_RX_BUF];
81 	uint8_t rx_data[CC13XX_CC26XX_NUM_RX_BUF][CC13XX_CC26XX_RX_BUF_SIZE];
82 	uint8_t tx_data[CC13XX_CC26XX_TX_BUF_SIZE];
83 
84 	/* Common Radio Commands */
85 	volatile rfc_CMD_CLEAR_RX_t cmd_clear_rx;
86 	volatile rfc_CMD_SET_TX_POWER_t cmd_set_tx_power;
87 	volatile rfc_CMD_FS_t cmd_fs;
88 
89 	/* Sub-GHz Radio Commands */
90 	volatile rfc_CMD_PROP_RX_ADV_t cmd_prop_rx_adv;
91 	volatile rfc_CMD_PROP_TX_ADV_t cmd_prop_tx_adv;
92 	volatile rfc_propRxOutput_t cmd_prop_rx_adv_output;
93 	volatile rfc_CMD_PROP_CS_t cmd_prop_cs;
94 };
95 
96 #endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_CC13XX_CC26XX_SUBG_H_ */
97