28
8/9/2019 AN-1403 http://slidepdf.com/reader/full/an-1403 1/28 Empowering Embedded Systems µC/OS-II and The Fujitsu MB91403 (FR) (Using the MB91943EB Evaluation Board) Application Note AN-1403 www.Micrium.com  

AN-1403

Embed Size (px)

Citation preview

Page 1: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 1/28

Empowering Embedded Systems

µC/ OS-II  and

The Fujitsu MB91403 (FR)(Using the MB91943EB Evaluation Board)

Application NoteAN-1403

www.Micrium.com 

Page 2: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 2/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

Table of Contents

1.00  Introduction 4 1.01  Softune Workbench V6  5 1.02  Emulator 5 2.00  Directories and Files  7 3.00  Project Setup  9 3.01  Project Settings 10 3.01.01  Project Settings, MCU tab 11 3.01.02  Project Settings, C/C++ Compiler tab 11 3.01.03  Project Settings, Assembler tab 13 3.01.04  Project Settings, Linker tab 14 3.02  Debugging 17 3.02  Setting up a new Debug configuration 19 4.00  Test Code 21 4.01  Test Code, app.c 21 4.02  Test Code, app_cfg.h 23 4.03  Test Code, app_vect.asm 23 4.04  Test Code, includes.h 23 4.05  Test Code, os_cfg.h 24 4.06  Test Code, OS.* 24 5.00  Board Support Package (BSP) 25 5.01  Board Support Package, bsp.c 26 5.02  Board Support Package, bsp.h 27 5.03  Board Support Package, bsp_a.asm 27 

References 28 Contact Information 28

 

2

Page 3: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 3/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

3

Page 4: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 4/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

1.00 Introduction1.00 Introduction

This document describes example code for using µC/ OS-II with the Fujitsu FR series of

processors. To test the code, we used an MB91943EB evaluation board, which contains anMB91403 processor, as shown in Figure 1-1.

RS-232C

EthernetEmulator Pod

Emulator Interface

Power

MB91403

8 User LEDs

 

Figure 1-1, MB91943EB Evaluation Board with Emulator Pod

This example uses the µC/ OS-II port which is described in AN-1015. The details of the port

itself will not be described in this application note, just what needs to be done to get µC/ OS-II  

working on this evaluation board.

4

Page 5: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 5/28

Page 6: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 6/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

MB2198-01 Emulator 

Emulator Pod

MB92943 Evaluation Board 

Figure 1-3, MB2198-01 Emulator, Pod and MB91943EB

6

Page 7: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 7/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

2.00 Directories and Files

The code for this application note is placed in a directory structure according to “AN-2002,µC/OS-II Directory Structure”. Specifically, the files are placed in the following directories:

µC/ OS-II : 

\Micrium\Software\uCOS-II\Source

This directory contains the processor independent code for µC/ OS-II . The version used

was 2.81.

\Micrium\Software\uCOS-II\Ports\FR\Softune

This directory is the main directory for Fujitsu FR port. Refer to Micriµm’s AN-1015 fordetails on this port.

This directory contains the standard processor specific files for a µC/ OS-II portassuming the Softune toolchain. Specifically, this directory contains the following files:

os_cpu.h

os_cpu_a.asm

os_cpu_i.asm

os_cpu_c.c

os_dbg_c

Appl ic at ion Code : 

\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OS

This directory contains the source code for an example running on the MB91943EBEvaluation Board. This directory contains:

app_vect.asm

app.c

app_cfg.h

includes.h

os_cfg.h

os.*

app.c contains the test code, app_vect.asm contains the interrupt vector table for the

MB91403 processor and app_cfg.h contains application specific configurationinformation, such as task priorities, stack sizes, etc.

includes.h contains a master include file used by the application, and os_cfg.h is

the µC/ OS-II configuration file.

os.* are the Softune Workbench project files.

7

Page 8: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 8/28

Page 9: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 9/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

3.00 Project Setup

This section describes how we setup the Softune Workbench. We first created a workspace andthen a project, both called OS (for Operating System). The necessary files were included asshown in Figure 3-1. Note that we created sub-folders to keep everything organized as opposed

to putting everything in the ‘Source Files’ folder.

Figure 3-1, OS Project

9

Page 10: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 10/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

3.01 Project Settings3.01 Project Settings

This section describes how we configured the tools. You get to the project setup screen byclicking on the ‘Project’ menu item and then the ‘Setup…’ sub-item as shown in Figure 3-2.

Figure 3-2, Setting up the project options

This opens the dialog box shown in Figure 3-3.

Project (OS.prj)

and its path

Figure 3-3, General Settings

10

Page 11: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 11/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

The project is found in the following directory (called OS.prj):The project is found in the following directory (called OS.prj):

C:\Micrium\SOFTWARE\EvalBoards\Fujitsu\MB91943EB\Softune\OS\OS.prj C:\Micrium\SOFTWARE\EvalBoards\Fujitsu\MB91943EB\Softune\OS\OS.prj 

3.01.01 Project Settings, MCU tab3.01.01 Project Settings, MCU tab

As shown in Figure 3-4, the MCU tab determines the type of CPU (FR) and the specific part used(MB91403). If you are also using this CPU and the MB91403 is not listed in the pulldown, youmight want to contact your Fujitsu representation and have them send you the 911.csv file

which contains the definitions of that processor (you’d place that in C:\Softune6\lib\911).

MCU

tab

Select the FRClass of Chips

We used theMB91403

Figure 3-4, MCU Settings

3.01.02 Project Settings, C/C++ Compiler tab

The C/C++ Compiler tab is shown in Figure 3-5. You will note that there are actually six (6)sub-categories of settings (see Category:) to chose from:

GeneralDefine Macros

Include PathOptimizeC++Language

When you click on the C/C++ Compiler tab, the General category is presented and it should beset as shown in Figure 3-5.

We didn’t have any macros to define and thus, didn’t need to do anything with the Define Macros category.

11

Page 12: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 12/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

Because we place source files in multiple directories, the Include Path category was set asshown in Figure 3-6 and contains the following entries:Because we place source files in multiple directories, the Include Path category was set asshown in Figure 3-6 and contains the following entries:

C:\Micrium\Software\uCOS-II\SourceC:\Micrium\Software\uCOS-II\SourceC:\Micrium\Software\uCOS-II\Ports\FR\SoftuneC:\Micrium\Software\uCOS-II\Ports\FR\Softune

C:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OSC:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OSC:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\BSPC:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\BSP

Figure 3-5, C/C++ Compiler, General category

Click hereto add

new paths

Project

Paths

Figure 3-6, C/C++ Compiler, Include Path category

The Optimize, C++ and Language categories were not changed from their defaults.

12

Page 13: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 13/28

Page 14: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 14/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

Click hereto add

new paths

ProjectPaths

Figure 3-8, Assembler, Include Path

3.01.04 Project Settings, Linker tab

The Linker tab is shown in Figure 3-9. You will note that there are actually six (6) sub-categoriesof settings (see Category:) to chose from:

GeneralDisposition/Connection

Define SymbolOutput ListAbsolute Assembly ListControl Library

When you click on the Linker tab, the General category is presented and it should be set asshown in Figure 3-9.

You’ll notice that we added the –sc @INIT-CS7ROM option in the Other Option: section.

Figure 3-10 shows the Disposition/Connection sub-category. This is an important section sinceit defines the memory map of the project and the different linker sections.

Section Start Address Stop Address Type SizeCS7ROM 0x80000000 0x801FFFFF ROM 2M _INRAM02 0x0003F800 0x0003FFFF RAM 32KCS1RAM 0x00100000 0x0010FFFF RAM 64KIO_I2C 0x010F0000 0x010FFFFF RAM 64KSMI 0x01100000 0x0113FFFF RAM 256K

IO_EXIF 0x01140000 0x0114FFFF RAM 64K

14

Page 15: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 15/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

Click here toadd newoptions

 

Figure 3-9, Linker, General

SetsMemory

Map

 

Figure 3-10, Linker, Disposition/Connection

The Define Symbol category was not changed from its default.

15

Page 16: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 16/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

The Output List category is shown in Figure 3-11. Here, we selected to generate a link map,create a memory usage list and provide information about each memory section.The Output List category is shown in Figure 3-11. Here, we selected to generate a link map,create a memory usage list and provide information about each memory section.

GenerateLink Map

Eachmemory

section willbe detailed

Create aMemory

Usage List

 

Figure 3-11, Linker, Disposition/Connection

16

Page 17: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 17/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

3.02 Debugging3.02 Debugging

The example code provided in this application note contains all the setup files you need to startdebugging. Assuming the MB91943EB is connected as shown in Figure 1-3, you can:

1) Press the ‘Build All’ button as shown below

Build ALL

2) Assuming there are no compiler errors, then you can start debugging by clicking on theDebug menu item and the Start debug sub-menu item as shown in Figure 3-12.

Figure 3-12, Starting the Debugger

3) If everything loaded correctly, you should see something similar to the screen shown inFigure 3-13.

4) If you click on the Run continuously icon, the 8 LEDs on the MB91943EB should beblinking from left-to-right and back (or up-and-down depending on the orientation of theboard).

17

Page 18: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 18/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

StartExecution

startup.asm 

code window

Figure 3-13, Ready to Run test application

18

Page 19: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 19/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

3.02 Setting up a new Debug configuration

The example code provided in this application note contains all the setup files you need to startdebugging. However, if you need to setup a new debug session, you will need to follow thesesteps:

Create a Debug SetupRight-mouse click on the Debug folder in the project window as shown in Figure 3-14 (you mustnot already be in a debug session in order to do this).

Figure 3-14, Setting up a New debug configuration

Enter a name for the debug settings as shown in Figure 3-15.

Figure 3-15, Creating a new debug configuration

19

Page 20: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 20/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

Run the Setup WizardThen follow the setup wizard which will ask you questions about your debug environment.

Figure 3-16 Follow the Setup Wizard

In our case, we selected the following options when prompted by the wizard:

Debug Type: Emulator Debugger ICE type: MB2198 

Monitor program auto-loadingDevice type: USB Batch file: C:\Micrium\SOFTWARE\EvalBoards\Fujitsu\MB91943EB\Softune\mb91403_init.prc  

Before: C:\Micrium\SOFTWARE\EvalBoards\Fujitsu\MB91943EB\Softune\mb91403_init.prc  After:Select All item

20

Page 21: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 21/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

4.00 Test Code4.00 Test Code

As mentioned previously, the test code for this board is found in the following directories and willbe briefly described:

\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OS

4.01 Test Code, app.c

The test code is found in app.c and will be described in this section.

Listing 4-1, main()

void main (void) (1)

{INT8U err;

BSP_IntDisAll(); (2)

OSInit(); (3)

OSTaskCreateExt(AppTaskStart, (4)

(void *)0,

(OS_STK *)&AppTaskStartStk[APP_TASK_START_STK_SIZE - 1],

See APP_CFG.H

For task stacksizes

APP_TASK_START_PRIO,

APP_TASK_START_PRIO,

(OS_STK *)&AppTaskStartStk[0],

APP_TASK_START_STK_SIZE,

(void *)0,

OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);

#if OS_TASK_NAME_SIZE > 13

OSTaskNameSet(APP_TASK_START_PRIO, "Startup", &err); (5)

See APP_CFG.H

For task

priorities 

#endif

OSStart(); (6)

}

L4-1(1) As with most C applications, the code starts in main().

L4-1(2) We start off by calling a BSP function (see bsp.c) that will disable all interrupts. Wedo this to ensure that initialization doesn’t get interrupted in case we do a ‘warmrestart’.

L4-1(3) As with all µC/ OS-II applications, you need to call OSInit() before creating any

tasks or other kernel objects.

L4-1(4) We then create at least one task (in this case we used OSTaskCreateExt() to

specify additional information about the task to µC/ OS-II). It turns out that µC/ OS-II  

creates one and possibly two tasks in OSInit(). As a minimum, µC/ OS-II creates

an idle task (OS_TaskIdle() which is internal to µC/ OS-II) and OS_TaskStat() 

(if you set OS_TASK_STAT_EN to 1 in OS_CFG.H). OS_TaskStat() is also an

internal task in µC/ OS-II .

21

Page 22: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 22/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

L4-1(5) As of V2.6x, you can now name µC/ OS-II tasks (and other kernel objects) and be

able to display task names at run-time or with a debugger. In this case, we name ourfirst task.

L4-1(6) We finally start µC/ OS-II by calling OSStart(). µC/ OS-II will then start executing

AppStartTask() since that’s the highest priority task created.

Listing 4-2, AppTaskStart()

static void AppStartTask (void *p_arg)

{

INT8U I;

(void)p_arg;

BSP_Init(); (1)

#if OS_TASK_STAT_EN > 0

OSStatInit(); (2)

#endif

#if OS_VIEW_MODULE > 0

OSView_Init(38400); (3)

OSView_TerminalRxSetCallback(AppTerminalRx); (4)

#endif

LED_Off(0); (5)

AppTaskCreate(); (6)

while (TRUE) { (7)for (i = 1; i <= 8; i++) {

LED_On(i);OSTimeDlyHMSM(0, 0, 0, 50);LED_Off(i);

}

for (i = 1; i <= 8; i++) {LED_On(9 - i);OSTimeDlyHMSM(0, 0, 0, 50);LED_Off(9 - i);

}}

}

L4-2(1) BSP_Init() is called to initialize the Board Support Package – the I/Os, the tick

interrupt, and so on. BSP_Init() will be discussed in the next section.

L4-2(2) OSStatInit() is used to initialize µC/ OS-II ’s statistic task. This only occurs if you

enable the statistic task by setting OS_TASK_STAT_EN to 1 in OS_CFG.H. Thestatistic task measures overall CPU usage (expressed as a percentage) and also

performs stack checking for all the tasks that have been created withOSTaskCreateExt() with the stack checking option set.

L4-2(3) OSView_Init() is called to initialize the µC/ OS-View module (assuming you have

purchased this optional module to µC/ OS-II). Here we need to specify the baud rate

of the RS-232C port connecting the µC/ OS-View ‘viewer’.

22

Page 23: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 23/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

L4-2(4) OSView_TerminalRxSetCallback() allows you to specify the name of a function

that will be called by µC/ OS-View when characters are typed on the ‘Terminal

Window’ of the µC/ OS-View viewer.

L4-2(5) This BSP function allows all of the board’s LEDs to be turned off.

L4-2(6) We then create all of the application tasks by calling AppTaskCreate(). In ourcase, we don’t have any other tasks. However, it’s cleaner to have a function tocreate other task, if you decide to add more tasks.

L4-2(7) As with ALL tasks managed by µC/ OS-II , the task must either enter an infinite loop,

‘waiting’ for some event to occur, or terminate itself. We decided to simply blink the 8LEDs on the MB91943EB in sequence.

4.02 Test Code, app_cfg.h

This file is used to configure:

the µC/ OS-II task priorities of each of the tasks in your application

the stack size for each task

The reason this is done here is to make it easier to configure your application from a single file.

4.03 Test Code, app_vect.asm

This file contains ALL the interrupt vectors for the MB91403 processor. However, only a fewentries are used:

RESET vector (INT #0)

µC/ OS-II ‘s tick interrupt using Timer #0 (INT #24)

µC/ OS-II ‘s context switch (INT #64)

The other entries in the table are filled with ‘AppIllegal()’ and will thus vector to this locationshould one of the non-configured interrupts occur.

If you need to add additional interrupt service routines, you will need to add the appropriate entryin this table.

4.04 Test Code, includes.h

includes.h is a ‘master’ header file that contains #include directives to include other headerfiles. This is done to make the code cleaner to read and easier to maintain.

23

Page 24: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 24/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

4.05 Test Code, os_cfg.h

This file is used to configure µC/ OS-II and defines the maximum number of tasks that your

application can have, the services that will be enabled (semaphores, mailboxes, queues, etc.),the size of the idle and statistic task, and more. In all, there are about 60 or so constants that youcan set in this file. Each entry is commented, and additional information about the purpose of

each #define can be found in the µC/ OS-II book. os_cfg.h assumes you have µC/ OS-II  

V2.81 or higher, but it could also works with previous versions of µC/ OS-II .

4.06 Test Code, OS.*

These files are Softune workbench project files.

24

Page 25: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 25/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

5.00 Board Support Package (BSP)

BSP stands for Board Support Package and provides functions to encapsulate common I/Oaccess functions in order to make it easier for you to port your application code. In fact, youshould be able to create other applications using the MB91943EB evaluation board and reusethese functions, thus saving you a lot of time.

The BSP performs the following functions:

- Configure the I/Os for the MB91943EB- Control the board’s LEDs- Handle interrupts

- Handling of µC/ OS-II ’s tick timer

The BSP for the MB91943EB board is found in the follow directory.

\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\BSP

The BSP files are:

bsp.c

bsp.h

bsp_a.asm

Other common files provided by Fujitsu are placed in the \BSP directory. These are:

 _fr_a.asm

startup.asm

 _fr.c

 _fr.h

mb91403.hFR70E.inc

mb91403_a.inc

lib911if.lib

25

Page 26: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 26/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

5.01 Board Support Package, bsp.c

We will not be discussing every aspect of the BSP but only cover topics that require specialattention.

Your application code must call BSP_Init() to initialize the BSP but it must be called from

within a µC/ OS-II task and not from main(). BSP_Init() in turn calls other functions as

needed.

Listing 5-1, BSP_Init()

void BSP_Init (void)

{

BSP_IO_Init(); (1)

LED_Init(); (2)

BSP_TickISR_Init(); (3)

 __set_il(31); (4)

}

L5-1(1) We call BSP_IO_Init() to initialize the I/O ports which basically sets up 8 of theGPIO lines for outputs since those are used to drive the 8 LEDs on the MB91943EB.

L5-1(2) We initialize the LED services provided by the BSP. At this point, your applicationcan call LED_On(), LED_Off() or LED_Toggle() to turn on, off and toggle theboard’s LEDs, respectively.

L5-1(3) We then call BSP_TickISR_Init() which will initialize Timer #0 to generate

interrupts for the µC/ OS-II clock tick. The code for this function is described below.

Listing 5-2, BSP_TickISR_Init()

void Tmr_TickInit (void)

{

IO_TMRLR0 = 0xFFFF;

IO_TMCSR0.hword = 0x001B;

IO_ICR[8].byte = 0x16; /* interrupt priority reload timer 0 "level 16" */

ICR8 = 30;

}

We setup timer #0 as a free-running timer (i.e. counts from 0xFFFF down to 0x0000). We

selected free-running mode because we are planning on adding µC/ OS-View for the FR and

we’ll be using the same timer to make time measurements. The tick rate is given by:

Tick Rate = ------------------ = 125.89 Hz Crystal Freq / 4

Timer Reload Value

Where, Crystal Freq is 33 MHz for the MB91943EB and Timer Reload Value is 65536 becauseof the free-running mode. The tick rate is thus 125.89 Hz.

26

Page 27: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 27/28

Page 28: AN-1403

8/9/2019 AN-1403

http://slidepdf.com/reader/full/an-1403 28/28

Micr iµmµC/ OS-II and the Fujitsu MB91403 

References

µC/OS-II, The Real-Time Kernel, 2 nd 

Edition Jean J. LabrosseR&D Technical Books, 2002

ISBN 1-57820-103-9

Embedded Systems Building Blocks Jean J. LabrosseR&D Technical Books, 2000ISBN 0-87930-604-1

Contact Information

CMP Books, Inc.6600 Silacci WayGilroy, CA 95020 USAPhone Orders: 1-800-500-6875

or 1-408-848-3854Fax Orders: 1-408-848-5784e-mail: [email protected]: http://www.cmpbooks.com

 Micriµm949 Crestview CircleWeston, FL 33327USA954-217-2036954-217-2037 (FAX)e-mail: [email protected]: www.Micrium.com