aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpennae <[email protected]>2023-05-05 20:46:10 +0200
committerpennae <[email protected]>2023-05-06 11:52:25 +0200
commit2873cb93ee3111d984c35287ea9d98f1218d1024 (patch)
tree82d07ca4b31413de8f54cd163ab36e2c1d06adb6
parent37b460637df0a20885ba8a0fbb0699e2d44ee4ec (diff)
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.
-rw-r--r--embassy-rp/src/pio_instr_util.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/embassy-rp/src/pio_instr_util.rs b/embassy-rp/src/pio_instr_util.rs
index e425cf092..25393b476 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
2 2
3use crate::pio::{Instance, StateMachine}; 3use crate::pio::{Instance, StateMachine};
4 4
5pub fn set_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) { 5pub unsafe fn set_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) {
6 const OUT: u16 = InstructionOperands::OUT { 6 const OUT: u16 = InstructionOperands::OUT {
7 destination: OutDestination::X, 7 destination: OutDestination::X,
8 bit_count: 32, 8 bit_count: 32,
@@ -12,7 +12,7 @@ pub fn set_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, val
12 sm.exec_instr(OUT); 12 sm.exec_instr(OUT);
13} 13}
14 14
15pub fn get_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 { 15pub unsafe fn get_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 {
16 const IN: u16 = InstructionOperands::IN { 16 const IN: u16 = InstructionOperands::IN {
17 source: InSource::X, 17 source: InSource::X,
18 bit_count: 32, 18 bit_count: 32,
@@ -22,7 +22,7 @@ pub fn get_x<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) ->
22 sm.rx().pull() 22 sm.rx().pull()
23} 23}
24 24
25pub fn set_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) { 25pub unsafe fn set_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, value: u32) {
26 const OUT: u16 = InstructionOperands::OUT { 26 const OUT: u16 = InstructionOperands::OUT {
27 destination: OutDestination::Y, 27 destination: OutDestination::Y,
28 bit_count: 32, 28 bit_count: 32,
@@ -32,7 +32,7 @@ pub fn set_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, val
32 sm.exec_instr(OUT); 32 sm.exec_instr(OUT);
33} 33}
34 34
35pub fn get_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 { 35pub unsafe fn get_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) -> u32 {
36 const IN: u16 = InstructionOperands::IN { 36 const IN: u16 = InstructionOperands::IN {
37 source: InSource::Y, 37 source: InSource::Y,
38 bit_count: 32, 38 bit_count: 32,
@@ -43,7 +43,7 @@ pub fn get_y<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>) ->
43 sm.rx().pull() 43 sm.rx().pull()
44} 44}
45 45
46pub fn set_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) { 46pub unsafe fn set_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) {
47 let set: u16 = InstructionOperands::SET { 47 let set: u16 = InstructionOperands::SET {
48 destination: SetDestination::PINDIRS, 48 destination: SetDestination::PINDIRS,
49 data, 49 data,
@@ -52,7 +52,7 @@ pub fn set_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>
52 sm.exec_instr(set); 52 sm.exec_instr(set);
53} 53}
54 54
55pub fn set_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) { 55pub unsafe fn set_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u8) {
56 let set: u16 = InstructionOperands::SET { 56 let set: u16 = InstructionOperands::SET {
57 destination: SetDestination::PINS, 57 destination: SetDestination::PINS,
58 data, 58 data,
@@ -61,7 +61,7 @@ pub fn set_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, d
61 sm.exec_instr(set); 61 sm.exec_instr(set);
62} 62}
63 63
64pub fn set_out_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) { 64pub unsafe fn set_out_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) {
65 const OUT: u16 = InstructionOperands::OUT { 65 const OUT: u16 = InstructionOperands::OUT {
66 destination: OutDestination::PINS, 66 destination: OutDestination::PINS,
67 bit_count: 32, 67 bit_count: 32,
@@ -70,7 +70,7 @@ pub fn set_out_pin<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM
70 sm.tx().push(data); 70 sm.tx().push(data);
71 sm.exec_instr(OUT); 71 sm.exec_instr(OUT);
72} 72}
73pub fn set_out_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) { 73pub unsafe fn set_out_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, data: u32) {
74 const OUT: u16 = InstructionOperands::OUT { 74 const OUT: u16 = InstructionOperands::OUT {
75 destination: OutDestination::PINDIRS, 75 destination: OutDestination::PINDIRS,
76 bit_count: 32, 76 bit_count: 32,
@@ -80,7 +80,7 @@ pub fn set_out_pindir<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO,
80 sm.exec_instr(OUT); 80 sm.exec_instr(OUT);
81} 81}
82 82
83pub fn exec_jmp<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, to_addr: u8) { 83pub unsafe fn exec_jmp<PIO: Instance, const SM: usize>(sm: &mut StateMachine<PIO, SM>, to_addr: u8) {
84 let jmp: u16 = InstructionOperands::JMP { 84 let jmp: u16 = InstructionOperands::JMP {
85 address: to_addr, 85 address: to_addr,
86 condition: JmpCondition::Always, 86 condition: JmpCondition::Always,