Home
M3T-MR30 V.3.30 User`s Manual
Contents
1. ichg pri Change Task Priority Changes the task priority irot rdg Rotate Ready Queue Rotates the task ready queue irel_wai Release Task Wait Forcibly clears the task WAIT state isus_tsk Suspend Task Puts a task into the SUSPEND state irsm_tsk Resume Task Resumes the suspended task iwup_tsk Wakeup Task Wakes up the waiting task iset_flg Set EventFlag Sets an eventflag isig sem Signal Semaphore Signal operation for a semaphore isnd msg Send Message to Mailbox Sends a message ista tsk Start Task Starts the task ret_int Return from Interrupt Handler Return from the interrupt handler 2 It isn t necessary to write this system call when specifying the interrupt handler as pragma INTHANDLER in C language 30 Chapter 3 Introduction to MR30 3 5 MR30 Kernel Structure 3 5 1 Module Structure The MR30 kernel consists of the modules shown in Figure 3 17 Each of these modules is composed of functions that exercise individual module features The MR30 kernel is supplied in the form of a library and only necessary features are linked at the time of system generation More specifically only the functions used are chosen from those which comprise these modules and linked by means of the Linkage Editor LN30 However the scheduler module part of the task management module and part of the time management module are linked at all times be cause they are essential feature functions The applications program is a program
2. 101 system clock interrupt eee 27 89 system clock interrupt handler 76 System clock interrupt priority level 101 System Definition Procedure 99 System Stack eee 135 System Stack pointer s es 89 System timer EE 48 89 system Blaine 77 g task pau K cita ic cds 100 BEE 20 Task definition eee 104 task ID number 19 task management sseseeeeseseeerrrrrerrereree 32 Task Status nun 20 task owitchlng 13 WG Bini A da ALVA KOS LAKE 25 TEVE UNISON ua ech 49 TEX OFF to oea e ad 110 TOY ON Aa 49 110 template le 116 ter tSK au een 32 The maximum number of alarm handler defined seen 104 The maximum number of cyclic activation handlers defined s 104 The maximum number of eventflags defined eae VK One A One u 103 The maximum number of fixed size memorypools defined 104 The maximum number of mailboxes defined Soon sani ok nalevo Gantt dem o ae EN 103 The maximum number of messages 107 The maximum number of semaphores GETING PARA are PO es 103 The maximum number of tasks defined 103 The time Of day eee 98 ME od 98 A eee cette eee eteee tees 48 CIMGOUE sores ace 48 Timeout function esseere 100 ger un EE 42 48 100 TRON Specification sseeeseeeeeereeeere 6 Epica eh 35 48 100 TS iia 33 Wald 37 48 100 LWAl SEM neennannasnnnnannnnnnannannnnnnnenn 40 48 100 Type NuUMber eee 51 g Unit tim
3. 52 If you want the OS independent interrupt handler to be assigned a priority level lower than OS dependent interrupt handlers change the description of the OS independent interrupt handler to that of the OS dependent interrupt handler 5 1 Program Coding Procedure in C Language 69 5 1 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in C language observe the following precautions 1 Describe the cyclic or alarm handler as a function 2 Be sure to declare the return value and argument of the interrupt handler start func tion as a void type 3 At the beginning of file be sure to include mr30 h which is in the system directory as well as id h which is in the current directory 4 The static declared functions cannot be registered as a cyclic handler or alarm handler 5 Don t describe extern declaration nor prototype declaration if system call is issued from your program 6 The cyclic handler and alarm handler are invoked by a subroutine call from a sys tem clock interrupt handler include lt mr30 h gt include id h void cychand void process Figure 5 5 Example Cyclic Handler Written in C Language 53 The handler to function name correlation is determined by the configuration file 70 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 Writ
4. MR30 kernel Application ROM2 MR ROM MR30 s ROM MR30 s ROM s data MR ROM data MR_CIF languagel F routine MR CIF C language I F routine application change App prog Task2 App pro Task2 Task3 Task3 Task4 Task4 Task5 Use Function Mailbox Use Function Eventflag Interrupt vector area Mailbox Interrupt vector area semaphore Eventflag Number of Task4 Fix Interrupt Fix Interrupt umber of Tas ak Number of Task5 Vector area Figure 9 1 ROM separate Programs to be located in the application ROM MR30 s ROM data the MR ROM section C language I F routines the MR CIE section Application programs the app prog section Interrupt vector area the INTERRUPT VECTOR section Fixed interrupt vector area FIX INTERRUPT VECTOR section eff o 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 programs to be located in the application ROM by use of pragma SECTION as shown below In NC30 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 70 You need not change the names of sections for tasks to be located int the kernel ROM 147 pragma SECTION program app prog Changing section of program The section names of
5. essssssrssissrisissrretnstnetintisrntnnnnnntnnnnnnnnernnnnnn 116 Figure 7 1 Processing Procedure for a System Call a Handler that caused an interrupt during Task Execution er essen 131 Figure 7 2 Processing Procedure for a System Call from a Handler that caused an interrupt during System Call Processing 20u4s0srn4onnnnnnnannnannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnannnannn 132 Figure 7 3 Processing Procedure for a system call from a Multiplex interrupt Handler 133 Figure 7 4 System Stack and User Stack 135 Figure 8 1 LED illumination Status nn nenn nn nnns 138 Figure 9 1 ROM separate ansia diia deet ee Eed EENS ee 146 Figure 9 2 Memory MAPA la is Pond B ole Hi 148 List of Tables vii List of Tables Table 2 1 Table 3 1 Table 3 2 Table 5 1 Table 5 2 Table 5 3 Table 6 1 Table 6 2 Table 6 3 Table 7 1 Table 8 1 MR30 Specifications OVErvieW e eee eee cece eee eee een eee rr 7 System Calls Issuable from only Handerz eee eee eee eee een 29 List of the system call can be issued from the task and handler 52 C Language Variable Treatment AAA 66 Interrupt Number Aseiopmert ccc cece ceee eee cece ects tees eee eee ee eee een nenene teen 75 Interrupt and Dispatch Status Transition by dis dsp and loc pu 80 Numerical Value EntrvExvamples AA 96 le le EE 97 Fixed I nterrupt Causes and Vector Numbers AAA 112 MR RAM Method for Caluculating Size of MR RAM Section
6. task3 and task4 are processed in the same way as task2 except that the wait time is different from task2 The values of variable pt10 and port 10 are modified in the cyclic handler cyh1 While shifting the value of variable pt10 one bit at a time the cyclic handler transfers the resulting value to port 10 to make it lit by the LED OJOJOJOJOJOLOLO M a Ol EE ke ER E E KAR RE E AAA Te OT OF Sook Sa a ROET Figure 8 1 LED illumination Status 8 2 Program Source Listing 139 LR RR kk kk kk 22 22 22 22 22 22 22 22 22 22 22 22 22 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2022 2 3 COPYRIGHT C 2003 RENESAS TECHNOLOGY CORPORATIO 4 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED 5 6 sample program 7 SId demo c v 1 7 2003 08 22 12 59 49 muraki Exp O A E E A I FE OEO E E TT 10 1l1 include lt stdio h gt 12 include lt mr30 h gt 13 14 include id h 15 16 pragma ADDRESS PD7 3efH 17 pragma ADDRESS PD8 3f2H 18 pragma ADDRESS PD10 3f6H 19 20 pragma ADDRESS P7 3edH 21 pragma ADDRESS P8 3f0H 22 pragma ADDRESS P9 3f 1H 23 pragma ADDRESS P10 3f4H 24 25char PD7 PD8 PD10 26char P7 P8 P9 P10 27 28char pt7 pt8 pt9 pt10 29 30void main 31 32 pragma AS 33 bset 2 0AH 34 mov w OFFH 3 3H 35 belr 2 0AH 36 pragma ENDASM 37 PD7 PD8 PD10 Oxff 38
7. stack_size User stack size of task priority Initial priority of task context Registers used initial start Initial startup status 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 lt lt Content gt gt Define the following for each task ID number 1 2 3 Start address of task Definition format Symbol or function name Definition range None Define the entry address of a task When written in the C language add at the end or ai the beginning of the function name you have defined The function name defined here causes the following declaration statement to be output in the id h file pragma TASK Function Name User stack size of task Definition format Numeric value Definition range 6 or more Define the user stack size for each task The user stack means a stack area used by each indi vidual task MR30 requires that a user stack area be allocated for each task which amount to at least 6 bytes Initial priority of task Definition format Numeric value Definition range 1 to maximum value of priority in system definition Define the priority of a task at startup time As for MR30 s priority the lower the value the higher the priority 6 1 Configuration File Creation Procedure 105 4 Regisers Used Definitio
8. Displays the information on the files generated by the command m Option Creates the UNIX standard or UNIX compatible system generation procedure description file makefile 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 di rectory the configurator copys them to the current directory form the directory indicated by the environment variable LIB30 57 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 6 2 Configurator Execution Procedures 119 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 dependen cy relationship of the files to be included by those Consequently observe the 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
9. 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 system calls loc_cpu and unl cpu The interrupts that can be controlled by the loc cpu system call are only the OS dependent interrupt Use method 1 to control the OS independent interrupts 5 6 Regarding Delay Dispatching 79 5 6 Regarding Delay Dispatching MR30 has four system calls related to delay dispatching dis dsp ena dsp loc cpu unl cpu The following describes task handling when dispatch is temporarily delayed by using these system calls 1 2 3 When the execution task in delay dispatching is preempted While dispatch is disabled even under conditions where the task under execution should be preempted 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 dis patch is being delayed Task under execution is in a RUN state and is linked to the ready queue Task to be executed after the dispatch disabled state is cleared is in a READY state and is linked to the highest priority ready queue among the queued tasks isus tsk irsm tsk during dispatch delay In cases when isus_tsk is issued from an interrupt handler that has been invoked in a dis patch disabled state to the task under execution a task to which dis dsp was is
10. jmp INT 330R39 jmp NIT 33 nop nop endif REIT if USE TIMER r System clock interrupt handler F SECTION MR_KERNEL CODE ALIGN glb SYS STMR INH SYS TIMEOUT glb DBG MODE ovo 158 __SYS_STMR_INH process issue system call zk __MR_NODBG else tst b 1H __DBG_MODE jz proc timer pushm RO R1 R2 R3 A0 mov w __SYS_ISS RO mov w __SYS_ISS 2 R1 mov w __SYS_ISS 4 R2 mov w __SYS_ISS 6 R3 mov w _SYS_1SS 8 A0 cmp w 108 R0 jeq INT 33 cmp w 110 RO jeq INT 33 cmp w GA BU me INT 33 1f RO lt 64 jmp INT 33 cmp w 68 RO jnc INT 330R39 7 1 RO gt 64 amp amp RO lt 68 cmp w 76 RO jne ANT 33 1f RO gt 68 ss RO lt 76 jmp b INT 39 INT 330R39 elt FAR_MSG_MODEL int 39 else int 33 endif jmp b END ISS SYS INT E int 39 jmp b END ISS SYS INT 33 int 33 END ISS SYS mov w RO SYS T585 error code mov w Ri 2SYSIISSH2 7 v mov w R2 SYS ISS 4 mov w R3 5 Sek and b 0FEH DBG MODE popm RO R1 R2 R3 A0 endif proc timer pushm R3 RO stc FLG RO mov w RO user FLG save user IPL mov b __SYS_IPL ROH change to system IPL ldc RO FLG fset I mov w __user_FLG R3 and w 0ff00H R3 System timer interrupt handler _STMR_hdr popm R3 RO ret_int endif 88 35 9 Chapter 5 Detailed Applications Figure 5 14 C Language Startup Program crtOmr a30 The following explains the content of the C language startup program crtOmr a30 Incorp
11. 07H E mov b 0 OAH mov w stmr_cnt stmr_ctr_reg set interval count or b Fstmr_bit 1 stmr_start system timer start ENDIF DH System timer initialize DH DE USE_SYSTEM_TIME MOV W __D_Sys_TIME_L Sys time 4 MOV W D Sys TIME M Sys time 2 MOV W o D Sys TIME H Sys time ENDIF DH d User Initial Routine if there are DH DH jmp MR INIT for Separate ROM DH S Initalization of System Data Area DH section MR_KERNEL CODE ALIGN glb init_sys init_tsk _END_INIT MR INIT jsr W init sys jsr W __init_tsk sa __MR_TIMEOUT glb init tout jsr w _ init tout endif if NUM FLG glb init lg jsr W _ init flg endif vit NUM SEM glb init sem jsr W init sem endif SIE ___ NUM_MBX glb init mbx jsr W __init_mbx endif LE ALARM_HANDLER glb a init alh jsr W _ init alh ENDIF 86 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 203 254 255 256 29 7 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 2T 278 279 280 281 282 283 284 285 Chapter 5 Detailed Applications o BB CYCLIC HANDLER glb init cyh jsr W __init_cyh ENDIF Fixed Memory Pool set NUM MPL glb init mpl jsr W _ i
12. 134 Sample Program Function LiSt e2 eee eee eee eee eee eee eee nenene 138 Chapter 1 User s Manual Organization 2 Chapter 1 User s Manual Organization The MR30 User s Manual consists of nine chapters and thee appendix Chapter 2 General Information Outlines the objective of MR30 development and the function and position of the MR30 Chapter 3 Introduction to MR30 Explains about the ideas involved in MR30 operations and defines some relevant terms Chapter 4 Applications Development Procedure Overview Outlines the applications program development procedure for the MR30 Chapter 5 Detailed Applications Details the applications program development procedure for the MR30 Chapter 6 Using Configurator Describes the method for writing a configuration file and the method for using the configurator in detail Chapter 7 Application Creation Guide Presents useful information and precautions concerning applications program development with MR30 Chapter 8 Sample Program Description Describes the MR30 sample applications program which is included in the product in the form of a source file Chapter 9 Separate ROMs Explains about how to Form Separate ROMs Chapter 2 General Information 4 Chapter 2 General Information 2 1 Objective of MR30 Development In line with recent rapid technological advances in microcomputers the functions of microcomputer based products have become com
13. 4 Figure 5 8 Example of OS depend interrupt handler 57 Use the GLB peudo directive 5 2 Program Coding Procedure in Assembly Language 73 5 2 3 Writing OS independent Interrupt Handler 1 For the symbol indicating the interrupt handler start address make the external declaration public declaration 2 Make sure that the registers used in a handler are saved at the entry and are re stored after use 3 Be sure to end the handler by REIT instruction No system calls can be issued from 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 an OS independent interrupt handler always make sure that the OS independent interrupt handler is assigned a priority level higher than other OS dependent interrupt handlers GLB inthand 1 inthand Registers used are saved to a stack 2 interrupt process Registers used are restored 2 RET ee A O SSS 3 Figure 5 9 Example of OS independent Interrupt Handler of Specific Level 58 If you want the OS independent interrupt handler to be assigned a priority level lower than OS dependent interrupt handlers change the description of the OS independent interrupt handler to that of the OS dependent interrupt handler 74 Chapter 5 Detailed Applications 5 2 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in Assembly
14. By his consent the MR30 is produced in compilance with the uITRON Specification Contents i Contents Chapter1 User s Manual Organization 4 eeeeeeeeeeeeee eee e nenene eee nene eee anne 1 Chapter 2 General Informationen 3 2 1 Objective of MR30 Development 4 2 2 Relationship between TRON Specification and MR30 eee eee eee eee 6 2 3 IMRIO Features ei E 8 Chapter3 Introduction to MR30 cccccssssecssssseessssseceeessseeeesessaeeesessaesensesseeeesessaeeesessnaeesesseees 9 3 1 Concept of Real time 08 dc 10 3 11 Why Real time OS is ANegesark 10 3 12 Operating Principles of Real fmedOs 13 32 System Call Hanne ia 17 321 Syste Call POCOS ia vines seek ek A A ev enable aap ee va widen das 18 3 2 2 Task Designation in System Call 19 E EL EE 20 3 3 1 Task StAtUs A A A al ee 20 3 3 2 Task Priority and Ready Ouere 24 BBS Task Control BORA TEBA ate 25 SE Mandler ua Wiener ee ay ata Reg neil ee rar m UDR nada n u ene 27 34 1 Difference between Tasks and Handler 27 3 4 2 System Calls Exclusive for Handler 29 35 MR30 Kernel Structu e casara ona lleida alan either 30 3251 MODULO SEEUCTUEO AA Se EE A LES 30 3 5 2 Module Overview A A a A a es EARNER RA 31 3 5 3 Task Management Eumction LAKE KARL P APA K KA RKK 32 35 4 Synchronization functions attfachei totaek 35 3 39 EVENT IO E 37 3 3 0 Ee E 39 B57 MAD sean toh ee AN Jo hd POZN Toy PRO ape eed 41 3 5 8 In
15. Handler een 27 Cyclic handler definition 110 Cydic handlers een 74 U data FE cad 92 data PE en 92 data O ii aa eet 92 data FOF cis alicante 92 data NE nacimos 92 data N E ansia nt 92 data Le 92 data NO licita 92 data SEA cuidao 92 data SEI unan acia 92 data Oriana ista 92 data Olano 92 default fga our 116 delay depatchlnmg 79 diS DEE 79 80 depatchtng vesiin an 13 Ou ESK A n a eiai 48 DORMAN eee eee een 23 U ena init 79 80 evemtflag EEN 37 Eventflag definition 106 Eventflag Oueie 22 A GENRE EEE EIER ten erer ees an 32 U FIX INTERRUPT VECTOR ee 91 Fixed size memorypool definition 108 Fixed size Memorypool Management 45 EGUEN either 97 function NAME eee eee 97 Index Wi GET WEE 34 get licita ic 49 EE 51 Wi handlers iii 27 Wi de Ve Hl Pili 29 32 O 64 Initial priority of task 105 Initial startup status 105 Initial value of semaphore counter 107 Initial value of system time 102 Initially Activated Task s es 81 NV 75 interrupt control reste 78 interrupt enable flag 77 Interrupt Handler eee 27 interrupt management s es 43 Interrupt vector definition 112 interrupt vector table 89 INTERRUPT MECTOR een 91 Intervals sera 110 Plisadas 76 77 Ol EE 29 33 OU e GE 29 33 79 ISM ISK wii decorate vinta hs died sa 29 35 79 SOLO etai iia 29 37 AA TOT 29 39 ISN
16. Language observe the following precautions 1 At the beginning of file be sure to include mr30 inc which is in the system direc tory 2 For the symbol indicating the handler start address make the external declara tion 3 Always use the RTS instruction subroutine return instruction to return from cyclic handlers and alarm handlers For examples INCLUDE mr30 ine 1 GLB cychand 2 9 2 cychand handler process BES ER 3 Figure 5 10 Example Handler Written in Assembly Language 5 Use the GLB pseudo directive 5 3 The Use of INT Instruction 5 3 The Use of INT Instruction MR30 has INT instruction interrupt numbers reserved for issuing system 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 48 and be sure to use some other numbers Table 5 2 Interrupt Number Assignment Interrupt No System calls Used 32 System calls that can be issued from only tasks 33 System calls that can be issued from only task independent sections System calls that can be issued from both tasks and task independent section 34 ret int system call 35 dis dsp system call 36 loc cpu system call 37 ext tsk system call 38 System calls that can be issued from only tasks 39 System calls that can be issued from only task independent sections System calls that can be issued from both t
17. NMI 254 FIX_INTERRUPT_VECTOR Reset 255 FIX_INTERRUPT_VECTOR 6 1 3 6 1 Configuration File Creation Procedure Configuration File Example The following is the configuration file example 360 J KK ok ok ok o ok o ok o oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko ok oko ok ok ok kok A k k 361 362 363 364 365 366 367 368 369 370 371 372 313 374 375 376 371 378 379 380 381 OGY CORPORATION Copyright 2003 RENESAS TECHNO AND RENESAS SOLUTIONS CORPORATION MR30 System Configuration File El J KK HK ok o oko oko oko RR RR RR RR RR RR RR RR RR RR kok ok kok kok A RA System Definition system stack size priority message size system IPL timeout y System Clock Definition clock mpu clock timer IPL unit time initial time y Task Definition task 1 entry_address stack_size priority context initial_start y task 2 entry_address stack_size priority context initial_start y task 3 entry_address stack_size priority context initial_start y flag 1 name y semaphore 1 name initial_count y mailbox 1 name buffer_size y memorypool 1 name section num_block siz_block 0x20 3 32 6 NO 10MHz A0 5 0 5ms 1 0x10 0xffff _taskl 0x20 1 RO R1 R2 A0 ON _task2 512 2 RO R1 R2 A0 O
18. Symbol Definition range YES or NO Specify YES when using or NO when not using tslp tsk twai flg twai sem and trov msg Task Pause Definition format Symbol Definition range YES or NO Specify YES when usig or NO when not using the Task Pause function of PD30 s OS Debug Function System Clock Definition Procedure lt lt Format gt gt System Clock Definition clock D I mpu clock MPU clock timer Timers used for system clock IPL System clock interrupt priority level unit time Unit time of system clock initial time Initial value of system time 3 If you define O here no system clock interrupt and OS dependent interrupt handlers can be used at all 6 1 Configuration File Creation Procedure 101 lt lt Content gt gt 1 MPU clock Definition format Freguency in MHz Definition range None Define the MPU operating clock freguency of the M16C in MHz 2 Timers used for system clock Definition format Symbol Definition range e 16C 60 Series AO to A4 BO to B5 OTHER NOTIMER 16C 30 Series AO to A3 B1 to B2 OTHER NOTIMER 16C 20 Series AO to A7 BO to B5 X0 to X2 OTHER NOTIMER 16C 10 Series OTHER NOTIMER Define the hardware timers used for the system clock The configurator don t check the timer setting for each series For M16C 10 Series you set OTHER and describe the timer setting in the startup fi
19. Task2 Interrupt vector area INTERRUPT VECTOR section Fix Interrupt F FIX_INTERRUPT_VECTOR section Figure 9 2 Memory map app_prog section Application ROM 9 Executing the configurator cfg30 10 Create an mrc file in which every system call is described Compiling the source pro gram creates a file having the extension mrc in the work directory Create an mrc file making reference to this Executing make clean in makefile created by cfg30 deletes the mrc file so be careful 11 Generating a system You execute the make command to generate a system 12 Carrying out steps 7 through 11 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 71 If the file mrtable a30 is not held in the current directory execute make command to generate a system a CCE CY E 49 alarm handler ee 48 69 Alarm Handler eee 27 Alarm handler definition 111 alarm handlers A 74 AND Walt 4 cette a iia 37 ASTON ro den inte ae 127 ASIN SOC ici i n 90 91 Wi A Ai 92 DSS FO un nr 92 SNE a 92 CV Le na 92 EE 92 O 92 U CSI Cit idas db 90 92 GAN WU Diese en 36 O30 cite led 19 NG Prise denken 32 Clear spec fication s es 37 CUP e EE 37 configuration file 114 configurator 19 61 118 119 121 CONLEXL OPA E ees e age Sde 27 105 qima E 82 dicha ANNER 48 69 Cyclic
20. 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 having 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 7 On condition that the ROM program burning step need not be performed 3 1 Concept of Real time OS 11 Key input Remote control LED illumination microcomputer microcomputer microcomputer Arbiter 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 Individual 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 development 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 operatedby a number of microcomputers are placed u
21. call procedures refer to the MR30 Reference Manual Reguirements for MR30 Use When creating programs based on the MR30 it is necessary to purchase the following product of Re nesas C compiler M3T NC30WA for M16C 60 30 20 10 Series When these related products are used increased program development efficiency is ob tained Document List The following sets of documents are supplied with the MR30 Release Note Presents a software overview and describes the corrections to the Users Manual and Refer ence Manual Users Manual PDF file Describes the procedures and precautions to observe when using the MR30 for programming purposes Reference Manual PDF file Describes the MR30 system call procedures and typical usage examples Before reading the Users Manual be sure to read the Release Note 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 MR30 for your product development purposes only and are not allowed to use it for the other purposes You should also note that this manual does not guarantee or permit the exercise of the right of software use 1 Hereinafter abbreviated real time OS 2 The uITRON Specification is originated by Dr Ken Sakamura and his laboratory members at the Faculty Science of University of Tokyo Therefore Dr Ken Sakamura holds the copyright on the uITRON Specification
22. command option is erroneous cfg30 Error illegal argument gt lt xx gt The configurator s startup format is erroneous cfg30 Error can t write open lt XXXX gt The XXXX file cannot be created Check the directory attribute and the remaining disk capacity available cfg30 Error can t open lt XXXX gt The XXXX file cannot be accessed Check the attributes of the XXXX file and whether it actu ally exists cfg30 Error can t open version file The MR30 version file version cannnot be found in the directory indicated by the environment variable LIB30 cfg30 Error can t open default configuration file The default configuration file cannnot be accessed default cfg is needed in the current direc tory or directory LIB30 specifying cfg30 Error can t open configuration file lt xxxx cfg gt The configuration file cannot be accessed Check that the file name has been properly desig nated cfg30 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 defini tion cfg30 Error Unknown XXXX gt lt xx gt near line xx xxxx cfg The symbol definition in definition item XXXX is incorrect Check the valid range of definition cfg30 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
23. dly tsk or tslp tsk system call wakes up after the specified time elapse The request of the task placed in the WAIT state by the wai_flg twai_flg wai sem twai_sem rcv_msg or trcv_msg system call is fulfilled The WAIT state is forcibly cleared by the rel_wai or irel_wai system call When the SUSPEND state clear request is made to a task in the WAIT SUSPEND state that task goes into the WAIT state Since a task in the SUSPEND state cannot request to be placed in the WAIT state status change from SUSPEND to WAIT SUSPEND does not possi bly occur 6 DORMANT This state refers to the condition in which a task is registered in the MR30 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 When a handler issued the isus_tsk system call to place a currently executed task in the SUSPEND state status switching is effected directly from RUN to SUSPEND This is exceptional status change and should be kept in mind 20 If the SUSPEND request is made to a task in the WAIT state that task goes into the WAIT SUSPEND state 21 rsm_tsk or irsm_tsk system call 22 ext_tsk system call gt ter_tsk system call 24 Chapter 3 Introduction to MR30 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 nece
24. 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 cfg30 Error bad start up file XXXX There is unnecessary start up file in the current directory cfg30 Error no source file No source file is found in the current directory cfg30 Error zero divide error near line xxx xxxx cfg A zero divide operation occured in some arithmetic expression cfg30 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 cfg30 Error RO must exist in task x context near line xxx xxxx cfg You must select RO regiseter in task x context 6 2 Configurator Execution Procedures 123 cfg30 Error can t define address match interrupt definition for Task Pause Fu nction near line xxx xxxx cfg Another interrupt is defined in interrupt vector definition needed by Task Pause Function cfg30 Error Set system timer system timeout YES near line xxx xxxx cfg Set clock timer symbol except NOTIMER 124 Chapter 6 Using Configurator Warning messages The following message are a warning A warning can be ignored providing that its content is understood cfg30 Warning system is not defined xxxx cfg cfg30 Warning system XXXX is not defined xxxx cfg System definition or system definition item XXXX is omitted in the configuration file cfg30 Warning system
25. from other task WAIT SUSPEND state WAIT state clear SUSPEND request request from other task SUSPEND SUSPEND state state dear request Forced termination request from other task DORMANT state Task activation Figure 3 13 MR30 Task Status Transition 1 RUN 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 condi tions occurs The task has normally terminated itself The task has placed itself in the WAIT 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 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 any of the above conditions occurs rescheduling takes place so that the task having the highest priority among those in the RUN or READY state is placed in the RUN state and the execution of that task starts 10 Upon ext_tsk system call 11 Upon slp tsk tslp tsk dly tsk wai flg twai flg wai sem twai sem rev msg or trcv_msg system call 12 Upon chg pri system
26. function When using the 32 bit message size you must specify libraries mr30lm lib and c30mrlm lib When using the 16 bit message size libraries mr30 lib and c30mr lib must be specified 6 Compile Option Specifications You must pay close attention to the specified compile options when compiling a file using a system call related to the mailbox functions When using 32 bit message size specify compile option Dfar msg 1 This option does not need to be specified when using the 16 bit mes sage size 7 Assemble Option Specifications Make sure to specify assemble option F when assembling the source file described in the assemble language which issues the system call 8 Process Before Linking Before executing a link make sure to execute the following two processes in the order as are listed 1 mkmrtbl 2 as30 mrtable a30 MR30 comes equipped with the mkmrtbl utility Execute it in the directory where Configurator cfg30 executes If that is not the same directory where the system call file XXX mrc and the r30 file are output by C Compiler or Assembler you need to specify the directory at parameters of mkmrtbl as following Ex mkmrtbl outputdir 6 3 Editing makefile 127 Chapter 7 Application Creation Guide 130 Chapter 7 Application Creation Guide 7 1 Processing Procedures for System Calls from Handlers When a system call is issued from a handler task switching does not occur unlike in the case of a sys tem ca
27. generated Consequently all stacks used by the interrupt handler are the system stack Chapter 8 Sample Program Description 138 Chapter 8 Sample Program Description 8 1 Overview of Sample Program As an application example of MR30 this section shows a program to light or turn on the LEDs con nected one for one to the M16C 80 series ports PO through P8 In this application example each port is controlled by using each independent function Table 2 1 lists these functions Table 8 1 Sample Program Function List Function Type ID No Priority Function Name main Task 1 1 Wake up tasks sequentially from task2 to task4 task2 Task 2 2 Controls the input output of port7 task3 Task 3 3 Controls the input output of port8 task4 Task 4 4 Controls the input output of port9 cyh1 Handler Modifies the output data of port10 The main mask first sets ports 7 8 9and 10 for the output mode Then task4 is activated from task2 task2 sets initial value Oxff to port 7 to turn on all ports and enters a wait state where it waits until the system clock counts 25 Then it sets value 0x01 to port 7 to light the LED It again enters a wait state where it waits until the system clock counts 25 and shifts the data value of port 7 one bit to turn on This operation is repeated 8 times Example 0000001 gt 00000010 gt 000001 00 This is in an endless loop Figure 8 1 depicts how port 7 is turned on
28. 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
29. in a program 1 Name Definition format Symbol Definition range None Define the name with which a mailbox is specified in a program 2 The maximum number of messages Definition format Numeric Value Definition range 0 16383 Define the maximum number of messages that can be stored in a mailbox An error is returned if an attempt is made to store messages exceeding this limit Fixed size memorypool definition This definition is necessary to use Fixed size memorypool function lt lt Format gt gt Fixed Memorypool Definition memorypool ID No name Name section Section Name num_block Number of blocks for Memorypool siz_block Block size of Memorypool 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 lt lt Content gt gt Define the following for each memorypool ID number 1 Name Definition format Symbol Definition range None Define the name with which a memorypool is specified in a program 108 Chapter 6 Using Configurator 2 Section name Definition format Symbol Definition range None Define the section name allocated memorypool Be sure to allocate this section in your section file asm_sec inc or c_sec inc If you don t define this section name in
30. issuing dis dsp several times The above status transition can be summarized in Table 5 3 below Table 5 3 Interrupt and Dispatch Status Transition by dis dsp and loc cpu Status Contents of Statusdis dis dsp is ena dspis loc cpu is unl cpu is No Interrupt Dispatch executed executed executed executed 1 Enabled Enabled 22 gt 1 3 gt 1 2 Enabled Disabled gt 22 gt 1 gt 3 gt 1 3 Disabled Disabled x x 3 gt 1 5 7 Regarding Initially Activated Task 81 5 7 Regarding Initially Activated Task MR30 allows you to specify a task that starts from a READY state at system startup This specification is made by setting the configuration file Refer to page 105 for details on how to set 82 Chapter 5 Detailed Applications 5 8 Modifying MR30 Startup Program MR30 comes with two types of startup programs as described below start a30 This startup program is used when you created a program using the assembly language 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 Initialize the processor after a reset initialize C language variables crtOmr a30 only Set the system timer Initialize MR30 s data area Copy these startup programs from the directory indicated by environment variable LIB30
31. printer engine task while 1 slp_tsk printf printer engine operation n void sent_in Centronics interface handler Process input from Centronics interface if l page input completed iset flg ID pagein setptn Figure 4 2 Program Example 60 Chapter 4 Applications Development Procedure Overview 4 2 2 Configuration File Preparation Prepare the configuration file in which the task entry address stack size and the like are defined Figure 4 3 shows the configuration file named Ibp cfg of the laser beam printer simulation program System Definition system stack_size 1024 priority 5 system_IPL 4 Y System Clock Definition clock mpu_clock 20MHz timer A0 IPL 4 unit time 10ms initial time 0 0 0 Task Definition task 1 entry_address main stack_size 512 priority 1 initial_start ON task 2 entry_address image stack_size 512 priority 2 task 3 entry_address printer stack_size 512 priority 4 task 4 entry_address idle stack_size 256 priority 5 Eventflag Definition flag 1 name pagein Interrupt Vector Definition interrupt_vector 0x23 os_int YES entry_address sent_in y Figure 4 3 Configuration File Example 4 2 Development Procedure Example 61 4 2 3 Configurator Execution Execute the configurator cfg30 to
32. reasons It is therefore recommended that customers con tact 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 inaccu racies 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 information 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 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 prod
33. stack section This section is provided for each task s user stack and system stack This section must be mapped between 0 and FFFFH near area MR_HEAP section This section stores the variable size memorypool MR_KERNEL section This section is where the MR30 kernel program is stored MR_CIF section This section stores the MR30 C language interface library MR_ROM section This section stores data such as task start addresses that area referenced by the MR30 ker nel program section This section stores user programs This section is not used by the MR30 kernel at all Therefore you can use this section as de sired INTERRUPT VECTOR section FIX INTERRUPT VECTOR section This section stores interrupt vectors The start address of this section varies with the type of M16C 60 30 20 10 series microcomputer used The address in the sample startup program is provided for use by the M16C 60 30 20 10 series micro computers This address must be modified if you are using a microcomputer of some other group 5 9 Memory Allocation 91 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 defined in the section definition file asm sec inc of the sample startup program for th
34. switching is initiated after the system returns to the interrupted system call process ing See Figure 7 2 TaskA OS Interrupt handler wup tsk Save Registers Save Registers Interrupt system call processing iset To Restore Registers Task selection SP lt User nn Restore Registers TaskB ret int Figure 7 2 Processing Procedure for a System Call from a Handler that caused an interrupt during System Call Processing 7 1 Processing Procedures for System Calls from Handlers 133 7 1 3 System Calls from a Handler That Caused an Interrupt during Handler Execution Let us think of a situation in which an interrupt occurs during handler execution this handler is herein after referred to as handler A for explanation purposes When task switching is called for as a handler hereinafter referred to as handler B that caused an interrupt during handler A execution issued a sys tem call task switching does not take place during the execution of the system call ret_int system call returned from handler B but is effected by the ret_int system call from handler A See Figure 7 3 TaskA Interrupt handler A Interrupt handler A Interrupt j Save Registers OS SP lt System Save Registers Interrupt P processing iset_flg Restore Register Restore Register EE Task selection ret_int SP lt User Restore Regi
35. than the total number of objects 122 Chapter 6 Using Configurator cfg30 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 cfg30 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 system call of system definition item cfg30 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 interrupt vector definition cfg30 Error XXXX is not defined xxxx cfg XXXX item must be set in your configuration file cfg30 Error system s default is not defined These items must be set int the default configuration file cfg30 Error double definition lt XXXX gt near line xxx xxx cfg XXXX is already defined Check and delete the extra definition cfg30 Error double definition XXXX x near line xxx default cfg cfg30 Error double definition XXXX x near line xxx xxxx cfg The ID number in item XXXX is already registered Modify the ID number or delete the extra definition cfg30 Error you must define XXXX near line xxx xxxx cfg XXXX cannot be ommited cfg30 Error you must define SYMBOL near line xxx xxxx cfg This symbol cannnot be omitted cfg30 Error start up file XXXX not
36. 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 system call Task activation and other processing operations can be initiated by such a system call See Figure 3 9 Key input Renge s Task Real time OS i System call Task switching Figure 3 9 System Call When application programs are to be written in C language a system call is accomplished by making a function call as indicated below sta tsk ID main 3 If application programs are to be written in assembly language a system call is accomplished by mak ing an assembler macro call as indicated below sta tsk ID_main 3 18 3 2 1 Chapter 3 Introduction to MR30 System Call Processing When a system 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 request made by the system 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 system call generation and task switching Key input Task Register Save System call issuance SP lt OS Processing Task Sel
37. to makefile Using makefile or Makefile in the current directory or makefile ews or makefile dos in the directory indicated by the environment variable LIB30 as a template file the configurator cre ates makefile in the current directory 120 Chapter 6 Using Configurator 6 2 5 Precautions on Executing Configurator The following lists the precautions to be observed when executing the configurator f you have re run the configurator always be sure to execute make clean or delete all object files extension r30 and execute the make command In this case an error may occur during linking Do not modify the strartup program name and the section definition file name Otherwise an er ror may be encountered when executing the configurator The configurator cfg30 can only generate UNIX standard makefile or one conforming to UNIX standards Namely it does not generate MS DOS standard makefile 6 2 Configurator Execution Procedures 121 6 2 6 Configurator Error Indications and Remedies If any of the following messages is displayed the configurator is not normally functioning Therefore correct the configuration file as appropriate and the execute the configurator again Error messages cfg30 Error syntax error near line xxx xxxx cfg There is an syntax error in the configuration file cfg30 Error not enough memory Memory is insufficient cfg30 Error illegal option gt lt x gt The configurator s
38. 0 kernel offers the following eventflag system calls Setting the Eventflag set flg iset_flg Sets the eventflag so that a task waiting the eventflag is released from the WAIT state Clearing the Eventflag clr_flg Clearing the Eventflag Waiting for eventflag wai flg twai flg Waits until the eventflag is set to a certain pattern There are three modes as listed below in which the eventflag is waited for AND wait Waits until all specified bits are set ORwait Waits until any one of the specified bits is set Clear specification Clears the flag when the AND wait or OR wait condition is met Getting eventflag pol flg Examines whether the eventflag is in a certain pattern In this system call tasks are not placed in a wait state Refer Eventflag Status ref flg Checks the existence of the bit pattern and wait task for the target eventflag Figure 3 24 shows an example of task execution control by the eventflag using the wai flg and set flg system calls The eventflag has a feature that it can wake up multiple tasks collectively at a time In Figure 3 24 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 system call the tasks that meet the wait conditions are removed sequentially from the top of the gueue In this diagram the tasks that meet the wait conditions are task A task C task E and task F Out of these tasks task A task C
39. 1 O ready oueuie eee eee een 24 READY State ea 22 real time OS eee een 4 real time OS een 10 ref Alm cee essen 49 NET C C een 49 CR O JPN P O naa 37 El 42 Feb MPR inant EP CO O VO E tate 45 e Wun RE 47 FET Se Os tein A EVR Pud ol ave n 40 ref USK reinste 34 registers Of bank 75 105 Registers Of bank 112 RE Tica A 73 Tallin 45 A P R R L P sn 47 CR etsii ira 33 ld 29 43 67 ROM write form Ile 8 O a a 92 FOM Oca iasa a 92 CONN Eriin died 92 e ul Le arca et k nake ta 92 OU OG E 33 79 round robin scheduling 33 ECH 35 KEE 74 RUN STALE icono agn iaei aiaiai 21 a sample startup ee e eee eee een 92 Schedule 45 Seen 43 section El Cie EE 91 section TIC cis eb 90 Sermmatphore ANEREN 20 semaphore counter 2 39 Semaphore definition 106 Semaphore Oueie eeeessesrererrerrer renee 22 separate ROMS een 102 144 El td 37 O akad kok onen 49 e LEE 78 SIG Mita iaa 39 SA anerkannte rennen 35 80 software interrupt z eee 75 Specification Version cs 51 SECS OOO 32 SLACK EE EE 91 SLACK EE 134 Start address of Lack AAA 104 Sa iii ia 82 startup progr am 91 Startup Program 82 Startup Ume EE 111 SUS E 35 SUSPEND State ee 22 SIE ain en ic 97 synchronization functions attached to task35 Ce vu LEE 116 system all 17 System Call Broceeelng 18 System Calls Exclusive for Handlers 29 Index system dock u eee eee 101 System Clock Definition Procedure
40. 39 sta tsk ID task2 1 40 sta tsk ID task3 1 41 sta tsk ID task4 1 42 43 44void task2 451 46 int k 47 48 P7 Oxff 49 50 while 1 51 dly_tsk 25 52 pt7 0x01 53 P7 pt7 54 for k 1 k lt 8 k 55 dly_tsk 25 56 pt7 lt lt 1 57 P7 pt7 58 59 60 61 62 63void task3 641 65 int k 66 P8 Oxff 67 68 while 1 69 dly_tsk 50 70 pt8 0x01 DL P8 pt8 72 for k 1 k lt 8 k T3 dly_tsk 50 74 pt8 lt lt 1 15 P8 pt8 80void task4 ER ER int k 83 P9 Oxff 85 while 1 86 dly_tsk 100 87 pt9 0x01 88 P9 pt9 89 for k 1 k lt 8 k 90 dly_tsk 100 91 pt9 lt lt 1 92 P9 pt9 97void cyhl 981 99 if pt10 0 100 pt10 0x01 101 P10 pt10 102 pt10 lt lt 1 103 Chapter 8 Sample Program Description 8 3 Configuration File VO OO Jon BUDNF O OGoOVGaOUG BUN 141 J KK HK ok ok oko oko o oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko oko ok oko ok ok ok kok ER Oe COPYRIGHT C 2003 RENESAS TECHNOLOGY CORPORATIO AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED MR30 System Configuration File fap SId smp cfg v 1 8 2003 08 22 12 59 49 muraki Exp EE T o Te Se EOE hla Tey Auto posta oo S Aho la mu ono a System Definition system stack size 1024 priority 10 system IPL 4 message size 16 t
41. 5 24 Initialize Macro declaration 25 3 26 N_BZERO macro TOP_ SECT_ 27 mov b 00H ROL 28 mov w TOP_ amp OFFFFH Al 29 mov w sizeof SECT_ R3 30 sstr b 31 endm 32 33 N_BCOPY macro FROM_ TO_ SECT_ 34 mov w FROM amp OFFFFH AO 35 mov b FROM _ gt gt 16 RI1H 36 mov w TO_ Al 37 mov w sizeof SECT_ R3 38 smovf b 39 endm 40 41 BZERO macro TOP_ SECT_ 42 push w sizeof SECT_ gt gt 16 43 push w sizeof SECT amp Offffh 44 pusha TOP gt gt 16 45 pusha TOP_ Offffh 46 47 glb _bzero 48 jsr a _bzero 49 endm 50 5A 52 BCOPY smacro FROM_ TO_ SECT 53 push w sizeof SECT gt gt 16 54 push w sizeof SECT Offffh 55 pusha TO_ gt gt 16 56 pusha TO amp Offffh 57 pusha FROM_ gt gt 16 58 pusha FROM amp Offffh 59 60 glb _bcopy 61 jsr a _bcopy 62 endm 63 64 65 Interrupt section start 66 r r r r r r glb section SYS_INITIAL __SYS_INITIAL MR_KERNEL CODE ALIGN Chapter 5 Detailed Applications after reset this program will start ldc __Sys_Sp amp OFFFFH ISP mov b 2H OAH mov b 00 PMOD mov b 0H OAH iag 00H FLG ldc __Sys_Sp 0FFFFH fb tdg SB sb set initial ISP Set Processor Mode Regsiter MR RAM DATA 0 zero clear H BZERO MR RAM top MR RAM ISSUE SYSTEM CALL DATA INITIALIZE AE __MR_NODBG 1 else mov b 0 __DBG_MO
42. AM size that must at least be available for MR30 to be used is 16 bytes Furthermore one additional task requires 11 bytes each without timeout function But it requires 15 bytes each with timeout function A section named MR_RAM_DBG is provided in addition to the MR RAM section The MR RAM DBG section is necessary for using the OS s debugging functions The RAM used for this section amounts to 17 bytes with the Task pause functions being in use or to 13 bytes with the Task pause function being not in use 7 3 Stacks 135 7 3 Stacks 7 31 System Stack and User Stack The MR30 provides two types of stacks system stack and user stack User Stack One user stack is provided for each task Therefore when writing applications with the MR30 it is necessary to furnish the stack area for each task System Stack This stack is used within the MR30 during system call processing When a system call is is sued from a task the MR30 switches the stack from the user stack to the system stack See Figure 7 4 The system stack use the interrupt stack ISP Task MR30 system call processing User Stack Save Registers XXX_XXX Stack switching System call processing System Stack Task selection 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
43. DE endif So So Se Se Se So So Ne Ne e So Se Se So Se NEAR area initialize bss zero clear N_BZERO bss_SE_top bss_SE N_BZERO bas SO top bss SO ERO bss NE top bss NE Di Di ERO bss_NO_top bss_NO initialize data section N BCOPY data SEI top data SE top data S N BCOPY data SOI top data SO top data S N BCOPY data NEI top data NE top data N N BCOPY data NOI top data NO top data NO Gl o LA FAR area initialize bss zero clear BZERO bss FE top bss FE BZERO bss FO top bss FO Copy edata E O section from edata EI OI section BCOPY data FEI top data FE top data FE BCOPY data FOI top data FO top data FO ldc __Sys_Sp amp 0OFFFFH sp lde __Sys_Sp amp OFFFFH fb Initialize standard I O glb jsr a init init Set System IPL and 5 8 Modifying MR30 Startup Program 85 Set Interrupt Vector DH mov b 0 ROL mov b __SYS_IPL ROH ldc RO FLG set system IPL ldc __INT_VECTOR gt gt 16 amp OFFFFH INTBH ldc __INT_VECTOR amp OFFFFH INTBL IF USE TIMER DH System timer interrupt setting DH mov b f stmr mod val stmr mod reg set timer mode A mov b 1H OAH E bset 6 07H mov b fstmr int IPL stmr int reg set timer IPL A belr 6
44. FF _task3 9125 3 RO R1 R3 A0 OFF flgl seml mbx1 3 mp11 FIX_MEM 100 ms SBD BA ss ss ss DBA DA DA DB BR BRD D I variable_memorypool 1 max_memsize 400 heap_size 1600 y cyclic_hand 1 interval counter Oxff mode TCY OFF entry address c hl y alarm_hand 1 time 1 0xff Oxffff entry_address _alhl y interrupt_vector 6 os_int YES entry_address _intr l Chapter 6 Using Configurator 6 2 Configurator Execution Procedures 115 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 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 di rectory Default configuration file default cfg This file contains default values that are referenced when settings in the configuration file are omitted This file is placed in the directory indicated by environment variable LIB30 or the cur rent directory If this file exists in both directories the file in the current directory is prioritized over the other makefile template files makefile ews makefile dos makefile Makefile Th
45. Figure 3 37 It cyclically actuates according to the system clock interrupt count For cyclic handler control purposes its activity status is specified by the system call For example TCY_ON may be selected to change the activity status from OFF to ON See Figure 3 38 or TCY INI ON may be select ed to initialize the handler count See Figure 3 39 Refer Cycle Start Handler Status ref cyc Checks the activity of the target cycle handler and the time remaining till the next start Refer Alarm Handler Status ref alm Checks the time remaining till the target alarm handler is next started Note that the system timer function is not indispensable Therefore if the following system calls and the time management function are not to be used there is no need to make an exclusive use of one timer for the MR30 50 Chapter 3 Introduction to MR30 1 System clock setup reading 2 Cyclic handler 3 Alarm handler 4 dly_tsk system call 5 system call with Timeout Figure 3 37 Cyclic Handler tcyorr So TCY_ON p l l l l l l l l Figure 3 38 Cyclic Handler TCY ON Selected as Activity Status TCY OFF act cyc TCY ON l I J l l l l TCY_INI_ON Figure 3 39 Cyclic Handler TCY_INI_ON Selected as Activity Status 4 set tim get tim system call 3 5 MR30 Kernel Structure 51 3 5 11 Version Management Function The information on the MR30 version can be obtained using the get ver system call Th
46. Memorypool Status ref_mpf Checks the number and size of free blocks in the target memorypool 46 Chapter 3 Introduction to MR30 Variable size Memorypool Management Function The technique that allows you to arbitrary define the size of memory block acquirable from the memo rypool is termed Variable size scheme The MR30 manages memory in terms of four fixed size memory block sizes The MR30 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 variable_memorypool max_memsize 400 lt Maximum size heap_size 5000 i Defining a variable size memorypool 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 MR30 performs calculations based on the specified size and selects and allocates the optimum one of four fixed size memory block sizes The MR30 cannot allo cate a memory block that is not one of the four sizes System calls the MR30 provides include the following e Acquiring a memory block pget_blk 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 memorypool The following equations define the block sizes a max_memsize X 1 X x 8 1 x 8 b ax2 c ax4 d ax8 ma
47. O MSG Adi 29 42 AER ae 29 32 ISUS Sica ia 29 35 79 ITRON Specification seeren 6 IWUP ASK ne 29 35 M Kernel Slash dla alu Gila les 30 U LIB SO ea telten eden a 118 EMG30 cece dle be ee ee 61 EN ieee tian Aaa 8 127 VOC CD EE 79 VOC MCU is ete TAS 43 78 80 Wi Allee EE 41 Mailbox definition sesser 107 Mailbox Oueie eee 22 makefile NENNEN 120 127 Makefile ra artes el 116 makefile doS iriiria niniin tania 116 Mmakefile eWS ooocococccnncccnoncccnonnnononnnnarnncnnnnos 116 Manufacturer Name 51 memory allocation eee 90 Message oueie nenn 4 Message SiZB eee eee 100 MPU dock een 101 MPU Information ne 51 MR Clara rear ne 91 MR HEAP uvas 91 109 MR KERNEL een 91 MR RAM een 91 108 134 MR RAM DBG 91 MRoRO Mica ica 91 MAS ii tia 8 MR30 Specifications Overview 7 MO riadas 64 HWSO C nen 70 72 74 116 multiple Interrugpte eee 73 O MES 8 127 O Operating Principles of Real time OS 13 OR Walton dae 37 OS interrupt disable level 89 100 OS dependent interrupt handler67 72 76 112 OS independent interrupt handler 68 76 OS independent Interrupt Handler 73 O ee L E 41 Poet Difin e a a e EE ea 45 pg DIK area eid estes eee 46 ee D EE 37 BEO TOSO E 42 pred Mita ns 40 Priory iniiai 24 100 processor mode register 89 Product Control Information 51 Product Version ee 51 DEG aM ia by eatin tides 9
48. O O O get_tid O O O O ref_tsk O O O O sus_tsk O x x x isus_tsk x O O O rsm_tsk O x x x irsm tisk x O O O slp tsk O x x x tslp_tsk O x x x dly tsk O x x x wup_ tsk O x x x iwup_tsk x O O O can_wup O O O O set_flg O x x x iset_flg x O O O clr_flg O O O O wai flg O x x x twai flg O x x x pol flg O O O O ref flg O O O O 3 5 MR30 Kernel Structure 53 System Call Task Interrupt Handler Cyclic Handler Alarm Handler sig sem O isig sem wai sem twai sem preg sem ref sem snd msg isnd msg rev msg trev msg prov msg ref mbx pget_blf rel_bif ref_mpf pget blk rel blk ref mpl ret int D loc_cpu unl cpu set tim get tim act cyc ref cyc ref alm get ver vrst msg vrst bt vrst blk OO OO Oo o Oo o o0 o o O o x OJO O OJO X x x xlololololo o x x Qlo x x ololololo x x o x o o x x o x X X X O O O O O O x x x Ox x OJOJO O O x x Ox O O x x o x x x x OJO O O O Oo x x X O IX x O O 0 O0 O IX x Ox O O x x o x 42 The System Call can t be issued from the Interrupt Handler in C language Chapter 4 Applications Development Procedure Overview 56 Chapter 4 Applications Development Procedure Overview 4 1 General Description The MR30 application programs are generally developed using the
49. The number of Cyclic handlers 3 3 5 Preparing configuration files You prepare configuration files based on the result brought by setting up the system configu ration maxdefine definition 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 Thus the individual items must be equal in number to each other in these applications maxdefine max_task max_flag max_sem max_mbx max mpl max cyh LA AUT LA UI No an ae Ne Se Se l No means is available to deal with variable length memory pools in the maxdefine definition So if you use the variable length memory pool functions in either of two applications give the same definitions of variable length memory pools in the two configuration files 145 system definition You need to make the following items which are dealt with in the system definition common to two applications message size timeout task pause priority O clock definition initial time The value assigned to this item in one of two applications can be different from its counter part Avoid defining this item in one application and omitting it in the other application Be sure to deal with this item in the same manner either define or omit in two applications O task definition initial start Switch this item ON only in the task first started up after the System is star
50. 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
51. al time operating system conforming to the uITORN Specification The MR30 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 microcomputer As the uITRON Specification is a subset of the ITRON Specifica tion most of the knowledge obtained from published ITRON textbooks and ITRON seminars can be used as is Further the application programs developed using the real time operating systems conform ing to the ITRON Specification can be transferred to the MR30 with comparative ease High speed processing is achieved MR30 enables high speed processing by taking full advantage of the microcomputer archi tecture Only necessary modules are automatically selected to constantly build up a system of the minimum size The MR30 is supplied in the form of a M16C 60 series microcomputer objective library Therefore the Linkage Editor LN30 functions are activated so that only necessary modules are automatically selected from numerous MR30 functional modules to generate a system Thanks to this feature a system of the minimum size is automatically generated at all times With the C compiler NC30 it is possible to develop application programs in C language When the C compiler NC30 is used MR30 application programs can be developed in C lan guage Also note that an interface library is supplied on software disk to permit ca
52. and task E are removed from the gueue However since task E is waiting in clear specification the flag is cleared when task E is remove from the gueue Therefore task F is not removed from the gueue 38 Chapter 3 Introduction to MR30 Flag queue TaskA TaskB TaskC TaskD TaskE TaskF Flag pattern 0 Wait pattern 0x0F OxFF 0x0F OxFF OxF F 0x0F Wait mode OR AND AND AND CLR OR CLR OR set Ho v TaskB TaskD TaskF Flag pattern 0x0F Flag pattern 0x0F 0 Figure 3 24 Task Execution Control by the Eventflag 3 5 MR30 Kernel Structure 39 3 5 6 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 as shown in Figure 3 25 communication line to task connections can be made without incurring contention Communication Line Communication Line Communication Line S Figure 3 25 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 26 Acquired Returned after use Figure 3 26 Semaphore Counter The MR30 kernel offers the following semaphore synchronization system calls Sig
53. ange None Define the start address of the alarm handler The function name defined here causes the fol lowing declaration statement to be output in the id h file pragma ALMHANDLER function name Interrupt vector definition This definition is necessary to use Interrupt function lt lt Format gt gt Interrupt Vector Definition interrupt_vector Vector No 14 os_int OS dependent interrupt handler entry address Start address y The vector number can be written in the range of O 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 rutine interrupt control register interrupt causes etc for this de fined interrupt You nead to create that Note Registers of bank 1 can not be specified in the configuration file Insert declaration pragma INTER RUPT B after the id h include command in the C language source file Example include lt mr30 h gt include id h pragma INTERRUPT B OS independent interrupt handler function name Registers of bank 1 in the OS dependent interrupt handler can not be described in C language You can describe in assembly language only Describe the interrupt handler entrance and exit as follows Make sure you clear B flag
54. ask 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 RO R1 Actual Register p PC Real time OS Remote control Task RO R1 Ltr PC Figure 3 6 Task Switching 3 1 Concept of Real time OS The example presented in Figure 3 1 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 Remote control Task Key input Task Real time OS Figure 3 8 shows the register and stack area of one task in detail In the MR30 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 LED illumination gt Figure 3 7 Task Register Area 16 Chapter 3 Introduction to MR30 Register not stored Key input task stack Key input Task M ar Register stored Figure 3 8 Actual Register and Stack Area Management 3 2 System Call 17 3 2 System Call How does the programmer use the real
55. asks and task independent section 40 extension system call 41 47 Reserved for future extension 5 4 The Use of registers of bank The registers of bank is 0 when a task starts on MR30 MR30 does not change the registers of bank in processing kernel You must pay attention to the followings Don t change the regisers of bank in processing a task H an interrupt handler with regisers of bank 1 have multiple interrupts of an interrupt handler with regisers of bank 1 the program can not execute normally 76 Chapter 5 Detailed Applications 5 5 Regarding Interrupts 5 5 1 Types of Interrupt Handlers MR30 s interrupt handlers consist of OS dependent and OS independent interrupt handlers The following shows the definition of each type of interrupt handler OS dependent interrupt handler The OS dependent interrupt handler is defined as one that satisfies one of the following two conditions Interrupt handlers issuing a system call Interrupt handlers including multiple interrupt handlers issuing a system call The OS dependent interrupt handler s IPL value must be below the OS interrupt disable level system IPL IPL 0 to system IPL OS independent interrupt handler The OS independent interrupt handler is defined as one that satisfies both of the following two conditions Interrupt handlers not issuing a system call Interrupt handlers that do not have multiple interrupts of interrupt ha
56. ate for certain time dly tsk Keeps a task waiting for a certain time Figure 3 35 shows an example in which task execution is kept waiting for 10 ms by the dly tsk system call dly tsk 10 Task HF FF Figure 3 35 dly tsk system call Specifying a timeout value in the wait state causes the MR30 to switch to a fixed wait time status You can specify a timeout in a system call for switching the task to the wait state The sys tem calls are named tslp tsk twai flg twai sem and trev msg If the conditions for exiting the wait state are not satisfied prior to the specified timeout time elapsing error code E TMOUT is returned and the wait state is cancelled If the conditions for exiting the wait state are satisfied error code E_OK is returned See Figure 3 36 The MR30 system clock is used as the reference time for the timeout 38 get tim system call 3 set tim system call 4 Cancel forced wait state 3 5 MR30 Kernel Structure 49 tslp tsk 50 E TMOUT WAIT state A 50 Timeout value tslp tsk 50 E OK RUN state a ps WAIT state es iwup tsk Figure 3 36 Timeout Processing Setting the System Time set tim Reading the System Time get tim The number of system clock interrupts generated after resetting is counted to indicate the system time in 48 bit data Controlling the Cyclic Handler Activity act cyc The cyclic handler is a program running at fixed time intervals See
57. before issuing the ret_int system call Example interrupt fset B fcr B ret_int 112 Chapter 6 Using Configurator MR30 kernel does not change the registers of bank NMI and Watch dog timer Interrupt can not be OS independ interrupt handler lt lt Content gt gt 3 OS dependent interrupt handler Definition format Symbol Definition range YES or NO Define whether or not the handler is an OS dependent interrupt handler If it is an OS dependent interrupt handler define YES if it is an OS independent interrupt han dler define NO If you define YES the following declaration statement is output in the id h file pragma INTHANDLER fuction name Or if you define NO the following declaration statement is output in the id h file pragma INTERRUPT function name 4 Start address Definition format Symbol or function name Definition range None 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 Table 6 3 Fixed Interrupt Causes and Vector Numbers Interrupt vector number Section Name Undefined instruction 247 FIX_INTERRUPT_VECTOR Over flow 248 FIX_INTERRUPT_VECTOR BRK instruction 249 FIX_INTERRUPT_VECTOR Address match 250 FIX_INTERRUPT_VECTOR Single Step 251 FIX_INTERRUPT_VECTOR Watch dog timer 252 FIX_INTERRUPT_VECTOR DBC 253 FIX_INTERRUPT_VECTOR
58. box The messages that can be placed into this mailbox are 16 bit or 32 bit data Standard specifications are such that MR30 uses this data as the start address of a message packet However this data can be used simply as ordinary data Data Es Message Packet Figure 3 29 Meaning of Message The mailbox is capable of storing messages Stored messages are retrieved on the FIFO basis However the number of messages that can be stored in the mailbox is limited The maximum number of messages that can be stored in the mailbox is referred to as the Message queue size See Figure 3 30 34 According to the standard stated in ITRON Specification this data is to be used as the message packet first address 35 In this case Cast to the data of argument of the system call to convert into pointer types 36 First in first out 42 Chapter 3 Introduction to MR30 Message gueue Size Figure 3 30 Message gueue Size The MR30 kernel offers the following mailbox system calls Transmitting a Message snd msg isnd msg Sends a message or puts a message into the mailbox Receiving a Message rev msg trev msg Receives a message or obtains a message from the mailbox If the message is not in the mailbox the WAIT state prevails until the message is put in the mailbox Receiving a Message prcv_msg Receives a message This system call differs from the rcv_msg system call in that the former returns an error
59. call 13 Upon ichg_pri system call 22 Chapter 3 Introduction to MR30 2 READY state The READY state refers to the situation in which the task that meets the task execution con ditions 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 to the ready queue is placed in the RUN state Acurrently executed task has normally terminated itself Acurrently executed task has placed itself in the WAIT 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 ms 3 WAIT state When a task in the RUN state requests to be placed in the WAIT state it exits the RUN state and enters the WAIT state The WAIT state is usually used as the condition in which the com pletion of I O device I O operation or the processing of some other task is awaited The task goes into the WAIT state in one of the following ways The task enters the WAIT state simply when the slp tsk system call is issued In this case the task does not go into the READY state until its WAIT state is cleared explicitly by some other task The task enters and remains
60. code without incurring the WAIT state if the message is not found in the mail box Refer Mailbox Status ref_mbx Checks the existence of tasks waiting for messages to enter the target mailbox and checks the first message in the mailbox 3 5 MR30 Kernel Structure 43 3 5 8 Interrupt Management Function The interrupt management function provides a function to process requested external interrupts in real time The interrupt management system calls provided by the MR30 kernel include the following e Returning from interrupt handler ret int The ret int system call activates the scheduler to switch over tasks as necessary when re turning from the interrupt handler When using the C language this function is automatically called at completion of the han dler function In this case therefore there is no need to invoke this system call Disabling interrupts and task dispatch oc cpu The loc cpu system call disables OS dependent external interrupts and task dispatch Enabling interrupts and task dispatch unl cpu The unl cpu system call enables external interrupts and task dispatch Therefore this sys tem call re enables the interrupts and task dispatch that have been disabled by the loc cpu system call Figure 3 31 shows an interrupt processing flow Processing a series of operations from task selection to register restoration is called a scheduler 37 In the case that the interruput handler is spec
61. completed it is then necessary to register the applications program in the MR30 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 0X to the beginning of a numerical value or h or H to the end If the value be gins 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 0Xf12 0a12h Hexadecimal 0a12H 12h 12H Decimal 32 017 Octal 170 170 Binary 101110b 101010B 51 The system distinguishes between the upper and lower case l
62. created by the user It consists of tasks interrupt handler alarm handler and cyclic handler User Module Application Program Task Time Manaos Mailbox Semaphore Management MR30 kernel Task dependent Memorypool Version synchronization Eventflag Management Management Interrupt Scheduler Management Hardware M16C Microcomputer Figure 3 17 MR30 Structure 30 For details See 3 5 10 3 5 MR30 Kernel Structure 31 3 5 2 Module Overview The MR30 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 RUN READY WAIT and SUSPEND 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 MR30 kernel and starts the user created alarm han dler and cyclic handler Version Management Module Reports the MR30 kernel version number or other information Sync Communication Module This is the function for synchronization and communication among the tasks The following three functional modules are offered Eventflag Checks
63. de format error The file read format is incorrect Rewrite it to the correct format cfg30 Warning xxxx line xxx can t find lt XXXX gt cfg30 Warning xxxx line xxx can t find XXXX The include file XXXX cannot be found Check the file name and whether the file actually ex ists 6 2 Configurator Execution Procedures 125 cfg30 Warning over character number of including path name The path name of include file is longer than 255 characters 126 Chapter 6 Using Configurator 6 3 Editing makefile Here you edit makefile the configurator generated and set compilation options libraries and so on The procedure for setting them is given below 1 NC30 command options You define command options of the C compiler in CFLAGS Be sure to define the c option 2 AS30 command options You define command options of the assembler in ASFLAGS 3 LN30 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 di rectory and defines them in LIBS Either add or delete libraries when necessary If you create the own makefile for MR30 system be sure to describe the following 4 items in the makefile file 5 MR30 Library Specifications The MR30 library varies according to the message size of the mailbox
64. e assembly language data SE section bes SE section data SO section bes SO section data NE section bss NE section data NO section bes NO section rom NE section rom NO section data FE section bss FE section data FO section bes FO section rom FE section rom FO section data SEl section data SOI section data NEI section data NOI section data FEI section data FOI section These sections are those that are generated by NC30 These sections are not defined in the section file for the assembly language Refer to the NC30 manual for details 92 Chapter 5 Detailed Applications The diagram below shows the section allocation in the sample startup program See Figure 5 15 00000H SFR ee Section generated by NC30 MR_RAM_DBG MR_RAM sen Za gt L 010000H OF 0000H MR_KERNEL MR_CIF INTERRUPT_VECTOR FIX_INTERRUPT_VECTOR OF F DOOH OFFFDCH Figure 5 15 data_SE bss_SE data_SO bss_SO data_NE bss NE data_NO bss NO rom_NE bss FE data_FO bss FO rom_FE rom_FO data GEI data GO data NEI data NOI data FEI data FOI Ki This section is no linked when the program is written in the assembly language Selection Allocation in C Language Startup Program 5 10 Cautions for each microcontroler 93 5 10 Cautions for each microcontroler 5 10 1 To use the M16C 62 group MCUs To use the memory expansi
65. e file Application Startup program Assembler source start a30 crtOmr a30 J amp table file mrtable a30 Relocatable Assembler 4 Create amp table utility mkmrtbl file mrc ee C standard MR30 Library Application Library object Linkage Editor In30 y Absolute module Load module converter Imc30 ROM write format Figure 4 1 MR30 System Generation Detail Flowchart 58 Chapter 4 Applications Development Procedure Overview 4 2 Development Procedure Example This chapter outlines the development procedures on the basis of a typical MR30 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 Centronics interface interrupt handler This program uses the following MR30 library functions sta tsk Starts a task Give the appropriate ID number as the argument to select the task to be acti vated When the id h file which is generated by the configurator is included it is possible to specify the task by name character string e wai To Waits until the eventflag is set up In the example this function is used to wait until one page of data is
66. e of system clock 102 Index UNS CPU siria 43 78 79 User Stack 135 User stack size of task eeen 105 A Vari able size memorypool definition 109 Variable size Memorypool Management 46 Variation Descriptor AE 51 Vector NUMDETS 2 eee eee 135 MO O ci 116 Version Management nen bl 153 g Wai flO yasni 37 Wal SOM acid 40 80 WAIT Sale iii 22 WAIT SUSPEND eee eee 23 WUP ES aa 35 ITRON Specification ssscnrrrrsn 6 ITRON Specification V 2 0 no 6 ITRON specifications M30 6 M3T MR30 V 3 30 Users Manual Rev 1 00 September 16 2003 REJ10J00101 0100Z COPYRIGHT 2003 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED M3T MR30 V 3 30 User s Manual ENESAS Renesas Electronics Corporation 1753 Shimonumabe Nakahara ku Kawasaki shi Kanagawa 211 8668 Japan REJ10J0101 0100Z
67. e version information is obtained in the format standardized in the TRON Specification The get ver system call furnishes the following information Manufacturer Name Number indicating Renesas Corporation Type Number Product identification number Specification Version The number representing the uITRON Specification plus the version number of the uITRON Specification document on which the product is based Product Version MR30 version number Product Control Information Product release number release date and other associated data MPU Information Number representing the M16C 80 Series Microcomputer Variation Descriptor Number of the function set available for use with the MR30 52 Chapter 3 Introduction to MR30 3 5 12 System Calls That Can Be Issued from Task and Handler There are system calls that can be issued from a task and those that can be issued from a handler while there are other system calls that can be issued from both Table 3 2 lists those system calls Table 3 2 List of the system call can be issued from the task and handler System Call Task Interrupt Handler Cyclic Handler Alarm Handler sta tisk O x x x ista tsk x O O O ext_tsk O x x x ter tsk O x x x dis_dsp O x x x ena dsp O x x x chg pri O x x x ichg pri x O O O rot rdg O x x x irot_rdq x O O O rel wai O x x x irel_ wai x
68. eats the C language variables as indicated in Table 5 1 48 The configurator generates the id h file which converts the task ID number to the associated character string for task designa tion That is id h is used to make the define declaration for converting the character string consisting of ID and task start function name to the task ID number 4 Started beginning with the task start function at the initial priority level and with the wake up count cleared 66 Table 5 1 Chapter 5 Detailed Applications 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 Static variable in function Variable for specific task 5 1 Program Coding Procedure in C Language 67 5 1 2 Writing OS dependent Interrupt Handler When describing the OS dependent interrupt handler in C language observe the following precautions 1 Describe the 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 mr30 h which is in the system directory as well as id h which is in the current directory Do not use the ret int system call in the interrupt handler 5 Don t describe extern declaration no
69. ection Task gt SP LED illumination Task Register Restore Figure 3 10 System Call Processing Flowchart 9 A different sequence is followed if the issued system call does not evoke task switching 3 2 System Call 19 3 2 2 Task Designation in System Call Within the MR30 real time OS each task is identified by ID number For example the system says Start the task having the task ID number 1 However if a task number is directly written in a program the resultant program would be very low in readability If for instance the following is entered in a program the programmer is constantly required to know what the No 2 task is sta_tsk 2 1 Further if this program is viewed by another person he she does not understand at a glance what the No 2 task is To avoid such inconvenience the MR30 provides means of specifying the task by name function or symbol name The program named configurator cfg30 which is supplied with the MR30 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 Startingthetask having the designated Name ID number gt ID number Configurator Program Real time OS Figure 3 11 Task Identification sta_tsk ID_task 1 In the above example the system is instructed to start the task having the function name task or the symbol name task It sh
70. ed up and switch this item OFF in any other tasks e variable memorypool definition Deal with this item in the same manner either define or omit in two applications Avoid de fining this item in one application and omitting it in the other application Other definitions though different from each other between two configuration files raise no problem Changing the processor mode register You change the processor mode register for a startup program in compliance with the system Preparing application programs You prepare two application programs Locating respective sections Programs to be located in the kernel ROM and in the application ROM are given below Programs to be located in the kernel ROM Startup program MR KERNEL section MR30 s kernel MR KERNEL section Programs common to two applications program section This example assumes that the task identified by 1 is a program common to two applications Locating a common program in the application ROM raises no problem With a common pro gram located in the kernel ROM the system calls given below cannot be issued so be care ful can Wwup get tid pget_blf pget blk pol To prev msg rev msg trev msg twai_flg wai flg To issue these system calls from a common program locate it in the application ROM 146 MR KERNEL program Application ROM1 Chapter 9 Separate ROMs kernel ROM Internal ROM Startup Program Task of ID 1
71. efile Template File sys ram inc mr30 inc M R30 Version File version Figure 6 1 Chapter 6 Using Configurator System Data Difinition File sys ram inc sys rom inc s cfg30 K System generation File A Indude File makefile mr30 inc The operation of the Configurator 6 2 Configurator Execution Procedures 117 6 2 2 Setting Configurator Environment Before executing the configurator check to see if the environment variable LIB30 is set correctly The configurator cannot be executed normally unless the following files are present in the directory indi cated by the environment variable LIB30 Default configuration file default cfg This file can be copied to the current directory for use In this case the file in the current direc tory is given priority System RAM area definition database file sys_ram inc mr30 inc template file mr30 inc Section definition file c_sec inc or asm_sec inc Startup file crtOmr a30 or start a30 makefile template file makefile ews or makefile dos MR30 version file version 118 Chapter 6 Using Configurator 6 2 3 Configurator Start Procedure Start the configurator as indicated below A gt cfg30 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
72. emiconductor products better and more reliable but there is always the possibility that trouble may occur with them Trouble with semiconductors may lead to personal injury fire or property damage Remember to give due consideration to safety when making your circuit designs with appro priate measures such as i placement of substitutive auxiliary circuits ii use of nonflammable material or iii prevention against any malfunction or mishap Notes regarding these materials 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 Re nesas 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 examples 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 Renesas Solutions Corporation without notice due to product improvements or other
73. entered into the buffer via the Centronics interface wup_tsk Wakes up a specified task from the WAIT state This function is used to start the printer en gine task slp tsk Causes a task in the RUN state to enter the WAIT state In the example this function is used to make the printer engine task wait for image expansion iset Toi Sets up the eventflag In the example this function is used to notify the image expansion task of the completion of one page data input At this time make sure that the startup program crtOmr a30 and section definition file ce sec inc are copied to the current directory For example gt copy LIB30 crtOmr a30 gt copy LIB30 c_sec inc 45 The configurator converts the ID number to the associated name character string in accordance with the information entered int the configuration file 4 2 Development Procedure Example 59 include lt mr30 h gt include id h void main main task printf LBP start simulation n sta_tsk ID_idle 1 activate idle task sta tsk ID image l activate image expansion task sta tsk ID printer 1 activate printer engine task void image activate image expansion task while 1 wai_flg amp flgptn ID_pagein waiptn TWF_ANDW TWF_CLR wait for 1 page input printf bit map expansion processing n wup tsk ID printer wake up printer engine task void printer
74. ential 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 effi ciency by promoting modular software development However the conventional methods are not adequate for the purpose of solving the problems Under these circumstances it is necessary to introduce a new system named real time OS To answer the above mentioned demand Renesas has developed a real time operating system tradenamed MR30 for use with the M16C 60 Series 16 bit one chip microcomputers When the MR30 is introduced the following advantages are offered 1 Software recycling is facilitated When the real time OS is introduced timing signals are furnished via the real time OS so that programs dependent on timing can be reused Further as programs are divided into modules called tasks structured programming will be spontaneously provided That is recyclable programs are automatically prepared 2 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 al
75. etails of calculating the processing time of the system clock interrupt handler see the ref erence manual Initial value of system time Definition format Time of day Definition range 0 0 0 Ox7FFF OxFFFF OxFFFF Define the initial value of the system time If you do not use the functions based on system time e g set_tim get_tim alarm handler there is no need to set this item If this item is not de fined system clock interrupt handler processing is optimized automatically Note however that if a default value is defined in the default configuration file said processing is not optimized 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 maxdefinel max task the maximum number of tasks defined max flag the maximum number of eventflags defined max mbx the maximum number of mailboxes defined max sem the maximum number of semaphores defined max mpl the maximum number of fixed size memorypools defined max cyh the maximum number of cyclic handlers defined max_alh the maximum number of alarm handlers defined lt lt Contents gt gt The maximum number of tasks defined Definit
76. etters except for the numbers A F and a f 6 1 Configuration File Creation Procedure 97 It is also possible to enter operators in numerical values Table 6 2 lists the operators available Table 6 2 Operators Operator Priority Direction of computation High From left to right Unary_minus From right to left From left to right Binary minus Low From loft to right Numerical value examples are presented below e 123 e 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 alphabetical letters _ underscore and and begins with a non numeric character Example symbols are presented below _TASKI 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 char acter and ends with The following shows an example of a function name written in the C language main func When written in the assembly language the start label of a module is assumed to be a function name Freguency The freguency 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 f
77. f tasks appear to be executed simultaneously Key input Task Remote control Task LED illumination Task Volume control Task Monitor Task Mechanical control Task gt 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 sys tems The factors causing task switching dispatching are as follows Task switching occurs upon request from a task Task switching occurs due to an external factor such as interrupt When a certain task is to be executed again upon task switching the system resumes its execution at the point of last interruption See Figure 3 5 14 Chapter 3 Introduction to MR30 Program execution Program execution interrupt resumed Key input Task During this interval it ad SS appears that the key input microcomputer is haled Figure 3 5 Task Execution Interruption and Resumption In the state shown in Figure 3 5 it appears to the programmer that the key input task or its microcom puter 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 t
78. finition format Symbol Definition range TGY ON or TGY OFF Define the initial mode of the cyclic handler One of the following two modes can be defined here TCY OFF In this mode the cyclic handler is activated by a act cyc system call TCY_ON In this mode the cyclic handler is activated simultaneously when the system starts up 3 Start Address Definition format Symbol or Function Name Definition range None Define the start address of the cyclic handler The function name defined here causes the following declaration statement to be output in the id h file pragma CYCHANDLER function name Alarm handler definition This definition is necessary to use Alarm handler function lt lt Format gt gt Alarm Handlar Definition alarm_hand ID No time Startup time entry address Start address 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 lt lt Content gt gt Define the following for each alarm handler ID number 6 1 Configuration File Creation Procedure 111 1 Startup time Definition format Time of day Definition range 0 0 0 0Ox7FFF OxFFFF OxFFFF Define the startup time of the alarm handler 2 Start address Definition format Symbol or Function Name Definition r
79. following procedures 1 Applications Program Coding Code application programs in C or assembly language At this time copy the sample startup program crtOmr a30 or start a30 from the directory indicated by the environment variable LIB30 to the current directory Further if necessary modify the startup program and the section definition file Configuration File Preparation Using the editor prepare the configuration file in which the task entry address stack size and the like are defined Configurator Execution Using the configuration file create the system data definition files sys rom inc and sys ram inc include files mr30 inc and id h and system generation procedure description file makefile System Generation Generate the system by executing the make command Writing into ROM Using the prepared ROM write form file write the program into ROM or allow the debugger to read the program to conduct debugging Figure 4 1 shows MR30 System Generation Detail Flowchart 4 The standard startup programs crtOmr a30 and start a30 are in the directory indicated by the environmentr variable LIB30 4 The make command comes the UNIX standard and UNIX compatible 4 1 General Description 57 Configuration file Configurator dg30 Indudefile id h l ndude file System data definition file mr30 inc sys ram inc sys rom inc C standard MR30indude file header file mr30 h Application indud
80. generate the system data definition files sys rom inc and sys_ram inc include files mr30 inc and id h and system generation procedure description file makefile from the configuration file A gt cfg30 mv Ilbp cfg MR30 system configurator V 3 30 01 Copyright 2003 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED MR30 version gt V 3 30 Release 1 A gt Figure 4 4 Configurator Execution 4 2 4 System generation Execute the make command to generate the system A gt nmake f makefile as30 F Dtest 1 crtOmr a30 nc30 c task c 1n30 1n30 sub A gt Figure 4 5 System Generation 4 2 5 Writing ROM Using the Imc30 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 46 It is possible for MR30 to use only make command compatible to UNIX standard To use MS DOS use make command for instance nmake command attached to C compiler make by Microsoft Corporation compatible to UNIX For make command interchangeable to UNIX refer to the release note This paragraph describes an example for case when nmake command interchangeable to UNIX is executed Chapter 5 Detailed Applications 64 Chapter 5 Detailed Applications 5 1 Program Coding Procedure in C Language 5 1 1 Task Description Procedure 1 Describe the task as a fu
81. gister and Stack Area Management 16 System Gall ee 17 System Call Processing Flowchart nnne 18 Task Identification ene nennen 19 Task Status a ae ma ead in Sabla are nena ee 20 MR30 Task Status Transition 21 Ready Queue Execution Oueuel 000 ee eene nene nn n nen n nn 24 Task Control block alent dek ako en 26 Cyclic Handler Alarm Handler Acvation eee eee eee eee eee nene 28 MR30Structure 2222 ee 30 RE Tele BEEN ES Klein lee ES Ready Queue Management by rot rdg System Call 33 Suspending and Resuming a Task A 35 Wake up Request Gtorage AANEREN 36 Wake up Request Cancellation 22 4 eee eee eee eee eee eee eee nene teen teen nen ent 36 Task Execution Control by UheEventflag A 38 Exclusive Control by Gemapbore 2 2 4 eee eee eee eee eee eee carr nenene 39 Semaphore Counters E 39 Task Execution Control by Gemapbore 2 2 2222 eee eee eee eee eee eee een nenn ne 40 NS CAPE A AE AE cht von arene oe eu need cate ele Oe nine n aren 41 Meaning of Messages sa cine hn ay eit EE EE a nat 41 Message queue Glze EEN 42 Interrupt process low ENEE 44 Memorypool Management 22 2 nn 45 poet DIK Processing ties is zed geneze ee Be hin een 47 rel BIK Processing DEE 47 diy tsk system Call rataa Rena 48 Timeout Processing cimas boda 49 Cyclic Handi Of vise cece lates Sian eevee en Rieden 50 Cyclic Handler TCY ON Selected as Activity Status een 50 Cyclic Handler TCY INI ON Selected as Activity Status 50 MR30 System Generati
82. h which an eventflag is specified in a program 106 Chapter 6 Using Configurator Semaphore definition This definition is necessary to use Semaphore function lt lt Format gt gt Semaphore Definition semaphore ID No name Name initial count Initial value of semaphore counter 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 lt lt Content gt gt Define the following for each semaphore ID number 1 Name Definition format Symbol Definition range None Define the name with which a semaphore is specified in a program 2 Initial value of semaphore counter Definition format Numeric value Definition range 0 32767 Define the initial value of the semaphore counter Mailbox definition This definition is necessary to use Mailbox function lt lt Format gt gt Mailbox Definition mailbox ID No name Name buffer_size Maximum number of mailbox messages l The ID number must be in the range of 1 to 255 The ID number can be omitted 6 1 Configuration File Creation Procedure 107 If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the name with which a mailbox is specified
83. he uITRON specification 4 The uITRON specifications V 3 0 has its system calls classified into level R level S level E and level C MR30 implements all of level R and level S system calls and part of level E system calls among those stipulated under uITRON specifications V 3 0 The MR30 specifications are outlined in Table 2 1 4 Static object generation 5 Dynamic object generation MR30 V 1 00 conforms to uITRON Specifications V 3 0 2 2 Relationship between TRON Specification and MR30 Table 2 1 MR30 Specifications Overview Item Specifications Target microprocessor M16C 60 30 20 10 series microcomputers Maximum number of tasks 255 Task priorities 255 Maximum number of eventflags 255 Eventflag width 16 bit Maximum number of semaphores 255 Semaphore type Counter type Maximum number of mailboxes 255 Message size 16 bit or 32 bit Buffer size of Mailbox more than 0 byte Maximum number of Fixed size Memorypool 255 Maximum number of Variable size Memorypool 1 Number of system calls 61 OS nucleus code size OS nucleus data size OS nucleus language Approx 1 0K to 10 0K bytes 16bytes min 11 byte increment per task except stack In addition if you use timeout function increased 15byte per task C and Assembly language 8 Chapter 2 General Information 2 3 MR30 Features The MR30 offers the following features Re
84. her or not to validate a preset cyclic handler 3 Alarm Handler This handler starts at preselected times If a system time is reset etc set_tim system call to a tme before an Alarm Handler already started the Alarm Handler will never restart If the system time is reset to a time after an Alarm Handler starts all Alarm Handler will never start The cyclic handler and alarm handler are called up by means of a subroutine call from the system clock interrupt timer interrupt handler See Figure 3 16 Therefore the cyclic handler and alarm handler function as part of the system clock interrupt handler Note that the cyclic handler and alarm handler are called up under the conditions whose state is the system clock interrupt priority level 27 This transfer is called dispatching or switching 28 act_cyc system call 28 Chapter 3 Introduction to MR30 Task System clock interrupt handler Cydic handler Alarm handler Subroutine call Timer interrupt Figure 3 16 Cyclic Handler Alarm Handler Activation 3 4 Handler 3 4 2 In the MR30 the following system calls can be issued from the handlers only Note however that the ret int system call is dedicated to the interrupt handler and therefore cannot be issued from the cyclic handler or alarm handler Table 3 1 System Calls Exclusive for Handlers System Calls Issuable from only Handlers System call name Function
85. ication is promoted The ITRON Specification is an abbreviation for the Industrial TRON Specification It denotes the real time operating system that is designed with a view toward establishing industrial real time operating systems The ITRON Specification provides a number of functions to properly meet the application requirements In other words ITRON systems reguire relatively large memory capacities and enhanced processing capabilities The uITRON Specification V 2 0 is the arranged version of the ITRON Specification for the higher processing speed and incorporated only a minimum of functions necessary The uITRON Specification V 2 0 can be said to be a subset of the ITRON Specification for the following reasons 1 The system call time out function is not incorporated 2 Tasks semaphores and other objects can be generated only at the time of system gen eration They cannot be generated after system startup 3 Only memorypools of a fixed size can be handled Memorypools of a variable size can not be handled 4 Neither the system call exception management function nor the CPU exception man agement function is provided Currently stipulated are uITRON specifications V 3 0 The uITRON specifications V 3 0 provides en hanced connection functions by integrating uITRON specifications V 2 0 and ITRON specifications MR30 is a real time operating system developed for the M16C 60 Series series of 16 bit microproces sors according to t
86. ified by pragma INTHANDLER 44 Chapter 3 Introduction to MR30 TaskA AN Interrupt Save Registers Handler Processing pragma INTHANDLER Declare C language Task Selection Restore Registers TaskB Figure 3 31 Interrupt process flow 3 5 MR30 Kernel Structure 45 3 5 9 Memorypool Management Function The memorypool management function provides system memory space RAM space dynamic control This function is used to manage a specific memory area memorypool dynamically obtain memory blocks from the memorypool as needed for tasks or handlers and release unnecessary memory blocks to the memorypool The MR30 supports two types of memorypool management functions one for fixed size and the other for variable size Fixed size Memorypool Management Function You specify memory block size using configuration file The MR30 kernel offers the following Fixed size memorypool management system calls e Acquiring a Memory Block pget D e Releasing a Memory Block rel bit As shown in Figure 3 32 memory block 3 in the memorypool is passed to task C upon memory block acauisition reguest from task C It is presumed in this case that memory blocks 1 and 2 are used by tasks A and B respectively M Block 1 TaskA Wee 27 Memory block acguisition Memory Block 2 Used by TaskB reguest Memory Bloks Memory block acquisition Unused area Memorypool Figure 3 32 Memorypool Management e Refer
87. imeout NO task_pause NO y System Clock Definition clock mpu clock 10MHz timer A0 IPL 4 unit time 100ms ms initial_time 0 0 0 y Task Definition task 1 entry_address main stack_size 100 priority Je initial start ON y task 2 entry_address task2 stack_size 100 priority 2 y task 3 entry_address task3 stack_size 100 priority 3 y task 4 entry_address task4 stack_size 100 priority 4 y Cyclic Handler Definition cyclic_hand 1 interval_counter 150 mode TCY_ON entry_address cyhl Chapter 9 Separate ROMs 144 Chapter 9 Separate ROMs 9 1 How to Form Separate ROMs This chapter describes how to form the MR30 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 kernel 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 4 System configuration Here you set up a system configuration of application programs Here descriptions are given on the supposition that the system configuration of two applica tion programs is as shown below Application 1 Application 2 The number of Tasks 4 5 The number of Eventflags 1 3 The number of Semaphores 4 2 The number of Mailboxes 3 5 The number of Fixed size memorypools 3 1
88. in the WAIT state for a specified time period when the dly_tsk system call is issued In this case the task goes into the READY state when the specified time has elapsed or its WAIT state is cleared explicitly by some other task When the wai_flg wai sem or rev msg system call is issued the task enters the WAIT state and waits to be requested In this case the task moves into the READY state when the request condition is met or its WAIT state is cleared explicitly by some other task The tslp_tsk twai_flg twai_sem and trev msg system calls specify the time outs for the slp tsk wai_flg wai sem and rev msg system calls The system enters the wait state for the wait condition specified in each system call After the wait condition is met or the specified time has elapsed the task enters the executable state When the task enters the WAIT state and waits to be requested upon the issuance of the wai_flg twai_flg wai_sem twai_sem rev msg or trev msg system call it joins any of the following queues depending on the request Eventflag Queue Semaphore Queue Mailbox Queue 4 SUSPEND state When the sus_tsk system call is issued from a task in the RUN 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 SUSPEND state If a task in the WAIT state is placed in this situation it goes into the WAIT SUSPEND state 14 For the inf
89. ing Task This section describes how to write an application using the assembly language 1 Be sure to include mr30 inc at the beginning of file For the symbol indicating the task start address make the external declaration 3 Be sure that an infinite loop is formed for the task or the task is terminated by the ext_tsk system call INCLUDE mr30 ino 1 GLB task 2 task process jmp task 3 Figure 5 6 Example Infinite Loop Task Described in Assembly Language INCLUDE mr30 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 O zero except the PC SB RO and FLG registers 5 When specifying a task use a character string that consists of the task s start sym bol name plus ID as you specify it wup tsk ID task 6 When specifying an eventflag semaphore or mailbox use a character string that consists of the name defined in the configuration file plus ID as you specify it For example assume that the semaphore is defined in the configuration file as follows semaphore 1 name abc D I To specify this semaphore write your specification as follows sig sem fID abc 7 When specifying a cyclic handler or alarm handler use a character string that con 54 Use the GLB pseudo directive 55 The configurator generates an instruction necessary to c
90. inition ir tas ron ak t dada nao adu cia 106 Fixed size memorypool definition 1 107 Variable size memorypool definition H 108 ICcydichandler defE ON cra A H dy no Rat asennad 109 Alarmi handler definition 1 a aa Train 110 CInterr ptvector defi nition miii diras 111 6 13 Configuration File Example sssssessessssrsrsrsrsrressnrrnsnsnrnsrannnnranssnnnnsennnnnannnneannnnsanennena 113 6 2 Configurator Execution Procedures e 2422 eeee eee eee eee eee anna ne en an Kannan 115 621 Configurator Okerkdeit 000000 ae na anna ae KARR RSK rr 115 Contents iii 6 22 Setting Configurator ENVironMENt ssssssssessssssessrsssrsrrnnrnernnsnnrnnrnnennnrnnnnnnanennnennnnnen 117 6 2 3 Configurator Start Drocehure rr 118 6 24 makefile generate Euncion 119 6 2 5 Precautions on Executing CC onfiourator 120 6 2 6 Configurator Error Indications and Reechee 121 Error O EE 121 Warning Messages a ae a sn ea po zk ne ihren 124 Other Messages nennen A ahnen en ne he ehe ehren here 124 6 3 Editing makefile iio ia 126 Chapter 7 Application Creation Guide oooonnccconicononcccnncnnnoncnonanncnnanocnnnencnnnncnnnnn crac ncnnnr cnn 129 7 1 Processing Procedures for System Calls from Handlerz 2 eee eee 130 7 11 System Calls from a Handler That Caused an Interrupt during Task Execution 131 7 12 System Calls from a Handler That Caused an Interrupt during System Call PLOCESSING EE 132 7 13 System Call
91. ion Interrupt vector definition System Definition Procedure lt lt Format gt gt System Definition system stack size System stack size priority Maximum value of priority message siz Message size system IPL OS interrupt disable level timeout Timeout function task pause Task Pause lt lt Content gt gt 1 System stack size Definition format Numeric value Definition range 1 or more Define the total stack size used in system call and interrupt processing 62 All items except task definition can omitted If omitted definitions in the default configuration file are referenced 100 Chapter 6 Using Configurator Maximum value of priority value of lowest priority Definition format Numeric value Definition range 1 255 Define the maximum value of priority used in MR30 s application programs This must be the value of the highest priority used Message Size Definition format Numeric value Definition range 16 or 32 Specify the message size of mailbox Specify 16 for 16 bit message data or 32 for 32 bit mes sage data Omitting this assumes 16 OS interrupt disable level Definition format Numeric value Definition range 0 7 Set the IPL value in system calls that is the OS interrupt disable level Timeout function Definition format
92. ion format Numeric value Definition range 1 255 Define the maximum number of tasks defined 64 For details of forming the into separate ROMs see page 143 6 1 Configuration File Creation Procedure 103 2 The maximum number of eventflags defined Definition format Numeric value Definition range 1 255 Define the maximum number of eventflags defined 3 The maximum number of mailboxes defined Definition format Numeric value Definition range 1 255 Define the maximum number of mailboxes defined 4 The maximum number of semaphores defined Definition format Numeric value Definition range 1 255 Define the maximum number of semaphores defined 5 The maximum number of fixed size memorypools defined Definition format Numeric value Definition range 1 255 Define the maximum number of fixed size memorypools defined 6 The maximum number of cyclic activation handlers defined Definition format Numeric value Definition range 1 255 The maximum number of cyclic handler defined 7 The maximum number of alarm handler defined Definition format Numeric value Definition range 1 255 Define the maximum number of alarm handlers defined 104 Chapter 6 Using Configurator Task definition lt lt Format gt gt Tasks Definition task ID No entry address Start task of address
93. is file is used as a template file when generating makefile Refer to Section 6 2 4 mr30 inc template file mr30 inc This file serves as the template file of include file mr30 inc It resides in the directory indicated by environment variable LIB30 MR30 version file version This file contains description of MR30 s version It resides in the directory indicated by envi ronment variable LIB30 The configurator reads in this file and outputs MR30 s version infor mation 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 This file contains definition of system settings Include file mr30 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 5 The template file used for the EWS version is makefile ews and that for the DOS version is makefile dos D This makefile is a system generation procedure description file that can be processed by UNIX standard make commands or those conforming to UNIX standards 116 Configuration File XXX C G Default Configuration File default cfg makefile Template File makefile ews makefile dos makefile M ak
94. le If you do not use a system clock define NOTIMER 3 System clock interrupt priority level Definition format Numeric value Definition range 1 OS interrupt disable level in system definition Define the priority level of the system clock timer interrupt The value set here must be smaller than the OS interrupt disable level Interrupts whose priority levels are below the interrupt level defined here are not accepted dur ing system clock interrupt handler processing 4 Unit time of system clock Definition format Time in ms 32 x 65535 Br 1 S I Definition range MPU clock mpu clock MPU clock mpu clock Define the unit time of the system clock system clock interrupt generation intervals in ms The minimum value of this period can be calculated using the eguation However no value that is less than 0 001 ms is allowed to set even if the calculation gives the minimum value less than 0 001 ms Therefore if you set the value less than 0 001 ms in the configuration file the configurator will return such an error message as shown below Example of Error Messages 102 Chapter 6 Using Configurator When setting the system clock s pulse period in the configuration file make sure that this peri od of time is greater than the processing time of the system clock interrupt handler operating in OS Note that the value of the processing time varies with the type of MCU and the operating condition For d
95. ll from a task However task switching occurs when a return from a handler is made The processing procedures for system calls from handlers are roughly classified into the following three types 1 A system call from a handler that caused an interrupt during task execution 2 A system call from a handler that caused an interrupt during system call processing 3 A system call from a handler that caused an interrupt multiplex interrupt during han dler execution 8 The system call can t be issued from OS independent handler Therefore The handler described here does not include the OS independent handler 7 1 Processing Procedures for System Calls from Handlers 131 7 1 1 System Calls from a Handler That Caused an Interrupt during Task Execution Scheduling task switching is initiated by the ret int system call See Figure 7 1 TaskA Interrupt handler SS OS Interrupt Save Registers Il i g Restore Registers Task selection SP lt User TaskB Restore Registers ret int Scheduler Figure 7 1 Processing Procedure for a System Call a Handler that caused an interrupt during Task Execution The ret int system call is issued automatically when OS dependent handler is written in C language when pragma INTHAN DLER specified 132 Chapter 7 Application Creation Guide 7 1 2 System Calls from a Handler That Caused an Interrupt during System Call Processing Scheduling task
96. lling up the MR30 functions in C language An upstream process tool named Configurator is provided to simplify development procedures A configurator is furnished so that various items including a ROM write form file can be creat ed by giving simple definitions Therefore there is no particular need to care what libraries must be linked Chapter 3 Introduction to MR30 10 Chapter 3 Introduction to MR30 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 reguired development time program development difficulty This figure is nothing more than a schematic diagram However it indicates that the development peri od increases 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 program i Development Period gt 4 8 16 32 Kbyte Program Size Figure 3 1 Relationship between Program Size and Development Period
97. located to individual tasks so that all steps from devel opment to debugging 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 allo 3 OS Operating System 2 1 Objective of MR30 Development 5 cated to individual tasks work assignment is easy 3 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 ob serving the small modules 4 Timer control is made easier To perform processing at 10 ms intervals the microcomputer timer function was formerly used to periodically 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 perform ing processing at fixed time intervals making use of the real time OS time management func tion 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 numer ous timers are provided for the mic
98. m Coding Procedure in C Language 65 include lt mr30 h gt include id h void task void for 77 process Figure 5 2 Example Task Terminating with ext_tsk Described in C Language 8 When designating a task use a character string consisting of ID_ and task func tion name wup tsk ID main 9 When designating an eventflag semaphore mailbox or memorypool use a charac ter string consisting of ID and the name defined in the configuration file Suppose that the eventflag is defined as follows in the configuration file flag 1 name abc D I To designate this eventflag proceed as follows set flg ID abc ssetptn 10 When designating the cyclic handler or alarm handler use a character string con sisting of ID and handler start function name To designate the cyclic handler cyc for instance proceed as follows act cyc ID cyc TCY ON 11 When a task is reactivated by the sta tsk system call after it has been terminated by the ter tsk system 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 pro gram crtOmr a30 which actuates before MR30 startup 12 The task executed when the MR30 system starts up is setup 13 The variable storage classification is described below The MR30 tr
99. 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 cfg30 Warning task x XXXX is not defined near line xxx xxxx cfg The task definition item XXXX in ID number is omitted cfg30 Warning Already definition XXXX near line xxx xxxx cfg XXXX has already been defined The defined content is ignored check to delete the extra defi nition cfg30 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 cfg30 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 con figuration file cfg30 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 cfg30 Warning system stack_size is an uneven number near line xxx cfg30 Warning task x stack_size is an uneven number near line xxx Please set even size in system stack_size or task x stack_size Other messages The following message are a warning message that is output only when generating makefile The con figurator skips the sections that have caused such a warning as it generates makefile cfg30 Error xxxx line xxx inclu
100. 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
101. n format Symbol Symbol Definition range Selected from RO R1 R2 R3 A0 A1 SB FB Define the registers used in a task MR30 handles the register defined here as a context Specify the R1 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 lan guage 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 system call parameters used in each task MR30 kernel does not change the registers of bank If this definition is omitted it is assumed that all registers are selected 5 Initial startup status Definition format Symbol Definition range ON or OFF If you specify ON the task is placed in a READY state when the system initially starts up The start code of initial start task is 0 Eventflag definition This definition is necessary to use Eventflag function lt lt Format gt gt Eventflag Definition flag ID No name Name 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 lt lt Content gt gt Define the following for each eventflag ID number 1 Name Definition format Symbol Definition range None Define the name wit
102. n the slp tsk tslp tsk system call or tasks in other states except one that is in a DORMANT state are waked up by the iwup tsk system call it results in only wakeup reguests being accumulated Therefore if a wakeup reguest is issued for a task in executing state for example that wake up reguest is stored in memory temporarily Then when the task in that executing state is placed in a wait state by the slp tsk system call the accumulated wakeup request becomes valid so the task is executed continuously without being placed in a wait state See Figure 3 22 33 Tasks waiting under the following conditions will not be waked up Waiting for the eventflag Waiting for the semaphore Waiting for the message Waiting for timeout 36 Chapter 3 Introduction to MR30 Canceling a Task Wake up Request can wup Clears the stored wake up regues See Figure 3 23 wup tsk Wwup ek wup tsk slp_tsk slp_tsk Task Spee ene Wake up count 0 0 1 2 1 Figure 3 22 Wake up Request Storage wup tsk wup_tsk can wup slp_tsk slp_tsk Task got O g ac Wake up count 0 0 1 0 0 Figure 3 23 Wake up Reguest Cancellation 3 5 MR30 Kernel Structure 37 3 5 5 Eventflag The eventflag is an internal facility of MR30 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 wait ing until the flag wait conditions set are met The MR3
103. naling the Semaphore sig sem isig sem Sends a signal to the semaphore This system 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 semaphores service 40 Chapter 3 Introduction to MR30 Acquiring the Semaphore wai sem twai sem Waits for the semaphores service If the semaphore counter value is 0 zero the semaphore cannot be acquired Therefore the WAIT state prevails Acquiring the Semaphore preg sem Acquires the semaphore If there is no semaphore to acquire an error code is returned and the WAIT state does not prevail Refer Semaphore Status ref_sem Checks the status of the target semaphore Checks the count value and existence of the wait task for the target semaphore Figure 3 27 shows example task execution control provided by the wai_sem and sig_sem system calls wai sem sig sem Task o aes wai_sem Task e l wai_sem wai_sem Task WAIT state I I t ele ler 3 2 1 0 x 0 Counter Figure 3 27 Task Execution Control by Semaphore 3 5 MR30 Kernel Structure 41 3 5 7 Mailbox The mailbox is a mechanism that provides data communication between tasks A typical example is presented in Figure 3 28 In this example after task A sends a message in the mailbox task B can obtain the message from the mailbox Pee Message Message TaskA TaskB Figure 3 28 Mail
104. nction To register the task for the MR30 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 entry_address task stack_size 100 priority 3 l 2 At the beginning of file be sure to include mr30 h which is in system directory as well as id h which is in the current directory That is be sure to enter the following two lines at the beginning of file include lt mr30 h gt include 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 Don t describe extern declaration nor prototype declaration if system call is issued from your program 7 Itis also possible to describe the task startup function using the infinite loop include lt mr30 h gt include id h void task void process Figure 5 1 Example Infinite Loop Task Described in C Language 47 The task is ended by ext_tsk automatically if pramga TASK is declared in the MR30 Similarly it is ended by ext_tsk when returned halfway of the function by return sentence 5 1 Progra
105. nder software control of one microcomputer making it appear that the programs run on separate microcomputers you can obviate all the above disadvantages while retain ing 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 indicated in Figure 3 2 8 In the case presented in Figure 3 2 for instance the remote control microcomputer can be used for other products without being modified 12 Chapter 3 Introduction to MR30 Key input LED illumination Task Task Volume control Mechanical Task control Task Figure 3 3 Example System Configuration with Real time OS Audio Eguipment In other words the real time OS is the software that makes a one microcomputer system look like operating a number of microcomputers In the real time OS the individual programs which correspond to a number of microcomputers used in a conventional system are called tasks 3 1 Concept of Real time OS 13 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 microcomputers You should be wondering how the real time OS makes a one microcomputer sys tem 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 o
106. ndlers issuing a sys tem call system clock interrupt handler The OS independent interrupt handler s IPL value must be between system IPL 1 to 7 Namely the OS independent interrupt handler s IPL value cannot be set below the OS independent interrupt disable level Figure 5 11 shows the relationship between the OS independent and OS dependent interrupt handlers where the OS interrupt disable level is set to 3 OS Interrupt disable level Low High 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 task independent interrupt handller If they are a task dependent interrupt handler the program will not work normally 0 system IPL is set by the configuration file 5 5 Regarding Interrupts 77 5 5 3 Controlling Interrupts Interrupt enable disable control in a system call is accomplished by IPL manipulation The IPL value in a system call is set to the OS interrupt disable level system IPL in order to disable interrupts for the OS dependent interrupt handler In sections where all interrupts can be enabled it is returned to the initial IPL value when the system call was invoked Figure 5 12 shows the interrupt enable flag and IPL status in a system call For system calls that can be issued from only task When the flag before issuing a system call is 1 Task Sy
107. ne 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 per a block control Variable size memorypool function needs 8 byte RAM area per a block control Memorypool 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 interval counter Intervals mode Mode entry address Start address l 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 lt lt Content gt gt Define the following for each cyclic handler ID number 1 Intervals Definition format Numeric value Definition range 1 to 32767 Define the intervals at which time the cyclic handler is activated periodically The intervals here must be defined in the same unit of time as the system clock s unit time that is defined in sys tem clock definition item If the system clock s unit time is 10 ms and you want the cyclic han dler to be activated at 10 second intervals for example the intervals here must be set to 1000 110 Chapter 6 Using Configurator 2 Mode De
108. 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
109. nit mpl endif Variable Memory Pool IF MR HEAPSIZE glb init memblk init vmpl jsr w __init_vmpl jsr w __init_memblk ENDIF if __MR_NODBG else or b 80H DBG MOD endif END INIT E S Start initial active task r mov w 1 AO __start_task lde b __D_INIT_START 1 A0 Al jeq start end mov w AO R1 move counter to R1 mov w A1 A0 set task id mov w 0 R2 set start code mov w TFN_ISTA_TSK RO set func code ASSERT ista tsk gt gt file mrc int 33 mov w R1 A0 inc w AO jmp B start task __ start end glb __rdyq_search jmp W _ rdyg search DH A Define Dummy r glb __SYS_DMY_INH __SYS_DMY_INH reit E exit function FA glb _exit exit exit Sexit jmp exit DH A Syscall exit rouitne trace error code r glb sys end sys end ott __MR_NODBG else glb __ SYS TREC mov w RO __SYS_TRC MOV Ww R1 __SYS_TRC MOV W R2 __SYS_TRC mov w Roy SYS TRC 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 WWWW WW W UY 00000000 VO OO 301 014 YN WWWWWW WWW Y w N H o KOOOUOUG BUN O 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 393 354 355 356 357 358 5 8 Modifying MR30 Startup Program 87
110. o o Acquiring Its Own ID get_tid Acauires its own task ID number When this system call is issued from a handler O zero is obtained instead of the ID number Refer Task Status ref tsk Checks the status of the target task 3 5 MR30 Kernel Structure 35 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 SUSPEND or WAIT SUSPEND state or waking up a WAIT state task The MR30 offers the following task incorporated synchronization system calls Placing a Task in the SUSPEND State sus tisk isus tsk Restarting a Task Placed in SUSPEND State rem tsk irsm tsk Forcibly suspends or resumes task execution If a READY task is forced to wait it enters the SUSPEND state If a WAITING state task is forcibly suspended it enters the WAIT SUSPEND state See Figure 3 21 READY state WAIT state sus tsk rsm_tsk sus tsk rsm tsk isus tsk irsm tsk isus tsk irsm tsk SUSPEND state WAIT SU SPEND state Figure 3 21 Suspending and Resuming a Task Placing a Task in the WAIT State slp tsk tslp tsk Waking up wait state task wup tsk iwup tsk Wakes up a task that has been placed in a WAIT state by the slp tsk or tslp tsk system call No task can be waked up unless they have been placed in a WAIT state by If tasks that have been placed in a WAIT state for other conditions tha
111. on Detail Flowchart 2 eeeeeeeeeeeeee eee eee een 57 Program Example 420 24 enh vdala ea diera teen 59 Configuration File Example AAA 60 vi List of Figures Figure 4 4 Configurator E xXecution xa 61 Figure 4 5 System Generation EEN 61 Figure 5 1 Example Infinite Loop Task Described in C Language eee 64 Figure 5 2 Example Task Terminating with ext_tsk Described in C Languaoce 65 Figure 5 3 Example of OS dependent Interrupt H ander 67 Figure 5 4 Example of OS independent Interrupt Handler eee eee eee een 68 Figure 5 5 Example Cyclic Handler Written in C Language 69 Figure 5 6 Example Infinite Loop Task Described in Assembly Language 70 Figure 5 7 Example Task Terminating with ext_tsk Described in Assembly Language 70 Figure 5 8 Example of OS depend interrupt handler 2 2 2 72 Figure 5 9 Example of OS independent Interrupt Handler of Specific Level 73 Figure5 10 Example Handler Written in Assembly Language eee eee eee 74 Figure5 11 Interrupt handler IP e ENNEN 76 Figure5 12 Interrupt control in a System Call that can be Issued from only a Task 71 Figure5 13 Interrupt control in a System Call that can be Issued from a Task independent 78 Figure5 14 C Language Startup Program crt mr a20 88 Figure5 15 Selection Allocation in C Language Startup Program 92 Figure 6 1 The operation of the Configurator
112. on function in memory space expansion mode 1 1 2M available mem ory Locate the MR30 kernel MR KERNEL section between addresses 30000H and FFFFFH To use the memory expansion function in memory space expansion mode 2 4M available mem ory Locate the MR30 kernel MR KERNEL section between addresses 3C0000H and 3FFFFFH 5 10 2 To use the M16C 6N group MCUs Please append the following program to the point of the MR30 s system timer setting in the startup program The setting point of MR30 s system timer is lines 160 in crtOmr a30 or lines 73 in start a30 These startup files are in MR30 s install directory LIB30 directory If you select no division by changing the value of the peripheral function clock register need not append the following program System timer interrupt setting mov b stmr mod val stmr mod reg set timer mode mov b 1H OAH i bset 6 07H mov b stmr int IPL stmr int reg set timer IPL A bclr 6 07H mov b 0 0AH mov w stmr cnt stmr ctr reg set interval count mov b stmr mod reg ROL lt append and b OCOH ROL lt append jnz MR SYSTIME END lt append mov w stmr cnt 2 stmr ctr reg lt append MR SYSTIME END lt append or b stmr bit 1 stmr start Chapter 6 Using Configurator 96 Chapter 6 Using Configurator 6 1 Configuration File Creation Procedure When applications program coding and startup program modification are
113. onvert the task s ID number into a character string to specify the task in the file mr30 inc That is to say the EQU declaration necessary to convert the character string consisting of the task s start symbol name plus ID_ into that task s ID number is make in mr30 inc 5 2 Program Coding Procedure in Assembly Language 71 sists of the handler s start symbol name plus ID as you specify it For example if you want to specify a cyclic handler cyc write your specification as follows act cyc ID_cyc TCY_ON 8 Set a task that is activated at MR30 system startup in the configuration file 5 The relationship between task ID numbers and tasks program is defined in the configuration file 72 Chapter 5 Detailed Applications 5 2 2 Writing OS dependent Interrupt Handler When describing the OS dependent interrupt handler in assembly language observe the following precautions 1 At the beginning of file be sure to include mr30 inc which is in the system direc tory 2 For the symbol indicating the interrupt handler start address make the external declaration Global declaration 3 Make sure that the registers used in a handler are saved at the entry and are re stored after use 4 Return to the task by ret int system call INCLUDE me A rees 4 4 4 ASS 1 GLB o En 2 inth Registers used are saved to a stack 3 iwup tsk ID_taskl process Registers used are restored EH ret int
114. orate a section definition file 12 in Figure 5 14 Incorporate an include file for MR30 13 in Figure 5 14 Incorporate a system ROM area definition file 14 in Figure 5 14 Incorporate a system RAM area definition file 15 in Figure 5 14 This is the initialization program SYS INITIAL that is activated immediately after a reset 98 254 in Figure 5 14 1 2 3 4 5 D D D D D D D D 6 7 8 9 Setting the System Stack pointer 99 in Figure 5 14 Setting the processor mode register 101 103 in Figure 5 14 Setting the SB FB register 104 108 in Figure 5 14 Initial set the C language 123 154 in Figure 5 14 When using no standard input output functions remove the lines 191 and 192 in Figure 5 14 Setting OS interrupt disable level 163 165 in Figure 5 14 Setting the address of interrupt vector table 166 in Figure 5 14 Set MR30 s system clock interrupt 171 176 in Figure 5 14 Initial set MR30 s system timer 181 185 in Figure 5 14 Initial set parameters inherent in the application 190 in Figure 5 14 Initialize the RAM data used by MR30 197 241 in Figure 5 14 Activate the initial startup task 251 in Figure 5 14 This is a system clock interrupt handler 287 295 in Figure 5 14 5 9 Memory Allocation 89 5 9 Memory Allocation This section describes how memory is allocated for the application program data Use the section file provided by MR30 to set memory allocation MR30 comes
115. ormation on the ready gueue see the next chapter 15 Upon ext_tsk system call 16 Upon slp tsk tslp tsk dly tsk wai flg twai_flg wai sem twai sem or rev msg system call 17 Upon chg pri system call 18 Upon ichg pri system call 3 3 Task 23 The SUSPEND state is the condition in which a READY task or currently executed task1 is excluded from scheduling to halt processing due to I O or other error occurrence That is when the SUSPEND request is made to a READY task that task is excluded from the execu tion queue Note that no queue is formed for the SUSPEND request Therefore the SUSPEND request can only be made to the tasks in the RUN READY or WAIT state If the SUSPEND request is made to a task in the SUSPEND state an error code is returned 5 WAIT SUSPEND When the SUSPEND request is made to a task in the WAIT state that task goes into the WAIT SUSPEND state When the SUSPEND request is made to a task that is waiting for a request made by the wai_flg twai_flg wai_sem twai_sem rcv_msg or trcv_msg system call that task remains in the request queue and simply goes into the WAIT SUSPEND state When the wait condition for a task in the WAIT SUSPEND state is cleared that task goes into the SUSPEND state It is conceivable that the wait condition may be cleared when any of the following conditions occurs The task wakes up upon wup_tsk or iwup_tsk system call issuance The task placed in the WAIT state by the
116. ould also be noted that task name to ID number conversion is effected at the time of program gen eration Therefore the processing speed does not decrease due to this conversion feature 20 Chapter 3 Introduction to MR30 3 3 Task This chapter explains how the real time OS controls the tasks 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 RUN state While the system waits for key input task execution is not needed In that situa tion the key input task in the WAIT state Key input Task Key input Waiting for Key input processing key input processing RUN state WAIT state RUN state Figure 3 12 Task Status The MR30 controls the following six different states including the RUN and WAIT states 1 RUN state 2 READY state 3 WAIT state 4 SUSPEND state 5 WAIT SUSPEND state 6 DORMANT state Every task is in one of the above six different states Figure 3 13 shows task status transition 3 3 Task 21 MPU exedusive right acquisition READY state WAIT state dear MPU exedusive right relinquishment Entering the WAIT state WAIT state SUSPEND state dear SUSPEND request Forced request from other task from other task ee
117. plicated In addition the microcomputer program size has increased Further as product development competition has been intensified manufacturers are compelled to develop their microcomputer based products within a short period of time In other words engineers engaged in microcomputer software development are now reguired to de velop larger 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 gen eral purpose subroutines and other program segments and using them for program develop ment In this method however it is difficult to reuse programs that are dependent on time or timing In reality the greater part of application programs are dependent on time or timing Therefore the above recycling method is applicable to only a limited number of programs 2 To promote team programming so that a number of engineers are engaged in the de velopment of one software package There are various problems with team programming One major problem is that debugging can be initiated only when all the software program segments created individually by team members are ready for debugging It is ess
118. r current SP register value Wake up counter Task wake up reguest 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 Flag wait mode This is a wait mode during eventflag wait Timer gueue connection pointer This area is used when using the timeout function This area stores the task connection pointer used when constructing the timer gueue Flag wait pattern This area is used when using the timeout function This area stores the flag wait pattern when using the eventflag wait system call with the time out function twai_flg No flag wait pattern area is allocated when the eventflag is not used The task control block is schematized in Figure 3 15 26 Called the task context 26 Chapter 3 Introduction to MR30 TCB TCB TCB Time out counter or Flag wait pattern Timer queue Connection pointer Flag wait pattern Figure 3 15 Task control block This area is allocated only when the timeout function is used 3 4 Handler 27 3 4 Handler 3 4 1 Difference between Tasks and Handlers The tasks are program units that the MR30 executes and controls Each task has its own independent context program counter stack pointer status register and other registers Therefore to transfer execution from one task to another it is necessary to effect contex
119. 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 o m d lt D D M3 T MR30 V 3 30 User s Manual Real time OS for M16C 60 30 20 10 Series R Electroni enesas ER Rev 1 00 2003 09 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 Sun Solaris Java and all Java based trademarks and logos are trademarks or registered trademarks of Sun Microsystems Inc in the U S or other countries and are used under license Linux is a trademark of Linus Torvalds Turbolinux and its logo are trademarks of Turbolinux Inc 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 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 s
120. r prototype declaration if system call is issued from your program 6 The static declared functions can not be registered as an interrupt handler include lt mr30 h gt include id h void inthand void process iwup_tsk ID_main Figure 5 3 Example of OS dependent Interrupt Handler 5 A configuration file is used to define the relationship between handlers and functions 5 When an OS dependent interrupt handler is declared with pragma INTHANDLER code for the ret_int system call is auto matically generated 68 Chapter 5 Detailed Applications 5 1 3 Writing OS independent Interrupt Handler When describing the OS independent interrupt handler in C language observe the following precau tions 1 Be sure to declare the return value and argument of the interrupt handler start func tion as a void type 2 No system call can be issued from 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 an OS independent interrupt handler always make sure that the OS independent interrupt handler is assigned a priority level higher than other OS dependent interrupt handlers include lt mr30 h gt include id h void inthand void process Figure 5 4 Example of OS independent Interrupt Handler
121. reguency can be entered using decimal numbers only Frequency entry examples are presented below 98 Chapter 6 Using Configurator 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 10ms 10 5ms It is also well to remember that the time must not begin with period The time of day The time of day is expressed using 3 word 48 bit data which consists of 1 word 16 bit num bers joined with colon as shown in the example below 23 0x02 100B If one or two high order numbers of a total of three numbers are omitted the omitted numbers are regarded as 0 For instance 12 is equivalent to 0 0 12 6 1 Configuration File Creation Procedure 6 1 2 Configuration File Definition Items The following definitions are to be formulated in the configuration file System definition System clock definition Respective maximum number of items Task definition Eventflag definition Semaphore definition Mailbox definition Fixed size Memorypool definition Variable size Memorypool definition Cyclic handler definition Alaram handler definit
122. rocomputer 5 Software maintainability is enhanced When the real time OS is put to use the developed software consists of small program mod ules called tasks Therefore increased software maintainability is provided because devel oped software maintenance can be carried out simply by maintaining small tasks 6 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 7 The microcomputer performance can be optimized to improve the performance of mi crocomputer 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 improve ment 6 Chapter 2 General Information 2 2 Relationship between TRON Specification and MR30 The TRON Specification is an abbreviation for The Real time Operating system Nucleus specification It denotes the specifications for the nucleus of a real time operating system The TRON Project which is centered on TRON Specification design is pushed forward under the leadership of Dr Ken Sakamu ra at Faculty of Science University of Tokyo As one item of this TRON Project the ITRON Specif
123. rupt Handler 72 5 23 Writing OS independent Interrupt Handler 73 5 2 4 Writing Cydic Handler Alarm Handler 74 53 TheUseof INT Jett 200 dg en 75 5 4 TheUseof registers of bank 75 5 5 Regardina terruptS z5 v1 sealed raat dee kbd rd br weird Rn 76 5 5 1 Types ofInterrupt Handler 76 5 5 2 The Use of MNon oekabieloterrugt 76 5 3 3 Controlling Ree 77 5 6 Regarding Delay Dispatching 79 5 7 Regarding Initially Activated Task AA 81 5 8 Modifying MR30 Startup Program 82 5 81 C Language Startup Program toi a 201 63 5 9 gt Memory Allocation iii AA a nebu 89 591 Section Allocation Of start a 90 3 92 Section Allocation of ot a 91 5 10 Cautions for each microcontroler ssssssessissssrresississrntirsttnttsrnttnstnninstnntnnstnnnnnnnnn annen nnna 93 5 10 1 To use the Ier S7oroupMCUe 93 5 10 2 To use the M16C 6N group AMCUe 93 Chapter6 Using Configurator iioncionanaionacaiodaconninalondanesinanadanadodadaniznanidanadondu nada nado dadadadasiaViniiaddasaias 95 6 1 Configuration File Creation Procechure nnns 96 6 11 Configuration Eieiiatzafotrkformat 96 OP an 97 Direction of COMPUTATION 0 ee eee i ne rr 97 6 12 Configuration File Definition Jrente 99 CSystem Definition Procedure licita 99 System Clock Definition Procedure il 100 Definition respective maximum numbers of items 1 102 Task definition a A cde aaa Cae OAs TE 104 CEventilag definition di 105 Semaphore definition H 106 LEM al box def
124. s a different task placed in a state other than DORMANT and places it in the DORMANT state When the forcibly terminated task is activated again it acts as if it is reset See Figure 3 18 TaskA TaskB ter tsk B sta tsk B Terminated Reseting TaskB Figure 3 18 Task Resetting Changing the Task Priority chg pri ichg pri Changes the task priority and if the task is in the READY or RUN state updates the ready queue also See Figure 3 19 3 5 MR30 Kernel Structure Priority NEL yn Figure 3 19 33 TCB TCB TCB TCB TCB o Priority Change Rotating the Ready Queue rot rda irot rdg This system call establishes the TSS time sharing system That is if the ready gueue is ro tated at regular intervals round robin scheduling reguired for the TSS is accomplished See Figure 3 20 Priority Figure 3 20 TCB TCB TCB Move the end of the queue Ready Queue Management by rot_rdq System Call Forcibly Clearing the Task WAIT State rel_wai irel_wai Forcibly clears the task WAIT state The WAIT state tasks to be cleared by this system call are those which have entered the WAIT state under the following conditions 34 Chapter 3 Introduction to MR30 Waiting for timeout Waiting for by the slp tsk system call With Timeout Waiting for the eventflag With Timeout Waiting for the semaphore With Timeout Waiting for a message With Timeout s
125. s from a Handler That Caused an Interrupt during Handler Execution 133 7 2 Calculating the Amount of RAM Used by the System eee eee 134 AS SUACKS ia 135 731 System Stack and User Stack 135 Chapter8 Sample Program Description 4e eeeseeeeneeeeeee eee eee eee nene eee een 137 8 1 Overview of Sample Proor am 138 8 2 Program SourceListing r ur ebene 139 8 3 Configuration EEN 141 Chapter 9 Separ teROMS iia a nl 143 9 1 How to Form SepnaratebOM e AAA 144 List of Figures v List of Figures Figure 3 1 Figure 3 2 Figure 3 3 Figure 3 4 Figure 3 5 Figure 3 6 Figure 3 7 Figure 3 8 Figure 3 9 Figure 3 10 Figure 3 11 Figure 3 12 Figure 3 13 Figure 3 14 Figure 3 15 Figure 3 16 Figure 3 17 Figure 3 18 Figure 3 19 Figure 3 20 Figure 3 21 Figure 3 22 Figure 3 23 Figure 3 24 Figure 3 25 Figure 3 26 Figure 3 27 Figure 3 28 Figure 3 29 Figure 3 30 Figure 3 31 Figure 3 32 Figure 3 33 Figure 3 34 Figure 3 35 Figure 3 36 Figure 3 37 Figure 3 38 Figure 3 39 Figure 4 1 Figure 4 2 Figure 4 3 Relationship between Program Size and Development Period 10 Microcomputer based System Example Audio Equipment 11 Example System Configuration with Real time OS Audio E quipment 12 Time division Task Operation 13 Task Execution Interruption and Resumption nn 14 Task SWIECHING SK SR R NE S R a a 14 Task Register Area icon late d kana bu 15 Actual Re
126. ssary to determine which task the system should execute first To properly handle this kind of situation the system organizes 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 The MR30 permits giving the same priority to several tasks To provide proper control over the READY task execution order the system generates a task execution gueue called ready gueue 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 RUN state Priority TCB TCB TCB 2 r TCB TCB Figure 3 14 Ready Queue Execution Queue 24 The TCB task control block is described in the next chapter 2 The task in the RUN state remains in the ready queue 3 3 Task 25 3 3 3 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 MR30 manages the following task information as the task control block Task connection pointer Task connection pointer used for ready gueue formation or other purposes Task status Task priority Task register information and other data storage stack area pointe
127. stem call issued System call processing flag l gt 0 lt 1 1 1 IPL 0 systemiPL 0 systemiPL ie 0 When the flag before issuing a system call is 0 Task System call issued System call processing E 2 O se A abs I IPL O system PL 0 gt system PL o 0 Figure 5 12 Interrupt control in a System Call that can be Issued from only a Task For system calls that can be issued from only task independent section or from both task independent section and task 78 Chapter 5 Detailed Applications When the flag before issuing a system call is 1 po Syst II issued stem call processing Task ot Handler PETS Y Handler T IT flag 1 His 1 1 I IPL 4 system PL el 4 lt system PL lt 4 When the I flag before issuing a system call is O Task OF system call issued stem call processin TOR Handler P y p 9 Handler m flag 0 lt 0 0 IPL 4 al systemIPL 4 a systemiPL ie 4 Figure 5 13 Interrupt control in a System Call that can be Issued from a Task independent As shown in Figure 5 12 and Figure 5 13 the interrupt enable flag and IPL change in a system 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
128. sters TaskB ret int Figure 7 3 Processing Procedure for a system call from a Multiplex interrupt Handler 134 Chapter 7 Application Creation Guide 7 2 Calculating the Amount of RAM Used by the System The RAM used by the MR30 kernel to manage tasks etc is placed in the MR RAM section The RAM capacity used by MR30 in the MR RAM section can be found by calculation according to Table 7 1 However this does not include the stacks used by the system and tasks Refer to the reference manual for details on how to calculate the stack size Table 7 1 MR RAM Method for Caluculating Size of MR RAM Section Area Name Numbers of Bytes System work area 4 number of priority levels System clock management area 6 Task management area 11 x number of tasks Without Timeout 15 x number of tasks With Timeout Timer queue management area 6 Cyclic handler management area 3 x number of cyclic handlers Alarm handler management area 1 Eventflag management area 4 x number of Eventflag 1 number of Eventflag 1 8 Semaphore management area 3 x number of semaphore Fixed size memorypool management area 2 x number of Fixed size memorypool Variable size memorypool management area 44 Mailbox management area 7 x number of mailbox mailbox buffer size x 2 case 16 bit or mailbox buffer size x 4 case 32 bit The minimum R
129. sued to place itin a SUSPEND state During delay dispatching 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 re moved from the ready gueue and placed in a SUSPEND 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 returned However tasks are not switched over until delay dis patching is cleared The task to be executed after disabled dispatching is re enabled is linked to the ready queue rot rdg irot_rdq during dispatch delay When rot_rdq TPRI RUN 0 is issued during dispatch delay the ready queue of the own task s priority is rotated Also when irot_rdq 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 during dispatch delay 80 Chapter 5 Detailed Applications 4 Precautions No system 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 orloc cpu ena dsp and dis dsp cannot be issued while in a state where interrupts and dispatch are dis abled by loc cpu Disabled dispatch is re enabled by issuing ena dsp once after
130. t switching This processing operation takes time Interrupt processing which reguires high speed response can be carried out by the MR30 without effecting context switching That is the interrupted task context registers can be used as is to run a program This type of program is called the handler As the handler uses the interrupted task context registers as is it is always necessary to save the interrupted task context into memory at the begin ning of the handler and put the saved context back into the original position when returning to the task To make a return from the interrupt handler the ret int system call should normally be used when writ ten in assembly language See 5 2 2 However if no MR30 system call is used within the interrupt handler the reit instruction can be used to make a return See 5 2 3 The following handlers are provided 1 Interrupt Handler A program that starts upon hardware interruption is called the interrupt handler The MR30 is not concerned in interrupt handler activation Therefore the interrupt handler entry address is to be directly written into the interrupt vector table The interrupt handler is provided for two types of interrupts OS independent and OS dependent interrupts Refer to Section 5 5 for details about each interrupt 2 Cyclic Handler This handler is a program that starts cyclically at preselected time intervals The cyclic han dler activity is to be changed determine whet
131. task2 and task3 turn to app prog void task2 void void task3 void Locating sections 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 sec tions given below must agree with each other between two applications MR30 s RAM data MR RAM MR RAM DBG section VR HEAP section MR30 s ROM data MR ROM section Interrupt vector area INTERRUPT VECTOR section Settings of the section files are given below section MR RAM DBG DATA R30 s RAM data DH org 500H The address common to two applications section MR_RAM DATA MR30 s RAM data org 600H The address common to two applications section MR HEAP DATA MR30 s RAM data org 10000H The address common to two applications section MR ROM ROMDATA MR30 s ROM data org 0e0000H The address common to two applications section MR CIF COD 1 C language I F routine section app_prog CODE Use Program section INTERRUPT_VECTOR Interrupt Vector org Offd00H The address common to two applications The memory map turns to give below See Figure 9 2 148 Chapter 9 Separate ROMs d EOOOOH Startup program MR KERNEL section AROR MR30 kernel Task of ID 1 program section common program F 0000H MR30 s ROM data MR ROM section
132. terrupt Management Eugchion 43 3 5 9 Memorypool Management Function enssnsensnensnensnnnnnnnnnnnennnonnnonnnnnnnennnsnnsnnnnnnannn 45 Fixed size Memorypool Management EFunclon nen nnnn nn n 45 Variable size Memorypool Management Fundlon nennen 46 3 5 10 Time Management Eunmction 48 3 5 11 Version Management Function u uunsnensnennsnnnonensnnnnnnnnnnnnunnnennnonnnonnrnnnnnennnonnrsnnnnnnennn 51 3 5 12 System Calls That Can Be Issued from Task and Handler 52 Chapter 4 Applications Development Procedure Overview nnnnssesessnnsnnnnnnnnnnnnnannnnnnnnnnnnnnnnnnnnnn 55 4 1 General Description 56 4 2 Development Procedure Example nenn ea nenene ran 58 4 2 1 Applications Program Coing 58 ii Contents 4 2 2 Configuration File Drenaration 0000000000000 00 000K A ARK A ARK AR KARA KAR KARA RKK K Ann 60 423 Configurator E vecution PAKA R AREA REESE KEE KAR KARA E AKA E KARA KKK K A 61 4 2 4 SYSLOMOEOFA EE 61 4 25 WEIENG EE 61 Chapter5 Detailed Applications ae raaa a aare a aaa aaa Aa Aa aaa aa EA Taa SEA Ree ASK KAS Ken 63 5 1 Program Coding Procedure in C Language nac cnc 64 5 11 Task Description Brochure 64 5 1 2 Writing OS dependent Interrupt Handler 67 3 1 3 Writing OS independent Interrupt Handler 68 3 1 4 Writing Cyclic Handler Alarm Handler 69 5 2 Program Coding Procedure in Assembly Language 70 524 WONG TASK eerie el vier Mn hii anna tne ee wen ae SALE PRUSKA Ati ies batata 70 5 2 2 Writing OS dependent Inter
133. 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
134. to the cur rent directory If necessary correct or add the sections below Setting processor mode register Set a processor mode matched to your system to the processor mode register 102th line in crtOmr a30 Adding user required initialization program When there is an initialization program that is required for your application add it to the 190th line in the C language startup program crtOmr a30 Comment out the 192th 192th line in the C language startup program crtOmr a30 if no standard I O function is used 5 8 Modifying MR30 Startup Program 5 8 1 C Language Startup Program crtOmr a30 Figure 5 14 shows the C language startup program crtOmr a30 83 1 F AkkkkAkkAkXA A KA A A A KA X AA KA AKA KA A KA ZA A KA AKA KA AKA AK KH KK KA KA A FH KA KH A AH KA A U 2 3 MR30 start up program for C language 4 COPYRIGHT C 2003 RENESAS TECHNOLOGY CORPORATION DS AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED KKK KKK KKK A KA KA A KA AAA KA AX KA KA AKA KA A KA KA KA AAA KH A FH KH RARA AAA 8 Id crtOmr a30 v 1 44 2003 08 22 13 00 34 muraki Exp 9 10 Pd E E OFF 11 include c sec inc 12 include mr30 inc 13 include sys_rom inc 14 include sys_ram inc 1 5 list ON 16 Si 18 SBDATA area definition 19 20 glb LB r 21 SB __SB__ 22 23
135. uct distributor when considering the use of a product contained herein for any specific pur poses such as apparatus or systems for transportation vehicular medical aerospace nuclear or undersea repeater use The prior written approval of Renesas Technology Corporation and Renesas Solutions Corporation is necessary to reprint or reproduce in whole or in part these materials 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 O Please contact Renesas Technology Corporation or Renesas Solutions Corporation for further details on these materials or the pro ducts 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 MR30 is a real time operating system for the M16C microcomputers The MR30 conforms to the uITRON Specification This manual describes the procedures and precautions to observe when you use the MR30 for pro gramming purposes For the detailed information on individual system
136. whether the flag controlled within the MR30 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 MR30 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 Memorypool Management Module Provides dynamic allocation or release of a memory area used by a task or a handler 31 This handler actuates once only at preselected times 32 This handler periodically actuates 32 Chapter 3 Introduction to MR30 3 5 3 Task Management Function The task management function is used to perform task operations such as task start stop and task priority updating The MR30 kernel offers the following task management function system calls Starting the Task sta tsk Starts the task changing its status from DORMANT to either READY or RUN Starting the Task from the handler ista tsk By activating a task from the handler the status of the task to be activated is changed from the DORMANT state to either READY or RUN Ending lts Own Task ext tsk Ends its own task and places it in the DORMANT state so that this task will not be executed until activated again Forcibly Terminating Some Other Task ter tsk Forcibly terminate
137. 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 90 for details about each section 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 NC30 Refer to page 90 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 0F0000H Correct this address to F1000H J section program org OF1000H 90 5 9 1 Chapter 5 Detailed Applications Section Allocation of start a30 The section allocation of the sample startup program for the assembly language start a30 is defined in asm sec inc Edit asm_sec inc if section reallocation is required The following explains each section that is defined in the sample section definition file asm_sec inc MR_RAM_DBG section This section is stored MR30 s debug function RAM data This section must be mapped in the Internal RAM area MR_RAM section This section is where the RAM data MR30 s system management data is stored that is ref erenced in absolute addressing This section must be mapped between 0 and FFFFH near area
138. x_memsize the value specified in the configuration file X data size for block control 8 byte For example if you request 200 byte the MR30 rounds off the size to 244 bytes and ac quires 244 byte memory If memory acquirement goes well the MR30 returns the first address of the memory acquired along with the error code E_OK If memory acquirement fails the MR30 returns the error code E TMOUT 3 5 MR30 Kernel Structure 47 TaskA Rounding Memorypool pget_blk 224 bytes gt 200 bytes Figure 3 33 pget blk processing e Releasing a Memory block rel blk Release a acquired memory block by pget blk system call TaskA Memorypool Figure 3 34 rel blk processing Refer Memorypool Status ref mpl Checks the total free area of the memorypool and the size of the maximum free area that can immediately be acauired 48 Chapter 3 Introduction to MR30 3 5 10 Time Management Function The time management function provides system time management time reading time setup and the functions of the alarm handler which actuates at preselected times and the cyclic handler which actuates at preselected time intervals The MR30 kernel makes an exclusive use of one M16C 60 Series microcomputer hardware timer as the system timer The configuration file is used to determine which timer is to be employed as the sys tem timer The MR30 kernel offers the following time management system calls Placing a task in wait st
139. your file c_sec inc or asm_sec inc allocate this section in MR_RAM section 3 Number of block Definition format Numeric value Definition range 1 16 Define all Number of block for memorypool 4 Size Definition format Numeric value Definition range 1 65535 Define the size of one memorypool block When this definition is formulated the RAM capacity of the memorypool is set to number of blocks x size Variable size memorypool definition This definition is necessary to use Variable size memorypool function lt lt Format gt gt Variable Size Memorypool Definition variable _memorypool ID No max_memsize The maximum memory block size to be allocated heap_size Memorypool size y Assign 1 to the ID number The memorypool is allocated in MR_HEAP section lt lt Content gt gt 1 The maximum memory block size to be allocated Definition format Numeric value Definition range 1 65520 Specify within an application program the maximum memory block size to be allocated 6 1 Configuration File Creation Procedure 109 2 Memorypool size Definition format Numeric value Definition range 16 524288 Specify a memorypool 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 memorypool The following eguations defi
Download Pdf Manuals
Related Search
Related Contents
FR-FE ・FRS-FE 正面型取扱説明書 工事成績評定表(土木工事編) 取扱説明書 - Bose User Manual - Boardman Medical Supply Seagate DiamondMax 21 22 1TB SATA Les cahiers techniques - Spontex Professionnel Sony KV-14V5U TV VCR Combo User Manual Copyright © All rights reserved.
Failed to retrieve file