/** **************************************************************************************** * @brief conditionally_run_radio_cals(). Runs conditionally (time + temperature) RF and coarse calibration. ltime and temp changes) RF and coarse calibration * * @return void **************************************************************************************** */ void conditionally_run_radio_cals(void) { uint16_t count, count_diff; uint8_t force_rf_cal = 0; bool rf_cal_stat; uint32_t current_time = lld_evt_time_get(); if (current_time < last_temp_time) { last_temp_time = 0; } if (force_rf_cal) { force_rf_cal = 0; last_temp_time = current_time; last_temp_count = get_rc16m_count(); #if LUT_PATCH_ENABLED pll_vcocal_LUT_InitUpdate(LUT_UPDATE); //Update pll look up table #endif rf_cal_stat = rf_calibration(); if ( rf_cal_stat == false) force_rf_cal = 1; return; } if ( (current_time - last_temp_time) >= 3200) //2 sec { last_temp_time = current_time; count = get_rc16m_count(); // Estimate the RC16M frequency if (count > last_temp_count) count_diff = count - last_temp_count; else count_diff = last_temp_count - count ; if (count_diff >= 24)// If corresponds to 5 C degrees difference { // Update the value of last_count last_temp_count = count; #if LUT_PATCH_ENABLED pll_vcocal_LUT_InitUpdate(LUT_UPDATE); //Update pll look up table #endif rf_cal_stat = rf_calibration(); if ( rf_cal_stat == false) force_rf_cal = 1; // Perform the readio calibrations } } }
void rf_init_func(struct rwip_rf_api *api) { uint32 tmp32 = 0; uint8 idx = 0; uint8 temp_freq_tbl[EM_BLE_FREQ_TABLE_LEN]; // Initialize the RF driver API structure api->reg_rd = rf_reg_rd; api->reg_wr = rf_reg_wr; api->txpwr_dbm_get = rf_txpwr_dbm_get; //api->txpwr_max = RPL_POWER_MAX; api->sleep = rf_sleep; api->reset = rf_reset; #ifdef CFG_BLE api->isr = RADIOCNTL_Handler; api->force_agc_enable = rf_force_agc_enable; #endif //CFG_BLE api->rssi_convert = rf_rssi_convert; #ifdef CFG_BT api->txpwr_inc = rf_txpwr_inc; api->txpwr_dec = rf_txpwr_dec; api->txpwr_epc_req = rf_txpwr_epc_req; api->txpwr_cs_get = rf_txpwr_cs_get; api->rssi_high_thr = (uint8_t)RPL_RSSI_20dB_THRHLD; api->rssi_low_thr = (uint8_t)RPL_RSSI_60dB_THRHLD; api->rssi_interf_thr = (uint8_t)RPL_RSSI_70dB_THRHLD; #ifdef CFG_BTCORE_30 api->wakeup_delay = RPL_WK_UP_DELAY; #endif //CFG_BTCORE_30 api->skew = RPL_RADIO_SKEW; #endif //CFG_BT // CLK_FREQ_TRIM_REG initialization was moved to main_func() in arch_main.c // The initialization of this register is done by the Boot ROM code if a valid // value has been written to the corresponding position in the OTP header by // the customer. // main_func() will write this register with a default value and the customer // must remove this code when he has written the OTP header. SetBits32(&tmp32, RTRIP_DELAY, 7); SetBits32(&tmp32, TXPWRDN, 0x5); SetBits32(&tmp32, RXPWRUP, RXPWRUP_VAL); SetBits32(&tmp32, TXPWRUP, TXPWRUP_VAL); SetWord32(BLE_RADIOPWRUPDN_REG,tmp32); SetBits32(BLE_RADIOCNTL0_REG, DPCORR_EN, 0); //THIS MAY NOT BE '1', THEN WE MISS 12 BITS IN THE SYNCWORD DURING A RX BURST SetBits32(BLE_RADIOCNTL1_REG, XRFSEL, 3); SetBits32(BLE_CNTL2_REG, SW_RPL_SPI ,0); SetBits32(BLE_CNTL2_REG, BB_ONLY,0); while(idx < EM_BLE_FREQ_TABLE_LEN) { temp_freq_tbl[idx] = idx ; idx++; } em_ble_burst_wr(&temp_freq_tbl[0], EM_BLE_FT_OFFSET, EM_BLE_FREQ_TABLE_LEN); rf_regs(); last_temp_count = get_rc16m_count(); #if LUT_PATCH_ENABLED pll_vcocal_LUT_InitUpdate(LUT_INIT); #endif rf_calibration(); }