Added a new freertos shell command to interact with freertos concepts (tasks, notifications, queue etc), not feature complete yet though

This commit is contained in:
Anatole SCHRAMM 2025-07-31 16:21:03 +02:00
parent 3cbb87e390
commit cd851cf044

View File

@ -95,7 +95,7 @@ static void tls_rtc_irq_cb(void *arg)
rtc_time.tm_sec,
rtc_time.tm_mday,
rtc_time.tm_mon,
rtc_time.tm_year);
rtc_time.tm_year + 1900);
tls_rtc_timer_stop();
}
@ -582,6 +582,8 @@ int _pmu(const shell_cmd_t *pcmd, int argc, char *const argv[])
int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
bool cmd_found = true;
if(argc > 1)
{
if(strcmp(argv[1], "get") == 0)
@ -595,7 +597,7 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
rtc_time.tm_sec,
rtc_time.tm_mday,
rtc_time.tm_mon,
rtc_time.tm_year);
rtc_time.tm_year + 1900);
}
else if(strcmp(argv[1], "set") == 0)
{
@ -616,6 +618,8 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
rtc_time.tm_mon,
rtc_time.tm_year);
rtc_time.tm_year -= 1900;
tls_set_rtc(&rtc_time);
tls_rtc_isr_register(&(tls_rtc_irq_cb), NULL);
}
@ -638,17 +642,26 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
rtc_time.tm_mon,
rtc_time.tm_year);
rtc_time.tm_year -= 1900;
tls_rtc_timer_start(&(rtc_time));
}
else
{
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
cmd_found = false;
}
}
else
{
cmd_found = false;
}
if(!cmd_found)
{
shell_printf("List of rtc actions :"NEW_LINE"get"NEW_LINE"set <h> <m> <s> <d> <m> <y>"NEW_LINE"alarm <h> <m> <s> <d> <m> <y>"NEW_LINE);
}
return 0;
}
@ -973,6 +986,136 @@ int _utils(const shell_cmd_t *pcmd, int argc, char *const argv[])
return 0;
}
tls_os_task_t task_handle = NULL;
u8 *task_stack = NULL;
#define TASK_STK_SIZE (256)
void task_function(void *param)
{
(void)param;
for(;;)
{
char *notification_data = (char *)ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
shell_printf("%s got notification : #%s#"NEW_LINE, __func__, notification_data);
}
}
void task_free_function(void)
{
task_handle = NULL;
tls_mem_free(task_stack);
task_stack = NULL;
}
int _freertos(const shell_cmd_t *pcmd, int argc, char * const argv[])
{
bool cmd_found = true;
if(argc > 1)
{
if(strcmp(argv[1], "task") == 0)
{
if(argc > 2)
{
if(strcmp(argv[2], "create") == 0)
{
if(task_handle == NULL)
{
task_stack = tls_mem_alloc(TASK_STK_SIZE * sizeof(StackType_t));
if(task_stack)
{
if(tls_os_task_create(&task_handle, "demo_task", &(task_function), NULL, task_stack, TASK_STK_SIZE * sizeof(StackType_t), 62, 0) == TLS_OS_SUCCESS)
{
shell_printf("Task created"NEW_LINE);
}
else
{
shell_printf("Failed to create task"NEW_LINE);
tls_mem_free(task_stack);
}
}
else
{
shell_printf("Failed to allocate task stack"NEW_LINE);
}
}
else
{
shell_printf("Task already created"NEW_LINE);
}
}
else if(strcmp(argv[2], "destroy") == 0)
{
if(task_handle)
{
if(tls_os_task_del_by_task_handle(task_handle, &(task_free_function)) == TLS_OS_SUCCESS)
{
shell_printf("Task deleted"NEW_LINE);
}
else
{
shell_printf("Failed to delete task"NEW_LINE);
}
}
else
{
printf("No task to destroy"NEW_LINE);
}
}
else if(strcmp(argv[2], "notify") == 0)
{
if(argc > 3)
{
if(task_handle)
{
if(xTaskNotify(task_handle, (uint32_t)argv[3], eSetValueWithoutOverwrite) == pdFAIL)
{
shell_printf("Failed to notify task"NEW_LINE);
}
}
else
{
shell_printf("No task to notify"NEW_LINE
"Use: freertos task create, to start the task"NEW_LINE);
}
}
else
{
cmd_found = false;
}
}
else
{
cmd_found = false;
}
}
else
{
cmd_found = false;
}
}
else
{
cmd_found = false;
}
}
else
{
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
cmd_found = false;
}
if(!cmd_found)
{
shell_printf("List of %s actions :"NEW_LINE
"task create"NEW_LINE
"task destroy"NEW_LINE
"task notify \"msg\""NEW_LINE, argv[0]);
}
return 0;
}
NANO_SHELL_ADD_CMD(bus,
_bus,
"Command to interact with the SPI bus",
@ -1029,3 +1172,8 @@ NANO_SHELL_ADD_CMD(utils,
_utils,
"Command used to test various utils functions",
" Use this command to try various utility functions out lilke random and more"NEW_LINE);
NANO_SHELL_ADD_CMD(freertos,
_freertos,
"Command to test various FreeRTOS concepts",
" Use this command to interact with various FreeRTOS concepts (tasks, queues, notifications...)"NEW_LINE);