IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Similar documents
embos Real Time Operating System CPU & Compiler specifics for Texas Instruments MSP430 CPUs and Rowley compiler for MSP430 Document Rev.

embos Real-Time Operating System CPU & Compiler specifics for Texas Instruments using TI Code Composer for MSP430

IAR PowerPac RTOS for ARM Cores

embos Real Time Operating System CPU & Compiler specifics for RENESAS M16C CPUs and HEW workbench Document Rev. 1

embos Real Time Operating System CPU & Compiler specifics for ARM core with ARM RealView Developer Suite 3.0 Document Rev. 1

embos Real Time Operating System CPU & Compiler specifics for RENESAS SH2 CPUs and RENESAS HEW4 Document Rev. 1

embos Real Time Operating System CPU & Compiler specifics for RENESAS M16C CPUs and IAR compiler Document Rev. 5

embos Real Time Operating System CPU & Compiler specifics for PIC18 core using C18 compiler and MPLAB

embos Real-Time Operating System CPU & Compiler specifics for embos Visual Studio Simulation

embos Real Time Operating System CPU & Compiler specifics for RENESAS SH2A CPUs and KPIT GNU compiler Document Rev. 1

embos Real-Time Operating System CPU & Compiler specifics for Renesas RX using Renesas CCRX compiler and e2studio

embos Real-Time Operating System CPU & Compiler specifics for RH850 using IAR

embos Real-Time Operating System CPU & Compiler specifics for SH2A core using IAR Embedded Workbench

embos Real-Time Operating System CPU & Compiler specifics for Renesas RX using IAR compiler for RX

embos Real-Time Operating System CPU & Compiler specifics for Renesas RH850 and IAR

embos Real-Time Operating System CPU & Compiler specifics for Renesas RX using KPIT GNU tools

embos Real-Time Operating System CPU & Compiler specifics for ARM core using Keil MDK

embos Real-Time Operating System CPU & Compiler specifics for RZ core using KPIT GNU and ARM DS-5

embos Real-Time Operating System CPU & Compiler specifics for Cortex- M using Rowley CrossStudio for ARM

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.1 Revision: 0 Date: May 3, 2018

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.0 Revision: 0 Date: September 18, 2017

embos Real-Time Operating System CPU & Compiler specifics for ARM core using Atollic TrueStudio

IAR C-SPY Hardware Debugger Systems User Guide

embos Real-Time Operating System CPU & Compiler specifics for ARM core using GCC / emide

IAR Embedded Workbench

embos Real-Time Operating System CPU & Compiler specifics for Cortex M using Atmel Studio

IAR Embedded Workbench

IAR C-SPY Hardware Debugger Systems User Guide. for Renesas E30A/E30 Emulators

embos Real-Time Operating System CPU & Compiler specifics for Document: UM01039 Software Version: 5.02 Revision: 0 Date: June 26, 2018

Getting Started with IAR Embedded Workbench for Renesas Synergy

embos Operating System CPU & Compiler specifics for Altera SoC using ARM DS-5 and GNU compiler

IAR Embedded Workbench

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document C28X CCS

H8 C-SPY. User Guide WINDOWS WORKBENCH VERSION

Lab 1: I/O, timers, interrupts on the ez430-rf2500

ATOLLIC TRUESTUDIO FOR STM32 QUICK START GUIDE

Lab 4 Interrupts ReadMeFirst

Introduction to the ThreadX Debugger Plugin for the IAR Embedded Workbench C-SPYDebugger

MetaWatch Firmware Design Guide

Application Note. Using embos tickless support with STM32

Programming in the MAXQ environment

ATOLLIC TRUESTUDIO FOR ARM QUICK START GUIDE

Timer Module Timer A. ReadMeFirst

Integrating a visualstate application with a Real-Time Operating System (RTOS)

5/11/2012 CMSIS-RTOS. Niall Cooling Feabhas Limited CMSIS. Cortex Microcontroller Software Interface Standard.

real-time kernel documentation

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document MSP430/X CCS

ZiLOG Real-Time Kernel Version 1.2.0

Installation and Licensing Guide for the IAR Embedded Workbench

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ARM Cortex-M3 CCS

Getting Started. with IAR Embedded Workbench GSEW-2

MSP430 IAR Embedded Workbench IDE User Guide. for Texas Instruments MSP430 Microcontroller Family

Getting Started with the Texas Instruments ez430

ECE PRACTICE EXAM #2 Clocks, Timers, and Digital I/O

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega128 IAR

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document MSP430 IAR

CODE TIME TECHNOLOGIES. Abassi RTOS. CMSIS Version 3.0 RTOS API

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

IAR PowerPac File System User Guide

Texas Instruments Mixed Signal Processor Tutorial Abstract

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega IAR

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ARM Cortex-A9 CCS

IAR Embedded Workbench

Team 3. By: Miriel Garcia. Microcontrollers/ TI MSP430F5438A. ECE 480 senior Design. Application Note 4/3/15

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document MSP430 GCC

CPE 323: MSP430 Timers

IAR PowerPac RTOS User Guide

Getting Started with the MSP430 IAR Assembly

AT09381: SAM D - Debugging Watchdog Timer Reset. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

IAR PowerPac USB User Guide

Lab 4: Interrupt. CS4101 Introduction to Embedded Systems. Prof. Chung-Ta King. Department of Computer Science National Tsing Hua University, Taiwan

Zilog Real-Time Kernel

PICMICRO C-SPY. User Guide

Viewing the tm4c123gh6pm_startup_ccs.c file, the first piece of code we see after the comments is shown in Figure 1.

CPE 323: Laboratory Assignment #1 Getting Started with the MSP430 IAR Embedded Workbench

IDE Project Management and Building Guide

IAR C/C++ Compiler Reference Guide

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega128 GCC

IAR Embedded Workbench MISRA C:2004. Reference Guide

AN10955 Full-duplex software UART for LPC111x and LPC13xx

IDE Project Management and Building Guide

EMBEDDED SYSTEMS: Jonathan W. Valvano INTRODUCTION TO THE MSP432 MICROCONTROLLER. Volume 1 First Edition June 2015

DSP/BIOS Kernel Scalable, Real-Time Kernel TM. for TMS320 DSPs. Product Bulletin

IAR C/C++ Development Guide Compiling and linking

AN HONORS UNIVERSITY IN MARYLAND UMBC. AvrX. Yousef Ebrahimi Professor Ryan Robucci

Interrupt/Timer/DMA 1

Salvo Compiler Reference Manual CrossWorks for MSP430

AVR IAR Embedded Workbench IDE Migration Guide. for Atmel Corporation s AVR Microcontroller

Using the FreeRTOS Real Time Kernel

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. 8051/8052 Keil Compiler

Embedded System Curriculum

ssj1708 User s Manual Version 1.3 Revised February 2nd, 2009 Created by the J1708 Experts

Development Tools. 8-Bit Development Tools. Development Tools. AVR Development Tools

ECE2049: Embedded Computing in Engineering Design C Term Spring Lecture #11: More Clocks and Timers

BASICS OF THE RENESAS SYNERGY PLATFORM

Device support in IAR Embedded Workbench for 8051

Application Note. Startup DevKit16. History 19 th June 00 TKa V1.0 started 20 th June 00 TKa V1.1 Some minor text corrections

The ThreadX C-SPY plugin

Transcription:

IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family CPU and compiler specifics

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. 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 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: Internal reference: ISUD.

Contents Preface... 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 3

4 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Preface Welcome 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 guide You 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 SYNTAX This guide uses the following typographic conventions: Style Keyword Parameter Sample Reference GUIElement Emphasis Description Table 1: Typographic conventions Text that you enter at the command-prompt or that appears on the display (that is system functions, file- or pathnames). Parameters in API functions. Sample code in program examples. Reference to chapters, tables and figures or other documents. Buttons, dialog boxes, menu names, menu commands. Very important sections 5

6 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Using IAR PowerPac RTOS with IAR Embedded Workbench This 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 steps After 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: 7

6 Build the project; it should be built without any error or warning messages. The example application Start_LEDBlink.c The 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; } 8 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Using IAR PowerPac RTOS with IAR Embedded Workbench Stepping through the example application using C-SPY When 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. 9

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). 10 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

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

12 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Building an application This 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 application To 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 mode For 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 CPU IAR 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. 13

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. 14 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

MSP430 specifics Data / Memory models, compiler options IAR 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: Data Model Default memory attribute Data placement Small data16 0-0xFFFF Table 2: MSP430 data model For MSP430X devices, the IAR compiler offers three data models: 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 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 libraries IAR 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 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 roundrobin and task names. R: Release S: Stack check D: Debug Table 4: Library naming conventions Example os430sf_d.r43 is the library for an MSP430 project using 32-bit floating-point calculation and debug support.32- bit64-bit 15

For MSP430 CPUs, the following IAR PowerPac RTOS libraries are available: 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 Note:For MSP430 CPUs, only the small data model is available. For MSP430x CPUs, the following IAR PowerPac RTOS libraries are available: 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 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 Modes Using 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. 16 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

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 Routine OS_POWER_GetMask OS_POWER_UsageDec OS_POWER_UsageInc Table 7: Power management API Description Returns a mask that shows which power management counters are set. Decrements power management counters. Increments power management counters. OS_POWER_UsageDec() Description Decrements power management counters. Prototype void OS_POWER_UsageDec( OS_UINT Index ); 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 17

Additional Information The debug version checks for underflow, overflow and undefined counter number. OS_POWER_UsageInc() Description Increments power management counters. Prototype void OS_POWER_UsageInc( OS_UINT Index ); 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 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) 18 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

MSP430 specifics OS_POWER_GetMask() Description Returns a mask that shows which power management counters are set. Prototype OS_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! */ } 19

20 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Compiler specifics Standard system libraries IAR 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. 21

22 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Stacks This chapter describes the handling of stacks. Task stack for MSP430 Every 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 MSP430 The 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 MSP430 MSP430 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 family The 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 family The stack pointer of the MSP430X family of microcontroller can address the whole memory. Stacks can be located anywhere in RAM. 23

24 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

MSP430 clock specifics This chapter describes the options for the CPU and peripheral clock generation. Introduction MSP430 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 source The 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. 25

26 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Interrupts This 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 C Routines 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-stack Because 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. 27

28 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Technical data This chapter includes information about the memory requirements of IAR 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 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 29

30 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

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 31

32 IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

Index Index C Compiler options.....................................15 copyright notice.......................................2 D Data models.........................................15 disclaimer............................................2 document conventions..................................5 E edition, of this guide...................................2 G guidelines, reading.....................................5 I Interrupt stack.......................................23 Interrupts............................................27 L Library mode........................................13 Library naming convention............................15 Low-Power Modes...................................16 M Memory models......................................15 Memory requirements.................................29 P part 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 R reading guidelines..................................... 5 registered trademarks.................................. 2 S Stacks.............................................. 23 Syntax, conventions used............................... 5 System libraries...................................... 21 System stack......................................... 23 T Timer clock source................................... 25 trademarks........................................... 2 V version, IAR Embedded Workbench..................... 2 33