Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
8Activity
0 of .
Results for:
No results containing your search query
P. 1
real-time operation system for psoc mcus

real-time operation system for psoc mcus

Ratings: (0)|Views: 534 |Likes:
Published by ATL95148

More info:

Published by: ATL95148 on Mar 15, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/10/2014

pdf

text

original

10/21/2002
Revision A
-1 -
Application Note
AN2046
Real-Time Operation System for PSoC MCUs

By: Edward Nova
Associated Project: Yes
Associated Part Family: CY8C25xxx, CY8C26xxx

Summary

This Application Note is a demonstration of a Real-Time Operation System (RTOS) for PSoC microcontrollers. This can be used for variety of applications such as control systems or automotive industries.

Introduction

PSoC microcontrollers have versatile interrupt capabilities, which is what modern embedded applications require.

It was considered that the implementation of a RTOS\u2019 Kernel, using the Rate Monotonic Scheduling (RMS) with task blocking method is best suited for PSoC. We will show how this Real-Time Multi-tasking Kernel provides means to run a number of tasks at a specific time interval by using Periodic Time Slot method. In this implementation, the Periodic Time Slots do not block each other. The task blocking is possible only by using the Interrupt services.

The implementation is very simple, runs very fast and does not consume valuable CPU time and memory. This framework also can be extended to accommodate much more complex scheduling methods.

This project has been developed with the PSoC Designer Version 3.10 Build 240.This Application will run with Pod 28 Rev D. or E.

To illustrate the Multithread feature of the RTOS, eight LEDs on the Pod (Or Pup) are being toggled. Each task has an associated LED. The LED will blink according to its task time slot. Every time slot is twice as long as the previous one.

Using this RTOS will enable you to create your project in much shorter time. At the same time, the structure of RTOS is helpful to organize your program modules.

There are many variations of RTOSs. The one described in this Application Note is designed to be very fast and simple to implement. As I will demonstrate, this RTOS does not take too many resources from PSoC. There are number of other advantages that will be discussed in more details later.

Real-Time Operating System
A typical Operating System includes some or all
of the following functions:
\ue000
Hardware Interface
\ue000
Memory Management
\ue000
Task Scheduling
\ue000
Interrupt Handling
\ue000
File Management
\ue000
Device Drivers
\ue000
Networking

In Real-Time Systems a right answer at the wrong time is a wrong answer. In time-critical systems, operating system guarantees that all the critical sections of the program are processed in a timely manner and will meet their deadlines.

Embedded System Modeling

Depending on each application, the designer needs to choose a proper microcontroller. The CPU speed, memory space and the number of input and output are some of the features that must be considered when choosing a microcontroller. On the other hand, designers also need to choose how to handle the software requirements.

AN2046
10/21/2002
Revision A
-2 -
There are number of ways to model an
embedded system, these include:
\ue000
Sequential Processing
\ue000
State Machines
\ue000
Multitasking
Sequential Processing

In Sequential Processing, tasks are handled one at a time and CPU is allocating all its time and other resources to this specific task. Traditional flowcharts are quite capable of illustrating these systems. Sequential Processing can be used in sections of a complex system, a small size system or an application that does not deal with multiple events or external interrupts.

State Machines

State Machines are very useful and can simplify systems that have limited number of states. The transaction rules are not complicated. For example, scanning a keyboard or modeling of an elevator can be implemented with a simple State Machines.

Multitasking

A task is a small program section to do a job. It is a basic unit of resource allocation. Tasks are competing for CPU time, memory space or other resources. A complex problem can be divided to a number of smaller and simpler tasks. A big task also can be divided into several small time slots. A time slot may contain several tasks.

Every task handles only a small portion of the problem. These tasks can run at different priorities or at regular time intervals. Modern embedded systems with a number of external interrupts are inherently closer to Multitasking Operating Systems.

TASK 1
TASK 2
TASK 3
TASK 4
TASK 5
TA
SK 6
1 2 3 4 5 6 7 8 910
11
12
13
14
20
19
18
17
16
15
24
23
22
21
32
31
30
29
28
27
26
25
33
Figure 1: Periodic Task Scheduler

Time slot is the minimum time interval that can be allocated to a task. In this example the time slot is 1 ms so Task 1 is running at a periodic rate of every 2 ms for up to 1 ms. Task 2 executes at every 4 ms for up to 1 ms, and so on. Tasks requiring higher priority need shorter periodic rates.

Task period for every task can be calculated
using the following formula:
Task n Period = Time Slot Period x 2^n

Task 1 Period = 1 ms x 2^1 = 2 ms.
Task 2 Period = 1 ms x 2^2 = 4 ms.
Task 3 Period = 1 ms x 2^3 = 8 ms.
Task 4 Period = 1 ms x 2^4 = 16 ms.
Task 5 Period = 1 ms x 2^5 = 32 ms.
Task 6 Period = 1 ms x 2^6 = 64 ms.

Real-Time Multitasking Kernel

A typical embedded system is cost sensitive. Processors alone usually determine the cost of the system. Speed and memory are major factor for a processor. To reduce the cost, designers choose the most cost-effective processor to get the job done.

Real-Time Kernels contain only the essential functions of RTOS such as task scheduling and interrupt handling.

It is true that developing a Real-Time Kernel needs extra work and takes time and memory from the processor, but more and more Real- Time Kernels are being used in embedded systems for various reasons.

Real-Time
Kernels
have
the
following
advantages:
\ue000
Reliable Scheduling
\ue000
Simplified Framework
Reliable Scheduling

Reliable Scheduling simplifies the process of calculating how much CPU time is being utilized. Having a reliable scheduling mechanism also allows the designer to use the state-driven techniques.

For example, in applications that need to de- bounce a key, the designer would use a task to test the status of the key and the time delay. This task will block the CPU from running other tasks.

State-driven keyboard de-bouncer is much more accurate and versatile and while the de-bounce task is in various states, the CPU can run other tasks.

AN2046
10/21/2002
Revision A
-3 -
Simplified Framework

Faster time to market becomes more and more vital for embedded systems and having a simple framework helps to add the application easily in the Real-Time Kernel.

Using Real-Time Kernel enables designers to simplify a complex operation into a few much smaller tasks. This will also allow multiple designers to share the CPU resources in an organized manner.

Completely different applications can use the
same Real-Time Kernel.
Functions of Real-Time Kernel
A Real-Time Kernel may contain many functions.
In this Application Note we will discuss:
\ue000
Scheduling
\ue000
Context Switching
Scheduling

Scheduler in a RTOS is the function that determines the status of all the tasks. In this application a task state can be:

\ue000
Running
\ue000
Pending
\ue000
Blocked

The Scheduler evaluates a number of factors such as task priority or interrupt status. Based on this evaluation it sets tasks to an appropriate state.

Context Switching

When the Scheduler determines that a task with higher priority needs to be executed, it will block the running task. Then it will store the information needed to resume its execution. This Information is called \u201cTask Context\u201d and it usually contains Program Counter (PC), CPU Registers and the Accumulator. The Scheduler runs the higher priority task. Upon completion it performs a reverse process of restoring the Task Context. Storing and restoring the Task Context by Scheduler is called \u201cContext Switching.\u201d

Stacks are commonly used to store Context Switching information, but some designers prefer to dedicate static memory location.

To have an efficient Context Switching, a good C compiler will examine all the registers in every task and store only those registers that are being changed. This not only makes the Context Switching faster but also reduces usage of valuable RAM and programming space.

Context Switching increases additional time and memory overhead. This is why in some applications a Non-Preemptive Scheduler is preferred.

Types of Real-Time Kernel

Depending on the hardware and software in an embedded system, designers can choose one of many types of Real-Time Kernels. Two of the most commonly used are:

\ue000
Non-Preemptive
\ue000
Preemptive
Non-Preemptive

In systems that do not require interruption of tasks, a Non-Preemptive kernel is most common. In a Non-Preemptive kernel, the task started by the Scheduler gains the time and memory resource of the system. Only after this task is completed does the control go back to the Scheduler.

Implementing a Non-Preemptive kernel is relatively simple because it does not deal with Context Switching.

Preemptive

In a Preemptive kernel, the Scheduler can transfer the resources of the system by running the task to a task with a higher priority. In other words, tasks can be interrupted by higher priority tasks. That is why most Preemptive kernels are using an Interrupt mechanism to schedule higher priority tasks.

Some tasks or sections of a task need to have total control of resources. In this case no other task should be able to interrupt them. These critical sections need to be as short as possible so other tasks are able to meet their deadlines. In this case, a global interrupt disable can be used to disable all maskable interrupts. Special care should be taken to deal with the non-maskable interrupts.

Rate Monotonic Scheduling

Rate Monotonic Scheduling (RMS) is a method to implement the kernel in many Real-Time Operating Systems.

RMS is fairly simple to implement and is very reliable. In RMS, the priorities are determined and fixed at the design time. Periodic tasks with shorter periods get the higher priority.

Activity (8)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Abishek Ponraj liked this
sivar22 liked this
Yusniar Reza K liked this
prashant liked this
Thirtha Prasad liked this
Arnold Motley liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->