mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
suppress formatting on in-line assembly in xous-pio
This commit is contained in:
parent
508476a085
commit
f00293a3a8
7 changed files with 557 additions and 579 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
use crate::*;
|
||||
use super::report_api;
|
||||
use crate::*;
|
||||
|
||||
pub fn adder_test() -> bool {
|
||||
report_api(0x5030_0000);
|
||||
|
|
@ -7,7 +7,7 @@ pub fn adder_test() -> bool {
|
|||
let mut pio_ss = PioSharedState::new();
|
||||
|
||||
let mut pio_sm = pio_ss.alloc_sm().unwrap();
|
||||
|
||||
#[rustfmt::skip]
|
||||
let adder_prog = pio_proc::pio_asm!(
|
||||
// Pop two 32 bit integers from the TX FIFO, add them together, and push the
|
||||
// result to the TX FIFO. Autopush/pull should be disabled as we're using
|
||||
|
|
@ -49,4 +49,4 @@ pub fn adder_test() -> bool {
|
|||
report_api(0x5030_600D);
|
||||
// loop panics if the sum doesn't work
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,9 @@
|
|||
use utralib::generated::utra::rp_pio;
|
||||
|
||||
use crate::*;
|
||||
use super::report_api;
|
||||
use crate::*;
|
||||
|
||||
pub fn i2c_init(
|
||||
pio_sm: &mut PioSm,
|
||||
program: &LoadedProg,
|
||||
pin_sda: usize,
|
||||
pin_scl: usize,
|
||||
) {
|
||||
pub fn i2c_init(pio_sm: &mut PioSm, program: &LoadedProg, pin_sda: usize, pin_scl: usize) {
|
||||
pio_sm.sm_set_enabled(false);
|
||||
program.setup_default_config(pio_sm);
|
||||
|
||||
|
|
@ -42,9 +37,7 @@ pub fn i2c_init(
|
|||
pio_sm.sm_init(program.entry());
|
||||
pio_sm.sm_set_enabled(true);
|
||||
}
|
||||
pub fn i2c_check_error(pio_sm: &mut PioSm) -> bool {
|
||||
pio_sm.sm_interrupt_get(pio_sm.sm_index())
|
||||
}
|
||||
pub fn i2c_check_error(pio_sm: &mut PioSm) -> bool { pio_sm.sm_interrupt_get(pio_sm.sm_index()) }
|
||||
pub fn i2c_resume_after_error(pio_sm: &mut PioSm) {
|
||||
pio_sm.sm_drain_tx_fifo();
|
||||
pio_sm.sm_jump_to_wrap_bottom();
|
||||
|
|
@ -52,7 +45,8 @@ pub fn i2c_resume_after_error(pio_sm: &mut PioSm) {
|
|||
pio_sm.pio.wfo(rp_pio::SFR_IRQ_SFR_IRQ, pio_sm.sm_bitmask());
|
||||
while i2c_check_error(pio_sm) {
|
||||
// wait for the IRQ to report cleared. This in not necessary on the RP2040, but because
|
||||
// our core can run much faster than the PIO we have to wait for the PIO to catch up to the core's state.
|
||||
// our core can run much faster than the PIO we have to wait for the PIO to catch up to the core's
|
||||
// state.
|
||||
}
|
||||
}
|
||||
pub fn i2c_rx_enable(pio_sm: &mut PioSm, en: bool) {
|
||||
|
|
@ -60,10 +54,11 @@ pub fn i2c_rx_enable(pio_sm: &mut PioSm, en: bool) {
|
|||
unsafe {
|
||||
let baseval = pio_sm.pio.base().add(rp_pio::SFR_SM0_SHIFTCTRL.offset() + sm_offset).read_volatile();
|
||||
let bitval = pio_sm.pio.ms(rp_pio::SFR_SM0_SHIFTCTRL_AUTO_PUSH, 1);
|
||||
pio_sm.pio.base().add(rp_pio::SFR_SM0_SHIFTCTRL.offset() + sm_offset).write_volatile(
|
||||
baseval & !bitval
|
||||
| if en {bitval} else {0}
|
||||
);
|
||||
pio_sm
|
||||
.pio
|
||||
.base()
|
||||
.add(rp_pio::SFR_SM0_SHIFTCTRL.offset() + sm_offset)
|
||||
.write_volatile(baseval & !bitval | if en { bitval } else { 0 });
|
||||
}
|
||||
}
|
||||
pub fn i2c_put16(pio_sm: &mut PioSm, data: u16) {
|
||||
|
|
@ -75,7 +70,7 @@ pub fn i2c_put16(pio_sm: &mut PioSm, data: u16) {
|
|||
pub fn i2c_put_or_err(pio_sm: &mut PioSm, data: u16) {
|
||||
while pio_sm.sm_txfifo_is_full() {
|
||||
if i2c_check_error(pio_sm) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
if i2c_check_error(pio_sm) {
|
||||
|
|
@ -83,14 +78,12 @@ pub fn i2c_put_or_err(pio_sm: &mut PioSm, data: u16) {
|
|||
}
|
||||
pio_sm.sm_txfifo_push_u16_msb(data);
|
||||
}
|
||||
pub fn i2c_get(pio_sm: &mut PioSm) -> u8 {
|
||||
pio_sm.sm_rxfifo_pull_u8_lsb() as u8
|
||||
}
|
||||
pub fn i2c_get(pio_sm: &mut PioSm) -> u8 { pio_sm.sm_rxfifo_pull_u8_lsb() as u8 }
|
||||
const PIO_I2C_ICOUNT_LSB: u16 = 10;
|
||||
const PIO_I2C_FINAL_LSB: u16 = 9;
|
||||
const PIO_I2C_FINAL_LSB: u16 = 9;
|
||||
#[allow(dead_code)]
|
||||
const PIO_I2C_DATA_LSB: u16 = 1;
|
||||
const PIO_I2C_NAK_LSB: u16 = 0;
|
||||
const PIO_I2C_DATA_LSB: u16 = 1;
|
||||
const PIO_I2C_NAK_LSB: u16 = 0;
|
||||
const I2C_SC0_SD0: usize = 0;
|
||||
#[allow(dead_code)]
|
||||
const I2C_SC0_SD1: usize = 1;
|
||||
|
|
@ -117,14 +110,19 @@ pub fn i2c_repstart(pio_sm: &mut PioSm, set_scl_sda_program_instructions: &[u16;
|
|||
}
|
||||
pub fn i2c_wait_idle(pio_sm: &mut PioSm) {
|
||||
pio_sm.pio.wfo(rp_pio::SFR_FDEBUG_TXSTALL, pio_sm.sm_bitmask());
|
||||
while ((pio_sm.pio.rf(rp_pio::SFR_FDEBUG_TXSTALL) & pio_sm.sm_bitmask()) == 0)
|
||||
|| i2c_check_error(pio_sm) {
|
||||
while ((pio_sm.pio.rf(rp_pio::SFR_FDEBUG_TXSTALL) & pio_sm.sm_bitmask()) == 0) || i2c_check_error(pio_sm)
|
||||
{
|
||||
// busy loop
|
||||
}
|
||||
}
|
||||
/// returns false if there is an error; true if no error
|
||||
#[allow(dead_code)]
|
||||
pub fn i2c_write_blocking(pio_sm: &mut PioSm, set_scl_sda_program_instructions: &[u16; 4], addr: u8, txbuf: &[u8]) -> bool {
|
||||
pub fn i2c_write_blocking(
|
||||
pio_sm: &mut PioSm,
|
||||
set_scl_sda_program_instructions: &[u16; 4],
|
||||
addr: u8,
|
||||
txbuf: &[u8],
|
||||
) -> bool {
|
||||
i2c_start(pio_sm, set_scl_sda_program_instructions);
|
||||
i2c_rx_enable(pio_sm, false);
|
||||
i2c_put16(pio_sm, ((addr as u16) << 2) | 1);
|
||||
|
|
@ -135,9 +133,9 @@ pub fn i2c_write_blocking(pio_sm: &mut PioSm, set_scl_sda_program_instructions:
|
|||
}
|
||||
if !pio_sm.sm_txfifo_is_full() {
|
||||
if let Some(&d) = txbuf_iter.next() {
|
||||
i2c_put_or_err(pio_sm,
|
||||
(d as u16) << PIO_I2C_DATA_LSB |
|
||||
if txbuf_iter.peek().is_none() { 1 } else { 0 }
|
||||
i2c_put_or_err(
|
||||
pio_sm,
|
||||
(d as u16) << PIO_I2C_DATA_LSB | if txbuf_iter.peek().is_none() { 1 } else { 0 },
|
||||
);
|
||||
} else {
|
||||
break;
|
||||
|
|
@ -155,7 +153,12 @@ pub fn i2c_write_blocking(pio_sm: &mut PioSm, set_scl_sda_program_instructions:
|
|||
}
|
||||
}
|
||||
/// returns false if there is an error; true if no error
|
||||
pub fn i2c_read_blocking(pio_sm: &mut PioSm, set_scl_sda_program_instructions: &[u16; 4], addr: u8, rxbuf: &mut [u8]) -> bool {
|
||||
pub fn i2c_read_blocking(
|
||||
pio_sm: &mut PioSm,
|
||||
set_scl_sda_program_instructions: &[u16; 4],
|
||||
addr: u8,
|
||||
rxbuf: &mut [u8],
|
||||
) -> bool {
|
||||
report_api(0x12C0_0000);
|
||||
|
||||
i2c_start(pio_sm, set_scl_sda_program_instructions);
|
||||
|
|
@ -180,12 +183,9 @@ pub fn i2c_read_blocking(pio_sm: &mut PioSm, set_scl_sda_program_instructions: &
|
|||
report_api(0x12C0_0000 + ((tx_remain as u32) << 8) | len as u32);
|
||||
if (tx_remain != 0) && !pio_sm.sm_txfifo_is_full() {
|
||||
tx_remain -= 1;
|
||||
i2c_put16(pio_sm,
|
||||
(0xff << 1)
|
||||
| if tx_remain != 0 { 0 } else {
|
||||
1 << PIO_I2C_FINAL_LSB
|
||||
| 1 << PIO_I2C_NAK_LSB
|
||||
}
|
||||
i2c_put16(
|
||||
pio_sm,
|
||||
(0xff << 1) | if tx_remain != 0 { 0 } else { 1 << PIO_I2C_FINAL_LSB | 1 << PIO_I2C_NAK_LSB },
|
||||
);
|
||||
}
|
||||
if !pio_sm.sm_rxfifo_is_empty() {
|
||||
|
|
@ -231,7 +231,7 @@ pub fn i2c_test() -> bool {
|
|||
let mut pio_ss = PioSharedState::new();
|
||||
let mut pio_sm = pio_ss.alloc_sm().unwrap();
|
||||
pio_sm.sm_set_enabled(false); // stop the machine from running so we can initialize it
|
||||
|
||||
#[rustfmt::skip]
|
||||
let i2c_prog = pio_proc::pio_asm!(
|
||||
".side_set 1 opt pindirs",
|
||||
|
||||
|
|
@ -304,7 +304,7 @@ pub fn i2c_test() -> bool {
|
|||
let prog_i2c = LoadedProg::load_with_entrypoint(i2c_prog.program, ep, &mut pio_ss).unwrap();
|
||||
i2c_init(&mut pio_sm, &prog_i2c, PIN_SDA, PIN_SCL);
|
||||
report_api(0x012C_3333);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let i2c_cmds_raw = pio_proc::pio_asm!(
|
||||
".side_set 1 opt",
|
||||
// Assemble a table of instructions which software can select from, and pass
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use crate::*;
|
||||
use utralib::utra::rp_pio;
|
||||
|
||||
use super::report_api;
|
||||
use crate::*;
|
||||
|
||||
const SIM_SCALE_FACTOR: f32 = 200.0; // speedup over real time to have simulation finish in a reasonable amount of time
|
||||
const BURST_PERIOD: f32 = 562.5e-6 / SIM_SCALE_FACTOR;
|
||||
const BURST_PERIOD: f32 = 562.5e-6 / SIM_SCALE_FACTOR;
|
||||
const CARRIER_PERIOD: f32 = 38.222e3 * SIM_SCALE_FACTOR;
|
||||
pub fn carrier_burst_init(pio_sm: &mut PioSm, program: &LoadedProg, pin: usize, freq: f32) {
|
||||
pio_sm.sm_set_enabled(false);
|
||||
|
|
@ -12,8 +13,7 @@ pub fn carrier_burst_init(pio_sm: &mut PioSm, program: &LoadedProg, pin: usize,
|
|||
// Map the SET pin group to one pin, namely the `pin`
|
||||
// parameter to this function.
|
||||
//
|
||||
pio_sm.config_set_set_pins (pin, 1);
|
||||
|
||||
pio_sm.config_set_set_pins(pin, 1);
|
||||
|
||||
// Set the pin direction to output at the PIO
|
||||
pio_sm.sm_set_pindirs_with_mask(pin, 1);
|
||||
|
|
@ -43,9 +43,10 @@ pub fn carrier_control_init(pio_sm: &mut PioSm, program: &LoadedProg, tick_rate:
|
|||
// configure the output shift register
|
||||
//
|
||||
pio_sm.config_set_out_shift(
|
||||
true, // shift right
|
||||
false, // disable autopull
|
||||
bits_per_frame);
|
||||
true, // shift right
|
||||
false, // disable autopull
|
||||
bits_per_frame,
|
||||
);
|
||||
|
||||
// join the FIFOs to make a single large transmit FIFO
|
||||
//
|
||||
|
|
@ -68,7 +69,7 @@ pub fn carrier_control_init(pio_sm: &mut PioSm, program: &LoadedProg, tick_rate:
|
|||
pub fn nec_tx_init(pio_ss: &mut PioSharedState, pin_num: usize) -> PioSm {
|
||||
let mut burst_sm = pio_ss.alloc_sm().unwrap();
|
||||
let mut control_sm = pio_ss.alloc_sm().unwrap();
|
||||
|
||||
#[rustfmt::skip]
|
||||
let carrier_burst_prog = pio_proc::pio_asm!(
|
||||
// Generate bursts of carrier.
|
||||
//
|
||||
|
|
@ -89,7 +90,7 @@ pub fn nec_tx_init(pio_ss: &mut PioSharedState, pin_num: usize) -> PioSm {
|
|||
" jmp x--, cycle_loop ", // (1 more cycle)
|
||||
".wrap ",
|
||||
);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let carrier_control_prog = pio_proc::pio_asm!(
|
||||
// Transmit an encoded 32-bit frame in NEC IR format.
|
||||
//
|
||||
|
|
@ -132,19 +133,14 @@ pub fn nec_tx_init(pio_ss: &mut PioSharedState, pin_num: usize) -> PioSm {
|
|||
carrier_burst_init(&mut burst_sm, &carrier_prog, pin_num, CARRIER_PERIOD);
|
||||
|
||||
let control_prog = LoadedProg::load(carrier_control_prog.program, pio_ss).unwrap();
|
||||
carrier_control_init(
|
||||
&mut control_sm,
|
||||
&control_prog,
|
||||
2.0 * (1.0 / BURST_PERIOD),
|
||||
32
|
||||
);
|
||||
carrier_control_init(&mut control_sm, &control_prog, 2.0 * (1.0 / BURST_PERIOD), 32);
|
||||
control_sm
|
||||
}
|
||||
|
||||
// Create a frame in `NEC` format from the provided 8-bit address and data
|
||||
//
|
||||
// Returns: a 32-bit encoded frame
|
||||
pub fn nec_encode_frame(address: u8, data: u8) -> u32{
|
||||
pub fn nec_encode_frame(address: u8, data: u8) -> u32 {
|
||||
// a normal 32-bit frame is encoded as address, inverted address, data, inverse data,
|
||||
address as u32 | (address as u32 ^ 0xff) << 8 | (data as u32) << 16 | (data as u32 ^ 0xff) << 24
|
||||
}
|
||||
|
|
@ -156,9 +152,10 @@ pub fn nec_receive_init(pio_sm: &mut PioSm, program: &LoadedProg, pin: usize, bu
|
|||
// configure the Input Shift Register
|
||||
//
|
||||
pio_sm.config_set_in_shift(
|
||||
true, // shift right
|
||||
true, // enable autopush
|
||||
32); // autopush after 32 bits
|
||||
true, // shift right
|
||||
true, // enable autopush
|
||||
32,
|
||||
); // autopush after 32 bits
|
||||
|
||||
// join the FIFOs to make a single large receive FIFO
|
||||
//
|
||||
|
|
@ -189,7 +186,7 @@ pub fn nec_receive_init(pio_sm: &mut PioSm, program: &LoadedProg, pin: usize, bu
|
|||
|
||||
pub fn nec_rx_init(pio_ss: &mut PioSharedState, pin_num: usize) -> PioSm {
|
||||
let mut rx_sm = pio_ss.alloc_sm().unwrap();
|
||||
|
||||
#[rustfmt::skip]
|
||||
let nec_receive = pio_proc::pio_asm!(
|
||||
// Decode IR frames in NEC format and push 32-bit words to the input FIFO.
|
||||
//
|
||||
|
|
@ -234,19 +231,16 @@ pub fn nec_rx_init(pio_ss: &mut PioSharedState, pin_num: usize) -> PioSm {
|
|||
rx_sm
|
||||
}
|
||||
|
||||
|
||||
// Validate a 32-bit frame and store the address and data at the locations
|
||||
// provided.
|
||||
//
|
||||
// Returns: `true` if the frame was valid, otherwise `false`
|
||||
pub fn nec_decode_frame(frame: u32, addr: &mut u8, d: &mut u8) -> bool {
|
||||
|
||||
let [address, inverted_address, data, inverted_data] = frame.to_le_bytes();
|
||||
|
||||
// a valid (non-extended) 'NEC' frame should contain 8 bit
|
||||
// address, inverted address, data and inverted data
|
||||
if address != (inverted_address ^ 0xff) ||
|
||||
data != (inverted_data ^ 0xff) {
|
||||
if address != (inverted_address ^ 0xff) || data != (inverted_data ^ 0xff) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -292,4 +286,3 @@ pub fn nec_ir_loopback_test() {
|
|||
|
||||
report_api(0x1300_600D);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
use utralib::generated::utra::rp_pio;
|
||||
use crate::*;
|
||||
|
||||
use super::report_api;
|
||||
use crate::*;
|
||||
|
||||
#[inline(always)]
|
||||
pub fn pio_spi_write8_read8_blocking (
|
||||
pio_sm: &mut PioSm,
|
||||
src: &[u8],
|
||||
dst: &mut [u8],
|
||||
) {
|
||||
pub fn pio_spi_write8_read8_blocking(pio_sm: &mut PioSm, src: &[u8], dst: &mut [u8]) {
|
||||
assert!(src.len() == dst.len(), "src and dst arrays are not the same length!");
|
||||
|
||||
let mut src_iter = src.iter();
|
||||
|
|
@ -50,7 +47,7 @@ pub fn pio_spi_write8_read8_blocking (
|
|||
rx_done = true;
|
||||
}
|
||||
if tx_done && rx_done {
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +86,7 @@ pub fn pio_spi_init(
|
|||
cpol: bool,
|
||||
pin_sck: usize,
|
||||
pin_mosi: usize,
|
||||
pin_miso: usize
|
||||
pin_miso: usize,
|
||||
) {
|
||||
pio_sm.sm_set_enabled(false);
|
||||
// this applies a default config to the PioSm object that is relevant to the program
|
||||
|
|
@ -103,13 +100,10 @@ pub fn pio_spi_init(
|
|||
pio_sm.config_set_clkdiv(clkdiv);
|
||||
|
||||
// MOSI, SCK output are low, MISO is input
|
||||
pio_sm.sm_set_pins_with_mask(
|
||||
0,
|
||||
(1 << pin_sck) | (1 << pin_mosi)
|
||||
);
|
||||
pio_sm.sm_set_pins_with_mask(0, (1 << pin_sck) | (1 << pin_mosi));
|
||||
pio_sm.sm_set_pindirs_with_mask(
|
||||
(1 << pin_sck) | (1 << pin_mosi),
|
||||
(1 << pin_sck) | (1 << pin_mosi) | (1 << pin_miso)
|
||||
(1 << pin_sck) | (1 << pin_mosi) | (1 << pin_miso),
|
||||
);
|
||||
|
||||
pio_sm.gpio_set_outover(pin_sck, cpol);
|
||||
|
|
@ -136,12 +130,14 @@ pub fn spi_test() -> bool {
|
|||
let mut pio_sm = pio_ss.alloc_sm().unwrap();
|
||||
|
||||
// spi_cpha0 example
|
||||
#[rustfmt::skip]
|
||||
let spi_cpha0_prog = pio_proc::pio_asm!(
|
||||
".side_set 1",
|
||||
"out pins, 1 side 0 [1]",
|
||||
"in pins, 1 side 1 [1]",
|
||||
);
|
||||
// spi_cpha1 example
|
||||
#[rustfmt::skip]
|
||||
let spi_cpha1_prog = pio_proc::pio_asm!(
|
||||
".side_set 1",
|
||||
"out x, 1 side 0", // Stall here on empty (keep SCK deasserted)
|
||||
|
|
@ -169,7 +165,7 @@ pub fn spi_test() -> bool {
|
|||
cpol,
|
||||
PIN_SCK,
|
||||
PIN_MOSI,
|
||||
PIN_MISO
|
||||
PIN_MISO,
|
||||
);
|
||||
report_api(0x05D1_0003);
|
||||
if spi_test_core(&mut pio_sm) == false {
|
||||
|
|
@ -186,7 +182,7 @@ pub fn spi_test() -> bool {
|
|||
cpol,
|
||||
PIN_SCK,
|
||||
PIN_MOSI,
|
||||
PIN_MISO
|
||||
PIN_MISO,
|
||||
);
|
||||
report_api(0x05D1_0005);
|
||||
if spi_test_core(&mut pio_sm) == false {
|
||||
|
|
@ -211,4 +207,4 @@ pub fn spi_test() -> bool {
|
|||
}
|
||||
assert!(passing);
|
||||
passing
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use pio::RP2040_MAX_PROGRAM_SIZE;
|
||||
use utralib::utra::rp_pio::{self, SFR_FDEBUG, SFR_FLEVEL, SFR_FSTAT, SFR_DBG_CFGINFO};
|
||||
use crate::*;
|
||||
use utralib::utra::rp_pio::{self, SFR_DBG_CFGINFO, SFR_FDEBUG, SFR_FLEVEL, SFR_FSTAT};
|
||||
|
||||
use super::report_api;
|
||||
use crate::*;
|
||||
|
||||
/// Test the sticky out bits
|
||||
pub fn sticky_test() {
|
||||
|
|
@ -33,15 +34,15 @@ pub fn sticky_test() {
|
|||
report_api(0x51C2_0001);
|
||||
pio_ss.clear_instruction_memory();
|
||||
report_api(0x51C2_0002);
|
||||
let mut sm_a = unsafe{pio_ss.force_alloc_sm(1).unwrap()};
|
||||
let mut sm_a = unsafe { pio_ss.force_alloc_sm(1).unwrap() };
|
||||
report_api(0x51C2_0003);
|
||||
let mut sm_b = unsafe{pio_ss.force_alloc_sm(2).unwrap()};
|
||||
let mut sm_b = unsafe { pio_ss.force_alloc_sm(2).unwrap() };
|
||||
report_api(0x51C2_0004);
|
||||
sm_a.sm_set_enabled(false);
|
||||
report_api(0x51C2_0005);
|
||||
sm_b.sm_set_enabled(false);
|
||||
report_api(0x51C2_0006);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"set pins, 1",
|
||||
"set pins, 2",
|
||||
|
|
@ -51,6 +52,7 @@ pub fn sticky_test() {
|
|||
"nop"
|
||||
);
|
||||
let a_prog = LoadedProg::load(a_code.program, &mut pio_ss).unwrap();
|
||||
#[rustfmt::skip]
|
||||
let b_code = pio_proc::pio_asm!(
|
||||
// bit 4 indicates enable; bit 3 is the "B" machine flag. bits 2:0 are the payload
|
||||
"nop",
|
||||
|
|
@ -60,7 +62,8 @@ pub fn sticky_test() {
|
|||
"set pins, 0x1D", // with enable
|
||||
"set pins, 0x0E", // without enable
|
||||
);
|
||||
// note: this loads using sm_a so we can share the "used" vector state, but the code is global across all SM's
|
||||
// note: this loads using sm_a so we can share the "used" vector state, but the code is global across all
|
||||
// SM's
|
||||
let b_prog = LoadedProg::load(b_code.program, &mut pio_ss).unwrap();
|
||||
|
||||
report_api(0x51C2_0007);
|
||||
|
|
@ -89,9 +92,9 @@ pub fn sticky_test() {
|
|||
sm_a.pio.wo(
|
||||
rp_pio::SFR_CTRL,
|
||||
sm_a.pio.ms(rp_pio::SFR_CTRL_CLKDIV_RESTART, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_CLKDIV_RESTART, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_CLKDIV_RESTART, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_b.sm_bitmask()),
|
||||
);
|
||||
while (sm_a.pio.r(rp_pio::SFR_CTRL) & !0xF) != 0 {
|
||||
// wait for the bits to self-reset to acknowledge that the command has executed
|
||||
|
|
@ -101,7 +104,7 @@ pub fn sticky_test() {
|
|||
sm_a.pio.wo(
|
||||
rp_pio::SFR_CTRL,
|
||||
sm_a.pio.ms(rp_pio::SFR_CTRL_EN, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_EN, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_EN, sm_b.sm_bitmask()),
|
||||
);
|
||||
// wait for it to run
|
||||
for i in 0..16 {
|
||||
|
|
@ -126,9 +129,9 @@ pub fn sticky_test() {
|
|||
sm_a.pio.wo(
|
||||
rp_pio::SFR_CTRL,
|
||||
sm_a.pio.ms(rp_pio::SFR_CTRL_CLKDIV_RESTART, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_CLKDIV_RESTART, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_CLKDIV_RESTART, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_RESTART, sm_b.sm_bitmask()),
|
||||
);
|
||||
while (sm_a.pio.r(rp_pio::SFR_CTRL) & !0xF) != 0 {
|
||||
// wait for the bits to self-reset to acknowledge that the command has executed
|
||||
|
|
@ -138,7 +141,7 @@ pub fn sticky_test() {
|
|||
sm_a.pio.wo(
|
||||
rp_pio::SFR_CTRL,
|
||||
sm_a.pio.ms(rp_pio::SFR_CTRL_EN, sm_a.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_EN, sm_b.sm_bitmask())
|
||||
| sm_a.pio.ms(rp_pio::SFR_CTRL_EN, sm_b.sm_bitmask()),
|
||||
);
|
||||
// wait for it to run
|
||||
for i in 0..16 {
|
||||
|
|
@ -162,7 +165,7 @@ pub fn sticky_test() {
|
|||
pub fn delay(count: usize) {
|
||||
let mut target = [0u32; 1];
|
||||
for i in 0..count * 2 {
|
||||
unsafe {target.as_mut_ptr().write_volatile(i as u32)}
|
||||
unsafe { target.as_mut_ptr().write_volatile(i as u32) }
|
||||
core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
|
@ -195,9 +198,9 @@ fn wait_rx_or_fail(sm: &mut PioSm, rxval: u32, mask: Option<u32>, timeout: Optio
|
|||
}
|
||||
|
||||
fn wait_gpio_or_fail(ss: &PioSharedState, pinval: u32, mask: Option<u32>, timeout: Option<usize>) {
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
let io_mask = 0x3FFF_FFFF;
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
let io_mask = 0xFFFF_FFFF;
|
||||
|
||||
let mask = mask.unwrap_or(io_mask);
|
||||
|
|
@ -242,9 +245,9 @@ fn wait_irq_exactly_or_fail(sm: &PioSm, irq_index: usize, timeout: Option<usize>
|
|||
/// corner cases
|
||||
pub fn corner_cases() {
|
||||
report_api(0xF1F0_0000);
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
let io_mask = 0x3FFF_FFFF;
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
let io_mask = 0xFFFF_FFFF;
|
||||
|
||||
report_api(0xcc00_0000);
|
||||
|
|
@ -254,7 +257,7 @@ pub fn corner_cases() {
|
|||
let mut sm_a = pio_ss.alloc_sm().unwrap();
|
||||
pio_ss.clear_instruction_memory();
|
||||
pio_ss.pio.rmwf(rp_pio::SFR_CTRL_EN, 0);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"out y, 0", // 32 is coded as 0. If you put 32 in, this changes the "y" source to "null"!
|
||||
"in y, 0", // 32 is coded as 0
|
||||
|
|
@ -288,6 +291,7 @@ pub fn corner_cases() {
|
|||
|
||||
report_api(0xcc00_1111);
|
||||
// exec corner case: EXEC instruction should side-effect the PC -----------------------
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"set x, 17", // 18
|
||||
"exec_loop:", // normally you'd want out exec, 32 to keep things simple but out exec, 16 will cause two instructions to run per pull of the fifo
|
||||
|
|
@ -362,6 +366,7 @@ pub fn corner_cases() {
|
|||
report_api(0xcc00_2222);
|
||||
// exec corner case: exec can clear stalled IRQ -----------------------
|
||||
let mut sm_b = pio_ss.alloc_sm().unwrap(); // run this on SM_B so we can test `rel` irqs
|
||||
#[rustfmt::skip]
|
||||
let b_code = pio_proc::pio_asm!(
|
||||
"set x, 12", // 0x1d put an initial value in x
|
||||
"wait 1 irq 6 rel", // 0x1e this should stall <--- wait target
|
||||
|
|
@ -378,7 +383,7 @@ pub fn corner_cases() {
|
|||
sm_b.sm_clear_fifos(); // ensure the fifos are cleared for this test
|
||||
sm_b.sm_set_enabled(true);
|
||||
|
||||
wait_addr_or_fail(&sm_b, 0x1e, Some(100)); // manual match to wait target
|
||||
wait_addr_or_fail(&sm_b, 0x1e, Some(100)); // manual match to wait target
|
||||
let exec_set_irq6 = pio_proc::pio_asm!("irq set 6 rel").program.code[0];
|
||||
sm_b.sm_exec(exec_set_irq6);
|
||||
wait_rx_or_fail(&mut sm_b, 12, None, None);
|
||||
|
|
@ -388,6 +393,7 @@ pub fn corner_cases() {
|
|||
|
||||
// exec corner case: exec can clear stalled IRQ --------------------------------
|
||||
// exec corner case: exec can break out of stalled instruction with JMP --------
|
||||
#[rustfmt::skip]
|
||||
let b_code = pio_proc::pio_asm!(
|
||||
"top:",
|
||||
" set y, 12", // 0x1a put an initial value in y
|
||||
|
|
@ -403,37 +409,37 @@ pub fn corner_cases() {
|
|||
// check multiple clkdiv cases to capture corners in the irq_stb logic
|
||||
let divs = [1.0f32, 3.5f32, 4.0f32];
|
||||
let mut divstate = 0x3333u32;
|
||||
divs.map(
|
||||
|clkdiv: f32| {
|
||||
report_api(0xcc00_0000 + divstate);
|
||||
divstate += 0x1111;
|
||||
sm_b.sm_set_enabled(false);
|
||||
b_prog.setup_default_config(&mut sm_b);
|
||||
sm_b.config_set_out_pins(0, 32);
|
||||
sm_b.config_set_clkdiv(clkdiv);
|
||||
sm_b.config_set_out_shift(true, true, 32);
|
||||
sm_b.config_set_in_shift(false, true, 32);
|
||||
sm_b.sm_init(b_prog.entry());
|
||||
sm_b.sm_clear_fifos(); // ensure the fifos are cleared for this test
|
||||
sm_b.sm_set_enabled(true);
|
||||
divs.map(|clkdiv: f32| {
|
||||
report_api(0xcc00_0000 + divstate);
|
||||
divstate += 0x1111;
|
||||
sm_b.sm_set_enabled(false);
|
||||
b_prog.setup_default_config(&mut sm_b);
|
||||
sm_b.config_set_out_pins(0, 32);
|
||||
sm_b.config_set_clkdiv(clkdiv);
|
||||
sm_b.config_set_out_shift(true, true, 32);
|
||||
sm_b.config_set_in_shift(false, true, 32);
|
||||
sm_b.sm_init(b_prog.entry());
|
||||
sm_b.sm_clear_fifos(); // ensure the fifos are cleared for this test
|
||||
sm_b.sm_set_enabled(true);
|
||||
|
||||
wait_addr_or_fail(&sm_b, 0x1b, Some(100)); // manual match to wait target
|
||||
let exec_set_irq6 = pio_proc::pio_asm!("irq set 6 rel").program.code[0];
|
||||
sm_b.sm_exec(exec_set_irq6);
|
||||
// exactly one entry should go into the Rx fifo. If the irq does not self-clear after exec, we will get more than one, and the next check fails.
|
||||
wait_rx_or_fail(&mut sm_b, 12, None, None);
|
||||
wait_addr_or_fail(&sm_b, 0x1b, Some(100)); // manual match to wait target
|
||||
let exec_set_irq6 = pio_proc::pio_asm!("irq set 6 rel").program.code[0];
|
||||
sm_b.sm_exec(exec_set_irq6);
|
||||
// exactly one entry should go into the Rx fifo. If the irq does not self-clear after exec, we will
|
||||
// get more than one, and the next check fails.
|
||||
wait_rx_or_fail(&mut sm_b, 12, None, None);
|
||||
|
||||
// program will loop back to top, and will be stuck at wait again
|
||||
wait_addr_or_fail(&sm_b, 0x1b, Some(100)); // manual match to wait target
|
||||
let exec_jmp_bypass = pio_proc::pio_asm!("jmp y--, 0x1e").program.code[0];
|
||||
sm_b.sm_exec(exec_jmp_bypass);
|
||||
wait_rx_or_fail(&mut sm_b, !11, None, None);
|
||||
}
|
||||
);
|
||||
// program will loop back to top, and will be stuck at wait again
|
||||
wait_addr_or_fail(&sm_b, 0x1b, Some(100)); // manual match to wait target
|
||||
let exec_jmp_bypass = pio_proc::pio_asm!("jmp y--, 0x1e").program.code[0];
|
||||
sm_b.sm_exec(exec_jmp_bypass);
|
||||
wait_rx_or_fail(&mut sm_b, !11, None, None);
|
||||
});
|
||||
|
||||
// exec corner case: OUT EXEC can clear stalled IRQ -------------------
|
||||
pio_ss.clear_instruction_memory();
|
||||
report_api(0xcc00_6666);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"top:",
|
||||
" set y, 5", // 0x19 put an initial value in y
|
||||
|
|
@ -456,16 +462,16 @@ pub fn corner_cases() {
|
|||
sm_a.sm_clear_fifos(); // ensure the fifos are cleared for this test
|
||||
sm_a.sm_set_enabled(true);
|
||||
|
||||
wait_addr_or_fail(&sm_a, 0x1a, Some(100)); // manual match to wait target
|
||||
wait_addr_or_fail(&sm_a, 0x1a, Some(100)); // manual match to wait target
|
||||
let exec_set_irq2 = pio_proc::pio_asm!("irq set 2 rel").program.code[0];
|
||||
sm_a.sm_txfifo_push_u32(exec_set_irq2 as u32);
|
||||
wait_rx_or_fail(&mut sm_a, 5, None, None);
|
||||
|
||||
// exec corner case: writing over stalled instruction breaks stall ----------
|
||||
wait_addr_or_fail(&sm_a, 0x1a, Some(100)); // manual match to wait target
|
||||
wait_addr_or_fail(&sm_a, 0x1a, Some(100)); // manual match to wait target
|
||||
let nop = pio_proc::pio_asm!("mov y, y").program.code[0];
|
||||
sm_a.sm_txfifo_push_u32(nop as u32); // break the out exec stall, but get stuck at "wait 1 irq 2 rel"
|
||||
wait_addr_or_fail(&sm_a, 0x1b, Some(100)); // manual match to wait target
|
||||
wait_addr_or_fail(&sm_a, 0x1b, Some(100)); // manual match to wait target
|
||||
let set_y_31 = pio_proc::pio_asm!("set y, 31").program.code[0];
|
||||
// slot this over the blocked instruction: 0x1b == 27
|
||||
pio_ss.pio.wfo(rp_pio::SFR_INSTR_MEM27_INSTR, set_y_31 as u32);
|
||||
|
|
@ -488,6 +494,7 @@ pub fn corner_cases() {
|
|||
// IO corner case: side-set happens when SM is stalled --------------------
|
||||
pio_ss.clear_instruction_memory();
|
||||
report_api(0xcc00_7777);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
".side_set 1 opt"
|
||||
"top:",
|
||||
|
|
@ -527,6 +534,7 @@ pub fn corner_cases() {
|
|||
pio_ss.clear_instruction_memory();
|
||||
report_api(0xcc00_8888);
|
||||
// this one will toggle pins via a side-set
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
".side_set 1 opt"
|
||||
" mov osr, null", // 0x1b load OSR with 0
|
||||
|
|
@ -562,6 +570,7 @@ pub fn corner_cases() {
|
|||
pio_ss.clear_instruction_memory();
|
||||
sm_a.sm_set_enabled(false);
|
||||
report_api(0xcc00_9999);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
".side_set 5",
|
||||
" out pins, 16 side 0x1A", // 0x1d
|
||||
|
|
@ -574,7 +583,7 @@ pub fn corner_cases() {
|
|||
sm_a.config_set_clkdiv(1.15);
|
||||
sm_a.config_set_out_shift(true, true, 16);
|
||||
sm_a.config_set_out_pins(24, 16); // should wrap to lower 8 bits
|
||||
sm_a.config_set_set_pins(28, 5); // should wrap 1 bit over
|
||||
sm_a.config_set_set_pins(28, 5); // should wrap 1 bit over
|
||||
sm_a.config_set_sideset_pins(30); // should wrap 3 bits over
|
||||
sm_a.sm_init(a_prog.entry());
|
||||
sm_a.sm_clear_fifos();
|
||||
|
|
@ -619,8 +628,9 @@ pub fn corner_cases() {
|
|||
sm_a.sm_set_enabled(false);
|
||||
report_api(0xcc00_aaaa);
|
||||
// set all the output
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
sm_a.sm_set_pindirs_with_mask(0xffff_ffff, 0xffff_ffff);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
" out pins, 0",
|
||||
" in pins, 24",
|
||||
|
|
@ -642,12 +652,13 @@ pub fn corner_cases() {
|
|||
sm_a.sm_set_enabled(true);
|
||||
|
||||
sm_a.sm_txfifo_push_u32(0xaa12_3455);
|
||||
// the differences from the pushed is due to the test bench harnessing, some gpio pins are not looped back or are modified by the test bench for other tests!
|
||||
// this value is just read back manually from the waveforms
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
let model = rot_left(0x2a12_345D, 32-9) & 0xFF_FFFF;
|
||||
#[cfg(feature="rp2040")]
|
||||
let model = rot_left(0xaa12_3455 & io_mask & !(1 << 25), 32-9) & 0xFF_FFFF; // top 2 bits don't exist on rp2040, bit 25 is for LED
|
||||
// the differences from the pushed is due to the test bench harnessing, some gpio pins are not looped back
|
||||
// or are modified by the test bench for other tests! this value is just read back manually from the
|
||||
// waveforms
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
let model = rot_left(0x2a12_345D, 32 - 9) & 0xFF_FFFF;
|
||||
#[cfg(feature = "rp2040")]
|
||||
let model = rot_left(0xaa12_3455 & io_mask & !(1 << 25), 32 - 9) & 0xFF_FFFF; // top 2 bits don't exist on rp2040, bit 25 is for LED
|
||||
report_api(model);
|
||||
wait_rx_or_fail(&mut sm_a, model, None, None);
|
||||
|
||||
|
|
@ -661,14 +672,15 @@ pub fn corner_cases() {
|
|||
|
||||
// autopush/pull cases ----------------------------------------------------
|
||||
// 1. auto p/p does not happen while SM is disabled
|
||||
// 2. auto pull happens on an EXEC, even when SM is disabled
|
||||
// a. case of EXEC is an instruction that would do a pull, but stalled instruction does not do pull
|
||||
// b. case of EXEC is an instruction that is NOP, but stalled instruction does do pull
|
||||
// 2. auto pull happens on an EXEC, even when SM is disabled a. case of EXEC is an instruction that would
|
||||
// do a pull, but stalled instruction does not do pull b. case of EXEC is an instruction that is NOP,
|
||||
// but stalled instruction does do pull
|
||||
// 3. OUT with empty OSR but nonempty TX FIFO should not set TX stall flag, + 1-cycle stall
|
||||
// 4. EXEC of OUT 32 to disabled SM, with empty OSR + filled FIFO consumes two words from FIFO
|
||||
pio_ss.clear_instruction_memory();
|
||||
sm_a.sm_set_enabled(false);
|
||||
report_api(0xcc00_bbbb);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
" out x, 0",
|
||||
" in x, 0", // loop back for testing
|
||||
|
|
@ -711,6 +723,7 @@ pub fn corner_cases() {
|
|||
pio_ss.clear_instruction_memory();
|
||||
sm_a.sm_set_enabled(false);
|
||||
report_api(0xcc04_bbbb);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
" wait 1 irq 0", // this will do a wait
|
||||
" in x, 0",
|
||||
|
|
@ -753,6 +766,7 @@ pub fn corner_cases() {
|
|||
report_api(0xcc08_cccc);
|
||||
pio_ss.clear_instruction_memory();
|
||||
sm_a.sm_set_enabled(false);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
" out x, 0",
|
||||
" in x, 0", // loop back for testing
|
||||
|
|
@ -776,9 +790,7 @@ pub fn corner_cases() {
|
|||
|
||||
report_api(0xcc00_600d);
|
||||
}
|
||||
fn rot_left(word: u32, count: u32) -> u32 {
|
||||
(word << count) | ((word >> (32-count)) & ((1 << count) - 1))
|
||||
}
|
||||
fn rot_left(word: u32, count: u32) -> u32 { (word << count) | ((word >> (32 - count)) & ((1 << count) - 1)) }
|
||||
|
||||
pub fn instruction_tests() {
|
||||
report_api(0x1c5f_0000);
|
||||
|
|
@ -788,6 +800,7 @@ pub fn instruction_tests() {
|
|||
pio_ss.pio.rmwf(rp_pio::SFR_CTRL_EN, 0);
|
||||
|
||||
// check mov, irq, wait corners ------------------------------------------------------
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"irq set 7", // just to make sure this is behaving correctly (staring at waveforms)
|
||||
"out x, 0",
|
||||
|
|
@ -805,8 +818,9 @@ pub fn instruction_tests() {
|
|||
let a_prog = LoadedProg::load(a_code.program, &mut pio_ss).unwrap();
|
||||
sm_a.sm_set_enabled(false);
|
||||
a_prog.setup_default_config(&mut sm_a);
|
||||
// if this is set to <2.0 the "retrograde PC" check at the bottom needs to be commented out, because the PC moves too fast for the APB to reliably sample
|
||||
// also, this should not be an even multiple, otherwise we can end up sampling the exact same phase over and over again.
|
||||
// if this is set to <2.0 the "retrograde PC" check at the bottom needs to be commented out, because the
|
||||
// PC moves too fast for the APB to reliably sample also, this should not be an even multiple,
|
||||
// otherwise we can end up sampling the exact same phase over and over again.
|
||||
sm_a.config_set_clkdiv(5.0);
|
||||
sm_a.config_set_out_shift(true, true, 32);
|
||||
sm_a.config_set_in_shift(true, true, 32);
|
||||
|
|
@ -822,25 +836,24 @@ pub fn instruction_tests() {
|
|||
rp_pio::SFR_SM0_EXECCTRL,
|
||||
pio_ss.pio.zf(
|
||||
rp_pio::SFR_SM0_EXECCTRL_STATUS_SEL,
|
||||
pio_ss.pio.zf(rp_pio::SFR_SM0_EXECCTRL_STATUS_N,
|
||||
pio_ss.pio.r(rp_pio::SFR_SM0_EXECCTRL)
|
||||
)
|
||||
)
|
||||
| pio_ss.pio.ms(rp_pio::SFR_SM0_EXECCTRL_STATUS_SEL, status_sel as u32)
|
||||
| pio_ss.pio.ms(rp_pio::SFR_SM0_EXECCTRL_STATUS_N, level as u32)
|
||||
pio_ss.pio.zf(rp_pio::SFR_SM0_EXECCTRL_STATUS_N, pio_ss.pio.r(rp_pio::SFR_SM0_EXECCTRL)),
|
||||
) | pio_ss.pio.ms(rp_pio::SFR_SM0_EXECCTRL_STATUS_SEL, status_sel as u32)
|
||||
| pio_ss.pio.ms(rp_pio::SFR_SM0_EXECCTRL_STATUS_N, level as u32),
|
||||
);
|
||||
let expected_value = if 2 < level {0xFFFF_FFFF} else {0};
|
||||
let expected_value = if 2 < level { 0xFFFF_FFFF } else { 0 };
|
||||
|
||||
// reset the PC
|
||||
let mut a = pio::Assembler::<32>::new();
|
||||
let mut initial_label = a.label_at_offset(a_prog.entry() as u8);
|
||||
a.jmp(pio::JmpCondition::Always, &mut initial_label);
|
||||
let p= a.assemble_program();
|
||||
let p = a.assemble_program();
|
||||
sm_a.sm_exec(p.code[p.origin.unwrap_or(0) as usize]);
|
||||
pio_ss.pio.wfo(rp_pio::SFR_CTRL_RESTART, sm_a.sm_bitmask());
|
||||
sm_a.sm_set_enabled(true);
|
||||
|
||||
for i in 1..=5 { // put 5 entries in; the first two should go to the Rx fifo, 1 should be in the state machine, 2 remaining in the FIFO
|
||||
for i in 1..=5 {
|
||||
// put 5 entries in; the first two should go to the Rx fifo, 1 should be in the state machine, 2
|
||||
// remaining in the FIFO
|
||||
sm_a.sm_txfifo_push_u32(0x1c5f_0000 + i);
|
||||
}
|
||||
// we should now have a level == 2 for both
|
||||
|
|
@ -864,9 +877,9 @@ pub fn instruction_tests() {
|
|||
wait_rx_or_fail(&mut sm_a, 0x1c5f_0002, None, None);
|
||||
report_api(expected_value);
|
||||
wait_rx_or_fail(&mut sm_a, expected_value, None, None);
|
||||
// retrograde movement of address would indicate we're in the loop (this might not work perfectly on real hardware due to synchronizers)
|
||||
// commented out, because this test is too sensitive to external clock config
|
||||
// wait_addr_or_fail(&sm_a, 31, None);
|
||||
// retrograde movement of address would indicate we're in the loop (this might not work perfectly on
|
||||
// real hardware due to synchronizers) commented out, because this test is too sensitive to
|
||||
// external clock config wait_addr_or_fail(&sm_a, 31, None);
|
||||
// wait_addr_or_fail(&sm_a, 30, None);
|
||||
|
||||
level += 1;
|
||||
|
|
@ -885,6 +898,7 @@ pub fn instruction_tests() {
|
|||
pio_ss.pio.rmwf(rp_pio::SFR_CTRL_EN, 0);
|
||||
report_api(0x1c5f_1111);
|
||||
// all the jumps --------------------------------------------------------------
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
" set x, 3",
|
||||
"test_notx:",
|
||||
|
|
@ -950,6 +964,7 @@ pub fn instruction_tests() {
|
|||
pio_ss.pio.rmwf(rp_pio::SFR_CTRL_EN, 0);
|
||||
report_api(0x1c5f_2222);
|
||||
// all the ISRs and OSRs (left shifting) -------------------------------------------------
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"start:",
|
||||
"pull ifempty block", // 09 get a value from the Tx FIFO -> OSR
|
||||
|
|
@ -1028,6 +1043,7 @@ pub fn instruction_tests() {
|
|||
pio_ss.pio.rmwf(rp_pio::SFR_CTRL_EN, 0);
|
||||
report_api(0x1c5f_3333);
|
||||
// all the MOVs (plus right shifting) -------------------------------------------------
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"start:",
|
||||
"pull block",
|
||||
|
|
@ -1077,12 +1093,12 @@ pub fn instruction_tests() {
|
|||
sm_a.sm_txfifo_push_u32(0b101_110 | 0xFF00_0000); // shifting right, so we'll take these LSBs; or something else at the top so we can detect if it shifted the other way
|
||||
wait_irq_exactly_or_fail(&sm_a, 0, None);
|
||||
wait_rx_or_fail(&mut sm_a, !0x1234_abcd, None, None);
|
||||
wait_rx_or_fail(&mut sm_a, 0b100_011 << (32-6), None, None);
|
||||
wait_rx_or_fail(&mut sm_a, 0b100_011 << (32 - 6), None, None);
|
||||
report_api(0x1c5f_3334);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
let gpio_val = 0b011_101 << (32-6);
|
||||
#[cfg(feature="rp2040")]
|
||||
let gpio_val = (0b011_101 << (32-6)) & !(1 << 25) & 0x3FFF_FFFF;
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
let gpio_val = 0b011_101 << (32 - 6);
|
||||
#[cfg(feature = "rp2040")]
|
||||
let gpio_val = (0b011_101 << (32 - 6)) & !(1 << 25) & 0x3FFF_FFFF;
|
||||
report_api(gpio_val);
|
||||
wait_gpio_or_fail(&pio_ss, gpio_val, None, None);
|
||||
// clear the IRQ wait
|
||||
|
|
@ -1091,12 +1107,12 @@ pub fn instruction_tests() {
|
|||
// pins <- pins mov test
|
||||
report_api(0x1c5f_3335);
|
||||
wait_irq_exactly_or_fail(&sm_a, 1, None);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
{
|
||||
let rbk_val = !rot_left(gpio_val | 0xC, 16); // 0xC is or'd in due to the i2c loopback pins
|
||||
wait_gpio_or_fail(&pio_ss, rbk_val, Some(!0x8000_000C), None); // ignore the pins not looped back by the test bench (2,3,31)
|
||||
}
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
{
|
||||
let rbk_val = !rot_left(gpio_val & 0x3FFF_FFFF | 3, 16); // lowest 2 bits read back back as 11
|
||||
report_api(rbk_val);
|
||||
|
|
@ -1122,6 +1138,7 @@ pub fn instruction_tests() {
|
|||
pio_ss.clear_instruction_memory();
|
||||
pio_ss.pio.rmwf(rp_pio::SFR_CTRL_EN, 0);
|
||||
report_api(0x1c5f_4444);
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"start:",
|
||||
" set x, 0",
|
||||
|
|
@ -1182,6 +1199,7 @@ pub fn restart_imm_test() {
|
|||
pio_ss.pio.rmwf(rp_pio::SFR_CTRL_EN, 0);
|
||||
|
||||
let mut sm_a = pio_ss.alloc_sm().unwrap();
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"set pins, 1",
|
||||
"set pins, 2",
|
||||
|
|
@ -1207,7 +1225,7 @@ pub fn restart_imm_test() {
|
|||
|
||||
let mut a = pio::Assembler::<32>::new();
|
||||
a.out(pio::OutDestination::PINS, 16);
|
||||
let p= a.assemble_program();
|
||||
let p = a.assemble_program();
|
||||
|
||||
// this should stall the state machine
|
||||
sm_a.sm_exec(p.code[p.origin.unwrap_or(0) as usize]);
|
||||
|
|
@ -1243,9 +1261,9 @@ pub fn restart_imm_test() {
|
|||
|
||||
pub fn fifo_join_test() -> bool {
|
||||
report_api(0xF1F0_0000);
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
let io_mask = 0x3FFF_FFFF;
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
let io_mask = 0xFFFF_FFFF;
|
||||
|
||||
let mut pio_ss = PioSharedState::new();
|
||||
|
|
@ -1254,6 +1272,7 @@ pub fn fifo_join_test() -> bool {
|
|||
|
||||
// test TX fifo with non-join. Simple program that just copies the TX fifo content to pins, then stalls.
|
||||
let mut sm_a = pio_ss.alloc_sm().unwrap();
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"out pins, 32",
|
||||
);
|
||||
|
|
@ -1263,9 +1282,9 @@ pub fn fifo_join_test() -> bool {
|
|||
pio_ss.pio.wo(rp_pio::SFR_IRQ1_INTE, 0);
|
||||
a_prog.setup_default_config(&mut sm_a);
|
||||
sm_a.config_set_out_pins(0, 32);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
sm_a.config_set_clkdiv(192.0); // slow down the machine so we can read out the values after writing them...
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
sm_a.config_set_clkdiv(32768.0);
|
||||
sm_a.config_set_out_shift(false, true, 0);
|
||||
sm_a.sm_init(a_prog.entry());
|
||||
|
|
@ -1273,7 +1292,8 @@ pub fn fifo_join_test() -> bool {
|
|||
|
||||
report_api(0xF1F0_1111);
|
||||
// load up the TX fifo, count how many entries it takes until it is full
|
||||
// note: full test requires manual inspection of waveform to confirm GPIO out has the expected report value.
|
||||
// note: full test requires manual inspection of waveform to confirm GPIO out has the expected report
|
||||
// value.
|
||||
let mut entries = 0;
|
||||
while !sm_a.sm_txfifo_is_full() {
|
||||
entries += 1;
|
||||
|
|
@ -1332,7 +1352,7 @@ pub fn fifo_join_test() -> bool {
|
|||
sm_a.sm_init(a_prog.entry());
|
||||
|
||||
// ----------- now test with "margin" on the FIFOs. ----------
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
{
|
||||
assert!(sm_a.sm_get_tx_fifo_margin() == 0);
|
||||
sm_a.sm_set_tx_fifo_margin(1);
|
||||
|
|
@ -1341,7 +1361,8 @@ pub fn fifo_join_test() -> bool {
|
|||
|
||||
// repeat, this time measuring the depth of the FIFO with margin
|
||||
let mut entries = 0;
|
||||
// loop looks at the raw interrupt value, the asserts look at the feedback INTS value, so we have coverage of both views
|
||||
// loop looks at the raw interrupt value, the asserts look at the feedback INTS value, so we have
|
||||
// coverage of both views
|
||||
while (pio_ss.pio.rf(rp_pio::SFR_INTR_INTR_TXNFULL) & sm_a.sm_bitmask()) != 0 {
|
||||
entries += 1;
|
||||
sm_a.sm_txfifo_push_u32(0xF1F0_0000 + entries);
|
||||
|
|
@ -1373,7 +1394,7 @@ pub fn fifo_join_test() -> bool {
|
|||
last_val = latest_val;
|
||||
}
|
||||
}
|
||||
report_api(0xF1F0_2100 + if passing {1} else {0});
|
||||
report_api(0xF1F0_2100 + if passing { 1 } else { 0 });
|
||||
sm_a.sm_set_tx_fifo_margin(0);
|
||||
|
||||
// this should reset join TX and also halt the engine
|
||||
|
|
@ -1388,7 +1409,8 @@ pub fn fifo_join_test() -> bool {
|
|||
|
||||
// repeat, this time measuring the depth of the FIFO with margin
|
||||
let mut entries = 0;
|
||||
// loop looks at the raw interrupt value, the asserts look at the feedback INTS value, so we have coverage of both views
|
||||
// loop looks at the raw interrupt value, the asserts look at the feedback INTS value, so we have
|
||||
// coverage of both views
|
||||
while (sm_a.pio.rf(rp_pio::SFR_INTR_INTR_TXNFULL) & sm_a.sm_bitmask()) != 0 {
|
||||
entries += 1;
|
||||
sm_a.sm_txfifo_push_u32(0xF1F0_0000 + entries);
|
||||
|
|
@ -1424,11 +1446,12 @@ pub fn fifo_join_test() -> bool {
|
|||
}
|
||||
}
|
||||
sm_a.sm_irq0_source_enabled(PioIntSource::TxNotFull, false);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
sm_a.sm_set_tx_fifo_margin(0);
|
||||
sm_a.sm_irq0_source_enabled(PioIntSource::RxNotEmpty, true);
|
||||
|
||||
// a program for testing IN
|
||||
#[rustfmt::skip]
|
||||
let b_code = pio_proc::pio_asm!(
|
||||
" set x, 16",
|
||||
"loop: ",
|
||||
|
|
@ -1460,9 +1483,7 @@ pub fn fifo_join_test() -> bool {
|
|||
if val != expected {
|
||||
passing = false;
|
||||
}
|
||||
report_api(
|
||||
0xF1F0_0000 + val
|
||||
);
|
||||
report_api(0xF1F0_0000 + val);
|
||||
entries += 1;
|
||||
expected -= 1;
|
||||
}
|
||||
|
|
@ -1487,9 +1508,7 @@ pub fn fifo_join_test() -> bool {
|
|||
if val != (expected & io_mask) {
|
||||
passing = false;
|
||||
}
|
||||
report_api(
|
||||
0xF1F0_0000 + val
|
||||
);
|
||||
report_api(0xF1F0_0000 + val);
|
||||
entries += 1;
|
||||
expected -= 1;
|
||||
}
|
||||
|
|
@ -1497,7 +1516,7 @@ pub fn fifo_join_test() -> bool {
|
|||
report_api(0xF1F0_4000 + entries);
|
||||
|
||||
// no join, but with margin
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
{
|
||||
sm_a.config_set_fifo_join(PioFifoJoin::None);
|
||||
sm_a.sm_init(b_prog.entry());
|
||||
|
|
@ -1519,14 +1538,12 @@ pub fn fifo_join_test() -> bool {
|
|||
sm_a.pio.wfo(rp_pio::SFR_CTRL_EN, 0);
|
||||
entries = 0;
|
||||
expected = 16;
|
||||
while (pio_ss.pio.rf(rp_pio::SFR_INTR_INTR_RXNEMPTY) & sm_a.sm_bitmask()) != 0 {
|
||||
while (pio_ss.pio.rf(rp_pio::SFR_INTR_INTR_RXNEMPTY) & sm_a.sm_bitmask()) != 0 {
|
||||
let val = sm_a.sm_rxfifo_pull_u32();
|
||||
if val != (expected & io_mask) {
|
||||
passing = false;
|
||||
}
|
||||
report_api(
|
||||
0xF1F0_0000 + val
|
||||
);
|
||||
report_api(0xF1F0_0000 + val);
|
||||
entries += 1;
|
||||
expected -= 1;
|
||||
}
|
||||
|
|
@ -1558,14 +1575,12 @@ pub fn fifo_join_test() -> bool {
|
|||
sm_a.pio.wfo(rp_pio::SFR_CTRL_EN, 0);
|
||||
entries = 0;
|
||||
expected = 16;
|
||||
while (pio_ss.pio.rf(rp_pio::SFR_INTR_INTR_RXNEMPTY) & sm_a.sm_bitmask()) != 0 {
|
||||
while (pio_ss.pio.rf(rp_pio::SFR_INTR_INTR_RXNEMPTY) & sm_a.sm_bitmask()) != 0 {
|
||||
let val = sm_a.sm_rxfifo_pull_u32();
|
||||
if val != (expected & io_mask) {
|
||||
passing = false;
|
||||
}
|
||||
report_api(
|
||||
0xF1F0_0000 + val
|
||||
);
|
||||
report_api(0xF1F0_0000 + val);
|
||||
entries += 1;
|
||||
expected -= 1;
|
||||
}
|
||||
|
|
@ -1579,7 +1594,7 @@ pub fn fifo_join_test() -> bool {
|
|||
|
||||
// clean up
|
||||
sm_a.sm_irq0_source_enabled(PioIntSource::RxNotEmpty, false);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
sm_a.sm_set_rx_fifo_margin(0);
|
||||
pio_ss.clear_instruction_memory();
|
||||
|
||||
|
|
@ -1621,7 +1636,6 @@ pub fn fifo_join_test() -> bool {
|
|||
/// 18..20 SM1 sideset via pindirs
|
||||
/// 20..22 SM2 sideset
|
||||
/// 31 synchronizing GPIO input
|
||||
///
|
||||
|
||||
pub fn register_tests() {
|
||||
const REGTEST_DIV: f32 = 2.5;
|
||||
|
|
@ -1636,6 +1650,7 @@ pub fn register_tests() {
|
|||
sm_a.pio.wo(rp_pio::SFR_FDEBUG, 0xFFFF_FFFF); // clear all the FIFO debug registers
|
||||
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
".side_set 2 opt",
|
||||
" set x, 24", // 18
|
||||
|
|
@ -1649,6 +1664,7 @@ pub fn register_tests() {
|
|||
" jmp x--, loop", // 1F
|
||||
);
|
||||
#[cfg(feature="rp2040")]
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
".side_set 2 opt",
|
||||
" set x, 24", // 18
|
||||
|
|
@ -1670,12 +1686,12 @@ pub fn register_tests() {
|
|||
sm_a.config_set_out_shift(false, true, 0);
|
||||
sm_a.config_set_sideset_pins(16);
|
||||
sm_a.config_set_clkdiv(REGTEST_DIV);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
sm_a.config_set_set_pins(31, 1); // special case, A is used to set GPIO 31 to resume machines on wait
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
sm_a.config_set_set_pins(28, 1); // special case, A is used to set GPIO 31 to resume machines on wait
|
||||
sm_a.sm_init(a_prog.entry());
|
||||
|
||||
#[rustfmt::skip]
|
||||
let b_code = pio_proc::pio_asm!(
|
||||
".side_set 2 opt pindirs",
|
||||
" set y, 16 [1]", // 10 start with some variable delay to prove syncing works
|
||||
|
|
@ -1693,9 +1709,9 @@ pub fn register_tests() {
|
|||
sm_b.sm_set_enabled(false);
|
||||
b_prog.setup_default_config(&mut sm_b);
|
||||
sm_b.config_set_out_pins(4, 4);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
sm_b.config_set_in_pins(31); // maps pin 0 to GPIO 31
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
sm_b.config_set_in_pins(28); // maps pin 0 to GPIO 28
|
||||
sm_b.config_set_out_shift(false, true, 0);
|
||||
sm_b.config_set_sideset_pins(18);
|
||||
|
|
@ -1703,6 +1719,7 @@ pub fn register_tests() {
|
|||
sm_b.sm_init(b_prog.entry());
|
||||
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[rustfmt::skip]
|
||||
let c_code = pio_proc::pio_asm!(
|
||||
".side_set 2 opt",
|
||||
" set x, 8 [2]",
|
||||
|
|
@ -1716,6 +1733,7 @@ pub fn register_tests() {
|
|||
" jmp x--, loop",
|
||||
);
|
||||
#[cfg(feature="rp2040")]
|
||||
#[rustfmt::skip]
|
||||
let c_code = pio_proc::pio_asm!(
|
||||
".side_set 2 opt",
|
||||
" set x, 8 [2]",
|
||||
|
|
@ -1728,7 +1746,7 @@ pub fn register_tests() {
|
|||
" wait 0 gpio 28 side 1", // wait until GPIO 28 is 0
|
||||
" jmp x--, loop",
|
||||
);
|
||||
let mut sm_c = pio_ss.alloc_sm().unwrap();
|
||||
let mut sm_c = pio_ss.alloc_sm().unwrap();
|
||||
let c_prog = LoadedProg::load(c_code.program, &mut pio_ss).unwrap();
|
||||
sm_c.sm_set_enabled(false);
|
||||
c_prog.setup_default_config(&mut sm_c);
|
||||
|
|
@ -1738,7 +1756,7 @@ pub fn register_tests() {
|
|||
sm_c.config_set_sideset_pins(20);
|
||||
sm_c.config_set_clkdiv(REGTEST_DIV);
|
||||
sm_c.sm_init(c_prog.entry());
|
||||
|
||||
#[rustfmt::skip]
|
||||
let d_code = pio_proc::pio_asm!(
|
||||
".side_set 2 opt",
|
||||
" set y, 2 [3]",
|
||||
|
|
@ -1751,14 +1769,14 @@ pub fn register_tests() {
|
|||
" wait 0 pin 7 side 0", // wait until the mapped input pin is 0. Map this to GPIO 31.
|
||||
" jmp y--, loop",
|
||||
);
|
||||
let mut sm_d = pio_ss.alloc_sm().unwrap();
|
||||
let mut sm_d = pio_ss.alloc_sm().unwrap();
|
||||
let d_prog = LoadedProg::load(d_code.program, &mut pio_ss).unwrap();
|
||||
sm_d.sm_set_enabled(false);
|
||||
d_prog.setup_default_config(&mut sm_d);
|
||||
sm_d.config_set_out_pins(12, 4);
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
sm_d.config_set_in_pins(24); // maps pin 7 to GPIO 31
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
sm_d.config_set_in_pins(21); // maps pin 7 to GPIO 28
|
||||
sm_d.config_set_out_shift(false, true, 0);
|
||||
sm_d.config_set_sideset_pins(14); // deliberate conflict with out_pins
|
||||
|
|
@ -1778,57 +1796,23 @@ pub fn register_tests() {
|
|||
|
||||
// dump the loaded instructions. Tests all the INSTR registers for readback.
|
||||
// must be re-generated every time programs are updated
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
let expected_instrs: [u16; 32] = [
|
||||
0xe342,
|
||||
0x5e40,
|
||||
0x8020,
|
||||
0xd801,
|
||||
0x7400,
|
||||
0x30a7,
|
||||
0x3027,
|
||||
0x0081,
|
||||
0xe228,
|
||||
0x5d20,
|
||||
0x8220,
|
||||
0x38c1,
|
||||
0x7400,
|
||||
0x309f,
|
||||
0x341f,
|
||||
0x0049,
|
||||
0xe150,
|
||||
0x5d40,
|
||||
0x8120,
|
||||
0x38c1,
|
||||
0x7400,
|
||||
0x30a0,
|
||||
0x3420,
|
||||
0x0091,
|
||||
0xe038,
|
||||
0x5e20,
|
||||
0x8120,
|
||||
0x38c1,
|
||||
0x7400,
|
||||
0x309f,
|
||||
0x341f,
|
||||
0x0059,
|
||||
0xe342, 0x5e40, 0x8020, 0xd801, 0x7400, 0x30a7, 0x3027, 0x0081, 0xe228, 0x5d20, 0x8220, 0x38c1,
|
||||
0x7400, 0x309f, 0x341f, 0x0049, 0xe150, 0x5d40, 0x8120, 0x38c1, 0x7400, 0x30a0, 0x3420, 0x0091,
|
||||
0xe038, 0x5e20, 0x8120, 0x38c1, 0x7400, 0x309f, 0x341f, 0x0059,
|
||||
];
|
||||
for i in 0..RP2040_MAX_PROGRAM_SIZE {
|
||||
let rbk = unsafe{sm_a.pio.base().add(rp_pio::SFR_INSTR_MEM0.offset() + i).read_volatile()};
|
||||
let rbk = unsafe { sm_a.pio.base().add(rp_pio::SFR_INSTR_MEM0.offset() + i).read_volatile() };
|
||||
report_api(rbk + ((i as u32) << 24));
|
||||
#[cfg(not(feature="rp2040"))]
|
||||
#[cfg(not(feature = "rp2040"))]
|
||||
assert!(rbk as u16 == expected_instrs[i]); // on RP2040 you can't read back the instructions
|
||||
}
|
||||
report_api(0x1336_0002);
|
||||
|
||||
// load the TX fifos with output data we expect to see on the GPIO pins
|
||||
let tx_vals: [[u32; 4]; 4] =
|
||||
[
|
||||
[0x3, 0xC, 0x6, 0x0],
|
||||
[0xA, 0x5, 0x0, 0xF],
|
||||
[0xC, 0x0, 0x1, 0x2],
|
||||
[0x3, 0x2, 0x1, 0x0],
|
||||
];
|
||||
[[0x3, 0xC, 0x6, 0x0], [0xA, 0x5, 0x0, 0xF], [0xC, 0x0, 0x1, 0x2], [0x3, 0x2, 0x1, 0x0]];
|
||||
// load the FIFO values, and check that the levels & flags change as we expected.
|
||||
let mut sm_array = [sm_a, sm_b, sm_c, sm_d];
|
||||
for (sm_index, sm) in sm_array.iter_mut().enumerate() {
|
||||
|
|
@ -1872,10 +1856,11 @@ pub fn register_tests() {
|
|||
let clear_bit31_oe = pio_proc::pio_asm!("set pindirs, 0").program.code[0];
|
||||
// prepare an instruction that stalls
|
||||
let p_wait = pio_proc::pio_asm!("wait 1 irq 0").program.code[0];
|
||||
// prepare an instruction that can set & clear the *pin*, not just the pindir. For RP2040 HW test, because we can't hack the OE to IN as a loopback like we can in a verilog model.
|
||||
#[cfg(feature="rp2040")]
|
||||
// prepare an instruction that can set & clear the *pin*, not just the pindir. For RP2040 HW test, because
|
||||
// we can't hack the OE to IN as a loopback like we can in a verilog model.
|
||||
#[cfg(feature = "rp2040")]
|
||||
let pinset = pio_proc::pio_asm!("set pins, 1").program.code[0];
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
let pinclear = pio_proc::pio_asm!("set pins, 0").program.code[0];
|
||||
|
||||
// check that the RX FIFOs have the correct levels
|
||||
|
|
@ -1889,7 +1874,7 @@ pub fn register_tests() {
|
|||
sm_array[0].pio.wo(
|
||||
rp_pio::SFR_CTRL,
|
||||
sm_array[0].pio.ms(rp_pio::SFR_CTRL_CLKDIV_RESTART, 0xF)
|
||||
| sm_array[0].pio.ms(rp_pio::SFR_CTRL_EN, 0xF)
|
||||
| sm_array[0].pio.ms(rp_pio::SFR_CTRL_EN, 0xF),
|
||||
); // sync the clocks; the clock free-runs after the div is setup, and the divs are set up at arbitrary points in time
|
||||
while (sm_array[0].pio.r(rp_pio::SFR_CTRL) & !0xF) != 0 {
|
||||
// wait for the bits to self-reset to acknowledge that the command has executed
|
||||
|
|
@ -1909,9 +1894,10 @@ pub fn register_tests() {
|
|||
for (index, vals) in tx_vals.iter().enumerate() {
|
||||
expected |= (vals[waiting_for] & 0xF) << (index as u32 * 4);
|
||||
}
|
||||
// compensate for sideset override on SM3 (doesn't apply, because the sideset is out of phase with out)
|
||||
// expected &= 0x3FFF;
|
||||
// expected |= 0x4000; // "side 1" should be executed on SM3 on bits 14-16, overriding any TX fifo value
|
||||
// compensate for sideset override on SM3 (doesn't apply, because the sideset is out of phase with
|
||||
// out) expected &= 0x3FFF;
|
||||
// expected |= 0x4000; // "side 1" should be executed on SM3 on bits 14-16, overriding any TX fifo
|
||||
// value
|
||||
|
||||
let outputs = sm_array[0].pio.r(rp_pio::SFR_DBG_PADOUT);
|
||||
report_api(0x1336_0000 | (outputs & 0xFFFF));
|
||||
|
|
@ -1938,16 +1924,24 @@ pub fn register_tests() {
|
|||
|
||||
// read the address of the PC, and confirm the instruction is correct
|
||||
report_api(0x1336_0008);
|
||||
#[cfg(not(feature="rp2040"))] // can't read instructions on actual rp2040
|
||||
#[cfg(not(feature = "rp2040"))] // can't read instructions on actual rp2040
|
||||
{
|
||||
assert!(expected_instrs[sm_array[0].pio.rf(rp_pio::SFR_SM0_ADDR_PC) as usize] ==
|
||||
sm_array[0].pio.rf(rp_pio::SFR_SM0_INSTR_IMM_INSTR) as u16);
|
||||
assert!(expected_instrs[sm_array[1].pio.rf(rp_pio::SFR_SM1_ADDR_PC) as usize] ==
|
||||
sm_array[1].pio.rf(rp_pio::SFR_SM1_INSTR_IMM_INSTR) as u16);
|
||||
assert!(expected_instrs[sm_array[2].pio.rf(rp_pio::SFR_SM2_ADDR_PC) as usize] ==
|
||||
sm_array[2].pio.rf(rp_pio::SFR_SM2_INSTR_IMM_INSTR) as u16);
|
||||
assert!(expected_instrs[sm_array[3].pio.rf(rp_pio::SFR_SM3_ADDR_PC) as usize] ==
|
||||
sm_array[3].pio.rf(rp_pio::SFR_SM3_INSTR_IMM_INSTR) as u16);
|
||||
assert!(
|
||||
expected_instrs[sm_array[0].pio.rf(rp_pio::SFR_SM0_ADDR_PC) as usize]
|
||||
== sm_array[0].pio.rf(rp_pio::SFR_SM0_INSTR_IMM_INSTR) as u16
|
||||
);
|
||||
assert!(
|
||||
expected_instrs[sm_array[1].pio.rf(rp_pio::SFR_SM1_ADDR_PC) as usize]
|
||||
== sm_array[1].pio.rf(rp_pio::SFR_SM1_INSTR_IMM_INSTR) as u16
|
||||
);
|
||||
assert!(
|
||||
expected_instrs[sm_array[2].pio.rf(rp_pio::SFR_SM2_ADDR_PC) as usize]
|
||||
== sm_array[2].pio.rf(rp_pio::SFR_SM2_INSTR_IMM_INSTR) as u16
|
||||
);
|
||||
assert!(
|
||||
expected_instrs[sm_array[3].pio.rf(rp_pio::SFR_SM3_ADDR_PC) as usize]
|
||||
== sm_array[3].pio.rf(rp_pio::SFR_SM3_INSTR_IMM_INSTR) as u16
|
||||
);
|
||||
}
|
||||
|
||||
// execute the "program" that flips the OE bit, which should get us to the next iteration
|
||||
|
|
@ -1958,12 +1952,13 @@ pub fn register_tests() {
|
|||
report_api(0x1336_000A);
|
||||
assert!(sm_array[0].pio.rf(rp_pio::SFR_SM0_EXECCTRL_EXEC_STALLED_RO0) == 1);
|
||||
|
||||
// now exec the instruction that should clear the wait condition on an input pin by flipping bit 31 via a side-set operation
|
||||
// this requires the testbench to reflect that bit back correctly!
|
||||
#[cfg(feature="rp2040")]
|
||||
// now exec the instruction that should clear the wait condition on an input pin by flipping bit
|
||||
// 31 via a side-set operation this requires the testbench to reflect that bit back
|
||||
// correctly!
|
||||
#[cfg(feature = "rp2040")]
|
||||
sm_array[0].sm_exec(pinset);
|
||||
sm_array[0].sm_exec(set_bit31_oe);
|
||||
#[cfg(feature="rp2040")]
|
||||
#[cfg(feature = "rp2040")]
|
||||
sm_array[0].sm_exec(pinclear);
|
||||
sm_array[0].sm_exec(clear_bit31_oe);
|
||||
delay(4); // give some time for the state machines to run to the stall point (necessary for fast pclk case)
|
||||
|
|
@ -1977,10 +1972,9 @@ pub fn register_tests() {
|
|||
report_api(0x1336_000C);
|
||||
sm_array[0].pio.wfo(rp_pio::SFR_CTRL_EN, 0);
|
||||
|
||||
// since the program ran one extra iteration out the bottom of the loop, we should have overflowed the RX fifo, etc.
|
||||
report_api(
|
||||
sm_array[0].pio.r(rp_pio::SFR_FDEBUG)
|
||||
);
|
||||
// since the program ran one extra iteration out the bottom of the loop, we should have overflowed the RX
|
||||
// fifo, etc.
|
||||
report_api(sm_array[0].pio.r(rp_pio::SFR_FDEBUG));
|
||||
assert!(sm_array[0].pio.r(rp_pio::SFR_FDEBUG) == 0xF); // stalls should be asserted
|
||||
sm_array[0].pio.wfo(rp_pio::SFR_FDEBUG_RXSTALL, 0xF); // clear the stall
|
||||
assert!(sm_array[0].pio.r(rp_pio::SFR_FDEBUG) == 0); // confirm it is cleared
|
||||
|
|
@ -2041,4 +2035,4 @@ pub fn register_tests() {
|
|||
}
|
||||
|
||||
report_api(0x1336_600d);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
use crate::*;
|
||||
use super::report_api;
|
||||
use utralib::*;
|
||||
|
||||
use super::report_api;
|
||||
use crate::*;
|
||||
|
||||
/// used to generate some test vectors
|
||||
pub fn lfsr_next(state: u32) -> u32 {
|
||||
let bit = ((state >> 31) ^
|
||||
(state >> 21) ^
|
||||
(state >> 1) ^
|
||||
(state >> 0)) & 1;
|
||||
let bit = ((state >> 31) ^ (state >> 21) ^ (state >> 1) ^ (state >> 0)) & 1;
|
||||
|
||||
(state << 1) + bit
|
||||
}
|
||||
|
||||
pub fn basic_tests (pl230: &mut Pl230) -> bool {
|
||||
pub fn basic_tests(pl230: &mut Pl230) -> bool {
|
||||
report_api("channels", pl230.csr.rf(utra::pl230::STATUS_CHNLS_MINUS1) + 1);
|
||||
//report_api("id0", pl230.csr.r(utra::pl230::PERIPH_ID_0));
|
||||
//report_api("id1", pl230.csr.r(utra::pl230::PERIPH_ID_1));
|
||||
|
|
@ -21,13 +19,12 @@ pub fn basic_tests (pl230: &mut Pl230) -> bool {
|
|||
// conjure the DMA control structure in IFRAM0. In order to guarantee Rust
|
||||
// semantics, it must be initialized to 0: 4 word-sized entries * 8 channels * 2 banks = 4 * 8 * 2
|
||||
let init_ptr = utralib::HW_IFRAM0_MEM as *mut u32;
|
||||
for i in 0..(4*8*2) {
|
||||
unsafe {init_ptr.add(i).write_volatile(0)};
|
||||
for i in 0..(4 * 8 * 2) {
|
||||
unsafe { init_ptr.add(i).write_volatile(0) };
|
||||
}
|
||||
// safety: we guarantee that the pointer is aligned and initialized
|
||||
let cc_struct: &mut ControlChannels = unsafe {
|
||||
(utralib::HW_IFRAM0_MEM as *mut ControlChannels).as_mut().unwrap()
|
||||
};
|
||||
let cc_struct: &mut ControlChannels =
|
||||
unsafe { (utralib::HW_IFRAM0_MEM as *mut ControlChannels).as_mut().unwrap() };
|
||||
|
||||
// read the status register
|
||||
// report_api("status", pl230.csr.r(utra::pl230::STATUS));
|
||||
|
|
@ -37,23 +34,24 @@ pub fn basic_tests (pl230: &mut Pl230) -> bool {
|
|||
const DMA_LEN: usize = 16;
|
||||
// setup the PL230 to do a simple transfer between two memory regions
|
||||
// dma_mainram feature will cause us to DMA between main memory regions. This works under RTL sims.
|
||||
#[cfg(feature="dma_mainram")]
|
||||
#[cfg(feature = "dma_mainram")]
|
||||
let mut region_a = [0u32; DMA_LEN];
|
||||
#[cfg(feature="dma_mainram")]
|
||||
#[cfg(feature = "dma_mainram")]
|
||||
let region_b = [0u32; DMA_LEN];
|
||||
// The alternate is to DMA between IFRAM regions. This works under FPGA and RTL sim.
|
||||
#[cfg(not(feature="dma_mainram"))]
|
||||
let region_a = unsafe{core::slice::from_raw_parts_mut((utralib::HW_IFRAM0_MEM + 4096) as *mut u32, DMA_LEN)};
|
||||
#[cfg(not(feature="dma_mainram"))]
|
||||
let region_b = unsafe{core::slice::from_raw_parts_mut(utralib::HW_IFRAM1_MEM as *mut u32, DMA_LEN)};
|
||||
#[cfg(not(feature = "dma_mainram"))]
|
||||
let region_a =
|
||||
unsafe { core::slice::from_raw_parts_mut((utralib::HW_IFRAM0_MEM + 4096) as *mut u32, DMA_LEN) };
|
||||
#[cfg(not(feature = "dma_mainram"))]
|
||||
let region_b = unsafe { core::slice::from_raw_parts_mut(utralib::HW_IFRAM1_MEM as *mut u32, DMA_LEN) };
|
||||
let mut state = 0x1111_1111;
|
||||
for d in region_a.iter_mut() {
|
||||
*d = state;
|
||||
state = lfsr_next(state);
|
||||
}
|
||||
|
||||
cc_struct.channels[0].dst_end_ptr = unsafe{region_b.as_ptr().add(region_b.len() - 1)} as u32;
|
||||
cc_struct.channels[0].src_end_ptr = unsafe{region_a.as_ptr().add(region_a.len() - 1)} as u32;
|
||||
cc_struct.channels[0].dst_end_ptr = unsafe { region_b.as_ptr().add(region_b.len() - 1) } as u32;
|
||||
cc_struct.channels[0].src_end_ptr = unsafe { region_a.as_ptr().add(region_a.len() - 1) } as u32;
|
||||
let mut cc = DmaChanControl(0);
|
||||
cc.set_src_size(DmaWidth::Word as u32);
|
||||
cc.set_src_inc(DmaWidth::Word as u32);
|
||||
|
|
@ -84,10 +82,10 @@ pub fn basic_tests (pl230: &mut Pl230) -> bool {
|
|||
let mut timeout = 0;
|
||||
while (DmaChanControl(cc_struct.channels[0].control).cycle_ctrl() != 0) && timeout < 16 {
|
||||
// report_api("dma progress ", cc_struct.channels[0].control);
|
||||
report_api("progress as baseptr[2]", unsafe{cc_struct.channels.as_ptr().read()}.control);
|
||||
report_api("progress as baseptr[2]", unsafe { cc_struct.channels.as_ptr().read() }.control);
|
||||
timeout += 1;
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
unsafe {core::arch::asm!(
|
||||
".word 0x500F",
|
||||
"nop",
|
||||
|
|
@ -125,16 +123,16 @@ pub fn basic_tests (pl230: &mut Pl230) -> bool {
|
|||
passing
|
||||
}
|
||||
|
||||
#[cfg(feature="pio")]
|
||||
#[cfg(feature = "pio")]
|
||||
pub fn pio_test(pl230: &mut Pl230) -> bool {
|
||||
use xous_pio::*;
|
||||
|
||||
let iox_csr = utra::iox::HW_IOX_BASE as *mut u32;
|
||||
unsafe {
|
||||
iox_csr.add(0x8 / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PBL
|
||||
iox_csr.add(0xC / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PBH
|
||||
iox_csr.add(0x10 / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PCL
|
||||
iox_csr.add(0x14 / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PCH
|
||||
iox_csr.add(0x8 / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PBL
|
||||
iox_csr.add(0xC / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PBH
|
||||
iox_csr.add(0x10 / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PCL
|
||||
iox_csr.add(0x14 / core::mem::size_of::<u32>()).write_volatile(0b0101_0101_0101_0101); // PCH
|
||||
iox_csr.add(0x200 / core::mem::size_of::<u32>()).write_volatile(0xffffffff); // PIO sel port D31-0
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +142,7 @@ pub fn pio_test(pl230: &mut Pl230) -> bool {
|
|||
let mut sm_a = pio_ss.alloc_sm().unwrap();
|
||||
pio_ss.clear_instruction_memory();
|
||||
sm_a.sm_set_enabled(false);
|
||||
|
||||
#[rustfmt::skip]
|
||||
let a_code = pio_proc::pio_asm!(
|
||||
"out pins, 0", // 0 is 32
|
||||
);
|
||||
|
|
@ -152,10 +150,7 @@ pub fn pio_test(pl230: &mut Pl230) -> bool {
|
|||
sm_a.sm_set_enabled(false);
|
||||
a_prog.setup_default_config(&mut sm_a);
|
||||
sm_a.config_set_out_pins(0, 32);
|
||||
sm_a.sm_set_pindirs_with_mask(
|
||||
0xFFFF_FFFF,
|
||||
0xFFFF_FFFF
|
||||
);
|
||||
sm_a.sm_set_pindirs_with_mask(0xFFFF_FFFF, 0xFFFF_FFFF);
|
||||
sm_a.config_set_clkdiv(133.0); // have it run slow so this test operates in the background
|
||||
sm_a.config_set_out_shift(false, true, 32);
|
||||
sm_a.sm_set_pindirs_with_mask(0x10, 0x10);
|
||||
|
|
@ -181,13 +176,12 @@ pub fn pio_test(pl230: &mut Pl230) -> bool {
|
|||
|
||||
// setup control structure
|
||||
let init_ptr = utralib::HW_IFRAM0_MEM as *mut u32;
|
||||
for i in 0..(4*8*2) {
|
||||
unsafe {init_ptr.add(i).write_volatile(0)};
|
||||
for i in 0..(4 * 8 * 2) {
|
||||
unsafe { init_ptr.add(i).write_volatile(0) };
|
||||
}
|
||||
// safety: we guarantee that the pointer is aligned and initialized
|
||||
let cc_struct: &mut ControlChannels = unsafe {
|
||||
(utralib::HW_IFRAM0_MEM as *mut ControlChannels).as_mut().unwrap()
|
||||
};
|
||||
let cc_struct: &mut ControlChannels =
|
||||
unsafe { (utralib::HW_IFRAM0_MEM as *mut ControlChannels).as_mut().unwrap() };
|
||||
pl230.csr.wfo(utra::pl230::CFG_MASTER_ENABLE, 1); // enable
|
||||
|
||||
const DMA_LEN: usize = 1024;
|
||||
|
|
@ -200,7 +194,7 @@ pub fn pio_test(pl230: &mut Pl230) -> bool {
|
|||
|
||||
cc_struct.channels[0].dst_end_ptr =
|
||||
(utra::rp_pio::SFR_TXF0.offset() * core::mem::size_of::<u32>() + utra::rp_pio::HW_RP_PIO_BASE) as u32;
|
||||
cc_struct.channels[0].src_end_ptr = unsafe{region_a.as_ptr().add(region_a.len() - 1)} as u32;
|
||||
cc_struct.channels[0].src_end_ptr = unsafe { region_a.as_ptr().add(region_a.len() - 1) } as u32;
|
||||
let mut cc = DmaChanControl(0);
|
||||
cc.set_src_size(DmaWidth::Word as u32);
|
||||
cc.set_src_inc(DmaWidth::Word as u32);
|
||||
|
|
@ -212,18 +206,19 @@ pub fn pio_test(pl230: &mut Pl230) -> bool {
|
|||
cc_struct.channels[0].control = cc.0;
|
||||
|
||||
pl230.csr.wo(utra::pl230::CTRLBASEPTR, cc_struct.channels.as_ptr() as u32);
|
||||
pl230.csr.wo(utra::pl230::CHNLREQMASKCLR, 1); // don't mask the hardware request line
|
||||
pl230.csr.wo(utra::pl230::CHNLREQMASKCLR, 1); // don't mask the hardware request line
|
||||
pl230.csr.wo(utra::pl230::CHNLUSEBURSTCLR, 1); // don't mask single request line
|
||||
pl230.csr.wo(utra::pl230::CHNLENABLESET, 1);
|
||||
report_api("pio baseptr", cc_struct.channels.as_ptr() as u32);
|
||||
report_api("pio src start", region_a.as_ptr() as u32);
|
||||
report_api("pio dst start", unsafe{cc_struct.channels.as_ptr().read()}.dst_end_ptr);
|
||||
report_api("pio dst start", unsafe { cc_struct.channels.as_ptr().read() }.dst_end_ptr);
|
||||
|
||||
// setup EVC to route requests
|
||||
report_api("mdma_base", unsafe{pl230.mdma.base()} as u32);
|
||||
report_api("mdma_base", unsafe { pl230.mdma.base() } as u32);
|
||||
// select event number 83, which is PIO[0].
|
||||
// TODO: make this not hard-coded
|
||||
// WTF: oddly enough, it actually maps to... channel 163??? weird. this probably indicates a bug of some sort.
|
||||
// WTF: oddly enough, it actually maps to... channel 163??? weird. this probably indicates a bug of some
|
||||
// sort.
|
||||
pl230.mdma.wo(utra::mdma::SFR_EVSEL_CR_EVSEL0, 163);
|
||||
// bit 0 - enable
|
||||
// bit 1 - mode: 1 is edge, 0 is level
|
||||
|
|
@ -257,4 +252,4 @@ pub fn pio_test(pl230: &mut Pl230) -> bool {
|
|||
} else {
|
||||
true
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue