rp/pio: allow wrap-around program loading
execution wraps around after the end of instruction memory and wrapping works with this, so we may as well allow program loading across this boundary. could be useful for reusing chunks of instruction memory.
This commit is contained in:
parent
374c7513f9
commit
b38d496d51
@ -855,13 +855,14 @@ impl<'d, PIO: Instance> Common<'d, PIO> {
|
|||||||
{
|
{
|
||||||
let mut used_mask = 0;
|
let mut used_mask = 0;
|
||||||
for (i, instr) in instrs.enumerate() {
|
for (i, instr) in instrs.enumerate() {
|
||||||
let addr = (i + start) as u8;
|
// wrapping around the end of program memory is valid, let's make use of that.
|
||||||
let mask = 1 << (addr as usize);
|
let addr = (i + start) % 32;
|
||||||
if self.instructions_used & mask != 0 {
|
let mask = 1 << addr;
|
||||||
return Err(addr as usize);
|
if (self.instructions_used | used_mask) & mask != 0 {
|
||||||
|
return Err(addr);
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
PIO::PIO.instr_mem(addr as usize).write(|w| {
|
PIO::PIO.instr_mem(addr).write(|w| {
|
||||||
w.set_instr_mem(instr);
|
w.set_instr_mem(instr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,7 @@ where
|
|||||||
Some(if instr & 0b1110_0000_0000_0000 == 0 {
|
Some(if instr & 0b1110_0000_0000_0000 == 0 {
|
||||||
// this is a JMP instruction -> add offset to address
|
// this is a JMP instruction -> add offset to address
|
||||||
let address = (instr & 0b1_1111) as u8;
|
let address = (instr & 0b1_1111) as u8;
|
||||||
let address = address + self.offset;
|
let address = address.wrapping_add(self.offset) % 32;
|
||||||
assert!(
|
|
||||||
address < pio::RP2040_MAX_PROGRAM_SIZE as u8,
|
|
||||||
"Invalid JMP out of the program after offset addition"
|
|
||||||
);
|
|
||||||
instr & (!0b11111) | address as u16
|
instr & (!0b11111) | address as u16
|
||||||
} else {
|
} else {
|
||||||
instr
|
instr
|
||||||
@ -62,8 +58,8 @@ impl<'a, const PROGRAM_SIZE: usize> RelocatedProgram<'a, PROGRAM_SIZE> {
|
|||||||
let wrap = self.program.wrap;
|
let wrap = self.program.wrap;
|
||||||
let origin = self.origin;
|
let origin = self.origin;
|
||||||
Wrap {
|
Wrap {
|
||||||
source: wrap.source + origin,
|
source: wrap.source.wrapping_add(origin) % 32,
|
||||||
target: wrap.target + origin,
|
target: wrap.target.wrapping_add(origin) % 32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ impl<'l> HD44780<'l> {
|
|||||||
let prg = pio_proc::pio_asm!(
|
let prg = pio_proc::pio_asm!(
|
||||||
r#"
|
r#"
|
||||||
.side_set 1 opt
|
.side_set 1 opt
|
||||||
|
.origin 20
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
out x, 24
|
out x, 24
|
||||||
@ -148,7 +149,7 @@ impl<'l> HD44780<'l> {
|
|||||||
// many side sets are only there to free up a delay bit!
|
// many side sets are only there to free up a delay bit!
|
||||||
let prg = pio_proc::pio_asm!(
|
let prg = pio_proc::pio_asm!(
|
||||||
r#"
|
r#"
|
||||||
.origin 7
|
.origin 27
|
||||||
.side_set 1
|
.side_set 1
|
||||||
|
|
||||||
.wrap_target
|
.wrap_target
|
||||||
|
Loading…
Reference in New Issue
Block a user