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