From 40140a17e2770de85a31653cd4b4a73cf31c0eb3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 16 Apr 2013 17:32:03 +1000 Subject: [PATCH] improved initial search and fixed default air rate --- Firmware/radio/loop.c | 13 ++-- Firmware/radio/main.c | 6 +- Firmware/radio/radio.c | 137 ++++++----------------------------------- Firmware/radio/radio.h | 14 +---- 4 files changed, 30 insertions(+), 140 deletions(-) diff --git a/Firmware/radio/loop.c b/Firmware/radio/loop.c index eb4119c..3f62884 100644 --- a/Firmware/radio/loop.c +++ b/Firmware/radio/loop.c @@ -138,11 +138,12 @@ static void one_second(void) one_second_counter++; seconds_since_boot++; if (seconds_last_packet == 0 || (seconds_since_boot - seconds_last_packet) > 10) { - // we are doing initial lock, decrement channel - // more rapidly - fhop_prev(); - radio_set_frequency(fhop_receive_freqency()); - radio_receiver_on(); + if (one_second_counter > 51) { + fhop_prev(); + radio_set_frequency(fhop_receive_freqency()); + radio_receiver_on(); + one_second_counter = 0; + } printf("Searching %lu at %lu Hz\n", (unsigned long)seconds_since_boot, (unsigned long)fhop_receive_freqency()); @@ -355,8 +356,8 @@ serial_loop(void) __pdata uint8_t len; if (delay_expired()) { - one_second(); delay_set_ticks(100); + one_second(); } if (_canary != 42) { diff --git a/Firmware/radio/main.c b/Firmware/radio/main.c index 351331d..950a006 100644 --- a/Firmware/radio/main.c +++ b/Firmware/radio/main.c @@ -233,9 +233,9 @@ radio_init(void) } // And intilise the radio with them. - if (!radio_configure(param_get(PARAM_AIR_SPEED)) && - !radio_configure(param_get(PARAM_AIR_SPEED)) && - !radio_configure(param_get(PARAM_AIR_SPEED))) { + if (!radio_configure() && + !radio_configure() && + !radio_configure()) { panic("radio_configure failed"); } } diff --git a/Firmware/radio/radio.c b/Firmware/radio/radio.c index 1a3f76a..2e707b5 100644 --- a/Firmware/radio/radio.c +++ b/Firmware/radio/radio.c @@ -176,14 +176,6 @@ radio_current_rssi(void) return register_read(EZRADIOPRO_RECEIVED_SIGNAL_STRENGTH_INDICATOR); } -// return the actual air data rate in BPS -// -uint8_t -radio_air_rate(void) -{ - return settings.air_data_rate; -} - // clear the transmit FIFO // static void @@ -326,82 +318,28 @@ __code static const uint8_t reg_index[NUM_RADIO_REGISTERS] = { EZRADIOPRO_FREQUENCY_DEVIATION, // 0x72 }; -// air data rates in kbps units -__code static const uint8_t air_data_rates[NUM_DATA_RATES] = { - 2, 4, 8, 16, 19, 24, 32, 48, 64, 96, 128, 192, 250 -}; - // register table for 915MHz radios -__code static const uint8_t reg_table_915[NUM_RADIO_REGISTERS][NUM_DATA_RATES] = { - {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D}, - {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}, - {0xD0, 0xE8, 0xF4, 0xFA, 0xD0, 0xD0, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30}, - {0xE0, 0x60, 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02}, - {0x10, 0x20, 0x41, 0x83, 0x9D, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA}, - {0x62, 0xC5, 0x89, 0x12, 0x49, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB}, - {0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07}, - {0x23, 0x44, 0x85, 0x08, 0x7D, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF}, - {0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x20, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50}, - {0x10, 0x20, 0x41, 0x83, 0x9D, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40}, - {0x62, 0xC5, 0x89, 0x12, 0x49, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00}, - {0x03, 0x06, 0x0D, 0x1A, 0x0F, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE} -}; - - -// register table for 433MHz radios -__code static const uint8_t reg_table_433[NUM_RADIO_REGISTERS][NUM_DATA_RATES] = { - {0x27, 0x27, 0x27, 0x2E, 0x16, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D}, - {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}, - {0xF4, 0xFA, 0x7D, 0x3F, 0x69, 0xA7, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30}, - {0x20, 0x00, 0x01, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02}, - {0x41, 0x83, 0x06, 0x0C, 0x37, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA}, - {0x89, 0x12, 0x25, 0x4A, 0x4C, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB}, - {0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07}, - {0x85, 0x08, 0x0E, 0x12, 0x72, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF}, - {0x1D, 0x1D, 0x1D, 0x1E, 0x1E, 0x1E, 0x20, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50}, - {0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40}, - {0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00}, - {0x03, 0x06, 0x0D, 0x1A, 0x1E, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE} -}; - -// register table for 470MHz radios -__code static const uint8_t reg_table_470[NUM_RADIO_REGISTERS][NUM_DATA_RATES] = { - {0x2B, 0x2B, 0x2B, 0x2E, 0x16, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D}, - {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}, - {0xF4, 0xFA, 0x7D, 0x3F, 0x69, 0xA7, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30}, - {0x20, 0x00, 0x01, 0x02, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02}, - {0x41, 0x83, 0x06, 0x0C, 0x37, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA}, - {0x89, 0x12, 0x25, 0x4A, 0x4C, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB}, - {0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07}, - {0x85, 0x08, 0x0E, 0x12, 0x72, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF}, - {0x1E, 0x1E, 0x1E, 0x21, 0x21, 0x21, 0x21, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50}, - {0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40}, - {0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00}, - {0x03, 0x06, 0x0D, 0x1A, 0x1E, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE} -}; - -// register table for 868MHz radios -__code static const uint8_t reg_table_868[NUM_RADIO_REGISTERS][NUM_DATA_RATES] = { - {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x05, 0x0B, 0x9A, 0x88, 0x8A, 0x8C, 0x8D}, - {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}, - {0xD0, 0xE8, 0xF4, 0xFA, 0xD3, 0xA7, 0x7D, 0x53, 0x5E, 0x7D, 0x5E, 0x3F, 0x30}, - {0xE0, 0x60, 0x20, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02}, - {0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x06, 0x89, 0x5D, 0x06, 0x5D, 0x0C, 0xAA}, - {0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x25, 0x37, 0x86, 0x25, 0x86, 0x4A, 0xAB}, - {0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x07}, - {0x23, 0x44, 0x85, 0x08, 0x39, 0x8A, 0x0E, 0x18, 0xBB, 0x0E, 0xBB, 0xEA, 0xFF}, - {0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1E, 0x20, 0x30, 0x41, 0x50, 0x50, 0x50, 0x50}, - {0x10, 0x20, 0x41, 0x83, 0x9B, 0xC4, 0x08, 0x0C, 0x10, 0x18, 0x20, 0x31, 0x40}, - {0x62, 0xC5, 0x89, 0x12, 0xA6, 0x9C, 0x31, 0x4A, 0x62, 0x93, 0xC5, 0x27, 0x00}, - {0x03, 0x06, 0x0D, 0x1A, 0x1E, 0x26, 0x33, 0x4D, 0x66, 0x9A, 0xCD, 0xFE, 0xFE} +__code static const uint8_t reg_table_915[NUM_RADIO_REGISTERS] = { + 0x01, + 0x03, + 0xD0, + 0x00, + 0x9D, + 0x49, + 0x02, + 0x7D, + 0x1E, + 0x9D, + 0x49, + 0x0F }; // configure radio based on the air data rate // bool -radio_configure(__pdata uint8_t air_rate) +radio_configure(void) { - __pdata uint8_t i, rate_selection; + __pdata uint8_t i; // disable interrupts register_write(EZRADIOPRO_INTERRUPT_ENABLE_1, 0x00); @@ -438,11 +376,6 @@ radio_configure(__pdata uint8_t air_rate) // set capacitance register_write(EZRADIOPRO_CRYSTAL_OSCILLATOR_LOAD_CAPACITANCE, EZRADIOPRO_OSC_CAP_VALUE); - // see Si1000.pdf section 23.3.8 - if (air_rate > 100) { - register_write(EZRADIOPRO_CHARGEPUMP_CURRENT_TRIMMING_OVERRIDE, 0xC0); - } - // setup frequency and channel spacing set_frequency_registers(settings.frequency); register_write(EZRADIOPRO_FREQUENCY_HOPPING_STEP_SIZE, settings.channel_spacing); @@ -472,22 +405,12 @@ radio_configure(__pdata uint8_t air_rate) register_write(EZRADIOPRO_TX_FIFO_CONTROL_2, TX_FIFO_THRESHOLD_LOW); register_write(EZRADIOPRO_RX_FIFO_CONTROL, RX_FIFO_THRESHOLD_HIGH); - settings.preamble_length = 8; - - register_write(EZRADIOPRO_PREAMBLE_LENGTH, settings.preamble_length); // nibbles + register_write(EZRADIOPRO_PREAMBLE_LENGTH, 8); // nibbles register_write(EZRADIOPRO_PREAMBLE_DETECTION_CONTROL, 4<<3); // setup minimum output power during startup radio_set_transmit_power(0); - // work out which register table column we will use - for (i = 0; i < NUM_DATA_RATES - 1; i++) { - if (air_data_rates[i] >= air_rate) break; - } - rate_selection = i; - - settings.air_data_rate = air_data_rates[rate_selection]; - register_write(EZRADIOPRO_MODULATION_MODE_CONTROL_1, 0x00); register_write(EZRADIOPRO_MODULATION_MODE_CONTROL_2, 0x23); @@ -498,33 +421,11 @@ radio_configure(__pdata uint8_t air_rate) // this follows the recommendation in the register spreadsheet // for AFC enabled and manchester disabled - if (settings.air_data_rate < 200) { - register_write(EZRADIOPRO_AFC_TIMING_CONTROL, 0x0A); - } else { - register_write(EZRADIOPRO_AFC_TIMING_CONTROL, 0x02); - } + register_write(EZRADIOPRO_AFC_TIMING_CONTROL, 0x0A); // set the registers from the tables - if (g_board_frequency == FREQ_433) { - for (i = 0; i < NUM_RADIO_REGISTERS; i++) { - register_write(reg_index[i], - reg_table_433[i][rate_selection]); - } - } else if (g_board_frequency == FREQ_470) { - for (i = 0; i < NUM_RADIO_REGISTERS; i++) { - register_write(reg_index[i], - reg_table_470[i][rate_selection]); - } - } else if (g_board_frequency == FREQ_868) { - for (i = 0; i < NUM_RADIO_REGISTERS; i++) { - register_write(reg_index[i], - reg_table_868[i][rate_selection]); - } - } else { - for (i = 0; i < NUM_RADIO_REGISTERS; i++) { - register_write(reg_index[i], - reg_table_915[i][rate_selection]); - } + for (i = 0; i < NUM_RADIO_REGISTERS; i++) { + register_write(reg_index[i], reg_table_915[i]); } return true; diff --git a/Firmware/radio/radio.h b/Firmware/radio/radio.h index 80650d6..51e81a6 100644 --- a/Firmware/radio/radio.h +++ b/Firmware/radio/radio.h @@ -179,12 +179,9 @@ extern uint8_t radio_get_channel(void); /// configure the radio for a given air data rate /// -/// @param air_rate The air data rate, in bits per second -/// Note that this value is rounded up to -/// the next supported value /// @return True if the radio was successfully configured. /// -extern bool radio_configure(__pdata uint8_t air_rate); +extern bool radio_configure(void); /// configure the radio network ID /// @@ -208,13 +205,6 @@ extern uint8_t radio_last_rssi(void); /// extern uint8_t radio_current_rssi(void); -/// return the air data rate -/// -/// @return The value passed to the last successful call -/// to radio_configure -/// -extern uint8_t radio_air_rate(void); - /// set the radio transmit power (in dBm) /// /// @param power The desired transmit power in dBm @@ -242,10 +232,8 @@ void MAVLink_report(void); struct radio_settings { uint32_t frequency; uint32_t channel_spacing; - uint8_t air_data_rate; uint8_t current_channel; uint8_t transmit_power; - uint8_t preamble_length; // in nibbles }; extern __pdata struct radio_settings settings;