Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Update bbqueue in demo #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion demos/demo-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ publish = false
rubble = { path = "../../rubble", default-features = false }
cortex-m = "0.7.2"
log = "0.4.8"
bbqueue = "0.4.1"
bbqueue = "0.5.1"
12 changes: 6 additions & 6 deletions demos/demo-utils/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Logging-related utilities and adapters.

use bbqueue::{ArrayLength, GrantW, Producer};
use bbqueue::{GrantW, Producer};
use core::{cell::RefCell, fmt};
use cortex_m::interrupt::{self, Mutex};
use log::{Log, Metadata, Record};
Expand Down Expand Up @@ -40,12 +40,12 @@ impl<T: Timer, L: fmt::Write> fmt::Write for StampedLogger<T, L> {
///
/// The sink will panic when the `BBBuffer` doesn't have enough space to the data. This is to ensure
/// that we never block or drop data.
pub struct BbqLogger<'a, N: ArrayLength<u8>> {
pub struct BbqLogger<'a, const N: usize> {
p: Producer<'a, N>,
data_lost: bool,
}

impl<'a, N: ArrayLength<u8>> BbqLogger<'a, N> {
impl<'a, const N: usize> BbqLogger<'a, N> {
pub fn new(p: Producer<'a, N>) -> Self {
Self {
p,
Expand All @@ -54,7 +54,7 @@ impl<'a, N: ArrayLength<u8>> BbqLogger<'a, N> {
}
}

impl<N: ArrayLength<u8>> fmt::Write for BbqLogger<'_, N> {
impl<const N: usize> fmt::Write for BbqLogger<'_, N> {
fn write_str(&mut self, msg: &str) -> fmt::Result {
let mut msg_bytes = msg.as_bytes();
while !msg_bytes.is_empty() {
Expand Down Expand Up @@ -88,12 +88,12 @@ impl<N: ArrayLength<u8>> fmt::Write for BbqLogger<'_, N> {
}

/// Wraps a granted buffer and provides convenience methods to append data and commit
struct GrantedBuffer<'a, N: ArrayLength<u8>> {
struct GrantedBuffer<'a, const N: usize> {
grant: GrantW<'a, N>,
written: usize,
}

impl<'a, N: ArrayLength<u8>> GrantedBuffer<'a, N> {
impl<'a, const N: usize> GrantedBuffer<'a, N> {
pub fn new(grant: GrantW<'a, N>) -> Self {
GrantedBuffer { grant, written: 0 }
}
Expand Down
2 changes: 1 addition & 1 deletion demos/nrf52-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ demo-utils = { path = "../demo-utils" }
cortex-m = "0.7.2"
cortex-m-rtic = { version = "0.5.8", default-features = false, features = ["cortex-m-7"] }
cortex-m-rt = "0.7.0"
bbqueue = "0.4"
bbqueue = "0.5.1"
rtt-target = { version = "0.3.0", features = ["cortex-m"] }
panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] }

Expand Down
14 changes: 7 additions & 7 deletions demos/nrf52-demo/src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#![cfg_attr(not(feature = "log"), allow(unused))]

use bbqueue::{BBBuffer, ConstBBBuffer, Consumer};
use bbqueue::{BBBuffer, Consumer};
use cortex_m::interrupt;
use demo_utils::logging::{BbqLogger, StampedLogger, WriteLogger};
use rubble_nrf5x::timer::StampSource;

#[cfg(feature = "log")]
pub(crate) use bbqueue::consts::U10000 as BufferSize;
pub(crate) const BUFFER_SIZE: usize = 10000;

#[cfg(not(feature = "log"))]
pub(crate) use bbqueue::consts::U1 as BufferSize;
pub(crate) const BUFFER_SIZE: usize = 1;

#[cfg(feature = "log")]
use log::LevelFilter;

type Logger = StampedLogger<StampSource<LogTimer>, BbqLogger<'static, BufferSize>>;
type Logger = StampedLogger<StampSource<LogTimer>, BbqLogger<'static, BUFFER_SIZE>>;

type LogTimer = crate::hal::pac::TIMER0;

/// Stores the global logger used by the `log` crate.
static mut LOGGER: Option<WriteLogger<Logger>> = None;

/// Stores the global BBBuffer for the log queue.
static BUFFER: BBBuffer<BufferSize> = BBBuffer(ConstBBBuffer::new());
static BUFFER: BBBuffer<BUFFER_SIZE> = BBBuffer::<BUFFER_SIZE>::new();

#[cfg(feature = "log")]
pub fn init(timer: StampSource<LogTimer>) -> Consumer<'static, BufferSize> {
pub fn init(timer: StampSource<LogTimer>) -> Consumer<'static, { BUFFER_SIZE }> {
let (tx, log_sink) = BUFFER.try_split().unwrap();
let logger = StampedLogger::new(BbqLogger::new(tx), timer);

Expand All @@ -43,6 +43,6 @@ pub fn init(timer: StampSource<LogTimer>) -> Consumer<'static, BufferSize> {
}

#[cfg(not(feature = "log"))]
pub fn init(timer: StampSource<LogTimer>) -> Consumer<'static, BufferSize> {
pub fn init(timer: StampSource<LogTimer>) -> Consumer<'static, { BUFFER_SIZE }> {
BUFFER.try_split().unwrap().1
}
2 changes: 1 addition & 1 deletion demos/nrf52-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const APP: () = {
ble_r: Responder<AppConfig>,
radio: BleRadio,
log_channel: UpChannel,
log_sink: Consumer<'static, logger::BufferSize>,
log_sink: Consumer<'static, { logger::BUFFER_SIZE }>,
}

#[init(resources = [ble_tx_buf, ble_rx_buf, tx_queue, rx_queue])]
Expand Down