| μC/OS-II is a real-time and preemptive multi-tasks operating system, which is based on priority. Since its launch, it has been widely used in many field. It has a very special and excellent task-scheduling structure, which is built on its ingenious query task and switching mechanism.However, the fixed priority algorithm that μC/OS-II adopts still has some limitation in its application. When several tasks compete at the same time, the high priority always has the opportunity. This would be inappropriate in some situations. It’s not wise if the staffs always give way to the managers in a competition. In a press conference, if the tall and those stand in front of the hall always get the opportunity to ask questions, other journalists must be not happy. In such case, limit priority algorithm LNoP (LimitedNumber of Preemption) is put forward. This algorithm aims to limit the priority times on each of the tasks in a system, so as to ensure the fairness of chance to run tasks.This thesis first carries out an in-depth research on μC/OS-II, analyzing the task scheduling algorithm and the structure of the program, and then it gives a strict definition of the LNoP algorithm as well as its detailed description, examples will be attached to analyze for easy understanding. Next, this thesis will introduce the main part of LNoP algorithm in its application to μC/OS-II. A variable limiting the times of task priority will be added to the data structure of task control blocks. A competing tasks table (array TaskPreemTbl and variable TaskPreemGrp) will be subtly designed for the system. The structure of the competing table is in accordance with the original system mission ready list. Therefore, the checking table and table operation can be modified by reference to the original ready list without influence on the original.The competing schedule is a8*8structure, with a total number of64position corresponding to the64tasks. If the digit is1, it indicates that the corresponding task has opportunity to compete. The array element DynamicCnt [i] is used for recording numbers that Task I has won. When Task I wins, DynamicCnt [i] subtracts1; when DynamicCnt [i] is equal to0, the corresponding location in the competing table turns to be zero. In order to complete correctly the implementation of the LNoP, system function such as OS_TCBInit (), OSTaskSuspend (INT8Uprio), OSTaskResume (INT8U prio) and OS_SchedNew (void) are modified.Next, a specific simulation method is put forward. By setting up a specialized monitoring tasks (priority0), identified operational difference LNoP algorithm and the μC/OS-II original fixed priority algorithm clearly, then prove that LNoP algorithm is correct and effective. |