Task

Operating System task management, scheduling, synchronization and inter-task communication services.

Task management

void task_os_init()

Initialize the task management system: Memory pool, Message package, Heap system, Timer service.

Note

MUST-BE called before any other task os function

Parameters:

none – [in]

Returns:

none

void task_os_create(uint8_t task_id, pf_task task_handler, uint8_t task_priority, uint32_t task_stack_size, void *mailbox, uint16_t mailbox_size, const uint8_t *task_name)

Create a single task.

Note

MUST-BE called after task_os_init and before task_os_run

Parameters:
  • task_id – [in] task id (MUST-BE unique and less than TASK_POOL_MAX_SIZE)

  • task_handler – [in] task handler function pointer

  • task_priority – [in] task priority (reference task_priority_t)

  • task_stack_size – [in] task stack size (unit: uint32_t, MUST-BE greater than 0)

  • mailbox – [in] pointer to the mailbox object (set MAILBOX_NULL if the task does not require a mailbox)

  • mailbox_size – [in] mailbox size (set the value to 0 if the task does not require a mailbox)

  • task_name – [in] pointer to the task name string

Returns:

none

void task_os_create_table(task_t *table)

Create tasks based on the provided task table (by user application)

Parameters:

table – [in] pointer to the task table

Returns:

none

void task_os_delete(uint8_t task_id)

Delete the specified task.

Parameters:

task_id – [in] task id to be deleted

Returns:

none

void task_os_suspend(uint8_t task_id)

Suspend the specified task.

Parameters:

task_id – [in] task id to be suspended

Returns:

none

void task_os_resume(uint8_t task_id)

Resume the specified task.

Parameters:

task_id – [in] task id to be resumed

Returns:

none

void task_os_run()

Start the os scheduler.

Note

MUST-BE called after task_os_init and task_os_create

Parameters:

none – [in]

Returns:

none

void task_os_tick(uint32_t tick)

Task os tick (System os tick base)

Note

MUST-BE called in systick interrupt, timer interrupt, …

Parameters:

tick – tick heart (unit: milliseconds)

Returns:

none

void task_os_scheduler()

Task scheduling based on the ready task list.

Warning

kernel private (should not be called by user applications directly)

Parameters:

none – [in]

Returns:

none

void task_os_pendsv_handler() __attribute__((naked))

Task context switching service.

User porting this function need to know: Initialize and trigger pendsv concept

Parameters:

none – [in]

Returns:

none

Task message transport

void task_post(uint8_t task_id, rk_msg_t *msg)

Task post a message.

Parameters:
  • task_id – [in] destination task id

  • msg – [in] pointer to the message to be sent (MUST-BE not NULL)

void task_post_pure_msg(uint8_t des_task_id, uint8_t signal)

Task post a pure message.

Parameters:
  • des_task_id – [in] destination task id

  • signal – [in] message execution signal

void task_post_common_msg(uint8_t des_task_id, uint8_t signal, uint8_t *data, uint32_t size)

Task post a common message.

Parameters:
  • des_task_id – [in] destination task id

  • signal – [in] message execution signal

  • data – [in] pointer to the data to be sent (MUST-BE not NULL)

  • size – [in] size of the data to be sent (unit: byte, MUST-BE less than or equal to RK_COMMON_MSG_DATA_SIZE)

void task_post_dynamic_msg(uint8_t des_task_id, uint8_t signal, uint8_t *data, uint32_t size)

Task post a dynamic message.

Parameters:
  • des_task_id – [in] destination task id

  • signal – [in] message execution signal

  • data – [in] pointer to the data to be sent (MUST-BE not NULL)

  • size – [in] size of the data to be sent (unit: byte)

rk_msg_t *task_receive_msg(uint8_t task_id)

Task receive the message.

Parameters:

task_id – [in] task id to receive message

Returns:

pointer to the received message

void task_free_msg(rk_msg_t *msg)

Task free the message.

Parameters:

msg – [in] pointer to the message to be freed (MUST-BE not NULL)

Returns:

none

Task ultilities

void task_os_info()

Show information about all tasks in the system (id, priority, stack size, stack used, name)

Parameters:

none – [in]

Returns:

none

tcb_t *task_os_get_current_tcb()

Get current task control block active at the time the function is called.

Parameters:

none – [in]

Returns:

pointer to the current task control block

void task_os_delay(uint32_t ms)

Block the current task for the specified number of milliseconds, allowing other tasks to run during the delay period.

Note

MUST-BE called in task handler, user application MUST-NOT call this function in interrupt handler

Parameters:

ms – [in] delay time in milliseconds

Returns:

none

Task list

void task_list_init(task_list_t *list)

Initialize a task list.

Warning

kernel private (should not be called by user applications directly)

Parameters:

list – [in] pointer to the task list to be initialized (MUST-BE not NULL)

Returns:

none

void task_list_put(task_list_t *list, tcb_t *tcb)

Put the specified task control block to the end of the given task list.

Warning

kernel private (should not be called by user applications directly)

Parameters:
  • list – [in] pointer to the task list (MUST-BE not NULL)

  • tcb – [in] pointer to the task control block to be added (MUST-BE not NULL)

Returns:

none

void task_list_remove(task_list_t *list, tcb_t *tcb)

Remove the specified task control block from the given task list.

Warning

kernel private (should not be called by user applications directly)

Parameters:
  • list – [in] pointer to the task list (MUST-BE not NULL)

  • tcb – [in] pointer to the task control block to be removed (MUST-BE not NULL)

Returns:

none

tcb_t *task_list_get(task_list_t *list)

Remove and return the head task control block from the given task list.

Warning

kernel private (should not be called by user applications directly)

Parameters:

list – [in] pointer to the task list (MUST-BE not NULL)

Returns:

pointer to the task control block of the head task list. If the list is empty, it will return NULL

tcb_t *task_list_get_head(task_list_t *list)

Return the head task control block from the given task list without removing it.

Warning

kernel private (should not be called by user applications directly)

Parameters:

list – [in] pointer to the task list (MUST-BE not NULL)

Returns:

pointer to the task control block of the head task (not removed from the list). If the list is empty, it will return NULL

tcb_t *task_list_get_higher_priority(task_list_t *list)

Remove and return the highest priority task control block from the given task list.

Warning

kernel private (should not be called by user applications directly)

Parameters:

list – [in] pointer to the task list (MUST-BE not NULL)

Returns:

pointer to the task control block of the highest priority task (removed from the list). If the list is empty, it will return NULL

bool task_list_is_available(task_list_t *list)

Check the availability of the given task list.

Warning

kernel private (should not be called by user applications directly)

Parameters:

list – [in] pointer to the task list (MUST-BE not NULL)

Returns:

TRUE if the list contain task, FALSE if the list is empty

Ready list

void task_ready_put(tcb_t *tcb)

Put the specified task control block to the ready list based on its priority.

Warning

kernel private (should not be called by user applications directly)

Parameters:

tcb – [in] pointer to the task control block to be put in the ready list (MUST-BE not NULL)

Returns:

none

void task_ready_remove(tcb_t *tcb)

Remove the specified task control block from the ready list based on its priority.

Warning

kernel private (should not be called by user applications directly)

Parameters:

tcb – [in] pointer to the task control block to be removed from the ready list (MUST-BE not NULL)

Returns:

none