μC/OS-II operating system device driver design and practical application examples

Device drivers are an essential and confidential part of any operating system. They implement a standard interface to all attached devices in a computer system and contain device drivers that are directly related to the hardware. Broadly speaking, "driver" refers to a collection of functions that operate on hardware devices. The concept of a driver is a vague definition when there is no fixed operating system. A simple understanding is to provide a function that operates from software to hardware (which can also be virtual hardware). Usually should mainly include: device initialization, device read and write (input and output), device control and other information. There is no unified device driver interface under μC/OS-II - unlike the definition mode of device files under Windows or Linux, some hardware operations are done through general functions, called "drivers". Not too much.

1 Introduction

The peripheral driver is the interface between the real-time kernel and the hardware, and is the link between the underlying hardware and the kernel.

Writing a driver module should satisfy the following main features:

1 Initialize the device;

2 transfer data from the kernel to the hardware and read data from the hardware;

3 reading the data transmitted by the application to the device and returning the data requested by the application;

4 Monitor and handle equipment anomalies. Since there is no unified device driver interface under μC/OS-II, the design and implementation of the device driver in this operating system is mainly accomplished by some function of hardware operation.

2. Hardware initialization during startup of μC/OS-II operating system

When the application system based on μC/OS-II works, the CPU is first initialized; then the operating system is initialized, mainly completing the task control block (TCB) initialization, the TCB priority table initialization, the creation of an empty task, etc.; then starting to create a new task And can create another new task in the newly created task; finally call the OSSTART () function to start multi-task scheduling.

When μC/OS-II is actually ported to a specific hardware platform, hardware initialization is also required during system initialization. The main function is a function that is executed first by the system startup. Before starting μC/OS-II, all interrupts are masked and global variables are initialized to prevent operation errors. Hardware initialization mainly includes interrupt initialization, serial port, keyboard, display and other device initialization. Initialization of μC/OS-II By assigning the OSInit() function, the task queue, priority status table, and preparation status table are assigned to the OS, global variables are initialized, and an empty loop task is created. Next, call OSTaskCreate() to create all user tasks before starting μC/OS-II, and set the ready state. When creating the task, specify the priority, stack size and position of each task, and the task function entry. Call OS2Start() to start μC/OS-II. The task with the highest priority is found from the ready queue and executed as the current task. The process is as shown.

3. μC/OS-II operating system operation and control of hardware

3.1 Function Control Hardware

As mentioned above, unlike other operating systems, there is no uniform device driver interface in μC/OS-II, so the operation and control of the hardware can be done by functions. After the hardware initialization is completed during the startup process, the system creates an empty loop task, and then can call OSTaskCreate() to create a user task, select the hardware to be controlled in the task user task, select the best control method, and call the user to write the own. The function is done.

μC/OS-II operating system device driver design and practical application examples

Graph system startup process

3.2 BSP

BSP (Board Support Package) is a software layer between the underlying hardware and the operating system. It completes the initial hardware and software initialization after the system is powered on, and encapsulates the underlying hardware, so that the operating system no longer faces specific operating.

Write a simple BSP for μC/OS-II. It first sets the CPU internal register and system stack, and initializes the stack pointer to establish the running and calling environment of the program; then it can easily set the hardware configuration environment using C language, and compile the corresponding operation function to provide uniform for the operating system call. Interface; after the CPU, board level and program itself are initialized, the control of the CPU can be given to the operating system.

Gel Battery

Gel Battery,Deep Cycle Battery,Gel VRLA Battery,Acid Battery

Shenzhen Unitronic Power System Co., Ltd , https://www.unitronicpower.com