kopia lustrzana https://github.com/RPiks/pico-hf-oscillator
Work in progress: USB console! Help is working)
rodzic
52d474ce0d
commit
54a04467d2
|
@ -29,11 +29,13 @@ 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}/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
|
||||
${CMAKE_CURRENT_LIST_DIR}/test.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/conswrapper.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/hfconsole/hfconsole.c
|
||||
)
|
||||
|
||||
pico_set_program_name(pico-hf-oscillator-test "pico-hf-oscillator-test")
|
||||
|
@ -46,6 +48,7 @@ pico_enable_stdio_usb(pico-hf-oscillator-test 1)
|
|||
target_include_directories(pico-hf-oscillator-test PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/gpstime
|
||||
${CMAKE_CURRENT_LIST_DIR}/hfconsole
|
||||
${CMAKE_CURRENT_LIST_DIR}/..
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Roman Piksaykin [piksaykin@gmail.com], R2BDY, PhD
|
||||
// https://www.qrz.com/db/r2bdy
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// conswrapper.c - Serial console commands processing manager.
|
||||
//
|
||||
// DESCRIPTION
|
||||
// -
|
||||
//
|
||||
// PLATFORM
|
||||
// Raspberry Pi pico.
|
||||
//
|
||||
// REVISION HISTORY
|
||||
// Rev 0.1 23 Dec 2023 Initial revision.
|
||||
//
|
||||
// PROJECT PAGE
|
||||
// https://github.com/RPiks/pico-hf-oscillator
|
||||
//
|
||||
// LICENCE
|
||||
// MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
//
|
||||
// Copyright (c) 2023 by Roman Piksaykin
|
||||
//
|
||||
// Permission is hereby granted, free of charge,to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction,including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "./lib/assert.h"
|
||||
|
||||
/// @brief Console commands manager. Currently available:
|
||||
/// @brief HELP - Usage.
|
||||
/// @brief SETFREQ [XXXXXXXX] - Set oscillator output frequency in Hz.
|
||||
/// @brief SWITCH [X] - Switch output to ON or OFF state.
|
||||
/// @param cmd Ptr to command.
|
||||
/// @param narg Argument count.
|
||||
/// @param params Command params, full string.
|
||||
void ConsoleCommandsWrapper(char *cmd, int narg, char *params)
|
||||
{
|
||||
assert_(cmd);
|
||||
|
||||
if(strstr(cmd, "HELP"))
|
||||
{
|
||||
printf("\n");
|
||||
printf("Pico-hf-oscillator project HELP page\n");
|
||||
printf("Copyright (c) 2023 by Roman Piksaykin\n");
|
||||
printf("Build date: %s %s\n",__DATE__, __TIME__);
|
||||
printf("Project official page: github.com/RPiks/pico-hf-oscillator\n");
|
||||
printf("----------------------------------------------------------\n");
|
||||
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("-\n");
|
||||
printf(" SWITCH [X] - switch generation to ON or OFF state.\n");
|
||||
printf(" Example: SWITCH ON - switch generation to ON state.\n");
|
||||
} else if(strstr(cmd, "SETFREQ"))
|
||||
{
|
||||
|
||||
} else if(strstr(cmd, "SWITCH"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Roman Piksaykin [piksaykin@gmail.com], R2BDY, PhD
|
||||
// https://www.qrz.com/db/r2bdy
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// hfconsole.c - Serial console of Raspberry Pi Pico.
|
||||
//
|
||||
// DESCRIPTION
|
||||
// -
|
||||
//
|
||||
// PLATFORM
|
||||
// Raspberry Pi pico.
|
||||
//
|
||||
// REVISION HISTORY
|
||||
// Rev 0.1 16 Dec 2023 Initial revision.
|
||||
//
|
||||
// PROJECT PAGE
|
||||
// https://github.com/RPiks/pico-hf-oscillator
|
||||
//
|
||||
// LICENCE
|
||||
// MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
//
|
||||
// Copyright (c) 2023 by Roman Piksaykin
|
||||
//
|
||||
// Permission is hereby granted, free of charge,to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction,including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#include "hfconsole.h"
|
||||
|
||||
HFconsoleContext *HFconsoleInit(int uart_id, int baud)
|
||||
{
|
||||
assert_(uart_id < 2);
|
||||
HFconsoleContext *pctx = calloc(1, sizeof(HFconsoleContext));
|
||||
assert_(pctx);
|
||||
|
||||
memset(pctx->buffer, 0, sizeof(pctx->buffer));
|
||||
|
||||
pctx->_uart_id = uart_id;
|
||||
pctx->_uart_baudrate = baud;
|
||||
|
||||
return pctx;
|
||||
}
|
||||
|
||||
void HFconsoleDestroy(HFconsoleContext **pp)
|
||||
{
|
||||
if(pp && *pp)
|
||||
{
|
||||
free(*pp);
|
||||
*pp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int HFconsoleProcess(HFconsoleContext *p, int ms)
|
||||
{
|
||||
const int ichr = getchar_timeout_us(ms);
|
||||
if(ichr < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(ichr)
|
||||
{
|
||||
case 13:
|
||||
HFconsoleEmitCommand(p);
|
||||
p->buffer[p->ix] = 0;
|
||||
p->ix = 0;
|
||||
printf("\n=> ");
|
||||
break;
|
||||
|
||||
case 8:
|
||||
if(p->ix)
|
||||
{
|
||||
--p->ix;
|
||||
}
|
||||
printf("%c", ichr);
|
||||
break;
|
||||
|
||||
default:
|
||||
p->buffer[p->ix++] = (char)ichr;
|
||||
printf("%c", ichr);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HFconsoleEmitCommand(HFconsoleContext *pc)
|
||||
{
|
||||
char *p = strchr(pc->buffer, ' ');
|
||||
if(p)
|
||||
{
|
||||
if(strlen(p) < 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int narg = 0;
|
||||
const char* delimiters = ",. ";
|
||||
char* token = strtok(pc->buffer, delimiters);
|
||||
while (token)
|
||||
{
|
||||
++narg;
|
||||
token = strtok(NULL, delimiters);
|
||||
}
|
||||
|
||||
if(pc->_pfwrapper)
|
||||
{
|
||||
*p = 0;
|
||||
(*pc->_pfwrapper)(pc->buffer, narg, p+1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pc->_pfwrapper)
|
||||
{
|
||||
(*pc->_pfwrapper)(pc->buffer, 0, pc->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HFconsoleSetWrapper(HFconsoleContext *pc, void *pfwrapper)
|
||||
{
|
||||
assert_(pc);
|
||||
|
||||
pc->_pfwrapper = pfwrapper;
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Roman Piksaykin [piksaykin@gmail.com], R2BDY, PhD
|
||||
// https://www.qrz.com/db/r2bdy
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// hfconsole.h - Serial console of Raspberry Pi Pico.
|
||||
//
|
||||
// DESCRIPTION
|
||||
// -
|
||||
//
|
||||
// PLATFORM
|
||||
// Raspberry Pi pico.
|
||||
//
|
||||
// REVISION HISTORY
|
||||
// Rev 0.1 16 Dec 2023 Initial revision.
|
||||
//
|
||||
// PROJECT PAGE
|
||||
// https://github.com/RPiks/pico-hf-oscillator
|
||||
//
|
||||
// LICENCE
|
||||
// MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
//
|
||||
// Copyright (c) 2023 by Roman Piksaykin
|
||||
//
|
||||
// Permission is hereby granted, free of charge,to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction,including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef HFTERM_H_
|
||||
#define HFTERM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/uart.h"
|
||||
#include "../lib/assert.h"
|
||||
#include "../lib/utility.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int _uart_id; // UART id (-1 when use Pico USB port)
|
||||
int _uart_baudrate; // UART baud rate (isn't used when uaer id is 0)
|
||||
|
||||
//const char **_ppcommands;
|
||||
//int _commands_count;
|
||||
|
||||
void (*_pfwrapper)(char *, int, char *);
|
||||
|
||||
char buffer[256];
|
||||
uint8_t ix;
|
||||
|
||||
} HFconsoleContext;
|
||||
|
||||
HFconsoleContext *HFconsoleInit(int uart_id, int baud);
|
||||
void HFconsoleDestroy(HFconsoleContext **pp);
|
||||
int HFconsoleProcess(HFconsoleContext *p, int ms);
|
||||
int HFconsoleEmitCommand(HFconsoleContext *pc);
|
||||
void HFconsoleSetWrapper(HFconsoleContext *pc, void *pfwrapper);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef PROTOS_H_
|
||||
#define PROTOS_H_
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
/* main.c */
|
||||
|
||||
void RAM (SpinnerMFSKTest)(void);
|
||||
void RAM (SpinnerSweepTest)(void);
|
||||
void RAM (SpinnerRTTYTest)(void);
|
||||
void RAM (SpinnerMilliHertzTest)(void);
|
||||
void RAM (SpinnerWide4FSKTest)(void);
|
||||
void RAM (SpinnerGPSreferenceTest)(void);
|
||||
|
||||
void core1_entry();
|
||||
|
||||
|
||||
|
||||
/* conswrapper.c */
|
||||
|
||||
void ConsoleCommandsWrapper(char *cmd, int narg, char *params);
|
||||
|
||||
#endif
|
30
test.c
30
test.c
|
@ -94,20 +94,15 @@
|
|||
|
||||
#include <GPStime.h>
|
||||
|
||||
#include <hfconsole.h>
|
||||
|
||||
#include "protos.h"
|
||||
|
||||
//#define GEN_FRQ_HZ 32333333L
|
||||
#define GEN_FRQ_HZ 29977777L
|
||||
|
||||
PioDco DCO; /* External in order to access in both cores. */
|
||||
|
||||
void RAM (SpinnerMFSKTest)(void);
|
||||
void RAM (SpinnerSweepTest)(void);
|
||||
void RAM (SpinnerRTTYTest)(void);
|
||||
void RAM (SpinnerMilliHertzTest)(void);
|
||||
void RAM (SpinnerWide4FSKTest)(void);
|
||||
void RAM (SpinnerGPSreferenceTest)(void);
|
||||
|
||||
void core1_entry();
|
||||
|
||||
int main()
|
||||
{
|
||||
const uint32_t clkhz = PLL_SYS_MHZ * 1000000L;
|
||||
|
@ -116,6 +111,23 @@ int main()
|
|||
stdio_init_all();
|
||||
sleep_ms(1000);
|
||||
printf("Start\n");
|
||||
|
||||
HFconsoleContext *phfc = HFconsoleInit(-1, 0);
|
||||
HFconsoleSetWrapper(phfc, ConsoleCommandsWrapper);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
sleep_ms(100);
|
||||
int r = HFconsoleProcess(phfc, 10);
|
||||
//printf("%d %s\n", r, phfc->buffer);
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
sleep_ms(100);
|
||||
int chr = getchar_timeout_us(100);//getchar();
|
||||
printf("%d %c\n", chr, (char)chr);
|
||||
}
|
||||
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
|
|
Ładowanie…
Reference in New Issue