aboutsummaryrefslogtreecommitdiff
path: root/src/runner.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-04-27 18:23:36 +0000
committerGitHub <[email protected]>2023-04-27 18:23:36 +0000
commitc19de2984751ba6fa2972ee66cfa2a6310d5f0c1 (patch)
tree9ba8fa01994be9ef43af404cb4399854e8c6de22 /src/runner.rs
parentf4bfda345d3d18232926a87b10333a2e624f4d04 (diff)
parent9e96655757180d7fe32ebff1ed93a35a4c3cff28 (diff)
Merge pull request #63 from kbleeke/generalize-events
rework event handling to allow sending data to `Control`
Diffstat (limited to 'src/runner.rs')
-rw-r--r--src/runner.rs37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/runner.rs b/src/runner.rs
index f0f6fceeb..806ddfc49 100644
--- a/src/runner.rs
+++ b/src/runner.rs
@@ -1,5 +1,3 @@
1use core::slice;
2
3use embassy_futures::select::{select3, Either3}; 1use embassy_futures::select::{select3, Either3};
4use embassy_net_driver_channel as ch; 2use embassy_net_driver_channel as ch;
5use embassy_sync::pubsub::PubSubBehavior; 3use embassy_sync::pubsub::PubSubBehavior;
@@ -9,12 +7,12 @@ use embedded_hal_1::digital::OutputPin;
9use crate::bus::Bus; 7use crate::bus::Bus;
10pub use crate::bus::SpiBusCyw43; 8pub use crate::bus::SpiBusCyw43;
11use crate::consts::*; 9use crate::consts::*;
12use crate::events::{EventQueue, EventStatus}; 10use crate::events::{Events, Status};
13use crate::fmt::Bytes; 11use crate::fmt::Bytes;
14use crate::ioctl::{IoctlState, IoctlType, PendingIoctl}; 12use crate::ioctl::{IoctlState, IoctlType, PendingIoctl};
15use crate::nvram::NVRAM; 13use crate::nvram::NVRAM;
16use crate::structs::*; 14use crate::structs::*;
17use crate::{events, Core, CHIP, MTU}; 15use crate::{events, slice8_mut, Core, CHIP, MTU};
18 16
19#[cfg(feature = "firmware-logs")] 17#[cfg(feature = "firmware-logs")]
20struct LogState { 18struct LogState {
@@ -45,7 +43,7 @@ pub struct Runner<'a, PWR, SPI> {
45 sdpcm_seq: u8, 43 sdpcm_seq: u8,
46 sdpcm_seq_max: u8, 44 sdpcm_seq_max: u8,
47 45
48 events: &'a EventQueue, 46 events: &'a Events,
49 47
50 #[cfg(feature = "firmware-logs")] 48 #[cfg(feature = "firmware-logs")]
51 log: LogState, 49 log: LogState,
@@ -60,7 +58,7 @@ where
60 ch: ch::Runner<'a, MTU>, 58 ch: ch::Runner<'a, MTU>,
61 bus: Bus<PWR, SPI>, 59 bus: Bus<PWR, SPI>,
62 ioctl_state: &'a IoctlState, 60 ioctl_state: &'a IoctlState,
63 events: &'a EventQueue, 61 events: &'a Events,
64 ) -> Self { 62 ) -> Self {
65 Self { 63 Self {
66 ch, 64 ch,
@@ -353,8 +351,6 @@ where
353 panic!("IOCTL error {}", cdc_header.status as i32); 351 panic!("IOCTL error {}", cdc_header.status as i32);
354 } 352 }
355 353
356 info!("IOCTL Response: {:02x}", Bytes(response));
357
358 self.ioctl_state.ioctl_done(response); 354 self.ioctl_state.ioctl_done(response);
359 } 355 }
360 } 356 }
@@ -406,11 +402,21 @@ where
406 Bytes(evt_data) 402 Bytes(evt_data)
407 ); 403 );
408 404
409 if evt_type == events::Event::AUTH || evt_type == events::Event::JOIN { 405 if self.events.mask.is_enabled(evt_type) {
410 self.events.publish_immediate(EventStatus { 406 let status = event_packet.msg.status;
411 status: event_packet.msg.status, 407 let event_payload = events::Payload::None;
412 event_type: evt_type, 408
413 }); 409 // this intentionally uses the non-blocking publish immediate
410 // publish() is a deadlock risk in the current design as awaiting here prevents ioctls
411 // The `Runner` always yields when accessing the device, so consumers always have a chance to receive the event
412 // (if they are actively awaiting the queue)
413 self.events.queue.publish_immediate(events::Message::new(
414 Status {
415 event_type: evt_type,
416 status,
417 },
418 event_payload,
419 ));
414 } 420 }
415 } 421 }
416 CHANNEL_TYPE_DATA => { 422 CHANNEL_TYPE_DATA => {
@@ -548,8 +554,3 @@ where
548 true 554 true
549 } 555 }
550} 556}
551
552fn slice8_mut(x: &mut [u32]) -> &mut [u8] {
553 let len = x.len() * 4;
554 unsafe { slice::from_raw_parts_mut(x.as_mut_ptr() as _, len) }
555}