Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PPCF-1
COPYRIGHT NOTICE
© Copyright 2007 IAR Systems. All rights reserved.
No part of this document may be reproduced without the prior written consent of IAR
Systems. The software described in this document is furnished under a license and may
only be used or copied in accordance with the terms of such a license.
DISCLAIMER
The information in this document is subject to change without notice and does not
represent a commitment on any part of IAR Systems. While the information contained
herein is assumed to be accurate, IAR Systems assumes no responsibility for any errors
or omissions.
In no event shall IAR Systems, its employees, its contractors, or the authors of this
document be liable for special, direct, indirect, or consequential damage, losses, costs,
charges, claims, demands, claim for lost profits, fees, or expenses of any nature or kind.
TRADEMARKS
IAR, IAR Systems, IAR Embedded Workbench, IAR MakeApp, C-SPY, visualSTATE,
From Idea To Target, IAR KickStart Kit and IAR PowerPac are trademarks or registered
trademarks owned by IAR Systems AB.
Microsoft and Windows are registered trademarks of Microsoft Corporation.
All other product names are trademarks or registered trademarks of their respective
owners.
EDITION NOTICE
First edition: October 2007
Part number: PPCF-1
Internal reference: ISUD.
PPCF-1
Contents
Preface ........................................................................................................................................................................ 5
Using PowerPac RTOS with IAR Embedded Workbench .......................................................................... 7
First steps ........................................................................................................................................................ 7
The example application Start_LEDBlink.c ............................................................................................ 8
Stepping through the example application using C-SPY ..................................................................... 9
Building an application ......................................................................................................................................... 13
Getting started ............................................................................................................................................. 13
Required files for an application ............................................................................................................... 13
Change library mode .................................................................................................................................. 13
Select another CPU .................................................................................................................................... 14
Freescale ColdFire specifics .............................................................................................................................. 15
CPU modes ................................................................................................................................................... 15
Available libraries ........................................................................................................................................ 15
Compiler specifics ................................................................................................................................................ 17
Standard system libraries .......................................................................................................................... 17
Stacks ........................................................................................................................................................................ 19
Task stack for Freescale ColdFire ........................................................................................................... 19
System stack for Freescale ColdFire ...................................................................................................... 19
Interrupt stack for Freescale ColdFire ................................................................................................... 19
Interrupts ................................................................................................................................................................ 21
What happens if an interrupt occurs ...................................................................................................... 21
Defining interrupt handlers in C .............................................................................................................. 21
Interrupt vector table ................................................................................................................................. 21
Fast interrupts with Freescale ColdFire ................................................................................................ 21
Interrupt priorities ...................................................................................................................................... 22
Interrupt handling with vectored interrupt controller ....................................................................... 22
High-priority non-maskable exceptions ................................................................................................. 23
Technical data ......................................................................................................................................................... 25
Memory requirements ............................................................................................................................... 25
Files shipped with PowerPac RTOS ................................................................................................................ 27
PPCF-1 3
IAR PowerPac™ RTOS
4 Freescale ColdFire® Cores PPCF-1
Preface
Welcome to the guide IAR PowerPac™ RTOS Freescale ColdFire® Cores. This guide describes how to use
PowerPac RTOS for the ARM Cores using IAR Embedded Workbench®.
Document conventions
TYPOGRAPHIC CONVENTIONS FOR SYNTAX
This guide uses the following typographic conventions:
Style Description
Text that you enter at the command-prompt or that appears on the display (that is system
Keyword
functions, file- or pathnames).
Parameter Parameters in API functions.
Sample Sample code in program examples.
Reference Reference to chapters, tables and figures or other documents.
GUIElement Buttons, dialog boxes, menu names, menu commands.
Emphasis Very important sections
Table 1: Typographic conventions
PPCF-1 5
IAR PowerPac™ RTOS
6 Freescale ColdFire® Cores PPCF-1
Using PowerPac RTOS with IAR
Embedded Workbench
The following chapter describes how to start with and use PowerPac RTOS for Freescale ColdFire and IAR
Embedded Workbench. You should follow these steps to become familiar with PowerPac RTOS for Freescale
ColdFire and IAR Embedded Workbench.
First steps
After you installed of PowerPac RTOS you can create your first multitasking application. You received ready to go
example start workspaces and projects and it is recommended to use one of these as a starting point of all your
applications.
Your PowerPac RTOS distribution contains one folder Start which contains the sample start workspaces and projects
and every additional files used to build your application.
To get your new application running, you should proceed as follows:
1 Create a working directory for your application, for example c:\work.
2 In the IAR Embedded Workbench IDE, select Example Application in the Startup dialog box. To open the Startup
dialog box, choose Help | Startup Screen.
3 Select BoardSupport from the Example Application list.
4 Select the project which is consistent to your hardware, or start with the IAR Simulator project. In this guide the
Start_M52223.eww is used.
PPCF-1 7
5 Choose a destination folder for your project, for example C:\Work. After generating the project of your choice, the
screen should look something like this:
6 Build the project; it should be built without any error or warning messages.
#include "RTOS.h"
#include "BSP.h"
/*********************************************************************
*
* main
*
*********************************************************************/
int main(void) {
OS_IncDI(); /* Initially disable interrupts */
OS_InitKern(); /* initialize OS */
OS_InitHW(); /* initialize Hardware for OS */
BSP_Init(); /* initialize LED ports */
/* You need to create at least one task before calling OS_Start() */
OS_CREATETASK(&TCBHP, "HP Task", HPTask, 100, StackHP);
OS_CREATETASK(&TCBLP, "LP Task", LPTask, 50, StackLP);
OS_Start(); /* Start multitasking */
return 0;
}
PPCF-1 9
Before you step into OS_Start(), you should set two breakpoints in the two tasks as shown below.
As OS_Start() is part of the PowerPac RTOS library, you can step through it in disassembly mode only.
Click GO, step over OS_Start(), or step into OS_Start() in disassembly mode until you reach the highest priority
task.
If you continue stepping, you will arrive in the task that has the lower priority:
Continue to step through the program, there is no other task ready for execution. PowerPac RTOS will therefore start
the idle-loop, which is an endless loop which is always executed if there is nothing else to do (no task is ready, no
interrupt routine or timer is executing).
The function OS_Idle() is part of RTOSInit*.c. Step into the OS_Delay() function to reach the idle-loop. You
may also set a breakpoint there before you step over the delay in LPTask.
If you set a breakpoint in one or both of our tasks, you will see that they continue execution after the given delay.
PPCF-1 11
As can be seen by the value of the timer variable OS_Time, displayed in the Watch window, HPTask continues
operation after expiration of the 10 ms delay.
Getting started
To build your own application, you should always start with one of the supplied example workspaces and projects.
Therefore, select a workspace as described in First steps on page 7 and modify the project to fit your needs. Using a
sample project as a starting point has the advantage that all necessary files are included and all settings for the project
are already done.
PPCF-1 13
Select another CPU
PowerPac RTOS for ColdFire contains CPU-specific code for various ColdFire cores. The folder BoardSupport
contains workspaces for different target CPUs and specific evaluation boards.
Check whether your CPU is supported by PowerPac RTOS. CPU-specific functions are located in the Setup subfolder
in each board support project folder. To select a CPU which is already supported, just select the appropriate project
from the Example application list in the Embedded Workbench Startup dialog box.
If your CPU is currently not supported, examine all RTOSInit files in the CPU-specific subfolders and select one
which almost fits your CPU. You may have to modify OS_InitHW(), OS_COM_Init(), and the interrupt service
routines for PowerPac RTOS timer tick.
Available libraries
PowerPac RTOS for Freescale ColdFire is shipped with 14 different libraries, one for each code model/library mode
combination.
The libraries are named as follows:
os<CodeModel><LibMode>.r68
Parameter Description Values
CodeModel Specifies the code model. n: near code model
f: far code model
LibMode Library mode XR: Release without round-
robin and task names.
R: Release
S: Stack check
D: Debug
Table 2: Library naming conventions
Example
cfrtosndp.r68 is the library for a project using the near code model with debug and profiling support.
PPCF-1 15
IAR PowerPac™ RTOS
16 Freescale ColdFire® Cores PPCF-1
Compiler specifics
Standard system libraries
PowerPac RTOS for Freescale ColdFire and IAR Embedded Workbench may be used with standard IAR Embedded
Workbench system libraries for most of all projects.
The heap management and file operation functions included in the standard system libraries are not reentrant and can
therefore not be used with PowerPac RTOS, if non thread safe-functions are used from different tasks.
For heap management, PowerPac RTOS delivers its own thread-safe functions which can be used. These functions are
described in PowerPac RTOS CPU independent manual.
PPCF-1 17
IAR PowerPac™ RTOS
18 Freescale ColdFire® Cores PPCF-1
Stacks
This chapter describes the handling of stacks.
PPCF-1 19
IAR PowerPac™ RTOS
20 Freescale ColdFire® Cores PPCF-1
Interrupts
This chapter describes the handling of interrupts.
The Freescale ColdFire core comes with a built in vectored interrupt controller which supports up to 57 separate
interrupt sources. The real number of interrupt sources depends on the specific target CPU.
void OS_ISR_TickHandler(void) {
PIT0_PMR |= PIT_PCSR_PIF; /* reset Timer interrupt flag */
OS_HandleTick();
}
PPCF-1 21
Interrupt priorities
Due to the introduction of fast interrupts, interrupt priorities useable for interrupts using PowerPac RTOS API
functions are limited.
● Any interrupt handler using PowerPac RTOS API functions has to execute with interrupt priorities from 0 to 4.
● Any Fast interrupt (running at priorities from 5 to 7) must not call any PowerPac RTOS API function. Even
OS_EnterInterrupt() and OS_LeaveInterrupt() must not be called.
Note:The priority limit between PowerPac RTOS interrupts and Fast interrupts is fixed to 5 and can only be changed
by recompiling the PowerPac RTOS libraries.
Return value
The address of the previous installed interrupt function, which was installed at the previous vector number address.
Additional information
This function installs the interrupt vector and modifies the priority and automatically enables the interrupt in the
interrupt controller by setting the interrupt mask.
Prototype
Ovoid OS_DisableISR(int ISRIndex);
Parameter Description
ISRIndex Index of the interrupt source which should be disabled.
Table 5: OS_DisableISR () parameter list
Additional information
This function disables the interrupt inside the interrupt controller. The function does not disable the interrupt of any
peripherals. This has to be done elsewhere.
PPCF-1 23
IAR PowerPac™ RTOS
24 Freescale ColdFire® Cores PPCF-1
Technical data
This chapter includes information about the memory requirements of PowerPac RTOS.
Memory requirements
These values are neither precise nor guaranteed but they give you a good idea of the memory-requirements. They vary
depending on the current version of PowerPac RTOS. The kernel itself has a minimum ROM size requirement of about
1.700 bytes.
In the table below, you can find the minimum RAM size for PowerPac RTOS resources for a release build. Note that
sizes depend on the selected PowerPac RTOS library mode.
Resource semaphore 8
Counting semaphore 4
Mailbox 20
Software timer 20
Table 6: Memory requirements
PPCF-1 25
IAR PowerPac™ RTOS
26 Freescale ColdFire® Cores PPCF-1
Files shipped with PowerPac RTOS
Use this chapter as template for all following chapters.
The following table gives an overview about all PowerPac RTOS related deliverables:
.\BoardSupport Start.* Example workspaces and project files for IAR Embedded
Workbench, including CPU-specific hardware routines for
various CPUs and starter boards.
.\RTOS\Example OS_Error.c PowerPac RTOS runtime error handler used in stack check
or debug builds.
Table 7: Files shipped with PowerPac RTOS
PPCF-1 27
IAR PowerPac™ RTOS
28 Freescale ColdFire® Cores PPCF-1
Index System stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
T
trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
C V
copyright notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
version, IAR Embedded Workbench . . . . . . . . . . . . . . . . . . . . . 2
D
disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
document conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
E
edition, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
G
guidelines, reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
I
Interrupt priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Interrupt stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Interrupt vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
M
Memory models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Memory requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
O
OS_DisableISR() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
OS_EnableISR() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
P
part number, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
publication date, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
R
reading guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
registered trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
S
Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Syntax, conventions used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
System libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
PPCF-1 29