Translated by Shao Beibei: Chapter 1 UCOS operating system migration analysis

Source: Internet
Author: User

UCOS operating system migration analysis

1. OS _cpu.h File

1. The processor must meet the following requirements:

(1). The C compiler of the processor can generate reentrant code.

(2). enable or disable interruptions in C language.

(3) The processor supports interruption and can generate scheduled interruption (usually between 10 to Hz ).

(4). the processor supports a hardware stack that can hold a certain amount of data (which may be several kilobytes.

(5) The processor reads and stores the stack pointer and other CPU registers into the stack or memory.

Because different microprocessors have different word lengths, the migration of µc/OS-ⅱ includes a series of Type Definitions to ensure portability. In particular, the microc/OS-ⅱ code never uses data types such as C short, Int, and long, because they are related to the compiler and cannot be transplanted.

2. Open interruption: OS _enter_critical () and Guanzhong disconnection: OS _exit_critical () µc/OS-ⅱ must first prohibit interruption and then access the critical segment of the Code, in addition, after the access is completed, the interruption is allowed again. This protects critical code segments from the destruction of multi-task or interrupted service routines (ISRs.

3. Stack processing OS _stk_growth. If OS _stk_growth is set to 0, the stack goes from bottom to top. If OS _stk_growth is set to 1, the stack goes from top to bottom.

4. OS _task_sw () is a macro, which is called when the microc/OS-ⅱ task switches from a low-priority task to the highest-priority task. OS _task_sw () is always called in task-level code. Another osintexit () function is used to execute the task switching function when ISR makes a higher-priority task ready.

 

Ii. OS _cpu_c.c File

The porting example of uCOS-II requires you to write 10 simple C functions:

Ostaskstkinit () // required function. ostaskcreat () and ostaskcreatext () call this function to initialize the stack structure of the task.

Ostaskcreathook () // when a task is created using ostaskcreate () or ostaskcreateext (), ostaskcreatehook () is called (). This function allows the user or the user who uses the user's transplanted instance to extend the function of μC/OS-ⅱ.

Ostaskswhook () // This function is called when a task is switched. This function is called no matter whether the task is executed through osctxsw () or osintctxsw. Ostaskswhook () can directly access ostcbcur and ostcbhighrdy because they are global variables. Ostcbcur points to OS _tcb of the task to be switched out, while ostcbhighrdy points to OS _tcb of the new task.

Ostaskstathook () // ostaskstathook () is called once every second by ostaskstat. You can use ostaskstathook () to extend the statistics function.

Ostimetickhook () // every clock cycle is called by ostimetick.

Ostcbinithook () // you can perform some processing related to the initialization control block OS _tcb.

The ostaskidlehook () // ostaskidle () function can be called to realize the CPU power consumption mode.

Osinithookbegin // This function is called immediately after you enter the osinit function.

Osinithookend () // same as osinithoobegin

 

Iii. OS _cpu_a.asm File

The porting instance of µc/OS-ⅱ requires you to write four simple assembly language functions:
Osstarthighrdy ()
Osctxsw ()
Osintctxsw ()
Ostickisr ()
If your compiler supports inserting assembly language code, you can put all the processor-related code into the OS _cpu_c.c file without having to have some scattered assembly language files.

1. The osstarthighrdy () osstart () function calls osstarthighrdy () to run the task with the highest priority in the ready task.

2. The osctxsw () task-level switch is implemented by executing Soft Interrupt commands or executing trap commands based on different processors, the vector address of the interrupt service subroutine, trap, or exception handling must point to osctxsw ().

3. ostickisr () uCOS-II requires you to provide a periodic clock source for time delay and timeout.

4. osintctxsw () osintexit () executes the task switching function in ISR by calling osintctxsw.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.