diff --git a/demo-app/src/main.rs b/demo-app/src/main.rs index 12e1cae..32b8c40 100644 --- a/demo-app/src/main.rs +++ b/demo-app/src/main.rs @@ -19,9 +19,12 @@ const DEMO_STACK_SIZE: usize = 1024; #[no_mangle] extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void) { - static mut THREAD_0: MaybeUninit = MaybeUninit::uninit(); - static mut THREAD_1: MaybeUninit = MaybeUninit::uninit(); + static mut THREAD0: MaybeUninit = MaybeUninit::uninit(); + const THREAD0_NAME: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"thread0\0") }; + static mut THREAD1: MaybeUninit = MaybeUninit::uninit(); + const THREAD1_NAME: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"thread1\0") }; static mut BYTE_POOL: MaybeUninit = 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()..."); @@ -29,10 +32,9 @@ extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void // wil hold on to in the object, so it must have static lifetime. So we // cast-away-const on a static string slice to appease the API. unsafe { - let pool_name = CStr::from_bytes_with_nul(b"byte-pool0\0").unwrap(); threadx_sys::_tx_byte_pool_create( BYTE_POOL.as_mut_ptr(), - pool_name.as_ptr() as *mut threadx_sys::CHAR, + BYTE_POOL_NAME.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, ); @@ -44,10 +46,9 @@ extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void threadx_sys::TX_NO_WAIT, ); defmt::println!("Stack allocated @ {:08x}", pointer); - let thread_name = CStr::from_bytes_with_nul(b"thread0\0").unwrap(); threadx_sys::_tx_thread_create( - THREAD_0.as_mut_ptr(), - thread_name.as_ptr() as *mut threadx_sys::CHAR, + THREAD0.as_mut_ptr(), + THREAD0_NAME.as_ptr() as *mut threadx_sys::CHAR, Some(my_thread), 0x12345678, pointer, @@ -67,10 +68,9 @@ extern "C" fn tx_application_define(_first_unused_memory: *mut core::ffi::c_void threadx_sys::TX_NO_WAIT, ); defmt::println!("Stack allocated @ {:08x}", pointer); - let thread_name = CStr::from_bytes_with_nul(b"thread1\0").unwrap(); threadx_sys::_tx_thread_create( - THREAD_1.as_mut_ptr(), - thread_name.as_ptr() as *mut threadx_sys::CHAR, + THREAD1.as_mut_ptr(), + THREAD1_NAME.as_ptr() as *mut threadx_sys::CHAR, Some(my_thread), 0xAABBCCDD, pointer,