aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bus.rs12
-rw-r--r--src/control.rs7
-rw-r--r--src/events.rs2
-rw-r--r--src/fmt.rs29
-rw-r--r--src/runner.rs29
-rw-r--r--src/structs.rs8
6 files changed, 62 insertions, 25 deletions
diff --git a/src/bus.rs b/src/bus.rs
index f77b890df..7700a832a 100644
--- a/src/bus.rs
+++ b/src/bus.rs
@@ -49,30 +49,30 @@ where
49 49
50 while self 50 while self
51 .read32_swapped(REG_BUS_TEST_RO) 51 .read32_swapped(REG_BUS_TEST_RO)
52 .inspect(|v| defmt::trace!("{:#x}", v)) 52 .inspect(|v| trace!("{:#x}", v))
53 .await 53 .await
54 != FEEDBEAD 54 != FEEDBEAD
55 {} 55 {}
56 56
57 self.write32_swapped(REG_BUS_TEST_RW, TEST_PATTERN).await; 57 self.write32_swapped(REG_BUS_TEST_RW, TEST_PATTERN).await;
58 let val = self.read32_swapped(REG_BUS_TEST_RW).await; 58 let val = self.read32_swapped(REG_BUS_TEST_RW).await;
59 defmt::trace!("{:#x}", val); 59 trace!("{:#x}", val);
60 assert_eq!(val, TEST_PATTERN); 60 assert_eq!(val, TEST_PATTERN);
61 61
62 let val = self.read32_swapped(REG_BUS_CTRL).await; 62 let val = self.read32_swapped(REG_BUS_CTRL).await;
63 defmt::trace!("{:#010b}", (val & 0xff)); 63 trace!("{:#010b}", (val & 0xff));
64 64
65 // 32-bit word length, little endian (which is the default endianess). 65 // 32-bit word length, little endian (which is the default endianess).
66 self.write32_swapped(REG_BUS_CTRL, WORD_LENGTH_32 | HIGH_SPEED).await; 66 self.write32_swapped(REG_BUS_CTRL, WORD_LENGTH_32 | HIGH_SPEED).await;
67 67
68 let val = self.read8(FUNC_BUS, REG_BUS_CTRL).await; 68 let val = self.read8(FUNC_BUS, REG_BUS_CTRL).await;
69 defmt::trace!("{:#b}", val); 69 trace!("{:#b}", val);
70 70
71 let val = self.read32(FUNC_BUS, REG_BUS_TEST_RO).await; 71 let val = self.read32(FUNC_BUS, REG_BUS_TEST_RO).await;
72 defmt::trace!("{:#x}", val); 72 trace!("{:#x}", val);
73 assert_eq!(val, FEEDBEAD); 73 assert_eq!(val, FEEDBEAD);
74 let val = self.read32(FUNC_BUS, REG_BUS_TEST_RW).await; 74 let val = self.read32(FUNC_BUS, REG_BUS_TEST_RW).await;
75 defmt::trace!("{:#x}", val); 75 trace!("{:#x}", val);
76 assert_eq!(val, TEST_PATTERN); 76 assert_eq!(val, TEST_PATTERN);
77 } 77 }
78 78
diff --git a/src/control.rs b/src/control.rs
index 7f1c9fe86..8bfa033ba 100644
--- a/src/control.rs
+++ b/src/control.rs
@@ -9,6 +9,7 @@ use embassy_time::{Duration, Timer};
9pub use crate::bus::SpiBusCyw43; 9pub use crate::bus::SpiBusCyw43;
10use crate::consts::*; 10use crate::consts::*;
11use crate::events::{Event, EventQueue}; 11use crate::events::{Event, EventQueue};
12use crate::fmt::Bytes;
12use crate::structs::*; 13use crate::structs::*;
13use crate::{countries, IoctlState, IoctlType, PowerManagementMode}; 14use crate::{countries, IoctlState, IoctlType, PowerManagementMode};
14 15
@@ -75,7 +76,7 @@ impl<'a> Control<'a> {
75 // read MAC addr. 76 // read MAC addr.
76 let mut mac_addr = [0; 6]; 77 let mut mac_addr = [0; 6];
77 assert_eq!(self.get_iovar("cur_etheraddr", &mut mac_addr).await, 6); 78 assert_eq!(self.get_iovar("cur_etheraddr", &mut mac_addr).await, 6);
78 info!("mac addr: {:02x}", mac_addr); 79 info!("mac addr: {:02x}", Bytes(&mac_addr));
79 80
80 let country = countries::WORLD_WIDE_XX; 81 let country = countries::WORLD_WIDE_XX;
81 let country_info = CountryInfo { 82 let country_info = CountryInfo {
@@ -205,7 +206,7 @@ impl<'a> Control<'a> {
205 let msg = subscriber.next_message_pure().await; 206 let msg = subscriber.next_message_pure().await;
206 if msg.event_type == Event::AUTH && msg.status != 0 { 207 if msg.event_type == Event::AUTH && msg.status != 0 {
207 // retry 208 // retry
208 defmt::warn!("JOIN failed with status={}", msg.status); 209 warn!("JOIN failed with status={}", msg.status);
209 self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; 210 self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await;
210 } else if msg.event_type == Event::JOIN && msg.status == 0 { 211 } else if msg.event_type == Event::JOIN && msg.status == 0 {
211 // successful join 212 // successful join
@@ -241,7 +242,7 @@ impl<'a> Control<'a> {
241 } 242 }
242 243
243 async fn set_iovar(&mut self, name: &str, val: &[u8]) { 244 async fn set_iovar(&mut self, name: &str, val: &[u8]) {
244 info!("set {} = {:02x}", name, val); 245 info!("set {} = {:02x}", name, Bytes(val));
245 246
246 let mut buf = [0; 64]; 247 let mut buf = [0; 64];
247 buf[..name.len()].copy_from_slice(name.as_bytes()); 248 buf[..name.len()].copy_from_slice(name.as_bytes());
diff --git a/src/events.rs b/src/events.rs
index 9e6bb9625..b9c8cca6b 100644
--- a/src/events.rs
+++ b/src/events.rs
@@ -6,7 +6,7 @@ use core::num;
6use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 6use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
7use embassy_sync::pubsub::{PubSubChannel, Publisher, Subscriber}; 7use embassy_sync::pubsub::{PubSubChannel, Publisher, Subscriber};
8 8
9#[derive(Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)] 9#[derive(Debug, Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)]
10#[cfg_attr(feature = "defmt", derive(defmt::Format))] 10#[cfg_attr(feature = "defmt", derive(defmt::Format))]
11#[repr(u8)] 11#[repr(u8)]
12pub enum Event { 12pub enum Event {
diff --git a/src/fmt.rs b/src/fmt.rs
index f8bb0a035..5730447b3 100644
--- a/src/fmt.rs
+++ b/src/fmt.rs
@@ -1,6 +1,8 @@
1#![macro_use] 1#![macro_use]
2#![allow(unused_macros)] 2#![allow(unused_macros)]
3 3
4use core::fmt::{Debug, Display, LowerHex};
5
4#[cfg(all(feature = "defmt", feature = "log"))] 6#[cfg(all(feature = "defmt", feature = "log"))]
5compile_error!("You may not enable both `defmt` and `log` features."); 7compile_error!("You may not enable both `defmt` and `log` features.");
6 8
@@ -226,3 +228,30 @@ impl<T, E> Try for Result<T, E> {
226 self 228 self
227 } 229 }
228} 230}
231
232pub struct Bytes<'a>(pub &'a [u8]);
233
234impl<'a> Debug for Bytes<'a> {
235 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
236 write!(f, "{:#02x?}", self.0)
237 }
238}
239
240impl<'a> Display for Bytes<'a> {
241 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
242 write!(f, "{:#02x?}", self.0)
243 }
244}
245
246impl<'a> LowerHex for Bytes<'a> {
247 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
248 write!(f, "{:#02x?}", self.0)
249 }
250}
251
252#[cfg(feature = "defmt")]
253impl<'a> defmt::Format for Bytes<'a> {
254 fn format(&self, fmt: defmt::Formatter) {
255 defmt::write!(fmt, "{:02x}", self.0)
256 }
257}
diff --git a/src/runner.rs b/src/runner.rs
index 5d840bc59..9945af3fc 100644
--- a/src/runner.rs
+++ b/src/runner.rs
@@ -11,6 +11,7 @@ use crate::bus::Bus;
11pub use crate::bus::SpiBusCyw43; 11pub use crate::bus::SpiBusCyw43;
12use crate::consts::*; 12use crate::consts::*;
13use crate::events::{EventQueue, EventStatus}; 13use crate::events::{EventQueue, EventStatus};
14use crate::fmt::Bytes;
14use crate::nvram::NVRAM; 15use crate::nvram::NVRAM;
15use crate::structs::*; 16use crate::structs::*;
16use crate::{events, Core, IoctlState, IoctlType, CHIP, MTU}; 17use crate::{events, Core, IoctlState, IoctlType, CHIP, MTU};
@@ -23,6 +24,7 @@ struct LogState {
23 buf_count: usize, 24 buf_count: usize,
24} 25}
25 26
27#[cfg(feature = "firmware-logs")]
26impl Default for LogState { 28impl Default for LogState {
27 fn default() -> Self { 29 fn default() -> Self {
28 Self { 30 Self {
@@ -175,7 +177,6 @@ where
175 let mut shared = [0; SharedMemData::SIZE]; 177 let mut shared = [0; SharedMemData::SIZE];
176 self.bus.bp_read(shared_addr, &mut shared).await; 178 self.bus.bp_read(shared_addr, &mut shared).await;
177 let shared = SharedMemData::from_bytes(&shared); 179 let shared = SharedMemData::from_bytes(&shared);
178 info!("shared: {:08x}", shared);
179 180
180 self.log.addr = shared.console_addr + 8; 181 self.log.addr = shared.console_addr + 8;
181 } 182 }
@@ -238,7 +239,7 @@ where
238 warn!("TX stalled"); 239 warn!("TX stalled");
239 } else { 240 } else {
240 if let Some(packet) = self.ch.try_tx_buf() { 241 if let Some(packet) = self.ch.try_tx_buf() {
241 trace!("tx pkt {:02x}", &packet[..packet.len().min(48)]); 242 trace!("tx pkt {:02x}", Bytes(&packet[..packet.len().min(48)]));
242 243
243 let mut buf = [0; 512]; 244 let mut buf = [0; 512];
244 let buf8 = slice8_mut(&mut buf); 245 let buf8 = slice8_mut(&mut buf);
@@ -275,7 +276,7 @@ where
275 276
276 let total_len = (total_len + 3) & !3; // round up to 4byte 277 let total_len = (total_len + 3) & !3; // round up to 4byte
277 278
278 trace!(" {:02x}", &buf8[..total_len.min(48)]); 279 trace!(" {:02x}", Bytes(&buf8[..total_len.min(48)]));
279 280
280 self.bus.wlan_write(&buf[..(total_len / 4)]).await; 281 self.bus.wlan_write(&buf[..(total_len / 4)]).await;
281 self.ch.tx_done(); 282 self.ch.tx_done();
@@ -295,7 +296,7 @@ where
295 if status & STATUS_F2_PKT_AVAILABLE != 0 { 296 if status & STATUS_F2_PKT_AVAILABLE != 0 {
296 let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT; 297 let len = (status & STATUS_F2_PKT_LEN_MASK) >> STATUS_F2_PKT_LEN_SHIFT;
297 self.bus.wlan_read(&mut buf, len).await; 298 self.bus.wlan_read(&mut buf, len).await;
298 trace!("rx {:02x}", &slice8_mut(&mut buf)[..(len as usize).min(48)]); 299 trace!("rx {:02x}", Bytes(&slice8_mut(&mut buf)[..(len as usize).min(48)]));
299 self.rx(&slice8_mut(&mut buf)[..len as usize]); 300 self.rx(&slice8_mut(&mut buf)[..len as usize]);
300 } 301 }
301 } 302 }
@@ -343,11 +344,11 @@ where
343 if cdc_header.id == self.ioctl_id { 344 if cdc_header.id == self.ioctl_id {
344 if cdc_header.status != 0 { 345 if cdc_header.status != 0 {
345 // TODO: propagate error instead 346 // TODO: propagate error instead
346 panic!("IOCTL error {=i32}", cdc_header.status as i32); 347 panic!("IOCTL error {}", cdc_header.status as i32);
347 } 348 }
348 349
349 let resp_len = cdc_header.len as usize; 350 let resp_len = cdc_header.len as usize;
350 info!("IOCTL Response: {:02x}", &payload[CdcHeader::SIZE..][..resp_len]); 351 info!("IOCTL Response: {:02x}", Bytes(&payload[CdcHeader::SIZE..][..resp_len]));
351 352
352 (unsafe { &mut *buf }[..resp_len]).copy_from_slice(&payload[CdcHeader::SIZE..][..resp_len]); 353 (unsafe { &mut *buf }[..resp_len]).copy_from_slice(&payload[CdcHeader::SIZE..][..resp_len]);
353 self.ioctl_state.set(IoctlState::Done { resp_len }); 354 self.ioctl_state.set(IoctlState::Done { resp_len });
@@ -365,7 +366,7 @@ where
365 return; 366 return;
366 } 367 }
367 let bcd_packet = &payload[packet_start..]; 368 let bcd_packet = &payload[packet_start..];
368 trace!(" {:02x}", &bcd_packet[..(bcd_packet.len() as usize).min(36)]); 369 trace!(" {:02x}", Bytes(&bcd_packet[..(bcd_packet.len() as usize).min(36)]));
369 370
370 let mut event_packet = EventPacket::from_bytes(&bcd_packet[..EventPacket::SIZE].try_into().unwrap()); 371 let mut event_packet = EventPacket::from_bytes(&bcd_packet[..EventPacket::SIZE].try_into().unwrap());
371 event_packet.byteswap(); 372 event_packet.byteswap();
@@ -382,7 +383,8 @@ where
382 if event_packet.hdr.oui != BROADCOM_OUI { 383 if event_packet.hdr.oui != BROADCOM_OUI {
383 warn!( 384 warn!(
384 "unexpected ethernet OUI {:02x}, expected Broadcom OUI {:02x}", 385 "unexpected ethernet OUI {:02x}, expected Broadcom OUI {:02x}",
385 event_packet.hdr.oui, BROADCOM_OUI 386 Bytes(&event_packet.hdr.oui),
387 Bytes(BROADCOM_OUI)
386 ); 388 );
387 return; 389 return;
388 } 390 }
@@ -405,7 +407,12 @@ where
405 407
406 let evt_type = events::Event::from(event_packet.msg.event_type as u8); 408 let evt_type = events::Event::from(event_packet.msg.event_type as u8);
407 let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize]; 409 let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize];
408 debug!("=== EVENT {}: {} {:02x}", evt_type, event_packet.msg, evt_data); 410 debug!(
411 "=== EVENT {:?}: {:?} {:02x}",
412 evt_type,
413 event_packet.msg,
414 Bytes(evt_data)
415 );
409 416
410 if evt_type == events::Event::AUTH || evt_type == events::Event::JOIN { 417 if evt_type == events::Event::AUTH || evt_type == events::Event::JOIN {
411 self.events.publish_immediate(EventStatus { 418 self.events.publish_immediate(EventStatus {
@@ -424,7 +431,7 @@ where
424 return; 431 return;
425 } 432 }
426 let packet = &payload[packet_start..]; 433 let packet = &payload[packet_start..];
427 trace!("rx pkt {:02x}", &packet[..(packet.len() as usize).min(48)]); 434 trace!("rx pkt {:02x}", Bytes(&packet[..(packet.len() as usize).min(48)]));
428 435
429 match self.ch.try_rx_buf() { 436 match self.ch.try_rx_buf() {
430 Some(buf) => { 437 Some(buf) => {
@@ -490,7 +497,7 @@ where
490 497
491 let total_len = (total_len + 3) & !3; // round up to 4byte 498 let total_len = (total_len + 3) & !3; // round up to 4byte
492 499
493 trace!(" {:02x}", &buf8[..total_len.min(48)]); 500 trace!(" {:02x}", Bytes(&buf8[..total_len.min(48)]));
494 501
495 self.bus.wlan_write(&buf[..total_len / 4]).await; 502 self.bus.wlan_write(&buf[..total_len / 4]).await;
496 } 503 }
diff --git a/src/structs.rs b/src/structs.rs
index 41a340661..e16808f30 100644
--- a/src/structs.rs
+++ b/src/structs.rs
@@ -44,7 +44,7 @@ pub struct SharedMemLog {
44} 44}
45impl_bytes!(SharedMemLog); 45impl_bytes!(SharedMemLog);
46 46
47#[derive(Clone, Copy)] 47#[derive(Debug, Clone, Copy)]
48#[cfg_attr(feature = "defmt", derive(defmt::Format))] 48#[cfg_attr(feature = "defmt", derive(defmt::Format))]
49#[repr(C)] 49#[repr(C)]
50pub struct SdpcmHeader { 50pub struct SdpcmHeader {
@@ -67,7 +67,7 @@ pub struct SdpcmHeader {
67} 67}
68impl_bytes!(SdpcmHeader); 68impl_bytes!(SdpcmHeader);
69 69
70#[derive(Clone, Copy)] 70#[derive(Debug, Clone, Copy)]
71#[cfg_attr(feature = "defmt", derive(defmt::Format))] 71#[cfg_attr(feature = "defmt", derive(defmt::Format))]
72#[repr(C)] 72#[repr(C)]
73pub struct CdcHeader { 73pub struct CdcHeader {
@@ -82,7 +82,7 @@ impl_bytes!(CdcHeader);
82pub const BDC_VERSION: u8 = 2; 82pub const BDC_VERSION: u8 = 2;
83pub const BDC_VERSION_SHIFT: u8 = 4; 83pub const BDC_VERSION_SHIFT: u8 = 4;
84 84
85#[derive(Clone, Copy)] 85#[derive(Debug, Clone, Copy)]
86#[cfg_attr(feature = "defmt", derive(defmt::Format))] 86#[cfg_attr(feature = "defmt", derive(defmt::Format))]
87#[repr(C)] 87#[repr(C)]
88pub struct BcdHeader { 88pub struct BcdHeader {
@@ -129,7 +129,7 @@ impl EventHeader {
129 } 129 }
130} 130}
131 131
132#[derive(Clone, Copy)] 132#[derive(Debug, Clone, Copy)]
133#[cfg_attr(feature = "defmt", derive(defmt::Format))] 133#[cfg_attr(feature = "defmt", derive(defmt::Format))]
134#[repr(C)] 134#[repr(C)]
135pub struct EventMessage { 135pub struct EventMessage {