Renesas 70 User Manual

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
Active X, Microsoft, MS-DOS, Visual Basic, Visual C++, Windows and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and other countries. IBM and AT are registered trademarks of International Business Machines Corporation. Intel and Pentium are registered trademarks of Intel Corporation. Adobe, Acrobat, and Acrobat Reader are trademarks of Adobe Systems Incorporated. TRON is an abbreviation of "The Real-time Operating system Nucleus." ITRON is an abbreviation of "Industrial TRON." µITRON is an abbreviation of "Micro Industrial TRON." TRON, ITRON, and µITRON do not refer to any specific product or products. All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
Keep safety first in your circuit designs!
z Renesas Technology Corporation and Renesas Solutions Corporation put the maximum effort into making semiconductor products
better and more reliable, but there is always the possibility that trouble may occur with them. Trouble with semiconductors may lead to personal injury, fire or property damage. Remember to give due consideration to safety when making your circuit designs, with appro­priate measures such as (i) placement of substitutive, auxiliary circuits, (ii) use of nonflammable material or (iii) prevention against any malfunction or mishap.
Notes regarding these materials
z 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.
z Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage, or infringement of
any third-party's rights, originating in the use of any product data, diagrams, charts, programs, algorithms, or circuit application exam­ples contained in these materials.
z All information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information
on products at the time of publication of these materials, and are subject to change by Renesas Technology Corporation and Rene­sas Solutions Corporation without notice due to product improvements or other reasons. It is therefore recommended that customers contact Renesas Technology Corporation, Renesas Solutions Corporation or an authorized Renesas Technology product distributor for the latest product information before purchasing a product listed herein. The information described here may contain technical in­accuracies or typographical errors. Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage, liability, or other loss rising from these inaccuracies or errors. Please also pay attention to information published by Renesas Technology Corporation and Renesas Solutions Corporation by various means, including the Renesas home page (http://www.renesas.com).
z When using any or all of the information contained in these materials, including product data, diagrams, charts, programs, and algo-
rithms, please be sure to evaluate all information as a total system before making a final decision on the applicability of the informa­tion and products. Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage, liability or other loss resulting from the information contained herein.
z Renesas Technology semiconductors are not designed or manufactured for use in a device or system that is used under circum-
stances in which human life is potentially at stake. Please contact Renesas Technology Corporation, Renesas Solutions Corporation or an authorized Renesas Technology product distributor when considering the use of a product contained herein for any specific purposes, such as apparatus or systems for transportation, vehicular, medical, aerospace, nuclear, or undersea repeater use.
z The prior written approval of Renesas Technology Corporation and Renesas Solutions Corporation is necessary to reprint or repro-
duce in whole or in part these materials.
z If these products or technologies are subject to the Japanese export control restrictions, they must be exported under a licen
se from the Japanese government and cannot be imported into a country other than the approved destination. Any diversion or reexport con­trary to the export control laws and regulations of Japan and/or the country of destination is prohibited.
z Please contact Renesas Technology Corporation or Renesas Solutions Corporation for further details on these materials or the prod-
ucts contained therein.
For inquiries about the contents of this document or product, fill in the text file the installer generates in the following directory and email to your local distributor.
\SUPPORT\Product-name\SUPPORT.TXT
Renesas Tools Homepage http://www.renesas.com/en/tools
Preface
The M3T-MR308/4(abbreviated as MR308) is a real-time operating system1 for the M16C/70,80, M32C/80 se­ries microcomputers. The MR308 conforms to the µITRON Specification. This manual describes the procedures and precautions to observe when you use the MR308 for programming purposes. 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-
computers
Document List
The following sets of documents are supplied with the MR308.
Release Note
Presents a software overview and describes the corrections to the Users Manual and Reference Manual.
2
Users Manual (PDF file)
Describes the procedures and precautions to observe when using the MR308 for programming pur­poses.
Reference Manual (PDF file)
Describes the MR308 service call procedures and typical usage examples.
Please read the release note before reading this manual.
Right of Software Use
The right of software use conforms to the software license agreement. You can use the MR308 for your product development purposes only, and are not allowed to use it for the other purposes. You should also note that this manual does not guarantee or permit the exercise of the right of software use.
1
Hereinafter abbreviated "real-time OS"
2
µITRON4.0 Specification is the open real-time kernel specification upon which the TRON association decided
The specification document of µITRON4.0 specification can come to hand from a TRON association homepage
(http://www.assoc.tron.org/).
The copyright of µITRON4.0 specification belongs to the TRON association.
Contents
Chapter 1 User’s Manual Organization ....................................................................................................- 1 -
Chapter 2 General Information ................................................................................................................. - 3 -
2.1 Objective of MR308 Development...................................................................................................... - 4 -
2.2 Relationship between TRON Specification and MR308................................................................... - 6 -
2.3 MR308 Features .................................................................................................................................- 7 -
Chapter 3 Introduction to MR308..............................................................................................................- 9 -
3.1 Concept of Real-time OS ..................................................................................................................- 10 -
3.1.1 Why Real-time OS is Necessary ............................................................................................... - 10 -
3.1.2 Operating Principles of Real-time OS...................................................................................... - 13 -
3.2 Service Call ....................................................................................................................................... - 16 -
3.2.1 Service Call Processing ............................................................................................................. - 17 -
3.2.2 Task Designation in Service call ..............................................................................................- 18 -
3.3 Task ................................................................................................................................................... - 19 -
3.3.1 Task Status................................................................................................................................ - 19 -
3.3.2 Task Priority and Ready Queue ............................................................................................... - 23 -
3.3.3 Task Priority and Waiting Queue............................................................................................. - 24 -
3.3.4 Task Control Block(TCB) .......................................................................................................... - 25 -
3.4 System States.................................................................................................................................... - 27 -
3.4.1 Task Context and Non-task Context........................................................................................ - 27 -
3.4.2 Dispatch Enabled/Disabled States ........................................................................................... - 28 -
3.4.3 CPU Locked/Unlocked States ................................................................................................... - 29 -
3.4.4 Dispatch Disabled and CPU Locked States............................................................................. - 29 -
3.5 MR308 Kernel Structure.................................................................................................................. - 30 -
3.5.1 Module Structure....................................................................................................................... - 30 -
3.5.2 Module Overview....................................................................................................................... - 31 -
3.5.3 Task Management Function..................................................................................................... - 32 -
3.5.4 Synchronization functions attached to task ............................................................................- 34 -
3.5.5 Synchronization and Communication Function (Semaphore)................................................ - 37 -
3.5.6 Synchronization and Communication Function (Eventflag) .................................................. - 39 -
3.5.7 Synchronization and Communication Function (Data Queue) .............................................. - 41 -
3.5.8 Synchronization and Communication Function (Mailbox) ..................................................... - 42 -
3.5.9 Memory pool Management Function ....................................................................................... - 44 -
Fixed-size Memory pool Management Function ................................................................................................. - 44 -
Variable-size Memory Pool Management Function............................................................................................. - 45 -
3.5.10 Time Management Function..................................................................................................... - 47 -
3.5.11 Cyclic Handler Function ........................................................................................................... - 49 -
3.5.12 Alarm Handler Function........................................................................................................... - 50 -
3.5.13 System Status Management Function..................................................................................... - 51 -
3.5.14 Interrupt Management Function .............................................................................................- 52 -
3.5.15 System Configuration Management Function ........................................................................ - 53 -
3.5.16 Extended Function (Short Data Queue) .................................................................................. - 53 -
3.5.17 Extended Function (Reset Function) ....................................................................................... - 54 -
3.5.18 Service calls That Can Be Issued from Task and Handler..................................................... - 55 -
Chapter 4 Applications Development Procedure Overview.................................................................... - 59 -
4.1 Overview............................................................................................................................................ - 60 -
i
4.2 Development Procedure Example.................................................................................................... - 62 -
4.2.1 Applications Program Coding................................................................................................... - 62 -
4.2.2 Configuration File Preparation ................................................................................................ - 64 -
4.2.3 Configurator Execution............................................................................................................. - 65 -
4.2.4 System generation..................................................................................................................... - 65 -
4.2.5 Writing ROM..............................................................................................................................- 65 -
Chapter 5 Detailed Applications.............................................................................................................. - 67 -
5.1 Program Coding Procedure in C Language..................................................................................... - 68 -
5.1.1 Task Description Procedure...................................................................................................... - 68 -
5.1.2 Writing a Kernel (OS Dependent) Interrupt Handler ............................................................ - 70 -
5.1.3 Writing Non-kernel (OS-independent ) Interrupt Handler .................................................... - 71 -
5.1.4 Writing Cyclic Handler/Alarm Handler................................................................................... - 72 -
5.2 Program Coding Procedure in Assembly Language ....................................................................... - 73 -
5.2.1 Writing Task .............................................................................................................................. - 73 -
5.2.2 Writing Kernel(OS-dependent) Interrupt Handler................................................................. - 75 -
5.2.3 Writing Non-kernel(OS-independent) Interrupt Handler ...................................................... - 76 -
5.2.4 Writing Cyclic Handler/Alarm Handler................................................................................... - 77 -
5.3 The Use of INT Instruction.............................................................................................................. - 78 -
5.4 The Use of registers of bank ............................................................................................................ - 78 -
5.5 Regarding Interrupts........................................................................................................................ - 79 -
5.5.1 Types of Interrupt Handlers..................................................................................................... - 79 -
5.5.2 The Use of Non-maskable Interrupt ........................................................................................- 79 -
5.5.3 Controlling Interrupts............................................................................................................... - 80 -
5.6 Regarding Delay Dispatching .......................................................................................................... - 82 -
5.7 Regarding Initially Activated Task..................................................................................................- 83 -
5.8 Modifying MR308 Startup Program................................................................................................ - 84 -
5.8.1 C Language Startup Program (crt0mr.a30)............................................................................. - 85 -
5.9 Memory Allocation............................................................................................................................ - 90 -
5.9.1 Section Allocation of start.a30 .................................................................................................. - 91 -
5.9.2 Section Allocation of crt0mr.a30............................................................................................... - 92 -
5.10 Using in M16C/70 Series.................................................................................................................. - 94 -
Chapter 6 Using Configurator ................................................................................................................. - 95 -
6.1 Configuration File Creation Procedure ........................................................................................... - 96 -
6.1.1 Configuration File Data Entry Format.................................................................................... - 96 -
Operator ................................................................................................................................................................ - 97 -
Direction of computation ...................................................................................................................................... - 97 -
6.1.2 Configuration File Definition Items......................................................................................... - 99 -
[( System Definition Procedure )]......................................................................................................................... - 99 -
[( System Clock Definition Procedure )]............................................................................................................. - 101 -
[( Definition respective maximum numbers of items )]..................................................................................... - 102 -
[( Task definition )].............................................................................................................................................. - 104 -
[( Eventflag definition )] ..................................................................................................................................... - 106 -
[( Semaphore definition )]................................................................................................................................... - 107 -
[(Data queue definition )] ................................................................................................................................... - 108 -
[( Short data queue definition )]......................................................................................................................... - 109 -
[( Mailbox definition )] .........................................................................................................................................- 110 -
[( Fixed-size memory pool definition )]................................................................................................................- 111 -
[( Variable-size memory pool definition )] ...........................................................................................................- 112 -
[( Cyclic handler definition )]...............................................................................................................................- 113 -
[( Alarm handler definition )] ..............................................................................................................................- 115 -
[( Interrupt vector definition )]............................................................................................................................- 116 -
6.1.3 Configuration File Example.................................................................................................... - 119 -
6.2 Configurator Execution Procedures .............................................................................................. - 123 -
6.2.1 Configurator Overview............................................................................................................ - 123 -
6.2.2 Setting Configurator Environment ........................................................................................ - 125 -
6.2.3 Configurator Start Procedure................................................................................................. - 126 -
6.2.4 makefile generate Function .................................................................................................... - 127 -
6.2.5 Precautions on Executing Configurator................................................................................. - 128 -
6.2.6 Configurator Error Indications and Remedies ...................................................................... - 129 -
Error messages ................................................................................................................................................... - 129 -
ii
Warning messages .............................................................................................................................................. - 131 -
Other messages................................................................................................................................................... - 131 -
6.3 Editing makefile .............................................................................................................................- 132 -
6.4 About an error when you execute make ........................................................................................ - 133 -
Chapter 7 Application Creation Guide .................................................................................................. - 135 -
7.1 Processing Procedures for System Calls from Handlers.............................................................. - 136 -
7.1.1 System Calls from a Handler That Caused an Interrupt during Task Execution .............. - 137 -
7.1.2 System Calls from a Handler That Caused an Interrupt during System Call Processing.- 138 -
7.1.3 System Calls from a Handler That Caused an Interrupt during Handler Execution........ - 139 -
7.2 Stacks .............................................................................................................................................. - 140 -
7.2.1 System Stack and User Stack................................................................................................. - 140 -
Chapter 8 Sample Program Description................................................................................................ - 141 -
8.1 Overview of Sample Program ........................................................................................................- 142 -
8.2 Program Source Listing.................................................................................................................. - 143 -
8.3 Configuration File........................................................................................................................... - 144 -
Chapter 9 Separate ROMs ..................................................................................................................... - 145 -
9.1 How to Form Separate ROMs........................................................................................................ - 146 -
iii
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 -
Figure 3.8 Actual Register and Stack Area Management .............................................................- 15 -
Figure 3.9 Service call......................................................................................................................- 16 -
Figure 3.10 Service Call Processing Flowchart..............................................................................- 17 -
Figure 3.11 Task Identification .......................................................................................................- 18 -
Figure 3.12 Task Status...................................................................................................................- 19 -
Figure 3.13 MR308 Task Status Transition...................................................................................- 20 -
Figure 3.14 Ready Queue (Execution Queue) ................................................................................- 23 -
Figure 3.15 Waiting queue of the TA_TPRI attribute ...................................................................- 24 -
Figure 3.16 Waiting queue of the TA_TFIFO attribute.................................................................- 24 -
Figure 3.17 Task control block ........................................................................................................- 26 -
Figure 3.18 Cyclic Handler/Alarm Handler Activation .................................................................- 28 -
Figure 3.19 MR308 Structure..........................................................................................................- 30 -
Figure 3.20 Task Resetting..............................................................................................................- 32 -
Figure 3.21 Alteration of task priority............................................................................................- 33 -
Figure 3.22 Task rearrangement in a waiting queue ....................................................................- 33 -
Figure 3.23 Wakeup Request Storage.............................................................................................- 34 -
Figure 3.24 Wakeup Request Cancellation.....................................................................................- 34 -
Figure 3.25 Forcible wait of a task and resume.............................................................................- 35 -
Figure 3.26 Forcible wait of a task and forcible resume................................................................- 35 -
Figure 3.27 dly_tsk service call .......................................................................................................- 36 -
Figure 3.28 Exclusive Control by Semaphore ................................................................................- 37 -
Figure 3.29 Semaphore Counter .....................................................................................................- 37 -
Figure 3.30 Task Execution Control by Semaphore.......................................................................- 38 -
Figure 3.31 Task Execution Control by the Eventflag...................................................................- 40 -
Figure 3.32 Data queue ...................................................................................................................- 41 -
Figure 3.33 Mailbox .........................................................................................................................- 42 -
Figure 3.34 Message queue .............................................................................................................- 43 -
Figure 3.35 Memory Pool Management..........................................................................................- 44 -
Figure 3.36 pget_mpl processing.....................................................................................................- 46 -
Figure 3.37 rel_mpl processing .......................................................................................................- 46 -
Figure 3.38 Timeout Processing......................................................................................................- 47 -
Figure 3.39 Cyclic handler operation in cases where the activation phase is saved ...................- 49 -
Figure 3.40 Cyclic handler operation in cases where the activation phase is not saved.............- 49 -
Figure 3.41 Typical operation of the alarm handler ......................................................................- 50 -
Figure 3.42 Ready Queue Management by rot_rdq System Call..................................................- 51 -
Figure 3.43 Interrupt process flow..................................................................................................- 52 -
Figure 4.1 MR308 System Generation Detail Flowchart ..............................................................- 61 -
Figure 4.2 Program Example ..........................................................................................................- 63 -
Figure 4.3 Configuration File Example ..........................................................................................- 64 -
Figure 4.4 Configurator Execution .................................................................................................- 65 -
Figure 4.5 System Generation.........................................................................................................- 65 -
Figure 5.1 Example Infinite Loop Task Described in C Language...............................................- 68 -
iv
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 -
Figure 5.7 Example Task Terminating with ext_tsk Described in Assembly Language.............- 73 -
Figure 5.8 Example of kernel(OS-depend) interrupt handler.......................................................- 75 -
Figure 5.9 Example of Non-kernel(OS-independent) Interrupt Handler of Specific Level.........- 76 -
Figure 5.10 Example Handler Written in Assembly Language ....................................................- 77 -
Figure 5.11 Interrupt handler IPLs................................................................................................- 79 -
Figure 5.12 Interrupt control in a System Call that can be Issued from only a Task.................- 80 -
Figure 5.13 Interrupt control in a System Call that can be Issued from a Task-independent ...- 81 -
Figure 5.14 C Language Startup Program (crt0mr.a30) ...............................................................- 88 -
Figure 5.15 Selection Allocation in C Language Startup Program...............................................- 93 -
Figure 6.1 The operation of the Configurator ..............................................................................- 124 -
Figure 7.1 Processing Procedure for a System Call a Handler that caused an interrupt during Task
Execution - 137 -
Figure 7.2 Processing Procedure for a System Call from a Handler that caused an interrupt during System
Call Processing........................................................................................................................- 138 -
Figure 7.3 Processing Procedure for a service call from a Multiplex interrupt Handler..........- 139 -
Figure 7.4 System Stack and User Stack .....................................................................................- 140 -
Figure 9.1 ROM separate ..............................................................................................................- 147 -
Figure 9.2 Memory map.................................................................................................................- 148 -
v
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 C Language Variable Treatment..........................................................................- 69 -
Table 5.2 Interrupt Number Assignment............................................................................- 78 -
Table 6.1 Numerical Value Entry Examples.......................................................................- 96 -
Table 6.2 Operators...............................................................................................................- 97 -
Table 6.3 Interrupt Causes and Vector Numbers ...............................................................- 118 -
Table 8.1 Functions in the Sample Program.....................................................................- 142 -
vi

Chapter 1 User’s Manual Organization

Chapter 1 User’s Manual Organization
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.
Chapter 4 Applications Development Procedure Overview
Outlines the applications program development procedure for the MR308.
Chapter 5 Detailed Applications
Details the applications program development procedure for the MR308.
Chapter 6 Using Configurator
Describes the method for writing a configuration file and the method for using the configurator in detail.
Chapter 7 Application Creation Guide
Presents useful information and precautions concerning applications program development with MR308.
Chapter 8 Sample Program Description
Describes the MR308 sample applications program which is included in the product in the form of a source file.
Chapter 9 Separate ROMs
Explains about how to Form Separate ROMs.
- 2 -

Chapter 2 General Information

Chapter 2 General Information
2.1 Objective of MR308 Development
In line with recent rapid technological advances in microcomputers, the functions of microcomputer-based products have become complicated. In addition, the microcomputer program size has increased. Further, as product development competition has been intensified, manufacturers are compelled to develop their micro­computer-based products within a short period of time.
In other words, engineers engaged in microcomputer software development are now required to develop lar­ger-size programs within a shorter period of time. To meet such stringent requirements, it is necessary to take the following considerations into account.
1. To enhance software recyclability to decrease the volume of software to be developed.
One way to provide for software recyclability is to divide software into a number of functional modules wherever possible. This may be accomplished by accumulating a number of general-purpose subrou­tines and other program segments and using them for program development. In this method, however, it is difficult to reuse programs that are dependent on time or timing. In reality, the greater part of ap­plication programs are dependent on time or timing. Therefore, the above recycling method is applica­ble to only a limited number of programs.
2. To promote team programming so that a number of engineers are engaged in the development of one software package
There are various problems with team programming. One major problem is that debugging can be ini­tiated only when all the software program segments created individually by team members are ready for debugging. It is essential that communication be properly maintained among the team members.
3. To enhance software production efficiency so as to increase the volume of possible software development per engineer.
One way to achieve this target would be to educate engineers to raise their level of skill. Another way would be to make use of a structured descriptive assembler, C-compiler, or the like with a view toward facilitating programming. It is also possible to enhance debugging efficiency by promoting modular software development.
However, the conventional methods are not adequate for the purpose of solving the problems. Under these cir­cumstances, it is necessary to introduce a new system named real-time OS
3
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.
4. Software recycling is facilitated.
When the real-time OS is introduced, timing signals are furnished via the real-time OS so that pro­grams dependent on timing can be reused. Further, as programs are divided into modules called tasks, structured programming will be spontaneously provided.
That is, recyclable programs are automatically prepared.
5. Ease of team programming is provided.
When the real-time OS is put to use, programs are divided into functional modules called tasks. Therefore, engineers can be allocated to individual tasks so that all steps from development to debug­ging can be conducted independently for each task.
Further, the introduction of the real-time OS makes it easy to start debugging some already finished tasks even if the entire program is not completed yet. Since engineers can be allocated to individual tasks, work assignment is easy.
6. Software independence is enhanced to provide ease of program debugging.
As the use of the real-time OS makes it possible to divide programs into small independent modules called tasks, the greater part of program debugging can be initiated simply by observing the small modules.
3
OS:Operating System
- 4 -
Chapter 2 General Information
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.
When the real-time OS is introduced, however, it is possible to create programs for performing proc­essing at fixed time intervals making use of the real-time OS time management function without paying special attention to the microcomputer timer function. At the same time, programming can also be done in such a manner as to let the programmer take that numerous timers are provided for the mi­crocomputer.
8. Software maintainability is enhanced
When the real-time OS is put to use, the developed software consists of small program modules called tasks. Therefore, increased software maintainability is provided because developed software mainte­nance can be carried out simply by maintaining small tasks.
9. Increased software reliability is assured.
The introduction of the real-time OS makes it possible to carry out program evaluation and testing in the unit of a small module called task. This feature facilitates evaluation and testing and increases software reliability.
10. The microcomputer performance can be optimized to improve the performance of microcom­puter-based products.
With the real-time OS, it is possible to decrease the number of unnecessary microcomputer operations such as I/O waiting. It means that the optimum capabilities can be obtained from microcomputers, and this will lead to microcomputer-based product performance improvement.
- 5 -
Chapter 2 General Information
2.2 Relationship between TRON Specification and MR308
The TRON Specification is an abbreviation for The Real-time Operating system Nucleus specification. It denotes the specifications for the nucleus of a real-time operating system. The TRON Project, which is centered on TRON Specification design, is pushed forward under the leadership of Dr. Ken Sakamura at University of Tokyo.
As one item of this TRON Project, the ITRON Specification is promoted. The ITRON Specification is an abbre­viation for the Industrial TRON Specification. It denotes the real-time operating system that is designed with a view toward establishing industrial real-time operating systems.
The ITRON Specification provides a number of functions to properly meet the application requirements. In other words, ITRON systems require relatively large memory capacities and enhanced processing capabilities. The µITRON 2.0 Specification is the arranged version of the ITRON Specification for the higher processing speed, and incorporated only a minimum of functions necessary.
In 1993, µITRON 2.0 Specification and ITRON Specification were unified, which resulted in establishment of µITRON 3.0 Specification, with connecting functions added.
Furthermore, in 1999, µITRON 4.0 Specification
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. Of these standard profiles, MR308 has implemented in it all service calls except for static APIs and task exception APIs.
4
with enhanced compatibility was established.
4
µITRON 4.0 Specification is an open, real-time kernel specification set forth by the TRON Association. The documented specification of µITRON 4.0 Specification can be obtained from the Web site of the TRON Association (http://www.assoc.tron.org/).
- 6 -
Chapter 2 General Information
2.3 MR308 Features
The MR308 offers the following features.
1. Real-time operating system conforming to the µITORN Specification.
The MR308 is designed in compliance with the µITRON Specification which incorporates a minimum of the ITRON Specification functions so that such functions can be incorporated into a one-chip mi­crocomputer. As the µITRON Specification is a subset of the ITRON Specification, most of the knowl­edge obtained from published ITRON textbooks and ITRON seminars can be used as is.
Further, the application programs developed using the real-time operating systems conforming to the ITRON Specification can be transferred to the MR308 with comparative ease.
2. High-speed processing is achieved.
MR308 enables high-speed processing by taking full advantage of the microcomputer architecture.
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.
Thanks to this feature, a system of the minimum size is automatically generated at all times.
4. With the C-compiler NC308WA, it is possible to develop application programs in C language.
Application programs of MR308 can be developed in C language by using the C compiler NC308WA. Furthermore, the interface library necessary to call the MR308 functions from C language is included with the software package.
5. An upstream process tool named "Configurator" is provided to simplify development proce­dures
A configurator is furnished so that various items including a ROM write form file can be created by giv­ing simple definitions.
Therefore, there is no particular need to care what libraries must be linked.
In addition, a GUI version of the configurator is available beginning with M3T-MR308 V.4.00. It helps the user to create a configuration file without the need to learn how to write it.
- 7 -

Chapter 3 Introduction to MR308

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. Fig.3.1 shows the relationship between the program size and required develop­ment time (program development difficulty).
This figure is nothing more than a schematic diagram. However, it indicates that the development period in­creases exponentially with an increase in program size.
For example, the development of four 8K byte programs is easier than the development of one 32K byte pro-
5
gram.
Development Period
4
8
16
Program Size
32
Kbyte
Figure 3.1 Relationship between Program Size and Development Period
Under these circumstances, it is necessary to adopt a method by which large-size programs can be developed within a short period of time. One way to achieve this purpose is to use a large number of microcomputers hav­ing a small ROM capacity. Figure 3.2 presents an example in which a number of microcomputers are used to build up an audio equipment system.
5
On condition that the ROM program burning step need not be performed.
- 10 -
p
Chapter 3 Introduction to MR308
Key input
microcomputer
Volume control microcomputer
Remote control microcomputer
Arbiter
microcomputer
Monitor
microcomputer
LED illumination
microcomputer
Mechanical
control
microcom
uter
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.
6
3. Completely independent programs are provided for various functions so that program devel­opment can easily be conducted by a number of engineers.
On the other hand, there are the following disadvantages.
1. The number of parts used increases, thereby raising the product cost.
2. Hardware design is complicated.
3. Product physical size is enlarged.
Therefore, if you employ the real-time OS in which a number of programs to be operated by a number of micro­computers are placed under software control of one microcomputer, making it appear that the programs run on separate microcomputers, you can obviate all the above disadvantages while retaining the above-mentioned advantages.
Figure 3.3 shows an example system that will be obtained if the real-time OS is incorporated in the system indi­cated in Figure 3.2.
6
In the case presented in エラー! 参照元が見つかりません。 for instance, the remote control microcomputer can be used for other prod-
ucts without being modified.
- 11 -
Chapter 3 Introduction to MR308
Key input
Tas k
Remote control
Task
LED illumination
Task
real-time
OS
Volume control
Task
Monitor
Tas k
Mechanical
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.
- 12 -
Chapter 3 Introduction to MR308
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. That is, it changes the task to execute at fixed time intervals so that a number of tasks appear to be executed simultane­ously.
Key input
Task
Remote control
Task
LED
illumination
Task
Volume control
Task
Monitor
Task
Mechanical
control
Task
Time
Figure 3.4 Time-division Task Operation
As indicated above, the real-time OS changes the task to execute at fixed time intervals. This task switching may also be referred to as dispatching (technical term specific to real-time operating systems). The factors causing task switching (dispatching) are as follows.
Task switching occurs upon request from a task.
Task switching occurs due to an external factor such as interrupt.
When a certain task is to be executed again upon task switching, the system resumes its execution at the point of last interruption (See Figure 3.5).
Program execution
interrupt
Program execution
resumed
Key input
Task
Remote control
Task
During this interval, it appears that the key input microcomputer is haled.
Figure 3.5 Task Execution Interruption and Resumption
- 13 -
Chapter 3 Introduction to MR308
A
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. In other words, task switching refers to the action performed to save the currently executed task register contents into the associated task management memory area and recover the register contents for the task to switch to.
To establish the real-time OS, therefore, it is only necessary to manage the register for each task and change the register contents upon each task switching so that it looks as if a number of microcomputers exist (See Figure 3.6).
R0
R1
PC
Real-time OS
ctual
Register
Key input
Tas k
R0
R1
PC
Remote control
Tas k
R0
R1
PC
RegisterRegister
Figure 3.6 Task Switching
The example presented in Figure 3.7
7
indicates how the individual task registers are managed. In reality, it is
necessary to provide not only a register but also a stack area for each task.
7
It is figure where all the stack areas of the task were arranged in the same section.
- 14 -
A
A
Remote control
Task
Key input
Tas k
LED illumination
Task
Chapter 3 Introduction to MR308
Memory map
Register
R0
PC
SP
R0
PC
SP
R0
PC
SP
Stack section
Real-time
OS
SP
SFR
Figure 3.7 Task Register Area
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.
Key input
Task
SP
Register not stored
SP
PC
FLG
FB
SB
1
0
R3
R2
R1
R0
Key input task stack
Register stored
SFR
Figure 3.8 Actual Register and Stack Area Management
- 15 -
Chapter 3 Introduction to MR308
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).
Key input
Task

Service call Task switching

Real-time OS
Figure 3.9 Service call
This service call is realized by a function call when the application program is written in C language, as shown below.
sta_tsk(ID_main,3);
Remote control
task
Furthermore, if the application program is written in assembly language, it is realized by an assembler macro call, as shown below.
sta_tsk #ID_main,#3
- 16 -
Chapter 3 Introduction to MR308

3.2.1 Service Call Processing

When a service call is issued, processing takes place in the following sequence.8
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. Processing is performed in compliance with the request made by the service call.
4. The task to be executed next is selected.
5. The stack pointer is changed to the task type.
6. The register contents are recovered to resume task execution.
The flowchart in Figure 3.10 shows the process between service call generation and task switching.
Key input Task
Service call issuance
Figure 3.10 Service Call Processing Flowchart
Register Save
<= OS
SP
Processing
Task S elect ion
Task => S P
Register Restore
LED illumination Task
8
A different sequence is followed if the issued service call does not evoke task switching.
- 17 -
Chapter 3 Introduction to MR308

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. 2 task is.
sta_tsk(2,1);
Further, if this program is viewed by another person, he/she does not understand at a glance what the No. 2 task is. To avoid such inconvenience, the MR308 provides means of specifying the task by name (function or symbol name).
The program named "configurator cfg308 ,"which is supplied with the MR308, then automatically converts the task name to the task ID number. This task identification system is schematized in Figure 3.11.
sta_tsk(Task name)
Name
Configurator
ID number
Starting the task having the designated ID number
Real-time OSProgram
Figure 3.11 Task Identification
sta_tsk(ID_task,1);
This example specifies that a task corresponding to "ID_task" be invoked.
It should also be noted that task name-to-ID number conversion is effected at the time of program generation. Therefore, the processing speed does not decrease due to this conversion feature.
- 18 -
Chapter 3 Introduction to MR308
p
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. That is, the key input task is placed in the execution (RUNNING) state. While the system waits for key input, task execution is not needed. In that situation, the key input task in the WAITING state.
Key input

Task

Key input processing
RUNNIG state WAITING state RUNNING state
Figure 3.12 Task Status
Waiting for key input
Key input
rocessing
The MR308 controls the following six different states including the RUNNING and WAITING states.
1. RUNNING state
2. READY state
3. WAITING state
4. SUSPENDED state
5. WAITING-SUSPENDED state
6. DORMANT state
Every task is in one of the above six different states. Figure 3.13 shows task status transition.
- 19 -
READY state
Chapter 3 Introduction to MR308
MPU execlusive right acquisition
MPU execlusive right relinquishment
WAITING state
WAITING state
RUNNING state
Entering the WAITING state
SUSPENDED state clear request from other task
SUSPEND request from other task
Forced termin ation request from other task
WAITING-SUSPENDED
state
WAITING state
SUSPEND request
clear
from other task
SUSPENDED
SUSPENDED state
state
clear request
Forced termination request from other task
DORMANT
state
Task activation
Figure 3.13 MR308 Task Status Transition
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.
The currently executed task changes into a different state when any of the following conditions occurs.
9
The task has normally terminated itself. The task has placed itself in the WAITING state.
10
Due to interruption or other event occurrence, the interrupt handler has placed a different task
having a higher priority in the READY state.
The priority assigned to the task has been changed so that the priority of another READY task is
rendered higher.
Due to interruption or other event occurrence, the priority of the task or a different READY task
has been changed so that the priority of the different task is rendered higher.
11
12
When the ready queue of the issuing task priority is rotated by the rot_rdq or irot_rdq service call
and control of execution is thereby abandoned
When any of the above conditions occurs, rescheduling takes place so that the task having the highest priority among those in the RUNNING or READY state is placed in the RUNNING state, and the exe­cution of that task starts.
2. READY state
The READY state refers to the situation in which the task that meets the task execution conditions is still waiting for execution because a different task having a higher priority is currently being executed.
When any of the following conditions occurs, the READY task that can be executed second according
9
Depends on the ext_tsk service call.
10
Depends on the dly_tsk, slp_tsk, tslp_tsk, wai_flg, twai_flg, wai_sem, twai_sem, rcv_mbx, trcv_mbx,snd_dtq,tsnd_dtq,rcv_dtq, trcv_dtq,
vtsnd_dtq, vsnd_dtq,vtrcv_dtq,tget_mpf, get_mpf or vrcv_dtq service call.
11
Depends on the chg_pri service call.
12
Depends on the ichg_pri service call.
- 20 -
Loading...
+ 132 hidden pages