Sunteți pe pagina 1din 42

REAL TIME PROCESSING WITH RTOS PORTING ON ARM PROCESSOR

Student: S.D. Mali Guide: Prof. Dr.A.D.Jadhav

Contents Introduction Block diagram of system Block diagram details Design of the system flow System Design Experimentation Result and conclusion References Publications

INTRODUCTION
Real-Time Systems Concepts -Real-time systems are characterized by the fact that severe consequences will result if logical as well as timing correctness properties of the system are not met. There are two types of real-time systems: SOFT and HARD. In a SOFT real-time system, tasks are performed by the system as fast as possible, but the tasks don't have to finish by specific times.

In HARD real-time systems, tasks have to be performed not only correctly but on time.
Most real-time systems have a combination of SOFT and HARD requirements.

Most applications for real-time systems are embedded. Examples of embedded systems are: Process control: Food processing, Chemical plants. Automotive: Engine controls, Anti-lock braking systems. Office automation: FAX machines, Copiers. Computer peripherals: Printers, Terminals, Scanners, Modems,Robots. Aerospace: Flight management systems, Weapons systems, Jet engine controls. Domestic: Microwave ovens, Dishwashers, Washing machines.

BLOCK DIAGRAM OF SYSTEM


Application Software

RTOS
Hardware

Fig.1. BLOCK DIAGRAM OF SYSTEM

Block Diagram Details


The block diagram consisting three main parts:
RTOS Hardware Application Software

Basic Concept of RTOS:


RTOS is real time operating system . It is not necessary in small embedded systems. But it is necessary in system where scheduling of multiple tasks, ISRs ,devices is important with respect to real time constraints.

Operating system that provides the most basic services to application software running on a processor.

Fig. 2. Basic Services Provided by a Real-Time Operating System.

Hardware
ARM7-2148 board with LED , Serial port, (16x2 Text)LCD and (4X4 matrix)Keyboard. Features of LPC2148 processor: - 16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package. - 40 kB of on-chip static RAM. - 512 kB of on-chip flash program memory. - 128 bit wide interface/accelerator enables high speed 60 MHz operation.

- In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader software. - One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of 6/14analog inputs, with conversion times as low as 2.44 s per channel. - Single 10-bit D/A converter provides variable analog output. - Two 32-bit timers/external event counters. PWM unit (six outputs) and watchdog. - Low power real-time clock with independent power and dedicated 32 kHz clock input. - Multiple serial interfaces including two UARTs.

Application Software
Multitasking of LED, Serial Port, LCD and Keyboard.

Design of the System Flow


Begin Development Port Application Integrate Components and download Hex file

Research on RTOS, COS-II

Port RTOS, COS-II Testing Configure Compiler

Research on Compiler

Research on Application

Configure Hardware

Fig.3. Design Flow

System Design RTOS


Scheduler : The scheduler, also called as dispatcher, is the part of the kernel which is responsible for determining which task will run next and when. Most real-time kernels are priority based; each task is assigned a priority based on its importance. Establishing the priority for each task is application specific. In a priority based kernel, control of the CPU will always be given to the highest priority task ready to run.

When the highest priority task gets the CPU, however, it depends on the type of scheduler used. There are two types of schedulers: non-preemptive and preemptive. Non-preemptive scheduling :

is also called cooperative multitasking. An ISR can make a higher priority task ready to run but the ISR always return to the interrupted task.

The new higher priority task will gain control of the CPU only when the current task voluntarily gives up the CPU.
Low priority task
ISR ISR makes high priority task ready

Low priority task Relinquishes cpu

High priority task Fig.4. Non Preemptive scheduling

Preemptive scheduling :
Low priority task
ISR makes high priority task ready
ISR

High priority task relinquishes cpu

High priority task

Fig.5. Preemptive scheduling

when an event makes a higher priority task ready to run, the current task is immediately suspended and the higher priority task is given control of the CPU. Most real-time systems employ preemptive schedulers because they are more responsive.

RTOS,COS-II is chosen here because it has preemptive scheduler. And also has many more features: Source code: is available free for non commercial use and is well documented that it describes how it works.

Portable: is written in highly portable ANSI C. Target processor code is in assembly language, purposely kept minimum to make it easy to port on any processor. ROMable: designed for embedded applications. if we have proper tool chain (i.e. C compiler, assembler and linker/locator) then we can embed it as a part of product. Scalable: We can use only the services that we need in our application. This allows us to reduce the amount of memory (both RAM and ROM) needed by C/OS-II. Scalability is accomplished with the use of conditional compilation. You simply specify (through #define constants) which features you need for your application.

Preemptive: is a fully-preemptive real-time kernel. This means that C/OS-II always runs the highest priority task that is ready. Multi-tasking: can manage up to 64 tasks, however, the current version of the software reserves eight (8) of these tasks for system use.56 tasks leaves for application. There are thus 64 priority levels. Deterministic: Execution time of all C/OS-II functions and services are deterministic. Task stacks: Each task requires its own stack, however, C/OS-II allows each task to have a different stack size. This allows you to reduce the amount of RAM needed in your application.

Services: provides a number of system services such as mailboxes, queues, semaphores, fixed-sized memory partitions, time related functions, etc. Interrupt Management: Interrupts can suspend the execution of a task and, if a higher priority task is awakened as a result of the interrupt, the highest priority task will run as soon as all nested interrupts complete. Interrupts can be nested up to 255 levels deep. Robust and reliable: C/OS-II is based on C/OS which has been used in hundreds of commercial applications since 1992 and uses the same core and most of the same functions as C/OS yet offers more features.

Port RTOS, COS-II: Adapting RTOS to any processor is known as RTOS porting.
Application Software COS-II
(Processor Independent Code) os_core.c,os_flag.c, os_mbox.c,os_mutex.c, os_q.c,os_sem.c os_task.c,os_time.c, ucos-ii.c,ucos-ii.h

COS-II Conf.
(Application Specific Code) os_cfg.h includes.h

COS-II Port
(Processor Specific Code) os_cpu.h os_cpu_c.c os_cpu_a.S

Software --------------------------------------------------------------------------------------Hardware Timer CPU Fig.6. COS-II, Hardware/Software Architecture

Fig. shows, COS-II file structure. Kernel code is organized in three segments. Application Specific Code: Contains user specific application software as well as some code related to COS-II. This includes initializing and starting the kernel and kernel specific code for task management, synchronization and communication. Processor Independent Code: Is main code of COS-II. Is independent of actual target processor. It provides kernel services for task management, time management, semaphores, scheduling policy and memory management.

Processor Specific Code:

Contains an adaptation layer: port to the selected target processor. This code typically manipulates directly individual processor registers. e.g. In order to switch context.

For porting RTOS, COS-II: Application Specific Code: includes.h: -is a master file, found at the top of all .c files. -it allows every .c file in the project to be written without concerns about which header file actually needed.
/*MASTER INCLUDE FILE*/ #include #include #include #include #include #include #include #include <stdio.h> <string.h> <ctype.h> <stdlib.h> <app_cfg.h> <ucos_ii.h> <bsp.h> "lpc21xx.h"

os_cfg.h: -is COS-II Configuration File. -Using this file we simply specify (through #define constants) which feature we need in our application.
/* COS-II Configuration File*/
#ifndef OS_CFG_H #define OS_CFG_H /* TASK MANAGEMENT */ #define OS_TASK_CHANGE_PRIO_EN #define OS_TASK_CREATE_EN #define OS_TASK_CREATE_EXT_EN #define OS_TASK_DEL_EN #define OS_TASK_NAME_SIZE #define OS_TASK_PROFILE_EN #define OS_TASK_QUERY_EN #define OS_TASK_SUSPEND_EN #define OS_TASK_SW_HOOK_EN 1 1 1 1 32 1 1 1 1 /* Include code for OSTaskChangePrio() */ /* Include code for OSTaskCreate() */ /* Include code for OSTaskCreateExt() */ /* Include code for OSTaskDel() */ /* Determine the size of a task name */ /* Include variables in OS_TCB for profiling */ /* Include code for OSTaskQuery() */ /* Include code for OSTaskSuspend() and OSTaskResume() */ /* Include code for OSTaskSwHook() */

/* TIME MANAGEMENT */ #define OS_TIME_DLY_HMSM_EN 1 /* Include code for OSTimeDlyHMSM() */ #define OS_TIME_DLY_RESUME_EN 0 /* Include code for OSTimeDlyResume() */ #define OS_TIME_GET_SET_EN 1 /* Include code for OSTimeGet() and OSTimeSet() */ #define OS_TIME_TICK_HOOK_EN 1 /* Include code for OSTimeTickHook() */ #endif

Processor Specific Code: os_cpu.h: OS_CPU.H contains processor and implementation specific #defines constants, macros, and typedefs. os_cpu_a.asm: A C/OS-II port requires that need to write four assembly language functions: OSStartHighRdy (), OSCtxSw (), OSIntCtxSw (), OSTickISR () OSStartHighRdy (): This is used to start multitasking. This function is called by OSStart () to start the highest priority task ready-to-run.

OSCtxSw(): This is used for task level context switch. This function is executed when an interrupt is encountered. C/OS-II causes a higher priority task to be ready-to-run. The job of OSCtxSw() is to save the current task context, switch over to higher priority task and then restore context. The code saves current tasks registers onto its stack; content of the link register is saved to both the link register and the program counter locations on the stack. The task stack pointer is then saved to its task control block, OSTaskSwHook() function is called, the higher priority task stack is loaded, and the context of higher priority task is restored.

OSIntCtxSw(): This is used for interrupt level context switch. This function is called by OSIntExit() to perform a context switch from an ISR, it is assumed that all the processor registers are already properly saved onto the interrupted tasks stack. The interrupt level context switch code is similar to the task level context switch, except that the ISR has already done the work of saving the processor context the task stack. OSTickISR (): C/OS-II requires that you should provide a periodic time source to keep track on time delays and timeouts.

os_cpu_c.c: COS-II port requires that you write six fairly simple C functions: OSTaskStkInit(), OSTaskCreateHook(), OSTaskDelHook(), OSTaskSwHook(), OSTaskStatHook(), OSTimeTickHook(). The only function that is actually necessary is OSTaskStkInit(). The other five functions must be declared but theres no need to contain any code inside them. OSTaskStkInit() function is called by OSTaskCreate() and OSTaskCreateExt() to initialize the stack frame of a task.

Processor Independent Code As per the earlier discussion, processor independent code is the main code of COS-II. This code is independent of actual target processor. Thus, this code need not to be changed; only it is required to be include in the project. It provides kernel services for task management, time management, semaphores, scheduling policy and memory management

For Porting Application: Application Software -it consists multitasking of three tasks Task 1: LED ON/OFF. Task 2: Print Character through Serial Port. Task3: Display key code on LCD display. -Each task is created with following function. OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)

OSTaskCreate() requires four arguments. task is a pointer to the task code, pdata is a pointer to an argument that will be passed to your task when it starts executing, ptos is a pointer to the top of the stack that will be assigned to the task(Task Stacks) and finally, prio is the desired task priority. For Example: OS_STK Task1Stk[1024]; OSTaskCreate(App_Task1,(void*)0,&Task1Stk[1023],6);

Declaration and definition of Task:


-Every task must be written as infinite loop void App_Task1 (void *pdata); /* Declaration of Task */

void App_Task1 (void *pdata) { (void)pdata;


IO0DIR |= 0x00004000 ; while(1) {

/* Task Definition */

/* IO Direction as Output*/

IO0CLR = (1<<14) ; OSTimeDlyHMSM(0,0,0,500); IO0SET = (1<<14) ; OSTimeDlyHMSM(0,0,0,500); } }

Infinite loop

Delaying a task, OSTimeDlyHMSM() We can specify time in hours (H), minutes (M), seconds (S) and milliseconds (M) which is more natural. Calling this function causes a context switch and forces C/OS-II to execute the next highest priority task that is ready-to-run. The task calling OSTimeDlyHMSM() will be made ready-to-run as soon as the time specified expires.

This is the way there is context switch between all three tasks and multitasking is observed for all three tasks.

Compilation and Downloading procedure:

All required files from application specific code, processor specific code, processor independent code and application software code are copied on single folder. New project is created using the ARM specific cross compiler (SCARM-IDE). The makefile is edited for writing path of the folder that is working directory. Then makefile is linked with the project in the compiler (SCARM-IDE) with project setting option. Then the code is compiled using build project option, this will generate hex file of project. This hex file is downloaded on ARM7 LPC2148 Board through Flash magic utility

Fig.7. Downloading the Hex file on LPC 2148 Processor

Experimental Setup:
Computer

Power Supply

Keyboard
LCD Display

LPC2148 Fig.8. Experimental Setup

Results:
1) LED becoming ON and OFF for 500ms. 2)Output on Flash magic Terminal through serial port for every 600ms.

Fig.9. Output on Flash magic Terminal through serial port

3)Displays key code on LCD whenever user press key from (4X4) matrix keyboard.

LCD Displays Key code

Fig.10. LCD output

Conclusion: Thus the use of COS-II for multitasking, met timing correctness. Preemptive scheduler in COS-II makes the real time system more responsive. THUMB code provide up to 65% of the code size of ARM, and 160% of the performance of an equivalent ARM processor connected to a 16-bit memory system. Poorly designed and configured software architectures might even generate high response times while the physical resources display low utilization.

References:
[1] V.Billy Rakesh Roy, Sanket Dessai, and S. G.Shiva Prasad Yadav, Design and Development of ARM Processor Based Web Server, International Journal of Recent Trends in Engineering, Vol. 1, No. 4, May 2009. [2] Jean J. Labrosse, MicroC/OS-II The real time kernel, R &D Publications, second edition, 1992. [3] http://www.uCOS-II.com [4] http://www.semiconductors.philips.com, http://www.arm.com, datasheet for LPC2148.. [5] http://www.micrium.com, C/OS-II and The ARM Processor, Application Note, AN-1011 Rev. D. [6] Gunar Schirner, Gautam Sachdeva, Andreas gerstlauer, Rainer Domer, Modeling, Simulation and Synthesis in an Embedded software design flow for ARM processor, University of California, Irvine, Irvine, (A92697-3425, USA, http://www.cecs.uci.edu [7] D.W.Hawkins, (dwh@ovro.caltech.edu), Real time processing with the Philips LPC ARM microcontroller using GCC and the MicroC/OS-II RTOS , Philips 05: Project Number AR1803.

Publications:
1) S.D.Mali, Dr.A.D.Jadhav Porting RTOS on ARM and Implementation of ARM based Web Server, IEEE sponsored National Conference on Pervasive Computing2010, Sinhgad college of Engineering, Pune. 2) S.D.Mali, Embedded Web Server using RTOS Porting on ARM Processor, 4th National Conference on Recent Trends in Communication, Electronics & Information Technology, CMRIT, Bangalore. 3) S.D.Mali, Dr.A.D.Jadhav Porting RTOS on ARM and Implementation of ARM based Web Server, ePGCON-2010, Rajashri College of Engineering, Thathwade, Pune & University of Pune.

THANK YOU

S-ar putea să vă placă și