kopia lustrzana https://github.com/RPiks/pico-hf-oscillator
Work in progress: Receiving NMEA sentences, Measure period of PPS. Debugging.
rodzic
c5f63751bd
commit
65aaacca12
|
@ -33,6 +33,7 @@ pico_generate_pio_header(pico-hf-oscillator-test ${CMAKE_CURRENT_LIST_DIR}/piodc
|
||||||
|
|
||||||
target_sources(pico-hf-oscillator-test PUBLIC
|
target_sources(pico-hf-oscillator-test PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}/lib/assert.c
|
${CMAKE_CURRENT_LIST_DIR}/lib/assert.c
|
||||||
|
# ${CMAKE_CURRENT_LIST_DIR}/lib/utility.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/piodco/piodco.c
|
${CMAKE_CURRENT_LIST_DIR}/piodco/piodco.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/gpstime/GPStime.c
|
${CMAKE_CURRENT_LIST_DIR}/gpstime/GPStime.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/test.c
|
${CMAKE_CURRENT_LIST_DIR}/test.c
|
||||||
|
@ -42,11 +43,12 @@ pico_set_program_name(pico-hf-oscillator-test "pico-hf-oscillator-test")
|
||||||
pico_set_program_version(pico-hf-oscillator-test "0.9")
|
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 1)
|
||||||
pico_enable_stdio_usb(pico-hf-oscillator-test 0)
|
pico_enable_stdio_usb(pico-hf-oscillator-test 1)
|
||||||
|
|
||||||
# Add the standard include files to the build
|
# Add the standard include files to the build
|
||||||
target_include_directories(pico-hf-oscillator-test PRIVATE
|
target_include_directories(pico-hf-oscillator-test PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/gpstime
|
||||||
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
|
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Plik binarny nie jest wyświetlany.
Plik binarny nie jest wyświetlany.
|
@ -64,11 +64,13 @@
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#include "GPStime.h"
|
#include "GPStime.h"
|
||||||
|
|
||||||
GPStimeContext *GPStimeInit(int uart_id, int uart_baud, int pps_pio)
|
static GPStimeData *spGPStimeData = NULL;
|
||||||
|
|
||||||
|
GPStimeContext *GPStimeInit(int uart_id, int uart_baud, int pps_gpio)
|
||||||
{
|
{
|
||||||
ASSERT_(0 == uart_id || 1 == uart_id);
|
ASSERT_(0 == uart_id || 1 == uart_id);
|
||||||
ASSERT_(uart_baud <= 115200);
|
ASSERT_(uart_baud <= 115200);
|
||||||
ASSERT_(pps_pio < 29);
|
ASSERT_(pps_gpio < 29);
|
||||||
|
|
||||||
// Set up our UART with the required speed.
|
// Set up our UART with the required speed.
|
||||||
uart_init(uart_id ? uart1 : uart0, uart_baud);
|
uart_init(uart_id ? uart1 : uart0, uart_baud);
|
||||||
|
@ -82,7 +84,13 @@ GPStimeContext *GPStimeInit(int uart_id, int uart_baud, int pps_pio)
|
||||||
ASSERT_(pgt);
|
ASSERT_(pgt);
|
||||||
pgt->_uart_id = uart_id;
|
pgt->_uart_id = uart_id;
|
||||||
pgt->_uart_baudrate = uart_baud;
|
pgt->_uart_baudrate = uart_baud;
|
||||||
pgt->_pps_pio = pps_pio;
|
pgt->_pps_pio = pps_gpio;
|
||||||
|
|
||||||
|
spGPStimeData = &pgt->_time_data;
|
||||||
|
|
||||||
|
gpio_init(pps_gpio);
|
||||||
|
gpio_set_dir(pps_gpio, GPIO_IN);
|
||||||
|
gpio_set_irq_enabled_with_callback(pps_gpio, GPIO_IRQ_EDGE_RISE, true, &GPStimePPScallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPStimeDestroy(GPStimeContext **pp)
|
void GPStimeDestroy(GPStimeContext **pp)
|
||||||
|
@ -94,3 +102,36 @@ void GPStimeDestroy(GPStimeContext **pp)
|
||||||
free(*pp);
|
free(*pp);
|
||||||
*pp = NULL;
|
*pp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __not_in_flash_func (GPStimePPScallback)(uint gpio, uint32_t events)
|
||||||
|
{
|
||||||
|
if(spGPStimeData)
|
||||||
|
{
|
||||||
|
const uint64_t tm64 = GetUptime64();
|
||||||
|
spGPStimeData->_u64_sysclk_pps_last = tm64;
|
||||||
|
const int32_t ksliding_len = sizeof(spGPStimeData->_pu64_sliding_pps_tm)
|
||||||
|
/ sizeof(spGPStimeData->_pu64_sliding_pps_tm[0]);
|
||||||
|
|
||||||
|
++spGPStimeData->_ix_last;
|
||||||
|
spGPStimeData->_ix_last %= ksliding_len;
|
||||||
|
const uint8_t ix_oldest = spGPStimeData->_ix_last;
|
||||||
|
|
||||||
|
int64_t dt_1M = 1000000LL * (tm64 - spGPStimeData->_pu64_sliding_pps_tm[ix_oldest]);
|
||||||
|
spGPStimeData->_pu64_sliding_pps_tm[spGPStimeData->_ix_last] = tm64;
|
||||||
|
|
||||||
|
if(spGPStimeData->_u64_pps_period_1M)
|
||||||
|
{
|
||||||
|
spGPStimeData->_u64_pps_period_1M += iSAR(dt_1M - spGPStimeData->_u64_pps_period_1M + 4, 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spGPStimeData->_u64_pps_period_1M = dt_1M;
|
||||||
|
}
|
||||||
|
#if 1
|
||||||
|
dt_1M = (dt_1M + ksliding_len/2) / ksliding_len;
|
||||||
|
const uint64_t tmp = (spGPStimeData->_u64_pps_period_1M + ksliding_len/2) / ksliding_len;
|
||||||
|
printf("%llu %lld %llu\n", spGPStimeData->_u64_sysclk_pps_last, dt_1M, tmp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -70,16 +70,26 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "hardware/uart.h"
|
#include "hardware/uart.h"
|
||||||
|
#include "../defines.h"
|
||||||
#include "../lib/assert.h"
|
#include "../lib/assert.h"
|
||||||
|
#include "../lib/utility.h"
|
||||||
|
|
||||||
#define ASSERT_(x) assert_(x)
|
#define ASSERT_(x) assert_(x)
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t _tm_unix_last;
|
uint8_t _u8_is_sol_active; // A navigation solution is valid.
|
||||||
float _flt_lat_deg, _flt_lon_deg;
|
uint32_t _u32_utime_nmea_last; // The last unix time received from GPS.
|
||||||
|
uint64_t _u64_sysclk_nmea_last; // The sysclk of the last unix time received.
|
||||||
|
int64_t _i64_lat_100k, _i64_lon_100k; // The lat, lon, degrees, multiplied by 1e5.
|
||||||
|
|
||||||
float _flt_GDOP, _flt_TDOP;
|
uint64_t _u64_sysclk_pps_last; // The sysclk of the last rising edge of PPS.
|
||||||
|
uint64_t _u64_pps_period_1M; // The PPS avg. period *1e6, filtered.
|
||||||
|
|
||||||
|
uint64_t _pu64_sliding_pps_tm[32]; // A sliding window to store PPS periods.
|
||||||
|
uint8_t _ix_last; // An index of last write to sliding window.
|
||||||
|
|
||||||
|
int32_t _i32_LO_freq_corr_milhz; // SYSCLK frequency correction, milliHertz.
|
||||||
|
|
||||||
} GPStimeData;
|
} GPStimeData;
|
||||||
|
|
||||||
|
@ -92,13 +102,17 @@ typedef struct
|
||||||
GPStimeData _time_data;
|
GPStimeData _time_data;
|
||||||
|
|
||||||
uint8_t _pbytebuff[256];
|
uint8_t _pbytebuff[256];
|
||||||
|
uint8_t _u8_ixw;
|
||||||
uint8_t _is_sentence_ready;
|
uint8_t _is_sentence_ready;
|
||||||
|
|
||||||
} GPStimeContext;
|
} GPStimeContext;
|
||||||
|
|
||||||
GPStimeContext *GPStimeInit(int uart_id, int uart_baud, int pps_pio);
|
GPStimeContext *GPStimeInit(int uart_id, int uart_baud, int pps_gpio);
|
||||||
void GPStimeDestroy(GPStimeContext **pp);
|
void GPStimeDestroy(GPStimeContext **pp);
|
||||||
|
|
||||||
void GPStimeTick(GPStimeContext *pg);
|
void GPStimeISRTick(GPStimeContext *pg);
|
||||||
|
int GPStimeProcNMEAsentence(GPStimeContext *pg);
|
||||||
|
|
||||||
|
void __not_in_flash_func (GPStimePPScallback)(uint gpio, uint32_t events);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef UTILITY_H_
|
||||||
|
#define UTILITY_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
|
||||||
|
inline uint64_t GetUptime64(void)
|
||||||
|
{
|
||||||
|
const uint32_t lo = timer_hw->timelr;
|
||||||
|
const uint32_t hi = timer_hw->timehr;
|
||||||
|
|
||||||
|
return ((uint64_t)hi << 32U) | lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline uint32_t GetTime32(void)
|
||||||
|
{
|
||||||
|
return timer_hw->timelr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
24
test.c
24
test.c
|
@ -68,6 +68,7 @@
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
|
@ -75,10 +76,13 @@
|
||||||
#include "build/dco.pio.h"
|
#include "build/dco.pio.h"
|
||||||
#include "hardware/vreg.h"
|
#include "hardware/vreg.h"
|
||||||
#include "pico/multicore.h"
|
#include "pico/multicore.h"
|
||||||
|
#include "pico/stdio/driver.h"
|
||||||
|
|
||||||
#include "./lib/assert.h"
|
#include "./lib/assert.h"
|
||||||
#include "hwdefs.h"
|
#include "hwdefs.h"
|
||||||
|
|
||||||
|
#include <GPStime.h>
|
||||||
|
|
||||||
#define GEN_FRQ_HZ 9400000L
|
#define GEN_FRQ_HZ 9400000L
|
||||||
|
|
||||||
PioDco DCO;
|
PioDco DCO;
|
||||||
|
@ -211,6 +215,26 @@ int main()
|
||||||
const uint32_t clkhz = PLL_SYS_MHZ * 1000000L;
|
const uint32_t clkhz = PLL_SYS_MHZ * 1000000L;
|
||||||
set_sys_clock_khz(clkhz / 1000L, true);
|
set_sys_clock_khz(clkhz / 1000L, true);
|
||||||
|
|
||||||
|
stdio_init_all();
|
||||||
|
|
||||||
|
//uart_init(uart0, 9600);
|
||||||
|
//gpio_set_function(0, GPIO_FUNC_UART);
|
||||||
|
//gpio_set_function(1, GPIO_FUNC_UART);
|
||||||
|
|
||||||
|
GPStimeContext *pGPS = GPStimeInit(0, 9600, 2);
|
||||||
|
for(;;) {}
|
||||||
|
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
char ch = uart_getc(uart0);
|
||||||
|
if(ch)
|
||||||
|
{
|
||||||
|
stdio_set_driver_enabled(&stdio_uart, false);
|
||||||
|
printf("%c", ch);
|
||||||
|
stdio_set_driver_enabled(&stdio_uart, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue