diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fa277d9..ea72b445 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,9 @@ jobs: RUSTFLAGS: -D warnings # Warnings disabled only in CI steps: - name: Clone - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry @@ -39,6 +39,7 @@ jobs: # run: cargo test #- name: Clippy # run: cargo clippy -- -Dwarnings + freertos-rust-stable: name: Build freertos-rust using stable runs-on: ubuntu-latest @@ -46,9 +47,9 @@ jobs: # RUSTFLAGS: -D warnings # Warnings disabled only in CI steps: - name: Clone - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry @@ -60,31 +61,37 @@ jobs: uses: dtolnay/rust-toolchain@stable - name: Build run: cargo build --verbose --no-default-features --features=sync,time,hooks,interrupt --package freertos-rust # Don't build the whole workspace because the examples use nightly features which will fail the build + freertos-rust-examples: name: Build examples - runs-on: ubuntu-latest strategy: matrix: include: - #- example: win - # target: x86_64-pc-windows-gnu - #- example: linux - # target: x86_64-unknown-linux-gnu + - example: win + target: x86_64-pc-windows-msvc + os: windows-latest + - example: linux + target: x86_64-unknown-linux-gnu + os: ubuntu-latest - example: stm32-cortex-m3 target: thumbv7m-none-eabi + os: ubuntu-latest - example: stm32-cortex-m4-blackpill target: thumbv7em-none-eabihf - #- example: nrf9160 - # target: thumbv8m.main-none-eabihf + os: ubuntu-latest + - example: nrf9160 + target: thumbv8m.main-none-eabihf + os: ubuntu-latest + runs-on: ${{ matrix.os }} #env: # RUSTFLAGS: -D warnings # Warnings disabled only in CI steps: - name: Clone - uses: actions/checkout@v3 + uses: actions/checkout@v6 with: submodules: recursive - name: Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.cargo/registry @@ -97,6 +104,7 @@ jobs: with: targets: ${{ matrix.target }} - name: Install cross deps + if: matrix.os == 'ubuntu-latest' run: | case ${{ matrix.target }} in "x86_64-pc-windows-gnu") diff --git a/freertos-rust-examples/Cargo.toml b/freertos-rust-examples/Cargo.toml index ab9cb2fa..299a574c 100644 --- a/freertos-rust-examples/Cargo.toml +++ b/freertos-rust-examples/Cargo.toml @@ -12,22 +12,24 @@ repository = "https://github.com/lobaro/FreeRTOS-rust" [dependencies] freertos-rust = {path = "../freertos-rust"} -[target.'cfg(target_arch = "arm")'.dependencies] -cortex-m = "0.7" -cortex-m-rt = "0.7" - # Example: stm32-cortex-m3 [target.thumbv7m-none-eabi.dependencies] +cortex-m = "0.7" +cortex-m-rt = "0.7" stm32f1xx-hal = {version = "0.10", features = ["rt", "stm32f103", "medium"]} # Example: stm32-cortex-m4-blackpill [target.thumbv7em-none-eabihf.dependencies] +cortex-m = "0.7" +cortex-m-rt = "0.7" embedded-hal = "1.0" stm32f4xx-hal = {version = "0.22", features = ["stm32f411"]} # Example: nrf9160 [target."thumbv8m.main-none-eabihf".dependencies] -nrf9160-pac = "0.2.1" +cortex-m = "0.7" +cortex-m-rt = "0.7" +nrf9160-pac = {version = "0.12", features = ["rt"]} # Example: win [target.x86_64-pc-windows-gnu.dependencies] diff --git a/freertos-rust-examples/examples/linux/FreeRTOSConfig.h b/freertos-rust-examples/examples/linux/FreeRTOSConfig.h index 1ae9a639..ad7d7de6 100644 --- a/freertos-rust-examples/examples/linux/FreeRTOSConfig.h +++ b/freertos-rust-examples/examples/linux/FreeRTOSConfig.h @@ -148,9 +148,11 @@ extern void vAssertCalled( const char * const pcFileName, unsigned long ulLine ) #define TRACE_EXIT_CRITICAL_SECTION() portEXIT_CRITICAL() /*#include "trcKernelPort.h" */ +#define portYIELD_FROM_ISR( x ) ( void ) x + #ifdef __cplusplus } #endif -#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file +#endif /* FREERTOS_CONFIG_H */ diff --git a/freertos-rust-examples/examples/linux/main.rs b/freertos-rust-examples/examples/linux/main.rs index 5703d7e8..a60b417f 100644 --- a/freertos-rust-examples/examples/linux/main.rs +++ b/freertos-rust-examples/examples/linux/main.rs @@ -8,9 +8,7 @@ fn main() { let x = Box::new(15); println!("Boxed int '{}' (allocator test)", x); - unsafe { - FREERTOS_HOOKS.set_on_assert(|| { println!("Assert hook called") }); - } + FREERTOS_HOOKS.set_on_assert(|| { println!("Assert hook called") }).unwrap(); //println!("Calling assert ..."); //FreeRtosUtils::invoke_assert(); diff --git a/freertos-rust-examples/examples/nrf9160/main.rs b/freertos-rust-examples/examples/nrf9160/main.rs index 1fee3e47..abd7d736 100644 --- a/freertos-rust-examples/examples/nrf9160/main.rs +++ b/freertos-rust-examples/examples/nrf9160/main.rs @@ -1,8 +1,7 @@ #![no_std] #![no_main] -// For allocator -#![feature(lang_items)] -#![feature(alloc_error_handler)] +#![allow(dead_code)] +#![allow(unused)] use cortex_m_rt::{entry, exception, ExceptionFrame}; @@ -11,18 +10,10 @@ use cortex_m::asm; use core::panic::PanicInfo; use freertos_rust::*; -use core::alloc::Layout; #[global_allocator] static GLOBAL: FreeRtosAllocator = FreeRtosAllocator; -// define what happens in an Out Of Memory (OOM) condition -#[alloc_error_handler] -fn alloc_error(_layout: Layout) -> ! { - asm::bkpt(); - loop {} -} - #[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop {} @@ -30,7 +21,7 @@ fn panic(_info: &PanicInfo) -> ! { #[exception] -unsafe fn DefaultHandler(irqn: i16) { +unsafe fn DefaultHandler(_irqn: i16) { do_blink(); // custom default handler // irqn is negative for Cortex-M exceptions @@ -41,7 +32,8 @@ unsafe fn DefaultHandler(irqn: i16) { #[exception] -fn HardFault(_ef: &ExceptionFrame) -> ! { +unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { + asm::bkpt(); do_blink(); loop {} } @@ -95,14 +87,18 @@ fn test_function(arg: i32) -> i32 { // FreeRTOS handler +#[allow(non_snake_case)] #[no_mangle] fn vApplicationMallocFailedHook() {} +#[allow(non_snake_case)] #[no_mangle] fn vApplicationIdleHook() {} +#[allow(non_snake_case)] #[no_mangle] fn vApplicationStackOverflowHook(pxTask: FreeRtosTaskHandle, pcTaskName: FreeRtosCharPtr) {} +#[allow(non_snake_case)] #[no_mangle] -fn vApplicationTickHook() {} \ No newline at end of file +fn vApplicationTickHook() {} diff --git a/freertos-rust-examples/examples/win/main.rs b/freertos-rust-examples/examples/win/main.rs index a0526564..27adffa4 100644 --- a/freertos-rust-examples/examples/win/main.rs +++ b/freertos-rust-examples/examples/win/main.rs @@ -8,9 +8,7 @@ fn main() { let x = Box::new(15); println!("Boxed int '{}' (allocator test)", x); - unsafe { - FREERTOS_HOOKS.set_on_assert(|| { println!("Assert hook called") }); - } + FREERTOS_HOOKS.set_on_assert(|| { println!("Assert hook called") }).unwrap(); //println!("Calling assert ..."); //FreeRtosUtils::invoke_assert(); @@ -29,9 +27,6 @@ fn main() { // println!("Free Memory: {}!", free); println!("Starting scheduler"); FreeRtosUtils::start_scheduler(); - loop { - println!("Loop forever!"); - } } #[test] diff --git a/freertos-rust/src/freertos/ports/arm/hooks.c b/freertos-rust/src/freertos/ports/arm/hooks.c deleted file mode 100644 index 0f783e95..00000000 --- a/freertos-rust/src/freertos/ports/arm/hooks.c +++ /dev/null @@ -1,159 +0,0 @@ -/* FreeRTOS kernel includes. */ -#include "FreeRTOS.h" -#include "task.h" - -/* This project provides two demo applications. A simple blinky style demo -application, and a more comprehensive test and demo application. The -mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two. - -If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is 1 then the blinky demo will be built. -The blinky demo is implemented and described in main_blinky.c. - -If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 then the comprehensive test and -demo application will be built. The comprehensive test and demo application is -implemented and described in main_full.c. */ -#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1 - -/* This demo uses heap_5.c, and these constants define the sizes of the regions -that make up the total heap. heap_5 is only used for test and example purposes -as this demo could easily create one large heap region instead of multiple -smaller heap regions - in which case heap_4.c would be the more appropriate -choice. See http://www.freertos.org/a00111.html for an explanation. */ -#define mainREGION_1_SIZE 8201 -#define mainREGION_2_SIZE 29905 -#define mainREGION_3_SIZE 7607 - -/*-----------------------------------------------------------*/ - - -/* - * Prototypes for the standard FreeRTOS application hook (callback) functions - * implemented within this file. See http://www.freertos.org/a00016.html . - */ -void vApplicationMallocFailedHook( void ); -void vApplicationIdleHook( void ); -void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ); -void vApplicationTickHook( void ); -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ); -void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ); - -/*-----------------------------------------------------------*/ - -/* When configSUPPORT_STATIC_ALLOCATION is set to 1 the application writer can -use a callback function to optionally provide the memory required by the idle -and timer tasks. This is the stack that will be used by the timer task. It is -declared here, as a global, so it can be checked by a test that is implemented -in a different file. */ -StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; - -void vApplicationMallocFailedHook( void ) -{ - /* vApplicationMallocFailedHook() will only be called if - configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook - function that will get called if a call to pvPortMalloc() fails. - pvPortMalloc() is called internally by the kernel whenever a task, queue, - timer or semaphore is created. It is also called by various parts of the - demo application. If heap_1.c, heap_2.c or heap_4.c is being used, then the - size of the heap available to pvPortMalloc() is defined by - configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() - API function can be used to query the size of free heap space that remains - (although it does not provide information on how the remaining heap might be - fragmented). See http://www.freertos.org/a00111.html for more - information. */ - configASSERT(1); -} -/*-----------------------------------------------------------*/ - -void vApplicationIdleHook( void ) -{ - /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set - to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle - task. It is essential that code added to this hook function never attempts - to block in any way (for example, call xQueueReceive() with a block time - specified, or call vTaskDelay()). If application tasks make use of the - vTaskDelete() API function to delete themselves then it is also important - that vApplicationIdleHook() is permitted to return to its calling function, - because it is the responsibility of the idle task to clean up memory - allocated by the kernel to any task that has since deleted itself. */ -} -/*-----------------------------------------------------------*/ - -void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) -{ - ( void ) pcTaskName; - ( void ) pxTask; - - /* Run time stack overflow checking is performed if - configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook - function is called if a stack overflow is detected. This function is - provided as an example only as stack overflow checking does not function - when running the FreeRTOS Windows port. */ - configASSERT(1); -} -/*-----------------------------------------------------------*/ - -void vApplicationTickHook( void ) -{ - /* This function will be called by each tick interrupt if - configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be - added here, but the tick hook is called from an interrupt context, so - code must not attempt to block, and only the interrupt safe FreeRTOS API - functions can be used (those that end in FromISR()). */ -} -/*-----------------------------------------------------------*/ - -void vApplicationDaemonTaskStartupHook( void ) -{ - /* This function will be called once only, when the daemon task starts to - execute (sometimes called the timer task). This is useful if the - application includes initialisation code that would benefit from executing - after the scheduler has been started. */ -} -/*-----------------------------------------------------------*/ - -/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an -implementation of vApplicationGetIdleTaskMemory() to provide the memory that is -used by the Idle task. */ -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) -{ -/* If the buffers to be provided to the Idle task are declared inside this -function then they must be declared static - otherwise they will be allocated on -the stack and so not exists after this function exits. */ - static StaticTask_t xIdleTaskTCB; - static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; - - /* Pass out a pointer to the StaticTask_t structure in which the Idle task's - state will be stored. */ - *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; - - /* Pass out the array that will be used as the Idle task's stack. */ - *ppxIdleTaskStackBuffer = uxIdleTaskStack; - - /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. - Note that, as the array is necessarily of type StackType_t, - configMINIMAL_STACK_SIZE is specified in words, not bytes. */ - *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; -} -/*-----------------------------------------------------------*/ -/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the -application must provide an implementation of vApplicationGetTimerTaskMemory() -to provide the memory that is used by the Timer service task. */ -void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) -{ -/* If the buffers to be provided to the Timer task are declared inside this -function then they must be declared static - otherwise they will be allocated on -the stack and so not exists after this function exits. */ - static StaticTask_t xTimerTaskTCB; - - /* Pass out a pointer to the StaticTask_t structure in which the Timer - task's state will be stored. */ - *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; - - /* Pass out the array that will be used as the Timer task's stack. */ - *ppxTimerTaskStackBuffer = uxTimerTaskStack; - - /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. - Note that, as the array is necessarily of type StackType_t, - configMINIMAL_STACK_SIZE is specified in words, not bytes. */ - *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; -} diff --git a/freertos-rust/src/hooks.rs b/freertos-rust/src/hooks.rs index d4ccdac3..dd1155d6 100644 --- a/freertos-rust/src/hooks.rs +++ b/freertos-rust/src/hooks.rs @@ -1,5 +1,4 @@ use crate::base::*; -use crate::prelude::v1::String; use crate::utils::*; use core::cell::OnceCell; @@ -11,12 +10,12 @@ pub struct FreeRtosHooks { } impl FreeRtosHooks { - pub fn set_on_assert(&mut self, c: Callback) -> Result<(), Callback> { + pub fn set_on_assert(&self, c: Callback) -> Result<(), Callback> { self.on_assert.set(c) } fn do_on_assert(&self) { - if let Some (cb) = self.on_assert.get() { + if let Some(cb) = self.on_assert.get() { cb() } } @@ -26,15 +25,14 @@ impl FreeRtosHooks { // kernel has asserted, both being single threaded situations. unsafe impl Sync for FreeRtosHooks {} -pub static FREERTOS_HOOKS: FreeRtosHooks = FreeRtosHooks { on_assert: OnceCell::new() }; +pub static FREERTOS_HOOKS: FreeRtosHooks = FreeRtosHooks { + on_assert: OnceCell::new(), +}; #[allow(unused_doc_comments)] #[no_mangle] pub extern "C" fn vAssertCalled(file_name_ptr: FreeRtosCharPtr, line: FreeRtosUBaseType) { - let file_name: String; - unsafe { - file_name = str_from_c_string(file_name_ptr).unwrap(); - } + let file_name = unsafe { str_from_c_string(file_name_ptr).unwrap() }; FREERTOS_HOOKS.do_on_assert(); diff --git a/freertos-rust/src/portmacro.h b/freertos-rust/src/portmacro.h deleted file mode 100644 index a295af87..00000000 --- a/freertos-rust/src/portmacro.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * FreeRTOS Kernel V10.3.0 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ - -#ifndef PORTMACRO_H -#define PORTMACRO_H - -// Do not include windows deps -//#include -//#include - -/****************************************************************************** - Defines -******************************************************************************/ -/* Type definitions. */ -#define portCHAR char -#define portFLOAT float -#define portDOUBLE double -#define portLONG long -#define portSHORT short -#define portSTACK_TYPE size_t -#define portBASE_TYPE long -#define portPOINTER_SIZE_TYPE size_t - -typedef portSTACK_TYPE StackType_t; -typedef long BaseType_t; -typedef unsigned long UBaseType_t; - - -#if( configUSE_16_BIT_TICKS == 1 ) - typedef uint16_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffff -#else - typedef uint32_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffffffffUL - - /* 32/64-bit tick type on a 32/64-bit architecture, so reads of the tick - count do not need to be guarded with a critical section. */ - #define portTICK_TYPE_IS_ATOMIC 1 -#endif - -/* Hardware specifics. */ -#define portSTACK_GROWTH ( -1 ) -#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) -#define portINLINE __inline - -#if defined( __x86_64__) || defined( _M_X64 ) - #define portBYTE_ALIGNMENT 8 -#else - #define portBYTE_ALIGNMENT 4 -#endif - -#define portYIELD() vPortGenerateSimulatedInterrupt( portINTERRUPT_YIELD ) - - -extern volatile BaseType_t xInsideInterrupt; -#define portSOFTWARE_BARRIER() while( xInsideInterrupt != pdFALSE ) - - -/* Simulated interrupts return pdFALSE if no context switch should be performed, -or a non-zero number if a context switch should be performed. */ -#define portYIELD_FROM_ISR( x ) ( void ) x -#define portEND_SWITCHING_ISR( x ) portYIELD_FROM_ISR( ( x ) ) - -void vPortCloseRunningThread( void *pvTaskToDelete, volatile BaseType_t *pxPendYield ); -void vPortDeleteThread( void *pvThreadToDelete ); -#define portCLEAN_UP_TCB( pxTCB ) vPortDeleteThread( pxTCB ) -#define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) ) -#define portDISABLE_INTERRUPTS() vPortEnterCritical() -#define portENABLE_INTERRUPTS() vPortExitCritical() - -/* Critical section handling. */ -void vPortEnterCritical( void ); -void vPortExitCritical( void ); - -#define portENTER_CRITICAL() vPortEnterCritical() -#define portEXIT_CRITICAL() vPortExitCritical() - -#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION - #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 -#endif - -#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 - - /* Check the configuration. */ - #if( configMAX_PRIORITIES > 32 ) - #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice. - #endif - - /* Store/clear the ready priorities in a bit map. */ - #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) - #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) - - - /*-----------------------------------------------------------*/ - - #ifdef __GNUC__ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \ - __asm volatile( "bsr %1, %0\n\t" \ - :"=r"(uxTopPriority) : "rm"(uxReadyPriorities) : "cc" ) - #else - /* BitScanReverse returns the bit position of the most significant '1' - in the word. */ - #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) ) - #endif /* __GNUC__ */ - -#endif /* taskRECORD_READY_PRIORITY */ - -#ifndef __GNUC__ - __pragma( warning( disable:4211 ) ) /* Nonstandard extension used, as extern is only nonstandard to MSVC. */ -#endif - - -/* Task function macros as described on the FreeRTOS.org WEB site. */ -#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters ) -#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters ) - -#define portINTERRUPT_YIELD ( 0UL ) -#define portINTERRUPT_TICK ( 1UL ) - -/* - * Raise a simulated interrupt represented by the bit mask in ulInterruptMask. - * Each bit can be used to represent an individual interrupt - with the first - * two bits being used for the Yield and Tick interrupts respectively. -*/ -void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber ); - -/* - * Install an interrupt handler to be called by the simulated interrupt handler - * thread. The interrupt number must be above any used by the kernel itself - * (at the time of writing the kernel was using interrupt numbers 0, 1, and 2 - * as defined above). The number must also be lower than 32. - * - * Interrupt handler functions must return a non-zero value if executing the - * handler resulted in a task switch being required. - */ -void vPortSetInterruptHandler( uint32_t ulInterruptNumber, uint32_t (*pvHandler)( void ) ); - -#endif - diff --git a/freertos-rust/src/task.rs b/freertos-rust/src/task.rs index 8bf5a224..e83156b0 100644 --- a/freertos-rust/src/task.rs +++ b/freertos-rust/src/task.rs @@ -210,7 +210,7 @@ impl Task { let name_ptr = freertos_rs_task_get_name(self.task_handle); let name = str_from_c_string(name_ptr); if let Ok(name) = name { - return Ok(name); + return Ok(name.to_string()); } Err(()) @@ -463,7 +463,7 @@ impl FreeRtosUtils { task_handle: t.handle, }, name: unsafe { str_from_c_string(t.task_name) } - .unwrap_or_else(|_| String::from("?")), + .unwrap_or_else(|_| "?").to_string(), task_number: t.task_number, task_state: t.task_state, current_priority: TaskPriority(t.current_priority as u8), diff --git a/freertos-rust/src/utils.rs b/freertos-rust/src/utils.rs index 1501a207..e5e67da3 100644 --- a/freertos-rust/src/utils.rs +++ b/freertos-rust/src/utils.rs @@ -2,6 +2,8 @@ use crate::base::*; use crate::prelude::v1::*; use crate::shim::*; +use core::ffi::CStr; + #[derive(Debug, Copy, Clone)] pub struct TypeSizeError { pub id: usize, @@ -54,19 +56,8 @@ pub fn shim_sanity_check() -> Result<(), TypeSizeError> { /// /// `str` must be a pointer to the beginning of nul-terminated sequence of bytes. #[cfg(any(feature = "time", feature = "hooks", feature = "sync"))] -pub unsafe fn str_from_c_string(str: *const u8) -> Result { - let mut buf = Vec::new(); - - let mut p = str; - loop { - if *p == 0 { - break; - } - buf.push(*p); - p = p.offset(1); - } - - match String::from_utf8(buf) { +pub unsafe fn str_from_c_string<'a>(str: *const u8) -> Result<&'a str, FreeRtosError> { + match CStr::from_ptr(str as *const _).to_str() { Ok(s) => Ok(s), Err(_) => Err(FreeRtosError::StringConversionError), }