Task management
1 ostaskcreate ()
Set up a new task. The creation of a task can also be established in a running task before the multi-tasking environment is started. The interrupt handler cannot
Set up a task. A task can be the structure of an infinite loop.
Function prototypes: int8u ostaskcreate (void (*task) (void *pd), void *pdata, Os_stk *ptos, int8u prio);
Parameter Description: Task is a pointer to the first address of the task code.
Pdata points to a data structure that is used to pass parameters to the task when the task is established.
PTOs is a pointer to the task ' s top of the stack. If the configuration constant os_stk_growth is
Set to 1, the stack was assumed to grow downward (i.e. from high memory to low memory). ' Pstk ' would thus
The highest (valid) memory location of the stack. If Os_stk_growth is set to 0, ' PSTK ' would
Point to the lowest memory location of the stack and the stack would grow with increasing memory
Locations.
Prio is the task's priority. A unique priority must is assigned to each task and the lower the
Number, the higher the priority.
return value:
The return value of Ostaskcreate () is one of the following:
* Os_no_err: Function call succeeded.
* Os_prio_exist: The task with this priority already exists.
* Os_prio_invalid: The parameter specifies a priority greater than Os_lowest_prio.
* OS_NO_MORE_TCB: No OS_TCB in the system can be assigned to the task.
2 Ostasksuspend ()
Suspends a task unconditionally. The task calling this function can also pass the parameter os_prio_self, suspending the calling task itself. When the current task is suspended,
Only other tasks can wake up a suspended task. Once the task is suspended, the system will reschedule the task and run the next highest-priority ready task. Call
Waking up a pending task requires calling the function Ostaskresume ().
The suspend of a task can be superimposed on other operations. For example, when a task is suspended while a delay operation is in progress, the wake of the task requires two conditions
: The end of the delay and the wake-up operation of other tasks. Also, when a task is suspended, it waits for a semaphore, and when the task is purged from the semaphore's wait-to-column
Cannot run immediately, but must wait until it is awakened.
Function prototype: int8u ostasksuspend (int8u prio);
Parameter Description: PRIO Specifies that you want to get a pending task priority, or you can specify a parameter os_prio_self to suspend the task itself. At this point, the next priority
The highest-level readiness task will run.
return value:
The return value of Ostasksuspend () is one of the following:
* Os_no_err: Function call succeeded.
* Os_task_suspend_idle: Attempted to suspend idle task in μc/Os. This is an illegal operation.
* Os_prio_invalid: The parameter specifies a value that is greater than Os_lowest_prio or not set os_prio_self.
* Os_task_suspend_prio: The task to suspend does not exist.
3 Ostaskresume ()
Wakes up a task that is suspended with the Ostasksuspend () function. Ostaskresume () is also the only function that can "hang" suspended tasks.
Function prototype: int8u ostaskresume (int8u prio);
Parameter Description: Prio Specifies the priority of the task to wake.
return value:
The return value of Ostaskresume () is one of the following:
* Os_no_err: Function call succeeded.
* Os_task_resume_prio: The task to be awakened does not exist.
* os_task_not_suspended: The task to be awakened is not in the suspended state.
* Os_prio_invalid: The parameter specifies a priority greater than or equal to Os_lowest_prio.
Signal Volume
1 ossemcreate ()
The function establishes and initializes a semaphore with the function of the semaphore as follows:
* Allow one task and other tasks or interrupt synchronization
* Access to Equipment
* Flag Event Occurrence
Function prototype: os_event *ossemcreate (int16u value);
Parameter description: The value parameter is the initial value of the semaphore being established and can take any value from 0 to 65535.
return value:
The Ossemcreate () function returns a pointer to a control block assigned to the semaphore being established. If no control block is available, the ossemcreate () function returns
Go home pointer.
2 Ossempend ()
This function is used for tasks that attempt to acquire the right to use the device, task needs and other tasks or interrupt synchronization, and the task needs to wait for the occurrence of a particular event.
If the task calls the Ossempend () function, the semaphore value is greater than 0, and the Ossempend () function decrements the value and returns the value. If the semaphore value is called
equals Zero, the Ossempend () function joins the task to the waiting queue for that semaphore. The Ossempend () function suspends the current task until other tasks or interrupts are set
or exceeding the expected time of the wait. If the semaphore is set within the expected clock beat, the Μc/os-ⅱ default allows the highest priority task to get the letter
Number and return to ready state. A task that is suspended by the Ostasksuspend () function can also accept the semaphore, but the task will remain suspended for straight
To restore the task's run by calling the Ostaskresume () function.
Function prototypes: void Ossempend (os_evnnt *pevent, int16u timeout, int8u *err);
Parameter description: Pevent is a pointer to the semaphore. The value of the pointer can be obtained when the semaphore is established. (Refer to the Ossemcreate () function).
Timeout allows a task to return to its ready state when it has not received the required semaphore after a specified number of ticks. If the value
A zero indicates that the task will continue to wait for the semaphore, with a maximum wait time of 65,535 clock beats. This length of time is not very strict and may exist
The error of a clock beat.
Err is a pointer to a variable that contains an error code, and the error code returned may be one of the following:
* Os_no_err: The semaphore is not zero.
* Os_timeout: The semaphore is not set within the specified number of clock cycles.
* OS_ERR_PEND_ISR: Call the function from the interrupt. Although the function is not allowed to be called from an interrupt, Μc/os-ⅱ still contains
The ability to detect this condition.
* Os_err_event_type:pevent is not a pointer to the semaphore.
return value: None
3 Ossempost ()
This function is used to set the specified semaphore. If the specified semaphore is 0 or greater than 0, the ossempost () function increments the semaphore value and returns. Such as
If any task waits for the semaphore, the task with the highest priority will get the semaphore and go into the ready state. Task scheduling functions will be scheduled to
Whether the currently running task is still the highest-priority ready task.
Function prototype: int8u ossempost (os_event *pevent);
Parameter description: Pevent is a pointer to the semaphore. The value of the pointer can be obtained when the semaphore is established. (Refer to the Ossemcreate () function).
return value:
The return value of the Ossempost () function is one of the following:
* Os_no_err: The semaphore is successfully set
* OS_SEM_OVF: Semaphore value Overflow
* Os_err_event_type:pevent is not a pointer to the semaphore
Time
1 ostimedly ()
This function is used to delay a task by a number of clock beats. If the delay time is greater than 0, the system will dispatch the task immediately. The length of the delay time can be
From 0 to 65,535 clock beats. The delay time of 0 means that the delay is not performed and the function returns the caller immediately. Time delay depends on how much the system has per second
A few clock beats (by file os_cfg. h in the OS_TICKS_PER_SEC macro to set).
Function prototype: void ostimedly (int16u ticks);
Parameter description: Ticks is the number of clock beats to be delayed.
return value: None
2 Ostimedlyhmsm ()
This function is used to delay a task for several times. The delay is measured in hours, minutes, seconds, and milliseconds. After calling Ostimedlyhmsm (), if the delay
When the time is not 0, the system will dispatch the task immediately.
Function prototype: int8u ostimedlyhmsm (int8u hours,int8u minutes,int8u seconds,int16u milli);
Parameter description: Hours is the delay hour, range from 0-255.
The minutes is a delay of minutes, ranging from 0-59.
Seconds is a delay of seconds, ranging from 0-59
The Milli is a delay of milliseconds, ranging from 0-999.
It is necessary to note that the operating system in the processing of the delay operation is in the clock ticks, the actual delay time is an integer multiple of the clock beat. If
The system clock beat interval is 10ms, and the set delay is 5ms, it will not produce a delay operation, and if the set delay is 15ms, then the actual delay is
Two clock beats, i.e. 20ms.
return value:
The return value of OSTIMEDLYHMSM () is one of the following:
* Os_no_err: Function call succeeded.
* Os_time_invalid_minutes: Parameter error, the number of minutes is greater than 59.
* Os_time_invalid_seconds: Parameter error, the number of seconds is greater than 59.
* Os_time_invalid_milli: Parameter error, the number of milliseconds is greater than 999.
* os_time_zero_dly: Four parameters are all 0.
Memory management
1 osmemcreate ()
This function establishes and initializes an area for dynamic memory allocation that contains a specified number of memory blocks that are determined by size. Applications can move
The memory blocks are requested and released back into the memory area when they are exhausted. The return value of the function is a pointer to this memory area control block and is used as a
Osmemget (), Osmemput (), osmemquery () parameters for related calls.
Function prototypes: Os_mem *osmemcreate (void *addr, int32u nblks, int32u blksize, int8u *err);
Parameter description: The starting address of the memory area established by addr. You can use a static array or use the malloc () function to allocate this area when the system is initialized
The space of the domain.
The number of nblks memory blocks. You need to define a minimum of two memory blocks per memory area.
Blksize the size of each memory block, the minimum should be able to accommodate a pointer variable.
Err is a pointer to a variable that contains an error code. Err may be in the following situations:
* Os_no_err: Successfully established memory area.
* OS_MEM_INVALID_ADDR: Illegal address, that is, the address is a null pointer.
* Os_mem_invalid_part: There is no free memory area.
* Os_mem_invalid_blks: No more than two blocks of memory have been established for the memory area.
* Os_mem_invalid_size: Memory block size is not enough to hold a pointer variable.
return value:
The Osmemcreate () function returns a pointer to the memory area control block that was created. If creation fails, the function returns a null pointer.
2 Osmemget ()
This function is used to allocate a block of memory from the memory area. The user program must know the size of the block of memory that was created and must be released after the memory block has been used
It. You can call the Osmemget () function multiple times. Its return value is a pointer to the allocated memory block and is used as a parameter to the Osmemput () function.
Function prototypes: void *osmemget (Os_mem *pmem, int8u *err);
Parameter description: Pmem is a pointer to the memory area control block, which can be obtained from the return value of the Osmemcreate () function.
Err is a pointer to a variable that contains an error code. Err may be the following scenario:
* Os_no_err: Successfully get a block of memory.
* Os_mem_no_free_blks: There are not enough memory blocks in the memory area.
return value:
The Osmemget () function returns a pointer to the allocated memory block. If there are no memory blocks to allocate, the Osmemget () function returns a null pointer.
3 Osmemput ()
This function frees up a block of memory, and the memory block must be released back to its original memory area, or it will cause a system error.
Function prototypes: int8u osmemput (Os_mem *pmem, void *pblk);
Parameter description: Pmem is a pointer to the memory area control block, which can be obtained from the return value of the Osmemcreate () function.
PBLK is a pointer to a block of memory that will be freed.
return value:
The return value of the Osmemput () function is one of the following:
* Os_no_err: Successfully freed memory block
* Os_mem_full: The memory area is full and no more memory blocks are allowed to be freed. This situation indicates that the user program has made an error and released more than
The Osmemget () function gets the block of memory.
4 Osmemquery ()
This function is used to get information about the area of memory.
Function prototypes: int8u osmemquery (Os_mem *pmem, Os_mem_data *pdata);
Parameter description: Pmem is a pointer to the memory area control block, which can be obtained from the return value of the Osmemcreate () function.
Pdata is a pointer to the OS_MEM_DATA data structure that contains the following fields:
void osaddr; /* Pointer to the memory area start address */
void Osfreelist; /* Pointer to the free memory block list start Address */
INT32U osblksize; /* Size of each memory block */
INT32U osnblks; /* The total number of memory blocks in the memory area */
INT32U Osnfree; /* Number of free memory blocks */
INT32U osnused; /* Number of memory blocks already in use */
Message Queuing
1 osqcreate ()
This function is used to establish a message queue. A task or interrupt can send a message to one or more tasks through Message Queuing. The meaning of the message is and specific
Applications are closely related.
Function prototypes: Os_event *osqcreate (void **start, int8u size);
Parameter description: Start is the first address of the message memory area, and the message memory area is an array of pointers.
The size of the message memory area.
return value:
The Osqcreate () function returns a pointer to the Message Queuing control block. If there is no idle control block, the Osqcreate () function returns a null pointer.
2 Osqpend ()
This function is used for task wait messages. Messages are sent to the required tasks through interrupts or tasks. The message is a pointer variable, in a different application where the message
Specific meanings are different. If a message already exists in the queue when the Osqpend () function is called, the message is returned to the caller of the Osqpend () function, which
Messages are purged from the queue at the same time. If there is no message in the queue when the Osqpend () function is called, the Osqpend () function suspends the calling task until the message is received or
Exceeded the defined timeout period. If there are multiple tasks waiting for the same message at the same time, Μc/os-ⅱ the default highest priority task gets the message. One by
The Ostasksuspend () function can also accept messages for a pending task, but the task will remain suspended until the Ostaskresume () letter is called
The number of recovery tasks to run.
Function prototypes: void *osqpend (os_event *pevent, int16u timeout, int8u *err);
Parameter description: Pevent is a pointer to a message queue, and the value of the pointer is available when the queue is established. (Refer to the Osqcreate () function).
Timeout allows a task to wait for a message with a specified number of clock ticks. Returns to the ready state if the message has not been received after a timeout. Such as
If the value is set to zero, the task will continue to wait for the message, with a maximum wait time of 65,535 ticks. The length of the time is not very strict.
, there may be a clock-beat error.
Err is a pointer to a variable that contains an error code. The error code returned by the Osqpend () function may be as follows:
* Os_no_err: The message is correctly accepted.
* Os_timeout: The message does not receive a message within the specified number of clock cycles.
* OS_ERR_PEND_ISR: Call the function from the interrupt. Although it is stipulated that the function is not allowed to be called from the interrupt, Μc/os-ⅱ still packages
Includes the ability to detect this condition.
* Os_err_event_type:pevent is not a pointer to a message queue.
return value:
The Osqpend () function returns the obtained message and resets the *err to Os_no_err. If no messages are received within a specified number of clock beats, osqpend
The () function returns a null pointer and sets *err to Os_timeout.
3 Osqpostfront ()
This function is used to send messages to Message Queuing. The Osqpostfront () function is very similar to the Osqpost () function, except that the
The Osqpostfront () function inserts the message that is sent to the front of the message queue. In other words, the Osqpostfront () function causes the message queue to follow the
Out (LIFO) in a way that works instead of first in, first Out (FIFO). The message is a pointer-length variable, and the meaning of the message in different applications may not
With. If the message is already filled in the queue, the call returns an error code. The same is true for the Osqpost () function. When this function is called, if any of the tasks are
Waits for a message in the queue, the highest priority task will get the message. If the task priority of the wait message is higher than the task that sent the message, that
A high-priority task will immediately preempt the current task execution when it gets the message, that is, a task switch will occur.
Function prototypes: int8u osqpostfront (os_event *pevent, void *msg);
Parameter description: Pevent is a pointer to the message queue that will receive the message. The value of the pointer can be obtained when the queue is established. (Refer to Osqcreate ()
function).
MSG is a pointer to the message that is about to be sent. Passing a null pointer is not allowed.
return value:
The return value of the Osqpostfront () function is one of the following:
* Os_no_err: The message was successfully placed in the message queue.
* Os_q_full: Message queue is full.
* Os_err_event_type:pevent is not a pointer to a message queue.
4 Osqpost ()
This function is used to send messages to Message Queuing. The message is a pointer-length variable, and the message may have different meanings in different applications. If the queue
The call returns an error code if the message is already full. If there are any tasks waiting for a message in the queue, the highest priority task will get the message.
If the task priority of the wait message is higher than the task that sent the message, then the high priority task will preempt the current task execution immediately after the message is received.
In other words, a task switch occurs. The message is entered in a first-in, first-out (FIFO) manner, that is, the message that enters the queue first is passed to the task.
Function prototypes: int8u osqpost (os_event *pevent, void *msg);
Parameter description: Pevent is a pointer to the message queue that will accept the message. The value of the pointer can be obtained when the queue is established. (Refer to Osqcreate ()
function).
MSG is the message that is about to be sent to the queue. Passing a null pointer is not allowed.
return value:
The return value of the Osqpost () function is one of the following:
* Os_no_err: The message was successfully placed in the message queue.
* Os_q_full: Message queue is full.
* Os_err_event_type:pevent is not a pointer to a message queue.
5 Osqflush ()
This function is used to empty the message queue.
Function prototype: int8u *osqflush (os_event *pevent);
Parameter description: Pevent is a pointer to Message Queuing. The value of the pointer can be obtained when the queue is established. (Refer to the Osqcreate () function).
return value:
The return value of the Osqflush () function is one of the following:
* Os_no_err: Message queue was successfully emptied
* Os_err_event_type: Attempt to purge objects that are not Message Queuing
6 Osqquery ()
This function is used to obtain Message Queuing information. The user program must establish a OS_Q_DATA data structure that is used to hold the message queue from the
The data that the control block obtains. You can call this function to know if a task is waiting for a message, how many tasks are waiting for a message, how many messages are in the queue,
And the number of messages that Message Queuing can hold. The Osqquery () function can also get the message that is about to be passed to the task.
Function prototypes: int8u osqquery (os_event *pevent, Os_q_data *pdata);
Parameter description: Pevent is a pointer to Message Queuing. The value of this pointer can be obtained when a message queue is established. (Refer to the Osqcreate () function).
Pdata is a pointer to the OS_Q_DATA data structure that contains the following members:
void *osmsg; /* Next Available message */
int16u osnmsgs; /* Number of messages in the queue */
int16u osqsize; /* Size of message Queue */
int8u Oseventtbl[os_event_tbl_size]; /* Wait queue for Message Queuing */
Int8u oseventgrp;
return value:
The return value of the Osqquery () function is one of the following:
* Os_no_err: Call succeeded
* Os_err_event_type:pevent is not a pointer to a message queue.
7 Osqdel ()
This function is used to delete the specified message queue.
System Management functions:
1.OSStatInit (); /* Determine CPU capacity after Systick Start,before other tasks being created */
Enable task statistics function, Osstatinit () to be called at the time of establishment of the first and only one task, this is done because the statistics task calculates the CPU benefit
Need to use the rate, call this function to note that the main reason is because in Osstatinit () Call ostimedly occurred task scheduling, so do embed
Application, the user must turn on the clock-beat interrupt in the first task, i.e. after Systick start
The calculation of CPU utilization is done by the Osstattask () function in μc/OS, which executes once per second. And when Osstatrdy is set to true, the μ
The C/OS-II will count the CPU utilization.
2.Osschedlock ();
Role: dispatch lock function
Description: Prevents the dispatch from happening, it makes you ready to perform a task switch when the task switch
Parameters: None
Because task scheduling is usually done by ostimedly (). In this function, the current task execution is suspended. Also see if the Task Scheduler table has a priority-ready task. If the current task runs, call Osschedlock () to lock the scheduler so that the current task is suspended when you call ostimedly (). However, because the scheduler is locked, it does not allow other tasks to use the CPU. In this way, there is no task to run except to interrupt the accident. Unless the interruption is handled in this case.
Must call Osschedlock () and Osschedunlock () must appear in pairs
3.Systick_config (systemcoreclock/1000); This function opens the interrupt for the SysTick and also sets the reload register for SysTick.
The systemcoreclock/1000 is 1 per thousand of the tether clock frequency. That is, every second, the Systick register will be filled 1000 times, 1ms each time. This is
is the base unit of the timekeeping. When the reload register is full, a systick interrupt is generated, which we then process in the interrupt function: in the file
Stm32f4xx_it.c add a bit of Systick interrupt handler function Systick Handler tick timer for (config) OS core clock
ucosii clock frequency 200hz, 1m 200 x ticks clock beats
Delay of 2 ticks, i.e. 2/200=10ms
ostimedly (2); /* Synchronize with clock tick */
system function of Uc/os-ii 20160526