(2) Detailed explanation of self-written zrtos API

Let's take a look at the api functions related to zrtos. By the way, I will also upload the source code:

(task) task related api:

 void start_os(void);

start_os: start the task scheduling of the operating system

 void open_scheduling(void);

open_scheduling: Calling this function will immediately schedule the task, and the task will give up cpu by itself
 void enter_int(void);

endter_int: After calling this function, global interrupt mask
 void exit_int(void);

exit_int: After calling this function, the global interrupt mask is turned on


uint32 os_create_n(void(*fun_poi)(void* prg), void *prg, uint32 level, uint32 task_num);

os_create_n:

Parameter Description:

fun_poi: the function pointed to by the task

prg: parameter to be passed

level: the priority of the task

task_num: The memory size occupied by the task (task_num*4 bytes)

Description: Create a task

void z_os_start(void);

z_os_start; A space task (lowest priority) will be created internally, systick will be turned on, and then the start_os function will be called to start scheduling
void os_task_delay(uint32 count);

os_task_delay: task delay, hand the cpu to other tasks
void os_task_del(void );

os_task_del: delete this running task


(msg) message mailbox:

TCB_MSG* msg_create(void);

msg_create: Create a message mailbox
void msg_close(TCB_MSG* mTCB_MSG);

msg_close: close a message mailbox
uint32 msg_get(TCB_MSG* mTCB_MSG, void **msg, uint32 msg_get_delay);

msg_get:

Parameter Description:

mTCB_MSG: control block for message mailboxes

msg: address of the message

msg_get_delay: wait time for messages

Description: Get the message in the message mailbox
uint32 msg_put(TCB_MSG* mTCB_MSG, uint32 msg, uint32 msg_get_delay);

msg_put:

Parameter Description:

mTCB_MSG: message control block

msg_get_delay: timeout for message acquisition


(SEM) Semaphore:

TCB_SEM* sem_create(void);

sem_create: create a semaphore

void sem_free (TCB_SEM * mSEM);

sem_free: semaphore release
uint32 sem_post(TCB_SEM *mSEM);
sem_post:

Parameter Description:

mSEM: semaphore control block

Description: Send a semaphore

uint32 sem_pend (TCB_SEM * mSEM, uint32 sem_wait_delay);

sem_pend:

Parameter Description:

mSEM: semaphore control block

sem_wait_delay: semaphore wait timeout


Project code:

Three tasks have been created in the project, two with the same priority and one with a high priority.

Baidu Cloud Download: http://pan.baidu.com/s/1hswNuTm Password: e586

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325964429&siteId=291194637