CHAPTER 2 SYSTEM CONSTRUCTION


This chapter describes how to build a system (load module) that uses the functions provided by the RI78V4.

2.1 Outline

System building consists in the creation of a load module using the files (kernel library, etc.) installed on the user development environment (host machine) from the RI78V4's supply media.

The following shows the procedure for organizing the system.

Figure 2-1 Example of System Construction



2.2 Coding of Processing Program

Code the processing that should be implemented in the system.

In the RI78V4, the processing program is classified into the following three types, in accordance with the types and purposes of the processing that should be implemented.

- Tasks
A task is processing program that is not executed unless it is explicitly manipulated via service calls provided by the RI78V4, unlike other processing programs (cyclic handler and interrupt handler).

Note For details about the task, refer to "3.2 Tasks".

- Cyclic Handlers
The cyclic handler is a routine dedicated to cycle processing that is activated periodically at a constant interval (activation cycle).
The RI78V4 handles the cyclic handler as a "non-task (module independent from tasks)". Therefore, even if a task with the highest priority in the system is being executed, the processing is suspended when a specified activation cycle has come, and the control is passed to the cyclic handler.


Note For details about the cyclic handler, refer to "7.5 Cyclic Handlers".

- Interrupt Handlers
The interrupt handler is a routine dedicated to interrupt servicing that is activated when an interrupt occurs.
The RI78V4 handles the interrupt handler as a "non-task (module independent from tasks)". Therefore, even if a task with the highest priority in the system is being executed, the processing is suspended when an interrupt occurs, and the control is passed to the interrupt handler.


Note 1 For details about the interrupt handler, refer to "9.3 Interrupt Handlers".

Note 2 The user must code the interrupt handlers that calls the Timer Handler.

2.3 Coding of System Configuration File

Code the SYSTEM CONFIGURATION FILE required for creating information files (system information table file, system information header file, Interrupt information definition file) that contain data to be provided for the RI78V4.

Note For details about the system configuration file, refer to "CHAPTER 13 SYSTEM CONFIGURATION FILE".

2.4 Coding of User-Own Coding Module

Code the user-own coding modules that are extracted to allow the RI78V4 to be supported in various execution environments.

In the RI78V4, the user-own coding module is classified into the following four types, in accordance with the types and purposes of the processing that should be implemented.

- Interrupt Entry Processing
A routine dedicated to entry processing that is extracted from the INTERRUPT MANAGEMENT FUNCTIONS as a user-own coding module to assign instructions to branch to relevant processing (such as Interrupt Handlers or Boot Processing), to the vector table address to which the CPU forcibly passes the control when an interrupt occurs.

Note 1 For details about the interrupt entry processing, refer to "9.2 Interrupt Entry Processing".

Note 2 When the interrupt handler is described by C language (the TA_HLNG attribute is specified in a interrupt handler definition of the system configuration file(DEF_INH)), the user does not have to describe interrupt entry processing because of the C compiler outputing "interrupt entry processing which corresponds to an interrupt request name" automatically.

- Boot Processing
A routine dedicated to initialization processing that is extracted from the SYSTEM CONFIGURATION MANAGEMENT FUNCTIONS as a user-own coding module to initialize the minimum required hardware for the RI78V4 to perform processing. It is called from Interrupt Entry Processing that is assigned to the vector table address to which the CPU forcibly passes the control when a reset interrupt occurs.

Note For details about the boot processing, refer to "10.2 Boot Processing".

- Initialization Routine
A routine dedicated to initialization processing that is extracted from the SYSTEM CONFIGURATION MANAGEMENT FUNCTIONS as a user-own coding module to initialize the hardware dependent on the user execution environment (such as the peripheral controller), and is called from the Kernel Initialization Module.

Note For details about the initialization routine, refer to "10.3 Initialization Routine".

- Idle Routine
A routine dedicated to idle processing that is extracted from the SCHEDULER as a user-own coding module to utilize the standby function provided by the CPU (to achieve the low-power consumption system), and is called from the scheduler when there no longer remains a task subject to scheduling by the RI78V4 (task in the RUNNING or READY state) in the system.

Note For details about the idle routine, refer to "11.7 Idle Routine".

2.5 Start address of section

Specifies the start address of section by the user to fix the address allocation done by the linker. In the RI78V4, the allocation destinations (section names) of management objects modularized for each function are specified.

The following lists the section names prescribed in the RI78V4.

Table 2-1 RI78V4 Section

Section Name

ROM/RAM

Relocation Attribute

Description

.kernel_system

Code flash

area

TEXTF

Area where the RI78V4's core processing part and main processing part of service calls provided by the RI78V4 are to be allocated.

The start can be aligned at an even address in the area from 0x000c0 to 0xeffff.

.kernel_system_timer_n

Code flash

area

TEXT

Area where the interrupt for system timer and information of FAR branch are to be allocated.

The start can be aligned at an even address in the area from 0x000c0 to 0x0ffff.

.kernel_info

Code flash

area

CONSTF

Area where information items such as the RI78V4 version are to be allocated.

The start can be aligned at an even address that does not span a 64K-1 boundary.

.kernel_const

.kernel_const_f

Code flash

area

CONSTF

Area where initial information items related to OS resources that do not change dynamically are allocated as system information tables and Interrupt infomation definition file.

The start can be aligned at an even address that does not span a 64K-1 boundary.

.kernel_stack

RAM area

BSS

Area where the system stack and the task stack are to be allocated.

The start can be aligned at an even address in the built-in RAM area from 0xf0000 to 0xfffff and that does not span a 64K-1 boundary.

.kernel_data

RAM area

BSS

Area where information items required to implement the functionalities provided by the RI78V4 and information items related to OS resources that change dynamically are allocated as management objects.

The start can be aligned at an even address in the built-in RAM area from 0xf0000 to 0xfffff and that does not span a 64K-1 boundary.

.kernel_data_init

RAM area

BSS

Area where initial information items of RI78V4 are to be allocated.

The start can be aligned at an even address in the built-in RAM area from 0xf0000 to 0xfffff and that does not span a 64K-1 boundary.

.kernel_work0

.kernel_work1

.kernel_work2

.kernel_work3

RAM area

BSS

Area where data queues and fixed-sized memory pools are to be allocated.

The start can be aligned at an even address in the built-in RAM area from 0xf0000 to 0xfffff and that does not span a 64K-1 boundary.

.kernel_data_trace_n

RAM area

BSS

Area where the trace data are to be allocated.

The start can be aligned at an even address in the built-in RAM area from 0xf0000 to 0xfffff and that does not span a 64K-1 boundary.

.kernel_const_trace_f

Code flash

area

CONSTF

Area where information items to get trace data are to be allocated.

The start can be aligned at an even address that does not span a 64K-1 boundary.

.kernel_system_trace_f

Code flash

area

TEXTF

Area where the processing part to get trace data are to be allocated.

The start can be aligned at an even address in the area from 0x000c0 to 0xeffff.

.kernel_sbss

RAM area

SBSS

SADDR area where the RI78V4's core processing are to be allocated.

The start can be aligned at an even address in the saddr area.



Note 1 Specification of .kernel_work0, .kernel_work1, .kernel_work2 and .kernel_work3 is required only when the relevant section names are specified in Data queue information and Fixed-sized memory pool information.

Note 2 The RI78V4 occupies the 8-byte area from the saddr area (0xffe20 to 0xfff1f). Therefore, the available saddr area for the user is up to 247 bytes.

Note 3 The section for RI78V4 is set automatically on CS+. When you want to change the start address of section, changes in the linker setting. For details about the directive file, refer to "CS+ RL78 Building".

Note 4 For details about the directive file, refer to "CS+ RL78 Coding".

2.5.1 .kernel_system section

The size of the .kernel_system section is approximately 1 KB to 9 KB depends on the service calls used in the processing program.

2.5.2 .kernel_system_timer_n section

The following shows an expression required for estimating the .kernel_system_timer_n section size (unit: bytes).

system_timer_n = 16 + (inthnum_FAR * 8)

inthnum_FAR: Total amount of Interrupt handler information with TA_FAR attribute

2.5.3 .kernel_system_trace_f section

The following shows an expression required for estimating the .kernel_system_trace_f section size (unit: bytes).

[ When the trace mode is "Not tracing" ]

system_trace_f = 0

[ When the trace mode is "Takes in trace chart by hardware trace mode" ]

system_trace_f = 184

[ When the trace mode is "Takes in trace chart by software trace mode" ]

system_trace_f = 706

[ When the trace mode is "Takes in long-statistics by software trace mode" ]

system_trace_f = 590

2.5.4 .kernel_info section

The size of the .kernel_info section is approximately 16 bytes.

2.5.5 .kernel_const section

The following shows an expression required for estimating the .kernel_const section size (unit: bytes).

const = ( tsknum * 10 ) + semnum + flgnum + ( dtqnum * 5 ) + ( mpfnum * 8 ) + ( cycnum * 12 ) + ( kindnum * 4 ) + 16

tsknum: Total amount of Task information

semnum: Total amount of Semaphore information

flgnum: Total amount of Eventflag information

dtqnum: Total amount of Data queue information

mpfnum: Total amount of Fixed-sized memory pool information

kindnum: Total number of types defined in the system configuration file among five types of information related to OS resources (Semaphore information, Eventflag information, Data queue information, Mailbox information, Fixed-sized memory pool information and Cyclic handler information)

2.5.6 .kernel_const_f section

The following shows an expression required for estimating the .kernel_const_f section size (unit: bytes).

[ When the trace mode is "Not tracing" ]

const_f = 0

[ When the trace mode is "Takes in trace chart by hardware trace mode" ]

const_f = 0

[ When the trace mode is "Takes in trace chart by software trace mode" ]

const_f = 0

[ When the trace mode is "Takes in long-statistics by software trace mode" ]

const_f = 63

2.5.7 .kernel_stack section

The following shows an expression required for estimating the .kernel_stack section size (unit: bytes).

tsknum

stack = ( stksz k + 20 ) + ( sys_stksz + 2 )

k = 1

tsknum: Total amount of Task information

stksz k: Stack size specified in Task information

sys_stksz: Stack size specified in System stack information. When multiple interrupt occurs, adds 18 bytes every one time.

2.5.8 .kernel_data section

The following shows an expression required for estimating the .kernel_data section size (unit: bytes).

The expression varies depending on whether or not Semaphore information is defined in the system configuration file.

[ When semaphore information is defined ]

data = align2 ( maxtpri + 1 ) + align2 { ( tsknum * 24 ) + ( semnum * 2 ) + 1 } + align2 ( flgnum * 3 ) + align2 { ( dtqnum * 4 ) + 1} + ( mbxnum * 8 ) + align2 ( primbx ) + ( mpfnum * 4 ) + ( cycnum * 8 ) + 20

[ When semaphore information is not defined ]

data = align2 ( maxtpri + 1 ) + ( tsknum * 24 ) + align2 ( flgnum * 3 ) + align2 { ( dtqnum * 4 ) + 1} + ( mbxnum * 8 ) + align2 ( primbx ) + ( mpfnum * 4 ) + ( cycnum * 8 ) + 20

maxtpri: Priority range specified in Task priority information

tsknum: Total amount of Task information

semnum: Total amount of Semaphore information

flgnum: Total amount of Eventflag information

dtqnum: Total amount of Data queue information

mbxnum: Total amount of Mailbox information

primbx: Total amount of Mailbox information for which the priority is specified for the attribute (message queuing method)

mpfnum: Total amount of Fixed-sized memory pool information

cycnum: Total amount of Cyclic handler information

2.5.9 .kernel_data_init section

The size of the .kernel_data_init section is approximately 2 bytes.

2.5.10 .kernel_work0, .kernel_work1, .kernel_work2, .kernel_work3 section

The following shows an expression required for estimating the size of the .kernel_work0, .kernel_work1, .kernel_work2, and .kernel_work3 section (unit: bytes).

mpfnum dtqnum

workX = ( blkcnt kblksz k ) ( dtqcnt k4 )

k = 1 k = 1

mpfnum: Total number of section units for Fixed-sized memory pool information

blkcnt k: Number of fixed-sized memory blocks specified in Fixed-sized memory pool information

blksz k: Block size specified in Fixed-sized memory pool information

dtqnum: Total number of section units for Data queue information

dtqcnt k: Number of datq queue specified in Data queue information

2.5.11 .kernel_data_trace_n section

The following shows an expression required for estimating the .kernel_data_trace_n section size (unit: bytes).

[ When the trace mode is "Not tracing" ]

data_trace_n = 0

[ When the trace mode is "Takes in trace chart by hardware trace mode" ]

data_trace_n = 2

[ When the trace mode is "Takes in trace chart by software trace mode" ]

data_trace_n = 8 + bufsize

bufsize: Trace buffer size

[ When the trace mode is "Takes in long-statistics by software trace mode" ]

data_trace_n = { ( tsknum + 1) * 20 ) } + { ( inhnum + 1)* 8 ) }34

tsknum: Total amount of Task information

inhnum: Total amount of Interrupt handler information

2.5.12 .kernel_const_trace_f section

The following shows an expression required for estimating the .kernel_const_trace_f section size (unit: bytes).

[ When the trace mode is "Not tracing" ]

const_trace_n = 6

[ When the trace mode is "Takes in trace chart by hardware trace mode" ]

const_trace_n = 64

[ When the trace mode is "Takes in trace chart by software trace mode" ]

const_trace_n = 70

[ When the trace mode is "Takes in long-statistics by software trace mode" ]

const_trace_n = 70



2.6 Creating Load Module

Run a build on the CS+ for files created in sections from "2.2 Coding of Processing Program" to "2.5 Start address of section", and library files provided by the RI78V4 and C compiler package, to create a load module.

The following lists the files required for creating load modules.

1 ) Create or load a project

Create a new project, or load an existing one.

Note See "RI Series Start" or "CS+ Start" for details about creating a new project or loading an existing one.

2 ) Set a build target project

When making settings for or running a build, set the active project.

If there is no subproject, the project is always active.

Note See "CS+ Build" for details about setting the active project.

3 ) Set build target files

For the project, add or remove build target files and update the dependencies.

Note See "CS+ Build" for details about adding or removing build target files for the project and updating the dependencies.

The following lists the files required for creating a load module.

- C/assembly language source files created in "2.2 Coding of Processing Program"

- Tasks, Cyclic Handlers, Interrupt Handlers

- System configuration file created in "2.3 Coding of System Configuration File"

- SYSTEM CONFIGURATION FILE

Note Specify "cfg" as the extention of the system configuration file name.
If the extension is different, "cfg" is automatically added (for example, if you designate "aaa.c" as a file name, the file is named as "aaa.c.cfg").


- C/assembly language source files created in "2.4 Coding of User-Own Coding Module"

- Interrupt Entry Processing, Boot Processing, Initialization Routine, Idle Routine

- Directive file created in "2.5 Start address of section"

- Directive file

- Files provided by the RI78V4

- Trace information file

- Library files provided by the RI78V4

- Kernel library

- Library files provided by the C compiler/assembler package

- Standard library, runtime library, etc.

Note 1 If the system configuration file is added to the Project Tree panel, the Realtime OS generated files node is appeared.
The following information files are appeared under the Realtime OS generated files node. However, these files are not generated at this point in time.


- System information table file

- System information header file (for C language)

- System information header file (for assembly language)

- Interrupt Information definition file

Figure 2-2 Project Tree Panel (After Adding sys.cfg)





Note 2 When replacing the system configuration file, first remove the added system configuration file from the project, then add another one again.

Note 3 Although it is possible to add more than one system configuration files to a project, only the first file added is enabled. Note that if you remove the enabled file from the project, the remaining additional files will not be enabled; you must therefore add them again.

4 ) Set the output of information files

Select the system configuration file on the project tree to open the Property panel.

On the [System Configuration File Related Information] tab, set the output of information files (system information table file and system information header files).

Figure 2-3 Property Panel: [System Configuration File Related Information] Tab



5 ) Specify the output of a load module file

Set the output of a load module file as the product of the build.

Note See "CS+ RL78 Build" for details about specifying the output of a load module file.

6 ) Set trace information

Set the detailed information on the using task analyzer in RI78V4 package.

Figure 2-4 [Task Analyzer] Tab



7 ) Set build options

Set the options for the compiler, assembler, linker, and the like.

Note See "CS+ RL78 Build" for details about setting build options.

8 ) Run a build

Run a build to create a load module.

Note See "CS+ RL78 Build" for details about runnig a build.

Figure 2-5 Project Tree Panel (After Running Build)



9 ) Save the project

Save the setting information of the project to the project file.

Note See "CS+ Start" for details about saving the project.

2.7 Embedding System

If the output of hex files are set in 4 ) of "2.6 Creating Load Module", hex files are created.

After that, embed the modules to the system by using a flash programmer.