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_config { 78 struct gpio_dt_spec irq_gpio; 79 struct gpio_dt_spec reset_gpio; 80 struct gpio_dt_spec slptr_gpio; 81 struct gpio_dt_spec dig2_gpio; 82 struct gpio_dt_spec clkm_gpio; 83 84 struct spi_dt_spec spi; 85 86 uint8_t inst; 87 uint8_t has_mac; 88 89 uint8_t const *tx_pwr_table; 90 uint8_t tx_pwr_table_size; 91 int8_t tx_pwr_min[2]; 92 int8_t tx_pwr_max[2]; 93 }; 94 95 struct rf2xx_context { 96 struct net_if *iface; 97 98 const struct device *dev; 99 100 struct gpio_callback irq_cb; 101 102 struct k_thread trx_thread; 103 K_KERNEL_STACK_MEMBER(trx_stack, 104 CONFIG_IEEE802154_RF2XX_RX_STACK_SIZE); 105 struct k_sem trx_isr_lock; 106 struct k_sem trx_tx_sync; 107 108 enum rf2xx_trx_model_t trx_model; 109 110 /* PHY specific driver attributes */ 111 enum ieee802154_phy_channel_page cc_page; 112 struct ieee802154_phy_channel_range cc_range; 113 struct ieee802154_phy_supported_channels cc_channels; 114 115 enum rf2xx_trx_state_trac_t trx_trac; 116 117 enum ieee802154_tx_mode tx_mode; 118 uint8_t mac_addr[8]; 119 uint8_t pkt_lqi; 120 uint8_t pkt_ed; 121 int8_t trx_rssi_base; 122 uint8_t trx_version; 123 uint8_t rx_phr; 124 bool promiscuous; 125 }; 126 127 #endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_RF2XX_H_ */ 128