Skip to content
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

build(deps): bump heapless from 0.7.16 to 0.8.0 #807

Closed
wants to merge 2 commits into from
Closed
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
38 changes: 29 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ log = { version = "0.4", features = ["max_level_trace", "release_max_level_info"
rtt-target = "0.3"
serde = { version = "1.0", features = ["derive"], default-features = false }
serde-json-core = "0.5"
heapless = { version = "0.7.16", features = ["serde"] }
heapless = { version = "0.8.0", features = ["serde"] }
cortex-m-rtic = "1.0"
embedded-hal = "0.2.7"
num_enum = { version = "0.7.1", default-features = false }
Expand Down
50 changes: 22 additions & 28 deletions src/net/data_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
//! of livestreamed data.
use core::mem::MaybeUninit;
use heapless::{
pool::{Box, Init, Pool, Uninit},
box_pool,
pool::boxed::{Box, BoxBlock},
spsc::{Consumer, Producer, Queue},
};
use num_enum::IntoPrimitive;
Expand Down Expand Up @@ -53,13 +54,14 @@
// allocated frame buffer should fit in the queue.
const FRAME_QUEUE_SIZE: usize = FRAME_COUNT * 2;

// Static storage used for a heapless::Pool of frame buffers.
static mut FRAME_DATA: [u8; core::mem::size_of::<u8>()
* FRAME_SIZE
* FRAME_COUNT] = [0; core::mem::size_of::<u8>() * FRAME_SIZE * FRAME_COUNT];

type Frame = [MaybeUninit<u8>; FRAME_SIZE];

box_pool!(FRAME_POOL: Frame);

Check warning on line 59 in src/net/data_stream.rs

View workflow job for this annotation

GitHub Actions / clippy

type `FRAME_POOL` should have an upper camel case name

warning: type `FRAME_POOL` should have an upper camel case name --> src/net/data_stream.rs:59:11 | 59 | box_pool!(FRAME_POOL: Frame); | ^^^^^^^^^^ help: convert the identifier to upper camel case: `FramePool` | = note: `#[warn(non_camel_case_types)]` on by default

// Static storage used for a heapless::Pool of frame buffers.
const BLOCK: BoxBlock<Frame> = BoxBlock::new();

Check warning on line 62 in src/net/data_stream.rs

View workflow job for this annotation

GitHub Actions / clippy

a `const` item should never be interior mutable

warning: a `const` item should never be interior mutable --> src/net/data_stream.rs:62:1 | 62 | const BLOCK: BoxBlock<Frame> = BoxBlock::new(); | -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | make this a static item (maybe with lazy_static) | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const = note: `#[warn(clippy::declare_interior_mutable_const)]` on by default
static mut FRAME_DATA: [BoxBlock<Frame>; FRAME_COUNT] = [BLOCK; FRAME_COUNT];

/// Represents the destination for the UDP stream to send data to.
///
/// # Miniconf
Expand Down Expand Up @@ -129,34 +131,32 @@
.unwrap();
let (producer, consumer) = queue.split();

let frame_pool = cortex_m::singleton!(: Pool<Frame> = Pool::new()).unwrap();

// Note(unsafe): We guarantee that FRAME_DATA is only accessed once in this function.
let memory = unsafe { &mut FRAME_DATA };
frame_pool.grow(memory);
let blocks = unsafe { &mut FRAME_DATA };
for block in blocks {
FRAME_POOL.manage(block);
}

let generator = FrameGenerator::new(producer, frame_pool);
let generator = FrameGenerator::new(producer);

let stream = DataStream::new(stack, consumer, frame_pool);
let stream = DataStream::new(stack, consumer);

(generator, stream)
}

#[derive(Debug)]
struct StreamFrame {
buffer: Box<Frame, Init>,
buffer: Box<FRAME_POOL>,
offset: usize,
batches: u8,
}

impl StreamFrame {
pub fn new(
buffer: Box<Frame, Uninit>,
mut buffer: Box<FRAME_POOL>,
format_id: u8,
sequence_number: u32,
) -> Self {
let mut buffer = buffer.init([MaybeUninit::uninit(); FRAME_SIZE]);

for (byte, buf) in MAGIC
.to_le_bytes()
.iter()
Expand Down Expand Up @@ -197,20 +197,15 @@
/// The data generator for a stream.
pub struct FrameGenerator {
queue: Producer<'static, StreamFrame, FRAME_QUEUE_SIZE>,
pool: &'static Pool<Frame>,
current_frame: Option<StreamFrame>,
sequence_number: u32,
format: u8,
}

impl FrameGenerator {
fn new(
queue: Producer<'static, StreamFrame, FRAME_QUEUE_SIZE>,
pool: &'static Pool<Frame>,
) -> Self {
fn new(queue: Producer<'static, StreamFrame, FRAME_QUEUE_SIZE>) -> Self {
Self {
queue,
pool,
format: StreamFormat::Unknown.into(),
current_frame: None,
sequence_number: 0,
Expand Down Expand Up @@ -242,7 +237,9 @@
self.sequence_number = self.sequence_number.wrapping_add(1);

if self.current_frame.is_none() {
if let Some(buffer) = self.pool.alloc() {
if let Ok(buffer) =
FRAME_POOL.alloc([MaybeUninit::uninit(); FRAME_SIZE])
{
self.current_frame.replace(StreamFrame::new(
buffer,
self.format,
Expand Down Expand Up @@ -276,7 +273,6 @@
stack: NetworkReference,
socket: Option<<NetworkReference as UdpClientStack>::UdpSocket>,
queue: Consumer<'static, StreamFrame, FRAME_QUEUE_SIZE>,
frame_pool: &'static Pool<Frame>,
remote: SocketAddr,
}

Expand All @@ -290,14 +286,12 @@
fn new(
stack: NetworkReference,
consumer: Consumer<'static, StreamFrame, FRAME_QUEUE_SIZE>,
frame_pool: &'static Pool<Frame>,
) -> Self {
Self {
stack,
socket: None,
remote: StreamTarget::default().into(),
queue: consumer,
frame_pool,
}
}

Expand Down Expand Up @@ -350,7 +344,7 @@
if self.open().is_ok() {
// If we just successfully opened the socket, flush old data from queue.
while let Some(frame) = self.queue.dequeue() {
self.frame_pool.free(frame.buffer);
drop(frame.buffer);
}
}
}
Expand All @@ -365,7 +359,7 @@
)
};
self.stack.send(handle, data).ok();
self.frame_pool.free(frame.buffer)
drop(frame.buffer);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ where
// `settings_path` has to be at least as large as `miniconf::mqtt_client::MAX_TOPIC_LENGTH`.
let mut settings_path: String<128> = String::new();
match self.miniconf.handled_update(|path, old, new| {
settings_path = path.into();
settings_path = path.try_into().or(Err("path too long"))?;
*old = new.clone();
Result::<(), &'static str>::Ok(())
Result::<_, &'static str>::Ok(())
}) {
Ok(true) => NetworkState::SettingsChanged(settings_path),
_ => poll_result,
Expand Down
7 changes: 4 additions & 3 deletions src/net/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! sampling frequency. Instead, the raw codes are stored and the telemetry is generated as
//! required immediately before transmission. This ensures that any slower computation required
//! for unit conversion can be off-loaded to lower priority tasks.
use heapless::{String, Vec};
use heapless::String;
use serde::Serialize;

use super::NetworkReference;
Expand Down Expand Up @@ -115,7 +115,8 @@ impl<T: Serialize> TelemetryClient<T> {
>,
prefix: &str,
) -> Self {
let mut telemetry_topic: String<128> = String::from(prefix);
let mut telemetry_topic: String<128> =
String::try_from(prefix).unwrap();
telemetry_topic.push_str("/telemetry").unwrap();

Self {
Expand All @@ -134,7 +135,7 @@ impl<T: Serialize> TelemetryClient<T> {
/// # Args
/// * `telemetry` - The telemetry to report
pub fn publish(&mut self, telemetry: &T) {
let telemetry: Vec<u8, 512> =
let telemetry: serde_json_core::heapless::Vec<u8, 512> =
serde_json_core::to_vec(telemetry).unwrap();
self.mqtt
.client()
Expand Down
Loading