ucos-II operating system

19.1  Operating System Introduction

UC / OS-II can support up to 64 tasks, priority respectively from 0 to 63, where 0 is the highest priority. 63 is the lowest level, the system retains the four highest-priority task and four lowest-priority task, the number of tasks that can be used for all users with 56.

19.1.1  Operating System Introduction

What is the operating system

The operating system is to manage and control the computer hardware and software resources of the computer program is run directly on the "bare metal" of the basic system software, any other software must be run in order to support the operating system. Between APP between and hardware.

19.1.1  common operating systems

Common operating systems:

IOS (Apple), Android () , Windows , Linux , Symbian, U COS , FreeRTOS , RT-T (made in China) , Vxworks , eCos , and so on.

 Real-Time Operating System (RTOS)

 UCOS ( learning free, commercial registration required), FreeRTOS , RT-T (made in China) , Vxworks , eCos

 The length of time each task will give a basic, when appropriately adjusted according to length of mission requirements of the task. Tasks and tasks directly switch has a corresponding rule.

 Sharing operating system

 Windows ---- 2000 before, Linux 2.6 ---- ago

 To each task is assigned a fixed length of time, if this task within a fixed time has been idle for a long, time-sharing operating system or give the mandate a good long time.

 Semi-real-time operating system

 ---- 7/8/10 Windows , Linux 2.6 ---- after

19.1  U COS operating system introduced

19.1.1  scheduling principles of the operating system

UCOS operating system scheduling principles are: priority task scheduling principle. The smaller the task priority number, the higher priority task.
Precautions: Each task has only one priority, priority number of different tasks can not be the same.

19.1.1  operating system program structure

When there is no operating system

Bare metal in the entire project and only one death cycle, this cycle of death there is the main function. Other places may have an infinite loop, but must have an exit condition.

When the operating system

The entire operating system project can have more than an endless loop, each task has an infinite loop, main function is no infinite loop.

Note the point: the operating system must complete the main two points: ① set up the operating system heartbeat rhythm; ② create a task ( this task must be created successfully ).

19.1.1  operating system task scheduling

Task scheduling: that is when scheduling occurs.

Task scheduling occurs in both cases.

The heart beat to reach the operating system. Heart beat is called a Tick . The U- COS has a dedicated operating system heart beat function: OSTimeTick ();

Program code for operating system calls OS_Sched (); generated when the task scheduling function. OS_Sched (): called task scheduling function.

Note: We do not task scheduling function can be called directly, only the operating system calls. Programmers call this function will make the UCOS operating system crashes.

Note point ①: the operating system task scheduler task switching may not occur; task switching necessary to generate a certain task scheduling.

Precautions ②: the operating system must have a high-priority task to release C PU control function calls.

19.1.1  operating system task status

UCOS operating system, there are five state task : stop / sleep, ready to run, suspend / wait, interrupts. Only when the task into the operating state can perform tasks in the program code.

 

Stop: The task is deleted.
Sleep: Currently there is no task ready to run state is not the task execution.
Ready: the task running conditions need to be met are ready.
Run: The task is running.
Pending: The task needs to wait for a certain condition occurs, other tasks can hang this task.
Wait: Delay relevant.
Interrupt: program interrupt event occurred, CPU going to interrupt service routine, interrupt the operating system.

 

 

 

19.1.1  operating system interrupt tasks

Interrupt status needs to note the following:
From the running state enters the interrupt state must call the function OSIntEnter (); function this function is used to tell the operating system of the current interrupt service routine.
Must be called before entering the operating status from the interrupt status exit function OSIntExit (); function this function is used to tell the operating system exits the current program interrupted.

The program exits from the interrupt, the operating system to return to the task, then do not necessarily return to the original task.

 

 

 

1  / * 
2  Function: initialize the system timer tick
 3  function parameter: any ms
 4  Function Return Value: None
 5  Remarks: heart beat control of the operating system interrupt ----
 6  OF: Li Gong
 7  Time: 2018- 09-19
 . 8  * / 
. 9  void SysTick_Init (U16 n_ms)
 10  {
 . 11      SysTick-> the CTRL = 0 ; // Clear configuration
 12      // selected clock source 21MHz 
13 is      
14      SysTick-> VAL = 0 ;
 15      
16      SysTick-> the LOAD n_ms * = 21000 ;
 . 17      
18 is      SysTick-> the CTRL | = ( 0X1<< 1 ); // open the module-level interrupt is enabled 
. 19      
20 is      SysTick-> the CTRL | = ( 0X1 << 0 ); // open down counter - Enable 
21  }
 22 is  
23 is  / * 
24  Function: system tick timer an interrupt service function
 25  function parameters: None
 26  function return value: None
 27  Remarks: tell the operating system into the interrupt, the interrupt function of the heart beats
 28  author: Li Gong
 29  time: 2018-09-19
 30  * / 
31  void SysTick_Handler ( void )
 32  {
 33 is      OSIntEnter (); // into the interrupt 
34 is      
35      IF(SysTick-> the CTRL & ( 0X1 << 16 ))
 36      {
 37 [          OSTimeTick (); // heart beat function 
38 is      }
 39      
40      OSIntExit (); // the interrupt 
41  }
 42 is  
43 is  / * 
44  Function: main function
 45  function parameters: None
 46  function return values: integer
 47  Note: use UCOS OS
 48  
49  * / 
50  int main ( void )
 51 is  {
 52 is      // initializes the system timer tick 
53 is      SysTick_Init ( 1000 /OS_TICKS_PER_SEC);
 54 is      // initialize the OS 
55      OSInit ();
 56 is      // Create a task 
57 is      OSTaskCreate (os_start_task, NULL, & OS_STK_START_TASK_SIZE [OS_STK_START_TASK_LENGTH - . 1 ], OS_START_TASK_PRIO);
 58      // start the operating system 
59      OSStart ();
 60      / / If the task execution fails to create infinite loop 
61 is      the while ( . 1 )
 62 is      {
 63 is          ;
 64      }
 65 }
UCOS operating system code necessary

 

. 1 INT8U OSTaskCreate ( void    (* Task) ( void * p_arg),
 2                       void     * p_arg,
 . 3                       OS_STK * PTOS,
 . 4                       INT8U PRIO)
 . 5  Function: Create a task
 6 Function Parameters: void    (* Task) ( void * p_arg ): function pointer, the function used to store the task
 . 7          void     * p_arg: shape parameter transfer function of the task, if the parameter is transmitted using invisible to NULL
 . 8          OS_STK * PTOS: stack task stack task
 . 9          INT8U PRIO: task priority No.
 10  function return value: OS_ERR_NONE: means creating successful; otherwise, it indicates failure
 11  to use:
12 is OSTaskCreate (os_start_task, NULL, & OS_STK_START_TASK_SIZE [OS_STK_START_TASK_LENGTH - . 1 ], OS_START_TASK_PRIO);
 13 is  embodied tasks:
 14  #define OS_START_TASK_PRIO 10
 15  #define OS_STK_START_TASK_LENGTH 256
 16  OS_STK OS_STK_START_TASK_SIZE [OS_STK_START_TASK_LENGTH];
 . 17  
18 is  / * 
. 19  Function: Start Task
 20  function parameters: universal pointer
 21  function return value: None
 22  Note: no
 23  OF: Li Gong
 24  time: 2018-09-19
 25  * / 
26 is  void os_start_task ( void * p_arg)
 27 {
28     
29     while(1)
30     {
31         
32     }
33 }
UCOS operating system to create a task

 

19.1  U COS operating system administration tasks

19.4.1ucos tasks

Task control block (bottom, no control), task priority, task stack, task function.

Task Control Block: When creating a task when, ucos will allocate some memory space for this task, this memory space is called a task control block. Task control block records information about the job: a priority, task status, task stack address assignment function address, the task.
Task Priority: Each task has a unique priority, priority only our priority task in ucos uniquely identify the task it is to do the task ucos scheduled basis.
Task stack: when task switching task is to save the state (where the execution before switching to local variables).
Task function: when the task is scheduled when the work to be done.

19.1  U COS inter-task communication operating system

19.1.1  Semaphore

(Protection of that code will not be snatched away by another process)
role: to protect shared resources.
Semaphore: In UCOS operating system which is equivalent to a global variable, so that the value of the semaphore is released the semaphore plus 1, so that the use of semaphores semaphore value by one. The minimum value is 0.

19.1.1  Messaging Mailbox

19.1.1  Message Queuing

19.1.1  mutex

19.1  U COS operating system event flags group

 

Guess you like

Origin www.cnblogs.com/zhouyuqing1024/p/11852111.html