Compare commits

..

No commits in common. "0140e363ce19cac3b8b1a06355d240e1e7b3c360" and "71775c72d6a9212e84ff0c2eeb0c3a5dd4ad9e57" have entirely different histories.

3 changed files with 13 additions and 34 deletions

View file

@ -3,22 +3,18 @@ use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_sync::mutex;
use static_cell::StaticCell;
struct Shared<'a> {
struct CrcShared<'a> {
inner: mutex::Mutex<ThreadModeRawMutex, crc::Crc<'a>>,
}
static STORAGE: StaticCell<Shared> = StaticCell::new();
#[derive(Clone, Copy)]
pub struct Handle {
shared: &'static Shared<'static>,
pub struct CrcHandle {
shared: &'static CrcShared<'static>,
}
struct Stream<'a> {
guard: mutex::MutexGuard<'a, ThreadModeRawMutex, crc::Crc<'a>>,
}
static STORAGE: StaticCell<CrcShared> = StaticCell::new();
impl Handle {
impl CrcHandle {
pub fn new(r: crate::CrcEngineResources) -> Self {
let cfg = crc::Config::new(
crc::InputReverseConfig::None,
@ -29,11 +25,11 @@ impl Handle {
)
.unwrap();
let shared_ref = STORAGE.init(Shared {
let shared_ref = STORAGE.init(CrcShared {
inner: mutex::Mutex::new(crc::Crc::new(r.crc_engine, cfg)),
});
Handle { shared: shared_ref }
CrcHandle { shared: shared_ref }
}
#[allow(clippy::cast_possible_truncation)]
@ -44,21 +40,4 @@ impl Handle {
engine.reset();
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
}
}

View file

@ -2,7 +2,7 @@
extern crate core;
mod crc;
mod crc_engine;
mod io;
mod tasks;
mod utils;
@ -132,7 +132,7 @@ pub fn spawn_tasks(spawner: Spawner) {
let wdg = wdg::IndependentWatchdog::new(r.wdg, 4_000_000);
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());

View file

@ -1,4 +1,4 @@
use crate::{crc, io, println, utils};
use crate::{crc_engine, io, println, utils};
use byteorder::{ByteOrder, LittleEndian};
use embassy_executor::Spawner;
use embassy_stm32::{gpio, usart};
@ -36,7 +36,7 @@ static MESSAGE_BUF: StaticCell<MessageBuf> = StaticCell::new();
struct Tx {
uart: usart::BufferedUartTx<'static>,
channel: crate::TargetMessagePublisher,
crc: crc::Handle,
crc: crc_engine::CrcHandle,
}
#[allow(dead_code)]
@ -44,7 +44,7 @@ struct Rx {
message_buf: &'static mut MessageBuf,
uart: usart::BufferedUartRx<'static>,
channel: crate::TargetMessageGenerator,
crc: crc::Handle,
crc: crc_engine::CrcHandle,
clr_host_transmit: gpio::OutputOpenDrain<'static>,
set_host_transmit: gpio::OutputOpenDrain<'static>,
host_active_led: gpio::OutputOpenDrain<'static>,
@ -53,7 +53,7 @@ struct Rx {
pub fn start(
r: crate::HostInterfaceResources,
spawner: Spawner,
crc: crc::Handle,
crc: crc_engine::CrcHandle,
publisher: crate::TargetMessagePublisher,
generator: crate::TargetMessageGenerator,
) {