1 /* ieee802154_rf2xx.h - IEEE 802.15.4 Driver definition for ATMEL RF2XX */
2 
3 /*
4  * Copyright (c) 2019-2020 Gerson Fernando Budke
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef ZEPHYR_DRIVERS_IEEE802154_IEEE802154_RF2XX_H_
10 #define ZEPHYR_DRIVERS_IEEE802154_IEEE802154_RF2XX_H_
11 
12 /* Runtime context structure
13  ***************************
14  */
15 enum rf2xx_trx_state_cmd_t {
16 	RF2XX_TRX_PHY_STATE_CMD_NOP             = 0x00,
17 	RF2XX_TRX_PHY_STATE_CMD_TX_START        = 0x02,
18 	RF2XX_TRX_PHY_STATE_CMD_FORCE_TRX_OFF   = 0x03,
19 	RF2XX_TRX_PHY_STATE_CMD_FORCE_PLL_ON    = 0x04,
20 	RF2XX_TRX_PHY_STATE_CMD_RX_ON           = 0x06,
21 	RF2XX_TRX_PHY_STATE_CMD_TRX_OFF         = 0x08,
22 	RF2XX_TRX_PHY_STATE_CMD_PLL_ON          = 0x09,
23 	RF2XX_TRX_PHY_STATE_CMD_PREP_DEEP_SLEEP = 0x10,
24 	RF2XX_TRX_PHY_STATE_CMD_RX_AACK_ON      = 0x16,
25 	RF2XX_TRX_PHY_STATE_CMD_TX_ARET_ON      = 0x19,
26 	/* Implemented by Software */
27 	RF2XX_TRX_PHY_STATE_CMD_SLEEP           = 0x0f,
28 	RF2XX_TRX_PHY_STATE_CMD_DEEP_SLEEP      = 0x20,
29 };
30 
31 enum rf2xx_trx_state_status_t {
32 	RF2XX_TRX_PHY_STATUS_P_ON               = 0x00,
33 	RF2XX_TRX_PHY_STATUS_BUSY_RX            = 0x01,
34 	RF2XX_TRX_PHY_STATUS_BUSY_TX            = 0x02,
35 	RF2XX_TRX_PHY_STATUS_RX_ON              = 0x06,
36 	RF2XX_TRX_PHY_STATUS_TRX_OFF            = 0x08,
37 	RF2XX_TRX_PHY_STATUS_PLL_ON             = 0x09,
38 	RF2XX_TRX_PHY_STATUS_SLEEP              = 0x0f,
39 	RF2XX_TRX_PHY_STATUS_BUSY_RX_AACK       = 0x11,
40 	RF2XX_TRX_PHY_STATUS_BUSY_TX_ARET       = 0x12,
41 	RF2XX_TRX_PHY_STATUS_RX_AACK_ON         = 0x16,
42 	RF2XX_TRX_PHY_STATUS_TX_ARET_ON         = 0x19,
43 	RF2XX_TRX_PHY_STATUS_RX_ON_NOCLK        = 0x1c,
44 	RF2XX_TRX_PHY_STATUS_RX_AACK_ON_NOCLK   = 0x1d,
45 	RF2XX_TRX_PHY_STATUS_BUSY_RX_AACK_NOCLK = 0x1e,
46 	RF2XX_TRX_PHY_STATUS_STATE_TRANSITION   = 0x1f,
47 	RF2XX_TRX_PHY_STATUS_MASK               = 0x1f
48 };
49 
50 /**
51  *	TRAC STATE			RX_AACK	TX_ARET
52  *	SUCCESS				   X	   X
53  *	SUCCESS_DATA_PENDING			   X
54  *	SUCCESS_WAIT_FOR_ACK		   X
55  *	CHANNEL_ACCESS_FAILED			   X
56  *	NO_ACK					   X
57  *	INVALID				   X	   X
58  */
59 enum rf2xx_trx_state_trac_t {
60 	RF2XX_TRX_PHY_STATE_TRAC_SUCCESS                = 0x00,
61 	RF2XX_TRX_PHY_STATE_TRAC_SUCCESS_DATA_PENDING   = 0x01,
62 	RF2XX_TRX_PHY_STATE_TRAC_SUCCESS_WAIT_FOR_ACK   = 0x02,
63 	RF2XX_TRX_PHY_STATE_TRAC_CHANNEL_ACCESS_FAILED  = 0x03,
64 	RF2XX_TRX_PHY_STATE_TRAC_NO_ACK                 = 0x05,
65 	RF2XX_TRX_PHY_STATE_TRAC_INVALID                = 0x07,
66 };
67 
68 enum rf2xx_trx_model_t {
69 	RF2XX_TRX_MODEL_INV     = 0x00,
70 	RF2XX_TRX_MODEL_230     = 0x02,
71 	RF2XX_TRX_MODEL_231     = 0x03,
72 	RF2XX_TRX_MODEL_212     = 0x07,
73 	RF2XX_TRX_MODEL_232     = 0x0A,
74 	RF2XX_TRX_MODEL_233     = 0x0B,
75 };
76 
77 struct rf2xx_dt_gpio_t {
78 	const char *devname;
79 	uint32_t pin;
80 	uint32_t flags;
81 };
82 
83 struct rf2xx_dt_spi_t {
84 	const char *devname;
85 	uint32_t freq;
86 	uint32_t addr;
87 	struct rf2xx_dt_gpio_t cs;
88 };
89 
90 struct rf2xx_config {
91 	struct rf2xx_dt_gpio_t irq;
92 	struct rf2xx_dt_gpio_t reset;
93 	struct rf2xx_dt_gpio_t slptr;
94 	struct rf2xx_dt_gpio_t dig2;
95 	struct rf2xx_dt_gpio_t clkm;
96 
97 	struct rf2xx_dt_spi_t spi;
98 
99 	uint8_t inst;
100 	uint8_t has_mac;
101 };
102 
103 struct rf2xx_context {
104 	struct net_if *iface;
105 
106 	const struct device *dev;
107 
108 	const struct device *irq_gpio;
109 	const struct device *reset_gpio;
110 	const struct device *slptr_gpio;
111 	const struct device *dig2_gpio;
112 	const struct device *clkm_gpio;
113 
114 	const struct device *spi;
115 	struct spi_config spi_cfg;
116 	struct spi_cs_control spi_cs;
117 
118 	struct gpio_callback irq_cb;
119 
120 	struct k_thread trx_thread;
121 	K_KERNEL_STACK_MEMBER(trx_stack,
122 			      CONFIG_IEEE802154_RF2XX_RX_STACK_SIZE);
123 	struct k_sem trx_isr_lock;
124 	struct k_sem trx_tx_sync;
125 
126 	enum rf2xx_trx_model_t trx_model;
127 	enum rf2xx_trx_state_trac_t trx_trac;
128 
129 	enum ieee802154_tx_mode tx_mode;
130 	uint8_t mac_addr[8];
131 	uint8_t pkt_lqi;
132 	uint8_t pkt_ed;
133 	int8_t trx_rssi_base;
134 	uint8_t trx_version;
135 	uint8_t rx_phr;
136 };
137 
138 #endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_RF2XX_H_ */
139