Skip to content

Commit

Permalink
Use byte_strings crate.
Browse files Browse the repository at this point in the history
Will replace with c"Hello" strings in around Rust 1.77.
  • Loading branch information
jonathanpallant committed Dec 7, 2023
1 parent b2c7178 commit cc4015b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
21 changes: 21 additions & 0 deletions demo-app/Cargo.lock

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

1 change: 1 addition & 0 deletions demo-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
defmt = "0.3.5"
defmt-rtt = "0.4"
threadx-sys = { path = "../threadx-sys" }
byte-strings = "0.3.1"

# optimize code in both profiles
[profile.dev]
Expand Down
12 changes: 5 additions & 7 deletions demo-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#![no_main]
#![no_std]

use core::{ffi::CStr, mem::MaybeUninit};
use core::mem::MaybeUninit;

use byte_strings::c;
use cortex_m_rt::entry;
use defmt_rtt as _;
use nrf52840_hal::prelude::OutputPin;
Expand All @@ -20,11 +21,8 @@ const DEMO_STACK_SIZE: usize = 1024;
#[no_mangle]
extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void) {
static mut THREAD0: MaybeUninit<threadx_sys::TX_THREAD> = MaybeUninit::uninit();
const THREAD0_NAME: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"thread0\0") };
static mut THREAD1: MaybeUninit<threadx_sys::TX_THREAD> = MaybeUninit::uninit();
const THREAD1_NAME: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"thread1\0") };
static mut BYTE_POOL: MaybeUninit<threadx_sys::TX_BYTE_POOL> = MaybeUninit::uninit();
const BYTE_POOL_NAME: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"byte-pool0\0") };
static mut BYTE_POOL_STORAGE: MaybeUninit<[u8; 32768]> = MaybeUninit::uninit();

defmt::println!("In tx_application_define()...");
Expand All @@ -34,7 +32,7 @@ extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void
unsafe {
threadx_sys::_tx_byte_pool_create(
BYTE_POOL.as_mut_ptr(),
BYTE_POOL_NAME.as_ptr() as *mut threadx_sys::CHAR,
c!("byte-pool0").as_ptr() as *mut threadx_sys::CHAR,
BYTE_POOL_STORAGE.as_mut_ptr() as *mut _,
core::mem::size_of_val(&BYTE_POOL_STORAGE) as u32,
);
Expand All @@ -48,7 +46,7 @@ extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void
defmt::println!("Stack allocated @ {:08x}", pointer);
threadx_sys::_tx_thread_create(
THREAD0.as_mut_ptr(),
THREAD0_NAME.as_ptr() as *mut threadx_sys::CHAR,
c!("thread0").as_ptr() as *mut threadx_sys::CHAR,
Some(my_thread),
0x12345678,
pointer,
Expand All @@ -70,7 +68,7 @@ extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void
defmt::println!("Stack allocated @ {:08x}", pointer);
threadx_sys::_tx_thread_create(
THREAD1.as_mut_ptr(),
THREAD1_NAME.as_ptr() as *mut threadx_sys::CHAR,
c!("thread1").as_ptr() as *mut threadx_sys::CHAR,
Some(my_thread),
0xAABBCCDD,
pointer,
Expand Down

0 comments on commit cc4015b

Please sign in to comment.