diff --git a/tracker/software/cfg/pp10a/portab.c b/tracker/software/cfg/pp10a/portab.c index 5071f33c..0a8b63e4 100644 --- a/tracker/software/cfg/pp10a/portab.c +++ b/tracker/software/cfg/pp10a/portab.c @@ -32,10 +32,7 @@ /* Module exported variables. */ /*===========================================================================*/ -typedef struct SysProviders { - -} providers_t; - +/* Definition of radio IO for radio on this board. */ const si446x_mcucfg_t radio1_cfg = { .gpio0 = LINE_RADIO_GPIO0, .gpio1 = LINE_RADIO_GPIO1, @@ -47,10 +44,13 @@ const si446x_mcucfg_t radio1_cfg = { .spi = PKT_RADIO_SPI }; +/* Definition of radio specific data for radio on this board. */ si446x_data_t radio1_dat = { .lastTemp = 0x7FFF + // TODO: Move part and func structs into here and add functions to get }; +/* Radios on this board. */ const radio_config_t radio_list[] = { { /* Radio #1 */ .unit = PKT_RADIO_1, @@ -91,22 +91,6 @@ const SerialConfig debug_config = { /* Module exported functions. */ /*===========================================================================*/ -/** - * Get number of radios for this board type. - */ -uint8_t pktGetNumRadios(void) { - uint8_t i = 0; - while(radio_list[i++].unit != PKT_RADIO_NONE); - return --i; -} - -/** - * Return pointer to radio object array. - */ -const radio_config_t *pktGetRadioList(void) { - return radio_list; -} - void pktConfigSerialDiag(void) { #if ENABLE_EXTERNAL_I2C == FALSE /* USART3 TX. */ @@ -126,29 +110,10 @@ ioline_t pktSetLineModeICU(const radio_unit_t radio) { return LINE_ICU; } -/** - * TODO: Move this into pktradio.c or make it an Si446x function in si446x.c - * The GPIO assignments per radio should be in the radio record. - */ -/*ioline_t pktSetLineModeRadioGPIO1(const radio_unit_t radio) { - (void)radio; - palSetLineMode(LINE_RADIO_GPIO1, PAL_MODE_INPUT_PULLDOWN); - return LINE_RADIO_GPIO1; -}*/ - -/** - * TODO: Move this into pktradio.c or make it an Si446x function in si446x.c - * The GPIO assignments per radio should be in the radio record. - */ -/*ioline_t pktSetLineModeRadioGPIO0(const radio_unit_t radio) { - (void)radio; - palSetLineMode(LINE_RADIO_GPIO0, PAL_MODE_INPUT_PULLDOWN); - return LINE_RADIO_GPIO0; -}*/ - /* * Read GPIO that are used for: - * a) general use or + * a) general use + * or * b) UART and s/w I2C external. * * @return State of lines regardless of general or specific use. diff --git a/tracker/software/cfg/pp10a/portab.h b/tracker/software/cfg/pp10a/portab.h index f5a3c5bc..d07ab243 100644 --- a/tracker/software/cfg/pp10a/portab.h +++ b/tracker/software/cfg/pp10a/portab.h @@ -264,6 +264,7 @@ typedef struct radioConfig { extern const radio_band_t band_2m; extern const radio_band_t band_70cm; +extern const radio_config_t radio_list[]; #ifdef __cplusplus extern "C" { @@ -278,12 +279,7 @@ extern "C" { void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len); int dbgPrintf(uint8_t level, const char *format, ...); void pktWrite(uint8_t *buf, uint32_t len); - //void pktPowerUpRadio(radio_unit_t radio); - //void pktPowerDownRadio(radio_unit_t radio); - radio_freq_t pktCheckAllowedFrequency(radio_unit_t radio, radio_freq_t freq); uint8_t pktReadIOlines(void); - uint8_t pktGetNumRadios(void); - const radio_config_t *pktGetRadioList(void); #ifdef __cplusplus } #endif diff --git a/tracker/software/cfg/pp10b/portab.c b/tracker/software/cfg/pp10b/portab.c index f5e4757e..977acf94 100644 --- a/tracker/software/cfg/pp10b/portab.c +++ b/tracker/software/cfg/pp10b/portab.c @@ -32,10 +32,7 @@ /* Module exported variables. */ /*===========================================================================*/ -typedef struct SysProviders { - -} providers_t; - +/* Definition of PKT_RADIO_1. */ const si446x_mcucfg_t radio1_cfg = { .gpio0 = LINE_RADIO_GPIO0, .gpio1 = LINE_RADIO_GPIO1, @@ -49,8 +46,10 @@ const si446x_mcucfg_t radio1_cfg = { si446x_data_t radio1_dat = { .lastTemp = 0x7FFF + // TODO: Move part and func structs into here and add functions to get }; +/* Radios on this board. */ const radio_config_t radio_list[] = { { /* Radio #1 */ .unit = PKT_RADIO_1, @@ -90,22 +89,6 @@ const SerialConfig debug_config = { /* Module exported functions. */ /*===========================================================================*/ -/** - * Get number of radios for this board type. - */ -uint8_t pktGetNumRadios(void) { - uint8_t i = 0; - while(radio_list[i++].unit != PKT_RADIO_NONE); - return --i; -} - -/** - * Return pointer to radio object array. - */ -const radio_config_t *pktGetRadioList(void) { - return radio_list; -} - void pktConfigSerialDiag(void) { /* USART3 TX. */ palSetLineMode(LINE_USART3_TX, PAL_MODE_ALTERNATE(7)); @@ -123,29 +106,10 @@ ioline_t pktSetLineModeICU(const radio_unit_t radio) { return LINE_ICU; } -/** - * TODO: Move this into pktradio.c or make it an Si446x function in si446x.c - * The GPIO assignments per radio should be in the radio record. - */ -/*ioline_t pktSetLineModeRadioGPIO1(const radio_unit_t radio) { - (void)radio; - palSetLineMode(LINE_RADIO_GPIO1, PAL_MODE_INPUT_PULLDOWN); - return LINE_RADIO_GPIO1; -}*/ - -/** - * TODO: Move this into pktradio.c or make it an Si446x function in si446x.c - * The GPIO assignments per radio should be in the radio record. - */ -/*ioline_t pktSetLineModeRadioGPIO0(const radio_unit_t radio) { - (void)radio; - palSetLineMode(LINE_RADIO_GPIO0, PAL_MODE_INPUT_PULLDOWN); - return LINE_RADIO_GPIO0; -}*/ - /* * Read GPIO that are used for: - * a) general use or + * a) general use + * or * b) UART and s/w I2C external. * * @return State of lines regardless of general or specific use. @@ -160,7 +124,6 @@ uint8_t pktReadIOlines() { void pktSerialStart(void) { #if ENABLE_SERIAL_DEBUG == TRUE pktConfigSerialDiag(); - //pktConfigSerialPkt(); sdStart(SERIAL_CFG_DEBUG_DRIVER, &debug_config); #endif /* Setup diagnostic resource access semaphore. */ diff --git a/tracker/software/cfg/pp10b/portab.h b/tracker/software/cfg/pp10b/portab.h index b2f776d4..99b1dda8 100644 --- a/tracker/software/cfg/pp10b/portab.h +++ b/tracker/software/cfg/pp10b/portab.h @@ -261,6 +261,7 @@ typedef struct radioConfig { extern const radio_band_t band_2m; extern const radio_band_t band_70cm; +extern const radio_config_t radio_list[]; #ifdef __cplusplus extern "C" { @@ -275,12 +276,7 @@ extern "C" { void dbgWrite(uint8_t level, uint8_t *buf, uint32_t len); int dbgPrintf(uint8_t level, const char *format, ...); void pktWrite(uint8_t *buf, uint32_t len); - void pktPowerUpRadio(radio_unit_t radio); - void pktPowerDownRadio(radio_unit_t radio); - radio_freq_t pktCheckAllowedFrequency(radio_unit_t radio, radio_freq_t freq); uint8_t pktReadIOlines(void); - uint8_t pktGetNumRadios(void); - const radio_config_t *pktGetRadioList(void); #ifdef __cplusplus } #endif diff --git a/tracker/software/source/config/config.c b/tracker/software/source/config/config.c index e098699f..da8f143a 100644 --- a/tracker/software/source/config/config.c +++ b/tracker/software/source/config/config.c @@ -25,7 +25,7 @@ const conf_t conf_flash_default = { .cca = 0x4F, }, // App identity - .call = "VK2GJ-13", + .call = "VK2GJ-12", .path = "WIDE1-1", .symbol = SYM_ANTENNA, .aprs_msg = true, // Enable APRS message reception on this call sign @@ -93,7 +93,7 @@ const conf_t conf_flash_default = { .cca = 0x4F }, // App identity - .call = "VK2GJ-13", + .call = "VK2GJ-12", .path = "", // Image settings @@ -128,7 +128,7 @@ const conf_t conf_flash_default = { .rx = { .svc_conf = { // The packet receive service is enabled if true - // Receive is resumed after any transmission + // Receive is paused and resumed by transmission .active = true, .init_delay = TIME_S2I(20) }, @@ -153,7 +153,7 @@ const conf_t conf_flash_default = { .cca = 0x4F }, // Digipeat transmission identity - .call = "VK2GJ-6", + .call = "VK2GJ-5", .path = "WIDE2-1", .symbol = SYM_DIGIPEATER, .beacon = { diff --git a/tracker/software/source/drivers/si446x.c b/tracker/software/source/drivers/si446x.c index d02c37d5..2cc0b404 100644 --- a/tracker/software/source/drivers/si446x.c +++ b/tracker/software/source/drivers/si446x.c @@ -42,10 +42,11 @@ static const uint8_t Radio_Patch_Data_Array[] = { 0x00 }; -/* TODO: Set the CS line dynamically per radio. */ -static /*const*/ SPIConfig ls_spicfg = { - .ssport = PAL_PORT(LINE_RADIO_CS), - .sspad = PAL_PAD(LINE_RADIO_CS), +/* + * @brief The SPI configuration. + * @note the CS line is set dynamically per radio. + */ +static SPIConfig ls_spicfg = { .cr1 = SPI_CR1_MSTR }; @@ -170,8 +171,6 @@ static bool Si446x_readBoot(const radio_unit_t radio, const uint8_t* txData, uint32_t txlen, uint8_t* rxData, uint32_t rxlen) { - /* TODO: Add radio unit ID and get SPI configuration accordingly. */ - //(void)radio; /* Acquire bus and get SPI Driver object. */ SPIDriver *spip = Si446x_spiSetupBus(radio, &ls_spicfg); @@ -231,8 +230,6 @@ static bool Si446x_read(const radio_unit_t radio, const uint8_t* txData, uint32_t txlen, uint8_t* rxData, uint32_t rxlen) { - /* TODO: Add radio unit ID and get SPI configuration accordingly. */ - //(void)radio; /* Acquire bus and then start SPI. */ SPIDriver *spip = Si446x_spiSetupBus(radio, &ls_spicfg); spiStart(spip, &ls_spicfg); @@ -345,8 +342,6 @@ static bool Si446x_init(const radio_unit_t radio) { packet_svc_t *handler = pktGetServiceObject(radio); - //chDbgAssert(handler != NULL, "invalid radio ID"); - /* * Set MCU GPIO for radio GPIO1 (CTS). * Execute radio startup sequence. @@ -569,8 +564,6 @@ static bool Si446x_init(const radio_unit_t radio) { * Intialize radio only if it has been shutdown. */ bool Si446x_conditional_init(const radio_unit_t radio) { - - packet_svc_t *handler = pktGetServiceObject(radio); if(!handler->radio_init) @@ -579,7 +572,8 @@ bool Si446x_conditional_init(const radio_unit_t radio) { } /* - * + * Set radio NCO registers for frequency. + * This function also collects the chip temperature data. */ bool Si446x_setBandParameters(const radio_unit_t radio, radio_freq_t freq, @@ -588,7 +582,10 @@ bool Si446x_setBandParameters(const radio_unit_t radio, if(freq == FREQ_APRS_DYNAMIC) { /* Get transmission frequency by geofencing. */ freq = getAPRSRegionFrequency(); - /* If using geofence step is not set. */ + /* If using geofence step is not set. + * TODO: Get step from the config for radio. + * Add new function Si446x_getBand(...) + */ step = 0; } /* Check frequency is in range of chip. */ @@ -605,6 +602,11 @@ bool Si446x_setBandParameters(const radio_unit_t radio, if(freq < 239000000UL) {outdiv = 16; band = 4;} if(freq < 177000000UL) {outdiv = 24; band = 5;} + /* TODO: Is this redundant now? + * The radio is set in sleep versus shutdown when inactive (not receiving). + * Shutdown is only used when the channel is completely closed. + * The radio is initialized again when the channel is (re)opened. + */ Si446x_conditional_init(radio); /* Set the band parameter. */ diff --git a/tracker/software/source/pkt/managers/pktradio.c b/tracker/software/source/pkt/managers/pktradio.c index b8f65885..035f200c 100644 --- a/tracker/software/source/pkt/managers/pktradio.c +++ b/tracker/software/source/pkt/managers/pktradio.c @@ -582,8 +582,8 @@ void pktSubmitRadioTask(const radio_unit_t radio, * @brief Called by transmit threads to schedule release after completing. * @post A thread release task is posted to the radio manager queue. * - * @param[in] radio radio unit ID. - * @param[in] thread thread reference. + * @param[in] rto reference to radio task object. + * @param[in] thread thread reference of thread terminating. * * @api */ @@ -602,7 +602,6 @@ void pktLLDradioSendComplete(radio_task_object_t *rto, /** * @brief Acquire exclusive access to radio. - * @notes returns when radio unit acquired. * * @param[in] radio radio unit ID. * @param[in] timeout time to wait for acquisition. @@ -633,8 +632,24 @@ void pktReleaseRadio(const radio_unit_t radio) { chBSemSignal(&handler->radio_sem); } +/** + * Return pointer to radio object array. + */ +const radio_config_t *pktGetRadioList(void) { + return radio_list; +} + +/** + * Get number of radios for this board type. + */ +uint8_t pktGetNumRadios(void) { + uint8_t i = 0; + while(radio_list[i++].unit != PKT_RADIO_NONE); + return --i; +} + /* - * TODO: Refactor this to use an array of strings. + * */ int pktDisplayFrequencyCode(const radio_freq_t code, char *buf, size_t size) { char* str = NULL; @@ -727,7 +742,8 @@ radio_freq_t pktGetReceiveOperatingFrequency(const radio_unit_t radio) { /** * @brief Validate an operating frequency in Hz. - * @pre Resolve special frequency codes before calling this function. + * @notes Checks absolute frequencies only. + * @notes Resolve special frequency codes before calling. * * @param[in] radio Radio unit ID. * @param[in] freq Radio frequency in Hz. @@ -737,8 +753,10 @@ radio_freq_t pktGetReceiveOperatingFrequency(const radio_unit_t radio) { * @retval FREQ_RADIO_INVALID if frequency or radio ID is invalid * * @api + * + * TODO: Return pointer to band or NULL if invalid. */ -radio_freq_t pktCheckAllowedFrequency(const radio_unit_t radio, +radio_band_t *pktCheckAllowedFrequency(const radio_unit_t radio, radio_freq_t freq) { /* Check validity. */ uint8_t radios = pktGetNumRadios(); @@ -751,11 +769,11 @@ radio_freq_t pktCheckAllowedFrequency(const radio_unit_t radio, continue; if(list->bands[x]->start <= freq && freq < list->bands[x]->end) - return freq; + return list->bands[x]; } /* End for bands */ } /* if(!unit == radio) */ } /* End for radios*/ - return FREQ_RADIO_INVALID; + return NULL; } /** @@ -774,16 +792,16 @@ const radio_config_t *pktGetRadioData(radio_unit_t radio) { /** * @brief Compute an operating frequency. - * @notes All special frequency codes are resolved to an actual frequency. + * @notes All special frequency codes are resolved to a frequency in Hz. * * @param[in] radio Radio unit ID. * @param[in] base_freq Radio base frequency in Hz. * @param[in] step Radio channel step size in Hz. * @param[in] chan Radio channel number. * - * @return operating frequency - * @retval an absolute operating frequency in Hz. - * @retval FREQ_RADIO_INVALID if frequency or radio ID is invalid + * @return operating frequency in Hz. + * @retval an absolute operating frequency in Hz. + * @retval FREQ_RADIO_INVALID if frequency or radio ID is invalid. * * @api */ @@ -826,7 +844,10 @@ radio_freq_t pktComputeOperatingFrequency(const radio_unit_t radio, /* Calculate operating frequency. */ radio_freq_t op_freq = base_freq + (step * chan); - return pktCheckAllowedFrequency(radio, op_freq); + if(pktCheckAllowedFrequency(radio, op_freq) != NULL) { + return op_freq; + } + return FREQ_RADIO_INVALID; } /** diff --git a/tracker/software/source/pkt/managers/pktradio.h b/tracker/software/source/pkt/managers/pktradio.h index d4813ae9..9308cd81 100644 --- a/tracker/software/source/pkt/managers/pktradio.h +++ b/tracker/software/source/pkt/managers/pktradio.h @@ -111,8 +111,6 @@ struct radioTask { radio_task_cb_t callback; msg_t result; thread_t *thread; - /* TODO: Create thread name in the radio unit thread itself. */ - //char tx_thd_name[16]; packet_svc_t *handler; packet_t packet_out; uint8_t tx_power; @@ -140,7 +138,9 @@ extern "C" { thread_t *thread); msg_t pktAcquireRadio(const radio_unit_t radio, sysinterval_t timeout); void pktReleaseRadio(const radio_unit_t radio); - radio_freq_t pktCheckAllowedFrequency(const radio_unit_t radio, + const radio_config_t *pktGetRadioList(void); + uint8_t pktGetNumRadios(void); + radio_band_t *pktCheckAllowedFrequency(const radio_unit_t radio, radio_freq_t freq); radio_freq_t pktComputeOperatingFrequency(const radio_unit_t radio, radio_freq_t base_freq, @@ -153,7 +153,6 @@ extern "C" { bool pktLLDradioResumeReceive(const radio_unit_t radio); bool pktLLDradioSendPacket(radio_task_object_t *rto); void pktLLDradioCaptureRSSI(const radio_unit_t radio); - //bool pktLLDradioExitShutdown(const radio_unit_t radio); bool pktLLDradioInit(const radio_unit_t radio); void pktLLDradioStandby(const radio_unit_t radio); void pktLLDradioShutdown(const radio_unit_t radio);