1 /* 2 * Copyright 2018 Oticon A/S 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef P2G4_PENDING_TX_LIST_H 7 #define P2G4_PENDING_TX_LIST_H 8 9 #include "bs_types.h" 10 #include "bs_pc_2G4_types.h" 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** 17 * For each device, current/next transmission parameters and packet 18 */ 19 typedef struct { 20 p2G4_txv2_t tx_s; 21 uint8_t *packet; 22 } tx_el_t; 23 24 25 /* State of each device (bitmask)*/ 26 #define TXS_OFF 0 /* It is currently not transmitting */ 27 #define TXS_NOISE 1 /* It is currently transmitting at least "noise" */ 28 #define TXS_PACKET_ONGOING 2 /* It is currently transmitting the packet itself */ 29 #define TXS_PACKET_STARTED 4 /* It did already start transmitting the packet*/ 30 #define TXS_PACKET_ENDED 8 /* It did already end the transmitting of this packet*/ 31 /** 32 * Transmission list container 33 */ 34 typedef struct{ 35 uint64_t ctr; //Counter: every time the tx list changes this counter is updated 36 tx_el_t *tx_list; //Array of transmission parameters with one element per device 37 uint *used; //Array with one element per device (one of TXS_*) 38 } tx_l_c_t; 39 40 /** 41 * Allocate whatever the Txlist requires 42 * 43 * @param n_devs Number of device interfaces 44 */ 45 void txl_create(uint n_devs); 46 47 /** 48 * Free any resources used by the Tx List 49 * (To be called before exiting) 50 */ 51 void txl_free(void); 52 53 /** 54 * Register a new transmission for a given device/interface 55 * 56 * Note that registering a transmission does not mean the transmission is yet 57 * active (registering can be done arbitrarily earlier than the actual start) 58 * For the transmission to be "active" txl_activate() must be called 59 * 60 * @param dev_nbr Device which will transmit 61 * @param tx_s Transmission parameters 62 * @param packet Pointer to the transmitted packet 63 */ 64 void txl_register(uint d, p2G4_txv2_t *tx_s, uint8_t* packet); 65 66 /** 67 * Remove a transmission from the list 68 * 69 * @param dev_nbr Device whos transmission is to be removed 70 */ 71 void txl_clear(uint dev_nbr); 72 73 /** 74 * Set a transmission as active (currently transmitting) 75 * 76 * Note that txl_register() must be called first to record the actual 77 * transmission parameters and packet 78 * 79 * @param dev_nbr Device which has just started transmitting 80 */ 81 void txl_start_tx(uint dev_nbr); 82 83 /** 84 * Set a transmission as actively transmitting the packet 85 * 86 * Note that txl_register() & txl_start_tx 87 * must be called first to record the actual 88 * transmission parameters and packet 89 * 90 * @param dev_nbr Device which has just started transmitting its packet 91 */ 92 void txl_start_packet(uint dev_nbr); 93 94 95 /** 96 * Mark that the packet has ended (noise may continue) 97 * 98 * Note that txl_register() & txl_start_tx 99 * must be called first to record the actual 100 * transmission parameters and packet 101 * 102 * @param dev_nbr Device which has just ended transmitting its packet 103 */ 104 void txl_end_packet(uint dev_nbr); 105 106 int txl_get_max_tx_nbr(void); 107 108 /** 109 * Reception state 110 */ 111 typedef enum { 112 Rx_State_NotSearching = 0, //Not actively searching for any tx 113 Rx_State_Searching,//Searching for a fitting tx 114 } rx_state_t; 115 116 typedef struct { 117 uint errorspercalc; //How many errors do we calculate each time that we calculate errors 118 uint rate_uspercalc; //Error calculation rate, in us between calculations 119 int us_to_next_calc; 120 } rx_error_calc_state_t; 121 /** 122 * Reception status (per device interface) 123 */ 124 typedef struct { 125 bs_time_t scan_end; //Last us (included) in which we will scan 126 bs_time_t sync_start; //When we try to start sync'ing (we delay it as much as possible into the amount of preamble the device does not need) 127 bs_time_t sync_end; //Last us (included) in which the preamble + address ends 128 bs_time_t header_end; //Last us (included) in which the header ends 129 bs_time_t payload_end; //Last us (included) in which the payload ends 130 p2G4_rxv2_t rx_s; //Reception request parameters 131 p2G4_rxv2_done_t rx_done_s; //Response message (being prepared) 132 int tx_nbr; //If we found a fitting Tx, which is its device number 133 uint biterrors; 134 rx_state_t state; 135 p2G4_address_t phy_address[16]; 136 rx_error_calc_state_t err_calc_state; 137 bool v1_request; 138 } rx_status_t; 139 140 /** 141 * Search compatible (CCA) status (per device interface) 142 */ 143 typedef struct { 144 bs_time_t scan_end; //Last us (possibly included) in which we will scan 145 bs_time_t next_meas;//us in which the next measurement should be done 146 p2G4_cca_t req; //Search request parameters 147 p2G4_cca_done_t resp; //Response message (being prepared) 148 uint n_meas; //How many measurements have been done 149 double RSSI_acc; //power in mW (natural units) 150 } cca_status_t; 151 152 #ifdef __cplusplus 153 } 154 #endif 155 156 #endif 157