Compare commits
No commits in common. "0140e363ce19cac3b8b1a06355d240e1e7b3c360" and "71775c72d6a9212e84ff0c2eeb0c3a5dd4ad9e57" have entirely different histories.
0140e363ce
...
71775c72d6
3 changed files with 13 additions and 34 deletions
|
|
@ -3,22 +3,18 @@ use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
||||||
use embassy_sync::mutex;
|
use embassy_sync::mutex;
|
||||||
use static_cell::StaticCell;
|
use static_cell::StaticCell;
|
||||||
|
|
||||||
struct Shared<'a> {
|
struct CrcShared<'a> {
|
||||||
inner: mutex::Mutex<ThreadModeRawMutex, crc::Crc<'a>>,
|
inner: mutex::Mutex<ThreadModeRawMutex, crc::Crc<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static STORAGE: StaticCell<Shared> = StaticCell::new();
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Handle {
|
pub struct CrcHandle {
|
||||||
shared: &'static Shared<'static>,
|
shared: &'static CrcShared<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Stream<'a> {
|
static STORAGE: StaticCell<CrcShared> = StaticCell::new();
|
||||||
guard: mutex::MutexGuard<'a, ThreadModeRawMutex, crc::Crc<'a>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Handle {
|
impl CrcHandle {
|
||||||
pub fn new(r: crate::CrcEngineResources) -> Self {
|
pub fn new(r: crate::CrcEngineResources) -> Self {
|
||||||
let cfg = crc::Config::new(
|
let cfg = crc::Config::new(
|
||||||
crc::InputReverseConfig::None,
|
crc::InputReverseConfig::None,
|
||||||
|
|
@ -29,11 +25,11 @@ impl Handle {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let shared_ref = STORAGE.init(Shared {
|
let shared_ref = STORAGE.init(CrcShared {
|
||||||
inner: mutex::Mutex::new(crc::Crc::new(r.crc_engine, cfg)),
|
inner: mutex::Mutex::new(crc::Crc::new(r.crc_engine, cfg)),
|
||||||
});
|
});
|
||||||
|
|
||||||
Handle { shared: shared_ref }
|
CrcHandle { shared: shared_ref }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
|
|
@ -44,21 +40,4 @@ impl Handle {
|
||||||
engine.reset();
|
engine.reset();
|
||||||
engine.feed_bytes(data) as u16
|
engine.feed_bytes(data) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn stream(&self) -> Stream {
|
|
||||||
let mut guard = self.shared.inner.lock().await;
|
|
||||||
let engine = &mut *guard;
|
|
||||||
|
|
||||||
engine.reset();
|
|
||||||
Stream { guard }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Stream<'_> {
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
|
||||||
pub fn compute(&mut self, data: &[u8]) -> u16 {
|
|
||||||
let engine = &mut *self.guard;
|
|
||||||
|
|
||||||
engine.feed_bytes(data) as u16
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
mod crc;
|
mod crc_engine;
|
||||||
mod io;
|
mod io;
|
||||||
mod tasks;
|
mod tasks;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
@ -132,7 +132,7 @@ pub fn spawn_tasks(spawner: Spawner) {
|
||||||
let wdg = wdg::IndependentWatchdog::new(r.wdg, 4_000_000);
|
let wdg = wdg::IndependentWatchdog::new(r.wdg, 4_000_000);
|
||||||
spawner.must_spawn(supervisor::watchdog_task(wdg));
|
spawner.must_spawn(supervisor::watchdog_task(wdg));
|
||||||
|
|
||||||
let crc_handle = crc::Handle::new(crc_engine_resources!(p));
|
let crc_handle = crc_engine::CrcHandle::new(crc_engine_resources!(p));
|
||||||
|
|
||||||
let tgt_msg_channel = TARGET_MESSAGE_CHANNEL.init(TargetMessageChannel::new());
|
let tgt_msg_channel = TARGET_MESSAGE_CHANNEL.init(TargetMessageChannel::new());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{crc, io, println, utils};
|
use crate::{crc_engine, io, println, utils};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::{gpio, usart};
|
use embassy_stm32::{gpio, usart};
|
||||||
|
|
@ -36,7 +36,7 @@ static MESSAGE_BUF: StaticCell<MessageBuf> = StaticCell::new();
|
||||||
struct Tx {
|
struct Tx {
|
||||||
uart: usart::BufferedUartTx<'static>,
|
uart: usart::BufferedUartTx<'static>,
|
||||||
channel: crate::TargetMessagePublisher,
|
channel: crate::TargetMessagePublisher,
|
||||||
crc: crc::Handle,
|
crc: crc_engine::CrcHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
@ -44,7 +44,7 @@ struct Rx {
|
||||||
message_buf: &'static mut MessageBuf,
|
message_buf: &'static mut MessageBuf,
|
||||||
uart: usart::BufferedUartRx<'static>,
|
uart: usart::BufferedUartRx<'static>,
|
||||||
channel: crate::TargetMessageGenerator,
|
channel: crate::TargetMessageGenerator,
|
||||||
crc: crc::Handle,
|
crc: crc_engine::CrcHandle,
|
||||||
clr_host_transmit: gpio::OutputOpenDrain<'static>,
|
clr_host_transmit: gpio::OutputOpenDrain<'static>,
|
||||||
set_host_transmit: gpio::OutputOpenDrain<'static>,
|
set_host_transmit: gpio::OutputOpenDrain<'static>,
|
||||||
host_active_led: gpio::OutputOpenDrain<'static>,
|
host_active_led: gpio::OutputOpenDrain<'static>,
|
||||||
|
|
@ -53,7 +53,7 @@ struct Rx {
|
||||||
pub fn start(
|
pub fn start(
|
||||||
r: crate::HostInterfaceResources,
|
r: crate::HostInterfaceResources,
|
||||||
spawner: Spawner,
|
spawner: Spawner,
|
||||||
crc: crc::Handle,
|
crc: crc_engine::CrcHandle,
|
||||||
publisher: crate::TargetMessagePublisher,
|
publisher: crate::TargetMessagePublisher,
|
||||||
generator: crate::TargetMessageGenerator,
|
generator: crate::TargetMessageGenerator,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue