Page 1
REJ10J1025-0200Z M3T-MR308/4 V.4.00 User’s Manual Real-time OS for M16C/70,80,M32C/80 Series Rev.2.00 Nov 1, 2005...
Page 2
These materials are intended as a reference to assist our customers in the selection of the Renesas Technology product best suited to the customer's application; they do not convey any license under any intellectual property rights, or any other rights, belonging to Renesas Technology Corporation, Renesas Solutions Corporation or a third party.
Page 3
For the detailed information on individual service call procedures, refer to the MR308 Reference Manual. Requirements for MR308 Use When creating programs based on the MR308, it is necessary to purchase the following product of Renesas. • C-compiler package M3T-NC308WA(abbreviated as NC308) for M16C/70,80 M32C/80 series micro-...
Page 7
Warning messages ... - 131 - Other messages... - 131 - Editing makefile ... - 132 - About an error when you execute make... - 133 - Application Creation Guide ... - 135 - Chapter 7 Processing Procedures for System Calls from Handlers... - 136 - 7.1.1 System Calls from a Handler That Caused an Interrupt during Task Execution ...
Page 8
List of Figures Figure 3.1 Relationship between Program Size and Development Period...- 10 - Figure 3.2 Microcomputer-based System Example(Audio Equipment) ... - 11 - Figure 3.3 Example System Configuration with Real-time OS(Audio Equipment) ...- 12 - Figure 3.4 Time-division Task Operation ...- 13 - Figure 3.5 Task Execution Interruption and Resumption ...- 13 - Figure 3.6 Task Switching ...- 14 - Figure 3.7 Task Register Area...- 15 -...
Page 9
Figure 5.2 Example Task Terminating with ext_tsk() Described in C Language...- 68 - Figure 5.3 Example of Kernel(OS-dependent) Interrupt Handler...- 70 - Figure 5.4 Example of Non-kernel(OS-independent) Interrupt Handler...- 71 - Figure 5.5 Example Cyclic Handler Written in C Language ...- 72 - Figure 5.6 Example Infinite Loop Task Described in Assembly Language...- 73 -...
Page 10
List of Tables Table 3-1 Task Context and Non-task Context ...- 27 - Table 3-2 Invocable Service Calls in a CPU Locked State ...- 29 - Table 3-3 CPU Locked and Dispatch Disabled State Transitions Relating to dis_dsp and loc_cpu - 29 - Table 3.4 List of the service call can be issued from the task and handler...- 55 - Table 5.1...
Page 12
The MR308 User’s Manual consists of nine chapters and thee appendix. • Chapter 2 General Information Outlines the objective of MR308 development and the function and position of the MR308. • Chapter 3 Introduction to MR308 Explains about the ideas involved in MR308 operations and defines some relevant terms. •...
OS To answer the above-mentioned demand, Renesas has developed a real-time operating system, tradenamed MR308, for use with the M16C/70, 80 and M32C/80 series of 16/32-bit microcomputers . When the MR308 is introduced, the following advantages are offered.
Page 15
7. Timer control is made easier. To perform processing at 10 ms intervals, the microcomputer timer function was formerly used to pe- riodically initiate an interrupt. However, as the number of usable microcomputer timers was limited, timer insufficiency was compensated for by, for instance, using one timer for a number of different processing operations.
Furthermore, in 1999, µITRON 4.0 Specification with enhanced compatibility was established. MR308 is the real-time operating system developed for use with the M16C/70, 80 and M32C/80 series of 16/32-bit microcomputers compliant with µITRON 4.0 Specification. µITRON 4.0 Specification stipulates stan- dard profiles as an attempt to ensure software portability.
3. Only necessary modules are automatically selected to constantly build up a system of the minimum size. MR308 is supplied in the object library format of the M16C/70, 80 and M32C/80 series. Therefore, the Linkage Editor LN308 functions are activated so that only necessary modules are automatically selected from numerous MR308 functional modules to generate a system.
Chapter 3 Introduction to MR308 3.1 Concept of Real-time OS This section explains the basic concept of real-time OS. 3.1.1 Why Real-time OS is Necessary In line with the recent advances in semiconductor technologies, the single-chip microcomputer ROM capacity has increased. ROM capacity of 32K bytes. As such large ROM capacity microcomputers are introduced, their program development is not easily carried out by conventional methods.
Key input microcomputer Volume control microcomputer Figure 3.2 Microcomputer-based System Example(Audio Equipment) Using independent microcomputers for various functions as indicated in the above example offers the following advantages. 1. Individual programs are small so that program development is easy. 2. It is very easy to use previously developed software. 3.
Key input Task Volume control Task Figure 3.3 Example System Configuration with Real-time OS(Audio Equipment) In other words, the real-time OS is the software that makes a one-microcomputer system look like operating a number of microcomputers. In the real-time OS, the individual programs, which correspond to a number of microcomputers used in a con- ventional system, are called tasks.
3.1.2 Operating Principles of Real-time OS The real-time OS is the software that makes a one-microcomputer system look like operating a number of mi- crocomputers. You should be wondering how the real-time OS makes a one-microcomputer system function like a number of microcomputers. As shown in Figure 3.4 the real-time OS runs a number of tasks according to the time-division system.
In the state shown in Figure 3.5, it appears to the programmer that the key input task or its microcomputer is halted while another task assumes execution control. Task execution restarts at the point of last interruption as the register contents prevailing at the time of the last interruption are recovered.
Remote control Task Key input Task LED illumination Task Real-time Figure 3.8 shows the register and stack area of one task in detail. In the MR308, the register of each task is stored in a stack area as shown in Figure 3.8. This figure shows the state prevailing after register storage. Register not stored Key input Task...
Page 26
3.2 Service Call How does the programmer use the real-time OS in a program? First, it is necessary to call up a real-time OS function from the program in some way or other. Calling a real-time OS function is referred to as a service call. Task activation and other processing operations can be initiated by such a service call (See Figure 3.9).
3.2.1 Service Call Processing When a service call is issued, processing takes place in the following sequence. 1. The current register contents are saved. 2. The stack pointer is changed from the task type to the real-time OS (system) type. 3.
3.2.2 Task Designation in Service call Each task is identified by the ID number internally in MR308. For example, the system says, "Start the task having the task ID number 1." However, if a task number is directly written in a program, the resultant program would be very low in readability. If, for instance, the following is entered in a program, the programmer is constantly required to know what the No.
3.3 Task This section describes how tasks are managed by MR308. 3.3.1 Task Status The real-time OS monitors the task status to determine whether or not to execute the tasks. Figure 3.12 shows the relationship between key input task execution control and task status. When there is a key input, the key input task must be executed.
READY state WAITING SUSPENDED state clear request from other task SUSPEND request from other task SUSPENDED state clear request Forced termination request from other task Task activation 1. RUNNING state In this state, the task is being executed. Since only one microcomputer is used, it is natural that only one task is being executed.
Page 31
to the ready queue is placed in the RUNNING state. ♦ A currently executed task has normally terminated itself. ♦ A currently executed task has placed itself in the WAITING state. ♦ A currently executed task has changed its own priority so that the priority of a different READY task is rendered higher.
Page 32
4. SUSPENDED state When the sus_tsk system call is issued from a task in the RUNNING state or the isus_tsk system call is issued from a handler, the READY task designated by the system call or the currently executed task enters the SUSPENDED state.
3.3.2 Task Priority and Ready Queue In the real-time OS, several tasks may simultaneously request to be executed. In such a case, it is necessary to determine which task the system should execute first. To properly handle this kind of situation, the system or- ganizes the tasks into proper execution priority and starts execution with a task having the highest priority.
3.3.3 Task Priority and Waiting Queue In The standard profiles in µITRON 4.0 Specification support two waiting methods for each object. In one method, tasks are placed in a waiting queue in order of priority (TA_TPRI attribute); in another, tasks are placed in a waiting queue in order of FIFO (TA_TFIFO).
3.3.4 Task Control Block(TCB) The task control block (TCB) refers to the data block that the real-time OS uses for individual task status, priority, and other control purposes. The MR308 manages the following task information as the task control block •...
Task Connection pointer Status Priority Wake-up counter Flag wait mode Time-out counter Flag wait pattern Timer queue This area is allocated only when Connection pointer the timeout function is used. Flag wait pattern Figure 3.17 Task control block - 26 -...
3.4 System States 3.4.1 Task Context and Non-task Context The system runs in either context state, "task context" or "non-task context." The differences between the task content and non-task context are shown in Table 3-1. Task Context and Non-task Context. Table 3-1 Invocable service call Task scheduling...
Timer interrupt Figure 3.18 Cyclic Handler/Alarm Handler Activation 3.4.2 Dispatch Enabled/Disabled States The system assumes either a dispatch enabled state or a dispatch disabled state. In a dispatch disabled state, no task scheduling is performed. Nor can service calls be invoked that may cause the service call issuing task to enter a wait state.
3.4.3 CPU Locked/Unlocked States The system assumes either a CPU locked state or a CPU unlocked state. In a CPU locked state, all external interrupts are disabled against acceptance, and task scheduling is not performed either. The system can be placed into a CPU locked state or a CPU unlocked state by the loc_cpu(iloc_cpu) or unl_cpu(iunl_cpu) service call, respectively.
3.5 MR308 Kernel Structure 3.5.1 Module Structure The MR308 kernel consists of the modules shown in Figure 3.19. Each of these modules is composed of func- tions that exercise individual module features. The MR308 kernel is supplied in the form of a library, and only necessary features are linked at the time of sys- tem generation.
3.5.2 Module Overview The MR308 kernel modules are outlined below. • Scheduler Forms a task processing queue based on task priority and controls operation so that the high-priority task at the beginning in that queue (task with small priority value) is executed. •...
3.5.3 Task Management Function The task management function is used to perform task operations such as task start/stop and task priority up- dating. The MR308 kernel offers the following task management function service calls. • Activate Task (act_tsk, iact_tsk) Activates the task, changing its status from DORMANT to either READY or RUNNING. In this service call, unlike in sta_tsk(ista_tsk), startup requests are accumulated, but startup code cannot be speci- fied.
Priority Figure 3.21 Alteration of task priority ID Number 1 2 taskA 3 Priority 1 n When the priority of Task B is changed into 4 Figure 3.22 Task rearrangement in a waiting queue • Reference task priority (get_pri, iget_pri) Gets the priority of a task.
3.5.4 Synchronization functions attached to task The task-dependent synchronization functions attached to task is used to accomplish synchronization between tasks by placing a task in the WAIT, SUSPENDED, or WAIT-SUSPENDED state or waking up a WAIT state task. The MR308 offers the following task incorporated synchronization service calls. •...
only one forcible wait request to be nested, if sus_tsk is issued to a task in a forcible wait state, the error E_QOVR is returned. (See Figure 3.25). sus_tsk Task RUNNING state WAITING state Number of suspension request Figure 3.25 Forcible wait of a task and resume •...
♦ Timeout wait state ♦ Wait state entered by slp_tsk service call (+ timeout included) ♦ Event flag (+ timeout included) wait state ♦ Semaphore (+ timeout included) wait state ♦ Message (+ timeout included) wait state ♦ Data transmission (+ timeout included) wait state ♦...
3.5.5 Synchronization and Communication Function (Semaphore) The semaphore is a function executed to coordinate the use of devices and other resources to be shared by several tasks in cases where the tasks simultaneously require the use of them. When, for instance, four tasks simultaneously try to acquire a total of only three communication lines as shown in Figure 3.28, communication line-to-task connections can be made without incurring contention.
• Reference Semaphore Status (ref_sem, iref_sem) Refers the status of the target semaphore. Checks the count value and existence of the wait task for the target semaphore. Figure 3.30 shows example task execution control provided by the wai_sem and sig_sem service calls.
3.5.6 Synchronization and Communication Function (Eventflag) The eventflag is an internal facility of MR308 that is used to synchronize the execution of multiple tasks. The eventflag uses a flag wait pattern and a 16-bit pattern to control task execution. A task is kept waiting until the flag wait conditions set are met.
3.5.7 Synchronization and Communication Function (Data Queue) The data queue is a mechanism to perform data communication between tasks. In Figure 3.32, for example, task A can transmit data to the data queue and task B can receive the transmitted data from the data queue. Data Task A Data in width of 32 bits can be transmitted to this data queue.
3.5.8 Synchronization and Communication Function (Mailbox) The mailbox is a mechanism to perform data communication between tasks. In Figure 3.33, for example, task A can drop a message into the mailbox and task B can retrieve the message from the mailbox. Since mail- box-based communication is achieved by transferring the beginning address of a message from a task to an- other, this mode of communication is performed at high speed independently of the message size.
Message queue There are following data queue service calls that are provided by the MR308 kernel. • Send to Mailbox (snd_mbx, isnd_mbx) Transmits a message. Namely, a message is dropped into the mailbox. • Receive from Mailbox (rcv_mbx, trcv_mbx) Receives a message. Namely, a message is retrieved from the mailbox. At this time, if the mailbox has no messages in it, the task is kept waiting until a message is sent to the mailbox.
3.5.9 Memory pool Management Function The memorypool management function provides system memory space (RAM space) dynamic control. This function is used to manage a specific memory area (memorypool), dynamically obtain memory blocks from the memorypool as needed for tasks or handlers, and release unnecessary memory blocks to the memorypool. The MR308 supports two types of memorypool management functions, one for fixed-size and the other for variable-size.
Variable-size Memory Pool Management Function The technique that allows you to arbitrary define the size of memory block acquirable from the memory pool is termed Variable-size scheme. The MR308 manages memory in terms of four fixed-size memory block sizes. The MR308 calculates the size of individual blocks based on the maximum memory block size to be acquired. You specify the maximum memory block size using the configuration file.
200 bytes Rounding 224 bytes • Release Acquire Variable-size Memory Block (rel_mpl) Releases a acquired memory block by pget_mpl service call. Memorypool • Reference Acquire Variable-size Memory Pool Status (ref_mpl, iref_mpl) Checks the total free area of the memory pool, and the size of the maximum free area that can imme- diately be acquired.
3.5.10 Time Management Function The time management function provides system time management, time reading tions of the alarm handler, which actuates at preselected times, and the cyclic handler, which actuates at prese- lected time intervals. The MR308 kernel requires one timer for use as the system clock. There are following time management ser- vice calls that are provided by the MR308 kernel.
Page 58
at the fifth occurrence of the time tick. • Set System Time (set_tim) • Reference System Time (get_tim) The system time indicates an elapsed time from when the system was reset by using 48-bit data. The time is expressed in ms units. - 48 -...
3.5.11 Cyclic Handler Function The cyclic handler is a time event handler that is started every startup cycle after a specified startup phase has elapsed. The cyclic handler may be started with or without saving the startup phase. In the former case, the cyclic han- dler is started relative to the point in time at which it was generated.
3.5.12 Alarm Handler Function The alarm handler is a time event handler that is started only once at a specified time. Use of the alarm handler makes it possible to perform time-dependent processing. The time of day is specified by a relative time. Figure 3.41 shows a typical operation of the alarm handler. Alarm handler operating created...
3.5.13 System Status Management Function • Rotate Task Precedence (rot_rdq, irot_rdq) This service call establishes the TSS (time-sharing system). That is, if the ready queue is rotated at regular intervals, round robin scheduling required for the TSS is accomplished (See Figure 3.42) Priority 1...
3.5.14 Interrupt Management Function The interrupt management function provides a function to process requested external interrupts in real time. The interrupt management service calls provided by the MR308 kernel include the following: • Returns from interrupt handler (ret_int) The ret_int service call activates the scheduler to switch over tasks as necessary when returning from the interrupt handler.
3.5.15 System Configuration Management Function This function inspects the version information of MR308. • References Version Information(ref_ver, iref_ver) The ref_ver service call permits the user to get the version information of MR308. This version infor- mation can be obtained in the standardized format of µITRON specification. 3.5.16 Extended Function (Short Data Queue) The short data queue is a function outside the scope of µITRON 4.0 Specification.
3.5.17 Extended Function (Reset Function) The reset function is a function outside the scope of µITRON 4.0 Specification. It initializes the mailbox, data queue, and memory pool, etc. • Clear Data Queue Area (vrst_dtq) Initializes the data queue. If there are any tasks waiting for transmission, they are freed from WAIT- ING state and the error code EV_RST is returned.
3.5.18 Service calls That Can Be Issued from Task and Handler Some service calls can be issued from a task, others can be issued from non-task context, and still others can be issued from both. These service calls are listed in Table 3.4. Table 3.4 List of the service call can be issued from the task and handler Service Call act_tsk...
4.1 Overview Application programs for MR308 should generally be developed following the procedure described below. 1. Generating a project When using HEW , create a new project using MR308 on HEW. 2. Coding the application program Write the application program in code form using C or assembly language. If necessary, correct the sample startup program (crt0mr.a30) and section definition file (c_sec.inc or asm_sec.inc).
C standard MR308 include file header file Application include file Application C source C compiler nc308 Relocatable Assembler as308 Application C standard object Library Linkage Editor ln308 Absolute module Load module converter lmc308 ROM write format Figure 4.1 MR308 System Generation Detail Flowchart Configuration file Configurator kernel.h...
4.2 Development Procedure Example This chapter outlines the development procedures on the basis of a typical MR308 application example. 4.2.1 Applications Program Coding Figure 4.2 shows a program that simulates laser beam printer operations. Let us assume that the file describing the laser beam printer simulation program is named lbp.c.
4.2.2 Configuration File Preparation Create a configuration file which has defined in it the task entry address, stack size, etc. Use of the GUI con- figurator available for MR308 helps to create a configuration file easily without having to learn how to write it. Figure 4.3 Configuration File Example shows an example configuration file for a laser beam printer simulation program (filename "lbp.cfg").
UNIX compatible make command (e.g., the make command included with the C compiler from Microsoft Corporation). For details about the usefulness of UNIX compatible make commands, refer to the release notes from Renesas. The description in this chapter is made for the case where a UNIX compatible make command is executed, as an example.
5.1 Program Coding Procedure in C Language 5.1.1 Task Description Procedure 1. Describe the task as a function. To register the task for the MR308, enter its function name in the configuration file. When, for instance, the function name "task()" is to be registered as the task ID number 3, proceed as follows. task[3]{ name entry_address...
7. To specify a task, use the string written in the task definition item “name” of the configura- tion file. wup_tsk(ID_main); 8. To specify an event flag, semaphore, or mailbox, use the respective strings defined in the configuration file. For example, if an event flag is defined in the configuration file as shown below, flag[1]{ To designate this eventflag, proceed as follows.
A configuration file is used to define the relationship between handlers and functions. When an kernel(OS-dependent) interrupt handler is declared with #pragma INTHANDLER ,code for the ret_int service call is automati- cally generated. /* process */ iwup_tsk(ID_main); - 70 -...
5.1.3 Writing Non-kernel (OS-independent ) Interrupt Handler When describing the non-kernel(OS-independent) interrupt handler in C language, observe the following pre- cautions. 1. Be sure to declare the return value and argument of the interrupt handler start function as a void type. 2.
5.1.4 Writing Cyclic Handler/Alarm Handler When describing the cyclic or alarm handler in C language, observe the following precautions. 1. Describe the cyclic or alarm handler as a function. 2. Be sure to declare the return value and argument of the interrupt handler start function as a void type.
5.2 Program Coding Procedure in Assembly Language This section describes how to write an application using the assembly language. 5.2.1 Writing Task This section describes how to write an application using the assembly language. 1. Be sure to include "mr308.inc" at the beginning of file. 2.
Page 84
Chapter 5 Detailed Applications 8. Set a task that is activated at MR308 system startup in the configuration file The relationship between task ID numbers and tasks(program) is defined in the configuration file. - 74 -...
5.2.2 Writing Kernel(OS-dependent) Interrupt Handler When describing the kernel(OS-dependent) interrupt handler in assembly language, observe the following pre- cautions 1. At the beginning of file, be sure to include "mr308.inc" which is in the system directory. 2. For the symbol indicating the interrupt handler start address, make the external declara- tion(Global declaration).
5.2.3 Writing Non-kernel(OS-independent) Interrupt Handler 1. For the symbol indicating the interrupt handler start address, make the external declaration (public declaration). 2. Make sure that the registers used in a handler are saved at the entry and are restored after use.
5.2.4 Writing Cyclic Handler/Alarm Handler When describing the cyclic or alarm handler in Assembly Language, observe the following precautions. 1. At the beginning of file, be sure to include "mr308.inc" which is in the system directory. 2. For the symbol indicating the handler start address, make the external declaration. 3.
5.3 The Use of INT Instruction MR308 has INT instruction interrupt numbers reserved for issuing service calls as listed in Table 5.2. For this reason, when using software interrupts in a user application, do not use interrupt numbers 63 through 55 and be sure to use some other numbers.
5.5 Regarding Interrupts 5.5.1 Types of Interrupt Handlers MR308's interrupt handlers (OS-independent) interrupt handlers. The following shows the definition of each type of interrupt handler. • Kernel(OS-dependent) interrupt handler The kernel(OS-dependent) interrupt handler is defined as one that satisfies one of the following two conditions: ♦...
5.5.3 Controlling Interrupts Interrupt enable/disable control in a service call is accomplished by IPL manipulation. The IPL value in a service call is set to the kernel mask level(OS interrupt disable level = system.IPL) in order to disable interrupts for the kernel(OS-dependent) interrupt handler.
, the interrupt enable flag and IPL change in a service call. For this reason, if you want to disable interrupts in a user application, Renesas does not recommend using the method for manipulating the interrupt disable flag and IPL to disable the interrupts.
5.6 Regarding Delay Dispatching MR308 has four service calls related to delay dispatching. • dis_dsp • ena_dsp • loc_cpu • unl_cpu The following describes task handling when dispatch is temporarily delayed by using these service calls. 1. When the execution task in delay dispatching is preempted While dispatch is disabled, even under conditions where the task under execution should be pre- empted, no time is dispatched to new tasks that are in an executable state.
Chapter 5 Detailed Applications 5.7 Regarding Initially Activated Task MR308 permits the user to specify a task that starts from a READY state at system startup time. To do this, add TA_STA as task attribute. This specification should be set in a configuration file. For details on how to set, refer to page - 105 -.
5.8 Modifying MR308 Startup Program MR308 comes with two types of startup programs as described below. • start.a30 This startup program is used when you created a program using the assembly language. • crt0mr.a30 This startup program is used when you created a program using the C language. This program is derived from "start.a30"...
C language startup program(crt0mr.a30). 1 ;**************************************************************** MR308 start up program for C language COPYRIGHT(C) 2003 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED MR308 V.1.10 Release 1 8 ; **************************************************************** "$Id: crt0mr.a30,v 1.1 2005/05/20 06:28:47 inui Exp $"...
Page 99
The following explains the content of the C language startup program (crt0mr.a30). 1. Incorporate a section definition file [13 in Figure 5.14] 2. Incorporate an include file for MR308 [14 in Figure 5.14] 3. Incorporate a system ROM area definition file [15 in Figure 5.14] 4.
5.9 Memory Allocation This section describes how memory is allocated for the application program data. Use the section file provided by MR308 to set memory allocation. MR308 comes with the following two types of section files: • asm_sec.inc This file is used when you developed your applications with the assembly language. Refer to page - 91 - for details about each section.
5.9.1 Section Allocation of start.a30 The section allocation of the sample startup program for the assembly language "start.a30" is defined in "asm_sec.inc". Edit "asm_sec.inc" if section reallocation is required. The following explains each section that is defined in the sample section definition file "asm_sec.inc". •...
5.9.2 Section Allocation of crt0mr.a30 The section allocation of the sample startup program for the C language "crt0mr.a30" is defined in "c_sec.inc". Edit "c_sec.inc" if section reallocation is required. The sections defined in the sample section definition file "c_sec.inc" include the following sections that are de- fined in the section definition file "asm_sec.inc"...
5.10 Using in M16C/70 Series When you use M16C/70 series, please be sure to set up the following options. Refer to the manual of each tool for detailed explanation of these options. 《NC308 Compile option》 -D M16C70=1 《AS308 Assemble option》...
6.1 Configuration File Creation Procedure When applications program coding and startup program modification are completed, it is then necessary to reg- ister the applications program in the MR308 system. This registration is accomplished by the configuration file. 6.1.1 Configuration File Data Entry Format This chapter describes how the definition data are entered in the configuration file.
Operator (Unary_minus) ∗ (Binary_minus) Numerical value examples are presented below. • • 123 + 0x23 • (23/4 + 3) ∗ 2 • 100B + 0aH Symbol The symbols are indicated by a character string that consists of numerals, upper- and lower-case al- phabetical letters, _(underscore), and ?, and begins with a non-numeric character.
Page 108
• 10ms • 10.5ms It is also well to remember that the time must not begin with . (period). - 98 -...
6.1.2 Configuration File Definition Items The following definitions are to be formulated in the configuration file • System definition • System clock definition • Respective maximum number of items • Task definition • Eventflag definition • Semaphore definition • Mailbox definition •...
Page 110
2. Maximum value of priority (value of lowest priority) [( Definition format )] [( Definition range )] [( Default value )] Define the maximum value of priority used in MR308's application programs. This must be the value of the highest priority used. 3.
Define the MPU operating clock frequency of the microcomputer in MHz units. For the M16C/70 series, set the same value as the one that is set for the peripheral function operating clock, f1. The M16C/70 series requires that compile options be set. For details, refer to Page - 94 -.
[( Definition respective maximum numbers of items )] This definition is to be given only in forming the separate ROMs. Here, define respective maximum numbers of items to be used in two or more applications. << Format >> // Max Definition maxdefine{ the maximum number of tasks defined max_task...
Page 113
5. The maximum number of semaphores defined [( Definition format )] [( Definition range )] [( Default value )] Define the maximum number of semaphores defined. 6. The maximum number of fixed-size memory pools defined [( Definition format )] [( Definition range )] [( Default value )] 7.
[( Task definition )] << Format >> // Tasks Definition ID No. task[ name entry_address stack_size priority context stack_section initial_start exinf The ID number must be in the range of 1 to 255. The ID number can be omitted. If omitted, numbers are automatically assigned sequentially beginning with the smallest. <<...
Page 115
3. User stack size of task [( Definition format )] [( Definition range )] [( Default value )] Define the user stack size for each task. The user stack means a stack area used by each individual task. MR308 requires that a user stack area be allocated for each task, which amount to at least 12 bytes.
The task startup code of the initial startup task is 0. 8. Extended information [( Definition format )] [( Definition range )] [( Default value )] Define the extended information of a task. This information is passed to the task as argument when it is restarted by a queued startup request, for example.
3. Initial value of the event flag [( Definition format )] [( Definition range )] [( Default value )] Specify the initial bit pattern of the event flag. 4. Multi-wait attribute [( Definition format )] [( Definition range )] [( Default value )] Specify whether multiple tasks can be enqueued in the eventflag waiting queue.
2. Selecting a semaphore waiting queue [( Definition format )] [( Definition range )] [( Default value )] Select a method in which tasks wait for the semaphore. If TA_TFIFO is selected, tasks are enqueued in order of FIFO. If TA_TPRI is selected, tasks are enqueued in order of priority beginning with the one that has the highest priority.
2. Number of data [( Definition format )] [( Definition range )] [( Default value )] Specify the number of data that can be transmitted. What should be specified here is the number of data, and not a data size. 3.
3. Selecting a data queue waiting queue [( Definition format )] [( Definition range )] [( Default value )] Select a method in which tasks wait for short data queue transmission. If TA_TFIFO is selected, tasks are enqueued in order of FIFO. If TA_TPRI is selected, tasks are enqueued in order of priority begin- ning with the one that has the highest priority.
4. Maximum message priority [( Definition format )] [( Definition range )] [( Default value )] Specify the maximum priority of message in the mailbox. [( Fixed-size memory pool definition )] This definition must always be set when the fixed-size memory pool function is to be used. <<...
4. Size (in bytes) [( Definition format )] [( Definition range )] [( Default value )] Define the size of the memory pool per block. The RAM size to be used as a memory pool is deter- mined by this definition: (number of blocks) x (size) in bytes. 5.
3. Section name [( Definition format )] [( Definition range )] [( Default value )] Define the name of the section in which the memory pool is located. The section defined here must always have an area allocated for it in the section file (asm_sec.inc or c_sec.inc). If no section names are defined, the memory pool is located in the MR_HEAP section.
Page 124
<< Content >> Define the following for each cyclic handler ID number. 1. ID name [( Definition format )] [( Definition range )] [( Default value )] Define the name by which the memory pool is specified in a program. 2.
7. Extended information [( Definition format )] [( Definition range )] [( Default value )] Define the extended information of the cyclic handler. This information is passed as argument to the cyclic handler when it starts. [( Alarm handler definition )] This definition is necessary to use Alarm handler function.
[( Interrupt vector definition )] This definition is necessary to use Interrupt function. << Format >> // Interrupt Vector Definition Vector No. interrupt_vector[ os_int entry_address pragma_switch The vector number can be written in the range of 0 to 63 and 247 to 255. However, whether or not the defined vector number is valid depends on the microcomputer used The relationship between interrupt causes and interrupt vector numbers for the M16C/80 series is shown in Table 6.3.
Page 127
specified at the same time. [Precautions] 1. Regarding the method for specifying a register bank A kernel (OS dependent) interrupt handler that uses register bank 1 cannot be written in C language. Such an interrupt handler can only be written in assembly language. When writing in assembly language, make sure the statements at the entry and exit of the interrupt handler are written as shown below.
6.1.3 Configuration File Example The following is the configuration file example. 1 //////////////////////////////////////////////////////////////////////////////// 2 // 3 // kernel.cfg : building file for MR308 Ver.4.00 4 // 5 // Generated by M3T-MR308 GUI Configurator at 2005/02/28 19:01:20 6 // 7 //////////////////////////////////////////////////////////////////////////////// 9 // system definition 10 system{ stack_size...
6.2 Configurator Execution Procedures 6.2.1 Configurator Overview The configurator is a tool that converts the contents defined in the configuration file into the assembly language include file, etc.Figure 6.1 outlines the operation of the configurator. When used on HEW, the configurator is automatically started, and an application program is built. 1.
Configuration File xxx.cfg Default Configuration File default.cfg makefile Template File makefile.dos makefile,Makefile Template File sys_ram.inc, mr308.inc MR308 Version File version Figure 6.1 The operation of the Configurator System Data Difinition File sys_ram.inc, sys_rom.inc cfg308 System generation File makefile Include File mr308.inc,kernel_id.h - 124 -...
6.2.2 Setting Configurator Environment Before executing the configurator, check to see if the environment variable "LIB308" is set correctly. The configurator cannot be executed normally unless the following files are present in the directory indicated by the environment variable "LIB308": •...
6.2.3 Configurator Start Procedure Start the configurator as indicated below. A> cfg308 [-vmV] Configuration file name Normally, use the extension .cfg for the configuration file name. Command Options -v Option Displays the command option descriptions and detailed information on the version. -V Option Displays the information on the files generated by the command.
6.2.4 makefile generate Function The configurator follows the procedure below to generate makefile. 1. Examine the source file's dependency relationship. Assuming that the files bearing extensions .c and .a30 in the current directory respectively to be the C language and the assembly language files, the configurator examines the dependency relationship of the files to be included by those.
6.2.5 Precautions on Executing Configurator The following lists the precautions to be observed when executing the configurator: • If you have re-run the configurator, always be sure to execute make clean or delete all object files (ex- tension .r30) and execute the make command. In this case, an error may occur during linking. •...
6.2.6 Configurator Error Indications and Remedies If any of the following messages is displayed, the configurator is not normally functioning. Therefore, correct the configuration file as appropriate and the execute the configurator again. Error messages cfg308 Error : syntax error near line xxx (xxxx.cfg) There is an syntax error in the configuration file.
Page 140
service call of system definition item. cfg308 Error : system timer's vector <x>conflict near line xxx A different vector is defined for the system clock timer interrupt vector. Confirm the vector No.x for in- terrupt vector definition. cfg308 Error : XXXX is not defined (xxxx.cfg) "XXXX"...
Warning messages The following message are a warning. A warning can be ignored providing that its content is understood. cfg308 Warning : system is not defined (xxxx.cfg) cfg308 Warning : system.XXXX is not defined (xxxx.cfg) System definition or system definition item XXXX is omitted in the configuration file. cfg308 Warning : system.message_size is not defined (xxxx.cfg) The message size definition is omitted in the system definition.
6.3 Editing makefile Here you edit makefile the configurator generated, and set compilation options, libraries, and so on. The proce- dure for setting them is given below. 1. NC308WA command options You define command options of the C compiler in "CFLAGS". Be sure to define the "-c" option. 2.
Chapter 6 Using Configurator 6.4 About an error when you execute make The following warning message of mr308tbl is displayed when you execute make. mr308tbl Warning : You need not specify systime.timeout YES in configuration file Unless the following service calls are used, there is no need to set "Timeout=YES" in the system defi- nition of a configuration file.
7.1 Processing Procedures for System Calls from Handlers When a service call is issued from a handler, task switching does not occur unlike in the case of a service call from a task. However, task switching occurs when a return from a handler The processing procedures for service calls from handlers are roughly classified into the following three types.
Chapter 7 Application Creation Guide 7.1.1 System Calls from a Handler That Caused an Interrupt during Task Execution (See Figure 7.1). Scheduling (task switching) is initiated by the ret_int service call TaskA Interrupt handler Interrupt Save Registers system call processing iset_flg Restore Registers ret_int...
Chapter 7 Application Creation Guide 7.1.2 System Calls from a Handler That Caused an Interrupt during System Call Processing Scheduling (task switching) is initiated after the system returns to the interrupted service call processing (See Figure 7.2). TaskA Interrupt handler wup_tsk Save Registers SP <= System...
Chapter 7 Application Creation Guide 7.1.3 System Calls from a Handler That Caused an Interrupt during Handler Execution Let us think of a situation in which an interrupt occurs during handler execution (this handler is hereinafter re- ferred to as handler A for explanation purposes). When task switching is called for as a handler (hereinafter re- ferred to as handler B) that caused an interrupt during handler A execution issued a service call, task switching does not take place during the execution of the service call (ret_int service call) returned from handler B, but is effected by the ret_int service call from handler A (See Figure 7.3).
7.2 Stacks 7.2.1 System Stack and User Stack The MR308 provides two types of stacks: system stack and user stack. • User Stack One user stack is provided for each task. Therefore, when writing applications with the MR308, it is necessary to furnish the stack area for each task.
8.1 Overview of Sample Program As an example application of MR308, the following shows a program that outputs a string to the standard output device from one task and another alternately. Table 8.1 Function Type Name main() Task task1() Task task2() Task cyh1()
9.1 How to Form Separate ROMs This chapter describes how to form the MR308's kernel and application programs into separate ROMs. Figure 9.1 shows an instance in which the sections common to two different applications together with the ker- nel are allocated in the kernel ROM and the applications are allocated in separate ROMs. Here is how to divide a ROM based on this example.
kernel ROM (Internal ROM) Startup MR_KERNEL Program MR308 kernel Task of ID=1 program Fix Interrupt Vector area Application ROM2 MR308’s ROM MR_ROM MR_CIF C language I/F routine App_prog Interrupt vector area • Programs to be located in the application ROM ♦...
Here you change the section files (c_sec.inc, asm_sec.inc), and set addresses of programs you locate in the application ROM. In this instance, the respective first addresses of the sections given below must agree with each other between two applications. Also, you need to invariably locate the MR_ROM section at the beginning of the application ROM.
Page 159
e.g. mr308tbl \product\app1 \product\app2 8. Generating a system You execute the make command to generate a system. 9. Carrying out steps 4 through 8 with respect to application 2 allows you to generate the system for application 2. The steps given above allows you to form the separate ROMs. If the file mrtable.a30 is not held in the current directory, execute make command to generate a system.