kopia lustrzana https://github.com/RPiks/pico-hf-oscillator
WIP: GPStime init/deinit.
rodzic
da28646abe
commit
905c937611
|
@ -54,9 +54,9 @@
|
|||
extern PioDco DCO;
|
||||
|
||||
/// @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.
|
||||
/// @brief HELP - Usage.
|
||||
/// @brief SETFREQ f - Set oscillator output frequency in Hz.
|
||||
/// @brief SWITCH ON/OFF - Switch output to ON or OFF state.
|
||||
/// @param cmd Ptr to command.
|
||||
/// @param narg Argument count.
|
||||
/// @param params Command params, full string.
|
||||
|
@ -82,6 +82,10 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params)
|
|||
printf("-\n");
|
||||
printf(" SWITCH s - enable/disable generation.\n");
|
||||
printf(" example: SWITCH ON - enable generation.\n");
|
||||
printf("-\n");
|
||||
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");
|
||||
} else if(strstr(cmd, "SETFREQ"))
|
||||
{
|
||||
if(2 != narg)
|
||||
|
@ -119,6 +123,45 @@ void ConsoleCommandsWrapper(char *cmd, int narg, char *params)
|
|||
PioDCOStop(&DCO);
|
||||
printf("\nOutput is disabled");
|
||||
}
|
||||
} else if(strstr(cmd, "GPSREC"))
|
||||
{
|
||||
if(4 == narg)
|
||||
{
|
||||
char *p = params;
|
||||
const uint32_t ui32uart = atol(p);
|
||||
if(0 != ui32uart && 1 != ui32uart)
|
||||
{
|
||||
PushErrorMessage(-12);
|
||||
return;
|
||||
}
|
||||
|
||||
p += strlen(p) + 1;
|
||||
if(p)
|
||||
{
|
||||
if(strlen(p))
|
||||
{
|
||||
const uint32_t ui32pps = atol(p);
|
||||
p += strlen(p) + 1;
|
||||
const uint32_t ui32baud = atol(p);
|
||||
GPStimeContext *pGPS = GPStimeInit(ui32uart, ui32baud, ui32pps);
|
||||
assert_(pGPS);
|
||||
DCO._pGPStime = pGPS;
|
||||
printf("\nGPS subsystem is set to UART%lu (%lu baud) & PPS pin%lu", ui32uart, ui32baud, ui32pps);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PushErrorMessage(-1);
|
||||
|
||||
return;
|
||||
|
||||
} else if(2 == narg)
|
||||
{
|
||||
if(DCO._pGPStime)
|
||||
{
|
||||
GPStimeDestroy(&DCO._pGPStime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,6 +177,10 @@ void PushErrorMessage(int id)
|
|||
printf("\nInvalid frequency");
|
||||
break;
|
||||
|
||||
case -12:
|
||||
printf("\nInvalid UART id, should be 0 OR 1");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("\nUnknown error");
|
||||
break;
|
||||
|
|
|
@ -111,6 +111,9 @@ void GPStimeDestroy(GPStimeContext **pp)
|
|||
ASSERT_(pp);
|
||||
ASSERT_(*pp);
|
||||
|
||||
spGPStimeContext = NULL; /* Detach global context Ptr. */
|
||||
spGPStimeData = NULL;
|
||||
|
||||
uart_deinit((*pp)->_uart_id ? uart1 : uart0);
|
||||
free(*pp);
|
||||
*pp = NULL;
|
||||
|
|
131
piodco/dco.pio
131
piodco/dco.pio
|
@ -1,131 +0,0 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Roman Piksaykin [piksaykin@gmail.com], R2BDY
|
||||
// https://www.qrz.com/db/r2bdy
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// dco.pio Digital controlled radio freq oscillator based on PIO.
|
||||
//
|
||||
//
|
||||
// DESCRIPTION
|
||||
// -
|
||||
//
|
||||
// PLATFORM
|
||||
// Raspberry Pi pico.
|
||||
//
|
||||
// REVISION HISTORY
|
||||
//
|
||||
// Rev 0.1 05 Nov 2023
|
||||
// Initial release.
|
||||
//
|
||||
// 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.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
.program dco
|
||||
set x, 0
|
||||
set y, 0
|
||||
|
||||
.wrap_target // CYCLES
|
||||
pull // load full 32-bit register. 1c
|
||||
out y, 8 // load 8-bit delay value. 2c
|
||||
mov x, y // copy value in order to do next PI cycle. 3c
|
||||
LOOP0:
|
||||
jmp x-- LOOP0 // do exactly X*CPU CLK delay. 4c+x
|
||||
set pins, 1 [3] // set output high. 5c+x
|
||||
|
||||
LOOP1:
|
||||
jmp y-- LOOP1 // do exactly X*CPU CLK delay. 8c+x
|
||||
set pins, 0 // set output high. 9c+x
|
||||
|
||||
// RPix: The next sections repeat aforementioned algo 3 times.
|
||||
out y, 8
|
||||
mov x, y [1]
|
||||
LOOP2:
|
||||
jmp x-- LOOP2
|
||||
set pins, 1 [3]
|
||||
LOOP3:
|
||||
jmp y-- LOOP3
|
||||
set pins, 0
|
||||
|
||||
|
||||
out y, 8
|
||||
mov x, y [1]
|
||||
LOOP4:
|
||||
jmp x-- LOOP4
|
||||
set pins, 1 [3]
|
||||
LOOP5:
|
||||
jmp y-- LOOP5
|
||||
set pins, 0
|
||||
|
||||
|
||||
out y, 8
|
||||
mov x, y [1]
|
||||
LOOP6:
|
||||
jmp x-- LOOP6
|
||||
set pins, 1 [3]
|
||||
LOOP7:
|
||||
jmp y-- LOOP7
|
||||
set pins, 0
|
||||
|
||||
.wrap
|
||||
|
||||
% c-sdk {
|
||||
|
||||
#define PIOASM_DELAY_CYCLES 5
|
||||
|
||||
static inline void dco_program_init(PIO pio, uint sm, uint offset, uint pin)
|
||||
{
|
||||
pio_sm_config c = dco_program_get_default_config(offset);
|
||||
sm_config_set_out_pins(&c, pin, 1);
|
||||
pio_gpio_init(pio, pin);
|
||||
|
||||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
|
||||
//sm_config_set_out_shift(&c, true, true, 32); // Autopull.
|
||||
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
|
||||
|
||||
sm_config_set_clkdiv_int_frac(&c, 1u, 0u);
|
||||
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
pio_sm_set_enabled(pio, sm, true);
|
||||
}
|
||||
//
|
||||
static inline void dco_program_puts(PIO pio, uint sm, const uint32_t *s)
|
||||
{
|
||||
pio_sm_put_blocking(pio, sm, s[0]);
|
||||
pio_sm_put_blocking(pio, sm, s[1]);
|
||||
pio_sm_put_blocking(pio, sm, s[2]);
|
||||
pio_sm_put_blocking(pio, sm, s[3]);
|
||||
pio_sm_put_blocking(pio, sm, s[4]);
|
||||
pio_sm_put_blocking(pio, sm, s[5]);
|
||||
pio_sm_put_blocking(pio, sm, s[6]);
|
||||
pio_sm_put_blocking(pio, sm, s[7]);
|
||||
}
|
||||
|
||||
static inline void dco_program_puts1w(PIO pio, uint sm, const uint32_t val)
|
||||
{
|
||||
pio_sm_put_blocking(pio, sm, val);
|
||||
}
|
||||
%}
|
Ładowanie…
Reference in New Issue