IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7...

33
PP430-1 IAR PowerPac™ RTOS for Texas Instruments’ MSP430 Microcontroller Family CPU and compiler specifics

Transcript of IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7...

Page 1: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

PP430-1

IAR PowerPac™ RTOSfor Texas Instruments’

MSP430 Microcontroller Family

CPU and compiler specifics

Page 2: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

PP430-1

COPYRIGHT NOTICE© Copyright 2008 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.

DISCLAIMERThe 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.

TRADEMARKSIAR Systems, IAR Embedded Workbench, C-SPY, visualSTATE, From Idea To Target, IAR KickStart Kit, IAR PowerPac, IAR YellowSuite, IAR Advanced Development Kit, IAR, and the IAR Systems logotype are trademarks or registered trademarks owned by IAR Systems AB. J-Link is a trademark licensed to 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: June 2008

Part number: PP430-1

Internal reference: ISUD.

Page 3: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

ContentsPreface ........................................................................................................................................................................ 5

Using IAR 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

Required files for an application ............................................................................................................... 13

Change library mode .................................................................................................................................. 13

Select another CPU .................................................................................................................................... 13

MSP430 specifics ................................................................................................................................................... 15

Data / Memory models, compiler options ............................................................................................. 15

Available libraries ........................................................................................................................................ 15

Low-Power Modes ....................................................................................................................................... 16

Compiler specifics ................................................................................................................................................ 21

Standard system libraries .......................................................................................................................... 21

Stacks ........................................................................................................................................................................ 23

Task stack for MSP430 ............................................................................................................................... 23

System stack for MSP430 .......................................................................................................................... 23

Interrupt stack for MSP430 ....................................................................................................................... 23

Stack specifics of the MSP430 family ...................................................................................................... 23

Stack specifics of the MSP430X family ................................................................................................... 23

MSP430 clock specifics ....................................................................................................................................... 25

Introduction .................................................................................................................................................. 25

IAR PowerPac RTOS timer clock source .............................................................................................. 25

Interrupts ................................................................................................................................................................ 27

What happens if an interrupt occurs ...................................................................................................... 27

Defining interrupt handlers in C .............................................................................................................. 27

Interrupt-stack ............................................................................................................................................. 27

Technical data ......................................................................................................................................................... 29

Memory requirements ............................................................................................................................... 29

Files shipped with IAR PowerPac RTOS ........................................................................................................ 31

Index ......................................................................................................................................................................... 33

PP430-1 3

Page 4: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

4

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 5: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

PrefaceWelcome to IAR PowerPac™ RTOS for Texas Instruments’ MSP430 Microcontroller Family. This guide describes how to use IAR PowerPac RTOS for the MSP430 Microcontroller Family and IAR Embedded Workbench®.

Who should read this guideYou should read this guide if you plan to develop an embedded system using IAR PowerPac RTOS and need to get information about the CPU and compiler specifics using.

How to use this guide This guide describes all CPU and compiler specifics of IAR PowerPac RTOS using ARM-based controllers. Before actually using IAR PowerPac RTOS, you should read or at least glance through this guide to become familiar with the software.

The chapter Using IAR PowerPac RTOS with IAR Embedded Workbench® gives you a step-by-step introduction, how to use IAR PowerPac RTOS for MSP430. If you have no experience using IAR PowerPac RTOS, you should follow this introduction, because it is an easy way to learn how to use IAR PowerPac RTOS in your application.

Most of the other chapters in this guide are intended to provide you with important detailed information about functionality and fine-tuning of IAR PowerPac RTOS for the MSP430-based controllers.

Document conventions

TYPOGRAPHIC CONVENTIONS FOR SYNTAXThis guide uses the following typographic conventions:

Style Description

KeywordText that you enter at the command-prompt or that appears on the display (that is system 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

PP430-1 5

Page 6: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

6

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 7: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Using IAR PowerPac RTOS with IAR Embedded WorkbenchThis chapter describes how to start with and use IAR PowerPac RTOS for Texas Instruments MSP430 and IAR Embedded Workbench. You should follow these steps to become familiar with IAR PowerPac RTOS for Texas Instruments MSP430 and IAR Embedded Workbench.

First stepsAfter you installed IAR PowerPac RTOS you can create your first multitasking application. You received ready to use example workspaces and projects and it is recommended to use one of these as a starting point for all your applications.

Your IAR PowerPac RTOS distribution contains a BoardSupport folder which contains the example workspaces and projects and every additional files used for building your application.

To get your new application running, follow these steps:

1 Create a working directory for your application, for example c:\work.

2 In the IAR Embedded Workbench IDE, choose Help | Startup Screen. Select Example Application in the Startup dialog box.

3 Select RTOS from the Example Application list.

4 Select the project which is consistent to your hardware, or start with the IAR Simulator project.

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:

PP430-1 7

Page 8: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

8

6 Build the project; it should be built without any error or warning messages.

The example application Start_LEDBlink.cThe following is a printout of the example application Start_LEDBlink.c. It is a good starting point for your application. Note that the file included in your IAR PowerPac RTOS installation might look slightly different from this one.

What happens is easy to see:

After initialization of IAR PowerPac RTOS; two tasks are created and started.The two tasks are activated and they execute until they run into the delay. They are then suspended for the specified time and then they continue to execute.

#include "RTOS.h"#include "BSP.h"

OS_STACKPTR int StackHP[128], StackLP[128]; /* Task stacks */OS_TASK TCBHP, TCBLP; /* Task-control-blocks */

static void HPTask(void) { while (1) { BSP_ToggleLED(0); OS_Delay (50); }}

static void LPTask(void) { while (1) { BSP_ToggleLED(1); OS_Delay (200); }}

/*********************************************************************** 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;}

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1

Page 9: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Using IAR PowerPac RTOS with IAR Embedded Workbench

Stepping through the example application using C-SPYWhen you start the debugger, you will see the main function (see example screenshot below). The main function appears as long as the C-SPY option Run to main is selected, which it is by default.

1 Now you can step through the program. OS_IncDI() initially disables interrupts. OS_InitKern() is part of the IAR PowerPac RTOS library and it is written in assembler; you can therefore only step into it in disassembly mode. The function initializes the relevant OS variables. Because of the previous call of OS_IncDI(), interrupts are not enabled during execution of OS_InitKern(). OS_InitHW() is part of RTOSInit_*.c and therefore part of your application. Its primary purpose is to initialize the hardware required to generate the timer-tick-interrupt for IAR PowerPac RTOS. Step through it to see what is done. OS_Start() is the last line in main, because it starts the multitasking and does not return.

2 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 IAR PowerPac RTOS library, you can step through it in disassembly mode only.

9PP430-1

Page 10: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

10

3 Click GO, step over OS_Start(), or step into OS_Start() in disassembly mode until you reach the highest priority task.

4 If you continue stepping, the program execution will reach the task that has the lower priority:

5 Continue to step through the program, there is no other task ready for execution. IAR PowerPac RTOS will therefore start the idle-loop, which is an endless loop that is always executed if there is nothing else to do (no task is ready, no interrupt routine or timer is executing).

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1

Page 11: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Using IAR PowerPac RTOS with IAR Embedded Workbench

6 The function OS_Idle() is part of RTOSInit*.c. Step into the OS_Delay() function to reach the idle-loop. You can also set a breakpoint there before you step over the delay in LPTask.

If you set a breakpoint in one or both of your tasks, you will see that they continue execution after the given delay.

7 As can be seen by the value of the timer variable OS_Time, displayed in the Watch window, HPTask continues operation the 10-ms delay has expired.

11PP430-1

Page 12: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

12

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 13: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Building an applicationThis chapter explains how to set up up your own IAR PowerPac RTOS project.

To build your own application, you should always start with one of the supplied example workspaces and projects. Therefore, select an IAR PowerPac RTOS 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.

Required files for an applicationTo build an application using IAR PowerPac RTOS, the following files from your IAR PowerPac RTOS distribution are required and have to be included in your project:

● RTOS.h available in the subfolder RTOS\Inc\.This header file declares all API functions and data types and has to be included in any source file using IAR PowerPac RTOS functions.

● RTOSInit_*.c available in the subfolder BoardSupport\[DeviceName]\Setup.The file contains hardware-dependent initialization code for the IAR PowerPac RTOS timer.

● One IAR PowerPac RTOS library from the subfolder RTOS\Lib\.● OS_Error.c from subfolder BoardSupport\[DeviceName]\Setup\.

The error handler is used if any library other than the Release build library is used in your project.● Additional low-level initialization code might be required by the CPU.

When you decide to write your own startup code or use a __low_level_init function, ensure that non-initialized variables are initialized with zero, according to the C standard. This is required for some IAR PowerPac RTOS internal variables.Also ensure, that main() is called with the CPU running in thread mode using the main stack.Your main() function has to initialize IAR PowerPac RTOS by calling OS_InitKern() and OS_InitHW() prior to any other IAR PowerPac RTOS functions are called.You should then modify or replace the Start_2Task.c source file in the subfolder BoardSupport\[DeviceName]\Application\.

Change library modeFor your application you might want to choose another library. For debugging and program development you should use a debug library. For your final application you might want to use a release library or a stack check library.

Therefore, you have to select or replace the IAR PowerPac RTOS library in your project:

● If your selected library is already available in your project, just select the appropriate configuration.● To add a library, you can add a new Lib group to your project and add this library to the new group. Exclude all

other library groups from the build. Delete unused Lib groups or remove them from the configuration.● Check and set the appropriate OS_LIBMODE_* symbol as preprocessor option in the Preprocessor option dialog

box.Define OS_LIBMODE_D for a debug library, OS_LIBMODE_R for a release library, OS_LIBMODE_XR for an extreme release library, OS_LIBMODE_S for a stack check library.

Select another CPUIAR PowerPac RTOS for MSP430 contains CPU-specific code for various MSP430 cores. The folder BoardSupport contains workspaces for different target CPUs and specific evaluation boards.

PP430-1 13

Page 14: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

14

Check whether your CPU is supported by IAR 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 might have to modify OS_InitHW() and the interrupt service routines for IAR PowerPac RTOS timer tick.

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1

Page 15: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

MSP430 specifics

Data / Memory models, compiler optionsIAR PowerPac RTOS for MSP430 is delivered with libraries for the most common data models and other optional settings used by the ARM Embedded Workbench IDE.

For MSP430 devices, the IAR compiler offers one data model:

For MSP430X devices, the IAR compiler offers three data models:

With IAR PowerPac RTOS these limitations exist:● The medium data model for MSP430X is not supported.● The options that control R4 and R5 utilization must be set to Normal use.

Available librariesIAR PowerPac RTOS for Texas Instruments MSP430 is shipped with different libraries, one for each code model/library mode combination.

The libraries are named as follows:

os<Architecture><DataModel><SizeOfDouble><LibMode>.r43

Example

os430sf_D.r43 is the library for an MSP430 project using 32-bit floating-point calculation and debug support.32-bit64-bit

Data Model Default memory attribute Data placement

Small __data16 0-0xFFFF

Table 2: MSP430 data model

Data Model Default memory attribute Data placement

Small __data16 0-0xFFFF

Medium __data16, __data20 possible 0-0xFFFF

Large __data20 0-0xFFFFF

Table 3: MSP430 data models

Parameter Description Values

Architecture Specifies the CPU variant. 430: MSP430

430x: MSP430x extended addr.

DataModel Selected data model, only for s: Small data model

MSP430x CPUs l: Large data model

SizeOfDouble Floating point precision. f: 32-bit floating point

d: 64-bit floating point

LibMode Library mode XR: Extreme release, a release without round- robin and task names.

R: Release

S: Stack check

D: Debug

Table 4: Library naming conventions

PP430-1 15

Page 16: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

16

For MSP430 CPUs, the following IAR PowerPac RTOS libraries are available:

Note:For MSP430 CPUs, only the small data model is available.

For MSP430x CPUs, the following IAR PowerPac RTOS libraries are available:

Note:For MSP430X CPUs, the Medium data model is not supported by IAR PowerPac RTOS.

Ensure that the defined symbol, according to the library type used, is set as compiler option in your project.

Choose Project | Options | C/C++ compiler | Preprocessor | Defined symbols and specify the appropriate symbol.

Low-Power ModesUsing low-power modes is one possibility to save power consumption during idle times. If required, you should modify the OS_Idle() routine, which is part of the hardware dependent module RtosInit_*.c to enter a low-power mode.

Library name Data model, options Libmode #define

os430sf_XR.r43 small, 32-bit float Extreme Release OS_LIBMODE_XR

os430sf_R.r43 small, 32-bit float Release OS_LIBMODE_R

os430sf_S.r43 small, 32-bit float Stack check OS_LIBMODE_S

os430sf_D.r43 small, 32-bit float Debug OS_LIBMODE_D

os430sd_XR.r43 small, 64-bit float Extreme Release OS_LIBMODE_XR

os430sd_R.r43 small, 64-bit float Release OS_LIBMODE_R

os430sd_S.r43 small, 64-bit float Stack check OS_LIBMODE_S

os430sd_D.r43 small, 64-bit float Debug OS_LIBMODE_D

Table 5: MSP430 prebuilt libraries

Library name Data model, options Libmode #define

os430xsf_XR.r43 small, 32-bit float Extreme Release OS_LIBMODE_XR

os430xsf_R.r43 small, 32-bit float Release OS_LIBMODE_R

os430xsf_S.r43 small, 32-bit float Stack check OS_LIBMODE_S

os430xsf_D.r43 small, 32-bit float Debug OS_LIBMODE_D

os430xsd_XR.r43 small, 64-bit float Extreme Release OS_LIBMODE_XR

os430xsd_R.r43 small, 64-bit float Release OS_LIBMODE_R

os430xsd_S.r43 small, 64-bit float Stack check OS_LIBMODE_S

os430xsd_D.r43 small, 64-bit float Debug OS_LIBMODE_D

os430xlf_XR.r43 large, 32-bit float Extreme Release OS_LIBMODE_XR

os430xlf_R.r43 large, 32-bit float Release OS_LIBMODE_R

os430xlf_S.r43 large, 32-bit float Stack check OS_LIBMODE_S

os430xlf_D.r43 large, 32-bit float Debug OS_LIBMODE_D

os430xld_XR.r43 large, 64-bit float Extreme Release OS_LIBMODE_XR

os430xld_R.r43 large, 64-bit float Release OS_LIBMODE_R

os430xld_S.r43 large, 64-bit float Stack check OS_LIBMODE_S

os430xld_D.r43 large, 64-bit float Debug OS_LIBMODE_D

Table 6: MSP430X prebuilt libraries

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1

Page 17: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

MSP430 specifics

Do not enter a Low-Power mode which stops the IAR PowerPac RTOS timer, as this would stop time scheduled task activations. If the IAR PowerPac RTOS timer is driven from the main clock, LPM0 or LPM1 should be selected during OS_Idle(). When ACLK is used for IAR PowerPac RTOS timer, LPM2 or LPM3 may also be used.

The following seven power modes are supported by MSP430X5xx devices:

Active mode AM● All clocks are active.

Low-power mode 0 (LPM0)● CPU is disabled.● ACLK and SMCLK remain active. MCLK is disabled.

Low-power mode 1 (LPM1)● CPU is disabled.● ACLK and SMCLK remain active. MCLK is disabled.● DCO’s dc-generator is disabled if DCO not used in active mode.

Low-power mode 2 (LPM2)● CPU is disabled.● MCLK and SMCLK are disabled.● DCO’s dc-generator remains enabled.● ACLK remains active.

Low-power mode 3 (LPM3)● CPU is disabled.● MCLK and SMCLK are disabled.● DCO’s dc-generator is disabled.● ACLK remains active.

Low-power mode 4 (LPM4);● CPU is disabled.● ACLK is disabled.● MCLK and SMCLK are disabled.● DCO’s dc-generator is disabled.● Crystal oscillator is stopped.

Low-power mode 5 (LPM5);● When PMMREGOFF = 1, regulator disabled. No memory retention.

POWER MANAGEMENT API FUNCTIONS

OS_POWER_UsageDec()Description

Decrements power management counters.

Prototypevoid OS_POWER_UsageDec( OS_UINT Index );

Routine Description

OS_POWER_GetMask Returns a mask that shows which power management counters are set.

OS_POWER_UsageDec Decrements power management counters.

OS_POWER_UsageInc Increments power management counters.

Table 7: Power management API

Parameter Description

Index Contains a bit mask. Each bits stands for a counter which should be updated. For example, Bit0 is Counter0, Bit1 is Counter1, ...

Table 8: OS_POWER_UsageDec() parameter list

17PP430-1

Page 18: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

18

Additional Information

The debug version checks for underflow, overflow and undefined counter number.

OS_POWER_UsageInc()Description

Increments power management counters.

Prototypevoid OS_POWER_UsageInc( OS_UINT Index );

Additional Information

The debug version checks for underflow, overflow and undefined counter number.

Example

This example is excerpt from Rtosinit_XMS430F5438.c.

/*********************************************************************** OS_InitHW()** Initialize the hardware (timer) required for embOS to run.* May be modified, if an other timer should be used*/void OS_InitHW(void) { OS_IncDI(); /* Ensure, interrupts are disabled */ TA0CTL = 0 /* Reset Timer_A5, division 1 */ | (1 << 2) /* Clear timer */ | (2 << 8) /* Use SMCLK as timer clock */ ; TA0CCR0 = (OS_PCLK_TIMER / 1000) - 1; /* Set to 1ms */ TA0CCTL0 = 0 /* Initilize capture control */ | (1 << 4); /* Enable compare interrupt */ TA0CTL |= (1 << 4); /* Start timer in UP-Mode */ OS_POWER_UsageInc(OS_POWER_USE_SMCLK); /* Mark SMCLK as used */ OS_COM_Init(); /* Initialize UART */ OS_DecRI(); /* Restore interrupt context */}

The available clocks are defined in RTOS.h:

#define OS_POWER_USE_ACLK (1 << 0)#define OS_POWER_USE_MCLK (1 << 1)#define OS_POWER_USE_SMCLK (1 << 2)

Parameter Description

Index Contains a bit mask. Each bits stands for a counter which should be updated. For example, Bit0 is Counter0, Bit1 is Counter1, ...

Table 9: OS_POWER_UsageInc() parameter list

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1

Page 19: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

MSP430 specifics

OS_POWER_GetMask()Description

Returns a mask that shows which power management counters are set.

PrototypeOS_UINT OS_POWER_GetMask( void );

Example

This example is excerpt from Rtosinit_XMS430F5438.c.

/*********************************************************************** Idle loop (OS_Idle)** Please note:* This is basically the "core" of the idle loop.* This core loop can be changed, but:* The idle loop does not have a stack of its own, therefore no* functionality should be implemented that relies on the stack* to be preserved. However, a simple program loop can be programmed* (like toggeling an output or incrementing a counter)** We just enter low power 0 mode here.*/void OS_Idle(void) { /* Idle loop: No task is ready to exec */ OS_UINT PowerMask; OS_U16 ClkControl;

OS_DI(); // // Examine which peripherals may be switched off */ // PowerMask = OS_POWER_GetMask(); // // Switch off peripherals which are not needed // ClkControl = UCSCTL8 & ~OS_POWER_USE_ALL; PowerMask &= OS_POWER_USE_ALL; UCSCTL8 = ClkControl | PowerMask; // // Nothing to do ... enter low power mode, with interrupts enabled // _BIS_SR(GIE+CPUOFF+OSCOFF+SCG1+SCG0); for (;;); /* Alternative endless loop, required */ /* when simulator is used ! */}

19PP430-1

Page 20: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

20

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 21: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Compiler specifics

Standard system librariesIAR PowerPac RTOS for Texas Instruments MSP430 can be used with standard IAR Embedded Workbench system libraries for most projects.

The heap management and file operation functions included in the standard system libraries are not reentrant and can therefore not be used with IAR PowerPac RTOS, if non thread safe-functions are used from different tasks.

For heap management, IAR PowerPac RTOS delivers its own thread-safe functions which can be used. These functions are described in the IAR PowerPac™ RTOS User Guide.

PP430-1 21

Page 22: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

22

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 23: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

StacksThis chapter describes the handling of stacks.

Task stack for MSP430Every IAR PowerPac RTOS task has to have its own stack. Task stacks can be located in any RAM memory location. The stack-size required is the sum of the stack size of all routines plus basic stack size. The basic stack size is the size of memory required to store the registers of the CPU plus the stack size required by IAR PowerPac RTOS routines.

System stack for MSP430The system stack size required by IAR PowerPac RTOS is about 30 bytes. However, because the system stack is also used by the application before the start of multitasking (the call to OS_Start()), and because software timers and IAR PowerPac RTOS internal scheduling functions also use the system stack, the actual stack requirements depend on the application. The size of the system stack is specified in the linker command file as size of CSTACK. We recommend a minimum of 80 bytes.

Interrupt stack for MSP430MSP430 CPUs do not support a separate interrupt stack pointer. Interrupts use the stack of the running application. Therefore, interrupts occupy additional stack space on every task and on the system stack.

Stack specifics of the MSP430 familyThe MSP430 family of microcontroller can address up to 64 Kbytes of memory. Because the stack pointer can address the entire memory area, stacks can be located anywhere in RAM.

Stack specifics of the MSP430X familyThe stack pointer of the MSP430X family of microcontroller can address the whole memory. Stacks can be located anywhere in RAM.

PP430-1 23

Page 24: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

24

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 25: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

MSP430 clock specificsThis chapter describes the options for the CPU and peripheral clock generation.

IntroductionMSP430 CPUs offer various options for the CPU and peripheral clock generation. You might need to modify the IAR PowerPac RTOS timer initialization function OS_InitHW() in RtosInit_*.c to fit your application. The example OS_InitHW() routine in RTOSInit_430F149.c uses the internal RC oscillator and DCO as CPU clock and selects this clock as source for the IAR PowerPac RTOS timer.

IAR PowerPac RTOS timer clock sourceThe IAR PowerPac RTOS timer can be driven from different clock sources. By default, MCLK is used as clock source for the timer. OS_InitHW() initializes the RC oscillator and DCO.

Using the RC oscillator

Using the RC oscillator and DCO has the advantage that no additional hardware is required. The disadvantage is that an exact frequency is not guaranteed. The frequency of MCLK has to be examined and OS_FSYS has to be adjusted to fit your application.

Using an external crystal

Using an external Main clock generator crystal has the advantage that the frequency is stable and precise. OS_InitHW() has to be modified to initialize the crystal oscillator. Check OS_FSYS and set a value that corresponds to your crystal frequency.

PP430-1 25

Page 26: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

26

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 27: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

InterruptsThis chapter describes the handling of interrupts.

What happens if an interrupt occurs● The CPU-core receives an interrupt request.● As soon as the interrupts are enabled, the interrupt is accepted.● The CPU saves PC and flags on the stack.● The CPU jumps to the address specified in the vector table for the interrupt service routine (ISR).● The ISR saves the registers.● The ISR executes user-defined functionality.● The ISR restores the registers from the stack.● The ISR executes the RETI command, restores the PC and the flags from the stack.● The interrupted function continuos executing.

Defining interrupt handlers in CRoutines defined with the keyword __interrupt automatically save and restore the registers they modify and return with RETI. The interrupt vector number has to be given as additional parameter by the #pragma vector directive prior the interrupt handler function. For a detailed description on how to define an interrupt routine in C, refer to the IAR C/C++ Compiler Reference Guide.

Example

A simple interrupt routine:

#prgama vector=12__interrupt void IntHandlerTimer(void) { IntCnt++;}

Interrupt-routine calling IAR PowerPac RTOS function#prgama vector=12__interrupt void IntHandlerTimer(void) { OS_EnterInterrupt(); /* Inform IAR PowerPac RTOS that interrupt function is running */ IntCnt++; OS_PutMailCond(&MB_Data, &IntCnt); OS_LeaveInterrupt();}

OS_EnterInterrupt() has to be the first function called in an interrupt handler using IAR PowerPac RTOS functions, when nestable interrupts are not required. OS_LeaveInterrupt() has to be called at the end of the interrupt handler. If interrupts should be nested, use OS_EnterNestableInterrupt() and OS_LeaveNestableInterrupt() instead.

Interrupt-stackBecause MSP430 CPUs do not provide a separate stack pointer for interrupts, every interrupt occupies additional stack space on the current stack. This can be the system stack or a task stack of a running task that is interrupted. The additional amount of necessary stack for all interrupts has to be reserved on all task stacks. The current version of IAR PowerPac RTOS for MSP430 does not support extra interrupt stack-switching in an interrupt routine. The routines OS_EnterIntStack() and OS_LeaveIntStack() are supplied for source code compatibility to other processors only and have no functionality.

PP430-1 27

Page 28: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

28

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 29: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Technical dataThis chapter includes information about the memory requirements of IAR PowerPac RTOS.

Memory requirementsThese 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 IAR 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 IAR PowerPac RTOS resources for a release build. Note that sizes depend on the selected IAR PowerPac RTOS library mode.

IAR PowerPac RTOS resource ROM [bytes] RAM [bytes]

Kernel approx. 1208 28

Event management < 200 --

Mailbox management < 550 --

Single-byte mailbox management < 300 --

Timer management < 250 --

Additional task -- 18

Additional counting semaphore -- 4

Additional resource semaphore -- 8

Additional mailbox -- 12

Additional timer -- 12

Power management -- --

Table 10: Memory requirements

PP430-1 29

Page 30: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

30

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 31: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Files shipped with IAR PowerPac RTOS

The following table gives an overview about all IAR PowerPac RTOS related deliverables:

Directory File Explanation

.\Doc *.pdf Generic API and target-specific documentation.

.\BoardSupport Start*.* Example workspaces and project files for IAR Embedded Workbench, including CPU-specific hardware routines for various CPUs and starter boards.

.\RTOS\Inc RTOS.h Include file for IAR PowerPac RTOS, to be included in every C-file using IAR PowerPac RTOS functions.

.\RTOS\Lib os*.r43 IAR PowerPac RTOS libraries.

.\RTOS\Application *.c Example programs to serve as a start.

.\RTOS\Example OS_Error.c IAR PowerPac RTOS runtime error handler used in stack check or debug builds.

Table 11: Files shipped with IAR PowerPac RTOS

PP430-1 31

Page 32: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

32

IAR PowerPac™ RTOSfor Texas Instruments’ MSP430 Microcontroller Family PP430-1
Page 33: IAR PowerPac™ RTOSsupp.iar.com/.../UPDINFO/004723/PowerPac/doc/PowerPac_RTOS_MS… · PP430-1 7 Using IAR PowerPac RTOS with IAR Embedded Workbench This chapter describes how to

Index

Index

CCompiler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15

copyright notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

DData models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15

disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2document conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

Eedition, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

Gguidelines, reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

IInterrupt stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23

Interrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

LLibrary mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Library naming convention . . . . . . . . . . . . . . . . . . . . . . . . . . . .15

Low-Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16

MMemory models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15

Memory requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29

Ppart number, of this guide. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

Power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

OS_POWER_GetMask(). . . . . . . . . . . . . . . . . . . . . . . . . . . .19

OS_POWER_UsageDec() . . . . . . . . . . . . . . . . . . . . . . . . . . .17

OS_POWER_UsageInc() . . . . . . . . . . . . . . . . . . . . . . . . . . .18

publication date, of this guide . . . . . . . . . . . . . . . . . . . . . . . . . . .2

Rreading guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

registered trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

SStacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Syntax, conventions used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

System libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

System stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

TTimer clock source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Vversion, IAR Embedded Workbench . . . . . . . . . . . . . . . . . . . . . 2

33PP430-1