static void gzp_preload_ack(uint8_t* src, uint8_t length, uint8_t pipe) { gzll_goto_idle(); gzll_tx_fifo_flush(); gzll_ack_payload_write(src, length, pipe); gzll_rx_start(); }
static void gzp_process_address_req(uint8_t* gzp_req) { uint8_t temp_rx_pipes, temp_host_mode; uint8_t pairing_resp[GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH]; gzp_address_exchanged_f = false; gzll_goto_idle(); temp_rx_pipes = gzll_get_param(GZLL_PARAM_RX_PIPES); temp_host_mode = gzll_get_param(GZLL_PARAM_HOST_MODE); // If requesting Device within close proximity if(gzll_rx_power_high()) { gzll_set_param(GZLL_PARAM_RX_PIPES, 0); gzll_set_param(GZLL_PARAM_HOST_MODE, 0); gzll_set_param(GZLL_PARAM_RX_TIMEOUT, GZP_CLOSE_PROXIMITY_BACKOFF_RX_TIMEOUT); gzll_rx_fifo_flush(); // Start "proximity" back off period gzll_rx_start(); while(gzll_get_state() != GZLL_IDLE) ; // Build pairing response packet pairing_resp[0] = GZP_CMD_HOST_ADDRESS_RESP; gzp_host_chip_id_read(&pairing_resp[GZP_CMD_HOST_ADDRESS_RESP_ADDRESS], GZP_SYSTEM_ADDRESS_WIDTH); gzll_ack_payload_write(&pairing_resp[0], GZP_CMD_HOST_ADDRESS_RESP_PAYLOAD_LENGTH, 0); gzll_set_param(GZLL_PARAM_RX_TIMEOUT, GZP_STEP1_RX_TIMEOUT); // Enable only pairing pipe when waiting for pairing request step 1 gzll_set_param(GZLL_PARAM_RX_PIPES, (1 << GZP_PAIRING_PIPE)); gzll_rx_start(); while(gzll_get_state() != GZLL_IDLE) { if(gzll_rx_fifo_read(&gzp_req[0], NULL, NULL)) { // Validate step 1 of pairing request if(gzp_req[0] == GZP_CMD_HOST_ADDRESS_FETCH) { gzp_address_exchanged_f = true; } } } gzll_tx_fifo_flush(); gzll_rx_fifo_flush(); gzll_set_param(GZLL_PARAM_RX_TIMEOUT, 0); gzll_set_param(GZLL_PARAM_RX_PIPES, temp_rx_pipes); gzll_set_param(GZLL_PARAM_HOST_MODE, temp_host_mode); // Return to normal operation gzll_rx_start(); } else { gzll_set_param(GZLL_PARAM_RX_PIPES, temp_rx_pipes & ~(1 << GZP_PAIRING_PIPE)); gzll_set_param(GZLL_PARAM_RX_TIMEOUT, GZP_NOT_PROXIMITY_BACKOFF_RX_TIMEOUT); // Start "not proximity" backoff period gzll_rx_start(); } }
bool com_execute() { xdata bool retval = false; xdata uint8_t user_data[32]; xdata uint16_t temp; xdata uint8_t t_length, t_pipe, curr_gzll_state; static xdata uint8_t prev_gzll_state = 0xff; // If Device operation if(device_mode) { // Get Gazell state curr_gzll_state = gzll_get_state(); if(curr_gzll_state == GZLL_IDLE) { // If state transition from TRANSMIT to IDLE if(prev_gzll_state == GZLL_DEVICE_ACTIVE) { retval = true; if(gzll_tx_success()) { statistics[TX_PL_CNT]++; statistics[TX_BYTE_CNT] += app_setup[TX_PL_LENGTH]; temp = gzll_get_tx_attempts(); statistics[TX_TRY_CNT] += temp; statistics[AVG_TX_TRIES] = (uint16_t)(((float)statistics[TX_TRY_CNT] * 100) / statistics[TX_PL_CNT] ); if(statistics[MAX_TX_TRIES] < temp) { statistics[MAX_TX_TRIES] = temp; } statistics[TX_CH_SWITCHES] += gzll_get_tx_channel_switches(); } if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe)) { statistics[RX_PL_CNT]++; statistics[RX_BYTE_CNT] += t_length; } } if(radio_run) { EA = 0; if(cnt_1ms >= app_setup[TX_PACKET_INTERVAL] ) { gzll_timer_tick = false; cnt_1ms = 0; EA = 1; while(!gzll_timer_tick) // Improves synchronization to start in synch with protocol timer ; gzll_tx_data(user_data, app_setup[TX_PL_LENGTH], app_setup[TX_PIPE]); curr_gzll_state = GZLL_DEVICE_ACTIVE; } EA = 1; } prev_gzll_state = curr_gzll_state; } } // Host operation else { if(gzll_rx_fifo_read(user_data, &t_length, &t_pipe)) { retval = true; statistics[RX_PL_CNT]++; statistics[RX_BYTE_CNT] += t_length; t_length = app_setup[ACK_PL_LENGTH]; if(t_length) { if(gzll_ack_payload_write(user_data, t_length, t_pipe)) { statistics[TX_PL_CNT]++; statistics[TX_BYTE_CNT] += t_length; } } } } return retval; }