Tasks can suspend themselves by waiting for semaphores and messages, time-lapse functions, and the system starts dispatching other tasks Ostasksuspend (5). Of course it is also possible to recover Ostaskresume (5)by the corresponding function.
Delay function: Through short delay ostimedly (n) and long time delay function ostimedlyhmsm (h,m,s,m)(up to 11 days) the system enters the dispatch, the delay is completed after the return to continue execution, but also through Stimedlyresume (n) resumes execution at any time without delay.
Signal Volume:
1 created : Os_event *sem=ossemcreate (n)//Parameter N (0~65535 value, different values represent different meanings)
2 Wait: value=ossemaccept (SEM); To see if a resource can be used, return the value of the semaphore
Ossempend (SEM,TIMEOUT,&ERR)///wait for the signal to be received before execution. Task timeout represents waiting for a timeout after the semaphore has not received a semaphore, automatically restore the operating state, if the timeout=0, indicating the amount of infinite wait semaphore;
3 Send: Ossempost (SEM);//Send signal volume
Mailbox: Data transfer for large amounts of data (shared data) between tasks. To pass a pointer-defined variable from one task to another or to a task, the task waiting for the mailbox can also be set to wait indefinitely and wait for several clock beats to resume execution automatically.
1 Created: Os_event * come=osmboxcreate ((void *) 0);//Set up a mailbox
2 Send: U16 buffer= "0X0FFF";//information to be sent
Osmboxpost (Come,&buffer);//Send messages (pointers) to tasks by email
3 Receive: U16 Msg=osmboxpend (COME,TIMEOUT,&ERR);//Gets the information pointer from the specified mailbox COM (pointer msg points to buffer), if timeout=0 is blocked, A non-0 means that it automatically runs after a fixed clock cycle.
Message Queuing: is actually an array of multiple mailboxes, which can be seen as an array of pointers. Used to process an ordered event.
Os_event *com1//define a pointer
void *commsg1[3]; Defines a pointer array
1 Create: Com1=osqcreate (&commsg1[0],3);//Create a message queue, that is, an array of pointers. (assigns the first address of the array pointer to COM1), the number of queues is 3
2 Send: Osqpost (Com1, (void*) &st[0]); Send to queue *commsg1[0] point to the first address of the array St, and the number of queue messages plus a
Osqpost (Com1, (void*) &aa[0]); Send to queue
Osqpost (Com1, (void*) &a1); Send to queue
2 receive: void *msg1=osqpend (COM1,0,&ERR); Gets the first pointer in the array of pointers commsg1[0], which points to st[0]. Each time the Osqpend function is called, the function will subtract the message of the queue 1,com1 the next message pointer *commsg1[i++].
Status of the task-suspend and resume