better PIO dumper code
This commit is contained in:
parent
69ab51a5e1
commit
565d13b7d4
|
@ -4,12 +4,15 @@
|
||||||
#include <hardware/clocks.h>
|
#include <hardware/clocks.h>
|
||||||
#include <hardware/pio.h>
|
#include <hardware/pio.h>
|
||||||
#include <hardware/pio_instructions.h>
|
#include <hardware/pio_instructions.h>
|
||||||
|
#include <hardware/sync.h>
|
||||||
#include <hardware/timer.h>
|
#include <hardware/timer.h>
|
||||||
|
|
||||||
#include "pio_sbw.h"
|
#include "pio_sbw.h"
|
||||||
#include "sbw.pio.h"
|
#include "sbw.pio.h"
|
||||||
|
|
||||||
static uint16_t pio_read_one(PIO pio, uint sm, uint32_t off) {
|
static uint16_t pio_read_one(PIO pio, uint sm, uint32_t off, int _) {
|
||||||
|
(void)_;
|
||||||
|
|
||||||
const int FREQ_SM = 500 * 1000; // 500 kHz
|
const int FREQ_SM = 500 * 1000; // 500 kHz
|
||||||
const int T_SM_US = 2; // 1/500 kHz = 2 us
|
const int T_SM_US = 2; // 1/500 kHz = 2 us
|
||||||
|
|
||||||
|
@ -19,7 +22,8 @@ static uint16_t pio_read_one(PIO pio, uint sm, uint32_t off) {
|
||||||
pio_sm_config defcfg = pio_get_default_sm_config();
|
pio_sm_config defcfg = pio_get_default_sm_config();
|
||||||
pio_sm_set_config(pio, sm, &defcfg);
|
pio_sm_set_config(pio, sm, &defcfg);
|
||||||
// set clkdiv to something slow
|
// set clkdiv to something slow
|
||||||
pio_sm_set_clkdiv(pio, sm, 2*(float)clock_get_hz(clk_sys) / FREQ_SM);
|
//pio_sm_set_clkdiv(pio, sm, 2*(float)clock_get_hz(clk_sys) / FREQ_SM);
|
||||||
|
pio_sm_set_clkdiv_int_frac(pio, sm, 0, 0);
|
||||||
// clear PIO FIFOs
|
// clear PIO FIFOs
|
||||||
pio_sm_clear_fifos(pio, sm);
|
pio_sm_clear_fifos(pio, sm);
|
||||||
// clear debug flags
|
// clear debug flags
|
||||||
|
@ -35,15 +39,21 @@ static uint16_t pio_read_one(PIO pio, uint sm, uint32_t off) {
|
||||||
// exec jmp to offset
|
// exec jmp to offset
|
||||||
uint16_t jmp = pio_encode_jmp(off);
|
uint16_t jmp = pio_encode_jmp(off);
|
||||||
pio_sm_exec(pio, sm, jmp);
|
pio_sm_exec(pio, sm, jmp);
|
||||||
|
|
||||||
|
uint32_t irq = save_and_disable_interrupts();
|
||||||
|
|
||||||
// enable
|
// enable
|
||||||
pio_sm_set_enabled(pio, sm, true);
|
pio_sm_set_enabled(pio, sm, true);
|
||||||
// wait 1 cycle
|
// wait 1 cycle
|
||||||
busy_wait_us_32(T_SM_US);
|
//busy_wait_us_32(T_SM_US);
|
||||||
|
pio_sm_clkdiv_restart(pio, sm);
|
||||||
// read SM insn
|
// read SM insn
|
||||||
uint16_t ret = pio->sm[sm].instr;
|
uint16_t ret = pio->sm[sm].instr;
|
||||||
// disable SM
|
// disable SM
|
||||||
pio_sm_set_enabled(pio, sm, false);
|
pio_sm_set_enabled(pio, sm, false);
|
||||||
|
|
||||||
|
restore_interrupts(irq);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +62,7 @@ struct bin {
|
||||||
uint16_t noccur;
|
uint16_t noccur;
|
||||||
};
|
};
|
||||||
#define BINS 32 /* idk */
|
#define BINS 32 /* idk */
|
||||||
static uint16_t pio_get_one(PIO pio, uint sm, uint32_t off, int runs) {
|
/*static uint16_t pio_get_one(PIO pio, uint sm, uint32_t off, int runs) {
|
||||||
// there's some variability in the return value of pio_read_one, sometimes
|
// there's some variability in the return value of pio_read_one, sometimes
|
||||||
// returning the next instruction. I don't know the exact reason, but a
|
// returning the next instruction. I don't know the exact reason, but a
|
||||||
// possible cause could be that the timing of the PIO instructions doesn't
|
// possible cause could be that the timing of the PIO instructions doesn't
|
||||||
|
@ -68,7 +78,7 @@ static uint16_t pio_get_one(PIO pio, uint sm, uint32_t off, int runs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < runs; ++j) {
|
for (int j = 0; j < runs; ++j) {
|
||||||
uint16_t v = pio_read_one(pio, sm, off);
|
uint16_t v = pio_read_one(pio, sm, off, 0);
|
||||||
for (int i = 0; i < BINS; ++i) {
|
for (int i = 0; i < BINS; ++i) {
|
||||||
if ((bins[i].value == v && bins[i].noccur > 0) || bins[i].noccur == 0) {
|
if ((bins[i].value == v && bins[i].noccur > 0) || bins[i].noccur == 0) {
|
||||||
bins[i].value = v;
|
bins[i].value = v;
|
||||||
|
@ -87,7 +97,7 @@ static uint16_t pio_get_one(PIO pio, uint sm, uint32_t off, int runs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return bins[maxind].value;
|
return bins[maxind].value;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
extern int sbw_piosm;
|
extern int sbw_piosm;
|
||||||
void piodump_main(void) {
|
void piodump_main(void) {
|
||||||
|
@ -99,7 +109,7 @@ void piodump_main(void) {
|
||||||
|
|
||||||
uint16_t stuff[32];
|
uint16_t stuff[32];
|
||||||
for (uint32_t i = 0; i < 32; ++i) {
|
for (uint32_t i = 0; i < 32; ++i) {
|
||||||
stuff[i] = pio_get_one(PINOUT_SBW_PIO, (uint)sbw_piosm, i, 8);
|
stuff[i] = /*pio_get_one*/pio_read_one(PINOUT_SBW_PIO, (uint)sbw_piosm, i, 8);
|
||||||
bool good = stuff[i] == sbw_program_instructions[i];
|
bool good = stuff[i] == sbw_program_instructions[i];
|
||||||
printf("PIO_INSN[0x%02lx] = 0x%04x (%s)\n", i, stuff[i],
|
printf("PIO_INSN[0x%02lx] = 0x%04x (%s)\n", i, stuff[i],
|
||||||
good ? "correct" : "wrong");
|
good ? "correct" : "wrong");
|
||||||
|
|
Loading…
Reference in New Issue