aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-nrf91
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-10-24 13:31:53 +0200
committerDario Nieuwenhuis <[email protected]>2024-11-04 00:47:31 +0100
commit51f6b813e1a4311ffb4adf2e66ed3effb990d246 (patch)
tree66a175cc893b00dcd56bcaff0e6b90b4d0753732 /embassy-net-nrf91
parent650f97924ab540d3232b187cbde73d7a0104f734 (diff)
nrf: port to chiptool-based `nrf-pac`.
Diffstat (limited to 'embassy-net-nrf91')
-rw-r--r--embassy-net-nrf91/Cargo.toml3
-rw-r--r--embassy-net-nrf91/src/lib.rs78
2 files changed, 39 insertions, 42 deletions
diff --git a/embassy-net-nrf91/Cargo.toml b/embassy-net-nrf91/Cargo.toml
index 07a0c8886..98356c1ba 100644
--- a/embassy-net-nrf91/Cargo.toml
+++ b/embassy-net-nrf91/Cargo.toml
@@ -17,7 +17,8 @@ log = [ "dep:log" ]
17defmt = { version = "0.3", optional = true } 17defmt = { version = "0.3", optional = true }
18log = { version = "0.4.14", optional = true } 18log = { version = "0.4.14", optional = true }
19 19
20nrf9160-pac = { version = "0.12.0" } 20nrf-pac = { git = "https://github.com/embassy-rs/nrf-pac", rev = "875a29629cc1c87aae00cfea647a956b3807d8be" }
21cortex-m = "0.7.7"
21 22
22embassy-time = { version = "0.3.1", path = "../embassy-time" } 23embassy-time = { version = "0.3.1", path = "../embassy-time" }
23embassy-sync = { version = "0.6.0", path = "../embassy-sync"} 24embassy-sync = { version = "0.6.0", path = "../embassy-sync"}
diff --git a/embassy-net-nrf91/src/lib.rs b/embassy-net-nrf91/src/lib.rs
index 60cdc38c6..80d08f7f5 100644
--- a/embassy-net-nrf91/src/lib.rs
+++ b/embassy-net-nrf91/src/lib.rs
@@ -17,12 +17,12 @@ use core::slice;
17use core::sync::atomic::{compiler_fence, fence, Ordering}; 17use core::sync::atomic::{compiler_fence, fence, Ordering};
18use core::task::{Poll, Waker}; 18use core::task::{Poll, Waker};
19 19
20use cortex_m::peripheral::NVIC;
20use embassy_sync::blocking_mutex::raw::NoopRawMutex; 21use embassy_sync::blocking_mutex::raw::NoopRawMutex;
21use embassy_sync::pipe; 22use embassy_sync::pipe;
22use embassy_sync::waitqueue::{AtomicWaker, WakerRegistration}; 23use embassy_sync::waitqueue::{AtomicWaker, WakerRegistration};
23use heapless::Vec; 24use heapless::Vec;
24use pac::NVIC; 25use {embassy_net_driver_channel as ch, nrf_pac as pac};
25use {embassy_net_driver_channel as ch, nrf9160_pac as pac};
26 26
27const RX_SIZE: usize = 8 * 1024; 27const RX_SIZE: usize = 8 * 1024;
28const TRACE_SIZE: usize = 16 * 1024; 28const TRACE_SIZE: usize = 16 * 1024;
@@ -38,11 +38,9 @@ static WAKER: AtomicWaker = AtomicWaker::new();
38 38
39/// Call this function on IPC IRQ 39/// Call this function on IPC IRQ
40pub fn on_ipc_irq() { 40pub fn on_ipc_irq() {
41 let ipc = unsafe { &*pac::IPC_NS::ptr() };
42
43 trace!("irq"); 41 trace!("irq");
44 42
45 ipc.inten.write(|w| w); 43 pac::IPC_NS.inten().write(|_| ());
46 WAKER.wake(); 44 WAKER.wake();
47} 45}
48 46
@@ -135,22 +133,21 @@ async fn new_internal<'a>(
135 "shmem must be in the lower 128kb of RAM" 133 "shmem must be in the lower 128kb of RAM"
136 ); 134 );
137 135
138 let spu = unsafe { &*pac::SPU_S::ptr() }; 136 let spu = pac::SPU_S;
139 debug!("Setting IPC RAM as nonsecure..."); 137 debug!("Setting IPC RAM as nonsecure...");
140 let region_start = (shmem_ptr as usize - 0x2000_0000) / SPU_REGION_SIZE; 138 let region_start = (shmem_ptr as usize - 0x2000_0000) / SPU_REGION_SIZE;
141 let region_end = region_start + shmem_len / SPU_REGION_SIZE; 139 let region_end = region_start + shmem_len / SPU_REGION_SIZE;
142 for i in region_start..region_end { 140 for i in region_start..region_end {
143 spu.ramregion[i].perm.write(|w| { 141 spu.ramregion(i).perm().write(|w| {
144 w.execute().set_bit(); 142 w.set_execute(true);
145 w.write().set_bit(); 143 w.set_write(true);
146 w.read().set_bit(); 144 w.set_read(true);
147 w.secattr().clear_bit(); 145 w.set_secattr(false);
148 w.lock().clear_bit(); 146 w.set_lock(false);
149 w
150 }) 147 })
151 } 148 }
152 149
153 spu.periphid[42].perm.write(|w| w.secattr().non_secure()); 150 spu.periphid(42).perm().write(|w| w.set_secattr(false));
154 151
155 let mut alloc = Allocator { 152 let mut alloc = Allocator {
156 start: shmem_ptr, 153 start: shmem_ptr,
@@ -158,8 +155,8 @@ async fn new_internal<'a>(
158 _phantom: PhantomData, 155 _phantom: PhantomData,
159 }; 156 };
160 157
161 let ipc = unsafe { &*pac::IPC_NS::ptr() }; 158 let ipc = pac::IPC_NS;
162 let power = unsafe { &*pac::POWER_S::ptr() }; 159 let power = pac::POWER_S;
163 160
164 let cb: &mut ControlBlock = alloc.alloc().write(unsafe { mem::zeroed() }); 161 let cb: &mut ControlBlock = alloc.alloc().write(unsafe { mem::zeroed() });
165 let rx = alloc.alloc_bytes(RX_SIZE); 162 let rx = alloc.alloc_bytes(RX_SIZE);
@@ -177,20 +174,20 @@ async fn new_internal<'a>(
177 cb.trace.base = trace.as_mut_ptr() as _; 174 cb.trace.base = trace.as_mut_ptr() as _;
178 cb.trace.size = TRACE_SIZE; 175 cb.trace.size = TRACE_SIZE;
179 176
180 ipc.gpmem[0].write(|w| unsafe { w.bits(cb as *mut _ as u32) }); 177 ipc.gpmem(0).write_value(cb as *mut _ as u32);
181 ipc.gpmem[1].write(|w| unsafe { w.bits(0) }); 178 ipc.gpmem(1).write_value(0);
182 179
183 // connect task/event i to channel i 180 // connect task/event i to channel i
184 for i in 0..8 { 181 for i in 0..8 {
185 ipc.send_cnf[i].write(|w| unsafe { w.bits(1 << i) }); 182 ipc.send_cnf(i).write(|w| w.0 = 1 << i);
186 ipc.receive_cnf[i].write(|w| unsafe { w.bits(1 << i) }); 183 ipc.receive_cnf(i).write(|w| w.0 = 1 << i);
187 } 184 }
188 185
189 compiler_fence(Ordering::SeqCst); 186 compiler_fence(Ordering::SeqCst);
190 187
191 // POWER.LTEMODEM.STARTN = 0 188 // POWER.LTEMODEM.STARTN = 0
192 // The reg is missing in the PAC?? 189 // The reg is missing in the PAC??
193 let startn = unsafe { (power as *const _ as *mut u32).add(0x610 / 4) }; 190 let startn = unsafe { (power.as_ptr() as *mut u32).add(0x610 / 4) };
194 unsafe { startn.write_volatile(0) } 191 unsafe { startn.write_volatile(0) }
195 192
196 unsafe { NVIC::unmask(pac::Interrupt::IPC) }; 193 unsafe { NVIC::unmask(pac::Interrupt::IPC) };
@@ -322,15 +319,15 @@ struct StateInner {
322impl StateInner { 319impl StateInner {
323 fn poll(&mut self, trace_writer: &mut Option<TraceWriter<'_>>, ch: &mut ch::Runner<MTU>) { 320 fn poll(&mut self, trace_writer: &mut Option<TraceWriter<'_>>, ch: &mut ch::Runner<MTU>) {
324 trace!("poll!"); 321 trace!("poll!");
325 let ipc = unsafe { &*pac::IPC_NS::ptr() }; 322 let ipc = pac::IPC_NS;
326 323
327 if ipc.events_receive[0].read().bits() != 0 { 324 if ipc.events_receive(0).read() != 0 {
328 ipc.events_receive[0].reset(); 325 ipc.events_receive(0).write_value(0);
329 trace!("ipc 0"); 326 trace!("ipc 0");
330 } 327 }
331 328
332 if ipc.events_receive[2].read().bits() != 0 { 329 if ipc.events_receive(2).read() != 0 {
333 ipc.events_receive[2].reset(); 330 ipc.events_receive(2).write_value(0);
334 trace!("ipc 2"); 331 trace!("ipc 2");
335 332
336 if !self.init { 333 if !self.init {
@@ -353,8 +350,8 @@ impl StateInner {
353 } 350 }
354 } 351 }
355 352
356 if ipc.events_receive[4].read().bits() != 0 { 353 if ipc.events_receive(4).read() != 0 {
357 ipc.events_receive[4].reset(); 354 ipc.events_receive(4).write_value(0);
358 trace!("ipc 4"); 355 trace!("ipc 4");
359 356
360 loop { 357 loop {
@@ -368,13 +365,13 @@ impl StateInner {
368 } 365 }
369 } 366 }
370 367
371 if ipc.events_receive[6].read().bits() != 0 { 368 if ipc.events_receive(6).read() != 0 {
372 ipc.events_receive[6].reset(); 369 ipc.events_receive(6).write_value(0);
373 trace!("ipc 6"); 370 trace!("ipc 6");
374 } 371 }
375 372
376 if ipc.events_receive[7].read().bits() != 0 { 373 if ipc.events_receive(7).read() != 0 {
377 ipc.events_receive[7].reset(); 374 ipc.events_receive(7).write_value(0);
378 trace!("ipc 7: trace"); 375 trace!("ipc 7: trace");
379 376
380 let msg = unsafe { addr_of!((*self.cb).trace.rx_state).read_volatile() }; 377 let msg = unsafe { addr_of!((*self.cb).trace.rx_state).read_volatile() };
@@ -437,13 +434,12 @@ impl StateInner {
437 } 434 }
438 } 435 }
439 436
440 ipc.intenset.write(|w| { 437 ipc.intenset().write(|w| {
441 w.receive0().set_bit(); 438 w.set_receive0(true);
442 w.receive2().set_bit(); 439 w.set_receive2(true);
443 w.receive4().set_bit(); 440 w.set_receive4(true);
444 w.receive6().set_bit(); 441 w.set_receive6(true);
445 w.receive7().set_bit(); 442 w.set_receive7(true);
446 w
447 }); 443 });
448 } 444 }
449 445
@@ -546,8 +542,8 @@ impl StateInner {
546 unsafe { addr_of_mut!((*list_item).state).write_volatile((self.tx_seq_no as u32) << 16 | 0x01) } 542 unsafe { addr_of_mut!((*list_item).state).write_volatile((self.tx_seq_no as u32) << 16 | 0x01) }
547 self.tx_seq_no = self.tx_seq_no.wrapping_add(1); 543 self.tx_seq_no = self.tx_seq_no.wrapping_add(1);
548 544
549 let ipc = unsafe { &*pac::IPC_NS::ptr() }; 545 let ipc = pac::IPC_NS;
550 ipc.tasks_send[ipc_ch].write(|w| unsafe { w.bits(1) }); 546 ipc.tasks_send(ipc_ch).write_value(1);
551 Ok(()) 547 Ok(())
552 } 548 }
553 549