3μcos_II transplantation and implementation on InfineonC164CI 16-bit microcontroller

Publisher:塞上老马Latest update time:2012-01-18 Keywords:3μcos_II Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Introduction

μc/osII is powerful and supports 56 user tasks. Its kernel is preemptive and supports a variety of commonly used inter-process communication mechanisms such as semaphores, mailboxes, and message queues. It has been successfully applied to many commercial embedded systems and is a mature and stable real-time kernel. Unlike most commercial RTOS, μc/osII discloses all source code. 90% of the code is written in the standard ANSI C language, and the program is highly readable and portable. At the same time, it is available for free, and even commercial applications only charge a small license fee. Therefore, it is of great significance to study, research, develop, and apply the μc/osII real-time operating system. The Infineon C164CI-8EM processor is a very excellent 16-bit microcontroller. The CPU system chip integrates the following components: 64KB OTP memory, 2KB on-chip RAM, 16-bit 3/6-channel PWM, 8-channel 10-bit A/D, timer unit, and compare/capture unit. It can achieve seamless connection with commonly used peripheral devices and is powerful. It is currently widely used in the automotive field.

μc/osII real-time operating system structure



Figure 1 illustrates the hardware and software architecture of μc/osII. The application is at the top level of the entire system. Each task can think that it has exclusive CPU, so it can be designed as an infinite loop. μc/osII processor-independent code provides μc/osII system services. Applications can use these API functions for memory management, inter-task communication, and task creation and deletion.

Most of the μc/osII code is written in ANSI C, so μc/osII has good portability. However, some processor-related code still needs to be written in C and assembly language. The porting of μc/osII needs to meet the following requirements:

① The C compiler of the processor can generate reusable code.

② C calls can be used to enter and exit the critical section code.

③ The processor must support hardware interrupts and requires a timer interrupt source.

④ The processor needs a hardware stack that can accommodate a certain amount of data.

⑤ The processor needs instructions that can exchange data between CPU registers and memory and stack.

The Infineon C164CI-8EM processor fully meets the above requirements.

Transplantation of real-time kernel μc/osII on Infineon C164CI-8EM processor

We use KEIL compiler. Transplantation of μc/osII mainly includes the following steps:

(1) Set the processor and compiler related codes in OS_CPU.H Compiler related
data types
typedef unsigned char BOOLEAN; / * Boolean value */
typedef unsigned char INT8U; / * 8-bit unsigned number */
typedef signed char INT8S; / * 8-bit signed number */
typedef unsigned short INT16U; / * 16-bit unsigned number */
typedef signed short INT16S; / * 16-bit signed number */
typedef unsigned long INT32U; / * 32-bit unsigned number */
typedef signed long INT32S; / * 32-bit signed number */
typedef unsigned int OS_STK; / * Stack entry width 16 bits */
Code related to C164 processor
#define OS_EXIT_CRITICAL() (IEN= 1) /* Enable interrupt and exit critical section*/
#define OS_ENTER_CRITICAL() (IEN= 0) /* Enable interrupt and exit critical section*/
#define OS_STK_GROWTH 1 /* The stack grows from high address to low address*/

(2) Write 6 operating system related functions in C language
(OS_CPU_C.C)
OS_STK *OSTaskStkInit (void (*task)
(void *pd), void *pdata, OS_STK *ptos,
INT16Uopt)
{
INT16U*stk;
INT32Uusr;
INT16Upage;
INT16Uoffset;
INT16Udata_pag;
INT16Udata_pof;
opt = opt;
data_pag = (INT16U)_pag(pdata);
data_pof = (INT16U)_pof(pdata);
stk = (INT16U*)ptos;
*stk-- = data_pag;
*stk-- = data_pof; *stk-- = (INT16U) _seg
(task); )- 10) | 0x4000); *stk-- = offset; page = (INT16U)(usr >> 0x000E); *stk-- = page; *stk-- =(INT16U)0x0800; *stk-- = (INT16U) _sof (task); OSTaskBuildStk(page, offset, data_pag, data_pof); return ((OS_STK *)stk); } The last five functions are hook functions, and no code is required: OSTaskCreateHook (OS_TCB *ptcb);
















OSTaskDelHook (OS_TCB *ptcb);
OSTaskSwHook (void);
OSTaskStatHook (void);
OSTimeTickHook (void);

(3) Write 4 processor-related functions (O S_ CPU. A SM) in assembly language. Functions called in the multi-task startup function:
OSStartHighRdy(), which is called by the OSStar() function and runs the ready task with the highest priority. Task switching function: OSCtxSw(), which implements task switching at the task level. Interrupt task switching function: OSIntCtxSw(), which implements interrupt-level task switching. Clock tick service function: OSTickISR(), which provides a clock resource to implement time delay and expiration functions.

After completing the above work, μc/osII can run on C164CI.

Test, write drivers and applications

After completing the above work, you need to test whether the transplantation is correct. Testing a μc/osII real-time kernel is not complicated. It is to make this real-time kernel run on your target board. At the beginning, you can run some simple tasks and clock beat interrupt tasks. If the debugging is successful, you can add applications on it.

After the μc/osII transplantation is completed, you need to write interface drivers on this real-time kernel. Because the embedded operating system is smaller in size, more powerful, fast, stable, and more targeted, it does not need to drive, manage, schedule, and monitor all interface devices of the system like other operating systems. Because embedded products are designed for special purposes and have strong specificity. Therefore, when writing drivers, the content is more concise, more stable, and the driver module is smaller.

The following basic functions should be completed when writing drivers;

① Initialize and release the device;

② Transfer data from the kernel to the hardware and read data from the hardware;

③ Read the data sent by the application to the device file and send back the data requested by the application;

④ Detect and handle errors in the device. After realizing the above functions, an embedded operating system is basically formed. After

completing the porting of μc/osII and the writing of the driver

, use the API functions provided by the operating system to write applications and call the system services related to the application in μc/osII. After debugging, solidify it on the target board, and the embedded application software is completed.

Conclusion

This article completes the porting of μc/osII on the C164CI 16-bit microcontroller. After debugging, the system runs stably, which builds a good development platform for the user's application project.
Keywords:3μcos_II Reference address:3μcos_II transplantation and implementation on InfineonC164CI 16-bit microcontroller

Previous article:Using CPLD to create a microcontroller with a flexible instruction set
Next article:Implementation of TCP/IP protocol stack on MSP430 microcontroller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号