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

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

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 Renesas RX using IAR compiler for RX

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 Renesas RH850 and IAR

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 CPU & Compiler specifics for RENESAS M16C CPUs and HEW workbench Document Rev. 1

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 Renesas RX using KPIT GNU tools

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

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

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 RENESAS SH2 CPUs and RENESAS HEW4 Document Rev. 1

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

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 SH2A CPUs and KPIT GNU compiler Document Rev. 1

IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

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

SEGGER J-Scope. User Guide. Document: UM08028 Software Version: 5.10 Revision: 0 Date: November 26, 2015

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

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

Flasher ATE. Production Programmer. Getting Started. Document: AN08007 Manual Version: 1.0 Revision: 2 Date: January 9, 2018

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

IAR PowerPac RTOS for ARM Cores

embos/ip Switch Board

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

Application Note. Using embos tickless support with STM32

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

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

Application Note. embos/ip Migration Guide

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

emfile NAND Image Creator User & Reference Guide Document: UM02003 Software version: 1.03 Revision: 0 Date: November 16, 2016

empower Evaluation and prototyping platform for SEGGER software User Guide & Reference Manual

Micrium OS Kernel Labs

emload Bootstrap loader for embedded applications User Guide & Reference Manual

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document C28X CCS

BASICS OF THE RENESAS SYNERGY TM

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

Application Note. Analyzing HardFaults on Cortex-M CPU

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

emmodbus CPU independent Modbus stack for embedded applications User Guide & Reference Manual

BASICS OF THE RENESAS SYNERGY PLATFORM

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

RTX MiniTutorial APPLICATION PROFILING USING RTX TIME VIEW

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

emlib Library collection User & Reference Guide Document: UM12001 Software version: 1.0 Revision: 2 Date: January 7, 2016

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

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

real-time kernel documentation

IAR C-SPY Hardware Debugger Systems User Guide

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

SEGGER Eval Software

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

ERIKA Enterprise LWIP Tutorial

Lab 3-2: Exploring the Heap

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document AVR32A GCC

Zilog Real-Time Kernel

EMULATOR SETUP MB BIT COMPACT-ICE

ZiLOG Real-Time Kernel Version 1.2.0

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

Micrium µc/os II RTOS Introduction EE J. E. Lumpp


μc/os-ii Real-Time Kernel for CrossCore Embedded Studio version Release Notes Introduction

CODE TIME TECHNOLOGIES. µabassi RTOS. User s Guide

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

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

Seehau. Nohau Monitor (NMon) March 6, Nohau. All rights reserved worldwide.

GLOSSARY. VisualDSP++ Kernel (VDK) User s Guide B-1

A New Real-time Kernel development on an embedded platform

The CMXBug Manual. The CMXBug Manual

H8 C-SPY. User Guide WINDOWS WORKBENCH VERSION

µcos-ii Real-Time Kernel for CrossCore Embedded Studio version Release Notes What is µc/os-ii Real-Time Kernel for CrossCore Embedded Studio

ToolStick-EK TOOLSTICK USER S GUIDE. 1. Kit Contents. 2. ToolStick Overview. Green and Red LEDs. C8051F321 provides USB debug interface.

IAR EWARM Quick Start for. Holtek s HT32 Series Microcontrollers

Using HAL Device Drivers with the Altera Monitor Program. 1 Introduction. For Quartus II 13.1

CODE TIME TECHNOLOGIES. mabassi RTOS. Porting Document. SMP / ARM Cortex-A9 CCS

ATOLLIC TRUESTUDIO FOR STM32 QUICK START GUIDE

AN1369 APPLICATION NOTE

What is µc/os-iii Real-Time Kernel for CrossCore Embedded Studio

Engineer-to-Engineer Note

Lab 3a: Scheduling Tasks with uvision and RTX

Enterprise Architect. User Guide Series. Profiling

Enterprise Architect. User Guide Series. Profiling. Author: Sparx Systems. Date: 10/05/2018. Version: 1.0 CREATED WITH

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document MSP430 GCC

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

2 ABOUT VISUALDSP++ In This Chapter. Figure 2-0. Table 2-0. Listing 2-0.

ATOLLIC TRUESTUDIO FOR ARM QUICK START GUIDE

REAL-TIME MULTITASKING KERNEL FOR IBM-BASED MICROCOMPUTERS

Debug Tool: Introduction. Performance Objectives

μez Software Quickstart Guide

Quadros. RTXC Kernel Services Reference, Volume 1. Levels, Threads, Exceptions, Pipes, Event Sources, Counters, and Alarms. Systems Inc.

Salvo Compiler Reference Manual HI-TECH PICC-18

MCUXpresso IDE FreeRTOS Debug Guide. Rev November, 2017

The CMXTracker Manual. The CMXTracker Manual

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

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

Salvo Compiler Reference Manual HI-TECH ARClite-C

Infor LN Studio Application Development Guide

AP16050 SAB C161V/K/O. Emulating an asynchronous serial interface (ASC) via software routines. Microcontrollers. Application Note, V 1.0, Feb.

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

Transcription:

embos Real-Time Operating System CPU & Compiler specifics for Document: UM01060 Software Version: 5.02 Revision: 0 Date: July 25, 2018 A product of SEGGER Microcontroller GmbH www.segger.com

2 Disclaimer Specifications written in this document are believed to be accurate, but are not guaranteed to be entirely free of error. The information in this manual is subject to change for functional or performance improvements without notice. Please make sure your manual is the latest edition. While the information herein is assumed to be accurate, SEGGER Microcontroller GmbH (SEG- GER) assumes no responsibility for any errors or omissions. SEGGER makes and you receive no warranties or conditions, express, implied, statutory or in any communication with you. SEGGER specifically disclaims any implied warranty of merchantability or fitness for a particular purpose. Copyright notice You may not extract portions of this manual or modify the PDF file in any way without the prior written permission of SEGGER. 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., Hilden / Germany Trademarks Names mentioned in this manual may be trademarks of their respective companies. Brand and product names are trademarks or registered trademarks of their respective holders. Contact address SEGGER Microcontroller GmbH In den Weiden 11 D-40721 Hilden Germany Tel. +49 2103-2878-0 Fax. +49 2103-2878-28 E-mail: support@segger.com Internet: www.segger.com

3 Manual versions This manual describes the current software version. If you find an error in the manual or a problem in the software, please inform us and we will try to assist you as soon as possible. Contact us for further information on topics or functions that are not yet documented. Print date: July 25, 2018 Software Revision Date By Description 5.02 0 180724 MM 4.40 0 180122 MC New software version. 4.36 0 170809 TS New software version. 4.34 0 170405 TS New software version. 4.24 0 160629 TS New software version. 4.22 0 160503 RH New software version. 4.12a 0 150917 TS New software version. 4.06a 0 150316 SC First version. New software version. Updated chapter Calling Windows API functions from tasks.

4

5 About this document Assumptions This document assumes that you already have a solid knowledge of the following: The software tools used for building your application (assembler, linker, C compiler). The C programming language. The target processor. DOS command line. If you feel that your knowledge of C is not sufficient, we recommend The C Programming Language by Kernighan and Richie (ISBN 0--13--1103628), which describes the standard in C programming and, in newer editions, also covers the ANSI C standard. How to use this manual This manual explains all the functions and macros that the product offers. It assumes you have a working knowledge of the C language. Knowledge of assembly programming is not required. Typographic conventions for syntax This manual uses the following typographic conventions: Style Body Keyword Parameter Sample Sample comment Reference GUIElement Emphasis Body text. Used for 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. Comments in program examples. Reference to chapters, sections, tables and figures or other documents. Buttons, dialog boxes, menu names, menu commands. Very important sections.

6

7 Table of contents 1 Using embos Simulation...9 1.1 Installation... 10 1.2 First Steps... 11 1.3 The example application OS_StartLEDBlink.c... 12 1.4 Stepping through the sample application...13 2 Build your own application...18 2.1 Introduction...19 2.2 Required files for an embos...19 2.3 Select a start project configuration...19 2.4 Add your own code... 19 2.5 Change library mode... 19 2.6 Rebuilding the embos library... 20 3 Device Simulation... 21 3.1 Introduction...22 3.2 How the device simulation works... 22 3.3 Modify periodical device update rate...22 3.4 Force immediate device update...22 3.5 How to use your own simulated device...23 4 Stacks... 24 4.1 Task stacks... 25 4.2 System stack...25 4.3 Interrupt stack... 25 5 Interrupts... 26 5.1 Introduction...27 5.2 How interrupt simulation works... 27 5.3 Defining interrupt handlers for simulation...27 5.4 Interrupt handler installation... 28 5.5 Interrupt priorities...28 6 Calling Windows API functions from tasks... 29 6.1 Introduction...30 6.2 API functions...30

8 7 Technical data...33 7.1 Memory requirements...34

Chapter 1 Using embos Simulation This chapter describes how to start with and use the embos Simulation running under Windows 32bit operating system using Visual Studio. You should follow these steps to become familiar with embos.

10 CHAPTER 1 Installation 1.1 Installation embos is shipped as a zip-file in electronic form. To install it, proceed as follows: Extract the zip-file to any folder of your choice, preserving the directory structure of this file. Keep all files in their respective sub directories. Make sure the files are not read only after copying. Assuming that you are using an IDE to develop your application, no further installation steps are required. You will find a lot of prepared sample start projects, which you should use and modify to write your application. So follow the instructions of section First Steps on page 11. You should do this even if you do not intend to use the IDE for your application development to become familiar with embos. If you do not or do not want to work with the IDE, you should: Copy either all or only the library-file that you need to your work-directory. The advantage is that when switching to an updated version of embos later in a project, you do not affect older projects that use embos, too. embos does in no way rely on an IDE, it may be used without the IDE using batch files or a make utility without any problem.

11 CHAPTER 1 First Steps 1.2 First Steps After installation of embos you can create your first multitasking application. You have received several ready to go sample start workspaces and projects and every other files needed in the subfolder Start. It is a good idea to use one of them as a starting point for all of your applications. The subfolder BoardSupport contains the workspaces and projects which are located in manufacturer- and CPU-specific subfolders. To start with, you may use any project from BoardSupport subfolder. To get your new application running, you should proceed as follows: Create a work directory for your application, for example c:\work. Copy the whole folder Start which is part of your embos distribution into your work directory. Clear the read-only attribute of all files in the new Start folder. Open one sample workspace/project in Start\BoardSupport\Simulation with your IDE (for example, by double clicking it). Build the project. It should be built without any error or warning messages. After generating the project of your choice, the screen should look like this:

12 CHAPTER 1 The example application OS_StartLEDBlink.c 1.3 The example application OS_StartLEDBlink.c The following is a printout of the example application OS_StartLEDBlink.c. It is a good starting point for your application. (Note that the file actually shipped with your port of embos may look slightly different from this one.) What happens is easy to see: After initialization of embos two tasks are created and started. The two tasks are activated and executed until they run into the delay, suspend for the specified time and continue execution. /********************************************************************* * SEGGER Microcontroller GmbH * * The Embedded Experts * ********************************************************************** -------------------------- END-OF-HEADER ----------------------------- File : OS_StartLEDBlink.c Purpose : embos sample program running two simple tasks, each toggling a LED of the target hardware (as configured in BSP.c). */ #include "RTOS.h" #include "BSP.h" static OS_STACKPTR int StackHP[128], StackLP[128]; // Task stacks static OS_TASK TCBHP, TCBLP; // Task control blocks static void HPTask(void) { while (1) { BSP_ToggleLED(0); OS_TASK_Delay(50); } } static void LPTask(void) { while (1) { BSP_ToggleLED(1); OS_TASK_Delay(200); } } /********************************************************************* * * main() */ int main(void) { OS_Init(); // Initialize embos OS_InitHW(); // Initialize required hardware BSP_Init(); // Initialize LED ports OS_TASK_CREATE(&TCBHP, "HP Task", 100, HPTask, StackHP); OS_TASK_CREATE(&TCBLP, "LP Task", 50, LPTask, StackLP); OS_Start(); // Start embos return 0; } /*************************** End of file ****************************/

13 CHAPTER 1 Stepping through the sample application 1.4 Stepping through the sample application When starting the debugger, you will see the main() function (see example screen shot below). The main() function appears as long as project option Run to main is selected, which it is enabled by default. Now you can step through the program. OS_Init() is part of the embos library and written in assembler; you can there fore only step into it in disassembly mode. It initializes the relevant OS variables. 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 system tick interrupt for embos. Step through it to see what is done. OS_Start() should be the last line in main(), because it starts multitasking and does not return. Before you step into OS_Start(), you should set two breakpoints in the two tasks as shown below.

14 CHAPTER 1 Stepping through the sample application After starting the debugger, the embos simulation environment is set up and displays a simulated device which is shown before the debugger stops at the breakpoint at main(). Now you can step through the program.

15 CHAPTER 1 Stepping through the sample application Step over OS_Start(), or step into OS_Start() in disassembly mode until you reach the highest priority task. If you continue stepping, the first LED of your device will be switched on, the HPTask() will run into its delay and therefore, embos will start the task with lower priority.

16 CHAPTER 1 Stepping through the sample application Continuing to step through the program, the LPTask() will switch on LED1 and then run into its delay. Please note, that the simulated device may not show the correct state of the LEDs immediately. Default settings update the screen for the simulated device every 20 ms. How to modify this behavior is described later on in this manual. As there is no other task ready for execution when LPTask() runs into its delay, embos will suspend LPTask() and switch to the idle process, which is always executed if there is nothing else to do (no task is ready, no interrupt routine or timer executing). embos Simulation does not contain an OS_Idle() function which is implemented in normal embos ports. Idle times are spent in the Windows idle process.

17 CHAPTER 1 Stepping through the sample application When you step over the OS_TASK_Delay() function of the LPTask(), you will arrive back in the HPTask(). As can be seen by the value of embos timer variable OS_Global.Time, shown in the Watch window, HPTask() continues operation after expiration of the 50 system tick delay. Please note, that delays seem to be longer than expected. When the debugger stops at a breakpoint, it takes some time until the screen is updated and the OS_Global.Time variable is examined. Therefore OS_Global.Time may show larger values than expected. After the delay of HPTask() expired, the simulated device shows both LEDs lit as can be seen in the following screenshot: You may now disable the two breakpoints in our tasks and continue the execution of the application to see how the simulated device runs in real time.

Chapter 2 Build your own application This chapter provides all information to set up your own embos project.

19 CHAPTER 2 Introduction 2.1 Introduction To build your own application, you should always start with one of the supplied sample workspaces and projects. Therefore, select an embos workspace as described in chapter First Steps on page 11 and modify the project to fit your needs. Using an embos start project as starting point has the advantage that all necessary files are included and all settings for the project are already done. 2.2 Required files for an embos To build an application using embos Simulation, the following files from your embos distribution are required and have to be included in your project: RTOS.h from subfolder Inc\. This header file declares all embos API functions and data types and has to be included in any source file using embos functions. RTOSInit*.c from the BoardSupport\Simulation\Setup\ subfolder. It contains initialization code for the embos timer interrupt handling and simulation. OS_Error.c from the BoardSupport\Simulation\Setup\ subfolder. One embos library from the subfolder Lib\. WinMain.c from the BoardSupport\Simulation\Win32\ subfolder. It contains the initialization code for the embos Simulation environment under Windows 32bit and the Windows message loop. SIM.c from the BoardSupport\Simulation\Win32\ subfolder. It contains initialization and update handling of the simulated device. This file may be modified to support your own simulated device as described later in this manual. Resource files from the BoardSupport\Simulation\Win32\ subfolder. These resource files contain commands and resources used for embos Simulation running under Windows 32bit operating system. 2.3 Select a start project configuration embos Simulation comes with one start project which includes two configurations: Start - Win32 Debug is the configuration normally used for development and debugging. Start - Win32 Release may be used to build an executable, which shows the application and simulated device and can be started on any PC running with Windows 32bit operating system. It may be used for demonstration purposes. 2.4 Add your own code For your own code, you may add a new folder to the project or add additional files to the Application folder. You may modify or replace the sample application source file in the subfolder Application. The main() function has to be used as an entry point of the embos Simulation. Your main() function has to initialize embos by calling OS_Init() and OS_InitHW() prior to any other embos functions that are called. 2.5 Change library mode embos Simulations are shipped with only one library, that is the debug library. This is because there is no need for a simulation to use any other library mode that removes additional runtime error checks or additional memory requirements, that are negligible on a Windows machine.

20 CHAPTER 2 Rebuilding the embos library 2.6 Rebuilding the embos library An new library for embos Simulation can only be built using the source version of embos Simulation. Modify the Prep.bat batch file in the root directory of the embos Simulation source distribution to set the path to the compiler which should be used. Finally start M.bat to produce a new Start folder which then contains the new library.

Chapter 3 Device Simulation This chapter describes how the device simulation works and how it is used.

22 CHAPTER 3 Introduction 3.1 Introduction embos Simulation contains additional functions to visualize and simulate a hardware device. This may be used to simulate and visualize hardware ports, LEDs or displays which would normally be controlled with functions running on your real hardware. The following chapter describes how device simulation works on our sample project and how this simulation can be modified to simulate your own hardware. 3.2 How the device simulation works During startup of the Windows application in WinMain(), the bitmap Device.bmp is set up and shown on the screen. The device bitmap is shown as main window of embos Simulation. SIM_Init(), called from WinMain() initializes a Windows timer which periodical sends a WM_TIMER message to the main window. The window procedure of the main window handles the WM_TIMER message and calls the timer callback function that was assigned to the timer during creation. The timer callback function (found in SIM.c) invalidates the main window, which results in a WM_PAINT message sent to the main window. The windows procedure of the main window handles the WM_PAINT message and calls SIM_Paint() which is responsible to draw the device bitmap. 3.3 Modify periodical device update rate The device update rate is controlled by the timer interval value which is set during creation of the update timer in SIM_Init(). The default update interval is set to 20 ms. According to your needs, you may modify the update interval. Therefore modify the following line in SIM_Init() found in SIM.c: SetTimer(hMainWindow, 0, 20, _cbtimer); The third parameter of SetTimer() specifies the update interval in ms. The update interval should not be set to short to avoid high CPU load. If short update reaction is required, it might be better to force immediate device update on demand as described below. 3.4 Force immediate device update Our sample device consist of 8 LEDs which can be switched on, off or can be toggled by the sample hardware specific functions declared in our sample code file BSP.c. During the sample debug session described in chapter 3, you may have noticed, that our sample device was not updated immediately when we called the BSP_ToggleLED() functions from our two sample tasks. Per default, a timer is used to update and redraw the simulated device periodically as described in previous chapter. The function SIM_Update() from SIM.c may be called to force an immediate update of the simulated device. This function does not take parameters and does not return any value. You may modify our sample code in BSP.c as shown below to force immediate device update when any LED function is called. /********************************************************************* * * BSP_SetLED() */ void BSP_SetLED(int Index) { if (Index < 32) { LEDs = (1u << Index); SIM_Update(); } }

23 CHAPTER 3 How to use your own simulated device /********************************************************************* * * BSP_ClrLED() */ void BSP_ClrLED(int Index) { if (Index < 32) { LEDs &= ~(1u << Index); SIM_Update(); } } /********************************************************************* * * BSP_ToggleLED() */ void BSP_ToggleLED(int Index) { if (Index < 32) { LEDs ^= (1u << Index); SIM_Update(); } } You may then restart the sample application to see the different behavior. 3.5 How to use your own simulated device Any Windows bitmap file can be used and shown as main window of embos Simulation to visualize a simulated device. To display the real contour of the device, the background outside the device contour may be filled with one specific color, which is treated as transparent when the bitmap is shown on the screen. This transparent color should of course not exist in the device itself. To display your device on the screen during simulation, proceed as follows: Create a bitmap file of your device. Follow the contour of your device and fill the background with one color, that does not exist in your device image to make the background transparent. Per default, we use pure red in our sample. Save the device as Device.bmp in subfolder BoardSupport\Simulation\Win32 of your start project. In WinMain.c check or modify the entry _rgbtransparent which defines the transparent color. To simulate visual elements of your device, write or modify the SIM_Paint() function in SIM.c. Finally you have to write your own hardware file similar to our BSP.c sample file which transforms your hardware outputs to any memory variables or states which can be visualized by your SIM_Paint() function.

Chapter 4 Stacks The following chapter describes stack handling of embos Simulation running under Windows 32bit operating system.

25 CHAPTER 4 Task stacks 4.1 Task stacks Every embos task has to have its own stack. Task stacks can be located in any RAM memory location. In embos Simulation, every task runs as a separate thread under Windows 32bit operating system. The real task stack is therefore managed by Windows. Declaration and size of task stacks in your application are necessary for generic embos functions, but do not affect the stack size of the generated Windows thread. A stack check and stack overflows can therefore not be simulated. 4.2 System stack The system stack used during startup and embos internal functions is controlled by Windows 32bit operating system, because simulated startup and system calls run in a Windows thread. Stack checking of system stack can therefore not be simulated. 4.3 Interrupt stack Simulated interrupts in embos Simulation run as Windows thread with higher priority. As the threads stacks are managed by Windows 32bit operating system, the interrupt stacks will never overflow and stack check can not be simulated.

Chapter 5 Interrupts This chapter describes how interrupts are handled by the embos simulation.

27 CHAPTER 5 Introduction 5.1 Introduction With embos Simulation, interrupts have to be simulated. This requires modified interrupt service routines which differ from those used in your embedded application. The following chapter describes interrupt simulation and handling in embos Simulation running on Windows 32bit operating system. 5.2 How interrupt simulation works With embos Simulation, all interrupt handler functions are started as individual threads running at highest priority. Under Windows 32bit operating system, interrupt handler functions run with priority THREAD_PRIORITY_TIME_CRITICAL. Because embos might have to disable interrupts when embos internal operations are performed, embos Simulation has to be able to suspend and resume interrupt handler threads. This requires, that all interrupt handler threads have to be created and installed by the special embos Simulation API function OS_SIM_CreateISRThread(). Interrupt simulation under embos Simulation functions as follows: An interrupt handler is written as normal C -function without parameter or return value. The interrupt handler function is started and initialized as Windows thread running at highest priority by a call of OS_SIM_CreateISRThread(). The interrupt handler function runs as endless loop which consists a Sleep_Ex() function call. As soon as the interrupt handler calls Sleep_Ex(), the thread is suspended by the Windows operating system. The interrupt is triggered by an APC function call which is used to resume the interrupt simulation thread suspended by Sleep_Ex(). The interrupt handler function is resumed by Windows and performs the required function. The interrupt handler running as endless loop calls Sleep_Ex() again and suspends until it is resumed again by the associated APC function call. To simulate a periodical interrupt, a Windows timer object can be used to call an APC function for the simulated interrupt handler, or Sleep_Ex() can be called with timeout value. 5.3 Defining interrupt handlers for simulation Interrupt handlers used in embos Simulation can not handle the real hardware normally used in your target application. The interrupt handler functions of your target application have to be replaced by a modified version which can be used in simulation. Example Simple interrupt routine: static void _ISRTimerThread(void) { while (1) { OS_INT_Enter(); /* Tell embos that interrupt code is running */ DoTimerHandling(); /* Any functionality can be added here */ OS_INT_Leave(); /* Tell embos that interrupt code ends */ SleepEx(10, TRUE); /* Suspend until delay expired or triggered */ /* by "APC" function */ } } How to create and use a timer object which periodical calls an APC function to signal the interrupt thread can be seen in RTOSInit.c. There we use a timer object to signal the embos timer interrupt thread.

28 CHAPTER 5 Interrupt handler installation Note OS_INT_Enter() or OS_INT_EnterNestable() has to be called before any other embos function is called from the interrupt handler. 5.4 Interrupt handler installation Any interrupt handler in embos Simulation has to be installed by a call of OS_SIM_CreateISRThread(). Prototype OS_U32 O_SIM_CreateISRThread(void (*pstartaddress)(void)) Parameter pstartaddress Description Pointer to void function which serves as simulated interrupt handler. Return Value OS_U32 value is the handle to the created interrupt simulation thread. Additional Information The returned thread handle may be used to create and assign a synchronization object for the created thread. An example on how to use this handle for creation of a timer object to periodical signal an interrupt can be seen in our RTOSInit.c where it is used for embos timer interrupt simulation. 5.5 Interrupt priorities With embos Simulation, all simulated interrupts, installed with function OS_SIM_CreateISRThread() run on the same ISR thread priority, which is THREAD_PRIORI- TY_TIME_CRITICAL. The order of thread activation is scheduled by Windows 32bit operating system and can not be influenced or predicted.

Chapter 6 Calling Windows API functions from tasks This chapter describes how to use Windows API function in the embos simulation.

30 CHAPTER 6 Introduction 6.1 Introduction With the embos Simulation, typically the embedded application shall be simulated. Calling Windows API functions from tasks may however, be required for several reasons, e.g. with a simulated TCP/IP stack that uses the Windows socket interface for communications via the PC. Typically, calling blocking Windows functions will freeze the calling task and no other task will be activated in its place: the simulated system would stop until the blocking Windows function returns. To avoid this, two embos API functions are available to manage the call of blocking Windows functions. Similar to handling of critical regions, there is one entry function (which has to be called before calling a blocking Windows function) and one exit function (which has to be called after execution of the blocking Windows function). The Application folder of the embos shipment contains the sample application OS_Sim- Blocked.c, which demonstrates these functions usage on blocking Windows API calls. 6.2 API functions Routine Description main Task ISR Timer OS_SIM_EnterSysCall() OS_SIM_LeaveSysCall() Must be called prior to calling any blocking Windows API function from a task. Must be called after calling any blocking Windows API function from a task, and before any other embos API function is called.

31 CHAPTER 6 API functions 6.2.1 OS_SIM_EnterSysCall() OS_SIM_EnterSysCall() has to be called before a blocking Windows function is called from a task. Prototype void OS_SIM_EnterSysCall(void); Additional information OS_SIM_EnterSysCall() has to be called before calling any blocking Windows API function. After calling OS_SIM_EnterSysCall(), no further embos API function except OS_SIM_EnterSysCall() or OS_SIM_LeaveSysCall() must be called. Nested calls of OS_SIM_EnterSysCall() are allowed. The function must only be called from tasks. Example... OS_SIM_EnterSysCall(); // Any blocking Windows API function may be called now...... recv (socket, pbuf, len, flags); // Any other code may follow. // No embos function must be called except OS_SIM_LeaveSysCall()... OS_SIM_LeaveSysCall(); // From now on, calling other embos functions is allowed...

32 CHAPTER 6 API functions 6.2.2 OS_SIM_LeaveSysCall() OS_SIM_LeaveSysCall() has to be called after execution of a blocking Windows function, before any other embos function is called. Prototype void OS_SIM_LeaveSysCall(void); Additional information OS_SIM_LeaveSysCall() has to be called after execution of blocking Windows API functions, and before calling any other embos function. It must be called only when OS_SIM_LeaveSysCall() has been called by the same task before. For every call of OS_SIM_EnterSysCall(), OS_SIM_LeaveSysCall() has to be called a corresponding number of times. After the last call to OS_SIM_LeaveSysCall(), the task is switched back to normal embos execution mode. Nested calls of OS_SIM_LeaveSysCall() are allowed. The function must only be called from tasks. Example... OS_SIM_EnterSysCall(); // Any blocking Windows API function may be called now...... recv (socket, pbuf, len, flags); // Any other code may follow. // No embos function must be called except OS_SIM_LeaveSysCall()... OS_SIM_LeaveSysCall(); // From now on, calling other embos functions is allowed...

Chapter 7 Technical data This chapter lists technical data of embos used with the simulation.

34 CHAPTER 7 Memory requirements 7.1 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 embos. The minimum ROM requirement for the kernel itself is about 2.500 bytes. In the table below, which is for the debug plus profiling build, you can find minimum RAM size requirements for embos resources. Note that the sizes depend on selected embos library mode. embos resource RAM [bytes] Task control block 116 Software timer 20 Mutex 20 Semaphore 16 Mailbox 32 Queue 40 Task event 0 Event object 24