Escolar Documentos
Profissional Documentos
Cultura Documentos
µC/OS-II
and
The Fujitsu MB91403 (FR)
(Using the MB91943EB Evaluation Board)
Application Note
AN-1403
www.Micrium.com
Micriµ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
References 28
Contact Information 28
2
Micriµm
µC/OS-II and the Fujitsu MB91403
3
Micriµm
µC/OS-II and the Fujitsu MB91403
1.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 an
MB91403 processor, as shown in Figure 1-1.
MB91403
8 User LEDs
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
Micriµm
µC/OS-II and the Fujitsu MB91403
Softune was installed in its default directory (C:\Softune6). The CPU information file (i.e.
911.csv) was updated from the standard Softune release to include information about the
MB91403. Consult Fujitsu if you are planning on using the MB91403 and the version of Softune
does not contain information on the MB91403.
1.02 Emulator
Fujitsu provided us with the MB2198-01 Emulator (see Figure 1-2) to test code on the
MB91943EB. The emulator connects to a Windows-based PC via a USB cable.
USB to PC Power
Cable to Pod
Figure 1-3 shows the Emulator connected to the Emulator Pod and the MB91943EB.
5
Micriµm
µC/OS-II and the Fujitsu MB91403
MB2198-01 Emulator
Emulator Pod
6
Micriµm
µC/OS-II and the Fujitsu MB91403
µ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 for
details on this port.
This directory contains the standard processor specific files for a µC/OS-II port
assuming 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
Application Code:
\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OS
This directory contains the source code for an example running on the MB91943EB
Evaluation 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 configuration
information, 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.
7
Micriµm
µC/OS-II and the Fujitsu MB91403
\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\BSP
This directory contains the Board Support Package (BSP) for the MB91943EB Evaluation
Board. This directory contains a few file provided by Micriµm:
bsp_a.asm
bsp.c
bsp.h
bsp.c contains functions to initialize the BSP, LED access functions, the µC/OS-II tick
interrupt handler (BSP_TickISR_Handler()) and other BSP related functions.
_fr_a.asm, _fr.c and _fr.h are standard Fujitsu FR file which include the
appropriate header files for the processor being used. In this case, they make reference
to mb91403.h.
mb91403.h contains the register and I/O definitions for the MB91403 processor.
startup.asm is the startup code. This file initialized the MB91403 processor following
a cold start. Note that this code was modified by Micriµm as follows:
1) The very first two lines of code following the ‘start:’ label were changed to
disable ALL interrupts instead of enabling them as the original code had. We
did this because we wanted to make sure we would not be getting any
interrupts until we were ready to process them.
8
Micriµm
µC/OS-II and the Fujitsu MB91403
9
Micriµm
µC/OS-II and the Fujitsu MB91403
Project (OS.prj)
and its path
10
Micriµm
µC/OS-II and the Fujitsu MB91403
C:\Micrium\SOFTWARE\EvalBoards\Fujitsu\MB91943EB\Softune\OS\OS.prj
MCU
tab
Select the FR
Class of Chips
We used the
MB91403
General
Define Macros
Include Path
Optimize
C++
Language
When you click on the C/C++ Compiler tab, the General category is presented and it should be
set 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
Micriµm
µC/OS-II and the Fujitsu MB91403
Because we place source files in multiple directories, the Include Path category was set as
shown in Figure 3-6 and contains the following entries:
C:\Micrium\Software\uCOS-II\Source
C:\Micrium\Software\uCOS-II\Ports\FR\Softune
C:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OS
C:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\BSP
Click here
to add
new paths
Project
Paths
12
Micriµm
µC/OS-II and the Fujitsu MB91403
General
Define Macro
Include Path
Target Depend
Output List
When you click on the Assembler tab, the General category is presented and it should be set as
shown in Figure 3-7.
We didn’t have any macros to define and thus, didn’t need to do anything with the Define Macro
category.
Because we place source files in multiple directories, the Include Path category was set as
shown in Figure 3-8 and contains the following entries:
C:\Micrium\Software\uCOS-II\Ports\FR\Softune
C:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OS
C:\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\BSP
The Target Depend and Output List categories were not changed from their defaults.
13
Micriµm
µC/OS-II and the Fujitsu MB91403
Click here
to add
new paths
Project
Paths
General
Disposition/Connection
Define Symbol
Output List
Absolute Assembly List
Control Library
When you click on the Linker tab, the General category is presented and it should be set as
shown 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 since
it defines the memory map of the project and the different linker sections.
14
Micriµm
µC/OS-II and the Fujitsu MB91403
Click here to
add new
options
Sets
Memory
Map
The Define Symbol category was not changed from its default.
15
Micriµ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.
Generate
Link Map
Create a
Memory
Usage List
Each
memory
section will
be detailed
16
Micriµm
µC/OS-II and the Fujitsu MB91403
3.02 Debugging
The example code provided in this application note contains all the setup files you need to start
debugging. Assuming the MB91943EB is connected as shown in Figure 1-3, you can:
2) Assuming there are no compiler errors, then you can start debugging by clicking on the
Debug menu item and the Start debug sub-menu item as shown in Figure 3-12.
3) If everything loaded correctly, you should see something similar to the screen shown in
Figure 3-13.
4) If you click on the Run continuously icon, the 8 LEDs on the MB91943EB should be
blinking from left-to-right and back (or up-and-down depending on the orientation of the
board).
17
Micriµm
µC/OS-II and the Fujitsu MB91403
Start
Execution
startup.asm
code window
18
Micriµm
µC/OS-II and the Fujitsu MB91403
19
Micriµm
µC/OS-II and the Fujitsu MB91403
20
Micriµm
µC/OS-II and the Fujitsu MB91403
\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\OS
BSP_IntDisAll(); (2)
See
APP_CFG.H
OSInit(); (3) For task stack
sizes
OSTaskCreateExt(AppTaskStart, (4)
(void *)0,
(OS_STK *)&AppTaskStartStk[APP_TASK_START_STK_SIZE - 1],
APP_TASK_START_PRIO,
APP_TASK_START_PRIO,
(OS_STK *)&AppTaskStartStk[0], See
APP_TASK_START_STK_SIZE,
(void *)0,
APP_CFG.H
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); For task
priorities
#if OS_TASK_NAME_SIZE > 13
OSTaskNameSet(APP_TASK_START_PRIO, "Startup", &err); (5)
#endif
OSStart(); (6)
}
L4-1(2) We start off by calling a BSP function (see bsp.c) that will disable all interrupts. We
do this to ensure that initialization doesn’t get interrupted in case we do a ‘warm
restart’.
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
Micriµ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 our
first 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.
(void)p_arg;
BSP_Init(); (1)
LED_Off(0); (5)
AppTaskCreate(); (6)
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. The
statistic task measures overall CPU usage (expressed as a percentage) and also
performs stack checking for all the tasks that have been created with
OSTaskCreateExt() 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
Micriµm
µC/OS-II and the Fujitsu MB91403
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 our
case, we don’t have any other tasks. However, it’s cleaner to have a function to
create 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 8
LEDs on the MB91943EB in sequence.
The reason this is done here is to make it easier to configure your application from a single file.
The other entries in the table are filled with ‘AppIllegal()’ and will thus vector to this location
should one of the non-configured interrupts occur.
If you need to add additional interrupt service routines, you will need to add the appropriate entry
in this table.
23
Micriµm
µC/OS-II and the Fujitsu MB91403
24
Micriµm
µC/OS-II and the Fujitsu MB91403
The BSP for the MB91943EB board is found in the follow directory.
\Micrium\Software\EvalBoards\Fujitsu\MB91943EB\Softune\BSP
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.h
FR70E.inc
mb91403_a.inc
lib911if.lib
25
Micriµm
µC/OS-II and the Fujitsu MB91403
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.
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 the
GPIO 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 application
can call LED_On(), LED_Off() or LED_Toggle() to turn on, off and toggle the
board’s LEDs, respectively.
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:
Crystal Freq / 4
Tick Rate = ------------------ = 125.89 Hz
Timer Reload Value
Where, Crystal Freq is 33 MHz for the MB91943EB and Timer Reload Value is 65536 because
of the free-running mode. The tick rate is thus 125.89 Hz.
26
Micriµm
µC/OS-II and the Fujitsu MB91403
When Timer #0 counts down to 0x0000, the timer is reloaded with 0xFFFF and an interrupt is
generated. If interrupts are enabled, the CPU pushes the PS and PC onto the current task’s
stack and jumps to the vector stored at INT #24 (see APP_VECT.ASM). In this case, the vector is
the address of BSP_TickISR() and the code for this function is found in BSP_A.ASM (see
section 5.03). BSP_TickISR() saves the the remaining processor registers and calls
BSP_TickISR_Handler() which services the interrupt using C code instead of assembly
language. The code for BSP_TickISR_Handler() is shown in Listing 5-3.
27
Micriµm
µC/OS-II and the Fujitsu MB91403
References
µC/OS-II, The Real-Time Kernel, 2nd Edition
Jean J. Labrosse
R&D Technical Books, 2002
ISBN 1-57820-103-9
Contact Information
Micriµm
949 Crestview Circle
Weston, FL 33327
USA
954-217-2036
954-217-2037 (FAX)
e-mail: Jean.Labrosse@Micrium.com
WEB: www.Micrium.com
28