static inline bool read_timestamp(uint8_t addr, uint64_t *data) { switch (addr) { case NIOS_PKT_8x64_TIMESTAMP_RX: *data = time_tamer_read(BLADERF_MODULE_RX); break; case NIOS_PKT_8x64_TIMESTAMP_TX: *data = time_tamer_read(BLADERF_MODULE_TX); break; default: DBG("Invalid addr: 0x%x\n", addr); return false; } return true; }
void pkt_retune2(struct pkt_buf *b) { int status = -1; bladerf_module module; uint8_t flags; uint64_t timestamp; uint64_t start_time; uint64_t end_time; uint64_t duration = 0; uint16_t nios_profile; uint8_t rffe_profile; uint8_t port; uint8_t spdt; fastlock_profile *profile; flags = NIOS_PKT_RETUNE2_RESP_FLAG_SUCCESS; nios_pkt_retune2_unpack(b->req, &module, ×tamp, &nios_profile, &rffe_profile, &port, &spdt); switch (module) { case BLADERF_MODULE_RX: profile = &fastlocks_rx[nios_profile]; break; case BLADERF_MODULE_TX: profile = &fastlocks_tx[nios_profile]; break; default: profile = NULL; } if (profile == NULL) { INCREMENT_ERROR_COUNT(); status = -1; } else { /* Update the fastlock profile data */ profile->profile_num = rffe_profile; profile->port = port; profile->spdt = spdt; } start_time = time_tamer_read(module); if (timestamp == NIOS_PKT_RETUNE2_NOW) { /* Fire off this retune operation now */ switch (module) { case BLADERF_MODULE_RX: case BLADERF_MODULE_TX: /* Load the profile data into RFFE memory */ profile_load(module, profile); /* Activate the fast lock profile for this retune */ profile_activate(module, profile); flags |= NIOS_PKT_RETUNE2_RESP_FLAG_TSVTUNE_VALID; status = 0; break; default: INCREMENT_ERROR_COUNT(); status = -1; } } else if (timestamp == NIOS_PKT_RETUNE2_CLEAR_QUEUE) { switch (module) { case BLADERF_MODULE_RX: reset_queue(&rx_queue); status = 0; break; case BLADERF_MODULE_TX: reset_queue(&tx_queue); status = 0; break; default: INCREMENT_ERROR_COUNT(); status = -1; } } else { uint8_t queue_size; switch (module) { case BLADERF_MODULE_RX: queue_size = enqueue_retune(&rx_queue, profile, timestamp); profile_load_scheduled(&rx_queue, module); break; case BLADERF_MODULE_TX: queue_size = enqueue_retune(&tx_queue, profile, timestamp); profile_load_scheduled(&tx_queue, module); break; default: INCREMENT_ERROR_COUNT(); queue_size = QUEUE_FULL; } if (queue_size == QUEUE_FULL) { status = -1; } else { status = 0; } } end_time = time_tamer_read(module); duration = end_time - start_time; if (status != 0) { flags &= ~(NIOS_PKT_RETUNE2_RESP_FLAG_SUCCESS); } nios_pkt_retune2_resp_pack(b->resp, duration, flags); }