1 /* 2 * Copyright (c) 2016 Brian Swetland 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 9 #pragma once 10 11 // Standard Packet Format 12 // [ Preamble ][ Sync Word ][ Length Field ][ Address ][ Payload ][ CRC ] 13 // 0-30 bytes 0-32 bytes opt byte opt byte 0-255 opt 16bit 14 15 #define CMD_PROP_TX 0x3801 16 #define CMD_PROP_RX 0x3802 17 #define CMD_PROP_TX_ADV 0x3803 18 #define CMD_PROP_RX_ADV 0x3804 19 #define CMD_PROP_CS 0x3805 // cc13xx only 20 #define CMD_PROP_RADIO_SETUP 0x3806 // cc26xx only 21 #define CMD_PROP_RADIO_DIV_SETUP 0x3807 // cc13xx only 22 23 #define CMD_PROP_SET_LEN 0x3401 24 #define CMD_PROP_RESTART_RX 0x3402 25 26 #define PROP_DONE_OK 0x3400 27 #define PROP_DONE_RXTIMEOUT 0x3401 28 #define PROP_DONE_BREAK 0x3402 // tx abort due to timeout 29 #define PROP_DONE_ENDED 0x3403 // rx end trigger 30 #define PROP_DONE_STOPPED 0x3404 // stopped by CMD_STOP 31 #define PROP_DONE_ABORT 0x3405 // stopped by CMD_ABORT 32 #define PROP_DONE_RXERR 0x3406 // crc error 33 #define PROP_DONE_IDLE 0x3407 // CS ended because idle (cc13xx only) 34 #define PROP_DONE_BUSY 0x3408 // CS ended because busy (cc13xx only) 35 #define PROP_DONE_IDLETIMEOUT 0x3409 // CS (cc13xx only) 36 #define PROP_DONE_BUSYTIMEOUT 0x3409 // CS (cc13xx only) 37 38 #define PROP_ERROR_PAR 0x3800 // illegal parameter 39 #define PROP_ERROR_TXBUF 0x3801 // no available tx buffer at sop 40 #define PROP_ERROR_RXFULL 0x3802 // out of rx buffers during rx 41 #define PROP_ERROR_NO_SETUP 0x3803 // radio not in proprietary mode 42 #define PROP_ERROR_NO_FS 0x3804 // freq synth was off 43 #define PROP_ERROR_RXOVF 0x3805 // rx overflow 44 #define PROP_ERROR_TXUNF 0x3806 // tx underflow 45 46 typedef struct rf_op_prop_tx rf_op_prop_tx_t; 47 typedef struct rf_op_prop_tx_adv rf_op_prop_tx_adv_t; 48 typedef struct rf_op_prop_rx rf_op_prop_rx_t; 49 typedef struct rf_prop_output rf_prop_output_t; 50 51 #define PROP_TX_FS_ON (0 << 0) // leave freq synth on after 52 #define PROP_TX_FS_OFF (1 << 0) // turn freq synth off after 53 #define PROP_TX_USE_CRC (1 << 3) // append CRC to packet 54 #define PROP_TX_VAR_LEN (1 << 4) // send pkt_len as first byte 55 56 struct rf_op_prop_tx { 57 uint16_t cmd; 58 uint16_t status; 59 void *next_op; 60 uint32_t start_time; 61 uint8_t start_trig; 62 uint8_t cond; 63 64 uint8_t config; 65 uint8_t pkt_len; 66 uint32_t sync_word; 67 void *data; 68 }; 69 70 #define PROP_TXA_FS_ON (0 << 0) // leave freq synth on after 71 #define PROP_TXA_FS_OFF (1 << 0) // turn off freq synth after 72 #define PROP_TXA_USE_CRC (1 << 3) // append crc to packet 73 #define PROP_TXA_CRC_INC_SW (1 << 4) // include sync word in crc calc 74 #define PROP_TXT_CRC_INC_HDR (1 << 5) // include header in crc calc 75 76 struct rf_op_prop_tx_adv { 77 uint16_t cmd; 78 uint16_t status; 79 void *next_op; 80 uint32_t start_time; 81 uint8_t start_trig; 82 uint8_t cond; 83 84 uint8_t config; 85 uint8_t num_hdr_bits; // 0-32 86 uint16_t pkt_len; // 0 = unlimited 87 uint8_t start_conf; // 0 88 uint8_t pre_trig; // trigger for preamble->sync, NOW = one preamble 89 uint32_t pre_time; 90 uint32_t sync_word; 91 void *data; // packet data, or TX queue for unlimited length 92 }; 93 94 #define PROP_RX_FS_ON (0 << 0) // leave freq synth on after 95 #define PROP_RX_FS_OFF (1 << 0) // turn off freq synth after 96 #define PROP_RX_REPEAT_OK (1 << 1) // continue receiving after success 97 #define PROP_RX_REPEAT_NOT_OK (1 << 2) // continue receiving after failure 98 #define PROP_RX_USE_CRC (1 << 3) // check crc 99 #define PROP_RX_VAR_LEN (1 << 4) // first byte is packet length 100 #define PROP_RX_CHECK_ADDRESS (1 << 5) 101 #define PROP_RX_END_STOP (1 << 6) // packet discarded if end trg during rx 102 #define PROP_RX_KEEP_BAD_ADDR (1 << 7) // receive (but mark ignored) if addr mismatch 103 104 #define PROP_RX_AUTOFLUSH_IGNORED (1 << 0) // discard ignored packets 105 #define PROP_RX_AUTOFLUSH_CRC_ERR (1 << 1) // discard CRC error packets 106 #define PROP_RX_INC_HDR (1 << 3) // include header byte in rxdata 107 #define PROP_RX_INC_CRC (1 << 4) // include crc field in rxdata 108 #define PROP_RX_INC_RSSI (1 << 5) // include rssi byte 109 #define PROP_RX_INC_TIMESTAMP (1 << 6) // include timestamp word 110 #define PROP_RX_INC_STATUS (1 << 7) // include status byte 111 112 #define PROP_STATUS_ADDR_INDEX_MASK 0x1F 113 #define PROP_STATUS_ALT_SYNC_WORD 0x20 114 #define PROP_STATUS_MASK 0xC0 115 #define PROP_STATUS_RX_OK 0x00 116 #define PROP_STATUS_CRC_ERR 0x40 117 #define PROP_STATUS_IGNORE 0x80 118 #define PROP_STATUS_EX_ABORTED 0xC0 119 120 struct rf_op_prop_rx { 121 uint16_t cmd; 122 uint16_t status; 123 void *next_op; 124 uint32_t start_time; 125 uint8_t start_trig; 126 uint8_t cond; 127 128 uint8_t config; 129 uint8_t rx_config; 130 uint32_t sync_word; 131 uint8_t max_pkt_len; // 0 = unknown/unlimited 132 uint8_t addr0; 133 uint8_t addr1; 134 uint8_t end_trig; 135 uint32_t end_time; 136 rf_queue_t *queue; 137 rf_prop_output_t *output; 138 }; 139 140 struct rf_prop_output { 141 uint16_t num_rx_ok; 142 uint16_t num_rx_err; 143 uint8_t num_rx_ignored; // ignored due to addr mismatch 144 uint8_t num_rx_stopped; // rx fail due to addr mismatch or bad length 145 uint8_t num_rx_full; // discarded due to lack of buffer space 146 uint8_t last_rssi; // rssi at last sync word match 147 uint32_t timestamp; // of last rx'd packet 148 }; 149 150 STATIC_ASSERT(sizeof(rf_op_prop_tx_t) == 24); 151 STATIC_ASSERT(sizeof(rf_op_prop_tx_adv_t) == 32); 152 STATIC_ASSERT(sizeof(rf_op_prop_rx_t) == 36); 153 //STATIC_ASSERT(sizeof(rf_op_prop_rx_adv_t) == 48); 154 STATIC_ASSERT(sizeof(rf_prop_output_t) == 12); 155