Compare commits
2 commits
71775c72d6
...
0140e363ce
| Author | SHA1 | Date | |
|---|---|---|---|
| 0140e363ce | |||
| bfa551c9e2 |
3 changed files with 34 additions and 13 deletions
|
|
@ -3,18 +3,22 @@ use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
||||||
use embassy_sync::mutex;
|
use embassy_sync::mutex;
|
||||||
use static_cell::StaticCell;
|
use static_cell::StaticCell;
|
||||||
|
|
||||||
struct CrcShared<'a> {
|
struct Shared<'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 CrcHandle {
|
pub struct Handle {
|
||||||
shared: &'static CrcShared<'static>,
|
shared: &'static Shared<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static STORAGE: StaticCell<CrcShared> = StaticCell::new();
|
struct Stream<'a> {
|
||||||
|
guard: mutex::MutexGuard<'a, ThreadModeRawMutex, crc::Crc<'a>>,
|
||||||
|
}
|
||||||
|
|
||||||
impl CrcHandle {
|
impl Handle {
|
||||||
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,
|
||||||
|
|
@ -25,11 +29,11 @@ impl CrcHandle {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let shared_ref = STORAGE.init(CrcShared {
|
let shared_ref = STORAGE.init(Shared {
|
||||||
inner: mutex::Mutex::new(crc::Crc::new(r.crc_engine, cfg)),
|
inner: mutex::Mutex::new(crc::Crc::new(r.crc_engine, cfg)),
|
||||||
});
|
});
|
||||||
|
|
||||||
CrcHandle { shared: shared_ref }
|
Handle { shared: shared_ref }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
|
|
@ -40,4 +44,21 @@ impl CrcHandle {
|
||||||
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_engine;
|
mod crc;
|
||||||
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_engine::CrcHandle::new(crc_engine_resources!(p));
|
let crc_handle = crc::Handle::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_engine, io, println, utils};
|
use crate::{crc, 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_engine::CrcHandle,
|
crc: crc::Handle,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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_engine::CrcHandle,
|
crc: crc::Handle,
|
||||||
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_engine::CrcHandle,
|
crc: crc::Handle,
|
||||||
publisher: crate::TargetMessagePublisher,
|
publisher: crate::TargetMessagePublisher,
|
||||||
generator: crate::TargetMessageGenerator,
|
generator: crate::TargetMessageGenerator,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue