stm32/ipcc: static methods for IPCC
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
|
||||
|
||||
use crate::ipcc::sealed::Instance;
|
||||
use crate::peripherals::IPCC;
|
||||
use crate::rcc::sealed::RccPeripheral;
|
||||
@ -29,22 +27,10 @@ pub(crate) mod sealed {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Ipcc<'d> {
|
||||
_peri: PeripheralRef<'d, IPCC>,
|
||||
}
|
||||
pub(crate) struct Ipcc;
|
||||
|
||||
impl<'d> Ipcc<'d> {
|
||||
pub fn new(peri: impl Peripheral<P = IPCC> + 'd, _config: Config) -> Self {
|
||||
Self::new_inner(peri)
|
||||
}
|
||||
|
||||
pub(crate) fn new_inner(peri: impl Peripheral<P = IPCC> + 'd) -> Self {
|
||||
into_ref!(peri);
|
||||
|
||||
Self { _peri: peri }
|
||||
}
|
||||
|
||||
pub fn init(&mut self) {
|
||||
impl Ipcc {
|
||||
pub(crate) fn init(_config: Config) {
|
||||
IPCC::enable();
|
||||
IPCC::reset();
|
||||
IPCC::set_cpu2(true);
|
||||
@ -61,56 +47,60 @@ impl<'d> Ipcc<'d> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn c1_set_rx_channel(&mut self, channel: IpccChannel, enabled: bool) {
|
||||
pub(crate) fn c1_set_rx_channel(channel: IpccChannel, enabled: bool) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
unsafe { regs.cpu(0).mr().modify(|w| w.set_chom(channel as usize, !enabled)) }
|
||||
}
|
||||
|
||||
pub fn c1_get_rx_channel(&self, channel: IpccChannel) -> bool {
|
||||
pub(crate) fn c1_get_rx_channel(channel: IpccChannel) -> bool {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
unsafe { !regs.cpu(0).mr().read().chom(channel as usize) }
|
||||
}
|
||||
|
||||
pub fn c2_set_rx_channel(&mut self, channel: IpccChannel, enabled: bool) {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn c2_set_rx_channel(channel: IpccChannel, enabled: bool) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
unsafe { regs.cpu(1).mr().modify(|w| w.set_chom(channel as usize, !enabled)) }
|
||||
}
|
||||
|
||||
pub fn c2_get_rx_channel(&self, channel: IpccChannel) -> bool {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn c2_get_rx_channel(channel: IpccChannel) -> bool {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
unsafe { !regs.cpu(1).mr().read().chom(channel as usize) }
|
||||
}
|
||||
|
||||
pub fn c1_set_tx_channel(&mut self, channel: IpccChannel, enabled: bool) {
|
||||
pub(crate) fn c1_set_tx_channel(channel: IpccChannel, enabled: bool) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
unsafe { regs.cpu(0).mr().modify(|w| w.set_chfm(channel as usize, !enabled)) }
|
||||
}
|
||||
|
||||
pub fn c1_get_tx_channel(&self, channel: IpccChannel) -> bool {
|
||||
pub(crate) fn c1_get_tx_channel(channel: IpccChannel) -> bool {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
unsafe { !regs.cpu(0).mr().read().chfm(channel as usize) }
|
||||
}
|
||||
|
||||
pub fn c2_set_tx_channel(&mut self, channel: IpccChannel, enabled: bool) {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn c2_set_tx_channel(channel: IpccChannel, enabled: bool) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
unsafe { regs.cpu(1).mr().modify(|w| w.set_chfm(channel as usize, !enabled)) }
|
||||
}
|
||||
|
||||
pub fn c2_get_tx_channel(&self, channel: IpccChannel) -> bool {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn c2_get_tx_channel(channel: IpccChannel) -> bool {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
// If bit is set to 1 then interrupt is disabled
|
||||
@ -118,53 +108,51 @@ impl<'d> Ipcc<'d> {
|
||||
}
|
||||
|
||||
/// clears IPCC receive channel status for CPU1
|
||||
pub fn c1_clear_flag_channel(&mut self, channel: IpccChannel) {
|
||||
pub(crate) fn c1_clear_flag_channel(channel: IpccChannel) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
unsafe { regs.cpu(0).scr().write(|w| w.set_chc(channel as usize, true)) }
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// clears IPCC receive channel status for CPU2
|
||||
pub fn c2_clear_flag_channel(&mut self, channel: IpccChannel) {
|
||||
pub(crate) fn c2_clear_flag_channel(channel: IpccChannel) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
unsafe { regs.cpu(1).scr().write(|w| w.set_chc(channel as usize, true)) }
|
||||
}
|
||||
|
||||
pub fn c1_set_flag_channel(&mut self, channel: IpccChannel) {
|
||||
pub(crate) fn c1_set_flag_channel(channel: IpccChannel) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
unsafe { regs.cpu(0).scr().write(|w| w.set_chs(channel as usize, true)) }
|
||||
}
|
||||
|
||||
pub fn c2_set_flag_channel(&mut self, channel: IpccChannel) {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn c2_set_flag_channel(channel: IpccChannel) {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
unsafe { regs.cpu(1).scr().write(|w| w.set_chs(channel as usize, true)) }
|
||||
}
|
||||
|
||||
pub fn c1_is_active_flag(&self, channel: IpccChannel) -> bool {
|
||||
pub(crate) fn c1_is_active_flag(channel: IpccChannel) -> bool {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
unsafe { regs.cpu(0).sr().read().chf(channel as usize) }
|
||||
}
|
||||
|
||||
pub fn c2_is_active_flag(&self, channel: IpccChannel) -> bool {
|
||||
pub(crate) fn c2_is_active_flag(channel: IpccChannel) -> bool {
|
||||
let regs = IPCC::regs();
|
||||
|
||||
unsafe { regs.cpu(1).sr().read().chf(channel as usize) }
|
||||
}
|
||||
|
||||
pub fn is_tx_pending(&self, channel: IpccChannel) -> bool {
|
||||
!self.c1_is_active_flag(channel) && self.c1_get_tx_channel(channel)
|
||||
pub(crate) fn is_tx_pending(channel: IpccChannel) -> bool {
|
||||
!Self::c1_is_active_flag(channel) && Self::c1_get_tx_channel(channel)
|
||||
}
|
||||
|
||||
pub fn is_rx_pending(&self, channel: IpccChannel) -> bool {
|
||||
self.c2_is_active_flag(channel) && self.c1_get_rx_channel(channel)
|
||||
}
|
||||
|
||||
pub fn as_mut_ptr(&self) -> *mut Self {
|
||||
unsafe { &mut core::ptr::read(self) as *mut _ }
|
||||
pub(crate) fn is_rx_pending(channel: IpccChannel) -> bool {
|
||||
Self::c2_is_active_flag(channel) && Self::c1_get_rx_channel(channel)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user