diff options
| author | Corey Schuhen <[email protected]> | 2024-03-03 20:45:51 +1000 |
|---|---|---|
| committer | Corey Schuhen <[email protected]> | 2024-03-07 17:45:01 +1000 |
| commit | b0f05e768225ae321cb08a469fa4a384cb8523ab (patch) | |
| tree | 4fbc06f1c397c6e22299607c172210fa67da2ac8 | |
| parent | 34687a0956f4bd6a736dcf9748eaa98040dfddae (diff) | |
Remove unused.
| -rw-r--r-- | embassy-stm32/src/can/bx/interrupt.rs | 130 | ||||
| -rw-r--r-- | embassy-stm32/src/can/bx/mod.rs | 72 |
2 files changed, 0 insertions, 202 deletions
diff --git a/embassy-stm32/src/can/bx/interrupt.rs b/embassy-stm32/src/can/bx/interrupt.rs deleted file mode 100644 index dac4b7b3c..000000000 --- a/embassy-stm32/src/can/bx/interrupt.rs +++ /dev/null | |||
| @@ -1,130 +0,0 @@ | |||
| 1 | //! Interrupt types. | ||
| 2 | |||
| 3 | use core::ops; | ||
| 4 | |||
| 5 | #[allow(unused_imports)] // for intra-doc links only | ||
| 6 | use crate::can::bx::{Can, Rx0}; | ||
| 7 | |||
| 8 | /// bxCAN interrupt sources. | ||
| 9 | /// | ||
| 10 | /// These can be individually enabled and disabled in the bxCAN peripheral. Note that the bxCAN | ||
| 11 | /// peripheral only exposes 4 interrupts to the microcontroller: | ||
| 12 | /// | ||
| 13 | /// * TX | ||
| 14 | /// * RX FIFO 1 | ||
| 15 | /// * RX FIFO 2 | ||
| 16 | /// * SCE (Status Change Error) | ||
| 17 | /// | ||
| 18 | /// This means that some of the interrupts listed here will result in the same interrupt handler | ||
| 19 | /// being invoked. | ||
| 20 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| 21 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 22 | #[non_exhaustive] | ||
| 23 | pub enum Interrupt { | ||
| 24 | /// Fires the **TX** interrupt when one of the transmit mailboxes returns to empty state. | ||
| 25 | /// | ||
| 26 | /// This usually happens because its message was either transmitted successfully, or | ||
| 27 | /// transmission was aborted successfully. | ||
| 28 | /// | ||
| 29 | /// The interrupt handler must clear the interrupt condition by calling | ||
| 30 | /// [`Can::clear_request_completed_flag`] or [`Can::clear_tx_interrupt`]. | ||
| 31 | TransmitMailboxEmpty = 1 << 0, | ||
| 32 | |||
| 33 | /// Fires the **RX FIFO 0** interrupt when FIFO 0 holds a message. | ||
| 34 | /// | ||
| 35 | /// The interrupt handler must clear the interrupt condition by receiving all messages from the | ||
| 36 | /// FIFO by calling [`Can::receive`] or [`Rx0::receive`]. | ||
| 37 | Fifo0MessagePending = 1 << 1, | ||
| 38 | |||
| 39 | /// Fires the **RX FIFO 0** interrupt when FIFO 0 holds 3 incoming messages. | ||
| 40 | /// | ||
| 41 | /// The interrupt handler must clear the interrupt condition by receiving at least one message | ||
| 42 | /// from the FIFO (making it no longer "full"). This can be done by calling [`Can::receive`] or | ||
| 43 | /// [`Rx0::receive`]. | ||
| 44 | Fifo0Full = 1 << 2, | ||
| 45 | |||
| 46 | /// Fires the **RX FIFO 0** interrupt when FIFO 0 drops an incoming message. | ||
| 47 | /// | ||
| 48 | /// The interrupt handler must clear the interrupt condition by calling [`Can::receive`] or | ||
| 49 | /// [`Rx0::receive`] (which will return an error). | ||
| 50 | Fifo0Overrun = 1 << 3, | ||
| 51 | |||
| 52 | /// Fires the **RX FIFO 1** interrupt when FIFO 1 holds a message. | ||
| 53 | /// | ||
| 54 | /// Behavior is otherwise identical to [`Self::Fifo0MessagePending`]. | ||
| 55 | Fifo1MessagePending = 1 << 4, | ||
| 56 | |||
| 57 | /// Fires the **RX FIFO 1** interrupt when FIFO 1 holds 3 incoming messages. | ||
| 58 | /// | ||
| 59 | /// Behavior is otherwise identical to [`Self::Fifo0Full`]. | ||
| 60 | Fifo1Full = 1 << 5, | ||
| 61 | |||
| 62 | /// Fires the **RX FIFO 1** interrupt when FIFO 1 drops an incoming message. | ||
| 63 | /// | ||
| 64 | /// Behavior is otherwise identical to [`Self::Fifo0Overrun`]. | ||
| 65 | Fifo1Overrun = 1 << 6, | ||
| 66 | |||
| 67 | Error = 1 << 15, | ||
| 68 | |||
| 69 | /// Fires the **SCE** interrupt when an incoming CAN frame is detected while the peripheral is | ||
| 70 | /// in sleep mode. | ||
| 71 | /// | ||
| 72 | /// The interrupt handler must clear the interrupt condition by calling | ||
| 73 | /// [`Can::clear_wakeup_interrupt`]. | ||
| 74 | Wakeup = 1 << 16, | ||
| 75 | |||
| 76 | /// Fires the **SCE** interrupt when the peripheral enters sleep mode. | ||
| 77 | /// | ||
| 78 | /// The interrupt handler must clear the interrupt condition by calling | ||
| 79 | /// [`Can::clear_sleep_interrupt`]. | ||
| 80 | Sleep = 1 << 17, | ||
| 81 | } | ||
| 82 | |||
| 83 | bitflags::bitflags! { | ||
| 84 | /// A set of bxCAN interrupts. | ||
| 85 | pub struct Interrupts: u32 { | ||
| 86 | const TRANSMIT_MAILBOX_EMPTY = 1 << 0; | ||
| 87 | const FIFO0_MESSAGE_PENDING = 1 << 1; | ||
| 88 | const FIFO0_FULL = 1 << 2; | ||
| 89 | const FIFO0_OVERRUN = 1 << 3; | ||
| 90 | const FIFO1_MESSAGE_PENDING = 1 << 4; | ||
| 91 | const FIFO1_FULL = 1 << 5; | ||
| 92 | const FIFO1_OVERRUN = 1 << 6; | ||
| 93 | const ERROR = 1 << 15; | ||
| 94 | const WAKEUP = 1 << 16; | ||
| 95 | const SLEEP = 1 << 17; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | impl From<Interrupt> for Interrupts { | ||
| 100 | #[inline] | ||
| 101 | fn from(i: Interrupt) -> Self { | ||
| 102 | Self::from_bits_truncate(i as u32) | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | /// Adds an interrupt to the interrupt set. | ||
| 107 | impl ops::BitOrAssign<Interrupt> for Interrupts { | ||
| 108 | #[inline] | ||
| 109 | fn bitor_assign(&mut self, rhs: Interrupt) { | ||
| 110 | *self |= Self::from(rhs); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | #[cfg(test)] | ||
| 115 | mod tests { | ||
| 116 | use super::*; | ||
| 117 | |||
| 118 | #[test] | ||
| 119 | fn interrupt_flags() { | ||
| 120 | assert_eq!(Interrupts::from(Interrupt::Sleep), Interrupts::SLEEP); | ||
| 121 | assert_eq!( | ||
| 122 | Interrupts::from(Interrupt::TransmitMailboxEmpty), | ||
| 123 | Interrupts::TRANSMIT_MAILBOX_EMPTY | ||
| 124 | ); | ||
| 125 | |||
| 126 | let mut ints = Interrupts::FIFO0_FULL; | ||
| 127 | ints |= Interrupt::Fifo1Full; | ||
| 128 | assert_eq!(ints, Interrupts::FIFO0_FULL | Interrupts::FIFO1_FULL); | ||
| 129 | } | ||
| 130 | } | ||
diff --git a/embassy-stm32/src/can/bx/mod.rs b/embassy-stm32/src/can/bx/mod.rs index d6e023217..c5801abec 100644 --- a/embassy-stm32/src/can/bx/mod.rs +++ b/embassy-stm32/src/can/bx/mod.rs | |||
| @@ -27,7 +27,6 @@ | |||
| 27 | pub mod filter; | 27 | pub mod filter; |
| 28 | mod frame; | 28 | mod frame; |
| 29 | mod id; | 29 | mod id; |
| 30 | mod interrupt; | ||
| 31 | 30 | ||
| 32 | #[allow(clippy::all)] // generated code | 31 | #[allow(clippy::all)] // generated code |
| 33 | mod pac; | 32 | mod pac; |
| @@ -43,7 +42,6 @@ pub use id::{ExtendedId, Id, StandardId}; | |||
| 43 | use self::pac::generic::*; | 42 | use self::pac::generic::*; |
| 44 | use crate::can::bx::filter::MasterFilters; | 43 | use crate::can::bx::filter::MasterFilters; |
| 45 | pub use crate::can::bx::frame::{Data, Frame, FramePriority}; | 44 | pub use crate::can::bx::frame::{Data, Frame, FramePriority}; |
| 46 | pub use crate::can::bx::interrupt::{Interrupt, Interrupts}; | ||
| 47 | pub use crate::can::bx::pac::can::RegisterBlock; // To make the PAC extraction build | 45 | pub use crate::can::bx::pac::can::RegisterBlock; // To make the PAC extraction build |
| 48 | 46 | ||
| 49 | /// A bxCAN peripheral instance. | 47 | /// A bxCAN peripheral instance. |
| @@ -551,76 +549,6 @@ where | |||
| 551 | } | 549 | } |
| 552 | } | 550 | } |
| 553 | 551 | ||
| 554 | /// Starts listening for a CAN interrupt. | ||
| 555 | pub fn enable_interrupt(&mut self, interrupt: Interrupt) { | ||
| 556 | self.enable_interrupts(Interrupts::from_bits_truncate(interrupt as u32)) | ||
| 557 | } | ||
| 558 | |||
| 559 | /// Starts listening for a set of CAN interrupts. | ||
| 560 | pub fn enable_interrupts(&mut self, interrupts: Interrupts) { | ||
| 561 | self.registers() | ||
| 562 | .ier | ||
| 563 | .modify(|r, w| unsafe { w.bits(r.bits() | interrupts.bits()) }) | ||
| 564 | } | ||
| 565 | |||
| 566 | /// Stops listening for a CAN interrupt. | ||
| 567 | pub fn disable_interrupt(&mut self, interrupt: Interrupt) { | ||
| 568 | self.disable_interrupts(Interrupts::from_bits_truncate(interrupt as u32)) | ||
| 569 | } | ||
| 570 | |||
| 571 | /// Stops listening for a set of CAN interrupts. | ||
| 572 | pub fn disable_interrupts(&mut self, interrupts: Interrupts) { | ||
| 573 | self.registers() | ||
| 574 | .ier | ||
| 575 | .modify(|r, w| unsafe { w.bits(r.bits() & !interrupts.bits()) }) | ||
| 576 | } | ||
| 577 | |||
| 578 | /// Clears the pending flag of [`Interrupt::Sleep`]. | ||
| 579 | pub fn clear_sleep_interrupt(&self) { | ||
| 580 | let can = self.registers(); | ||
| 581 | // Read-only register with write-1-to-clear, so `&self` is sufficient. | ||
| 582 | can.msr.write(|w| w.slaki().set_bit()); | ||
| 583 | } | ||
| 584 | |||
| 585 | /// Clears the pending flag of [`Interrupt::Wakeup`]. | ||
| 586 | pub fn clear_wakeup_interrupt(&self) { | ||
| 587 | let can = self.registers(); | ||
| 588 | // Read-only register with write-1-to-clear, so `&self` is sufficient. | ||
| 589 | can.msr.write(|w| w.wkui().set_bit()); | ||
| 590 | } | ||
| 591 | |||
| 592 | /// Clears the "Request Completed" (RQCP) flag of a transmit mailbox. | ||
| 593 | /// | ||
| 594 | /// Returns the [`Mailbox`] whose flag was cleared. If no mailbox has the flag set, returns | ||
| 595 | /// `None`. | ||
| 596 | /// | ||
| 597 | /// Once this function returns `None`, a pending [`Interrupt::TransmitMailboxEmpty`] is | ||
| 598 | /// considered acknowledged. | ||
| 599 | pub fn clear_request_completed_flag(&mut self) -> Option<Mailbox> { | ||
| 600 | let can = self.registers(); | ||
| 601 | let tsr = can.tsr.read(); | ||
| 602 | if tsr.rqcp0().bit_is_set() { | ||
| 603 | can.tsr.modify(|_, w| w.rqcp0().set_bit()); | ||
| 604 | Some(Mailbox::Mailbox0) | ||
| 605 | } else if tsr.rqcp1().bit_is_set() { | ||
| 606 | can.tsr.modify(|_, w| w.rqcp1().set_bit()); | ||
| 607 | Some(Mailbox::Mailbox1) | ||
| 608 | } else if tsr.rqcp2().bit_is_set() { | ||
| 609 | can.tsr.modify(|_, w| w.rqcp2().set_bit()); | ||
| 610 | Some(Mailbox::Mailbox2) | ||
| 611 | } else { | ||
| 612 | None | ||
| 613 | } | ||
| 614 | } | ||
| 615 | |||
| 616 | /// Clears a pending TX interrupt ([`Interrupt::TransmitMailboxEmpty`]). | ||
| 617 | /// | ||
| 618 | /// This does not return the mailboxes that have finished tranmission. If you need that | ||
| 619 | /// information, call [`Can::clear_request_completed_flag`] instead. | ||
| 620 | pub fn clear_tx_interrupt(&mut self) { | ||
| 621 | while self.clear_request_completed_flag().is_some() {} | ||
| 622 | } | ||
| 623 | |||
| 624 | /// Puts a CAN frame in a free transmit mailbox for transmission on the bus. | 552 | /// Puts a CAN frame in a free transmit mailbox for transmission on the bus. |
| 625 | /// | 553 | /// |
| 626 | /// Frames are transmitted to the bus based on their priority (see [`FramePriority`]). | 554 | /// Frames are transmitted to the bus based on their priority (see [`FramePriority`]). |
