Skip to content

Commit

Permalink
change Ingress to use external provided buffer (#189)
Browse files Browse the repository at this point in the history
* change Ingress to use external provided buffer

* enable portable-atomic critical-section to fix building for thumbv6m-none-eabi

* fixes after merge master

* fix embassy example

* remove generic parameter from ingress buf and rename it to RES_BUF_SIZE
  • Loading branch information
dragonnn authored Jan 30, 2024
1 parent aeac149 commit 8f057c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions atat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ atat_derive = { path = "../atat_derive", version = "^0.21.0", optional = true }
serde_bytes = { version = "0.11.14", default-features = false, optional = true }
heapless-bytes = { version = "0.3.0", optional = true }


nom = { version = "^7.1", default-features = false }

log = { version = "^0.4", default-features = false, optional = true }
Expand All @@ -41,6 +42,7 @@ serde_at = { path = "../serde_at", version = "^0.21.0", features = [
"heapless",
] }
tokio = { version = "1", features = ["macros", "rt"] }
static_cell = { version = "2.0.0" }

[features]
default = ["derive", "bytes"]
Expand Down
23 changes: 13 additions & 10 deletions atat/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,35 @@ pub struct Ingress<
'a,
D: Digester,
Urc: AtatUrc,
const INGRESS_BUF_SIZE: usize,
const RES_BUF_SIZE: usize,
const URC_CAPACITY: usize,
const URC_SUBSCRIBERS: usize,
> {
digester: D,
buf: [u8; INGRESS_BUF_SIZE],
buf: &'a mut [u8],
pos: usize,
res_slot: &'a ResponseSlot<INGRESS_BUF_SIZE>,
res_slot: &'a ResponseSlot<RES_BUF_SIZE>,
urc_publisher: UrcPublisher<'a, Urc, URC_CAPACITY, URC_SUBSCRIBERS>,
}

impl<
'a,
D: Digester,
Urc: AtatUrc,
const INGRESS_BUF_SIZE: usize,
const RES_BUF_SIZE: usize,
const URC_CAPACITY: usize,
const URC_SUBSCRIBERS: usize,
> Ingress<'a, D, Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>
> Ingress<'a, D, Urc, RES_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>
{
pub fn new(
digester: D,
res_slot: &'a ResponseSlot<INGRESS_BUF_SIZE>,
buf: &'a mut [u8],
res_slot: &'a ResponseSlot<RES_BUF_SIZE>,
urc_channel: &'a UrcChannel<Urc, URC_CAPACITY, URC_SUBSCRIBERS>,
) -> Self {

Check warning on line 107 in atat/src/ingress.rs

View workflow job for this annotation

GitHub Actions / clippy

docs for function which may panic missing `# Panics` section

warning: docs for function which may panic missing `# Panics` section --> atat/src/ingress.rs:102:5 | 102 | / pub fn new( 103 | | digester: D, 104 | | buf: &'a mut [u8], 105 | | res_slot: &'a ResponseSlot<RES_BUF_SIZE>, 106 | | urc_channel: &'a UrcChannel<Urc, URC_CAPACITY, URC_SUBSCRIBERS>, 107 | | ) -> Self { | |_____________^ | note: first possible panic found here --> atat/src/ingress.rs:113:28 | 113 | urc_publisher: urc_channel.0.publisher().unwrap(), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc = note: `-W clippy::missing-panics-doc` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::missing_panics_doc)]`
Self {
digester,
buf: [0; INGRESS_BUF_SIZE],
buf,
pos: 0,
res_slot,
urc_publisher: urc_channel.0.publisher().unwrap(),
Expand All @@ -117,10 +118,10 @@ impl<
impl<
D: Digester,
Urc: AtatUrc,
const INGRESS_BUF_SIZE: usize,
const RES_BUF_SIZE: usize,
const URC_CAPACITY: usize,
const URC_SUBSCRIBERS: usize,
> AtatIngress for Ingress<'_, D, Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>
> AtatIngress for Ingress<'_, D, Urc, RES_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>
{
fn write_buf(&mut self) -> &mut [u8] {
&mut self.buf[self.pos..]
Expand Down Expand Up @@ -319,8 +320,10 @@ mod tests {
fn advance_can_processes_multiple_digest_results() {
let res_slot = ResponseSlot::<100>::new();
let urc_channel = UrcChannel::<Urc, 10, 1>::new();
let mut buf = [0; 100];

let mut ingress: Ingress<_, Urc, 100, 10, 1> =
Ingress::new(AtDigester::<Urc>::new(), &res_slot, &urc_channel);
Ingress::new(AtDigester::<Urc>::new(), &mut buf, &res_slot, &urc_channel);

let mut sub = urc_channel.subscribe().unwrap();

Expand Down
2 changes: 2 additions & 0 deletions examples/src/bin/embassy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async fn main(spawner: Spawner) {

let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0);

static INGRESS_BUF: StaticCell<[u8; INGRESS_BUF_SIZE]> = StaticCell::new();
static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
static RX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
let uart = BufferedUart::new(
Expand All @@ -46,6 +47,7 @@ async fn main(spawner: Spawner) {
static URC_CHANNEL: UrcChannel<common::Urc, URC_CAPACITY, URC_SUBSCRIBERS> = UrcChannel::new();
let ingress = Ingress::new(
DefaultDigester::<common::Urc>::default(),
INGRESS_BUF.init([0; INGRESS_BUF_SIZE]),
&RES_SLOT,
&URC_CHANNEL,
);
Expand Down
12 changes: 11 additions & 1 deletion examples/src/bin/std-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,26 @@ const INGRESS_BUF_SIZE: usize = 1024;
const URC_CAPACITY: usize = 128;
const URC_SUBSCRIBERS: usize = 3;

macro_rules! singleton {

Check warning on line 16 in examples/src/bin/std-tokio.rs

View workflow job for this annotation

GitHub Actions / Build (x86_64-unknown-linux-gnu, derive)

unused macro definition: `singleton`

Check warning on line 16 in examples/src/bin/std-tokio.rs

View workflow job for this annotation

GitHub Actions / Build (x86_64-unknown-linux-gnu)

unused macro definition: `singleton`

Check warning on line 16 in examples/src/bin/std-tokio.rs

View workflow job for this annotation

GitHub Actions / Test

unused macro definition: `singleton`
($val:expr) => {{
type T = impl Sized;
static STATIC_CELL: StaticCell<T> = StaticCell::new();
let (x,) = STATIC_CELL.init(($val,));
x
}};
}

#[tokio::main]
async fn main() -> ! {
env_logger::init();

let (reader, writer) = SerialStream::pair().expect("Failed to create serial pair");

static INGRESS_BUF: StaticCell<[u8; INGRESS_BUF_SIZE]> = StaticCell::new();
static RES_SLOT: ResponseSlot<INGRESS_BUF_SIZE> = ResponseSlot::new();
static URC_CHANNEL: UrcChannel<common::Urc, URC_CAPACITY, URC_SUBSCRIBERS> = UrcChannel::new();
let ingress = Ingress::new(
DefaultDigester::<common::Urc>::default(),
INGRESS_BUF.init([0; INGRESS_BUF_SIZE]),
&RES_SLOT,
&URC_CHANNEL,
);
Expand Down

0 comments on commit 8f057c5

Please sign in to comment.