Home
M3T-MR308/4 V.4.00 User`s Manual
Contents
1. System clock interrupt handler GLB __SYS_STMR_INH ALIGN __SYS_STMR_INH process issue system call For PD308 __ISSUE_SYSCALL System timer interrupt handler _STMR_hdr ret_int ENDIF A1 A1 Figure 5 14 C Language Startup Program crtOmr a30 88 Chapter 5 Detailed Applications The following explains the content of the C language startup program crtOmr a30 Incorporate a section definition file 13 in Figure 5 14 Incorporate an include file for MR308 14 in Figure 5 14 Incorporate a system ROM area definition file 15 in Figure 5 14 Incorporate a system RAM area definition file 16 in Figure 5 14 This is the initialization program __SYS_INITIAL that is activated immediately after a reset 99 256 in Figure 5 14 1 2 3 4 5 6 7 8 9 Setting the System Stack pointer 100 in Figure 5 14 Setting the processor mode register 102 104 in Figure 5 14 Setting the SB FB register 105 109 in Figure 5 14 Initial set the C language 129 155 in Figure 5 14 When using no standard input output func tions remove the lines 191 and 192 in Figure 5 14 Setting OS interrupt disable level 164 166 in Figure 5 14 Setting the address of interrupt vector table 167 in Figure 5 14 Set MR308 s system clock interrupt 172 177 in Figure 5 14 Initial set MR308 s system timer 182 186 in Figure 5 14
2. uITRON 4 0 Specification is an open real time kernel specification set forth by the TRON Association The documented specification of UITRON 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 uITRON 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 High speed processing is achieved MR308 enables high speed processing by taking full advantage of the microcomputer architecture 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
3. 2 Depends on the ichg_pri service call 20 Chapter 3 Introduction to MR308 to the ready queue is placed in the RUNNING state Acurrently 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 Due to interruption or other event occurrence the priority of a currently executed task has been changed so that the priority of a different READY task is rendered higher When the ready queue of the issuing task priority is rotated by the rot_rdq or irot rdg service call and control of execution is thereby abandoned 3 WAITING state When a task in the RUNNING state requests to be placed in the WAITING state it exits the RUNNING state and enters the WAITING state The WAITING state is usually used as the condition in which the completion of I O device I O operation or the processing of some other task is awaited The task goes into the WAITING state in one of the following ways The task enters the WAITING state simply when the slp tsk service call is issued In this case the task does not go into the READY state until its WAITING state is cleared explicitly by some other task The task enters and remains in the WAITING state for a specified time period when the dly tsk service call is issued In this case the task goes into the
4. 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 reguires that compile options be set For details refer to Page 94 Timers used for system clock Definition format Symbol Definition range AO A1 A2 A3 A4 BO B1 B2 B3 B4 B5 OTHER NOTIMER Default value NOTIMER Define the hardware timers used for the system clock If you do not use a system clock define NOTIMER System clock interrupt priority level Definition format Numeric value Definition range 1 to Kernel mask OS interrupt disable level in system definition Default value 4 Define the priority level of the system clock timer interrupt The value set here must be smaller than the kernel mask OS interrupt disable level Interrupts whose priority levels are below the interrupt level defined here are not accepted during sys tem clock interrupt handler processing 101 Chapter 6 Using Configurator 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 lt lt Format gt gt Max Definition maxdefinef max task the maximum number of tasks defined max flag the maximum number of eventflags defined max dtg the maximum number of data queues defined
5. max mbx the maximum number of mailboxes defined max sem the maximum number of semaphores defined max mpf the maximum number of fixed size memory pools defined max mpl the maximum number of variable size memory pools defined max cyh the maximum number of cyclic handlers defined max alh the maximum number of alarm handlers defined max vdtg the maximum number of short data queues defined i lt lt Contents gt gt 1 The maximum number of tasks defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of tasks defined 2 The maximum number of eventflags defined Definition format Numeric value Definition range 1 to 255 Default value None 3 The maximum number of data queues defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of data gueues defined 4 The maximum number of mailboxes defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of mailboxes defined 5 9 For details of forming the into separate ROMs see page 145 102 Chapter 6 Using Configurator 5 The maximum number of semaphores defined Definition format Numeric value Definition range
6. 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 Starting the task having the designated Name ID number ID number Configurator Program Real time OS 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 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
7. 1 to 255 Default value None Define the maximum number of semaphores defined 6 The maximum number of fixed size memory pools defined Definition format Numeric value Definition range 1 to 255 Default value None 7 The maximum number of variable length memory blocks defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of variable length memory blocks defined 8 The maximum number of cyclic activation handlers defined Definition format Numeric value Definition range 1 to 255 Default value None The maximum number of cyclic handler defined 9 The maximum number of alarm handler defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of alarm handlers defined 10 The maximum number of short data queues defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of short data gueues defined 103 Chapter 6 Using Configurator Task definition lt lt Format gt gt Tasks Definition task ID No name ID name entry_address Start task of address stack size User stack size of task priority Initial priority of task context Registers used stack section Section na
8. Definition format Symbol Definition range TA_TFIFO or TA_TPRI Default value TA_TFIFO Select a method in which tasks wait for the event flag 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 106 Chapter 6 Using Configurator 3 Initial value of the event flag Definition format Numeric value Definition range 0 to OxFFFF Default value 0 Specify the initial bit pattern of the event flag 4 Multi wait attribute Definition format Symbol Definition range TA_WMUL or TA WSGL Default value TA WSGL Specify whether multiple tasks can be engueued in the eventflag waiting gueue If TA WMUL is se lected the TA WMUL attribute is added permitting multiple tasks to be engueued If TA WSGL is se lected the TA WSGL attribute is added prohibiting multiple tasks from being engueued 5 Clear attribute Definition format Symbol Definition range YES or NO Default value NO Specify whether the TA CLR attribute should be added as an eventflag attribute If YES is selected the TA CLR attribute is added If NO is selected the TA CLR attribute is not added Semaphore definition This definition is necessary to use Semaphore function lt lt Format gt gt Semaphore Definition semaphore ID No name ID name wa
9. Error messages cfg308 Error syntax error near line xxx xxxx cfg There is an syntax error in the configuration file cfg308 Error not enough memory Memory is insufficient cfg308 Error illegal option gt lt x gt The configurator s command option is erroneous cfg308 Error illegal argument gt lt xx gt The configurator s startup format is erroneous cfg308 Error can t write open lt XXXX gt The XXXX file cannot be created Check the directory attribute and the remaining disk capacity avail able cfg308 Error can t open lt XXXX gt The XXXX file cannot be accessed Check the attributes of the XXXX file and whether it actually ex ists cfg308 Error can t open version file The MR308 version file version cannot be found in the directory indicated by the environment vari able LIB308 cfg308 Error can t open default configuration file The default configuration file cannot be accessed default cfg is needed in the current directory or directory LIB308 specifying cfg308 Error can t open configuration file lt xxxx cfg gt The configuration file cannot be accessed Check that the file name has been properly designated cfg308 Error illegal XXXX gt lt xx gt near line xxx xxxx cfg The value or ID number in definition item XXXX is incorrect Check the valid range of definition cfg308 Error Unknown XXXX gt lt xx gt near line xx xxxx cfg The symbol definition in definition ite
10. 46 Figure 3 37 rel mpl processing cccccccsessssssceeecececeessnsececececsesessueeeeeeecsesessuesecesecseeeseaeaaeeesenenes 46 Figure 3 38 Timeout Processing ooococccononononnonnnoncnnonononnnnnnonnnnnnannan nono roncnnnnnnnn nn rn rn 494090 GG Rene R ee KR nn 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 coooonccnnonccccnonocnnnnnooonnnnnonnnnnonononnncnonocnnncnnnoss 50 Figure 3 42 Ready Queue Management by rot_rdq System Call eee 51 Figure 3 43 Interrupt process flOW cccccesssssccceceeeessnsececcececeeeessssesececececeensnssseeeeeeesesesenssaeeeeenenes 52 Figure 4 1 MR308 System Generation Detail Flowchart oooooconnnoccccnonocnnonononnnnnnononnnoconnnnnccnnnnos 61 Figure 4 2 Program Example diia ode 63 Figure 4 3 Configuration File Example 0 cccccccccssscccesssececsesseceesesseeeecsesseeecsesseeecsesseeeeneseeeeesesaes 64 Figure 4 4 Configurator Execution ooooconoooccnononononnnonnncnnnnnnnnonononononnnnnnnnnnnnnn ocn nnnnnnrnnnnnn enn KARR cancion 65 Figure 4 5 System Generatio iia toda deo dd od os AA nadstavba aaa 65 Figure 5 1 Example Infinite Loop Task Described in C Language u eee 68 iv Figure 5 2 Example Task Terminating with ext tsk Desc
11. Chapter 6 Using Configurator 4 Maximum message priority Definition format Numeric Value Definition range 1 to maximum value of message priority that was specified in definition of maximum number of items Default value 1 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 lt lt Format gt gt Fixed Memory pool Definition memorypool ID No 1 Ji name ID name section Section Name num block Number of blocks in memory pool siz block Block size of Memory pool siz block Select memory pool waiting gueue The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are auto matically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each memory pool ID number define the items described below 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the memory pool is specified in a program 2 Section name Definition format Symbol Definition range None Default value MR HEAP 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
12. Initial set parameters inherent in the application 191 in Figure 5 14 Initialize the RAM data used by MR308 198 251 in Figure 5 14 Activate the initial startup task 254 in Figure 5 14 This is a system clock interrupt handler 295 306 in Figure 5 14 89 Chapter 5 Detailed Applications 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 e c sec inc This file is used when you developed your applications with the C language c sec inc is derived from asm_sec inc by adding sections generated by C compiler NC308 Refer to page 92 for details about each section Modify the section allocation and start address settings in this file to suit your system The following shows how to modify the section file e g If you want to change the program section start address from F0000H to F1000H section program org OFOOOOH Correct this address to F1000H y section program org OF1000H 90 Chapter 5 Detailed Applications 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 Ed
13. NO 17 timeout YES 18 tic_nume sv 19 tic_deno 20 message pri 255 21 22 System Clock Definition 23 clock 24 mpu_clock 20MHz 25 timer A0 26 IPL 4 27 1 28 Task Definition 29 30 task l 31 entry address main 32 name ID main 33 stack size 100 34 priority 1 35 initial start ON 36 37 task l 38 entry address taskl 39 name ID taskl 40 stack_size 500 41 priority 2 42 43 task 44 entry address task2 45 name ID task2 46 stack_size 500 47 priority 35 48 49 50 semaphore 51 name ID seml 52 max count 1 53 initial count 1 54 wait queue TA_TPRI 55 Y 56 57 58 59 cyclic hand 1 60 name ID cyhl 61 interval_counter 100 62 start OFF 63 phsatr OFF 64 phs counter 07 65 entry address cyh1 66 exinf 1 67 144 Chapter9 Separate ROMs Chapter 9 Separate ROMs 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 1 System configuration Here you set up a system configuration of application programs Here descriptions are given
14. 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 pr
15. Chapter 3 Introduction to MR308 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 e Task connection pointer Task connection pointer used for ready gueue formation or other purposes e Task status e Task priority e Task register information and other data storage stack area pointer current SP register value Wake up counter Task wake up request storage area Time out counter or wait flag pattern When a task is in a time out wait state the remaining wait time is stored if in a flag wait state the flag s wait pattern is stored in this area e Flag wait mode This is a wait mode during eventflag wait Timer queue connection pointer This area is used when using the timeout function This area stores the task connection pointer used when constructing the timer queue e Flag wait pattern This area is used when using the timeout function This area stores the flag wait pattern when using the eventflag wait service call with the timeout func tion twai_flg No flag wait pattern area is allocated when the eventflag is not used Startup request counter This is the area in which task startup requests are accumulated e Extended task information Extended task information that was set during task generation is stored in
16. Default value __SYS_DMY_INH Define the entry address of the interrupt handler When written in the C language add at the end or at the beginning of the function name you have defined 3 Switch passed to PRAGMA extended function Definition format Symbol Definition range E F or B Default value None Specify the switch to be passed to pragma INTHANDLER or pragma INTERRUPT If E is specified the E switch is assumed in which case multiple interrupts another interrupt within an interrupt are enabled If F is specified the F switch is assumed in which case the FREIT instruction is output at return from the interrupt handler If B is specified the B switch is assumed in which case register bank 1 is specified Two or more switches can be specified at the same time For kernel OS dependent interrupt han dlers however only the E switch can be specified For non kernel OS independent interrupt han dlers the E F and B switches can be specified subject to a limitation that E and B cannot be 116 Chapter 6 Using Configurator 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
17. Execute the configurator cfg308 to generate system data definition files sys rom inc sys ram inc include files mr308 inc kernel_id h and a system generation procedure description file makefile from the configuration file A gt cfg308 mv lbp cfg MR308 system configurator V 4 00 06 Copyright 2003 2005 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED MR308 version gt V 4 00 Release 01 A gt Figure 4 4 Configurator Execution 4 2 4 System generation Execute the make command to generate the system A gt make f makefile as308 F Dtest 1 crtOmr a30 nc308 c task c 1n308 1n308 sub A gt Figure 4 5 System Generation 4 2 5 Writing ROM Using the Imc308 load module converter convert the absolute module file into a ROM writable format and then write it into ROM Or read the file into the debugger and debug it 4 There are two types of make commands one of which conforms to the MS DOS standard and the other conforms to or is compliant with the UNIX standard MR308 accepts only the make command that conforms to or is compliant with the UNIX standard When using MS DOS use a 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 m
18. Modify the ID number or delete the extra definition cfg308 Error you must define XXXX near line xxx xxxx cfg XXXX cannot be omitted cfg308 Error you must define SYMBOL near line xxx xxxx cfg This symbol cannot be omitted cfg308 Error start up file XXXX not found The start up file XXXX cannot be found in the current directory The startup file start a30 or ertOmr a30 is required in the current directory cfg308 Error bad start up file XXXX There is unnecessary start up file in the current directory cfg308 Error no source file No source file is found in the current directory cfg308 Error zero divide error near line xxx xxxx cfg A zero divide operation occurred in some arithmetic expression cfg308 Error task X stack size must set XX or more near line xxx xxxx cfg You must set more than XX bytes in task x stack_size cfg308 Error RO must exist in task x context near line xxx xxxx cfg You must select RO register in task x context cfg308 Error can t define address match interrupt definition for Task Pause Function near line xxx xxxx cfg Another interrupt is defined in interrupt vector definition needed by Task Pause Function cfg308 Error Set system timer system timeout YES near line xxx xxxx cfg Set clock timer symbol except NOTIMER 130 Chapter 6 Using Configurator Warning messages The following message are a warning A warning can be ignored providing tha
19. asm sec inc orc sec inc If no section names are defined the memory pool is located in the MR HEAP section 3 Number of block Definition format Numeric value Definition range 1 to 65 535 Default value 1 Define the total number of blocks that comprise the memory pool 111 Chapter 6 Using Configurator 4 Size in bytes Definition format Numeric value Definition range 4 to 65 535 Default value 256 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 Selecting a memory pool waiting queue Definition format Symbol Definition range TA TFIFO or TA TPRI Default value TA TFIFO Select a method in which tasks wait for acguisition of the fixed size memory pool If TA TFIFO is se lected tasks are engueued in order of FIFO If TA TPRI is selected tasks are engueued in order of priority beginning with the one that has the highest priority Variable size memory pool definition This definition is necessary to use Variable size memory pool function lt lt Format gt gt Variable Size Memory pool Definition variable _memorypool T name ID Name max memsize The maximum memory block size to be allocated mpl section Section name Memory pool size heap size W The ID number must be in the range 1 to 255 The
20. be sure to include mr308 inc which is in the system directory For the symbol indicating the handler start address make the external declaration Always use the RTS instruction subroutine return instruction to return from cyclic han dlers and alarm handlers For examples INCLUDE mr308 inc 1 GLB cychand 2 cychand A handler process FES ESK 3 Figure 5 10 Example Handler Written in Assembly Language Use the GLB pseudo directive 77 Chapter 5 Detailed Applications 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 Table 5 2 Interrupt Number Assignment Interrupt No Service calls Used 63 Service calls that can be issued from only task context 62 Service calls that can be issued from only non task context Service calls that can be issued from both task context and non task context 61 ret int service call 60 dis dsp service call 59 loc cpu iloc cpu service call 58 ext tsk service call 55 tsnd_dtq twai flg vtsnd_dtq service call 5 4 The Use of registers of bank The registers of bank is 0 when a task starts on MR308 MR308 does not change the registers of bank in processing kernel You must pay attentio
21. c cccccccccscssccssesscssesscsscescesecssesscssssscsscssessecssesscssesscsassscvscsscaesesenacseeaeses 101 Definition respective maximum numbers of items ccccccessessssssseecscesesecscscsececscsecsesscsscsecsesacsesseanscseceees 102 K Task definition A o ia 104 CEyentilas definition EA E E ek E A A AE a EA A ee 106 Semaphore definition lia 107 Data qu ve de Ton laaa Phan a dla 108 Short data queue definition lerene a N EA E A 109 A ONE E oo On ne o no eee 110 Fixed size memory pool definition c cccceececssccssesecssesscsscescssccssesecssesscsscsscssecssesecssesscsssesesscsesesenseesseaecaneass 111 Variable size memory pool definition c cccecceecesescescescesecssesscsscsscsscescssecesesecssesscsssssevsecssesecsecssesecaseesenseeses i KC Cycle handier definition ireniasno o ATE A al tii 113 Alarm handler definition eeecessscssesesesesseseseseececeesesesesesesecucncnencscseeceesescecseaeacsessusesaesesesesncesecaeaeaeeceteeeees 115 CTnterruptivector definitaon a 116 6 1 3 Configuration File Example 00000000 0eee 000000000 000000 00000000 00 0e0R RAK R Ko Ko ono none ena n n non 119 6 2 Configurator Execution Procedures cccccccssssscssececcecesnessecececccecsensnsasecececeecsesentsaseeeeeeesenensaaeees 123 6 2 1 Configurator OVErview cccccessccsscceceesesssecececcecseeessnseceeesececeesssseeeeseesece
22. stack size Other messages The following message are a warning message that is output only when generating makefile The configurator skips the sections that have caused such a warning as it generates makefile cfg308 Error xxxx line xxx include format error The file read format is incorrect Rewrite it to the correct format cfg308 Warning xxxx line xxx can t find lt XXXX gt cfg308 Warning xxxx line xxx can t find XXXX The include file XXXX cannot be found Check the file name and whether the file actually exists cfg308 Warning over character number of including path name The path name of include file is longer than 255 characters 131 Chapter 6 Using Configurator 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 AS308 command options You define command options of the assembler in ASFLAGS 3 LN308 command options You define command options of the linker in LDFLAGS There are no particular options you need to specify 4 Specifying libraries You define libraries in LIBS The configurator picks up necessary libraries from the configuration file and from the current directory and defines them in LIBS Either add or delete libraries when necessar
23. 1 Chapter 6 Using Configurator TA TFIFO NO TA WMUL 1 Ox0000f FFF TA_TPRI YES TA WMUL 0x00000008 TA_TPRI YES TA WSGL 1 TA TFIFO 0 TA TFIFO 5 TA TPRI 255 1 TA TFIFO 10 TA TPRI 5 TA TFIFO 256 1 TA TFIFO TA MFIFO TA TPRI TA MPRI TA_TFIFO TA MPRI TA TPRI TA MFIFO Chapter 6 Using Configurator 155 name ID mpfl 156 wait gueue TA TFIFO 157 section MR RAY 158 siz block 16 159 num block 5 160 161 memorypool 2 162 name ID mpf2 163 wait_queue TA_TPRI 164 section MR_RAM 165 siz block 32 166 num block 4 167 168 memorypool 3 169 name ID_mpf3 170 wait queue TA TFIFO 171 section MPF3 172 siz block 64 173 num block 256 174 175 176 variable memorypool 177 name ID mpl1 178 max memsize 8 179 heap_size 16 180 181 variable memorypool 182 name ID mpl2 183 max_memsize 64 184 heap_size 256 185 186 variable memorypool 3 187 name ID mpl3 188 max memsize 256 189 heap size 1024 190 191 192 cyclic_hand 193 entry address cyh1 194 name ID cyhl 195 exinf 0x0 196 start ON 1 97 phsatr OFF 198 interval counter 0x1 199 phs counter 0x0 200 201 cyclic_hand 202 entry address cyh2 203 name ID cyh2 204 exinf 0x1234 205 start OFF 206 phs
24. 3 16 3 2 1 Chapter 3 Introduction to MR308 Service Call Processing When a service call is issued processing takes place in the following sequence 1 2 5 6 The current register contents are saved The stack pointer is changed from the task type to the real time OS system type Processing is performed in compliance with the reguest made by the service call The task to be executed next is selected The stack pointer is changed to the task type 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 Register Save Service call issuance SP lt 0S Processing Task Selection Task gt SP LED illumination Task Register Restore Figure 3 10 Service Call Processing Flowchart 8 A different sequence is followed if the issued service call does not evoke task switching 17 e 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
25. 53 3 5 17 Extended Function Reset Function adidas 54 3 5 18 Service calls That Can Be Issued from Task and Handler eee 55 Chapter 4 Applications Development Procedure Overview cccccccecsscesssssessessscssessscssesseessessseseeees 59 AM Overview St ul dun A a te 60 4 2 Development Procedure Example 0000000e0eee 0000 0000000e 0000000000000 on nene no 00 een ena n ono nn 62 4 2 1 Applications Program Coding cccccccesscccsccecessessscececececeessssesseceeececsesesssaeeeeeeeesenesssseeeseesesenees 62 4 2 2 Configuration File Preparation cocccnnooononnnononnnonanononononnnnonnnnonononconononnnnonnnnnronnnnnnnn nora nnncononanns 64 4 2 3 Configurator EXecUtIO iii di a a dz la a naa dais 65 4 2 4 Dyst em ceneratom RARA AA EA AS e 65 425 Witnes ROM cuota tal iso balakogred cossbundseet ONEONE aa EE Ea cess Sunt ated careto babe 65 Chapter 5 Detailed Applications cccccscesesesseesseeeecesseeeseesseeeseeeseeseceeseeeeeeeeeeescesseeeeeeeeceseseeeceseeeeeeens 67 5 1 Program Coding Procedure in C Languagt ocooococononcnnnnoononnnononnononananononononnononnn nono nonconononnnnnnnncaconann 68 5 1 1 Task Description Procedure cccccsssssccsecessessssececececeenenssaececececesesenssseceeececsesestaaeeeeeeseseneaaaees 68 5 1 2 Writing a Kernel OS Dependent Interrupt Handler oonononicniononicononocnnnnnonononncanon
26. Figure 7 1 TaskA Interrupt handler OS Interrupt Save Registers system call processing Restore Registers ret_int Task selection SP lt User Scheduler TaskB Restore Registers Figure 7 1 Processing Procedure for a System Call a Handler that caused an interrupt during Task Execution 5 The ret int service call is issued automatically when OS dependent handler is written in C language when pragma INTHANDLER specified 137 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 lt System Save Registers P Interrupt system call processing Restore Registers Task selection ret_int SP lt User Restore Registers VW Figure 7 2 Processing Procedure for a System Call from a Handler that caused an interrupt during System Call Processing 138 Chapter 7 Application Creation Guide 7 13 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 h
27. READY or RUNNING state the ready queue also is updated See Figure 3 21 Furthermore if the target task is placed in a waiting queue of objects with TA_TPRI attribute the wait ing queue also is updated See Figure 3 22 32 Chapter 3 Introduction to MR308 Priority 1 Task A gt Task B M i as l l L al n 2235 TaskE Task F When the priority of task B has been changed from 3 to Figure 3 21 Alteration of task priority ID Number 1 2 EA y 3 7 taska 77 taskB jam taskC taskB Priority 1 Priority 2 Priority 3 Priority 4 n When the priority of Task B is changed into 4 Figure 3 22 Task rearrangement in a waiting gueue e Reference task priority get pri iget pri Gets the priority of a task e Reference task status simple version ref tst iref tst Refers to the state of the target task e Reference task status ref tsk iref tsk Refers to the state of the target task and its priority etc 33 Chapter 3 Introduction to MR308 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 incorpo
28. READY state when the specified time has elapsed or its WAITING state is cleared explicitly by some other task The task is placed into WAITING state for a wait request by the wai flg wai sem rev mbx snd_dtq rev dtag vsnd_dtq vrev_dtq or get mpf service call In this case the task goes from WAITING state to READY state when the reguest is met or WAITING state is explicitly canceled by another task The tslp_tsk twai flg twai sem trev mbx tsnd_dtq trcv_dtq vtsnd_dtq vtrev_dtq and tget mpf service calls are the timeout specified versions of the slp tsk wai flg wai sem rev mbx snd dtg rev dtg vsnd_dtq vrcv_dtq and get mpf service calls The task is placed into WAITING state for a wait reguest by one of these service calls In this case the task goes from WAITING state to READY state when the reguest is met or the specified time has elapsed If the task is placed into WAITING state for a wait request by the wai flg wai sem rev mbx snd_dtq rev dtg vsnd_dtq vrcv_dtq get mpf twai_flg twai sem trcv_mbx tsnd_dtq trcv_dtq vtsnd_dtq vtrev_dtq or tget mpf service call the task is queued to one of the following waiting queues depending on the request e Event flag waiting queue Semaphore waiting queue e Mailbox message reception waiting queue e Data queue data transmission waiting queue Data queue data reception waiting queue Short data queue data transmission waiting queue Short data queue da
29. The MR308 permits giving the same priority to several tasks To provide proper control over the READY task execution order the system generates a task execution queue called ready queue The ready queue structure is shown in Figure 3 14 The ready queue is provided and controlled for each priority level The first task in the ready queue having the highest priority is placed in the RUNNING state Priority 2 a z TCB TCB B TCB TCB TCB Figure 3 14 Ready Queue Execution Queue 2 The TCB task control block is described in the next chapter 75 The task in the RUNNING state remains in the ready queue 23 Chapter 3 Introduction to MR308 3 3 3 Task Priority and Waiting Oueue 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 gueue in order of FIFO TA TFIFO Figure 3 15 and Figure 3 16 depict the manner in which tasks are placed in a waiting queue in order of taskD taskC taskA and taskB ID No ES gt Priority 1 Priority 5 Priority 6 Priority 9 n Figure 3 15 Waiting queue of the TA_TPRI attribute ID No taskD taskC taskA taskB Priority 9 Priority 6 Priority 1 Priority 5 BC Figure 3 16 Waiting gueue of the TA TFIFO attribute 24
30. a System Call that can be Issued from only a Task and Figure 5 13 Interrupt control in a System Call that can be Issued from a Task independent 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 The following two methods for interrupt control are recommended 1 Modify the interrupt control register SFR for the interrupt you want to be disabled 2 Use service calls loc_cpu and unl_cpu The interrupts that can be controlled by the loc_cpu service call are only the kernel OS dependent interrupt Use method 1 to control the non kernel OS independent interrupts 81 Chapter 5 Detailed Applications 5 6 Regarding Delay Dispatching MR308 has four service calls related to delay dispatching e dis dsp e ena dsp e loc cpu e uni 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 Dispatching to the tasks to be executed is delayed until the dispatch disabled state is cleared When dispatch is being delayed e Task under execution is in a RUNNIN
31. activation phase is not saved e Start Cyclic Handler Operation sta_cyc ista_cyc Causes the cyclic handler with the specified ID to operational state Stop Cyclic Handler Operation stp_cyc istp_cyc Causes the cyclic handler with the specified ID to non operational state Reference Cyclic Handler Status ref_cyc iref_cyc Refers to the status of the cyclic handler The operating status of the target cyclic handler and the re maining time before it starts next time are inspected 49 3 5 12 Chapter 3 Introduction to MR308 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 Start Start Sto Alarm handler o k P operating operating operating created Activation Activation time time Handler starts Handler does not start Figure 3 41 Typical operation of the alarm handler Start Alarm Handler Operation sta_alm ista_alm Causes the alarm handler with the specified ID to operational state Stop alarm Handler Operation stp_alm istp_alm Causes the alarm handler with the specified ID to non operational state Reference Alarm Handler Status ref_alm iref_alm Refers to the status of the alarm handler The operating status of the target alarm ha
32. 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 Task Context Non task Context act tsk o x lact_tsk X o can act o X ican act X o sta tsk o X ista tsk X o ext tsk o x ter_tsk o x chg pri o X ichg pri X o get pri o X iget pri X o ref tsk o x iref tsk X o ref tst o x iref_tst X o slp tsk o X tslp tsk o x wup tsk o X iwup tsk X o can wup o x ican_wup X o rel wai o X irel_wai X o sus tsk o x isus tsk X o rsm tsk o X irsm tsk X o frsm tsk o x ifrsm_tsk X o dly_tsk o x 55 Chapter 3 Introduction to MR308 Service Call Task Context Non task Context s19 sem o x isig sem x o wal sem o x twai_sem o x pol sem o X ipol sem X o ref sem o X iref sem X o set flg o X iset_flg X o clr flg o X iclr flg X o wai_flg o x twai_flg o x pol flg o X ipol flg X o ref flg o X iref_flg X o snd_dtq o x tsnd dta o x psnd dtg o X ipsnd dtg X o fsnd_dtq o x ifsnd_dtq X o rev dtg o X trev_dtq o x prev dtg o X iprev dtg X o ref dta o x iref_dtq X o snd mbx o x isnd_mbx X o rev mbx o X trev mbx o X prev mbx o X iprev mbx X o ref mbx o x iref mbx X o 56 Chapter 3 Introduction to M
33. area FIX INTERRUPT VECTOR section 146 Chapter 9 Separate ROMs kernel ROM Application ROM1 Internal ROM MR KERNEL Startup MR ROM MR308 s ROM Program data MR308 kernel MR_CIF C language I F routine Use Functi n program TaskofID 1 App_prog Task2 Mailbox Eventflag Task3 Number of Task4 Fix Interrupt Vector area Task4 Interrupt vector area Application ROM2 MR_ROM MR308 s ROM application change data MR_CIF C language I F routine App_prog Task1 Use Function Task2 Mailbox Task3 Eventflag semaphore Task4 Number of Task5 Te Interrupt vector area Figure 9 1 ROM separate e Programs to be located in the application ROM MR308 s ROM data the MR ROM section C language I F routines the MR CIF section Application programs the app prog section Interrupt vector area the INTERRUPT VECTOR section e How to locate individual programs is given below Changing the section name of user program In dealing with application programs written in C language you change the section name of the pro grams to be located in the application ROM by use of pragma SECTION as shown below In NC308WA the section name of user program if not given turns to program section So you need to assign a different section name to the task you locate in the application ROM pragma SECTION program app prog Changing section of program T
34. be used lt lt Format gt gt Mailbox Definition mailbox ID No 1 name ID name wait_queue Select mailbox waiting queue message gueue Select message queue max pri Maximum message priority The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are auto matically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each mailbox ID number define the items described below 1 IDname Definition format Symbol Definition range None Default value None Define the name by which the mailbox is specified in a program 2 Select mailbox waiting queue Definition format Symbol Definition range TA_TFIFO or TA_TPRI Default value TA TFIFO Select a method in which tasks wait for the mailbox If TA TFIFO is selected tasks are engueued in order of FIFO If TA TPRI is selected tasks are engueued in order of priority beginning with the one that has the highest priority 3 Select message queue Definition format Symbol Definition range TA_MFIFO or TA_MRPI Default value TA MFIFO Select a method by which a message queue of the mailbox is selected If TA MFIFO is selected messages are engueued in order of FIFO If TA MPR is selected messages are enqueued in order of priority beginning with the one that has the highest priority 110
35. can be entered using decimal numbers only Frequency entry examples are presented below e 16MHz 8 1234MHz It is also well to remember that the frequency must not begin with period Time The time is indicated by a character string that consists of numerals and period and ends with ms The time values are effective up to three decimal places when the character string is terminated with ms Also note that the time can be entered using decimal numbers only 97 Chapter 6 Using Configurator e 10ms 10 5ms It is also well to remember that the time must not begin with period 98 Chapter 6 Using Configurator 6 1 2 Configuration File Definition Items The following definitions are to be formulated in the configuration file e System definition e System clock definition Respective maximum number of items e Task definition e Eventflag definition Semaphore definition Mailbox definition e Data queue definition e Short data queue definition Fixed size Memory Pool definition Variable size Memory Pool definition e Cyclic handler definition e Alarm handler definition e Interrupt vector definition System Definition Procedure lt lt Format gt gt System Definition system stack size System stack size priority Maximum value of priority system IPL Kernel mask level OS interrupt disable level timeout Timeout function ta
36. function lt lt Format gt gt Interrupt Vector Definition interrupt vector Vector No os int Kernel managed OS dependent interrupt handler entry address Start address pragma switch Switch passed to PRAGMA extended function W 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 Configurator can t create an Initialize routine interrupt control register interrupt causes etc for this defined in terrupt You need to create that lt lt Content gt gt 1 Kernel OS dependent interrupt handler Definition format Symbol Definition range YES or NO Define whether the handler is a kernel OS dependent interrupt handler If it is a kernel OS dependent interrupt handler specify YES if it is a non kernel OS independent interrupt handler specify No If this item is defined as YES the declaration statement shown below is output to the kernel_id h file pragma INTHANDLER V4 function name If this item is defined as NO the declaration statement shown below is output to the kernel_id h file pragma INTERRUPT V4 function name 2 Start address Definition format Symbol or function name Definition range None
37. hereby under any patents copyrights or other intellectual property rights of Renesas Electronics or others You should not alter modify copy or otherwise misappropriate any Renesas Electronics product whether in whole or in part Descriptions of circuits software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples You are fully responsible for the incorporation of these circuits software and information in the design of your eguipment Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits software or information When exporting the products or technology described in this document you should comply with the applicable export control laws and regulations and follow the procedures reguired by such laws and regulations You should not use Renesas Electronics products or the technology described in this document for any purpose relating to military applications or use by the military including but not limited to the development of weapons of mass destruction Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture use or sale is prohibited under any applicable domestic or foreign laws or regulations Renesas Electronics has used reasonable care in preparing the information included in this document but Re
38. in READY state the task is placed into SUSPENDED state if is sued to a task in WAIT state the task is placed into WAIT SUSPENDED state Since MR308 allows Note that tasks in WAIT state but kept waiting for the following conditions are not awaken Eventflag wait state semaphore wait state data transmission wait state data reception wait state timeout wait state fixed length memory pool acquisition wait short data transmission wait or short data reception wait 34 Chapter 3 Introduction to MR308 only one forcible wait reguest 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 E_QOVR sus_tsk sus_tsk rsm_tsk Task 20 NA L RUNNING SUSPENDED READY state state state WAITING WAITING state SUSPENDED WAITING state state Number of suspension 0 1 1 0 request Figure 3 25 Forcible wait of a task and resume Forcibly resume suspended task frsm_tsk ifrsm_tsk Clears the number of suspension requests nested to 0 and forcibly resumes execution of a task Since MR308 allows only one suspension request to be nested this service call behaves the same way as rsm_tsk and irsm_tsk See Figure 3 26 sus_tsk frsm_tsk Task BS ee nt ee READY state gt SUSPENDED READYstate state WAITING WAITING WAITING state SUSPENDED state state Number of suspension 0 1 0 requests Figure 3 26 Forcible wait of a task and forcible resume Release tas
39. is in the system di rectory as well as kernel id h which is in the current directory Do not use the ret_int service call in the interrupt handler The static declared functions can not be registered as an interrupt handler include lt itron h gt include lt kernel h gt include kernel id h void inthand void process iwup tsk ID main Figure 5 3 Example of Kernel OS dependent Interrupt Handler TA configuration file is used to define the relationship between handlers and functions 48 When an kernel OS dependent interrupt handler is declared with pragma INTHANDLER code for the ret int service call is automati cally generated 70 Chapter 5 Detailed Applications 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 No service call can be issued from a non kernel an OS independent interrupt handler NOTE If this restriction is not observed the software may malfunction 3 A function that is declared to be static cannot be registered as an interrupt handler If you want multiple interrupts to be enabled in a non kernel an OS independent interrupt handler always make sure that the non kernel OS independent interrupt handler is as signed a priority
40. level higher than other kernel OS dependent interrupt handlers include lt itron h gt include lt kernel h gt include kernel id h void inthand void process Figure 5 4 Example of Non kernel OS independent Interrupt Handler S you want the non kernel OS independent interrupt handler to be assigned a priority level lower than kernel OS dependent interrupt handlers change the description of the non kernel OS independent interrupt handler to that of the kernel OS dependent interrupt handler 71 Chapter 5 Detailed Applications 5 1 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in C language observe the following precautions 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 3 At the beginning of file be sure to include itron h kernel h which is in the system di rectory as well as kernel id h which is in the current directory The static declared functions cannot be registered as a cyclic handler or alarm handler The cyclic handler and alarm handler are invoked by a subroutine call from a system clock interrupt handler include lt itron h gt include lt kernel h gt include kernel id h void cychand void process Figure 5 5 Example Cyclic Handler Written in C Language 5 The handler to function name correlation
41. 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 crtOmr a30 and section definition file sec inc or asm_sec inc 3 Creating a configuration file Create a configuration file which has defined in it the task entry address stack size etc by using an editor The GUI configurator available for MR308 may be used to create a configuration file 4 Executing the configurator From the configuration file create system data definition files sys rom inc sys ram inc include files mr308 inc kernel id h and a system generation procedure description file makefile 5 System generation Execute the make command or execute build on HEW to generate a system 6 Writing to ROM Using the ROM programming format file created write the finished program file into the ROM Or load it into the debugger to debug Figure 4 1 shows a detailed flow of system generation js It is abbreviation of High performance Embedded Workshop 1 The make command comes the UNIX standard and UNIX compatible 60 Chapter 4 Applications Development Procedure Overview C standard MR308 include file header file kernel h Include file Z kernel_id h v Include file System data definition file
42. 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 reguirements In other words ITRON systems reguire relatively large memory capacities and enhanced processing capabilities The uITRON 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 HITRON 2 0 Specification and ITRON Specification were unified which resulted in establishment of HITRON 3 0 Specification with connecting functions added 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 Of these standard profiles MR308 has implemented in it all service calls except for static APIs and task exception APIs
43. the interrupt handler are written as shown below Always be sure to clear the B flag before issuing the ret int service call Example interrupt fset B felr B ret_int Internally in the MR308 kernel register banks are not switched over 2 Regarding the method for specifying a high speed interrupt To ensure an effective use of high speed interrupts make sure the registers of register bank 1 are used in the high speed interrupt Note also that high speed interrupts cannot be used for the kernel OS dependent inter rupt handler 3 Do not use NMI and watchdog timer interrupts in the kernel OS dependent interrupt 117 Chapter 6 Using Configurator Table 6 3Interrupt Causes and Vector Numbers Interrupt cause Interrupt vector number Section Name DMAO 8 INTERRUPT_VECTOR DMA1 9 INTERRUPT_VECTOR DMA2 10 INTERRUPT_VECTOR DMA3 11 INTERRUPT_VECTOR Timer AO 12 INTERRUPT_VECTOR Timer A1 13 INTERRUPT_VECTOR Timer A2 14 INTERRUPT_VECTOR Timer A3 15 INTERRUPT_VECTOR Timer A4 16 INTERRUPT_VECTOR UARTO transmit 17 INTERRUPT_VECTOR UARTO receive 18 INTERRUPT_VECTOR UART1 transmit 19 INTERRUPT_VECTOR UART1 receive 20 INTERRUPT_VECTOR Timer BO 21 INTERRUPT_VECTOR Timer B1 22 INTERRUPT_VECTOR Timer B2 23 INTERRUPT_VECTOR Timer B3 24 INTERRUPT
44. the task were arranged in the same section 14 Remote control Task Key input Task Chapter 3 Introduction to MR308 Register Memory map Stack section LED illumination Task Y ae mM has mid Real time OS 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 Y Key input Task 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 Real time OS Remote control Task task Service call Task switching 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 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
45. this area The task control block is schematized in Figure 3 17 2 Called the task context 25 Chapter 3 Introduction to MR308 TCB TCB TCB Time out counter or Flag wait pattern Timer gueue Connection pointer Flag wait pattern Figure 3 17 Task control block This area is allocated only when the timeout function is used 26 Chapter 3 Introduction to MR308 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 Task Context and Non task Context Task context Non task context Invocable service call Those that can be invoked from task context Those that can be invoked from non task context Task scheduling Occurs when the queue state It does not occur has changed to other than dis patch disabled and CPU locked states Stack User stack System stack The processes executed in non task context include the following 1 Interrupt Handler A program that starts upon hardware interruption is called the interrupt handler The MR308 is not concerned in interrupt handler activation Therefore the interrupt handler entry address is to be di rectly written into the interrupt vector table There are two interrupt handlers Non
46. using the Task Pause function of OS Debug Function of the debugger 6 Time tick denominator Definition format Numeric value Definition range Fixed to 1 Default value 1 Set the denominator of the time tick 7 Time tick numerator Definition format Numeric value Definition range 1 to 65 535 Default value 1 Set the numerator of the time tick The system clock interrupt interval is determined by the time tick denominator and numerator that are set here The interval is the time tick numerator divided by time tick denominator ms That is the time tick numerator ms The tic_nume value that can be specified for the M32C 82 or 83 operating with 20 MHz is 26 ms be cause of the microcomputer specification 100 8 Chapter 6 Using Configurator Maximum message priority value Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum value of message priority System Clock Definition Procedure lt lt Format gt gt System Clock Definition clock Fs mpu_clock MPU clock timer Timers used for system clock IPL System clock interrupt priority level lt lt Content gt gt 1 2 3 MPU clock Definition format Frequency in MHz Definition range None Default value 20MHz Define the MPU operating clock freguency of the microcomputer in MHz units
47. 31 132 N BZERO bss NE top bss NE 133 N BZERO bss NO top bss NO 134 T35 ji EEE EEE ease Se E n SAE Se So PF Se BHS 136 initialize data section US Ss E o E ae oN m sys 138 N BCOPY data SEI top data SE top data SE 139 N BCOPY data SOI top data SO top data SO 140 N BCOPY data NEI top data NE top data NE 141 N BCOPY data NOI top data NO top data NO 142 143 s s s s s s s s 144 FAR area initialize TAB ph AS SA A I me n a 146 bss zero clear IAT pea PE BSS P SRR aaa E SSeS eS SRP SR SSS eS Fe S ESSE 148 BZERO bss FE top bss FE 149 BZERO bss FO top bss FO 150 LSL E SSS ESS SFP PSE MSSF SFSPFEBRF SDSS ESBE See ae ssa eesse 152 Copy edata E O section from edata EI OI section 86 Chapter 5 Detailed Applications LB L P k n PS IS Pe m 154 BCOPY data FEI top data FE top data FE 155 BCOPY data FOI top data FO top data FO 156 157 LDC Sys Sp SP 158 LDC Sys Sp FB 159 160 161 pets se Petes stele ses tato ces sE nie 162 Set System IPL and Set Interrupt Vector L63 peo 55 See ae HS PSR P FE ASRS ASS Se AS EEE PS eee Se S PES rea Ses Sees 164 MOV B 0 ROL 165 MOV B SYS IPL ROH 166 LDC RO FLG 167 LDC INT VECTOR INTB 168 L690 POPS SS SSS SR E O Ss Se SSeS SS SSeS o E 170 System timer interrupt setting 171 3 172 IF USE TIMER 173 MOV B stm
48. 5 5 Synchronization and Communication Function Semaphore 37 3 5 6 Synchronization and Communication Function Eventflag oonnnnnonnninininnnninncncnnancnncnnananono 39 3 5 7 Synchronization and Communication Function Data Queue eee 41 3 5 8 Synchronization and Communication Function Mailbox oonnonininnninnincninninaninnnninicnnacananinn 49 3 5 9 Memory pool Management Function ccccecesesesesesssssseseseseseseseseseseseseseseseseeeeeeeseeeeeeseeeeeeees 44 Fixed size Memory pool Management Function ccccccecesececececececececececececeeeceeececececececeeeeececeeeeeeseeeeeecesenenenens 44 Variable size Memory Pool Management Functi0N oooocononooononononononononononononononononnnnnn nono nono nono nono no eee nenene nene nn nn 45 3 510 Time Management FUNCIONA dod vad ode 47 SOT Cych Handler Func a ass 49 3 5 12 Alarm Handler Function 00000000000000 000000000 000000 0000 R KKK KARR K KK EEr a AKA R RR R Kn n 50 3 5 13 System Status Management Functi0N ccccnnnnnonononnnnnonononnononononnonnnnnnononononnononnnnn ono nonnnnonannnnos 51 3 5 14 Interrupt Management Function ocoooonooonncnnnnnnnononnnononocononnanononononnnnnnnnononononnnnnonnnanenonnnconannnnos BA 3 5 15 System Configuration Management Function cccccssssccsececeesssseceeceeececeesenssseeeeeesesensaaees 53 3 5 16 Extended Function Short Data Queue uni tii
49. 6 SUB W 1 R1 87 JMP _loop 88 end 89 ENDM 90 91 92 Interrupt section start 93 94 SECTION MR_KERNEL CODE ALIGN 95 96 97 after reset this program will start 98 99 SYS INITIAL 100 LDC Sys Sp ISP set initial ISP 101 102 MOV B 2 0AH 103 MOV B 00 PMOD Set Processor Mode Register 104 MOV B 0 OAH 105 LDC 0010H FLG 106 LDC 4 SB SB 107 LDC 0000H FLG 108 LDC Sys Sp FB 109 LDC SB SB 110 111 112 ISSUE SYSTEM CALL DATA INITIALIZE 113 114 For PD308 115 INIT ISSUE SYSCALL 116 117 s s s s 118 MR_RAM zero clear VIA EE EEE Sere eae ssa eas Soest ese AB E 120 N BZERO MR RAM NE top MR RAM NE 121 N BZERO MR RAM NO top MR RAM NO 122 BZERO MR RAM top MR RAM 123 124 125 NEAR area initialize 126 555255 B n E SE SSSR eS FAR SaaS PE O EEE SSR SSeS 127 bss zero clear T2877 ESS Dara DAD SET Sei seas 129 N BZERO bss SE top bss SE 130 N BZERO bss SO top bss SO 1
50. D wait Waits until all specified bits are set OR wait Waits until any one of the specified bits is set Wait for Eventflag polling pol_flg ipol_flg Examines whether the eventflag is in a certain pattern In this service call tasks are not placed in WAITING state e Reference Eventflag Status ref flg iref flg Checks the existence of the bit pattern and wait task for the target eventflag Figure 3 31 shows an example of task execution control by the eventflag using the wai flg and set flg service calls The eventflag has a feature that it can wake up multiple tasks collectively at a time In Figure 3 31 there are six tasks linked one to another task A to task F When the flag pattern is set to OxF by the set flg service call the tasks that meet the wait conditions are removed seguentially from the top of the queue In this diagram the tasks that meet the wait conditions are task A task C and task E Out of these tasks task A task C and task E are removed from the gueue If this event flag has a TA CLR attribute when the waiting of Task A is canceled the bit pattern of the event flag will be set to 0 and Task C and Task E will not be removed from queue 30 Chapter 3 Introduction to MR308 Flag gueue TaskA TaskB TaskC TaskD TaskE TaskF O Flag pattern 0 Wait pattern 0x0F OxFF 0x0F OxFF OxFF 0x10 Wait mode OR AND AND AND OR OR set_flg TaskB TaskD TaskF Flag pattern 0x0F Figu
51. ES in the system defi nition of a configuration file tslp tsk twai_flg trev_mbx twai_sem tsnd_dtq trev_dtq vtsnd_dtq vtrev_dtq This waning will disappear when you define TIMEOUT NO of the system definition in your con figuration file If you don t use the following service call you had better to define TIMEOUT NO in the configura tion file 133 Chapter 7 Application Creation Guide Chapter 7 Application Creation Guide 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 is made The processing procedures for service calls from handlers are roughly classified into the following three types 1 A service call from a handler that caused an interrupt during task execution 2 A service call from a handler that caused an interrupt during service call processing 3 A service call from a handler that caused an interrupt multiplex interrupt during handler exe cution The service call can t be issued from OS independent handler Therefore The handler described here does not include the OS independent handler 136 Chapter 7 Application Creation Guide 7 1 1 System Calls from a Handler That Caused an Interrupt during Task Execution Scheduling task switching is initiated by the ret int service call See
52. Figure 3 22 Task rearrangement in a waiting queue ccocooocccnonononnnnnonnnnnnnonnnnnnnononnnnonnnnnnnonnnnnnnnnoss 33 Figure 3 23 Wakeup Request Storage ccccccccsscccccscsessssececececsesessssecececscsesenssseeeecececseseseesseeeeeeenes 34 Figure 3 24 Wakeup Request CancellatioD oooccnnnoccncnonocnncnonnnnnnnononnnonononnncnnnnnnnnnnonnnnnnnnnnrnnnnnnnnss 34 Figure 3 25 Forcible wait of a task and reSuMe cc ccecssscccesssececeessececeesseeeecseseeecsesseseeseseeeenesaes 35 Figure 3 26 Forcible wait of a task and forcible resuM occcoooccnnnonocnnnnnononnnnnonnnnncnonnnnncnnnnnncnnnnoss 35 Figure 3 27 dly tsk service call iio at lcbidas rai ta ENNS N E a ENNS RS 36 Figure 3 28 Exclusive Control by Semaphore oooooccccnnnonononanononnononnnanononononnononna nono nononnonannnananonononoos 37 Figure 3 29 Semaphore Counter nidad dalla ads 87 Figure 3 30 Task Execution Control by Semaphore cccccccccssssssecceeeseceeeessnssseceeeesesesssteaaeeeeees 38 Figure 3 31 Task Execution Control by the Eventflag cccocnonononononcnnononnananonononocnonnanononononnononos 40 Figure 3 32 Data queues aci di ta adidas iia 41 Piswire 3 33 Mapo ZR P O P P awed O O 42 Figure 3 34 Message queue sszbe sell raid 43 Figure 3 35 Memory Pool Management cccccccccccccssssssseceseeeesesesssscceceeeeseeesssseseeeecesesenssseaaeeeeees 44 Figure 3 36 pget mpl Processing linti a ta ie aia
53. G state and is linked to the ready queue e Task to be executed after the dispatch disabled state is cleared is in a READY state and is linked to the highest priority ready gueue among the gueued tasks 2 isus tsk irsm tsk during dispatch delay In cases when isus tsk is issued from an interrupt handler that has been invoked in a dispatch dis abled state to the task under execution a task to which dis dsp was issued to place it in a SUS PENDED state During delay dispatching e The task under execution is handled inside the OS as having had its delay dispatching cleared For this reason in isus_tsk that has been issued to the task under execution the task is removed from the ready queue and placed in a SUSPENDED state Error code E OK is returned Then when irsm_tsk is issued to the task under execution the task is linked to the ready queue and error code E_OK is re turned However tasks are not switched over until delay dispatching is cleared e The task to be executed after disabled dispatching is re enabled is linked to the ready queue 3 rot_rdq irot_rdq during dispatch delay When rot_rdq TPRI RUN 0 is issued during dispatch delay the ready queue of the own task s pri ority is rotated Also when irot rdg TPRI RUN 0 is issued the ready queue of the executed task s priority is rotated In this case the task under execution may not always be linked to the ready queue Such as when isus_tsk is issued to the executed task d
54. ID number can be omitted If omitted ID numbers are auto matically assigned in order of numbers beginning with the smallest lt lt Content gt gt 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the memory pool is specified in a program 2 The maximum memory block size to be allocated Definition format Numeric value Definition range 1 to 65520 Default value None Specify within an application program the maximum memory block size to be allocated 112 Chapter 6 Using Configurator 3 Section name Definition format Symbol Definition range None Default value MR HEAP 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 orc sec inc If no section names are defined the memory pool is located in the MR HEAP section 4 Memory pool size Definition format Numeric value Definition range 16 to OxFFFFFFFF Default value None Specify a memory pool size Round off a block size you specify to the optimal block size among the four block sizes and acquires memory having the rounded off size from the memory pool The following equations define the block sizes a max_memsize X 1 X x 8 1 x 8 b ax2 c ax4 d ax8 max_memsize the value specified in the configuration f
55. IF ALARM HANDLER 232 GLB _ init alh 87 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 3 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 Chapter 5 Detailed Applications JSR W _ init alh ENDIF IF CYCLIC HANDLER GLB __init_cyh JSR W o init cyh ENDIF IF NUM MPF Fixed Memory Pool GLB _ init mpf JSR W _ init mpf ENDIF IF NUM MPL Variable Memory Pool GLB _ init mpl JSR W init mpl ENDIF For PD308 LAST INITIAL END INIT Start initial active task __START_TASK GLB __rdyq_ search JMP W _ rdyq search Define Dummy GLB SYS _ DMY INH __SYS_DMY_INH REIT LE CUSTOM_SYS END Syscall exit rouitne to customize GLB _ sys end sys end Customize here REIT ENDIF exit function GLB _exit exit exit Sexit JMP exit IF USE TIMER
56. ND INIT 21 GLB init sys init tsk 22 23 LF M16C70 0 24 regoffset EQU 0220H 25 ELSE 26 regoffset EQU 0 27 ENDIF 28 29 30 SBDATA area definition 31 32 GLB SB __ 33 SB SB 34 35 s s s s e s 36 Initialize Macro declaration PR S PE RAE a i rt SE ey painy eS jet 38 N BZERO MACRO TOP_ SECT_ 39 MOV B 00H ROL 40 MOV L HTOP_ Al 41 MOV W sizeof SECT R3 42 SSTR B 43 ENDM 44 45 N_BCOPY MACRO FROM_ TO_ SECT_ 46 MOV L HFROM_ AO 47 MOV L TO Al 48 MOV W sizeof SECT R3 49 SMOVF B 50 ENDM 51 52 BZERO MACRO TOP_ SECT _ 53 local end loop 54 55 MOV L HTOP_ Al 56 MOV B 00H ROL 57 MOV L H sizeof SECT_ OFFFFFFH R3R1 58 XCHG W R1 R3 59 loop 60 SSTR B 61 CMP W 0 R1 62 JEQ _end 63 MOV B ROL A1 64 ADD L 1 A1 65 MOV W 0FFFFH R3 66 SUB W 1 R1 67 JMP loop 68 end 69 ENDM 70 71 BCOPY MACRO FROM_ TO_ SECT_ 72 local end loop 85 Chapter 5 Detailed Applications 73 74 MOV L FROM_ A0 75 MOV L TO Al 76 MOV L H sizeof SECT_ amp OFFFFFFH R3R1 77 XCHG W R1 R3 78 loop 79 SMOVF B 80 CMP W 0 R1 81 JEQ end 82 MOV B A0 A1 83 ADD L 1 A1 84 ADD L 1 A0 85 MOV W 0FFFFH R3 8
57. R308 Service Call Task Context Non task Context get mpf o X tget_mpf o X pget mpf o X rel mpf o x irel mpf X o ref mpf o x iref mpf X o ipget_mpf X o pget mpl o X rel mpl o x ref mpl o x iref mpl X o set tim o X iset tim X o get tim o X iget tim X o sta cyc o X ista cyc X o stp cyc o X istp cyc X o ref cyc o x iref_cyc X o sta alm o X ista alm X o stp_alm o X istp alm X o ref alm o x iref alm X o rot rdg o x irot rdg X o get tid o X iget_tid X o loc cpu o X iloc cpu x o unl cpu o x 1unl cpu X o dis dsp o x ena dsp o X sns_ctx o o sns loc o o sns dsp o o sns dpn o o 57 Chapter 3 Introduction to MR308 Service Call Task Context Non task Context ref ver lref ver vsnd_dtq vtsnd_dtq vpsnd_dtq vipsnd_dtq vfsnd_dtq vifsnd_dtq vrev_dtq vtrev_dtq vprev_dtq viprev_dtq vref_dtq viref_dtq vrst_mpf vrst_mpl vrst_mbx vrst dtg vrst vdtg o o olo o X O Xx o O o x Oo X JO JOJO XxX O X X X X X O X JO X X X O X O X X X O gt x 58 Chapter4 Applications Development Procedure Overview Chapter 4 Applications Development Procedure Overview 4 1 Overview Application programs for MR308 should generally be developed following the
58. RK k k k k k k RR k k RK k k k k k 2 MR308 smaple program 3 4 COPYRIGHT C 2003 2005 RENESAS TECHNOLOGY CORPORATION 5 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED M 8 Id demo c v 1 2 2005 06 15 05 29 02 inui Exp 9 HR K k KK RR RK RRR RR k k KR k k k k KR k k KR k k k k k RR KK k kk kk RR RR KK KK RK 10 11 include lt itron h gt 12 include lt kernel h gt 13 include kernel id h 14 include lt stdio h gt 15 16 17 void main VP INT stacd 18 19 sta tsk ID task1 0 20 sta tsk ID task2 0 21 sta cyc ID cyhl 22 23 void taskl VP INT stacd 24 25 while 1 26 wai sem ID seml 27 slp tsk 28 printf task1 running n 29 sig sem ID seml 30 31 32 33 void task2 VP INT stacd 34 35 while 1 36 wai sem ID seml 37 printf task2 running n 38 sig sem ID seml 39 40 41 42 ag cyhl VP INT exinf 43 44 iwup tsk ID taskl 45 46 143 Chapter 8 Sample Program Description 8 3 Configuration File al J BRK KKK KK RR RR KR RARA RK ARA AR RARA RRA RAR RRA RK k k RRR RR RR RRR KK k k RK k k 2 3 COPYRIGHT C 2003 2005 RENESAS TECHNOLOGY CORPORATION 4 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED 5 6 MR308 System Configuration File 7 SId smp cfg v 1 5 2005 06 15 05 41 54 inui Exp 8 9 O iN ates A eee 10 11 System Definition 12 system 13 stack size 1024 14 priority 10 15 system IPL 4 16 task pause
59. Table 6 2 lists the operators available 57 The system distinguishes between the upper and lower case letters except for the numbers A F and a f 96 Chapter 6 Using Configurator Table 6 2 Operators Operator Priority Direction of computation High From left to right Unary minus From right to left 1 From left to right Binary minus Low From loft to right Numerical value examples are presented below e 123 123 0x23 e 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 Example symbols are presented below e TASKI e IDLE3 Function Name The function names are indicated by a character string that consists of numerals upper and lower case alphabetical letters dollar and underscore begins with a non numeric character and ends with The following shows an example of a function name written in the C language main e func When written in the assembly language the start label of a module is assumed to be a function name Frequency The frequency is indicated by a character string that consist of numerals and period and ends with MHz The numerical values are significant up to six decimal places Also note that the frequency
60. To our customers Old Company Name in Catalogs and Other Documents On April 1 2010 NEC Electronics Corporation merged with Renesas Technology Corporation and Renesas Electronics Corporation took over all the business of both companies Therefore although the old company name remains in this document it is a valid Renesas Electronics document We appreciate your understanding Renesas Electronics website http www renesas com April 1 2010 Renesas Electronics Corporation Issued by Renesas Electronics Corporation http www renesas com Send any inquiries to http www renesas com inquiry ENESAS 8 10 11 12 Notice All information included in this document is current as of the date this document is issued Such information however is subject to change without any prior notice Before purchasing or using any Renesas Electronics products listed herein please confirm the latest product information with a Renesas Electronics sales office Also please pay regular and careful attention to additional and different information to be disclosed by Renesas Electronics such as that disclosed through our website Renesas Electronics does not assume any liability for infringement of patents copyrights or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document No license express implied or otherwise is granted
61. _VECTOR Timer B4 25 INTERRUPT_VECTOR INT5 external interrupt 26 INTERRUPT_VECTOR INT4 external interrupt 27 INTERRUPT_VECTOR INT3 external interrupt 28 INTERRUPT_VECTOR INT2 external interrupt 29 INTERRUPT_VECTOR INT1 external interrupt 30 INTERRUPT_VECTOR INTO external interrupt 31 INTERRUPT_VECTOR Timer B5 32 INTERRUPT_VECTOR UART2 transmit NACK 33 INTERRUPT_VECTOR UART2 receive ACK 34 INTERRUPT VECTOR UART3 transmit NACK 35 INTERRUPT_VECTOR UART3 receive ACK 36 INTERRUPT_VECTOR UART4 transmit NACK 37 INTERRUPT_VECTOR UART4 receive ACK 38 INTERRUPT_VECTOR BUS conflict UART2 39 INTERRUPT VECTOR BUS conflict UART3 40 INTERRUPT VECTOR BUS conflict UART4 41 INTERRUPT VECTOR A D 42 INTERRUPT VECTOR Key input interrupt 43 INTERRUPT VECTOR User Software interrupt 44 INTERRUPT VECTOR q INTERRUPT_VECTOR INTERRUPT VECTOR User Software interrupt 54 INTERRUPT VECTOR Software interrupt for MR308 55 INTERRUPT_VECTOR User Software interrupt 56 INTERRUPT_VECTOR User Software interrupt 57 INTERRUPT VECTOR Software interrupt for MR308 58 INTERRUPT_VECTOR INTERRUPT VECTOR Software interrupt for MR308 62 INTERRUPT_VECTOR Software interrupt for MR308 63 INTERRUPT_VECTOR Undefined instruction 247 FIX_INTERRUPT_VECTOR Over flow 248 FIX_INTERRUPT_VECTOR BRK instruction 249 FIX INTERRUPT VECTOR Address match 250 FIX INTERRUPT VECTOR FIX INTERRUPT VECTOR Watch dog timer 252 FIX INTERRUPT VECTOR FIX INTERRUPT VECTOR NMI 254 FIX INTERRUPT VECTOR R
62. acinononnninon 70 5 1 3 Writing Non kernel OS independent Interrupt Handler oconnnnnnnoninnnnnnninnancncanininncnnccnns L 5 1 4 Writing Cyclic Handler Alarm Handler occcnnnnicocucnnnnnonononnonnnnnnnononnnnanononononnononnnno non nnanononinnnnns 72 5 2 Program Coding Procedure in Assembly Language cccccccccessessssecceeeseceesessnsececeeecsesessnssseeeeeess 78 5 2 1 Writine Be Vc 0 r T O re 73 5 2 2 Writing Kernel OS dependent Interrupt Handler c cccccccecccssessescsseescscesceecssesecsseaeessesees 75 5 2 3 Writing Non kernel OS independent Interrupt Handler onnonncnininnnnnnnnninnananoncnnannncnncnnnann 76 5 2 4 Writing Cyclic Handler Alarm Handler occcnnnnncuuocnncnnnonononononnnnnonononnnnononononnononnn nono nnnnnonononnnnns p 5 37 The Use 0 INT Instruction A A EA a kein 78 5 4 The Use of registers of bank nanaonan ea a a arde a aa aa e R RAKA RK KO KK KR P ROPA Ke nn nen 78 5 5 Regarding Interrupts cas 4Sdu spove dodat a cbs eu nou ns dno oo oo noo Hide ona TA n 79 5 5 1 Typ sot Interrupt Handlers a dba 79 5 5 2 The Use of Non maskable Interrupt occcccnnnnnoononnnonnnonnnanonnnnnnnononnnnanononononnononnn nenene nene nenene 79 5 5 3 Controlling Interrupts nonr ass o teska dao 80 5 6 Regarding Delay Dispatching 00000 0000000000000 000000 nono Kone ne Ko PRA nero ncnnonnnna nora Kone n n 82 5 7 Regarding Initially Activated Tas
63. ake command is executed as an example 65 Chapter 5 Detailed Applications Chapter 5 Detailed Applications 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 ID_task entry address task stack size 100 priority 3 Ji 2 At the beginning of file be sure to include itron h kernel h which is in system directory as well as kernel id h which is in the current directory That is be sure to enter the fol lowing two lines at the beginning of file include lt itron h gt include lt kernel h gt include kernel id h 3 No return value is provided for the task start function Therefore declare the task start function as a void function A function that is declared to be static cannot be registered as a task It isn t necessary to describe ext tsk at the exit of task start function If you exit the task from the subroutine in task start function please describe ext tsk in the subroutine 6 It is also possible to describe the task startup function using the infinite loop include lt itron h gt include lt kernel h gt include kernel id h void task void process Figure 5 1 Example Infinite Loop T
64. al programs are small so that program development is easy 2 Itis very easy to use previously developed software 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 In the case presented in 7 7 272 AD20 A for instance the remote control microcomputer can be used for other prod ucts without being modified 11 Chapter 3 Introduction to MR308 Remote control LED illumination Task Task real time OS Key input Task Volume control Monitor Mechanical Task Task 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 microco
65. anonnnnnonoconononnanonononcnnonannnononos 96 Table 6 2 Operators ata adas 97 Table 6 3 Interrupt Causes and Vector Numbers ococccccnnonononanonononononnananononcnnononnanonononononos 118 Table 8 1 Functions in the Sample Program cccccccccccscessessceceeececessensaceceeeeeeesesenssaeees 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 e Chapter 2 General Information Outlines the objective of MR308 development and the function and position of the MR308 e Chapter 3 Introduction to MR308 Explains about the ideas involved in MR308 operations and defines some relevant terms e Chapter 4 Applications Development Procedure Overview Outlines the applications program development procedure for the MR308 e Chapter 5 Detailed Applications Details the applications program development procedure for the MR308 e Chapter 6 Using Configurator Describes the method for writing a configuration file and the method for using the configurator in detail e Chapter 7 Application Creation Guide Presents useful information and precautions concerning applications program development with MR308 e Chapter 8 Sample Program Description Describes the MR308 sample applications program which is included in the product in the form of a source file e Chapter 9 Separate ROMs Explains about how to Form Separate ROMs Chapter 2 Gen
66. ar attribute NO 70 wait multi TA WSGL 71 72 flag 1 73 name ID _f1g2 74 initial pattern 0x00000001 119 75 wait gueue 76 clear attribute 77 wait multi 78 79 flag 2 80 name ID flg3 81 initial pattern 82 wait gueue 83 clear attribute 84 wait multi 85 y 86 flag 87 name ID fl1g4 88 initial pattern 89 wait gueue 90 clear attribute 91 wait multi 92 y 93 94 semaphore 95 name ID seml 96 wait gueue 97 initial count 98 max count 10 99 100 semaphore 2 101 name ID_sem2 102 wait queue 103 initial count 104 max count 10 105 106 semaphore 1 107 name ID_sem3 108 wait_queue 109 initial count 110 max count 255 rit y 112 113 dataqueue 114 name IDdtal 115 wait_queue 116 buffer size 117 118 dataqueue 2 119 name ID dtq2 120 wait queue 121 buffer size 122 y 123 datagueue 3 124 name ID dta3 125 wait gueue 126 buffer size 127 128 129 mailbox 130 name ID_mbx1 131 wait gueue 132 message queue 133 max pri 4 134 y 135 mailboxI 136 name ID mbx2 137 wait gueue 138 message queue 139 max pri 64 140 141 mailbox 1 142 name ID mbx3 143 wait gueue 144 message queue 145 max pri 5 146 147 mailbox 4 148 name ID mbx4 149 wait gueue 150 message queue 151 max pri 6 152 153 memorypool
67. ask Described in C Language include lt itron h gt include lt kernel h gt include kernel id h void task void for process Figure 5 2 Example Task Terminating with ext_tsk Described in C Language The task is ended by ext_tsk automatically if pramga TASK is declared in the MR308 Similarly it is ended by ext_tsk when returned halfway of the function by return sentence 68 Chapter 5 Detailed Applications 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 name ID_abc hi To designate this eventflag proceed as follows set_flg ID abc amp setptn 9 To specify a cyclic or alarm handler use the string written in the cyclic or alarm handler definition item name of the configuration file sta cyc ID cyc 10 When a task is reactivated by the sta tsk service call after it has been terminated by the ter tsk service call the task itself starts from its initial state However the external variable and static variable are not automatically initialized when the task is started The external and static variables are initialized only by the startup program crtOmr a30 which actuates b
68. atr ON 207 interval counter 0x20 208 phs counter 0x10 209 210 cyclic_hand 211 entry address cyh3 212 name ID cyh3 213 exinf OxFFFF 214 start ON 215 phsatr OFF 216 interval counter 0x20 217 phs counter 0x0 218 219 cyclic_hand 4 220 entry address cyh4 221 name ID cyh4 222 exinf 0x0 223 start ON 224 phsatr ON 225 interval counter 0x100 226 phs counter 0x80 227 228 229 alarm_hand 230 entry address almi 231 name ID alml 232 exinf OxFFFF 233 234 alarm hana 2 121 Chapter 6 Using Configurator 235 entry address alm2 236 name ID alm2 237 exinf 0x12345678 238 239 240 241 242 End of Configuration 243 122 Chapter 6 Using Configurator 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 Executing the configurator requires the following input files Configuration file XXXX cfg This file contains description of the system s initial setup items It is created in the current directory Default configuration file default cfg This file contains default values that are refer
69. d 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 32 Kbyte Program Size 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 Chapter 3 Introduction to MR308 LED illumination microcomputer Arbiter I I microcomputer i l l l l l l l l l l l l l l l l l l l l l l Key input microcomputer Remote control microcomputer Volume control Monitor Mechanical microcomputer microcomputer 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 Individu
70. ded Function Short Data Queue The short data queue is a function outside the scope of ITRON 4 0 Specification The data queue function handles data as consisting of 32 bits whereas the short data gueue handles data as consisting of 16 bits Both behave the same way except only that the data sizes they handle are different e Send to Short Data Queue vsnd dtg vtsnd_dtq Transmits data Namely data is transmitted to the short data queue If the short data queue is full of data the task goes to a data transmission wait state Send to Short Data Queue vpsnd_dtq vipsnd_dtq Transmits data Namely data is transmitted to the short data queue If the short data queue is full of data the task returns error code without going to a data transmission wait state Forced Send to Short Data Queue vfsnd_dtq vifsnd_dtq Transmits data Namely data is transmitted to the data queue If the data queue is full of data the data at the top of the data queue or the oldest data is removed and the transmitted data is stored at the tail of the data queue Receive from Short Data Queue vrev_dtq vtrev_dtq Receives data Namely data is retrieved from the short data queue If the short data queue has no data in it the task is kept waiting until data is transmitted to the short data queue Receive from Short Data Queue vprcv_dtq viprcv_dtq Receives data Namely data is received from the short data queue If the short data queue has no data i
71. e 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 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 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 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
72. ececseseececeesaeseceeaaaeescsesseeecsesseeeesesseeeesesaeeeenaas 15 Figure 3 8 Actual Register and Stack Area Management cccooooconcnonoconononnnnncnonnnnnnnnnnnnnncnnnnnnncnnnnnss 15 Figure 3 9 Service Call oido ii A a E he KE dav a de 16 Figure 3 10 Service Call Processing Flowchart 4 4 0eee00e00000e0000 00000000 000eee ee ee neen nene 17 Figure 3 11 Task Identification A ah a eas 18 Figure 3 12 Task Status iii A ii ini 19 Figure 3 13 MR308 Task Status Transition oooooccnonocnnonononnnnnnnoncnnnnnnnnnnnnnnnnnnnnnnnnnncnnnnnnncnonnnnnnnnnnnss 20 Figure 3 14 Ready Queue Execution Queue scsccscssssssscssssssesssescecsessesscsssassesecatsaesessesecatsaseess 23 Figure 3 15 Waiting queue of the TA_TPRI attribute ocooooccnnnonoccnononocnnnnonncnnnnonononnnnnnnnnnnnnocnnnnnnoss 24 Figure 3 16 Waiting queue of the TA_TFIFO attribute cccoooocnncnonocnnonononnnononnnnnncnonnnnncnonnnnncnnnnos 24 Figure 3 17 Task control block ocio lid did 26 Figure 3 18 Cyclic Handler Alarm Handler Activation cccccccccsssccceesseccecsesseeeeseseceessseeeeeneaas 28 Figure 3 19 MR308 9UFUCLUFE sos zdis dan eii 30 Figure 3 20 Task Resetting cccccccccccssccessssseceesensececseaeseceessececeesaeeeceesaseeeceesaeeecsesseeeesesaeeeesesseesenaas 32 Figure 3 21 Alteration of task pri0rity cccccccccccccccsssssssceccceceesesssecececccsesenssaeceeceseeeesensaeaeeeeeesenes 33
73. efore MR308 startup 11 The task executed when the MR308 system starts up is setup 12 The variable storage classification is described below The MR308 treats the C language variables as indicated in Table 5 1 Table 5 1 C Language Variable Treatment Variable storage class Treatment Global Variable Variable shared by all tasks Non function static variable Variable shared by the tasks in the same file Auto Variable Register Variable Variable for specific task Static variable in function 15 The configurator generates the file kernel id h that is used to convert the ID number of a task into the string to be specified This means that the define declaration necessary to convert the string specified in the task definition item name into the ID number of the task is made in kernel_id h The same applies to the cyclic and alarm handlers S The task starts from its start function with the initial priority in a wakeup counter cleared state 69 Chapter 5 Detailed Applications 5 1 2 Writing a Kernel OS Dependent Interrupt Handler When describing the kernel OS dependent interrupt handler in C language observe the following precautions Describe the kernel OS dependent interrupt handler as a function 2 Be sure to use the void type to declare the interrupt handler start function return value and argument 3 At the beginning of file be sure to include itron h kernel h which
74. en the short data queue function is to be used lt lt Format gt gt Vdataqueue Definition mailbox 1 ID name name buffer_size Number of data queues wait queue Select data queue waiting queue The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are auto matically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each short data queue ID number define the items described below 1 IDname Definition format Symbol Definition range None Default value None Define the name by which the short data gueue is specified in a program 2 Number of data Definition format Numeric Value Definition range 0 to Ox3FFF Default value 0 Specify the number of data that can be transmitted What should be specified here is the number of data and not a data size 109 Chapter 6 Using Configurator 3 Selecting a data queue waiting queue Definition format Symbol Definition range TA_TFIFO or TA TRPI Default value TA TFIFO Select a method in which tasks wait for short data queue transmission If TA TFIFO is selected tasks are engueued in order of FIFO If TA TPRI is selected tasks are engueued in order of priority begin ning with the one that has the highest priority Mailbox definition This definition must always be set when the mailbox function is to
75. enced when settings in the configuration file are omitted This file is placed in the directory indicated by environment variable LIB308 or the current directory If this file exists in both directories the file in the current directory is prioritized over the other makefile template files makefile dos makefile Makefile This file is used as a template file when generating makefile Refer to Section 6 2 4 include template file mr308 inc sys_ram inc This file serves as the template file of include file mr308 inc and sys_ram inc It resides in the di rectory indicated by environment variable LIB308 MR308 version file version This file contains description of MR308 s version It resides in the directory indicated by environment variable LIB308 The configurator reads in this file and outputs MR308 s version information to the startup message 2 When the configurator is executed the files listed below are output Do not define user data in the files output by the configurator Starting up the configurator after entering data definitions may result in the user defined data being lost System data definition file sys_rom inc sys_ram inc This file contains definition of system settings Include file mr308 inc This is an include file for the assembly language System generation procedure description file makefile This file is used to generate the system automatically 9 This makefile is a system generat
76. eral 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 reguired to develop lar ger size programs within a shorter period of time To meet such stringent reguirements 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
77. ereinafter 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 TaskA Interrupt handler A AS Interrupt handler A Interrupt k Save Registers SP lt System OS NA Save Registers Interrupt System call processing iset_flg Restore Register Restore Register ret_int Task selection ret int SP lt User Restore Registers TaskB Figure 7 3 Processing Procedure for a service call from a Multiplex interrupt Handler 139 Chapter 7 Application Creation Guide 7 2 Stacks 7 2 1 System Stack and User Stack The MR308 provides two types of stacks system stack and user stack e 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 e System Stack This stack is used within the MR308 during service call processing When a service call is issued from a task the MR308 switches the stack from the user stack to the system stack See Figure 7 4 The system stack use the interrupt stack ISP Task MR308 system call processing User Stack Save Registers Stack switching System call processing System Stack Task se
78. ering 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 e 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 e If these products or technologies are subject to the Japanese export control restrictions they must be exported under a license 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 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 system 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 infor
79. eset 255 FIX INTERRUPT VECTOR 118 Chapter 6 Using Configurator 6 1 3 Configuration File Example The following is the configuration file example i Aa asd Mana a Sat Ce Aha oo E a ata A 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 T T T TT T T C TT TT TT TT 8 9 system definition 10 system 11 stack size 256 12 sysTm IPL 4 13 message pri 64 14 timeout NO 15 task_pause NO 16 tick nume 10 17 tick deno 1 18 y 19 20 max definition 21 maxdefine 22 max task 3 23 max flag 4 24 max sem 3 25 max dtg 3 26 max mbx 4 27 max mpf 3 28 max mpl 3 29 max cyh 4 30 max_alh 2 31 32 33 system clock definition 34 clock 35 timer clock 20 000000MHz 36 timer AO 37 IPL 3 38 39 40 task Al entry address taskl 42 name ID taskl 43 stack size 256 44 priority 1 45 initial start OFF 46 exinf 0x0 47 Y 48 task 49 entry address task2 50 name ID task2 51 stack size 256 52 priority 5 53 initial start ON 54 exinf OxFFFF 55 56 task 3 57 entry address task3 58 name ID_task3 59 stack size 256 60 priority 7 61 initial start OFF 62 exinf 0x0 63 y 64 65 flag 66 name ID flgl 67 initial pattern 0x00000000 68 wait gueue TA TFIFO 69 cle
80. eued at the top of the waiting gueue is assigned the freed memory block In this case the task changes its state from WAITING state to READY state If there are no tasks in a wait state the memory block is returned to the memory pool e Reference Fixed size Memory Pool Status ref mpf iref mpf Checks the number and the size of blank blocks available in the target memory pool 44 Chapter 3 Introduction to MR308 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 e g variable memorypool max_memsize 400 lt Maximum size heap_size 5000 Defining a variable size memory pool as shown above causes four fixed size memory block sizes to become 56 bytes 112 bytes 224 bytes and 448 bytes in compliance with max_memsize In the case of user requested memory the MR308 performs calculations based on the specified size and se lects and allocates the optimum one of four fixed size memory block sizes The MR308 cannot allocate a mem ory block that is not one of the four sizes Service calls the MR308 provides include the following e Acquire Va
81. example task execution control provided by the wai sem and sig sem service calls wai sem sig sem Task YY wai_sem Task e wai_sem meo O MA wai sem Task WAIT state l I E Semaphore 3 2 1 0 z 0 Counter Figure 3 30 Task Execution Control by Semaphore 38 Chapter 3 Introduction to MR308 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 It is possible to determine whether multiple waiting tasks can be engueued in one eventflag waiting queue by specifying the eventflag attribute TA WSGL or TA WMUL Furthermore it is possible to clear the eventflag bit pattern to O when the eventflag meets wait conditions by specifying TA CLR for the eventflag attribute There are following eventflag service calls that are provided by the MR308 kernel e Set Eventflag set flg iset flg Sets the eventflag so that a task waiting the eventflag is released from the WAITING state e Clear Eventflag clr_flg iclr_flg Clears the Eventflag Wait for Eventflag wai_flg twai_flg Waits until the eventflag is set to a certain pattern There are two modes as listed below in which the eventflag is waited for AN
82. 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 reguests are accumulated but startup code cannot be speci fied Activate Task sta tsk ista tsk Activates the task changing its status from DORMANT to either READY or RUNNING In this service call unlike in act tsk iact tsk startup reguests are not accumulated but startup code can be speci fied Terminate Invoking Task ext tsk When the issuing task is terminated its state changes to DORMANT state The task is therefore not executed until it is restarted If startup reguests are accumulated task startup processing is performed again In that case the issuing task behaves as if it were reset If written in C language this service call is automatically invoked at return from the task regardless of whether it is explicitly written when terminated Terminate Task ter tsk Other tasks in other than DORMANT state are forcibly terminated and placed into DORMANT state If startup reguests are accumulated task startup processing is performed again In that case the issuing task behaves as if it were reset See Figure 3 20 Startup request count gt 0 TaskB ter_tsk B Terminated Task B reset Figure 3 20 Task Resetting Change Task Priority chg_pri ichg_pri If the priority of a task is changed while the task is in
83. ge from SUSPENDED to WAITING SUSPENDED does not possibly occur DORMANT This state refers to the condition in which a task is registered in the MR308 system but not activated This task state prevails when either of the following two conditions occurs The task is waiting to be activated The task is normally terminated or forcibly terminated 19 If the task under execution is placed into a forcible wait state by the isus_tsk service call from the handler the task goes from an execut ing state directly to a forcible wait state Please note that in only this case exceptionally it is possible that a task will go from an executing state directly to a forcible wait state 20 If a forcible wait request is issued to a task currently in a wait state the task goes to a dual wait state h rsm_tsk or irsm_tsk service calls 22 23 ext_tsk service call ter_tsk service call 22 Chapter 3 Introduction to MR308 3 3 2 Task Priority and Ready Queue In the real time OS several tasks may simultaneously reguest 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 To complete task execution guickly tasks related to processing operations that need to be performed immediately should be given higher priorities
84. ge header and the area actually used by the application to store a message are called the message packet The kernel rewrites the content of the message header as it manages the message gueue The message header cannot be rewritten from the ap plication The structure of the message gueue is shown in Figure 3 34 The message header has its data types defined as shown below T MSG Mailbox message header T MSG PRI Mailbox message header with priority included Messages in any size can be engueued in the message gueue because the header area is reserved on the ap plication side In no event will tasks be kept waiting for transmission Messages can be assigned priority so that messages will be received in order of priority beginning with the highest In this case TA MPRI should be added to the mailbox attribute If messages need to be received in order of FIFO add TA MFIFO to the mailbox attribute Furthermore if tasks in a message wait state are to receive a message the tasks can be prioritized in which order they can receive a message beginning with one that has the highest priority In this case add TA_TPRI to the mailbox attribute If tasks are to receive a mes sage in order of FIFO add TA TFIFO to the mailbox attribute Message Message TaskA Figure 3 33 Mailbox E It is in the mailbox definition message gueue of the configuration file that the TA MPRI or TA MFIFO attribute should be added 35 It is in the ma
85. generate a system Thanks to this feature a system of the minimum size is automatically generated at all times 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 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 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 require
86. hat Caused an Interrupt during Handler Execution 139 DASS uti a cios 140 7 2 1 System Stack and User Stack sudar it ad ai aaa 140 Chapter 8 Sample Program Descripti0N ccccccoooooonnnncnnnnnnnooonnnnnnnnnnnnononnnnnnnnnnnnnnnononnnnnnnnnnnnn ono nnnnnnnnnnnns 141 8 1 Overview of Sample Program cccccccsscssssssecscececsessssnsccscececssesssnseessececcsessnsaeaseesecsessnsaaeascecenes 142 8 2 Program Source Listini ns nenen i n 000000 nono nonnononnno no Ko Ko PKP KK PPR nora RP K0 R PRA aoas 148 8 3 Gonfiguration File s n toad aia no cated ad 144 Chapter 9 Separate ROMS cinto E EEE TE id eset ein 145 9 1 How to Form Separate ROMS ococcccnnnnnononnnnncnononnnnnnnnononcnnononnnnonononcononnnnn nono nonnnnnonnnnnnnonnncononannnna nooo 146 List of Figures Figure 3 1 Relationship between Program Size and Development Period 10 Figure 3 2 Microcomputer based System Example Audio Equipment eeeeeee0eo 11 Figure 3 3 Example System Configuration with Real time OS Audio Equipment gos Figure 3 4 Time division Task Operation cocoooconononoccnonoooncnnnnonononnnonononnnnnnnnnnnnnonnnnnnnn nn 00 nee anne nn 13 Figure 3 5 Task Execution Interruption and Resumption cccccnnooononnnononnnnnnnonnnnonononnononnnonononcnnnos 13 Figure 3 6 Task Switching ico a it eae E 14 Figure 3 7 Task Register Area ccccccccccssssssceesensececsesa
87. he data queue or the oldest data is removed and the transmitted data is stored at the tail of the data queue Receive from Data Queue rcv_dtq trev_dtq Receives data Namely data is retrieved from the data queue If the data queue has no data in it the task is kept waiting until data is transmitted to the data queue e Receive from Data Queue prev dta iprev dtg Receives data Namely data is received from the data gueue If the data gueue has no data in it the task returns error code without going to a data reception wait state e Reference Data Queue Status ref dta iref dtg Checks to see if there are any tasks waiting for data to be entered in the target data gueue and refers to the number of the data in the data gueue 3 First In First Out 41 Chapter 3 Introduction to MR308 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 The kernel manages the message gueue by means of a link list The application should prepare a header area that is to be used for a link list This is called the message header The messa
88. he following precautions when creating a source file The source file must be placed in the current directory Use the extension c for the C language source file and a30 for the assembly language source file 2 Write the file dependency relationship to makefile Using makefile or Makefile in the current directory or makefile dos in the directory indicated by the environment variable LIB308 as a template file the configurator creates makefile in the current di rectory 127 Chapter 6 Using Configurator 6 2 5 Precautions on Executing Configurator The following lists the precautions to be observed when executing the configurator e 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 Do not modify the startup program name and the section definition file name Otherwise an error may be encountered when executing the configurator e The configurator cfg308 can only generate UNIX standard makefile or one conforming to UNIX stan dards Namely it does not generate MS DOS standard makefile 128 Chapter 6 Using Configurator 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
89. he section names of task2 and task3 turn to app prog void task2 void void task3 void Locating sections 54 You need not change the names of sections for tasks to be located int the kernel ROM 147 Chapter 9 Separate ROMs 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 The seguence of other sections are free of restrictions MR308 s ROM data MR ROM section C language I F routine MR_CIF section e Interrupt vector area INTERRUPT VECTOR section Settings of the section files are given below section MR ROM ROMDATA MR308 s ROM data org 0fe0000H The address common to two applications section MR_CIF CODE C language I F routine section app prog CODE Use Program section INTERRUPT VECTOR Interrupt Vector org Ofefd00H The address common to two applications The memory map turns to give below See Figure 9 2 FE0000H 2 ROM MR ROM section ata C language I F routine Task2 i Application ROM app_prog section External ROM Task3 Task4 Interrupt vector area INTERRUPT_VECTOR section FF0000H Startup program MR KERNEL sec
90. hi Kanagawa 211 8668 Japan REJ10J1025 0200Z
91. icated below A gt 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 m Option Creates the UNIX standard or UNIX compatible system generation procedure description file make file If this option is not selected makefile creation does not occur If the startup file crtOmr a30 or start a30 and the section definition file are not in the current directory the configurator copies them to the current directory form the directory indicated by the environment variable LIB308 UNIX standard makefile and one conforming to UNIX standards have a function to delete the work file by a clean target Namely if you want to delete the object file generated by the make command for example enter the following gt make clean 126 Chapter 6 Using Configurator 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 Consequently observe t
92. ication 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 Comment Statement A statement from to the end of a line is assumed to be a comment and not operated on End of statement Statements are terminated by Numerical Value Numerical values can be entered in the following format 1 Hexadecimal Number Add 0x or OX to the beginning of a numerical value or h or H to the end If the value begins with an alphabetical letter between A and F with h or H attached to the end be sure to add 0 to the beginning Note that the system does not distinguish between the upper and lower case alphabetical characters A F used as numerical values 2 Decimal Number Use an integer only as in 23 However it must not begin with 0 3 Octal Numbers Add 0 to the beginning of a numerical value of O or o to end 4 Binary Numbers Add B or b to the end of a numerical value It must not begin with 0 Table 6 1 Numerical Value Entry Examples Oxf12 Oxf12 0a12h Hexadecimal 0a12H 12h 12H Decimal 32 017 Octal 170 170 Binary 101110b 101010B It is also possible to enter operators in numerical values
93. ilbox definition wait queue of the configuration file that the TA TPRI or TA TFIFO attribute should be added 42 Chapter 3 Introduction to MR308 Message queue Message A Message B Message C Figure 3 34 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 e 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 Receive from Mailbox polling prev mbx iprcv_mbx Receives a message The difference from the rcv_mbx service call is that if the mailbox has no mes sages in it the task returns error code without going to a wait state e Reference Mailbox Status ref_mbx iref_mbx Checks to see if there are any tasks waiting for a message to be put into the target mailbox and refers to the message present at the top of the mailbox 43 Chapter 3 Introduction to MR308 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 me
94. ile X data size for block control 8 byte per a block control Variable size memory pool function needs 8 byte RAM area per a block control Memory pool size needs a size more than a b c or d that can be stored max_memsize 8 Cyclic handler definition This definition is necessary to use Cyclic handler function lt lt Format gt gt Cyclic Handlar Definition cyclic hand ID No 1 name ID name Activation cycle TA STA attribute TA PHS attribute Activation phase entry address Start address exitf Extended information interval counter start phsatr phs counter y 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 113 Chapter 6 Using Configurator lt lt Content gt gt Define the following for each cyclic handler ID number 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the memory pool is specified in a program 2 Activation cycle Definition format Numeric value Definition range 1 to 32767 Default value None Define the activation cycle at which time the cyclic handler is activated periodically The activation cy cle here must be defined in the same unit of time as the system clock s unit time that is defined in sys
95. in the WAITING state Key input Task Key input Waiting for Key input processing key input processing RUNNIG state WAITING state RUNNING state Figure 3 12 Task Status The MR308 controls the following six different states including the RUNNING and WAITING states 1 2 5 6 RUNNING state READY state WAITING state SUSPENDED state WAITING SUSPENDED state DORMANT state Every task is in one of the above six different states Figure 3 13 shows task status transition 19 Chapter 3 Introduction to MR308 MPU execlusive right acguisition READY state RUNNING state MPU execlusive right relinguishment WAITING state Entering the WAITING state WAITING state SUSPENDED state clear SUSPEND request Forced request from other task from other task aree from other task WAITING SUSPENDED state WAITING state clear SUSPEND request 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 The task has normally terminated itself The task has placed
96. int of last interruption See Figure 3 5 Program execution Program execution interrupt resumed Key input Tak Y O Aa 7 During this interval it Task appears that the key input microcomputer is haled Figure 3 5 Task Execution Interruption and Resumption 13 Chapter 3 Introduction to MR308 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 Actual Register Real time OS Key input Remote control Task Task Ro Register Register Figure 3 6 Task Switching The example presented in Figure 3 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 Itis figure where all the stack areas of
97. ion procedure description file that can be processed by UNIX standard make commands or those con forming to UNIX standards 123 Chapter 6 Using Configurator Configuration File XXX Cfg Default Configuration File default cfg System Data Difinition File sys_ram inc sys_rom inc makefile Template File makefile dos cfg308 System generation File makefile Makefile makefile Template File Include File sys_ram inc mr308 inc mr308 inc kernel id h MR308 Version File version Figure 6 1 The operation of the Configurator 124 Chapter 6 Using Configurator 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 e Default configuration file default cfg This file can be copied to the current directory for use In this case the file in the current directory is given priority e System RAM area definition database file sys_ram inc e mr308 inc template file mr308 inc e Section definition file c_sec inc or asm_sec inc e Startup file crtOmr a30 or start a30 makefile template file makefile dos MR308 version file version 125 Chapter 6 Using Configurator 6 2 3 Configurator Start Procedure Start the configurator as ind
98. is determined by the configuration file 72 Chapter 5 Detailed Applications 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 Be sure to include mr308 inc at the beginning of file For the symbol indicating the task start address make the external declaration Be sure that an infinite loop is formed for the task or the task is terminated by the ext tsk service call INCLUDE mr308 inc 1 GLB task 2 task process jmp task 3 Figure 5 6 Example Infinite Loop Task Described in Assembly Language INCLUDE mr308 inc GLB task task process ext_tsk Figure 5 7 Example Task Terminating with ext_tsk Described in Assembly Language 4 The initial register values at task startup are indeterminate except the PC SB RO and FLG registers 5 To specify a task use the string written in the task definition item name of the configura tion file wup tsk ID_task 6 To specify an event flag semaphore or mailbox use the respective strings defined in the configuration file For example if a semaphore is defined in the configuration file as shown below semaphore 1 name abc y To specify this semaphore write your specification as follows sig sem ID_abc 7 To specify a cyclic or alarm handle
99. ispatch disabled and the CPU locked states are clearly discriminated Therefore if the unl cpu service call is issued in a dispatch disabled state the dispatch disabled state remains intact and no task scheduling is performed State transitions are summarized in Table 3 3 Table 3 3 CPU Locked and Dispatch Disabled State Transitions Relating to dis_dsp and loc_cpu State Content of state dis_dsp ena dsp loc_cpu unl_cpu number CPU locked Dispatch disabled executed executed executed executed state state 1 O X X X gt 1 gt 3 2 O O X X gt 2 gt 4 3 X X gt 4 gt 3 gt 1 gt 3 4 X O gt 4 gt 3 gt 2 gt 4 8 MR308 does not return an error even when an uninvocable service call is issued from a CPU locked state in which case however its operation cannot be guaranteed 29 Chapter 3 Introduction to MR308 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 More specifically only the functions used are chosen from those which comprise these modules and linked by means of the Linkage Editor LN308 However the scheduler module part of the task manage ment module and part of the time manage
100. it 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 e MR RAM DBG section This section stores the MR308 s Debug functions RAM data This section must be mapped the internal area MR_RAM_NE section MR_RAM_NO section This section is where the RAM data MR308 s system management data is stored that is referenced in absolute addressing This section must be mapped between 0 and OFFFFH near area MR RAM section This section is where the RAM data MR308 s system management data is stored that is referenced in absolute addressing e stack section This is the section for the default user stack of each task and for the system stack MR HEAP section This is the section in which the variable size memory pool fixed size memory pool and data gueue area are stored MR KERNEL section This section stores MR308 kernel program MR CF section This section stores the MR308 C language interface library MR ROM section This section stores data such as task start addresses that area referenced by the MR308 kernel program section This section stores user programs This section is not used by the MR308 kernel at all Therefore you can use this section as desired program S section This section stores the functions invoked by aspecial page call This section is not used by the MR308 kernel at all e fvec
101. it _queue Selecting a semaphore waiting queue initial count Initial value of semaphore counter max_count Maximum value of the semaphore counter The ID number must be in the range of 1 to 255 The ID number can be omitted W If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each semaphore ID number 1 ID Name Definition format Symbol Definition range None Default value None Define the name with which a semaphore is specified in a program 107 Chapter 6 Using Configurator 2 Selecting a semaphore waiting queue Definition format Symbol Definition range TA_TFIFO or TA_TPRI Default value TA_TFIFO 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 3 Initial value of semaphore counter Definition format Numeric value Definition range 0 to 65535 Default value 1 Define the initial value of the semaphore counter 4 Maximum value of the semaphore counter Definition format Numeric value Definition range 1 to 65535 Default value 1 Define the maximum value of the semaphore counter Data queue definition This definition must alwa
102. itself in the WAITING state 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 1 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 When the ready queue of the issuing task priority is rotated by the rot_rdq or irot rdg 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 h Depends on the ext tsk service call 1 Depends on the dly tsk slp tsk tslp tsk wai_flg twai flg wai sem twai sem rcv_mbx trev_mbx snd_dtq tsnd_dtq rcv_dtq trev_dtq vtsnd dig vsnd_dtq vtrev_dtq tget_mpf get mpf or vrcv_dtq service call k Depends on the chg pri service call
103. k 000000 0e ee ee 00000000 e0e ee ee 00000 eo ee eee Reno no eo Renee Rent n 88 5 8 Modifying MR308 Startup Program ccccccccssscccccecesesessnsecececececcesesseceeecececsensesssaeeeeecsceetenssaeeeeess 84 5 8 1 C Language Startup Program crtOmr a30 cccceccssccssesccescssssccscescescssesscssesecssesecsceseesesseesens 85 5 9 Memory AO ATO a a cochoals ataca 90 5 9 1 Section Allocation of start aglossia sri DEn ASLE Sa Ea SARA S Ea Eas 91 5 9 2 Section Allocation of crtOmr a30 ccceccsccccssssccecesssececessseceeessseeeecessseeeesesseeeesesseeeeseseeeeseseeeeeees 92 5 10 Using in MIGCITO Seri s miii A a Se iat a ha bd 94 Chapter6 Using Configurator ssis s snas isi raes PSr arr ETE aE EEE EEE Eei DEE ESE SaaS 95 6 1 Configuration File Creation Procedure ccccccssccssccceceesessnsscecececsesesssssceceeecsesensaeceeesecsesensaeaeees 96 6 1 1 Configuration File Data Entry Format occccnnnnooononanonnnnnnnanonnnnnnnonononnanononononnononnanonanoncnnonanos 96 Operator 3 A EA A He LCE AEE EEE EE eto OT Direction of computation ccccccccccccesssssscecccecsesnsaececccecsessececececeeseseeeeeceececeeesseseeeeeceeseaaesecsesesaseeeececseneasaeeeeeees 97 6 1 2 Configuration File Definition temS ocooooococonnnnnonnnononnnononnnnnanononononnnononnanononononnononnn nn nn ncncononanos 99 Saa Da e e e 99 System Clock Definition Procedure
104. k from waiting rel_wai irel_wai Forcibly frees a task from WAITING state A task is freed from WAITING state by this service call when it is in one of the following wait states 35 Chapter 3 Introduction to MR308 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 Data reception timeout included wait state Fixed size memory block timeout included acquisition wait state Short data transmission timeout included wait state o M M gt M M M Short data reception timeout included wait state e Delay task dly tsk Keeps a task waiting for a finite length of time Figure 3 27 shows an example in which execution of a task is kept waiting for 10 ms by the dly_tsk service call The timeout value should be specified in ms units and not in time tick units dly_tsk 10 Task OS Figure 3 27 dly_tsk service call 36 Chapter 3 Introduction to MR308 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 reguire the use of them When for instance four tasks simultaneously try to acquire a total of only three communication lines a
105. kernel interrupts OS independent interrupts and kernel inter rupts OS dependent interrupts For details about each type of interrupt refer to Section 5 5 The system clock interrupt handler isig_tim is one of these interrupt handlers 2 Cyclic Handler The cyclic handler is a program that is started cyclically every preset time The set cyclic handler may be started or stopped by the sta_cyc ista_cyc or stp_cyc istp_cyc service call The cyclic handler startup time of day is unaffected by a change in the time of day by set_tim iset_tim 3 Alarm Handler The alarm handler is a handler that is started after the lapse of a specified relative time of day The alarm handler startup time of day is determined by a time of day relative to the time of day set by sta_alm ista_alm and is unaffected by a change in the time of day by set_tim iset_tim The cyclic and alarm handlers are invoked by a subroutine call from the system clock interrupt timer interrupt handler Therefore cyclic and alarm handlers operate as part of the system clock interrupt handler Note that when the cyclic or alarm handler is invoked it is executed in the interrupt priority level of the system clock inter rupt 27 Chapter 3 Introduction to MR308 Task System clock interrupt handler Cyclic handler Alarm handler Subroutine call Timer interrupt Figure 3 18 Cyclic Handler Alarm Handler Activation 3 4 2 Dispatch Enabled Disabled Sta
106. le LIB308 to the current direc tory lf necessary correct or add the sections below When using HEW the user can choose to automatically generate a sample during project generation or use an already created one Setting processor mode register Set a processor mode matched to your system to the processor mode register e Adding user required initialization program To add an initialization program needed for the user add it at a place immediately preceding the ini tialization of standard input output functions in the C language startup program crtOmr a30 If the standard input output functions are unused make the relevant part a comment 84 Chapter 5 Detailed Applications 5 8 1 C Language Startup Program crtOmr a30 Figure 5 14 C Language Startup Program crtOmr a30 shows the C language startup program crtOmr a30 t po k KO K K K K K KERR A RRE RARE kkk kkk kkk kkk kk kkk kkk kkk kkk kkk kkk 2 3 MR308 start up program for C language 4 COPYRIGHT C 2003 RENESAS TECHNOLOGY CORPORATION 5 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED 6 MR308 V 1 10 Release 1 7 8 7 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkxkxk 9 Id crtOmr a30 v 1 1 2005 05 20 06 28 47 inui Exp 10 A1 2005 02 28 for ES Jets 7 12 LIST OFF 13 INCLUDE c sec inc 14 INCLUDE mr308 inc 15 INCLUDE sys_rom inc 16 INCLUDE sys_ram inc 17 LIST ON 18 19 GLB __SYS_ INITIAL 20 GLB E
107. lection Stack switching Restore Registers User Stack Figure 7 4 System Stack and User Stack Switchover from user stack to system stack occurs when an interrupt of vector numbers 0 to 31 or 247 to 255 is generated Consequently all stacks used by the interrupt handler are the system stack 140 Chapter 8 Sample Program Description Chapter 8 Sample Program Description 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 Functions in the Sample Program Function Type ID No Priority Description Name main Task 1 1 Starts task1 and task2 task1 Task 2 2 Outputs task1 running task2 Task 3 3 Outputs task2 running cyh1 Handler 1 Wakes up task1 The content of processing is described below o The main task starts task1 task2 and cyh1 and then terminates itself e task1 operates in order of the following Gets a semaphore 1 2 Goes to a wakeup wait state 3 Outputs task1 running 4 Frees the semaphore e task2 operates in order of the following 1 Gets a semaphore 2 Outputs task2 running 3 Frees the semaphore cyh1 starts every 100 ms to wake up task1 142 Chapter 8 Sample Program Description 8 2 Program Source Listing T S EE K KK KK RK RR RR RRA k ke k RR k k KR k RARA RARA k RR k k
108. lic 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 In the latter case the cyclic handler is started relative to the point in time at which it started operating Figure 3 39 and Figure 3 40 show typical opera tions of the cyclic handler If the startup cycle is shorter than the time tick interval the cyclic handler is started only once every time tick supplied processing equivalent to isig_tim For example if the time tick interval is 10 ms and the startup cycle is 3 ms and the cyclic handler has started operating when a time tick is supplied then the cyclic handler is started every time tick Cyclic handler created Start operating Stop operating I A E R E F I Activation Activation Activation Activation Activation 4 phase cycle cycle cycle cycle i v v v Handler does Handler does Handler starts Handler starts Handler does not start not start not start Figure 3 39 Cyclic handler operation in cases where the activation phase is saved Start operating Stop operating Cyclic handler created I I Activation Activation i Activation Activation Activation i phase i cycle i cycle cycle cycle i v v v Handler does Handler does Handler starts Handler starts Handler does not start not start not start Figure 3 40 Cyclic handler operation in cases where the
109. m 51 Chapter 3 Introduction to MR308 3 5 14 Interrupt Management Function The interrupt management function provides a function to process reguested external interrupts in real time The interrupt management service calls provided by the MR308 kernel include the following e 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 When using the C language this function is automatically called at completion of the handler func tion In this case therefore there is no need to invoke this service call Figure 3 43 shows an interrupt processing flow Processing a series of operations from task selection to register restoration is called a scheduler TaskA NN Interrupt Save Registers Handler Processing pragma INTHANDLER Declare C language Task Selection Restore Registers TaskB Figure 3 43 Interrupt process flow 3 9 In the case that the interruput handler is specified by pragma INTHANDLER 52 Chapter 3 Introduction to MR308 3 5 15 System Configuration Management Function This function inspects the version information of MR308 e 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 uITRON specification 3 5 16 Exten
110. m XXXX is incorrect Check the valid range of definition cfg308 Error too big XXXX s ID number gt lt xx gt xxxx cfg A value is set to the ID number in XXXX definition that exceeds the total number of objects de fined The ID number must be smaller than the total number of objects cfg308 Error too big task x s priority gt lt xx gt near line xxx xxxx cfg The initial priority in task definition of ID number x exceeds the priority in system definition cfg308 Error too big IPL gt lt xx gt near line xxx xxxx cfg The system clock interrupt priority level for system clock definition item exceeds the value of IPL within 129 Chapter 6 Using Configurator service call of system definition item cfg308 Error system timer s vector lt x gt 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 item must be set in your configuration file cfg308 Error system s default is not defined These items must be set int the default configuration file cfg308 Error double definition lt XXXX gt near line xxx xxx cfg XXXX is already defined Check and delete the extra definition cfg308 Error double definition XXXX x near line xxx default cfg cfg308 Error double definition XXXX x near line xxx xxxx cfg The ID number in item XXXX is already registered
111. mation 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 e Release Note Presents a software overview and describes the corrections to the Users Manual and Reference Manual e 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 ulTRON4 0 Specification is the open real time kernel specification upon which the TRON association decided The specification document of nITRON4 0 specification can come to hand from a TRON association homepage http www assoc tron org The copyright of uITRON4 0 specification belongs
112. me in which the stack is located initial start TA ACT attribute initial startup state exinf Extended information The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned seguentially beginning with the smallest lt lt Content gt gt Define the following for each task ID number 1 2 Task ID name Definition format Symbol Definition range None Default value None Define the ID name of a task Note that the function name defined here is output to the kernel id h file as shown below define Task ID Name task ID Start address of task Definition format Symbol or function name Definition range None Default value None Define the entry address of a task When written in the C language add at the end or _at the begin ning of the function name you have defined The function name defined here causes the following declaration statement to be output in the ker nel id h file pragma TASK Function Name 104 Chapter 6 Using Configurator 3 User stack size of task Definition format Numeric value Definition range 12 or more Default value 256 Define the user stack size for each task The user stack means a stack area used by each individual task MR308 reguires that a user stack area be allocated for each task which amount to at least 12 bytes 4 Initial priori
113. ment module are linked at all times because they are essential fea ture functions The applications program is a program created by the user It consists of tasks interrupt handler alarm handler and cyclic handler i User Module Application Program Task Time Management Mailbox Semaphore Management MR308 kernel Task dependent Memorypool System stae synchronization Eventflag Management Management System configuration Interrupt Management Scheduler Data queue Management Hardware M32C Microcomputer Figure 3 19 MR308 Structure 2 For details See 3 5 10 30 x 3 5 2 Chapter 3 Introduction to MR308 Module Overview The MR308 kernel modules are outlined below Scheduler Forms a task processing gueue based on task priority and controls operation so that the high priority task at the beginning in that gueue task with small priority value is executed Task Management Module Exercises the management of various task states such as the RUNNING READY WAIT and SUS PENDED state Task Synchronization Module Accomplishes inter task synchronization by changing the task status from a different task Interrupt Management Module Makes a return from the interrupt handler Time Management Module Sets up the system timer used by the MR308 kernel and starts the user created alarm handler and cyclic handler System Status Management Module Gets the system status of MR308 S
114. mmunications eguipment test and measurement eguipment audio and visual eguipment home electronic appliances machine tools personal electronic eguipment and industrial robots High Quality Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems safety eguipment and medical eguipment not specifically designed for life support Specific Aircraft aerospace eguipment submersible repeaters nuclear reactor control systems medical eguipment or systems for life support e g artificial life support devices or systems surgical implantations or healthcare intervention e g excision etc and any other applications or purposes that pose a direct threat to human life You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics especially with respect to the maximum rating operating supply voltage range movement power voltage range heat radiation characteristics installation and other product characteristics Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges Although Renesas Electronics endeavors to improve the quality and reliability of its products semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use condi
115. morypool The MR308 supports two types of memorypool management functions one for fixed size and the other for variable size Fixed size Memory pool Management Function You specify memory block size using configuration file The MR308 kernel offers the following Fixed size memory pool management service calls Acquire Fixed size Memory Block get_mpf tget_mpf Acquires a memory block from the fixed size memory pool that has the specified ID If there are no blank memory blocks in the specified fixed size memory pool the task that issued this service call goes to WAITING state and is enqueued in a waiting queue Acquire Fixed size Memory Block polling pget mpf ipget_mpf Acquires a memory block from the fixed size memory pool that has the specified ID The difference from the get_mpf and tget_mpf service calls is that if there are no blank memory blocks in the memory pool the task returns error code without going to WAITING state Memory Block 1 Memory Block 2 Memory Block 3 Fixed Length Memorypool Used by TaskA Memory block acquisition request Used by TaskB Memory block acquisition Memory block acquisition request No blank memory blocks available Goes to a wait state Figure 3 35 Memory Pool Management Release Fixed size Memory Block rel mpf irel mpf Frees the acquired memory block If there are any tasks in a wait state for the specified fixed size memory pool the task engu
116. mputer 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 iii i 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 e Task switching occurs upon request from a task e 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 po
117. mr308 inc sys ram inc sys rom inc Jamp table file mrtable a30 v C standard Application Library object Absolute module v ROM write format Figure 4 1 MR308 System Generation Detail Flowchart 61 Chapter 4 Applications Development Procedure Overview 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 Ibp c This program consists of the following three tasks and one interrupt handler Main Task Image expansion task Printer engine task e Centronics interface interrupt handler This program uses the following MR308 library functions e sta tsk Starts a task Give the appropriate ID number as the argument to select the task to be activated When the kernel_id h file which is generated by the configurator is included it is possible to specify the task by name character string e waiflg Waits until the eventflag is set up In the example this function is used to wait until one page of data is entered into the buffer via the Centronics interface wup_tsk Wakes up a specified task from the WAITING state This function is used to start the prin
118. n format Symbol Definition range ON or OFF Default value OFF Define the initial startup state of a task If this attribute is specified ON the task goes to a READY state at the initial system startup time 105 Chapter 6 Using Configurator The task startup code of the initial startup task is 0 8 Extended information Definition format Numeric value Definition range 0 to OxFFFFFFFF Default value 0 Define the extended information of a task This information is passed to the task as argument when it is restarted by a gueued startup reguest for example Eventflag definition This definition is necessary to use Eventflag function lt lt Format gt gt Eventflag Definition flag ID No 1 name Name wait_queue Selecting an event flag waiting queue initial pattern Initial value of the event flag wait_multi Multi wait attribute Clear attribute clear attribute The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned seguentially beginning with the smallest lt lt Content gt gt Define the following for each eventflag ID number 1 ID Name Definition format Symbol Definition range None Default value None Define the name with which an eventflag is specified in a program 2 Selecting an event flag waiting queue
119. n it the task returns error code without going to a data reception wait state e Reference Short Data Queue Status vref_dtq viref_dtq Checks to see if there are any tasks waiting for data to be entered in the target short data queue and refers to the number of the data in the data queue 53 Chapter 3 Introduction to MR308 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 e 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 e Clear Mailbox Area vrst_mbx Initializes the mailbox Clear Fixed size Memory Pool Area vrst_mpf Initializes the fixed size memory pool If there are any tasks in WAITING state they are freed from the WAITING state and the error code EV_RST is returned e Clear Variable size Memory Pool Area vrst mpl Initializes the variable length memory pool e Clear Short Data Queue Area vrst_vdtq Initializes the short data queue If there are any tasks waiting for transmission they are freed from WAITING state and the error code EV_RST is returned 54 Chapter 3 Introduction to MR308 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
120. n to the followings Don t change the regisers of bank in processing a task e If an interrupt handler with regisers of bank 1 have multiple interrupts of an interrupt handler with regis ers of bank 1 the program can not execute normally 78 Chapter 5 Detailed Applications 5 5 Regarding Interrupts 5 5 1 Types of Interrupt Handlers MR308 s interrupt handlers consist of kernel OS dependent interrupt handlers and non kernel 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 Interrupt handlers issuing a service call Interrupt handlers including multiple interrupt handlers issuing a service call The kernel OS dependent interrupt handler s IPL value must be below the kernel mask level OS in terrupt disable level system IPL IPL 0 to system IPL Non kernel OS independent interrupt handler The non kernel OS independent interrupt handler is defined as one that satisfies both of the following two conditions Interrupt handlers not issuing a service call Interrupt handlers that do not have multiple interrupts of interrupt handlers issuing a service call system clock interrupt handler The non kernel OS independent interrupt handler s IPL value must be between system IPL 1 to 7 Namely
121. nded 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 lt lt Format gt gt Alarm Handlar Definition alarm hand ID No 1 name ID name entry address Start address exitf Extended information W The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned seguentially beginning with the smallest lt lt Content gt gt Define the following for each alarm handler ID number 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the alarm handler is specified in a program 2 Start address Definition format Symbol or Function Name Definition range None Define the start address of the alarm handler The function name defined here causes the following declaration statement to be output in the kernel id h file 3 Extended information Definition format Numeric value Definition range 1 to OxFFFFFFFF Default value 0 Define the extended information of the alarm handler This information is passed as argument to the alarm handler when it starts 115 Chapter 6 Using Configurator Interrupt vector definition This definition is necessary to use Interrupt
122. ndler 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 Note however that the system clock is not an essential func tion of MR308 Therefore if the service calls described below and the time management function of the MR308 are unused a timer does not need to be occupied for use by MR308 e Place a task in a finite time wait state by specifying a timeout value A timeout can be specified in a service call that places the issuing task into WAITING state This service call includes tslp tsk twai_flg twai sem tsnd_dtq trcv_dtq trev mbx tget_mpf vtsnd_dtq and vtrcv_dtq If the wait cancel condition is not met before the specified timeout time elapses the er ror code E TMOUT is returned and the task is freed from the wait state If the wait cancel condition is met the error code E_OK is returned The timeout time should be specified in ms units tslp tsk 50 E TMOUT READY state a WAITING state Timeout value tslp_tsk 50 E OK RUN state sm WAITING state pa n iwup tsk Figure 3 38 Timeout Processing MR308 guarantees that as stipulated in UITRON specification timeout processing is not performed until a time egual to or greater than the specified timeout value elapses More specifically timeout processi
123. ndler and the remaining time before it starts are inspected 50 Chapter 3 Introduction to MR308 3 5 13 System Status Management Function Rotate Task Precedence rot rdg irot rdg 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 al 3 taskB taskC a n taskD taskE taskF M gt E Move the end of the gueue Figure 3 42 Ready Oueue Management by rot rdg System Call e Reference task ID in the RUNNING state get tid iget tid References the ID number of the task in the RUNNING state If issued from the handler TSK NONE 0 is obtained instead of the ID number e Lock the CPU loc cpu iloc cpu Places the system into a CPU locked state Unlock the CPU unl cpu iunl cpu Frees the system from a CPU locked state e Disable dispatching dis dsp Places the system into a dispatching disabled state e Enable dispatching ena_dsp Frees the system from a dispatching disabled state e Reference context sns_ctx Gets the context status of the system Reference CPU state sns_loc Gets the CPU lock status of the system Reference dispatching state sns_dsp Gets the dispatching disable status of the system e Reference dispatching pending state sns_dpn Gets the dispatching pending status of the syste
124. nesas Electronics does not warrant that such information is error free Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein Renesas Electronics products are classified according to the following three quality grades Standard High Quality and Specific The recommended applications for each Renesas Electronics product depends on the products quality grade as indicated below You must check the guality grade of each Renesas Electronics product before using it in a particular application You may not use any Renesas Electronics product for any application categorized as Specific without the prior written consent of Renesas Electronics Further you may not use any Renesas Electronics product for any application for which it is not intended without the prior written consent of Renesas Electronics Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for an application categorized as Specific or for which the product is not intended where you have failed to obtain the prior written consent of Renesas Electronics The guality grade of each Renesas Electronics product is Standard unless otherwise expressly specified in a Renesas Electronics data sheets or data books etc Standard Computers office eguipment co
125. ng is performed with the following timing 1 If the timeout value is O for only dly tsk The task times out at the first time tick after the service call is issued 2 If the timeout value is a multiple of time tick interval The timer times out at the timeout value time tick interval first time tick For example if the time tick interval is 10 ms and the specified timeout value is 40 ms then the timer times out at the fifth occurrence of the time tick Similarly if the time tick interval is 5 ms and the specified timeout value is 15 ms then the timer times out at the fourth occurrence of the time tick 3 If the timeout value is not a multiple of time tick interval The timer times out at the timeout value time tick interval second time tick For example if the time tick interval is 10 ms and the specified timeout value is 35 ms then the timer times out get tim service call 37 set tim service call SUSPENDED state is not included 47 Chapter 3 Introduction to MR308 at the fifth occurrence of the time tick e Set System Time set tim e 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 Chapter 3 Introduction to MR308 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 cyc
126. nnnnononononnonannanonanoncnnon 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 Process oi ute sess eases aa sc OST CR db lud GH rokle aE EI IE 138 Figure 7 3 Processing Procedure for a service call from a Multiplex interrupt Handler 139 Figure 7 4 System Stack and User Stack 0000000000000 0000000000000 0000000 e ee ea Renee heat ent nn 140 Figure 971 ROM separate A as 147 Figure 9 2 Memory Mmap cccccsessecscecccesssnsececesccsenensnsenseessececssnsnseaeeesccsessnsaeaecesecsenersessaaeceecesees 148 List of Tables Table 3 1 Task Context and Non task Context 0 ooeeeeee0 0000000 000 ene nene nen 27 Table 3 2 Invocable Service Calls in a CPU Locked State eee een 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 ccccccccccccesesssssececccecescsessnssceeeceesesssssseseeeeeees 69 Table 5 2 Interrupt Number Assignment 0 00 00000e0eee 000000 00000 ee nenene eee none 78 Table 6 1 Numerical Value Entry Examples cccconcoouononcnnnnnnn
127. nterrupt 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 3 Be sure to end the handler by REIT instruction No service calls can be issued from a non kernel an OS independent interrupt handler NOTE If this restriction is not observed the software may malfunction 5 If you want multiple interrupts to be enabled in a non kernel an OS independent interrupt handler always make sure that the non kernel OS independent interrupt handler is as signed a priority level higher than other non kernel OS dependent interrupt handlers GLB inthand 77 gt 1 inthand Registers used are saved to a stack 2 interrupt process Registers used are restored 2 REIT 2 en 3 Figure 5 9 Example of Non kernel OS independent Interrupt Handler of Specific Level If you want the non kernel OS independent interrupt handler to be assigned a priority level lower than kernel OS dependent interrupt handlers change the description of the non kernel OS independent interrupt handler to that of the kernel OS dependent interrupt handler 76 Chapter 5 Detailed Applications 5 2 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in Assembly Language observe the following precautions At the beginning of file
128. on the supposition that the system configuration of two application pro grams is as shown below Application 1 Application 2 The number of Tasks 4 5 The number of Eventflags 1 3 The number of Semaphores 2 The number of Mailboxes 5 The number of Fixed size memory pools oO l Aa A The number of Cyclic handlers 2 Preparing configuration files You prepare configuration files based on the result brought by setting up the system configuration In this instance you need to make the following two items you set in the maxdefine definition division common to two configuration files You specify the greater of the two numbers of definitions as to the respective applications for a value to be set in the maxdefine definition division maxdefinef max task max flag max sem UWUWUBUU i Other definitions though different from each other between two configuration files raise no problem 3 Changing the processor mode register You change the processor mode register for a startup program in compliance with the system 4 Preparing application programs You prepare two application programs 5 Locating respective sections Programs to be located in the kernel ROM and in the application ROM are given below e Programs to be located in the kernel ROM Startup program MR KERNEL section MR308 s kernel MR KERNEL section Programs common to two applications program section Fixed interrupt vector
129. ons Development Procedure Overview 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 Ibp cfg System Definition system stack size 1024 priority 57 system IPL 4 tick_nume 10 System Clock Definition clock mpu_clock 20MHz timer A0 IPL 4 Task Definition task 1 name ID main entry address main stack size 29502 priority TE initial_start ON task 2 name ID_image entry address image stack size 51 2 priority 2 task 3 name ID printer entry address printer stack size 512 priority 4 task 4 name ID idle entry address idle stack size 256 priority 55 Eventflag Definition flag 1 name pagein Interrupt Vector Definition interrupt vector 0x23 os int YES entry address sent in Figure 4 3 Configuration File Example 64 Chapter 4 Applications Development Procedure Overview 4 2 3 Configurator Execution When using HEW select Build all which enables the user to execute the procedures described in 4 2 3 Executing the Configurator and 4 2 4 System Generation
130. ovided 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 OS Operating System 4 Chapter 2 General Information 7 Timer control is made easier 8 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 tim
131. r use the string written in the cyclic or alarm handler definition item name of the configuration file For example if you want to specify a cyclic handler cyc write your specification as follows sta cyc HID cyc 5 1 Use the GLB pseudo directive 73 Chapter 5 Detailed Applications 8 Set a task that is activated at MR308 system startup in the configuration file 5 The relationship between task ID numbers and tasks program is defined in the configuration file 74 Chapter 5 Detailed Applications 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 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 3 Make sure that the registers used in a handler are saved at the entry and are restored after use 4 Return to the task by ret_int service call INCLUDE mr308 inc 1 GLB in eS 2 inth Registers used are saved to a stack 3 iwup_tsk ID_task1 process Registers used are restored 3 ret int 2 nn 4 Figure 5 8 Example of kernel OS depend interrupt handler 5 Use the GLB peudo directive 75 Chapter 5 Detailed Applications 5 2 3 Writing Non kernel OS independent I
132. r if you have any other inquiries Note 1 Renesas Electronics as used in this document means Renesas Electronics Corporation and also includes its majority owned subsidiaries Note 2 Renesas Electronics product s means any product developed or manufactured by or for Renesas Electronics ENESAS C o m 7 lt D D M3 T MR308 4 V 4 00 User s Manual Real time OS for M16C 70 80 M32C 80 Series Renesas Electronics com Rev 2 00 2005 11 www renesas co 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 HITRON is an abbreviation of Micro Industrial TRON TRON ITRON and pITRON 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 Renesas Technology Corporation and Renesas Solutions Corporation put the maximum effort into making semiconductor products bet
133. r_mod_val stmr_mod_reg regoffset set timer mode 174 MOV W stmr_cnt stmr_ctr_reg regoffset set interval count 175 MOV B stmr_int_IPL stmr_int_reg set timer IPL 176 OR B stmr_bit 1 stmr_start regoffset system timer start 177 ENDIF 178 LY k PP EEA ESA DS LAA RA 180 System timer initialize T amp L p D bm mody m Sas 182 IF USE SYSTEM TIME 183 MOV W D Sys TIME L Sys time 4 184 MOV W OD Sys TIME M Sys time 2 185 MOV W D Sys TIME H Sys time 186 ENDIF 187 188 189 User Initial Routine if there are 190 191 Initialize standard I O 192 GLB _ init 193 JSR A init 194 195s PEPPERS AE EE ASS SRS BRA E APE 196 Initalization of System Data Area LOT Ar soos moai He eS SoS ce oi o 198 JSR W init sys 199 JSR W init tsk 200 201 IF MR TIMEOUT 202 GLB _ init tout 203 JSR W init tout 204 ENDIF 205 206 IF NUM FLG 207 GLB _ init flg 208 JSR W init flg 209 ENDIF 210 211 IF NUM SEM 212 GLB __init_sem 213 JSR W init sem 214 ENDIF 215 216 IF NUM DTO 217 GLB init dtq 218 JSR W init dtq 219 ENDIF 220 221 IF NUM VDTQ 7 A1 222 GLB init vdtq 223 JSR W init vdtq 224 ENDIF 225 226 IF NUM MBX 227 GLB _ init mbx 228 JSR W init mbx 229 ENDIF 230 231
134. rated synchronization service calls Put Task to sleep slp_tsk tslp_tsk Wakeup task wup_tsk iwup_tsk Wakeups a task that has been placed in a WAIT state by the slp_tsk or tslp_tsk service call No task can be waked up unless they have been placed in a WAIT state by If a wakeup request is issued to a task that has been kept waiting for conditions other than the slp tsk or tslp_tsk service call or a task in other than DORMANT state by the wup_tsk or iwup_tsk service call that wakeup request only will be accumulated Therefore if a wakeup request is issued to a task RUNNING state for example this wakeup request is temporarily stored in memory Then when the task in RUNNING state is going to be placed into WAIT state by the slp_tsk or tslp_tsk service call the accumulated wakeup request becomes effective so that the task continues executing again without going to WAIT state See Figure 3 23 e Cancel Task Wakeup Requests can_wup Clears the stored wakeup request See Figure 3 24 wup_tsk wup_tsk wup_tsk ae ol o slp_tsk Wakeup request count 0 0 1 2 1 Figure 3 23 Wakeup Request Storage wup_tsk wup tsk can wup k ps e slp a Paced Wakeup request count 0 0 1 0 0 Figure 3 24 Wakeup Request Cancellation Suspend task sus_tsk isus_tsk Resume suspended task rsm_tsk irsm_tsk These service calls forcibly keep a task suspended for execution or resume execution of a task If a suspend request is issued to a task
135. re 3 31 Task Execution Control by the Eventflag 40 Chapter 3 Introduction to MR308 3 5 7 Synchronization and Communication Function Data Queue The data gueue is a mechanism to perform data communication between tasks In Figure 3 32 for example task A can transmit data to the data gueue and task B can receive the transmitted data from the data gueue Task A Task B eh Figure 3 32 Data gueue Data in width of 32 bits can be transmitted to this data gueue The data queue has the function to accumulate data The accumulated data is retrieved in order of FIFO However the number of data that can be accumulated in the data queue is limited If data is transmitted to the data queue that is full of data the service call issuing task goes to a data transmission wait state There are following data queue service calls that are provided by the MR308 kernel e Send to Data Queue snd_dtq tsnd_dtq Transmits data Namely data is transmitted to the data queue If the data queue is full of data the task goes to a data transmission wait state e Send to Data Queue psnd_dtq ipsnd_dtq Transmits data Namely data is transmitted to the data queue If the data queue is full of data the task returns error code without going to a data transmission wait state Forced Send to Data Queue fsnd_dtq ifsnd_dtq Transmits data Namely data is transmitted to the data queue If the data queue is full of data the data at the top of t
136. 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 e 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 O 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 consid
137. riable size Memory Block pget_mpl Round off a block size you specify to the optimal block size among the four block sizes and acquires memory having the rounded off size from the memory pool The following equations define the block sizes a max_memsize X 1 X x 8 1 x 8 b ax2 c ax4 d ax8 max_memsize the value specified in the configuration file X data size for block control 8 byte For example if you request 200 byte the MR308 rounds off the size to 244 bytes and acquires 244 byte memory If memory acquirement goes well the MR308 returns the first address of the memory acquired along with the error code E OK If memory acquirement fails the MR308 returns the error code E TMOUT 45 Chapter 3 Introduction to MR308 200 bytes TaskA Rounding Memorypool pget_blk 224 bytes 200 bytes Figure 3 36 pget_mpl processing Release Acquire Variable size Memory Block rel_mpl Releases a acquired memory block by pget_mpl service call TaskA Memorypool Memorypool Figure 3 37 rel_mpl processing e 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 46 Chapter 3 Introduction to MR308 3 5 10 Time Management Function The time management function provides system time management time reading time setup and the func tions of the alarm ha
138. ribed in C Language 68 Figure 5 3 Example of Kernel OS dependent Interrupt Handler 0 ccccccccsscssessessescessescsseees 70 Figure 5 4 Example of Non kernel OS independent Interrupt Handler cccccccccceseeseeseees s Figure 5 5 Example Cyclic Handler Written in C Language eee eeeeeee0 eee een 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 8 Figure 5 8 Example of kernel OS depend interrupt handler c ccccccescesssccsseescssesecseeseescseees D Figure 5 9 Example of Non kernel OS independent Interrupt Handler of Specific Level aioe Figure 5 10 Example Handler Written in Assembly Language cocooooccnononononononannnoconononoanonononcnnon ss Figure 5 11 Interrupt handler IPLs 0000000000000 000e00 0000060000000 e 000000 e en ccoo nn nh Rent nn n 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 crtOmr a30 ee eeeeeeeeeeee0eee eee nenene 88 Figure 5 15 Selection Allocation in C Language Startup Program eee 93 Figure 6 1 The operation of the Configurator ccccccnnonooononnnonnononnnnononononnnono
139. s shown in Figure 3 28 communication line to task connections can be made without incurring contention Communication Line Communication Line Communication Line Semaphore x Figure 3 28 Exclusive Control by Semaphore The semaphore has an internal semaphore counter In accordance with this counter the semaphore is acquired or released to prevent competition for use of the same resource See Figure 3 29 Acquired Returned after use Figure 3 29 Semaphore Counter The MR308 kernel offers the following semaphore synchronization service calls e Release Semaphore Resource sig_sem isig_sem Releases one resource to the semaphore This service call wakes up a task that is waiting for the semaphores service or increments the semaphore counter by 1 if no task is waiting for the sema phores service e Acquire Semaphore Resource wai_sem twai sem Waits for the semaphores service If the semaphore counter value is O zero the semaphore cannot be acquired Therefore the WAITING state prevails e Acquire Semaphore Resource pol_sem ipol_sem Acquires the semaphore resource If there is no semaphore resource to acquire an error code is re turned and the WAITING state does not prevail 37 Chapter 3 Introduction to MR308 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
140. sk Priority and Waiting Queue sesesssssesereessssessesreecsessssoserrecsssssseseeeessessssoseeeesesessosreeeseses 224 5 3 3 4 Task Control Block TCB oc ccececccccccccccseescssccesecsccsccesecssesscseeceseescesssescaeceusessesscseeesseesesseeenes 25 BA Systemi States arrean autera ai a EG Note a au a Hae kok o odejel bases alge heed cos buck ais 27 3 4 1 Task Context and Non task Context ccccccccccssccccsessececeesssececsessececsesseeeenesseeecsesseeeessaeeeeseaaes 27 3 4 2 Dispatch Enabled Disabled tates oooccccccnnnnnnonannnonncnnnnanononononononnnnanononononnononnn ETE i a ak 28 3 4 3 CPU Locked Unlocked States cccccccssccccesssececesssseeecsesnececsesseeecseseeeeeseseeesseseeeessseeeesssseeeeees 29 3 4 4 Dispatch Disabled and CPU Locked StateS oooooooccnccnnnooonononanonncnonnananonononnononnn nono noncononannn nan nooo 29 3 5 MR808 Kernel Structure cccccccccccsssccccesssececessseeecssssseeecsssneeecssseeecesseeecesseeeeseseeesesesueeeeeseeeeesees 80 3 5 1 Module Structure italian RUS albo Lan ER EDI avvaaaavsuceda dad a wives ses 80 3 02 Module OveryiE Wsi serme ie enti erehe a A AR aE a Soda kou ao ES SKK dd dk Di dea datos 81 3 5 3 Task Management Function 0 e00000 0000000000000 00000000 E no KRKA RK Reno itara iak 82 3 5 4 Synchronization functions attached to task cccccccccccccesessssceececececeesessaeeeecceeseeesssseeseeeeeess 84 3
141. sk pause Task Pause tic deno Time tick denominator tic nume Time tick numerator message pri Maximum message priority value W lt lt Content gt gt 1 System stack size Definition format Numeric value Definition range 6 or more Default value 400H Define the total stack size used in service call and interrupt processing 5 8 All items except task definition can omitted If omitted definitions in the default configuration file are referenced 99 Chapter 6 Using Configurator 2 Maximum value of priority value of lowest priority Definition format Numeric value Definition range 1 to 255 Default value 63 Define the maximum value of priority used in MR308 s application programs This must be the value of the highest priority used 3 Kernel mask level OS interrupt disable level Definition format Numeric value Definition range 1to7 Default value 7 Set the IPL value in service calls that is the OS interrupt disable level 4 Timeout function Definition format Symbol Definition range YES or NO Default value NO Specify YES when using or NO when not using tslp tsk twai flg twai sem tsnd_dtq trcv_dtq tget mpf vtsnd_dtq vtrcv_dtq and trcv_msg 5 Task Pause Definition format Symbol Definition range YES or NO Default value NO Specify YES when using or NO when not
142. ssseceeeeeeesesenessaaeeeeens 123 6 2 2 Setting Configurator Environment ccccccccccsesssssscecececceceessssececececsesessneeeeececesesersssaaeeeeeens 125 6 2 3 Configurator Start Procedure ccccceessssscecececeessnsecececcececsesssseseeesecseeessseceeesecesesensstsaeeeeeess 126 6 2 4 makefile generate Function ccccccnnononononononononananononononnononnanononnnncnnononnnnnnnnonrononnananonnnnnnonannnnns 127 6 2 5 Precautions on Executing Configurator c cccccccccccsssssssceseccecessesssseceeecscessesssaeeesecesesesentsaeess 128 6 2 6 Configurator Error Indications and Remedies cccccccesssssececeeeceeeessnsececececesesesersseeeeees 129 Error messages ii A A severe duceuavedtars desk VSS VD da Send kate 129 Warning m ssag eshi ae 52555 i055 dona En Soon EES EOE O nos s eadues Fab ad oa dt ao aso v lt 131 Other messages iia ta sal A UT 132 6 4 About an error when you execute Make occccnnoncooooonncnnonononnnnnnnnconononnnnonononnnnnononnanonononcnnonannanonoss 133 Chapter 7 Application Creation Guide id a 135 7 1 Processing Procedures for System Calls from Handlers ccconnnnoncnnnnonnnononnanonanonononncnnannnnnnnnos 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 T
143. ssued from only task context When the I flag before issuing a service call is 1 Task Service call issued Service call processing y I flag 1 lt 0 1 1 I 1 I IPL 0 lt systemIPL l lt 0 lt systemIPL lt 0 l I 1 n l When the I flag before issuing a service call is 0 Task Service call issued Service call processing I I l I g l IPL 0 system IPL lt 0 system IPL 0 I I l l 1 1 l Figure 5 12 Interrupt control in a System Call that can be Issued from only a Task For service calls that can be issued from only non task context or from both task context and non task context 80 Chapter 5 Detailed Applications When the I flag before issuing a service call is 1 Taek or Servi lli d service call processin a Handler n So NA X E Handler I I l I flag 1 lt 0 e 1 lt 1 I 1 l IPL 4 s lt system IPL l lt 4 lt system IPL lt 4 I When the I flag before issuing a service call is 0 Task or Servi lli d service call processin ASK or v Handler ervice call issue p g Handler I l I flag 0 0 gt lt 0 l i l IPL 4 system IPL lt 4 lt system IPL lt 4 Figure 5 13 Interrupt control in a System Call that can be Issued from a Task independent As shown in Figure 5 12 Interrupt control in
144. t 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 Please specify message size 16 or 32 of the Mailbox function cfg308 Warning task x XXXX is not defined near line xxx xxxx cfg The task definition item XXXX in ID number is omitted cfg308 Warning Already definition XXXX near line xxx xxxx cfg XXXX has already been defined The defined content is ignored check to delete the extra definition cfg308 Warning interrupt vector x s default is not defined default cfg The interrupt vector definition of vector number x in the default configuration file is missing cfg308 Warning interrupt vector x s default is not defined near line xxx xxxx cfg The interrupt vector of vector number x in the configuration file is not defined in the default configura tion file cfg308 Warning Initial Start Task not defined The task of task ID number 1 was defined as the initial startup task because no initial startup task is defined in the configuration file cfg308 Warning system stack size is an uneven number near line xxx cfg308 Warning task x stack size is an uneven number near line xxx Please set even size in system stack size or task x
145. ta reception waiting queue Fixed size memory pool acquisition waiting queue 13 For the information on the ready queue see the next chapter 14 Depends on the ext tsk service call s 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 trev_dtq vtsnd_dtq vsnd_dtq vtrev_dtq tget_mpf get mpf or vrev_dtq service call k Depends on the chg pri service call A Depends on the ichg_pri service call The service call twai_flg twai sem and trcv_msg are included 21 Chapter 3 Introduction to MR308 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 If a task in the WAITING state is placed in this situation it goes into the WAITING SUSPENDED state The SUSPENDED state is the condition in which a READY task or currently executed task is ex cluded from scheduling to halt processing due to I O or other error occurrence That is when the sus pend request is made to a READY task that task is excluded from the execution queue Note that no queue is formed for the suspend request Therefore the suspend request can only be made to the tasks in the RUNNING READY or WAITING state If the suspend request is made to a task in the SUSPENDED state an error code is re
146. tem clock definition item If you want the cyclic handler to be activated at 1 second intervals for ex ample the activation cycle here must be set to 1000 3 TA STA attribute Definition format Symbol Definition range ON or OFF Default value OFF Specify the TA_STA attribute of the cyclic handler If ON is selected the TA_STA attribute is added if OFF is selected the TA_STA attribute is not added 4 TA_PHS attribute Definition format Symbol Definition range ON or OFF Default value OFF Specify the TA_PHS attribute of the cyclic handler If ON is selected the TA_PHS attribute is added if OFF is selected the TA_PHS attribute is not added 5 Activation phase Definition format Numeric value Definition range 1 to OxFFFFFFFF Default value None Define the activation phase of the cyclic handler The time representing this startup phase must be de fined in ms units 6 Start Address Definition format Symbol or Function Name Definition range None Default value None Define the start address of the cyclic handler Note that the function name defined here will have the declaration statement shown below output to the kernel_id h file pragma CYCHANDLER function name 114 Chapter 6 Using Configurator 7 Extended information Definition format Numeric value Definition range 1 to OXFFFFFFFF Default value 0 Define the exte
147. ter 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 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 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 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
148. ter engine task e slp tsk Causes a task in the RUNNING state to enter the WAITING state In the example this function is used to make the printer engine task wait for image expansion e set flg Sets the eventflag In the example this function is used to notify the image expansion task of the com pletion of one page data input 2 The configurator converts the ID number to the associated name character string in accordance with the information entered int the con figuration file 62 Chapter 4 Applications Development Procedure Overview include lt itron h gt include lt kernel h gt include kernel id h void main main task printf LBP start simulation An sta_tsk ID_idle 1 activate idle task sta tsk ID image 1 activate image expansion task sta tsk ID printer 1 activate printer engine task void image activate image expansion task while 1 wai flg ID pagein waiptn TWF ANDW amp flgptn wait for 1 page input printf bit map expansion processing In wup tsk ID printer wake up printer engine task void printer printer engine task while 1 slp tsk printf printer engine operation In void sent_in Centronics interface handler Process input from Centronics interface if 1 page input completed iset flg ID pagein setptn Figure 4 2 Program Example 63 Chapter 4 Applicati
149. tes 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 The system can be placed into a dispatch disabled state or a dispatch enabled state by the dis dsp or ena dsp service call respectively Whether the system is in a dispatch disabled state can be known by the sns dsp ser vice call 2 Ifa service call not issuable is issued when dispatch disabled MR308 doesnt return the error and doesn t guarantee the operation 28 Chapter 3 Introduction to MR308 3 43 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 un cpu iunl cpu service call respectively Whether the system is in a CPU locked state can be known by the sns loc service call The service calls that can be issued from a CPU locked state are limited to those that are listed in Table 3 2 Table 3 2 Invocable Service Calls in a CPU Locked State loc cpu iloc cpu unl cpu iunl cpu ext tsk exd tsk sns tex sns_ctx sns_loc sns_dsp sns_dpn 3 4 4 Dispatch Disabled and CPU Locked States In ITRON 4 0 Specification the d
150. the non kernel OS independent interrupt handler s IPL value cannot be set below the ker nel OS independent interrupt disable level Figure 5 11 shows the relationship between the non kernel OS independent interrupt handlers and ker nel OS dependent interrupt handlers where the kernel mask level OS interrupt disable level is set to 3 Kernel mask level OS Interrupt disable level Kernel Non kernel OS dependent OS independent Interrupt handler Interrupt handler Figure 5 11 Interrupt handler IPLs 5 5 2 The Use of Non maskable Interrupt An NMI interrupt and Watchdog Timer interrupt have to use be a non kernel OS independent interrupt handler If they are a kernel OS dependent interrupt handler the program will not work normally system IPL is set by the configuration file 79 Chapter 5 Detailed Applications 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 In sections where all interrupts can be enabled it is returned to the ini tial IPL value when the service call was invoked Figure 5 12 Interrupt control in a System Call that can be Issued from only a Task shows the interrupt enable flag and IPL status in a service call e For service calls that can be i
151. the section file for the assembly language Refer to the NC308 manual for details The diagram below shows the section allocation in the sample startup program See Figure 5 15 Selection Al location in C Language Startup Program 92 Chapter 5 Detailed Applications 000000H 000400H Section generated by NC308 MR RAM NE MR RAM NO MR RAM MR RAM a Section generated by NC308 stack MR HEAP Section generated by NC308 JFF0000H MR KERNEL MR CIF MR ROM OFFFDO0H program program S INTERRUPT VECTOR OFFFEOOH fvector OFFFFDCH FIX_INTERRUPT_VECTOR data_SE bss_SE data_SO bss_SO data_NE bss_NE data_NO bss_NO rom_NE rom_NO data_FE bss_FE data_FO bss_FO rom_FE rom_FO data_SEI data_SOI data_NEI data_NOI data_FEI data_FOI This section is no linked when the program is written in the assembly language Figure 5 15 Selection Allocation in C Language Startup Program 93 Chapter 5 Detailed Applications 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 DM16C70 1 94 Chapter 6 Using Configurator Chapter 6 Using Configurator 6 1 Configuration File Creation Procedure When applications program coding and startup program modif
152. tion kernel ROM MR308 kernel eee RON Task of ID 1 program section common program Fix Interrupt FIX_INTERRUPT_VECTOR section vector area E Figure 9 2 Memory map 6 Executing the configurator cfg308 7 Editing makefile You specify an argument for mr308tbl held in makefile You specify the argument for two directories in which each application is held An example is given here in which the directory product app1 is used for application 1 is and the di rectory product app2 is used for application 2 148 Chapter 9 Separate ROMs mr308tbl product appl 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 6 5 If the file mrtable a30 is not held in the current directory execute make command to generate a system 149 Real time OS for M16C 70 80 M32C 80 Series M3T MR308 4 User s Manual Publication Date Nov 1 2005 Rev 2 00 Sales Strategic Planning Div Published by Renesas Technology Corp Application Engineering Department 1 a Renesas Solutions Corp 2005 Renesas Technology Corp and Renesas Solutions Corp M3T MR308 4 V 4 00 User s Manual ENESAS Renesas Electronics Corporation 1753 Shimonumabe Nakahara ku Kawasaki s
153. tions Further Renesas Electronics products are not subject to radiation resistance design Please be sure to implement safety measures to guard them against the possibility of physical injury and injury or damage caused by fire in the event of the failure of a Renesas Electronics product such as safety design for hardware and software including but not limited to redundancy fire control and malfunction prevention appropriate treatment for aging degradation or any other appropriate measures Because the evaluation of microcomputer software alone is very difficult please evaluate the safety of the final products or system manufactured by you Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances including without limitation the EU RoHS Directive Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations This document may not be reproduced or duplicated in any form in whole or in part without prior written consent of Renesas Electronics Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products o
154. to the TRON association N Contents Chapter 1 User s Manual Organization ccccsscccssssssccessssseecesseeeecssceseccssesseecessseeeccesnaeeeesssueeeesssseeeeeees z Chapter 2 General Information cccccnooooooncnnnnnnnononnnnnonnnnnnnnnnnnnnnnonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnannnnnnnnnnnnnananes 3 2 1 Objective of MR308 Development cecccssssccccececeesessnseceeececsesensasececeeeecsceesessaaeeeeecseeentsaeeeeeess 4 2 2 Relationship between TRON Specification and MR308 eee 00eeeee ee nn n 6 229 GMER BOS Features cita nal o toi ti ii dis Chapter 3 Introduction to MR S08 visit is A A A da eS AA 9 3 1 Concept of Realtime O iia ia dll A s 10 3 1 1 Why Real time OS is Necessary cccccccccsssesssseceeececcsceenssssceeececsesessseceeeescesesessnsaaeeeeeeseeeneaaeas 10 3 1 2 Operating Principles of Real time OS ccccccccccccssessssececececeesesssaeeesececeensessseeeeeeeesesenssaeeeeees 18 3 2 Service Gallia fel heal ees boot A a opr ae 16 3 2 1 Service Gall Processing sais sess iii id c 3 2 2 Task Designation in Service call 0 00 00 0000 0000000000000 000000000 000 ee nene E nene nn 18 Bide VA A So na e o k an Rens eee aa he Seah td k a Noa ee a 19 3 3 1 Task Status viscid dada 19 3 3 2 Task Priority and Ready Queue cccccccccccsessssscecececeesensseceeececesesessaeceeececseeesssseeeeeeeeseneeeas 23 3 3 3 Ta
155. tor section This section stores the vector address of special page calls This section is not used by the MR308 kernel at all INTERRUPT VECTOR section FIX INTERRUPT VECTOR section This section stores interrupt vectors The start address of this section varies with the type of M16C 80 series microcomputer used The address in the sample startup program is provided for use by the M16C 80 series micro computers This address must be modified if you are using a microcomputer of some other group 91 Chapter 5 Detailed Applications 5 9 2 Section Allocation of crtOmr a30 The section allocation of the sample startup program for the C language crtOmr 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 of the sample startup program for the assembly language data_SE section e bss SE section e data SO section e bss SO section e data NE section e bss NE section e data NO section e bss NO section e rom NE section e rom NO section e data FE section e bss FE section e data FO section e bss FO section e rom FE section e rom FO section e data SEl section data SOl section data NEI section e data NOI section e data FEI section e data FOI section These sections are those that are generated by NC308 These sections are not defined in
156. turned 5 WAITING SUSPENDED If a forcible wait request is issued to a task currently in a wait state the task goes to a WAIT ING SUSPENDED state If a forcible wait request is issued to a task that has been placed into a wait state for a wait request by the slp tsk wai_flg wai sem rcv_mbx snd_dtq rev dtg vsnd dtg vrcv_dtq get mpf tslp tsk twai_flg twai sem trcv_mbx tsnd_dtq trcv_dtq vtsnd_dtq vtrcv_dtq or tget_mpf service call the task goes to a dual wait state When the wait condition for a task in the WAITING SUSPENDED state is cleared that task goes into the SUSPENDED state It is conceivable that the wait condition may be cleared when any of the fol lowing conditions occurs The task wakes up upon wup_tsk or iwup_tsk service call issuance The task placed in the WAITING state by the dly tsk or tslp_tsk service call wakes up after the specified time elapse The request of the task placed in the WAITING state by the wai_flg wai sem rcv_mbx snd_dtq rcv_dtq vsnd_dtq vrcv_dtq get mpf tslp_tsk twai_flg twai sem trev mbx tsnd_dtq trcv_dtq visnd_dtq vtrcv_dtq or tget_mpf service call is fulfilled The WAITING state is forcibly cleared by the rel wai or irel_wai service call When the SUSPENDED state clear request is made to a task in the WAITING SUSPENDED state that task goes into the WAITING state Since a task in the SUSPENDED state cannot request to be placed in the WAITING state status chan
157. ty of task Definition format Numeric value Definition range 1 to maximum value of priority in system definition Default value 1 Define the priority of a task at startup time As for MR308 s priority the lower the value the higher the priority 5 Regisers Used Definition format Symbol Symbol Definition range Selected from RO R1 R2 R3 A0 A1 SB FB Default value All registers Define the registers used in a task MR308 handles the register defined here as a context Specify the RO register because task startup code is set in it when the task starts However the registers used can only be selected when the task is written in the assembly language Select all registers when the task is written in the C language When selecting a register here be sure to select all registers that store service call parameters used in each task MR308 kernel does not change the registers of bank If this definition is omitted it is assumed that all registers are selected 6 Section name in which the stack is located Definition format Symbol Definition range None Default value stack Define the section name in which the stack 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 stack is located in the stack section 7 TA ACT attribute initial startup state Definitio
158. uring dispatch delay 4 Precautions e No service call e g slp_tsk wai_sem can be issued that may place the own task in a wait state while in a state where dispatch is disabled by dis_dsp or loc_cpu e Note that ena_dsp and dis dsp cannot be issued while the system is placed in a CPU locked state by loc_cpu e Disabled dispatch is re enabled by issuing ena_dsp once after issuing dis_dsp several times 82 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 83 Chapter 5 Detailed Applications 5 8 Modifying MR308 Startup Program MR308 comes with two types of startup programs as described below e start a30 This startup program is used when you created a program using the assembly language e crtOmr a30 This startup program is used when you created a program using the C language This program is derived from start a30 by adding an initialization routine in C language The startup programs perform the following e Initialize the processor after a reset Initialize C language variables crtOmr a30 only e Set the system timer Initialize MR308 s data area Copy these startup programs from the directory indicated by environment variab
159. y If you create the own makefile for MR308 system be sure to describe the following 4 items in the makefile 1 MR308 Library Specifications you must specify libraries mr308 lib and c308mr lib 2 Assemble Option Specifications Make sure to specify assemble option F when assembling the source file described in the assemble language which issues the service call 3 Process Before Linking Before executing a link make sure to execute the following two processes in the order as are listed 1 mr308tbl 2 as308 mrtable a30 MR308 comes equipped with the mr308tbl utility Execute it in the directory where Configurator cfg308 executes If that is not the same directory where the service call file XXX mrc and the r30 file are output by C Compiler or Assembler you need to specify the directory at parameters of mr308tbl as following Ex mr308tbl outputdir If you use Service call Issue Function on PD308 you need to add LIB308 at parameter of mr308tbl Once mr308tbl is executed the mrtable a30 file will be created After these two processes are com pleted execute the link including the mrtable r30 file 132 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 Y
160. ys be set when the data queue function is to be used lt lt Format gt gt Datagueue Definition mailbox ID No 1 name ID name buffer size Number of data queues wait queue Select data queue waiting queue W The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are auto matically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each data gueue ID number define the items described below 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the data gueue is specified in a program 108 Chapter 6 Using Configurator 2 Number of data Definition format Numeric Value Definition range 0 to Ox1FFF Default value 0 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 Selecting a data queue waiting queue Definition format Symbol Definition range TA_TFIFO or TA_TRPI Default value TA_TFIFO Select a method in which tasks wait for 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 beginning with the one that has the highest priority Short data queue definition This definition must always be set wh
161. ystem Configuration Management Module Reports the MR308 kernel version number or other information Sync Communication Module This is the function for synchronization and communication among the tasks The following three func tional modules are offered Eventflag Checks whether the flag controlled within the MR308 is set up and then determines whether or not to initiate task execution This results in accomplishing synchronization between tasks Semaphore Reads the semaphore counter value controlled within the MR308 and then determines whether or not to initiate task execution This also results in accomplishing synchronization between tasks Mailbox Provides inter task data communication by delivering the first data address Data queue Performs 32 bit data communication between tasks Memory pool Management Module Provides dynamic allocation or release of a memory area used by a task or a handler Extended Function Module Outside the scope of ITRON 4 0 Specification this function performs reset processing on short data queues and objects This handler actuates once only at preselected times 3 1 This handler periodically actuates Y AAA A lt _ Q _E__ 31 3 5 3 Chapter 3 Introduction to MR308 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
Download Pdf Manuals
Related Search
Related Contents
A1122SP • 91323 Gembird MUSW-206 mice Smeg STL827A dishwasher Cawt User Manual - poSoft (Medical Equipment for Garowe Hospital Somalia). Copyright © All rights reserved.
Failed to retrieve file