Skip to content

[embassy-net-nrf91] patch greater rx_data_len size #4098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ci/doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ docserver-builder -i ./embassy-usb-logger -o webroot/crates/embassy-usb-logger/g
docserver-builder -i ./embassy-usb-synopsys-otg -o webroot/crates/embassy-usb-synopsys-otg/git.zup

docserver-builder -i ./embassy-net -o webroot/crates/embassy-net/git.zup
docserver-builder -i ./embassy-net-nrf91 -o webroot/crates/embassy-net-nrf91/git.zup
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

embassy net nrf91 is missing in the embassy docs. this should add it so we have a nice and up to date documentation available online

docserver-builder -i ./embassy-net-driver -o webroot/crates/embassy-net-driver/git.zup
docserver-builder -i ./embassy-net-driver-channel -o webroot/crates/embassy-net-driver-channel/git.zup
docserver-builder -i ./embassy-net-wiznet -o webroot/crates/embassy-net-wiznet/git.zup
Expand Down
51 changes: 41 additions & 10 deletions embassy-net-nrf91/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ async fn new_internal<'a>(
let shmem_ptr = shmem.as_mut_ptr() as *mut u8;

const SPU_REGION_SIZE: usize = 8192; // 8kb
assert!(shmem_len != 0);
trace!(" shmem_ptr = {}, shmem_len = {}", shmem_ptr, shmem_len);

assert!(shmem_len != 0, "shmem length must not be zero");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return users readable error feedback

assert!(
shmem_len % SPU_REGION_SIZE == 0,
"shmem length must be a multiple of 8kb"
);
assert!(
(shmem_ptr as usize) % SPU_REGION_SIZE == 0,
"shmem length must be a multiple of 8kb"
"shmem pointer must be 8kb-aligned"
);
assert!(
(shmem_ptr as usize + shmem_len) < 0x2002_0000,
Expand All @@ -135,8 +137,15 @@ async fn new_internal<'a>(

let spu = pac::SPU_S;
debug!("Setting IPC RAM as nonsecure...");
trace!(
" SPU_REGION_SIZE={}, shmem_ptr=0x{:08X}, shmem_len={}",
SPU_REGION_SIZE,
shmem_ptr as usize,
shmem_len
);
let region_start = (shmem_ptr as usize - 0x2000_0000) / SPU_REGION_SIZE;
let region_end = region_start + shmem_len / SPU_REGION_SIZE;
trace!(" region_start={}, region_end={}", region_start, region_end);
for i in region_start..region_end {
spu.ramregion(i).perm().write(|w| {
w.set_execute(true);
Expand All @@ -154,13 +163,18 @@ async fn new_internal<'a>(
end: unsafe { shmem_ptr.add(shmem_len) },
_phantom: PhantomData,
};

let ipc = pac::IPC_NS;
let power = pac::POWER_S;
trace!(
" Allocator: start=0x{:08X}, end=0x{:08X}",
alloc.start as usize,
alloc.end as usize
);

let cb: &mut ControlBlock = alloc.alloc().write(unsafe { mem::zeroed() });

let rx = alloc.alloc_bytes(RX_SIZE);
trace!(" RX buffer at {}, size={}", rx.as_ptr(), RX_SIZE);
let trace = alloc.alloc_bytes(TRACE_SIZE);
trace!(" Trace buffer at {}, size={}", trace.as_ptr(), TRACE_SIZE);

cb.version = 0x00010000;
cb.rx_base = rx.as_mut_ptr() as _;
Expand All @@ -174,8 +188,10 @@ async fn new_internal<'a>(
cb.trace.base = trace.as_mut_ptr() as _;
cb.trace.size = TRACE_SIZE;

let ipc = pac::IPC_NS;
ipc.gpmem(0).write_value(cb as *mut _ as u32);
ipc.gpmem(1).write_value(0);
trace!(" GPMEM[0]={:#X}, GPMEM[1]={}", cb as *mut _ as u32, 0);

// connect task/event i to channel i
for i in 0..8 {
Expand All @@ -185,8 +201,9 @@ async fn new_internal<'a>(

compiler_fence(Ordering::SeqCst);

let power = pac::POWER_S;
// POWER.LTEMODEM.STARTN = 0
// The reg is missing in the PAC??
// TODO: The reg is missing in the PAC??
let startn = unsafe { (power.as_ptr() as *mut u32).add(0x610 / 4) };
unsafe { startn.write_volatile(0) }

Expand All @@ -202,6 +219,8 @@ async fn new_internal<'a>(

rx_control_list: ptr::null_mut(),
rx_data_list: ptr::null_mut(),
rx_control_len: 0,
rx_data_len: 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new variable RX lengths

rx_seq_no: 0,
rx_check: PointerChecker {
start: rx.as_mut_ptr() as *mut u8,
Expand Down Expand Up @@ -310,6 +329,10 @@ struct StateInner {

rx_control_list: *mut List,
rx_data_list: *mut List,
/// Number of entries in the control list
rx_control_len: usize,
/// Number of entries in the data list
rx_data_len: usize,
rx_seq_no: u16,
rx_check: PointerChecker,

Expand Down Expand Up @@ -346,8 +369,11 @@ impl StateInner {
self.rx_data_list = desc.data_list_ptr;
let rx_control_len = unsafe { addr_of!((*self.rx_control_list).len).read_volatile() };
let rx_data_len = unsafe { addr_of!((*self.rx_data_list).len).read_volatile() };
assert_eq!(rx_control_len, LIST_LEN);
assert_eq!(rx_data_len, LIST_LEN);

trace!("modem control list length: {}", rx_control_len);
trace!("modem data list length: {}", rx_data_len);
self.rx_control_len = rx_control_len;
self.rx_data_len = rx_data_len;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get and set the RX Lengths we got from the modem

self.init = true;

debug!("IPC initialized OK!");
Expand Down Expand Up @@ -463,7 +489,12 @@ impl StateInner {

fn process(&mut self, list: *mut List, is_control: bool, ch: &mut ch::Runner<MTU>) -> bool {
let mut did_work = false;
for i in 0..LIST_LEN {
let max = if is_control {
self.rx_control_len
} else {
self.rx_data_len
};
for i in 0..max {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either who is in control gets to tell the iteration length

let item_ptr = unsafe { addr_of_mut!((*list).items[i]) };
let preamble = unsafe { addr_of!((*item_ptr).state).read_volatile() };
if preamble & 0xFF == 0x01 && preamble >> 16 == self.rx_seq_no as u32 {
Expand Down Expand Up @@ -947,7 +978,7 @@ impl<'a> Runner<'a> {
}
}

const LIST_LEN: usize = 16;
const LIST_LEN: usize = 32;

#[repr(C)]
struct ControlBlock {
Expand Down