From 2873cb93ee3111d984c35287ea9d98f1218d1024 Mon Sep 17 00:00:00 2001 From: pennae Date: Fri, 5 May 2023 20:46:10 +0200 Subject: [PATCH] rp/pio: mark pio_instr_util unsafe none of these are safe. the x/y functions mangle the fifos, the set functions require the state machine to be stopped to be in any way safe, the out functions do both of those things at once. only the jump instruction is marginally safe, but running this on an active program is bound to cause problems. --- embassy-rp/src/pio_instr_util.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/embassy-rp/src/pio_instr_util.rs b/embassy-rp/src/pio_instr_util.rs index e425cf09..25393b47 100644 --- a/embassy-rp/src/pio_instr_util.rs +++ b/embassy-rp/src/pio_instr_util.rs @@ -2,7 +2,7 @@ use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestin use crate::pio::{Instance, StateMachine}; -pub fn set_x(sm: &mut StateMachine, value: u32) { +pub unsafe fn set_x(sm: &mut StateMachine, value: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::X, bit_count: 32, @@ -12,7 +12,7 @@ pub fn set_x(sm: &mut StateMachine, val sm.exec_instr(OUT); } -pub fn get_x(sm: &mut StateMachine) -> u32 { +pub unsafe fn get_x(sm: &mut StateMachine) -> u32 { const IN: u16 = InstructionOperands::IN { source: InSource::X, bit_count: 32, @@ -22,7 +22,7 @@ pub fn get_x(sm: &mut StateMachine) -> sm.rx().pull() } -pub fn set_y(sm: &mut StateMachine, value: u32) { +pub unsafe fn set_y(sm: &mut StateMachine, value: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::Y, bit_count: 32, @@ -32,7 +32,7 @@ pub fn set_y(sm: &mut StateMachine, val sm.exec_instr(OUT); } -pub fn get_y(sm: &mut StateMachine) -> u32 { +pub unsafe fn get_y(sm: &mut StateMachine) -> u32 { const IN: u16 = InstructionOperands::IN { source: InSource::Y, bit_count: 32, @@ -43,7 +43,7 @@ pub fn get_y(sm: &mut StateMachine) -> sm.rx().pull() } -pub fn set_pindir(sm: &mut StateMachine, data: u8) { +pub unsafe fn set_pindir(sm: &mut StateMachine, data: u8) { let set: u16 = InstructionOperands::SET { destination: SetDestination::PINDIRS, data, @@ -52,7 +52,7 @@ pub fn set_pindir(sm: &mut StateMachine sm.exec_instr(set); } -pub fn set_pin(sm: &mut StateMachine, data: u8) { +pub unsafe fn set_pin(sm: &mut StateMachine, data: u8) { let set: u16 = InstructionOperands::SET { destination: SetDestination::PINS, data, @@ -61,7 +61,7 @@ pub fn set_pin(sm: &mut StateMachine, d sm.exec_instr(set); } -pub fn set_out_pin(sm: &mut StateMachine, data: u32) { +pub unsafe fn set_out_pin(sm: &mut StateMachine, data: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::PINS, bit_count: 32, @@ -70,7 +70,7 @@ pub fn set_out_pin(sm: &mut StateMachine(sm: &mut StateMachine, data: u32) { +pub unsafe fn set_out_pindir(sm: &mut StateMachine, data: u32) { const OUT: u16 = InstructionOperands::OUT { destination: OutDestination::PINDIRS, bit_count: 32, @@ -80,7 +80,7 @@ pub fn set_out_pindir(sm: &mut StateMachine(sm: &mut StateMachine, to_addr: u8) { +pub unsafe fn exec_jmp(sm: &mut StateMachine, to_addr: u8) { let jmp: u16 = InstructionOperands::JMP { address: to_addr, condition: JmpCondition::Always,