Deep Learning Deeplearning Recommended Paper List List of Princess Scholars Recommended Learning route scoField

2023-03-14  

Inucos-II, in order to achieve the synchronization between tasks,The synchronization mechanism is: semaphore, mailbox and message queue.Among them, I mainly talk about the experience of the signal amount.

When the signal quantity is created, call the OSSEMCREATE (INT16U CNT) function.

cNT is the initial value of the semaphore. Different values are given to CNT, and the effects play differently.If SEMP = Ossemcreate (0), this semaphore indicates waiting for an event or multiple events.

If we want to do a public resource10 10 10, for example:

If we want two tasks TASK1 and TASK2 can call the fun () function, but cannot be called at the same time, it is best to define SEMP = OSSEMCREATE (1).OSSEMPEND (SEMP, 0, & ERR) request this semaphore, if available, call the fun (), and then callOSSEMPOST (SEMP) Release the semaphore. A mutually exclusive interview with a resource is realized here. (Note: Initialize ossemcreate (1), then there is OSSEMPEND in a task, then you can execute. After executing, cNT == 0, other tasks of other tasks cannot obtain SEM, you can only wait, unless the task has OSSEMPOST to make it CNT ++, so PEND of other tasks can be executed.)

The same reason, if a task is to wait for n events to perform, it should be defined as SEMP = Ossemcreate (n). Then call the OSSEMPOST (SEMP) when the N tasks are running, and this task can run until this N event occurs.
ossemcreate (CNT) to give the initial value CNT, Ossempend once, CNT-once, Ossempost once, CNT ++ once.


1、OSSemCreate (0);
......
OS_EVENT *Fun_Semp;
......
Fun_Semp = OSSemCreate (0);
......
void  MyTask (void *pdata)
{

.....
    for (;;) 
    {                                           
OSSEMPEND (fun_semp, 0, & err); // Request semaphore
   PC_DispStr(0,++y,  s1,  DISP_BGND_BLACK+DISP_FGND_WHITE );
OSTIMEDLYHMSM (0, 0, 1, 0); // Waiting for 1 second
    }
}
......
void  YouTask (void *pdata)
{

......
    for (;;) 
    {           
     PC_DispStr(0,++y,  s2,  DISP_BGND_BLACK+DISP_FGND_WHITE );
     if(YouTaskRun==5)
ossempost (fun_semp); // Send the semaphore
     YouTaskRun++;            
OSTIMEDLYHMSM (0, 0, 2, 0); // Waiting for 2 seconds
    }
}
In the above example, Mytask has been waiting for the signal amount, and it cannot be executed before the signal number does not come.Only after running 5 times in YouTask, YouTaskrun == 5, Ossempost (fun_semp); // Send the semaphore, and mytask can be executed.If the above example is shown, mytask can only execute once, because Youtask can no longer make YouTaskrun == 5. Mytask cannot run because the signal amount cannot be obtained.


2、OSSemCreate (1);
.....
OS_EVENT *Fun_Semp;
.....
Fun_Semp = OSSemCreate (1);
.....
void  MyTask (void *pdata)
{

..... 
    for (;;) 
    {                                           
ossempend (fun_semp, 0, & err); // Request semaphore
   PC_DispStr(0,++y,  s1,  DISP_BGND_BLACK+DISP_FGND_WHITE );
ossempost (fun_semp); // Send the semaphore
OSTIMEDLYHMSM (0, 0, 1, 0); // Waiting for 1 second
    }
}
void  YouTask (void *pdata)
{

    for (;;) 
    {                                           
ossempend (fun_semp, 0, & err); // Request semaphore
   PC_DispStr(0,++y,  s2,  DISP_BGND_BLACK+DISP_FGND_WHITE );
ossempost (fun_semp); // Send the semaphore
OSTIMEDLYHMSM (0, 0, 2, 0); // Waiting for 2 seconds
    }
}
In the above example, Mytask and YouTask are waiting for the signal amount. Because mytask priority is high, the semaphore is first executed. At this time, Youtask is still waiting for the semaphore. After mytask is executed, Ossempost (fun_semp); // Send the semaphore. Youtask sends the semaphore after the semaphore runs, so repeated.

http://www.zhixinrui.com/thread-1323-1-1.html

source

Related Posts

20.stm32CubeMX Configuration Template/Malaysia Lantern STM32CUBEMX horse

[FPGA] The design of the single port RAA (synchronous reading, synchronous writing)

MySQL8.0.26 Installation Tutorial (Super Simple)

[python] Pandas implements two tables to check highlights, go to kinglake

Deep Learning Deeplearning Recommended Paper List List of Princess Scholars Recommended Learning route scoField

Random Posts

PTA 11-Application and login of Shalement 3 QQ account (detailed explanation)

qt can’t find -lpulse -mailoop -glib, can’t find -lpulse problem

Deep Learning Deeplearning Recommended Paper List List of Princess Scholars Recommended Learning route scoField

Android Studio execute error com.android.ddmlib.adbcommandrejectException: Device Unauthorized.leo The following problems occur during the execution of the real machine.

[BZOJ1047] [Monocele] [haoi2007] ideal square