Skip to content

Commit af39b5a

Browse files
reitermarkusniondir
authored andcommitted
Allow getting scheduler state.
1 parent 8ec4cde commit af39b5a

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

freertos-rust/src/freertos/shim.c

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ void freertos_rs_vTaskStartScheduler() {
2020
vTaskStartScheduler();
2121
}
2222

23+
BaseType_t freertos_rt_xTaskGetSchedulerState(void) {
24+
return xTaskGetSchedulerState();
25+
}
26+
2327
void *freertos_rs_pvPortMalloc(size_t xWantedSize) {
2428
return pvPortMalloc(xWantedSize);
2529
}

freertos-rust/src/shim.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::base::*;
55
extern "C" {
66
pub fn freertos_rs_invoke_configASSERT();
77
pub fn freertos_rs_vTaskStartScheduler() -> !;
8+
pub fn freertos_rt_xTaskGetSchedulerState() -> FreeRtosBaseType;
89
pub fn freertos_rs_pvPortMalloc(xWantedSize: FreeRtosUBaseType) -> FreeRtosVoidPtr;
910
pub fn freertos_rs_vPortFree(pv: FreeRtosVoidPtr);
1011

freertos-rust/src/task.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@ impl CurrentTask {
322322
}
323323

324324
#[derive(Debug)]
325-
pub struct FreeRtosSchedulerState {
325+
pub struct FreeRtosSystemState {
326326
pub tasks: Vec<FreeRtosTaskStatus>,
327327
pub total_run_time: u32,
328328
}
329329

330-
impl fmt::Display for FreeRtosSchedulerState {
330+
impl fmt::Display for FreeRtosSystemState {
331331
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
332332
fmt.write_str("FreeRTOS tasks\r\n")?;
333333

@@ -385,6 +385,13 @@ pub struct FreeRtosTaskStatus {
385385

386386
pub struct FreeRtosUtils;
387387

388+
#[derive(Debug, Clone, Copy, PartialEq)]
389+
pub enum FreeRtosSchedulerState {
390+
Suspended,
391+
NotStarted,
392+
Running
393+
}
394+
388395
impl FreeRtosUtils {
389396
// Should only be used for testing purpose!
390397
pub fn invoke_assert() {
@@ -398,6 +405,17 @@ impl FreeRtosUtils {
398405
}
399406
}
400407

408+
pub fn scheduler_state() -> FreeRtosSchedulerState {
409+
unsafe {
410+
match freertos_rt_xTaskGetSchedulerState() {
411+
0 => FreeRtosSchedulerState::Suspended,
412+
1 => FreeRtosSchedulerState::NotStarted,
413+
2 => FreeRtosSchedulerState::Running,
414+
_ => unreachable!(),
415+
}
416+
}
417+
}
418+
401419
pub fn get_tick_count() -> FreeRtosTickType {
402420
unsafe { freertos_rs_xTaskGetTickCount() }
403421
}
@@ -410,7 +428,7 @@ impl FreeRtosUtils {
410428
unsafe { freertos_rs_get_number_of_tasks() as usize }
411429
}
412430

413-
pub fn get_all_tasks(tasks_len: Option<usize>) -> FreeRtosSchedulerState {
431+
pub fn get_all_tasks(tasks_len: Option<usize>) -> FreeRtosSystemState {
414432
let tasks_len = tasks_len.unwrap_or(Self::get_number_of_tasks());
415433
let mut tasks = Vec::with_capacity(tasks_len as usize);
416434
let mut total_run_time = 0;
@@ -441,7 +459,7 @@ impl FreeRtosUtils {
441459
})
442460
.collect();
443461

444-
FreeRtosSchedulerState {
462+
FreeRtosSystemState {
445463
tasks: tasks,
446464
total_run_time: total_run_time,
447465
}

0 commit comments

Comments
 (0)