2023-11-01 23:41:14 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-11-10 20:36:35 +00:00
|
|
|
#include "defines.h"
|
|
|
|
|
2023-11-01 23:41:14 +00:00
|
|
|
#include "piodco/piodco.h"
|
|
|
|
#include "build/dco.pio.h"
|
|
|
|
#include "hardware/vreg.h"
|
|
|
|
|
2023-11-07 00:07:42 +00:00
|
|
|
#include "./lib/assert.h"
|
|
|
|
#include "hwdefs.h"
|
|
|
|
#include "./dcoisr/dcoisr.h"
|
|
|
|
|
2023-11-10 20:36:35 +00:00
|
|
|
void __not_in_flash_func (WorkerCycle)(PioDco *pDCO, const int32_t i32frq_in_clk, uint32_t *preg32)
|
|
|
|
{
|
|
|
|
register int32_t acc_phase_error = 0;
|
|
|
|
register uint8_t *preg8 = (uint8_t *)preg32;
|
|
|
|
register PIO pio = pDCO->_pio;
|
|
|
|
register uint sm = pDCO->_ism;
|
|
|
|
|
|
|
|
pio_sm_set_enabled(pio, sm, true);
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
preg8 = (uint8_t *)preg32;
|
|
|
|
for(int i = 0; i < 32; ++i)
|
|
|
|
{
|
|
|
|
register const int32_t i32wc = (i32frq_in_clk - acc_phase_error + (1<<23)) >> 24;
|
|
|
|
acc_phase_error += (i32wc<<24) - i32frq_in_clk;
|
|
|
|
|
|
|
|
*preg8++ = i32wc - PIOASM_DELAY_CYCLES;
|
|
|
|
}
|
|
|
|
|
|
|
|
dco_program_puts(pio, sm, preg32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 23:41:14 +00:00
|
|
|
int main()
|
|
|
|
{
|
2023-11-07 00:07:42 +00:00
|
|
|
PioDco DCO;
|
2023-11-10 20:36:35 +00:00
|
|
|
//DcoIsrContext ISRC;
|
2023-11-07 00:07:42 +00:00
|
|
|
|
2023-11-08 21:28:29 +00:00
|
|
|
const uint32_t clkhz = PLL_SYS_MHZ * 1000000L;
|
|
|
|
set_sys_clock_khz(clkhz / 1000L, true);
|
2023-11-01 23:41:14 +00:00
|
|
|
|
|
|
|
gpio_init(PICO_DEFAULT_LED_PIN);
|
|
|
|
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
|
|
|
|
2023-11-10 20:36:35 +00:00
|
|
|
const uint32_t freq_hz = 2*10000000L;
|
|
|
|
|
|
|
|
assert_(0 == PioDCOInit(&DCO, 6, clkhz));
|
|
|
|
PioDCOStart(&DCO);
|
|
|
|
assert_(0 == PioDCOSetFreq(&DCO, freq_hz));
|
|
|
|
PioDCOWorker(&DCO);
|
|
|
|
|
|
|
|
/*
|
2023-11-07 00:07:42 +00:00
|
|
|
//DcoIsrInit(&ISRC, &DCO);
|
|
|
|
|
2023-11-08 21:28:29 +00:00
|
|
|
uint32_t preg32[8] = {0};
|
|
|
|
uint8_t *preg8 = (uint8_t *)preg32;
|
|
|
|
|
2023-11-10 20:36:35 +00:00
|
|
|
//const uint64_t frqhz = 2*(3573000L);
|
|
|
|
//const uint64_t frqhz = 2*7074000L + 1;
|
|
|
|
const uint64_t frqhz = 2*10000000L;
|
|
|
|
//const uint64_t frqhz = 2*10136000L;
|
|
|
|
//const int64_t frqhz = 2*(14074000L);
|
|
|
|
const int64_t i64frq_in_clk = ((int64_t)clkhz * (int64_t)(1<<24) + (frqhz>>1)) / frqhz;
|
|
|
|
const int32_t i32frq_in_clk = i64frq_in_clk;
|
2023-11-01 23:41:14 +00:00
|
|
|
|
2023-11-10 20:36:35 +00:00
|
|
|
WorkerCycle(&DCO, i32frq_in_clk, preg32);
|
|
|
|
*/
|
2023-11-01 23:41:14 +00:00
|
|
|
}
|