Skip to content

Commit dc74aec

Browse files
committed
Updated to nrfxlib v1.4.2
1 parent a93bddc commit dc74aec

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ repository = "https://github.com/42-technology-ltd/nrfxlib"
99
description = "Rust driver for the LTE stack on the Nordic nRF9160"
1010

1111
[dependencies]
12-
nrfxlib-sys = "1.2.0"
1312
nrf9160-pac = "0.2.1"
1413
cortex-m = "0.6"
1514
heapless = "0.5"
1615
log = "0.4"
16+
17+
# Note: when v1.4.2 is upstreamed we can merge this again.
18+
# nrfxlib-sys = "1.2.0"
19+
nrfxlib-sys = { git = "https://github.com/Wassasin/nrfxlib-sys", branch = "nrfxlib-v1.4.2" }

src/at.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct AtSocket(Socket);
5353
impl AtSocket {
5454
/// Create a new AT socket.
5555
pub fn new() -> Result<AtSocket, Error> {
56-
let skt = Socket::new(SocketDomain::Lte, SocketType::None, SocketProtocol::At)?;
56+
let skt = Socket::new(SocketDomain::Lte, SocketType::Datagram, SocketProtocol::At)?;
5757
Ok(AtSocket(skt))
5858
}
5959

src/lib.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ pub use ffi::get_last_error;
5353
pub use raw::{poll, PollEntry, PollFlags, PollResult, Pollable};
5454

5555
use log::{debug, trace};
56-
use nrfxlib_sys as sys;
5756
use nrf9160_pac as cpu;
57+
use nrfxlib_sys as sys;
5858

5959
//******************************************************************************
6060
// Types
@@ -132,12 +132,28 @@ pub enum Error {
132132
//******************************************************************************
133133

134134
/// Start the BSD library
135-
pub fn init() {
135+
pub fn init(trace_on: bool) -> Result<(), Error> {
136136
debug!("nrfxlib init");
137-
unsafe {
138-
sys::bsd_init();
137+
let bsd_memory_size = if trace_on {
138+
sys::BSD_RESERVED_MEMORY_SIZE
139+
} else {
140+
sys::BSD_RESERVED_MEMORY_SIZE_TRACE_DISABLED
141+
};
142+
143+
let result = unsafe {
144+
sys::bsd_init(&sys::bsd_init_params_t {
145+
trace_on,
146+
bsd_memory_address: sys::BSD_RESERVED_MEMORY_ADDRESS,
147+
bsd_memory_size,
148+
})
149+
};
150+
151+
if result < 0 {
152+
Err(Error::Nordic("init", result, ffi::get_last_error()))
153+
} else {
154+
trace!("nrfxlib init complete");
155+
Ok(())
139156
}
140-
trace!("nrfxlib init complete");
141157
}
142158

143159
/// Stop the BSD library

src/raw.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ pub(crate) enum SocketDomain {
7171
/// The type of socket (Stream, Datagram, or neither)
7272
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
7373
pub(crate) enum SocketType {
74-
/// Used with `SocketDomain::Lte`
75-
None,
7674
/// Used with `SocketDomain::Inet` for TCP and TLS streams
7775
Stream,
7876
/// Used with UDP sockets, and for GPS
@@ -323,7 +321,6 @@ impl Into<i32> for SocketType {
323321
fn into(self) -> i32 {
324322
use SocketType::*;
325323
match self {
326-
None => 0,
327324
Stream => sys::NRF_SOCK_STREAM as i32,
328325
Datagram => sys::NRF_SOCK_DGRAM as i32,
329326
}
@@ -434,14 +431,14 @@ pub fn poll(poll_list: &mut [PollEntry], timeout_ms: u16) -> Result<i32, Error>
434431
}
435432

436433
let mut poll_fds: [sys::nrf_pollfd; MAX_SOCKETS_POLL] = [sys::nrf_pollfd {
437-
handle: 0,
438-
requested: 0,
439-
returned: 0,
434+
fd: 0,
435+
events: 0,
436+
revents: 0,
440437
}; MAX_SOCKETS_POLL];
441438

442439
for (poll_entry, pollfd) in poll_list.iter_mut().zip(poll_fds.iter_mut()) {
443-
pollfd.handle = poll_entry.socket.get_fd();
444-
pollfd.requested = poll_entry.flags as i16;
440+
pollfd.fd = poll_entry.socket.get_fd();
441+
pollfd.events = poll_entry.flags as i16;
445442
count += 1;
446443
}
447444

@@ -452,7 +449,7 @@ pub fn poll(poll_list: &mut [PollEntry], timeout_ms: u16) -> Result<i32, Error>
452449
0 => Ok(0),
453450
n => {
454451
for (poll_entry, pollfd) in poll_list.iter_mut().zip(poll_fds.iter()) {
455-
poll_entry.result = PollResult(pollfd.returned as u32);
452+
poll_entry.result = PollResult(pollfd.revents as u32);
456453
}
457454
Ok(n)
458455
}

0 commit comments

Comments
 (0)