mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-23 20:51:31 +11:00
simplify jump offset calculation when loading PIO programs
This commit is contained in:
parent
ae629ad4c9
commit
7cca9a71d7
|
@ -195,26 +195,17 @@ impl<P: PIOExt> PIO<P> {
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|instr| {
|
.map(|instr| {
|
||||||
if let Some(Instruction {
|
if instr & 0b1110_0000_0000_0000 == 0 {
|
||||||
operands: InstructionOperands::JMP { condition, address },
|
// this is a JMP instruction -> add offset to address
|
||||||
delay,
|
let address = (instr & 0b11111) as usize;
|
||||||
side_set,
|
let address = address + offset;
|
||||||
}) = Instruction::decode(instr, p.side_set)
|
|
||||||
{
|
|
||||||
// JMP instruction. We need to apply offset here
|
|
||||||
let address = address + offset as u8;
|
|
||||||
assert!(
|
assert!(
|
||||||
address < pio::RP2040_MAX_PROGRAM_SIZE as u8,
|
address < pio::RP2040_MAX_PROGRAM_SIZE,
|
||||||
"Invalid JMP out of the program after offset addition"
|
"Invalid JMP out of the program after offset addition"
|
||||||
);
|
);
|
||||||
|
instr & (!0b11111) | address as u16
|
||||||
Instruction {
|
|
||||||
operands: InstructionOperands::JMP { condition, address },
|
|
||||||
delay,
|
|
||||||
side_set,
|
|
||||||
}
|
|
||||||
.encode(p.side_set)
|
|
||||||
} else {
|
} else {
|
||||||
|
// this is not a JMP instruction -> keep it unchanged
|
||||||
instr
|
instr
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue