diff --git a/conswrapper.c b/conswrapper.c index ea6183f..0422e90 100644 --- a/conswrapper.c +++ b/conswrapper.c @@ -48,6 +48,10 @@ #include #include #include "./lib/assert.h" +#include "piodco/piodco.h" +#include "protos.h" + +extern PioDco DCO; /// @brief Console commands manager. Currently available: /// @brief HELP - Usage. @@ -71,16 +75,103 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params) printf("-\n"); printf(" HELP - this page.\n"); printf("-\n"); - printf(" SETFREQ [X] - set output frequency in Hz.\n"); - printf(" Example: SETFREQ 14074010 - set output frequency to 14.074010 MHz.\n"); + printf(" STATUS - print system status.\n"); printf("-\n"); - printf(" SWITCH [X] - switch generation to ON or OFF state.\n"); - printf(" Example: SWITCH ON - switch generation to ON state.\n"); + printf(" SETFREQ f - set output frequency f in Hz.\n"); + printf(" example: SETFREQ 14074010 - set output frequency to 14.074145 MHz.\n"); + printf("-\n"); + printf(" SWITCH s - enable/disable generation.\n"); + printf(" example: SWITCH ON - enable generation.\n"); } else if(strstr(cmd, "SETFREQ")) { + if(2 != narg) + { + PushErrorMessage(-1); + return; + } + const uint32_t ui32frq = atol(params); + if(ui32frq < 1000000L || ui32frq > 32333333) + { + PushErrorMessage(-11); + return; + } + + PioDCOSetFreq(&DCO, ui32frq, 0U); + printf("\nFrequency is set to %lu Hz", ui32frq); + + } else if(strstr(cmd, "STATUS")) + { + PushStatusMessage(); } else if(strstr(cmd, "SWITCH")) { - + if(2 != narg) + { + PushErrorMessage(-1); + return; + } + if(strstr(params, "ON")) + { + PioDCOStart(&DCO); + printf("\nOutput is enabled"); + } else if(strstr(params, "OFF")) + { + PioDCOStop(&DCO); + printf("\nOutput is disabled"); + } + } +} + +void PushErrorMessage(int id) +{ + switch(id) + { + case -1: + printf("\nInvalid argument"); + break; + + case -11: + printf("\nInvalid frequency"); + break; + + default: + printf("\nUnknown error"); + break; + } +} + +void PushStatusMessage(void) +{ + printf("\nPico-hf-oscillator system status\n"); + + printf("Working freq: %lu Hz + %ld milliHz\n", DCO._ui32_frq_hz, DCO._ui32_frq_millihz); + + printf("Output is "); + if(DCO._is_enabled) + { + printf("ENABLED"); + } + else + { + printf("DISABLED"); + } + + //printf("\nGPS subsystem info"); + if(DCO._pGPStime) + { + printf("\nGPS UART id %d", DCO._pGPStime->_uart_id); + printf("\nGPS UART baud %d", DCO._pGPStime->_uart_baudrate); + printf("\nGPS PPS GPIO pin %d", DCO._pGPStime->_pps_gpio); + printf("\nGPS error count %ld", DCO._pGPStime->_i32_error_count); + printf("\nGPS NAV solution flag %u", DCO._pGPStime->_time_data._u8_is_solution_active); + printf("\nGPS GPRMC receive count %u", DCO._pGPStime->_time_data._u32_nmea_gprmc_count); + printf("\nGPS PPS period %llu", DCO._pGPStime->_time_data._u64_pps_period_1M); + printf("\nGPS frequency shift %lld ppb", DCO._pGPStime->_time_data._i32_freq_shift_ppb); + printf("\nGPS lat %lld deg1e5", DCO._pGPStime->_time_data._i64_lat_100k); + printf("\nGPS lon %lld deg1e5", DCO._pGPStime->_time_data._i64_lon_100k); + } + else + { + printf("\nGPS subsystem hasn't been initialized."); } } diff --git a/piodco/piodco.c b/piodco/piodco.c index 1a13e45..e5f3b37 100644 --- a/piodco/piodco.c +++ b/piodco/piodco.c @@ -128,6 +128,9 @@ int PioDCOSetFreq(PioDco *pdco, uint32_t ui32_frq_hz, int32_t ui32_frq_millihz) si32precise_cycles = pdco->_frq_cycles_per_pi - (PIOASM_DELAY_CYCLES<<24); + pdco->_ui32_frq_hz = ui32_frq_hz; + pdco->_ui32_frq_millihz = ui32_frq_millihz; + return 0; } @@ -169,6 +172,8 @@ void PioDCOStart(PioDco *pdco) { assert_(pdco); pio_sm_set_enabled(pdco->_pio, pdco->_ism, true); + + pdco->_is_enabled = YES; } /// @brief Stops the DCO. @@ -177,6 +182,8 @@ void PioDCOStop(PioDco *pdco) { assert_(pdco); pio_sm_set_enabled(pdco->_pio, pdco->_ism, false); + + pdco->_is_enabled = NO; } /// @brief Main worker task of DCO V.2. It is time critical, so it ought to be run on diff --git a/piodco/piodco.h b/piodco/piodco.h index 5a31800..f765f38 100644 --- a/piodco/piodco.h +++ b/piodco/piodco.h @@ -104,6 +104,10 @@ typedef struct GPStimeContext *_pGPStime; /* Ptr to GPS time context. */ + uint32_t _ui32_frq_hz; /* Working freq, Hz. */ + int32_t _ui32_frq_millihz; /* Working freq additive shift, mHz. */ + int _is_enabled; + } PioDco; int PioDCOInit(PioDco *pdco, int gpio, int cpuclkhz); diff --git a/protos.h b/protos.h index cae44e5..1525d63 100644 --- a/protos.h +++ b/protos.h @@ -19,5 +19,7 @@ void core1_entry(); /* conswrapper.c */ void ConsoleCommandsWrapper(char *cmd, int narg, char *params); +void PushErrorMessage(int id); +void PushStatusMessage(void); #endif diff --git a/test.c b/test.c index 29dcbcc..4270d91 100644 --- a/test.c +++ b/test.c @@ -115,11 +115,18 @@ int main() HFconsoleContext *phfc = HFconsoleInit(-1, 0); HFconsoleSetWrapper(phfc, ConsoleCommandsWrapper); + gpio_init(PICO_DEFAULT_LED_PIN); + gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); + + multicore_launch_core1(core1_entry); + for(;;) { - sleep_ms(100); + gpio_put(PICO_DEFAULT_LED_PIN, 0); + sleep_ms(5); int r = HFconsoleProcess(phfc, 10); - //printf("%d %s\n", r, phfc->buffer); + gpio_put(PICO_DEFAULT_LED_PIN, 1); + sleep_ms(1); } for(;;)