diff --git a/mission/freeRTOS_rust_helper.c b/mission/freeRTOS_rust_helper.c index eabd0dc..3cf2049 100644 --- a/mission/freeRTOS_rust_helper.c +++ b/mission/freeRTOS_rust_helper.c @@ -2,7 +2,7 @@ #include "semphr.h" #include "task.h" -#define NUMBER_OF_TASKS 300 +#define NUMBER_OF_TASKS 1 SemaphoreHandle_t taskMutex = NULL; StaticSemaphore_t taskMutexDescriptor; size_t nextFreeTaskDescriptor = 0; @@ -13,6 +13,14 @@ void initFreeRTOSHelper() { taskMutex = xSemaphoreCreateRecursiveMutexStatic(&taskMutexDescriptor); } +const char * getTaskName() { + return pcTaskGetName( NULL ); +} + +void stopIt() { + taskENTER_CRITICAL(); +} + // TODO return some error code? void *createTask(TaskFunction_t taskFunction, void *parameter, void *buffer, size_t buffersize) { diff --git a/mission_rust/src/lib.rs b/mission_rust/src/lib.rs index 948f291..2240e9e 100644 --- a/mission_rust/src/lib.rs +++ b/mission_rust/src/lib.rs @@ -24,6 +24,19 @@ use core::panic::PanicInfo; #[panic_handler] fn panic(panic: &PanicInfo<'_>) -> ! { + unsafe { + stopIt(); + } + sif!("In Task \""); + unsafe { + let task_name = getTaskName(); + let mut offset = 0; + while *task_name.offset(offset) != 0 { + sif!("{}", *task_name.offset(offset) as char); + offset = offset + 1; + } + } + sifln!("\":"); sifln!("{}", panic); //TODO: stop RTOS, exit if hosted loop {} @@ -41,6 +54,9 @@ extern "C" { buffersize: cty::size_t, ) -> *const cty::c_void; + fn getTaskName() -> *const cty::c_char; + fn stopIt(); + fn vTaskDelete(handle: *const cty::c_void); fn task_delay(milliseconds: cty::uint32_t); @@ -104,18 +120,23 @@ impl<'a, const STACKSIZE: usize> PeriodicTask<'a, STACKSIZE> { unsafe { instance.task = createTask(task_entry, runner_pointer, stack_pointer, STACKSIZE); } + if instance.task == 0 as *mut cty::c_void { + panic!("could not create Task"); + } instance } } impl<'a, const STACKSIZE: usize> Drop for PeriodicTask<'a, STACKSIZE> { fn drop(&mut self) { - unsafe {vTaskDelete(self.task);} + unsafe { + vTaskDelete(self.task); + } } } struct Handler { - id: u32 + id: u32, } impl ExecutableObjectIF for Handler { @@ -143,22 +164,18 @@ fn panics(a: &mut [i32]) { a[4] = 3; } - - - - fn mission() { sifln!("Mission enter"); - let mut h1 = Handler {id: 1}; - let mut h2 = Handler {id: 2}; + let mut h1 = Handler { id: 1 }; + let mut h2 = Handler { id: 2 }; let _t1: PeriodicTask<'_, 512> = PeriodicTask::new(&mut h1); let _t2: PeriodicTask<'_, 512> = PeriodicTask::new(&mut h2); sifln!("Mission done delay"); - unsafe {task_delay(3000);} - + unsafe { + task_delay(3000); + } } -