From 5e6ced24e18c7f2f37bafd2ab73a46e665ba59f8 Mon Sep 17 00:00:00 2001 From: roman Date: Sat, 23 Dec 2023 22:54:11 +0300 Subject: [PATCH] Beta release with USB terminal. --- CMakeLists.txt | 4 ++-- conswrapper.c | 25 +++++++++++++++++++++++-- gpstime/GPStime.c | 6 +++--- test.c | 4 ++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc63f28..86a5ea8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,6 @@ pico_generate_pio_header(pico-hf-oscillator-test ${CMAKE_CURRENT_LIST_DIR}/piodc target_sources(pico-hf-oscillator-test PUBLIC ${CMAKE_CURRENT_LIST_DIR}/lib/assert.c -# ${CMAKE_CURRENT_LIST_DIR}/lib/thirdparty/strnstr.c ${CMAKE_CURRENT_LIST_DIR}/piodco/piodco.c ${CMAKE_CURRENT_LIST_DIR}/gpstime/GPStime.c ${CMAKE_CURRENT_LIST_DIR}/debug/logutils.c @@ -41,7 +40,7 @@ target_sources(pico-hf-oscillator-test PUBLIC pico_set_program_name(pico-hf-oscillator-test "pico-hf-oscillator-test") pico_set_program_version(pico-hf-oscillator-test "0.9") -pico_enable_stdio_uart(pico-hf-oscillator-test 1) +pico_enable_stdio_uart(pico-hf-oscillator-test 0) pico_enable_stdio_usb(pico-hf-oscillator-test 1) # Add the standard include files to the build @@ -63,6 +62,7 @@ target_link_libraries( hardware_timer hardware_clocks hardware_pio + hardware_uart ) pico_add_extra_outputs(pico-hf-oscillator-test) diff --git a/conswrapper.c b/conswrapper.c index 268934f..a5378f8 100644 --- a/conswrapper.c +++ b/conswrapper.c @@ -47,6 +47,7 @@ #include #include #include +#include "hardware/uart.h" #include "./lib/assert.h" #include "piodco/piodco.h" #include "protos.h" @@ -86,6 +87,7 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params) printf(" GPSREC OFF/uart_id,pps_pin,baud - enable/disable GPS receiver connection.\n"); printf(" example: GPS 0,3,9600 - enable GPS receiver connection with UART0 & PPS on gpio3, 9600 baud port speed.\n"); printf(" example: GPS OFF - disable GPS receiver connection.\n"); + return; } else if(strstr(cmd, "SETFREQ")) { if(2 != narg) @@ -102,11 +104,13 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params) } PioDCOSetFreq(&DCO, ui32frq, 0U); - printf("\nFrequency is set to %lu Hz", ui32frq); + printf("\nFrequency is set to %lu+.000 Hz", ui32frq); + return; } else if(strstr(cmd, "STATUS")) { PushStatusMessage(); + return; } else if(strstr(cmd, "SWITCH")) { if(2 != narg) @@ -118,10 +122,12 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params) { PioDCOStart(&DCO); printf("\nOutput is enabled"); + return; } else if(strstr(params, "OFF")) { PioDCOStop(&DCO); printf("\nOutput is disabled"); + return; } } else if(strstr(cmd, "GPSREC")) { @@ -143,6 +149,11 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params) const uint32_t ui32pps = atol(p); p += strlen(p) + 1; const uint32_t ui32baud = atol(p); + if(DCO._pGPStime) + { + GPStimeDestroy(&DCO._pGPStime); + printf("\nGPS subsystem is disabled."); + } GPStimeContext *pGPS = GPStimeInit(ui32uart, ui32baud, ui32pps); assert_(pGPS); DCO._pGPStime = pGPS; @@ -154,15 +165,21 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params) PushErrorMessage(-1); return; - + } else if(2 == narg) { if(DCO._pGPStime) { GPStimeDestroy(&DCO._pGPStime); + printf("\nGPS subsystem is disabled."); } + + return; } } + + //printf("\ncmd=%s", cmd); + PushErrorMessage(-13); } void PushErrorMessage(int id) @@ -181,6 +198,10 @@ void PushErrorMessage(int id) printf("\nInvalid UART id, should be 0 OR 1"); break; + case -13: + printf("\nInvalid command"); + break; + default: printf("\nUnknown error"); break; diff --git a/gpstime/GPStime.c b/gpstime/GPStime.c index ef1e96f..c800b42 100644 --- a/gpstime/GPStime.c +++ b/gpstime/GPStime.c @@ -76,8 +76,8 @@ GPStimeContext *GPStimeInit(int uart_id, int uart_baud, int pps_gpio) // Set up our UART with the required speed & assign pins. uart_init(uart_id ? uart1 : uart0, uart_baud); - gpio_set_function(uart_id ? 8 : 12, GPIO_FUNC_UART); - gpio_set_function(uart_id ? 9 : 13, GPIO_FUNC_UART); + gpio_set_function(uart_id ? 8 : 0, GPIO_FUNC_UART); + gpio_set_function(uart_id ? 9 : 1, GPIO_FUNC_UART); GPStimeContext *pgt = calloc(1, sizeof(GPStimeContext)); ASSERT_(pgt); @@ -105,7 +105,6 @@ GPStimeContext *GPStimeInit(int uart_id, int uart_baud, int pps_gpio) /// @brief Deinits the GPS module and destroys allocated resources. /// @param pp Ptr to Ptr of the Context. -/// @attention *NOT* implemented completely so far. !FIXME! void GPStimeDestroy(GPStimeContext **pp) { ASSERT_(pp); @@ -199,6 +198,7 @@ void RAM (GPStimeUartRxIsr)() uart_inst_t *puart_id = spGPStimeContext->_uart_id ? uart1 : uart0; for(;;uart_is_readable(puart_id)) { + gpio_put(PICO_DEFAULT_LED_PIN, 1); uint8_t chr = uart_getc(puart_id); spGPStimeContext->_pbytebuff[spGPStimeContext->_u8_ixw++] = chr; spGPStimeContext->_is_sentence_ready = ('\n' == chr); diff --git a/test.c b/test.c index 4270d91..c27a69d 100644 --- a/test.c +++ b/test.c @@ -305,9 +305,9 @@ void RAM (SpinnerGPSreferenceTest)(void) if(0 == ++tick % 6) { - stdio_set_driver_enabled(&stdio_uart, false); + //stdio_set_driver_enabled(&stdio_uart, false); GPStimeDump(&(pGPS->_time_data)); - stdio_set_driver_enabled(&stdio_uart, true); + //stdio_set_driver_enabled(&stdio_uart, true); } } }