UCOS application and expansion

xiaoxiao2021-03-06  104

Tsinghua University Engineering Physics Department Motorola Center Xu Qingfeng

Abstract: This article introduces the specific application of μC / OS in ColdFire as the core system, and has expanded on this basis.

RAM disk and file system are implemented on the core of μC / OS. In order to facilitate application and debugging, the user shell will be implemented.

Order, accept and execute user commands, extend and enrich the μC / OS functionality.

Keywords: μC / OS, UClinux, embedded system, ColdFire.

Overview:

In recent years, with the continuous improvement of microcontroller performance, embedded applications are increasingly wide. Current large commercial market

Embedded real-time systems, such as Vertex, VxWork, PSOS, etc., it is already very mature, and it provides users with powerful

Development and commissioning tools. But commercial embedded real-time systems are expensive and are targeted for specific hardware platforms. For the country

The development of the inner and medium-sized system is not based on the real-time system of purchases. At this time, the free software and open code are not lost.

For a choice. At present, the source code open (C code) is inserted with μC / OS and UCLinux, μC / OS easy to learn

Provide the basic functions of the embedded system, and the core code is short, and if you optimize your hardware, you can

Get higher execution efficiency. But μC / OS relative commercial embedded systems is still too simple, and there is development

Debugging problems. Uclinux is the product of free software sports, including rich features, including file systems, all kinds of

Peripheral drivers, communication modules, TCP / IP, PPP, HTTP, and even the web server code. On the Internet

The flowing UCLinux has been ported to the currently almost all hardware platforms, and the functions of the Linux running on the PC.

Up and down, its code is also very complicated. It is not very difficult to fully transplant, but Uclinux's code has passed the world.

Optimization, stable and reliable and efficient, all modules can be obtained from the Internet. Module

transplant. In this example, the author runs the core of μC / OS on the ColdFire hardware platform and implements Uclinu.

X file system. This allows file operations in an embedded application. At the same time, the problem of difficulty in debugging μC / OS

The UCLinux user shell is also transplanted, so that users can debug and develop by the command line.

Hardware platform:

The hardware platform of this system uses a GPFC (General Purpose Fieldbus Controller) data acquisition system.

The system is developed by the research team leading by German Hamburg National Synchronous Radiation Laboratory (DESY) DR. CLAUSEN MATTHIAS

. The ColdFire MCF5206 processor of Motorola is used as the core. ColdFire MCF5206 processor belongs to MO

Torola 32-bit MCU family, is compatible with 68K on the source code. Full static design, the maximum operating frequency at 33MHz

17MIPS handling ability. In addition to the general functional external module with a 68K series, there is a DRAM control module in the on-chip.

Direct DRAM chip directly. Because ColdFire will selection logic circuit, bus controller, DRAM control module, etc.

Being inside the MCU, it is very simple to change the peripheral circuit.

In the GPFC system used by the author, ColdFire works in 32MHz, the peripheral circuit includes two DRAM chips.

,total

4M RAM, a 128K Flash for storing the boot program. The rest is I / O circuit. The system passes the serial port of RS-232

The PC is connected. software design:

The software of this system uses μC / OS as an embedded platform. In the application, the unreplaceable advantageous excellent

Point: First, you can go to the source code according to your own needs, remove unwanted variables and unused functions.

You can even rewrite the relevant function as needed. In the source code of μC / OS, there are many conditional judgments in the execution of the function.

It is an error transfer that prevents parameters. For example, the function related to the semaphoence is executed before the execution checks the function.

The pointer is not a valid seminated number pointer. As a general system, these conditions are determined to be completely essential, avoiding

The system crashes when it is wrong. But as a specific application, as long as the correctness of the parameter transmission is guaranteed, it is completely

Can be judged without condition, improve the performance of the function, especially some frequently called functions, or when the MCU is not high

When it is, rewriting some functions can often significantly improve system performance. In addition, since the user has source level.

Solution, you can add your own module, compatible with the original system, make the system scalable.

It is precisely because of μC / OS scalability, the author transplanted UClinux's RAM disk, file system and user shell to μ

On the C / OS, file operations can be performed in the user program, and the file system can save the data for the task, and provide a unified

Interface function. Single tasks prepared by the user can also be saved on the RAM disk, can be run in the terminal with commands,

Monitor, delete tasks.

File system:

Uclinux's file system is basically the same as Linux, and the file is organized in a tree directory. Due to the space limit, about documents

Details of the system, readers can refer to Linux and UNIX information. In this case, the high-end 1m of the RAM is assigned to the file system.

The system is established a RAM disk having a capacity of 1m. Uclinux's file system consists of logical blocks, if it is a disk file system,

Corresponding to a disk block; the RAM disk corresponds to a memory block, each block of 512 bytes. A standard logic disk is divided into several

Part: Boot block, super block, index node area, and data area.

Figure 1 File system layout

Guide the block in the beginning of the file system, usually a logical block, store the boot program, used to start and boot the operating system

. In our RAM file system, the boot block is not assigned since the RAM disk boot is not required. Super block record file

Current state, how much disk is available, how much file can be stored, where you can find idle space and use for file system management

information. The index node area is followed by the hyper block, and the index node table of the file system is stored. In each of the file system

The file (including the directory) occupies an index node entry. The index node is a data structure of a record file information:

Struct dinode {

Short di_mode; / * File mode: Is the file or a directory, it is

Read, write or executable * /

Short di_nlink; / * and files related to files * /

Short di_uid; / * File owner's logon * /

Short di_gid; / * File Owner's group logging * /

Long di_size; / * file size * /

CHAR DI_ADDR []; / * The logical block number where the file data is located * /

Time_t di_atime; / * The last time of the file * /

Time_t di_mtime; / * File last modified time * / time_t di_ctime; / * file established time * /

}

The array DI_ADDR [] records the logical block number where the file data is located. In this example, the RAM disk is 1m, each logic block 512

Bytes, a total of 2048 logical blocks, so the number of each logical block is represented by two bytes. In order to record a sufficiently long text

The logical blocks in the DI_ADDR [] can be divided into direct blocks and indirect blocks, the concept of direct blocks and indirect blocks, please readers

Refer to Linux related documents. The analysis of the index node can be seen that a file can be completely determined by an index node. index

The first item in the node table is the root directory. The size of the index node area determines how many files can have in the file system

(Including the directory). In this example, the author is set to 128 items. After the index node area is the data area, the data area is logically

The block is numbered in units. If you want to access a file, just find the index node entry corresponding to the file, from DI

_ADDR [] You can find the logical block where the file data is located. Document access needs to pass FREAD () or FWRITE (

The function, the details are no longer repeated.

After adding the file system, the runtime of the task will be related to the file, so the TCB (Task Control Block) should make a corresponding modification.

You need to add a task to the directory items and tasks to open the file item. When a task calls OsTaskcreate to create a new task

When the child tasks should inherit the directory items and tasks of the previous task to open the file item.

User shell:

User shell is actually a task running independently under μC / OS and is at the lowest priority. After the shell started,

Enter the sleep state, wait for the user to enter. When the user enters the command from the terminal, it will wake the shell, and shell first detects the output.

If the command is an internal command, if not, check the current file directory in the TCB, then query in the directory.

Is there a file that matches the input, if there is, when the file attribute is executable, call OstaskCreate to create a

New task. Since the shell priority is the lowest, the newly created task will run immediately. You can use O after the new task is implemented.

StaskDel deletes yourself. If a match is not found in the current directory, the error message is returned.

In this case, the internal commands included in the shell are CD (change the current directory), the PWD (displays the current work directory),

MKDir, RMDir (founded deleted directory), PS (displays tasks in the current system), Kill (delete task).

Since OrstaskCreate in μC / OS cannot dynamically allocate stack space, OstaskDel cannot release the stack of the task.

space. In order to realize the function of the SHELL, the author has rewritten on the above two functions, add it.

Memory management functions malloc () and mfree (). For simplicity, apply and release the memory block in 8K. system

The memory resources are managed by a two-way linked list. Call malloc (), parameter is hope in OstaskCreate

The number of memory blocks, Malloc () will retrieve the two-way lin list of memory management, return the idle block address. Ostaskde

L is called mfree () to release memory and re-join the two-way linked list. In order to avoid memory cavity, start in the shell

The task uses the same size stack.

Through the user shell, separate tasks can be saved on the RAM disk, run, monitor, view task status, delete tasks, as a powerful development and debug means.

Conclusion:

The emergence and application of μC / OS is only a matter of recent years, and its rapid development has proved huge open source software.

vitality

. I believe that after the continuous enrichment and improvement of users, the function of μC / OS will be increasingly mature, and the application will be broader.

转载请注明原文地址:https://www.9cbs.com/read-124766.html

New Post(0)