Home

MR32R V.3.50 Release 1 User`s Manual

image

Contents

1. include mr32r inc include sys rom inc include sys ram inc include mrtable inc 19 20 global Sys Sp sys timer START 21 global D INIT START sys timer init start up exit 22 global TOP USER STACK init usr memblk usr getmem 23 global SYSCALLO SYSCALL1 OP HEAP init memblk 24 25 a section definition of a start up file 26 27 Section STARTUP awx 28 balign 4 29 equ NULL 0 30 31 A start up program is started from here 32 33 START 34 35 A system stack pointer is set up 36 37 seth rl f4high Sys Sp 38 or3 rl rl tflow Sys Sp 39 addi rl t 4 40 mvtc rl CR2 SPI initialize 41 mvtc rl R3 42 idi r0 1 43 st r0 rl 44 ldi r0 NULL 45 mvtc rO CRO PSW initialize 46 47 SUE Dbg flg 48 1d24 rl 4 Dbg mode 49 ldi r2 0 50 ldi r2 4 Bd stb r2 rl 52 endif 53 54 Perform a setup in the mode of a microcomputer of operation etc 55 D6 3 573 Description below if you need 58 ex Master Slavemode initialize Power management initialize 5295s O O 8 2 How to Customize the MR32R Startup Program 177 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 LEN 142 IT3 114 TILS 116 117 118 119 120 T21 1 22 123 124 Initialize section The zero clearance of the data without initia
2. LM 0 Figure 6 1 Interrupt control in a System Call that can be Issued As shown in Figure 6 1 the interrupt enabling flag varies in value within a system call Thus it is not recommended to manipulate the interrupt disabling flag so as to disable interrupts within a user appli cation The following two methods for interrupt control are recommended 1 Modify the interrupt control register for the interrupt you want to be disabled 2 Use system calls loc cpu and uni cpu 6 6 Regarding Interrupts 99 6 6 2 The procedure for running the interrupt handler MR32R runs the interrupt handler in line with the procedure as shown in Figure 6 2 Task processing The part you describe Entry and Exit processing of MR32R Interrupt entry processing 2 3 Interrupt processing 4 5 Interrupt exit processing 6 i Scheduler Task processing Figure 6 2 The procedure for running the interrupt handler 1 Stores the register and calls the user s interrupt entry processing routine 2 Theuser s interrupt entry processing routine Reads the interrupt level and saves it in the stack Reads the interrupt factor and piles the jump address of the interrupt on the stack 3 Calls the address of the interrupt handler piled on the stack 4 The interrupt handling routine 5 Calls the user s interrupt exit routine 6 The interrupt exit routine Restores the interrupt level to
3. Key input Remote control Task Task x2 Register Register Figure 3 6 Task Switching The example presented in Figure 3 7 indicates how the individual task registers are managed In real 3 1 Concept of Real time OS 15 ity itis necessary to provide not only a register but also a stack area for each task Memory map Remote control Task Key input LED illumination Task gt Real time OS Figure 3 8 shows the register and stack area of one task in detail In the MR32R the register of each task is stored in a stack area as shown in Figure 3 8 This figure shows the state prevailing after reg ister storage Figure 3 7 Task Register Area 16 Chapter 3 Introduction to MR32R Key input task stack Key input Register stored EIT 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 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 Remote control Task Real time OS task 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
4. ssssss 134 MPU Information 66 MR RAM Sistah daar tds 203 MR32R 4 rcnt erede mtis eec dus 8 MR32R Specifications Overview 7 IE 32D iiU Oa een RE 82 A MO ea aaa aa a ia kiaii 88 90 91 92 145 N None Large Model 110 NON EXISTENT cpio e 24 O Operating Principles of Real time OS 13 OR Waltz tacet rob ra edis 40 OS dependent interrupt handler 90 P PACD por eene tete n e nte eia as 52 pcal por is Dd onde 51 Pr lira terret speret 57 poet BK icon tete te rts 60 A eren iis 40 DECVATTDT 2 553i rns e roe ern et erinnere tegere 49 PV come EET 45 A ee eicere is 43 priority 2a s eiie eno 120 Product Control Information 66 a A e 66 psnd MD cai rient rre 48 PS o 98 R e 49 A PEE E 45 READY Skate iare DR Reese 22 real time OS coeno rit perg t ici 4 real time OS ssssssssseeeeeeeenennnnes 10 Receive Message Buffer Queue 23 POT ANTM on 64 IzEejTm 64 ref fliiiair beet ec edis 40 A RO teat 49 o A qud 45 ref mpf iioii A 58 ret mpl cite der ee tte ote tes 62 A rec eter Debes 54 POP SOM ml eran ane eae 43 ref SYS iii nares cde einer a tide ne ning 66 Fef ESK ae AE 36 HH M 61 rel Wai cedente eene 35 Rendezvous ite ded Ue 32 Rendezvous definition esseeri 135 Feb Tb ss ceti e rb ee ah 30 55 ROM write form file
5. sse 8 O denegata 35 ds Bic LIRE 54 rSm tsk einerseits 37 RUN state e eet beers 21 S o anh Wee ep e ero Reds 106 Semaphore definition esseere 133 Semaphore Queue 23 Send Messagebuffer Queue sssess 23 Set flg 40 Set ELTTY a ra ttn ie nie n eie ni 64 ON 42 A X 38 snd IMD ie cse menge mid 48 Sndmsgsd c eite dee cet eed 45 Specification Version esere 66 Sta tsk A E n PORE 34 stack size sssssssseseeeeeenenns 203 Start address Of task sess 131 Startup time sss 140 SUS3ESK iuste det aere te pe ee estes 37 SUSPEND state eee 23 Symbol enn ete ERIS 117 synchronization functions attached to task 37 SYS rami lic siia ner needs 145 SYS TOMINC i ota gre e et a dens 145 Systermi call 35 eire rnt tados 17 System Call Processing 18 System Calls Exclusive for Handlers 30 systemi Clock ode RE nut 63 System clock interrupt priority level 127 System Definition Procedure 120 System M anagement sss 66 SSA Sa in 205 TE TAG O TO 52 63 Tasa sia 20 Task definition sse 131 task ID number tus eie cerei 19 task management sssssssssseeeeene 34 Task Statuses uno pnr since 20 task switching 13 tal POR ien etre ce reed rem dea 51 63 jio 26 O OFF 5i UE eoe e 139 TOY ON 2k esepen
6. 0 EIT Vector is defined as EIT OF ROM tart address of Int Vector is defined as INT OF ROM The start address of MR KERN MR The s KERNEL EL is defined as START_OF_ROM START_OF_ROM mr kernel start XA bs ERN EL MR K MR K _KERNEL2 OS_DEBUG mr kernel end STARTUP The s Aa STARTUP text text start text tart address of STARTUP is defined tart address of text is defined gnu warning sections are handled specially by elf32 em 190 Chapter 8 How to Customize l2 gnu warning 128 gnu linkonce t 129 text end 130 0 134 etext 132 PROVIDE etext 133 134 The start address of rodata is defined 135 136 rodata 137 138 rodata start 139 rodata 140 gnu linkonce r 141 rodata end 142 143 144 The start address of MR_RAM is defined as START_OF_MR_RAM 145 146 MR RAM START_OF_MR_RAM 147 148 MR RAM 149 MR Dbg RAM 150 151 152 Adjust the address for the data segment We want to adjust up to 153 the same address within the page on the next page up 154 155 The start address of data is defined 156 157 data ADDR MR_RAM SIZEOF MR_RAM AT LOADADD
7. Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating fixed size memorypool area The area of the specified size here is necessary to allocate a fixed size memorypool area internal RAM when issuing the cre_mpf system call A size of memory required for the fixed size memorypool specified by the cre_mpf system call is allocated from this dynamically creating fixed size memorypool area 7 1 Configuration File Creation Procedure 125 O Dynamically creating fixed size memory pool area definition external RAM lt lt Format gt gt ext_memmpf max_memsize Maximum size of fixed size memorypool to be created all memsize Size of dynamically creating fixed size memorypool area external RAM y lt lt Content gt gt 1 Maximum size of fixed size memorypool to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of fixed size memorypool size among those created by issuing the cre_mpf system call For this value specify the largest size among fixed size memory pools for which external RAM has been specified 2 Size of dynamically creating fixed size memorypool area external RAM Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating fixed size memorypool area The area of the specified size here is necessary to allocate
8. eeeeeeeseeeeeeee nennen nennen nnne nnne nennen 1 Chapter 2 General Information ainsast enana Ea EAEE s Eaa Ca a EAEE NaN EE aAa 3 2 1 Objective of MR32R Development ssssssssseseeeeeeneee nennen nnne entente nnn 4 2 2 Relationship between TRON Specification and MR32R sssssssessseeeenenene 6 2 3 MRSZR Feature 8 Chapter 3 Introduction to MR32R sssssssssssseseeseeeeener nennen nnne nennen nn rene rara 9 3 1 Concept of Real time OS sssssssssessseesseeeene ener ennn nnne tren teniente entes teens 10 311 Why Real time OS 15 Necessary sisse einen tnihi theta aiias ananas 10 312 Operating Principles of Real time OS seien tnn inar ntnn 13 3 2 System Callas eoe ada ete e hr eh de ee 17 321 System Call Processing enrayer aianei kirita aE A aara ENE EATA A Ai aan as EAEE E 18 322 Task Designation in System Call se seinen tnter 19 3 3 Task ii scie due neigt x Ree RN re HERR Le ERES Re HER Re ER te ERR e ERR eO 20 3 341 Task Status d debe db t pb nee pneus 20 332 Task Priority and Ready Queue i i serena 25 333 JTaskGontrol BlIOK I CB uiii t eb e tei iura ecieeks AAA do 26 344 Handler uer e ERE e CERE ERR E ELE See ER Rcg e LR Esp E RR e ERR edes 28 341 System Calls Exclusive for Handlers sie nennt ninh 30 35 MR32R Kernel Structure essssssessessseessee enne enhn enne nne 31 351 MOUUDIeSLTUGtUFe iu c e e ER e ER AUDI ETT A ct LG D
9. cre mbf del mbf for messagebuffer are cre mpf del mpf for fixed size memorypool are cre mpl del mpl for variable size memorypool area The size a b c d of four memory blocks as well as the variable size memory pool is calculable as follows Since the following sizes include management information they become a value fewer 12 bytes than this in fact a max memsize 12 1 96 1 12 b a 2 c a 4 d a 8 Example The task is generated with MR EXT Task A 256 bytes of stack Task B 1024 bytes of stack attribute in the user program In this case since the stack size of Task B serves as the maximum more than max memsize 1024 is specified When the ext memstk definition of a configuration file is set to max memsize 1024 the size of four memory blocks is as follows from the above mentioned formula kind of memory size Size which can be real used a 132 120 b 264 252 c 528 516 d 1056 1040 12 bytes of difference are used as a management information Since the stack size of Task A is 256 bytes the block of size c 7528 is assigned therefore the stack size 1024 bytes of Task B is allocated d 21056 byte memory block The relation of demand size real use size and useless size is as follows demand size real use size useless size TaskA 256 528 272 TaskB 1024 1056 32 Total 1280 1584 304 Therefore if it describe
10. sesssssseeeeeeeenen ens 104 691 When CC32R ls USB se e e A Rb Be 104 692 When TWSZRIS Used s idi oi d east tee t odd te Hed edens 105 693 When D CC M3ZR is used se eene tnit ah ainsi assis siia saa aaa 105 6 10 Memory mapplfig ino A ene uet eee E rene i ae eoo Bee eee 106 6101 Memory Allocation when USING CC3ZR siss seien tnnt tnnt innt 106 6102 MemoryAllocation when Using TW32R D CC M 32R ssssss seen nnns 108 6 103 Memory Model i nte A RET e RR AER AH HS 110 E siege cer deca da eine dr nere ree Pee de IR re Ee PR 110 e Nonelarge model sie etie ere et aa 110 6104 Arrangement to Space Exceeding 16MB of Kernel Area 111 Chapter 7 Using Configurator s aaa eaaa a aaa a Ee ai n nnnm nennen nnne nennen nennen 115 7 1 Configuration File Creation Procedure sess 116 71 1 Configuration File Data Entry Format sienne inniti 116 Slo AE OM pM CEU RM 117 Direction of COMPUTATION eect inanin ant nanain ne netfee ae aana aaa nennen nre nre nennen nen nennen 117 7 1 2 Configuration File Definition Items i iini nain anat 119 713 Configuration FITC Example se neither tnihi innata in sata sata satanas h sanas 142 7 2 Configurator Execution Procedures essssssessseseeeeneenneenne nnne enne 145 721 Configurator Overview seinen tnt h nata haa an sias saa a aaa asa asa assa 145 Contents iii 7 2 2 Setting Configurator Environment sisse teeth nhanh rr 147 7 2 3 Configurato
11. a TaskB Figure 9 3 Processing Procedure for a system call from a Multiplex interrupt Handler 9 2 Calculating the Amount of RAM Used by the System 203 9 2 Calculating the Amount of RAM Used by the System The RAM used by the MR32R kernel to manage tasks etc is placed in the MR RAM section If the dynamic OS object creation function is used the sum of the MR ROM section size and the MR RAM section size Because MR ROM section must be transferred to RAM in uing the dynamic OS object creation functio Table 9 1 Table 9 2 and Table 9 3 show the amount of RAM used by the system Note The stack size used by the system and the task are not included Note The interrupt vector tables were allocated in MR ROM as before but it is allocated in INTERRUPT VECTOR section now This section must be transferred from ROM are to RAM area if def int system call is used See the Refference Manual for the stack size calculation method Table 9 1 The Size of MR RAM Section Area Name Bytes 4 bytes alignment regulation is needed for each section System Management Area 24 4 x priority maximum task x 2 maximum flag maximum semaphore maximum mailbox maximum variable size memorypool maximum fixed size memory pool maximum messagebuffer x 2 maximum rendez vous port x 2 2 maximum priority x the number of mailbox specified as TA TPRI priority x the number of mailbox speci fied as TA
12. align 4 255 reset 256 bra __ START 257 Figure 8 3 Startup Program for C Language for TW32R 8 2 How to Customize the MR32R Startup Program 181 8 2 5 Startup Program for C Language for DCC M32R crtOmr s F SERRER CE KC RAL RACI N SORORE NIORT NON REA RAEE EAE LR ERS REE AR AEE RAE OUR NONE dee eoe Se opo lese KE 2 357 MR32R start up program for C language for DCC M32R 4 Copyright 2001 MITSUBISHI ELECTRIC CORPORATION 5 3 and MITSUBISHI ELECTRIC SEMICONDUCTOR APPLICATION ENGINEERING CORPORATION 6 All Rights Reserved 7j 8 Id crtOmr s v 1 3 2001 04 23 07 05 17 inui Exp 9 10 o A d RHODE EHE ER FE EO AAE eR KA EO dd d dodo dol 11 12 A file required to incorporate OS is included 13 Please do not change this portion 14 15 include mr32r inc 16 include sys_rom inc 17 include sys_ram inc 18 include mrtable inc 19 20 global Sys Sp sys timer START 24d global D INIT START sys timer init start up exit 22 global TOP USER STACK init usr memblk usr getmem 23 global SYSCALLO SYSCALL1 OP HEAP init memblk 24 25 a section definition of a start up file 26 27 Section STARTUP awx 28 balign 4 29 equ NULL 0 30 31 A start up program is started from here 32 33 START 34 35 A system stack pointer is set up 36 34 seth rl t Sys SpQh 38 or3 rl rl t Sys SpQGl 39 addi r1 4 40 mvtc rl CR2 SPI initialize 41
13. 6 2 Regarding Initially Activated Task MR32R allows you to specify a task that starts from a READY state at system startup This specifica tion is made by setting the configuration file Refer to page 132 for details on how to set 6 3 A note on using alarm handler Keep in mind that they are the following specifications at the time of alarm handler use in MR32R The alarm handler started at once is not again started though set up the system time by the set tim system call before starting time 95 When time is set up after the starting time of the alarm handler which has not been started yet by the set tim system call the alarm handler after setting time does not start Please let start se quentially from the early alarm handler of starting time and be sure to make 96 Chapter 6 Notes of developing user program 6 4 About dynamic generation and deletion of the objects 6 4 1 In case dynamic generation functions cre tsk cre mpf cre mpl etc are used it is made to assign the optimal size among the memory blocks of four sizes like the variable size memory pool function in MR32R the target system call is boiled and shown below Structure of Memory in Dynamic Allocation Generation Deletion Table 6 2 Dynamic generation deletion system call list System Call Function cre tsk del tsk exd tsk for stack area def exc for stack area of the exception cre mbx del mbx for mailbox area
14. Dbg sys exit2 Dbg sys timer Dbg idle Dbg RUNtsk Dbg int entry Dbg int exit Dbg int exit2 Dbg ent handler Dbg ext handler Dbg sys exit CkCkckckckckckckckckck ck ckck k ck ck kk ck E ALIGN 4 Dbg sys exit2 Dbg sys timer AENDI aif Y amp MR EXC HANDLER global DEF EXC HDR DEF EXC HDR vret exc aendi AIF XY amp Dbg flg gt 0 Section MR Dbg RAM data align 4 global Dbg mode global Dbg buffer start global Dbg buffer end global X Dbg cnt global Dbg addr global Dbg sys iss Dbg buffer start res b _ Dbg buffer size Dbg buffer end Dbg addr res w 1 Dbg cnt res w 1 Dbg sys iss res w 7 Dbg mode res b 1 aelse Section MR Dbg RAM data align 4 global Dbg mode global Dbg buffer start global Dbg buffer end global X Dbg cnt global Dbg addr global Dbg sys iss Dbg buffer start Dbg buffer end Dbg addr Dbg cnt Dbg mode Dbg sys iss aendi SORORE CR ACER Ue C RC KERK EIT Vector AREA EIT vector area is set up Section EIT Vector COD rte nop TRAPO 251 258 259 260 261 262 263 264 265 266 267 268 269 270 271 22 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 8 2 How to Customize the MR32R Startup Program r
15. Int_Vector 54 in rom3 55 56 GROUP 57 MR KERNEL 58 MR KERNEL 59 MR KERNEL2 60 OS DEBUG 61 62 text 63 text 8 3 Customizing the Section File 195 64 text2 65 init 66 fini 67 rodata 68 69 STARTUP STARTUP 70 gt in_rom4 71 72 GROUP 73 74 MR RAM MR RAM MR_Dbg_RAM T5 76 Arrange data section The start address of the section is defined as 77 START data and the end address of the section is defined as _ END data 78 The transmitting agency address is taken as _ ROM data The last of a file 79 defines transmitting agency address ROM data 80 81 START data 82 data LOAD ROM data 83 data 84 85 END data 86 87 Arrange MR ROM section The start address of the section is defined as 88 START MR ROM and the end address of the section is defined as END MR ROM 89 The transmitting agency address is taken as ROM MR ROM The last of a file 90 defines transmitting agency address ROM data 91 92 START MR ROM 93 MR ROM LOAD ROM MR ROM 94 MR ROM 95 INTERRUPT VECTOR 96 97 END MR ROM 98 99 bss 100 START bss 101 sbss 102 bss 103 COMMON 104 END bss 105 106 SP INIT 107 SYS STACK SYS_STACK 108 SP END 109 INT USR S
16. MFT00 m32102 tpl 4 10ms 020307 main 512 ON image 512 2 printer 512 4 idle 256 5 pagein sys timer sent in 4 2 Development Procedure Example System Definition system stack_size priority y System Clock Definition clock timer_clock timer file_name IPL unit_time initial time y Task Definition task 1 entry address stack size priority initial start y task 2 entry_address stack_size priority task 3 entry_address stack_size priority y task 4 entry_address stack_size priority y Eventflag Definition flag 1 name Interrupt Vector Definition interrupt_vector 16 interrupt_vector 23 Figure 4 3 1024 5 33 3MHz MFTOO m32102 tpl 4 10ms 0700 main 512 1 ON image 512 2 printer 512 4 idle 256 5 pagein Sys timer sent in Configuration File Example 79 80 Chapter 4 Applications Development Procedure Overview 4 2 3 Configurator Execution Execute the configurator cfg32r to generate the system data definition files sys rom inc and sys ram inc include files mr32r inc and id h and system generation procedure description file makefile from the configuration file A cfg32r mv lbp cfg MR32R system configurator V 3 40 00 for CC32R Copyright 1998 2000 MITSUBISHI ELECTRIC CORPORATION and MIT
17. YES 143 144 Chapter 7 Using Configurator rcv mbf YES acp_por YES cal_por YES rpl_rdv YES get blf YES rel_blf YES get blk YES rel blk YES unl_cpu YES dly tsk YES ista_tsk YES ichg_pri YES irot_rdq YES irel_wai YES get_tid YES isus_tsk YES irsm_tsk YES iwup_tsk YES can_wup YES iset_flg YES clr_flg VES pol_flg YES isig_sem YES preq_sem YES isnd_msg YES prcv msg YES set_tim YES get_tim YES act_cyc YES get_ver YES ret_int NO dis_dsp YES loc_cpu YES ext_tsk YES exd_tsk NO y Interrupt Vector Definition interrupt_vector 16 Sys timer End of Configuration 7 2 Configurator Execution Procedures 145 7 2 Configurator Execution Procedures 7 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 7 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 directory 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 LI
18. 94 98 Is A eee eie 205 User stack size of task ssseseess 131 V Variabel size memorypool definition 138 Variable size Memorypool Management 59 Variation Descriptor sesser 66 A tes 67 AS nene re 68 vda Moi roce 68 e 145 E A 66 ES emere 30 68 MPA MDX etes ted toti tinea eri m s 68 OI d e 67 OS trier etim ec eie 68 vref MX aaa naa 68 O eui erasa nianu iei ie anie ua 67 Me ae cete 67 MS E 67 VESE Mirian rad 67 VESE DX iii nth it nr nn p rer rre n i nen 68 VISE IMS sess correre e pes 67 A EE 67 A M 68 ge Mano c 68 W Wal Em 40 Wall Sem zen te epe da ree en nee 43 WAIT state nera epe naa 22 WAIT SUSPEND eeennm eem 23 M3T MR32R V 3 50 User s Manual Rev 1 00 June 1 2003 REJ10J0084 0100Z COPYRIGHT 2003 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED M3T MR32R V 3 50 User s Manual 21 NE SAS Renesas Electronics Corporation 1753 Shimonumabe Nakahara ku Kawasaki shi Kanagawa 211 8668 Japan REJ10J0084 0100Z
19. Define the maximum priority of messages No error is returned if an attempt is made to spec 7 1 Configuration File Creation Procedure 137 ify priority value exceeding the maximum priority of messages O Fixed size memorypool definition lt lt Format gt gt Fixed Memory Pool Definition memorypool ID No name Name mpf_area Fixed size Memorypool location section Section Name num_block Number of blocks for Memorypool siz_block Block size of Memorypool hi The ID number must be in the range of 1 to 32766 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 2 Fixed size Memorypool location Definition format Symbol Definition range MR INTor MR EXT Specify the location of the fixed size memorypool Specifically this means specifying whether you want the fixed size memorypool to be located in the internal RAM or in external RAM Tolocate the fixed size memorypool in the internal RAM Specify MR INT Tolocate the fixed size memorypool in external RAM Specify MR EXT If this item is omitted MR INT is set by default If you specify section in it
20. OJO O x O x O x x x x x 1x O x x 70 Chapter 3 Introduction to MR32R System Call Task Exception handler Interrupt handler Cyclic handler Alarm handler cre_sem x del sem sig sem isig sem wai sem twai sem preq sem ref sem cre mbx del mbx snd msg isnd msg rcv msg trcv msg prcv msg ref mbx cre mbf del mbf snd mbf tsnd mbf psnd mbf rcv mbf trcv mbf prcv mbf ref mbf cre por del por cal por tcal por pcal por acp por tacp por pacp por fwd por rpl rdv ref por Oj joOoOoOj oloocoojojojiojioooiloj jojojooj oojoo xojjoooojoo x ojJoo Ox x x x x x 1x x x x OQxIx x x xIxix x OIOx x Oix xix OJO x x O x x 3 5 MR32R Kernel Structure System Call Task Exception handler Interrupt handler Cyclic handler Alarm handler def int x ret int o amp loc_cpu unl_cpu cre_mpf del mpf get blf tget_blf pget blf rel bif ref mpf cre mpl del mpl get blk tget blk pget blk rel blk ref mpl set tim get tim dly tsk act cyc ref cyc ref alm get ver ref sys def exc vclr ems vset ems vret exc vras fex def cyc ojojoJo
21. Spi start SYS STACK Spi end The start address of INT USR STACK INT USR STACK is defined User stack sections int spu start or INT USR STACK int spu end The start address of MR_HEAP is defined MR HEAP Heap space sections int mpl start MR HEAP int mpl end sbss Sbss start sbss Scommon Sbss end Bes qv bss start dynbss bss COMMON bss end end 4 PROVIDE end The start address of EXT MR RAM The start address of 1 EXT USR STACK or EXT MR RAM is defined EXT MR RAM START OF EXT RAM EXT USR STACK is defined User stack sections ext spu start EXT USR STACK ext spu end or 191 192 254 259 Chapter 8 How to Customize 256 The start address of EXT_MR_HEAP is defined 257 258 259 260 261 262 263 264 EXT MR HEAP Heap space sections ext mpl start EXT MR HEAP ext mpl end 265 Debugging information is arranged This portion is not deleted 266 267 268 269 270 ATL 22 213 274 215 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 Stabs deb
22. acp por Rendezvous Bandes acp por cal por established accept Rendezvous Rendezvous Message transfer z a accept call request L a L End of rendezvous n wait i fwd Ww r a Released from _po Message transfer Rendezvous rendezvous Rendezvous n request call forwarding L rae cd E a a Rendezvous aie of established lendezvous wait a a a Port 2 Port 1 Figure 3 37 Rendezvous forwarding Chapter 3 Introduction to MR32R e Rendezvous reply rpl rdv When this system call rpl rdv is issued a reply message is returned to the calling task be fore terminating rendezvous This system call can only be executed after issuing the acp por tacp port or pacp por system call Upon receiving the reply message the calling task goes from the rendezvous wait state to an executable state TaskA Rendezvous TaskB established call pattern 000 001 AND Rendezvous accept pattern 001 001 accepi acp_por cal_por RRR ORS Message transfer request n lc c L n n a End of rendezvous rpl rdv Rendezvous n reply Processing Reply message restart r LI LI E LI E LI Port E Figure 3 38 Rendezvous reply Reference rendezvous port ref por Checks the rendezvous port of the specified ID to see if there is any task waiting for call or waiting for acceptance 3 5 MR32R Kernel Structure 55 3 5 10 Interrupt Management Function The interrupt management function provides a
23. 137 138 a Ww QC o bs RR I RES Ro C 000 1001 C ho Re al rn 152 153 154 155 156 157 158 159 seth SU ld id id addi jmp Chapter 8 How to Customize r4 shigh ICUIMASK r5 low ICUIMASK r4 r5 r1l5 r4 r1i5 TALA 2 5 r15 44 MM SS S SZ hii il tt E m 4 The initial cofiguration of an interruption priority level is performed It is called from a start up file global set ipl Set ipl ldi seth sth jmp r5 40x07 r4 shigh ICUIMASK r5 Low ICUIMASK r4 r14 It is the interruption routine of a dummy This routine is called when interruption which is not defined as an interrupt handler in a configuration file occures global Int Dummy int Dummy jmp r14 This routine is called when the system call is used in a user program in spite of having specified NO by the system call definition of a configuration file global __SYS_DUMMY SYS DUMMY jmp r14 8 1 Interruption Control Program 161 8 1 3 Interrupt Control Program for TW32R S ROEOCHRCICKECKCR AR Re OUR ROSE RETRATO RAE ARE RS BEARER REEL UR ERS BEER e e We RAE e e ERS dee o e opo lee de EE 2 3 Copyright 2001 MITSUBISHI ELECTRIC CORPORATION 4 and MITSUBISHI ELECTRIC SEMICONDUCTOR APPLICATION ENGINEERING CORPORATION 57 All Rights Reserved 6 dm Id ipl s v 1 3 2001 04 18 06 24 32 i
24. 178 Dbg buffer start 179 space _ Dbg buffer size 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 PALIN 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 Zod 228 229 230 231 232 233 234 235 236 23T 238 239 24 24 24 24 24 24 24 24 24 249 250 251 252 253 o 0 J3J00H4S0 NR 8 2 How to Customize the MR32R Startup Program global __Dbg_buffer_end Global X Dbg cnt global Dbg addr global Dbg sys iss Dbg buffer start Dbg buffer end Dbg addr Dbg cnt Dbg mode Dbg sys iss endif KKK KKK KKK ck k ck kc kk EIT Vector AREA N XXX kk kk kk kk kx kx x EIT vector area is set up SE D Section EIT Vector awx balign 4 TRAP2 TRAP3 TRAPA TRAP5 KHOR DA BKB KR BARB HK ct t if Dbg flg bra SYSCALLO TRAP7 bra SYSCALL1 TRAP8 else global _ Dbg_entry0 _ Dbg_entryl bra Dbg entryO bra Dbg entryl1 endif te TRAPO TRAP10 TRAP11 TRAP12 TRAP13 TRAP14 Hy D Hos Hum 529 5 9 B 905 ct te TRAP15 nop Section Int Vector awx balign 4 global int entry bra int entry MR EXC HANDLER global DEF EXC HDR EF EXC HDR vret exc endif Section RESET VECT ax 179 180 Chapter 8 How to Customize 254
25. 6 Notes of developing user program Memory Allocation when Using TW32R D CC M32R Here follows explanation as to the sections the OS uses when using TW32R or D CC M32R O Sections used when C is in use text Section This section is allocated for user application programs bss sbss Section This section is allocated for non initial valued data This section must be allocated to RAM area rodata Section This section is allocated for constant data sdata data Section This section is allocated for initial valued data This section must be transferred from ROM area to RAM area O Sections for use with MR32R SYS STACK Section This section is allocated for the system stack area Some inner members of the kernel the interrupt handlers and the like use this section This section must be allocated to RAM area INT USR STACK Section This is user stack area in the internal RAM EXT USR STACK Section This is user stack area in the external RAM MR KERNEL MR KERNEL2 Section The OS s kernel uses this section MR RAM Section This is the internal RAM data area used by MR32R EXT MR RAM Section This is the external RAM data area used by MR32R MR ROM Section This section is allocated for fixed data the OS uses This section must be transfer ROM area to RAM area when dynamic creation function is used MR HEAP Section This is the internal RAM heap area used by MR32R This section used when usin
26. 64 J Ver oc eda seed edd redes 66 I A nnn an ai 30 34 A a A ATT 82 Initial priority of task neseser 132 Initial startup Status 132 Initial value of semaphore counter 133 Initial value of system time 127 interrupt control register esseere 98 interrupt handler sesser 85 Interrupt Handler see 28 Interrupt vector definition eee 141 Intervals ettet dee eee e d 139 IPE Wal 5 oua EE 30 35 PROG SEC inerte irren 30 35 FSI te Ks Ooh ente erre 30 37 Iset flg eet inm te pe tesi e nre 30 40 ISl g Semi ccce a 30 42 ISrid ITISg AT 30 45 ista TSK iii TO 30 34 SUS ES viciado 30 37 ITRON Spedification sse 6 A A nentes 30 38 J JAD oes eee tre entrer tra decer RR decretis tone eet 91 L LargeModel cere eh te dep 110 L IB32R eremi terre eie 147 LMC32R i sut Ede equ 80 Ink32R 4 sie enda iei eto ete re nter 197 OC CD E P 94 VOC COU PEE 55 98 M m32r elf objcopy eseeenee 80 Mailbox definition eeeeeeneene 133 Mailbox Queue lt n 23 Mailbox with priority definition 136 maketilG ceste roe Er P Dr de s 149 197 Mak filIg eee 145 makefile dos ssssseeene 145 makefile EWS iina aaa 145 Manufacturer Name erriren 66 Maxmum value of semaphore counter 133 Messagebuffer sssssssseeeeneeenes 32 Messagebuffer definition
27. Identification oio ee ce ied ie bee n 19 Task Status isc p 20 MR32R Task Status Transition essen 21 Ready Queue Execution Queue essen enne nnne nennen 25 Task control block dte cop REA Cd EGRE OD eec te 27 Cyclic Handler Alarm Handler Activation eese 29 MES2R SEFUCLUEG d inne e dendi a Gens de e ce i de E naa CR du Ye anaes 31 Task Resetting isea eiea iee nete ee Ree Rene Ere d ten 35 Priority Changes inet oe eben eter debe Ri UR Ede ee 35 Ready Queue Management by rot rdq System Call sss 36 Suspending and Resuming a Task sesessssssseeeeneeennen nennen 37 Wake Up Request Storage ssssssssssseseeseeneeneenne nennen nnne enne 38 Wake up Request Cancellation sess enne 39 Task Execution Control by the Eventflag coonccoicinnccnnncncconcnconcnonanonancnancrnnnnannnnnn 41 Exclusive Control by Semaphore sssssssssseeeeeeeeee nennen 42 Semaphore Counter 0 ecceecceecceeceeeeceeeceeeneeeneeeaaeeaaecaaesnaesnaeeaaesaaesaaeseaeesnaeseaeseeeseeneeeaes 42 Task Execution Control by Semaphore sse 43 Mall ita m OGTR iad ts A A O ia 44 Meaning of Message ccconccinccincconocononcnonnconn nono 44 Message queue Size sessssssesseees eene er 45 MesSaGebu tien coy Jic tete date tbe rte e eaten utet eae PIRE eoa tet see uite nee
28. If omitted numbers are automatically assigned sequentially beginning with the smallest 134 Chapter 7 Using Configurator lt lt Content gt gt Define the name with which a mailbox is specified in a program 1 Name Definition format Symbol Definition range None Define the name with which a mailbox is specified in a program 2 Mailbox location Definition format Symbol Definition range MR INTor MR EXT Specify the location of the mailbox Specifically this means specifying whether you want the mailbox to be located in the internal RAM or in external RAM Tolocate the mailbox in the internal RAM Specify MR INT Tolocate the mailbox in external RAM Specify MR EXT If this item is omitted MR INT is set by default 3 The maximum number of messages Definition format Numeric Value Definition range 1 or more Define the maximum number of messages that can be stored in a mailbox An error is re turned if an attempt is made to store messages exceeding this limit Messagebuffer definition lt lt Format gt gt MessageBuffer Definition message buffer ID No name Name mbf_area Messagebuffer location buffer_size Maximum number of messagebuffer y The ID number must be in the range of 1 to 32765 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt l
29. Number Use an integer only as in 23 However it must not begin with O 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 O Table 7 1 Numerical Value Entry Examples Oxf12 Oxf12 0a12h Hexadecimal 0a12H 12h 12H Decimal 32 017 Octal 170 170 Binary 101110b 101010B It is also possible to enter operators in numerical values Table 7 2 lists the operators available Table 7 2Operators The system distinguishes between the upper and lower case letters except for the numbers A F and a f 7 1 Configuration File Creation Procedure 117 Operator Priority Direction of computation High From left to right Unary minus From right to left 96 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 e 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 char acter Example symbols are presented below e TASKI e IDLE3 Function Name The function names are indicated by a character string that consists of numerals upper and lower case alphabetical letters d
30. OJO O O O O O O O O O OJO O OJO O O O OJO O OJO O Ox O xIxxixix x OloOo OloO Oilx O OlOix xix x xix O xlOIx xx ix xix vret exc can t be issued from a task The System Call can t be issued from the Interrupt Handler in C language 71 72 Chapter 3 Introduction to MR32R System Call Task Exception handler Interrupt handler Cyclic handler Alarm handler vrst msg x vrst mbf vrst_blf vrst_blk vcre_mbx vdel mbx vsnd mbx visnd mbx vrcv mbx vtrcv mbx vprcv mbx vrst mbx vref mbx O OJIOOO xj oOo oOo Oo OJOJO O O IxlO x Ix OIx x xx ixi x Chapter 4 Applications Development Procedure Overview 74 Chapter 4 Applications Development Procedure Overview 4 14 General Description The MR32R application programs are generally developed using the following procedures 1 Applications Program Coding Code an applications program in C or assembly language 2 Generating an interrupt control program Generate an interrupt control program ipl ms for CC32R and ipl s for TW32R DCC M32R involved in the board M3A 2131 for the evaluation of M32102 which is ap pended to the product 3 Configuration File Preparation Using the editor prepare the configuration file in which the task entry address stack size and the like are defined 4 Configurator Execution Using the configuration file create the syst
31. ON y task entry_address task1 stack_size 0x1000 stack_area INTERNAL priority 2 y task entry_address task2 stack_area INTERNAL stack_size 0x1000 priority 3 y mailbox name mbx1 mbx area INTERNAL buffer_size 10 y mailbox name mbx2 mbx area INTERNAL 212 Chapter 10 Apendex 63 buffer size 10 64 65 66 variable memorypool 67 name memb1k1 68 max memsize 0x100 69 heap size 0x300 70 71 cyclic hand Yu interval counter 10 73 mode TCY_ON 74 entry_address cyh10 75 76 77 alarm hand 78 time 0 00 5 79 entry address alh1 80 81 82 systemcall 83 cre tsk NO 84 del tsk NO 85 sta tsk YES 86 ter tsk NO 87 chg pri NO 88 rot rdq NO 89 rel wai NO 90 ena dsp NO 91 sus_tsk NO 92 rsm_tsk NO 93 slp_tsk YES 94 wup_tsk NO 95 set_flg NO 96 wai_flg NO 97 sig_sem NO 98 wai sem NO 99 snd msg NO 100 rcv msg YES 101 pget blf NO 102 rel blf NO 103 pget blk YES 104 rel blk YES 105 unl cpu NO 106 dly tsk YES 107 ista tsk YES 108 ichg pri NO 109 irot rdq NO 110 irel wai NO 111 get tid NO 112 isus tsk NO 113 irsm_tsk NO 114 iwup_tsk YES 1 15 can wup NO 116 iset flg NO 117 elr_flg NO 118 pol_flg NO 119 isig_sem NO 120
32. Reserved I I CONDUCTOR APPLICATION ENGIN ERING CORPORATION SId crtOmr ms v 1 5 2001 04 23 07 05 17 inui Exp PRR RRR RRR KEK RK KK KKK RE KKK KK ke ko kk kk koc ke kk KKK KKK KKK KK RK KKK KKK KK ERK kk ko ke kk koc ke ke ke ke e ke ke A file required to incorporate OS is included Please do not change this portion Sys timer int entry START D INIT START Sys timer init start up exit TOP USER STACK init usr memblk S usr getmem _ SYSCALLO SYSCALLI1 TOP HEAP init memblk ROM INTERRUPT VECTOR data RUPT VECTOR data R HEAP data align 4 X R HEAP data align 4 T_USR_STACK data align 4 ACK data align 4 _RAM data align 4 ERNEL2 code align 4 1 code align 4 ROM_MR_ROM data align 4 R_ROM data align 4 _DEBUG code align 4 START_UP code align 4 include mr32r inc include sys_rom inc include sys_ram inc include mrtable inc global Sys Sp global global global global Set ipl Section B data Section D data Section P code Section C data Section ROM D data sSection Section ER Section HE Section EXT MR Section INT section EXT_USR_S Section EXT MR Section R_K Section R KERNE Section Section Section OS a section definition of a start up file Section NULL EQU 0 When you use the bas register function please se
33. a fixed size memorypool area external RAM when issuing the cre mpf system call A size of memory required for the fixed size memorypool specified by the cre mpf system call is allocated from this dynamically creating fixed size memorypool area Dynamically creating variable size memory pool area definition internal RAM lt lt Format gt gt int_memmp 1 max memsize Maximum size of variable size memorypool to be created all memsize Size of dynamically creating variable size memorypool area internal RAM y lt lt Content gt gt 1 Maximum size of variable size memorypool to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of variable size memorypool size among those created by issu ing the cre mpl system call For this value specify the largest size among variable size memorypools for which the internal RAM has been specified 2 Size of dynamically creating variable size memorypool area internal RAM Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating variable size memorypool area 126 Chapter 7 Using Configurator The area of the specified size here is necessary to allocate a variable size memorypool area internal RAM when issuing the cre mpl system call A size of memory required for the variable size memorypool specified by the cre mpl system ca
34. 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 Chapter 3 Introduction to MR32R 3 2 1 System Call Processing When a system call is issued processing takes place in the following sequence 1 Thecurrent register contents are saved 2 The stack pointer is changed from the task type to the real time OS system type 3 Processing is performed in compliance with the request made by the system call 4 Thetask to be executed next is selected 5 The stack pointer is changed to the task type 6 Theregister 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 Processing Task Selection Task gt SP LED illumination Task Figure 3 10 System Call Processing Flowchart 8 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 MR32R 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 fol
35. 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 When the execution task in delayed dispatch 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 2 isus tsk irsm tsk during delayed dispatch 3 4 e e e 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 issued to place it in a SUSPEND state During delayed dispatch The task under execution is handled inside the OS as having had its delayed dispatch cleared For this reason in isus tsk that has been issued to the task under execution the task is re moved from the ready queue and placed in a SUSPEND state Error code E OK is returned Then when irms tsk is issued to the task under execution the task is linked to the ready queue and error code E OK is returned Howeve
36. function to process requested external interrupts in real time The interrupt management system calls provided by the MR32R kernel include the following Define interrupt handler def int Defines an interrupt handler in the specified interrupt vector Return from interrupt handler ret int When returning from the interrupt handler this ret int system call starts the scheduler to Switch over the tasks as necessary The interrupt management function is automatically called at end of the handler function In this case therefore this system call does not need to be called Disabling interrupts and task dispatch loc cpu The loc cpu system call disables 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 39 shows an interrupt processing flow Processing a series of operations from task selection to register restoration is called a scheduler 56 Chapter 3 Introduction to MR32R TaskA NN Interrupt Save Registers iwup tsk Task Selection Restore Registers TaskB Figure 3 39 Interrupt process flow 3 5 MR32R Kernel Structure 57 3 5 11 Memorypool Management Function The memorypool management function provides system memory space RAM space dynamic con trol This functio
37. in your configuration file cfg32r Error system s default is not defined These items must be set int the default configuration file cfg32r Error double definition lt XXXX gt near line 17 test cfg XXXX is already defined Check and delete the extra definition cfg32r Error double definition XXXX x near line 77 default cfg cfg32r Error double definition XXXX x test cfg The ID number in item XXXX is already registered Modify the ID number or delete the extra definition cfg32r Error you must define XXXX near line 107 test cfg XXXX cannot be ommited cfg32r Error you must define SYMBOL near line 30 test cfg This symbol cannnot be omitted cfg32r Error start up file XXXX not found The start up file XXXX cannot be found in the current directory The startup file is required in the current directory cfg32r Error bad start up file XXXX There is unnecessary start up file in the current directory cfg32r Error no source file No source file is found in the current directory cfg32r Error zero divide error near line 28 test cfg A zero divide operation occured in some arithmetic expression 7 2 Configurator Execution Procedures 153 Warning messages The following message are a warning A warning can be ignored providing that its content is under stood cfg32r Warning system is not defined test cfg cfg32r Warning system XXXX is not defined test cfg System definition or system definiti
38. input task is placed in the execution RUN state While the system waits for key input task execution is not needed In that situation 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 MR32R 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 7 NON EXISTENTstate Every task is in one of the above seven different states Figure 3 13 shows task status transition 3 3 Task 21 MPU exedusive right acquisition READY state RUN state MPU exedusive right relinquishment Entering the WAIT state dear WAIT state WAIT state SUSPEND state clear SUSPEND request Forced request from other task from other task alles from other task WAIT SUSPEND 7 state WAIT state dear SUSPEND request request from other task SUSPEND gt SUSPEND state state clear request Forced termination request from other task DORMANT state Task activation Delete Task Create Task NON EXISTENT state Exit and Delete itself Figure 3 13 MR32R 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
39. it 114 115 1424 r6 __INT_VECTOR 116 add 6 275 117 ld r6 r6 T18 st r6 0 16 r15 119 ld r6 r1l5 120 ld r5 r1l5 121 ed r4 r1l5 122 ld r14 r15 123 jmp r14 124 125 An interruption control register is return 127 please do not change this label name outputted to a sys_rom inc file ion and can be arranged to d and it returns to OS kernel 126 Since it is called from OS kernel by interruption exit processing 8 1 Interruption Control Program 163 128 129 global RESTORE IPL from STACK 130 RESTORE IPL from STACK b e 5 131 st r14 r15 132 st r4 r15 l33 st 15 015 134 id r5 Q 12 r15 6 135 1d24 r4 ICUIMASK 136 st r5 r4 137 id rb Qrl5bt 5 5 138 id r4 Qr15 139 ld r14 r15 140 addi v15 4 141 jmp CV ee 4 142 143 The initial cofiguration of an interruption priority level is performed 144 It is called from a start up file 145 global __set_ipl 146 set ipl 147 ldi r5 0x07 148 1d24 r4 ICUIMASK 149 sth r5 r4 150 jmp r14 151 152 It is the interruption routine of a dummy 153 This routine is called when interruption which is not defined as an 154 interrupt handler in a configuration file occures 155 156 global Int Dummy 157 _ Int Dummy 158 jmp R14 159 160 This routine is called when the system call is used in a user program 161 in sp
40. label name O25 93 94 global SAVE IPL to STACK INT VECTOR 95 SAVE IPL to STACK 7 1 96 addi R15 4 8 ne 2 97 st R14 4 R15 98 st R4 Q R15 99 st R5 R15 100 st R6 Q R15 101 102 An interruption control register is saved on a stack and an interruption 103 factor number is read 104 105 1d24 v4 ICUISTS 3 106 id r5 r4 107 st r5 0 20 r15 108 srli r5 20 109 110 Table reference is carried out from __INT_VECTOR and interruption jump place 111 address is saved on a stack This table is outputted to a sys rom inc file 112 by configurator as an INTERRUPT VECTOR section and can be arranged to 113 arbitrary addresses by it 114 115 1d24 r6 __INT_VECTOR 116 add ro c5 117 ld r6 r6 118 st r6 0 16 r15 119 1d R6 Q0R154 0 3 120 id R5 R15 121 id R4 R15 122 id R14 R15 123 jmp Ri4 0 0 0 0 aas sssL 2 124 125 An interruption control register is returned and it returns to OS kernel 126 Since it is called from OS kernel by interruption exit processing 166 Chapter 8 How to Customize 127 please do not change this label name 128 129 global RESTORE IPL from STACK 130 RESTORE IPL from STACK 2 5 131 st R14 R15 132 st R4 R15 139 st R5 R15 134 ld R5 12 R15 enn nnn 6 135 1d24 r4 ICUIMASK 136
41. mvtc fl CR3 42 Tdi r0 1 43 st r0 rl 44 ldi r0 NULL 45 mvtc TO ORO PSW initialize 46 47 eL Dbg flg 48 1d24 rl 4 Dbg mode 49 3 ldi r2 0 50 ldi r2 4 Sl stb r2 rl 52 endif 53 54 Perform a setup in the mode of a microcomputer of operation etc 55 56 Description below if you need 5 ex Master Slavemode initialize Power management initialize 58 5 59 3 Initialize section 60 61 OY N The zero clearance of the data without initial value is carried out 182 63 64 65 66 67 68 69 70 71 72 73 74 15 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 ELG 117 118 119 120 121 122 123 124 125 126 127 Chapter 8 How to Customize This macro is defined by mr32r inc and a user can also use it freely RAM CLEAR RO R1 R2 START bss END bss It transmits to a built in RAM area from an external ROM area A user can also use this broad view freely RAM CLEAR RO R1 R2 START bss END bss DOWNLOAD RO R1 R2 R3 START MR ROM END MR ROM ROM MR ROM DOWNLOAD RO R1 R2 R3 START data END data ROM data The standard library of the C language is initialized initialize C language library OS is initialized ES BJNITS Initialize OS system ar
42. of the objects seen 96 641 Structure of Memory n DynamicAllocation Generation Deletion usus 96 642 Anoteon using dynamic generation deletion isnt 97 65 The Use of TRAP Instruction eesseesesssssseeesee enne enne enne nnne nnn nennen trennt nens 97 6 6 Regarding Interrupt irte ie rx re e E e IE de PER HER ne ERE E ned 98 661 Controlling Interrupts siiis einen inania si ana a Aa A nasa tara REA AARTE a 98 662 Theproceaure for running the interrupt hanaller een 99 663 Acceotion of Interruption at Time of Handler Execution enn 100 664 Enabling Multiple Interrupts iiis siii se seinen theta aiias aaa saisi aano 100 6 7 The procedure of using OS debug functions essere 101 671 The procedure of using OS debug functions iiie 101 672 Precautions in using OS debug functions einen inniti 101 68 System Clock Settings ale Ded ee ede ke Pen Re LC EO EE E SEDAN edades 103 6 8 1 Register system dock hanaller e sientan nni aita thin innata 103 Precautions about system clock handler sssssssssseeeeeee nennen enne 103 6 8 2 Automatic system dock sett ngs eiie seinen tnihi theirs tasas aant 103 The structure of system clock settings nennen emere nennen nens 103 Precautions about automatic timer settings nennen eene enne 103 6 9 Precautions about depending on compiler
43. 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 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 78 4 2 2 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 priority y System Clock Definition clock timer_clock timer file_name IPL unit time initial time y Task Definition task 1 entry address stack size priority initial start y task 2 entry_address stack_size priority y task 3 entry_address stack_size priority y task 4 entry_address stack_size priority un Eventflag Definition flag 1 name Interrupt Vector Definition interrupt_vector 16 interrupt_vector 23 Chapter 4 Applications Development Procedure Overview Configuration File Preparation 1024 5 33 3MHz
44. st r5 r4 137 ld R5 R15 138 ld R4 R15 139 ld RARA 5 140 addi R15 4 141 jmp RA a a a a a a 4 142 143 The initial cofiguration of an interruption priority level is performed 144 It is called from a start up file 145 146 global set ipl 147 set ipl 148 ldi r5 0x07 149 1d24 14 ICUIMASK 150 sth r5 r4 151 jmp r14 152 153 It is the interruption routine of a dummy 154 This routine is called when interruption which is not defined as an 155 interrupt handler in a configuration file occures 156 157 global Int Dummy 158 Int Dummy 159 jmp R14 160 161 This routine is called when the system call is used in a user program 162 in spite of having specified NO by the system call definition of a 163 configuration file 164 165 global SYS DUMMY 166 SYS DUMMY 167 jmp r14 168 8 2 How to Customize the MR32R Startup Program 167 8 2 How to Customize the MR32R Startup Program The MR32R is provided with two startup programs as given below start ms start s for TW32R or D CC M32R This is a startup program to use if you write a program in assembly language crtOmr ms crt mr s for TW32R or D CC M32R This is a startup program to use if you write a program in C A program resulting from adding a C written initialization routine to start ms The startup program process such as below Setting a stack pointer Initializing the processor after resetting Transferring t
45. task trace function and system call trace function MR32R communicate the debugger via a byte of data Dbg mode The default start up routine disables task trace function and system call trace function So if the program is downloaded into target board and open MR trace window the debugger does not display the trace result Please open MR trace window after start up routine executed The following is the procedure of enabling task trace function and system call trace function in start up routine for CC32R 102 Chapter 6 Notes of developing user program Modified seth R11 high __REL_BASE11 or3 R11 R11 low __REL_BASE11 seth R12 high __REL_BASE12 or3 R12 R12 low __REL_BASE12 seth R13 high __REL_BASE13 or3 R13 R13 How __REL_BASE13 X amp Dbg flg gt 0 r1 Dbg mode r2 40 lt Set the value to R2 register r2 r1 This example sets AFTER mode Original seth R11 high __REL_BASE11 or3 R11 R11 low __REL_BASE11 seth R12 high __REL_BASE12 or3 R12 R12 low __REL_BASE12 seth R13 high __REL_BASE13 or3 R13 R13 low __REL_BASE13 AIF X amp Dbg flg gt 0 Id24 r a Dbg mode Idi r2 0 Idi r2 4 stb r2 r1 AENDI The value to set to R2 register is 0 AFTER mode or 2 BREAK mode 6 8 System Clock Settings 103 6 8 System Clock Settings 6 8 1 Register system clock handler The system clock handler sys timer assembly language routine must be registered to MR32R as an interrupt han
46. the former state 7 Restores the interrupt level to the former state Steps 2 and 6 need to be written within the interrupt control program ipl ms by the user for details see Section 8 1 others are processed by the OS 100 6 6 3 Chapter 6 Notes of developing user program Acception of Interruption at Time of Handler Execution e Alarm Handler and Cyclic Handler The cyclic handler and alarm handler are started in the state of interruption permission e Interrupt Handler By the default an interrupt handler is started in the state of interruption prohibition 6 6 4 Enabling Multiple Interrupts To enable multiple interrupts follow the steps given below To enable multiple interrupts for any interrupts 1 Set the interrupt enabling bit within the interrupt entry processing routine Step 2 above Clear the interrupt enabling bit within the interrupt exit processing routing Step 1 above e To enable multiple interrupts for specific interrupts 1 Set the interrupt enabling bit at the beginning of the interrupt handler that enables multiple interrupts Clear the interrupt enabling bit at the tail of the interrupt handler that enables mul tiple interrupts 6 7 The procedure of using OS debug functions 101 6 7 The procedure of using OS debug functions 6 7 1 6 7 2 The following things are the procedure of using OS debug functions e q task trace func tion system call trace function and issuing sys
47. vret exc system call is issued processing is transferred to the task for which the exception handler was called include mr32r h include id h EXC exc REGS regs M EIT eit Prototype declaration void exc handler T EXC T REGS T EIT void exc handler T EXC amp exc T REGS amp regs T EIT amp eit process vret_exc Figure 5 5 Example Exception Handler Written in C Language a ext tsk system call can be issued when forced exception handler ends In this case the task corresponding to the forced exception handler is moved to DORMANT state 88 Chapter 5 Detailed Applications 5 2 Program Coding Procedure in Assembly Language This section describes how to write an application using the assembly language 5 2 1 Writing Task This section describes how to write an application using the assembly language 1 Be sure to include mr32r inc at the beginning of file 2 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 mr32r inc e 1 global task 2 task process bra t sk 70 e 3 Figure 5 6 Example Infinite Loop Task Described in Assembly Language include mr32r inc global task task process ext tsk Figure 5 7 Example Task Terminating wi
48. 0 r15 bra __ SYSCALLO AELSE Global __Dbg_entry0 ld r0O r15 bra __Dbg_entry0 AENDI _jmp_trap8 AIF XY amp Dbg_flg eq O global SYSCALL1 id r0 Gr15 bra SYSCALL1 AELSE global Dbg entryl ld EOP CELSE bra _ Dbg entryl AENDI jmp ei global int entry ld r0O r15 bra __int_entry Chapter 7 Using Configurator 116 Chapter 7 Using Configurator 7 1 Configuration File Creation Procedure When applications program coding and startup program modification are completed it is then neces sary to register the applications program in the MR32R system This registration is accomplished by the configuration file 7 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 Ox or OX to the beginning of a numerical value or h or H to the end If the value begins with an alphabetical letter between A and F with h or H at tached to the end be sure to add O 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
49. 1 0 38 sta tsk ID task2 0 39 40 ext tsk 41 42 void task1 void 43 44 INT length 45 char messagel 46 INT message2 47 48 rcv msg PT MSG amp messagel ID mbx1 49 rcv msg PT MSG amp message2 ID mbx2 50 OutputMessage messagel message2 54 52 while 1 53 dly tsk 100 54 act cyc ID cyhl1 TCY OFF 55 dly tsk 100 56 57 OutputMessage messagel message2 58 59 act cyc ID cyhl TCY INI ON 60 61 62 210 Chapter 10 Apendex 63 void task2 void 64 65 INT length 66 ER ercd 67 char messagel string tmp 68 INT message2 i 69 INT message4 sizeof MR32R is a Real Time OS for M32RYn 70 while 1 Yu slp tsk T2 ercd pget blk VP amp string ID_memblk1 message4 73 if ercd E OK 74 char message3 MR32R is a Real Time OS for M32REn 75 tmp string 76 for i 0 i lt message4 i t 77 string message3 78 string 19 message3 80 81 string tmp 82 OutputMessage string message4 83 string tmp 84 rel blk ID memblk1 string 85 86 87 88 89 void alhl void 90 91 INT message2 92 char messagel 93 messagel Hellow world n 94 message2 sizeof Hellow world n 95 isnd_msg ID_mbx1 PT MSG messagel 96 isnd msg ID mbx2 PT MSG message2 97 98 void cyhl void 99 100 iwup tsk ID task2 101 102 103 void OutputMessage char message INT length 104 105 INT i 106 for i 0 i
50. 32765 Define the maximum number of rendezvous defined 130 10 11 12 Chapter 7 Using Configurator The maximum number of mailbox with priority defined Definition format Numeric value Definition range 1 32765 Define the maximum number of mailbox with priority The maximum number of fixed size memorypools defined Definition format Numeric value Definition range 1 32766 Define the maximum number of fixed size memorypools defined The maximum number of variable size memorypools defined Definition format Numeric value Definition range 1 32766 Define the maximum number of variable size memorypools defined The maximum number of cyclic activation handlers defined Definition format Numeric value Definition range 1 32767 The maximum number of cyclic handler defined The maximum number of alarm handler defined Definition format Numeric value Definition range 1 32767 Define the maximum number of alarm handlers defined The maximum number of interrupt handler defined Definition format Numeric value Definition range 1 255 Define the maximum number of interrupt handlers defined 7 1 Configuration File Creation Procedure 131 O Task definition lt lt Format gt gt Tasks Definition task ID No entry address Start task of address stack_size User stack size of ta
51. 8 4 Semaphore Mamagement Area 8 x maximum semaphore maximum semaphore 1 8 4 Mailbox Management Area 8 x maximum mailbox maximum mailbox 1 8 4 Message buffer Management Area 8 x maximum message buffer maximum message buffer 1 8 4 Rendezvous port Management Area maximum rendezvous port 1 8 4 Mailbox with priority Manage ment Area 6 x the number of maximum mailbox with priority the number of maximum mailbox with priority 1 8 4 Fixed size Memorypool Man 12 x maximum fixed size memorypool maximum fixed size agement Area memorypool 1 8 4 Variable size Memorypool 17 x maximum variable size memorypool maximum vari Management Area able size memorypool 1 8 4 Cyclic handler Management 9 x cyclic handler Area Alarm handler Management 12 x alarm handler Area Version Management Area 20 in using get ver system call System call Table 384 Note System management area and system time management area are always secured If you specify the maximum number definition for other items as 0 or you omit the maximum number defini tion the area of corresponding items is not secured For example If you specify max sem 0 and does not define semaphore the Semaphore man agement area does not use any memory Table 9 3 The Size of INTERRUPT VECTOR Section Area
52. B32R or the current directory If this file exists in both directories the file in the current directory is priori tized over the other makefile template files is makefile ews makefile dos makefile Makefile This file is used as a template file when generating makefile Refer to section 0 mr32r inc template file mr32r inc This file contains description of MR32R s version It resides in the directory indicated by en vironment variable LIB32R The configurator reads in this file and outputs MR32R s version information to the startup message The template files for initializing timer XXX tpl A template file for initializing timer specified in configuration file is copied from LIB32R di rectory specified by environment variable to current directory as timer inc This file is in cluded in ipl ms ipl s MR32R version file version This file contains description of MR32R s version It resides in the directory indicated by en vironment variable LIB32R The configurator reads in this file and outputs MR32R s version information to the startup message 2 When the configurator is executed the files listed below are output Do not define user data in the files output by the configurator Starting up the configurator after enter ing data definitions may result in the user defined data being lost System data definition file sys rom inc sys ram inc This file contains definition of system settings Include file mr32r
53. Entry Examples enne 116 Table 7 2 Operators sieisen tea eee e dative Rete EE e ce iE rn as 116 Table7 3 Correspondence between microcomputer and template file 128 Table 8 1 The functions needed in pl MS eee eee eee e eee eteeeeeeeeeaeeeaeeeaaeeeaeeeaeeeaaeeaaeseaeeeaeenaeteas 156 Table 9 1 The Size of MR RAM Section cceccsssscsssseeeceesescesnsseeeecseeeseeseeseesseseeaesesseeseaseesseenaes 203 Table 9 2 The Size of MR ROM Section eseseseseseseeenenenn ener ennt ntn nnns 204 Table9 3 TheSizeof INTERRUPT VECTOR Section sese enn 204 Table10 1 Sample Program Function List sssssssssesessseeeeeeneeenneennenne enne 208 Chapter 1 User s Manual Organization 2 Chapter 1 User s Manual Organization The MR32R User s Manual consists of nine chapters and thee appendix e Chapter 1 User s Manual Organization Outlines the contents of MR32R User s Manual Chapter 2 General Information Outlines the objective of MR32R development and the function and position of the MR32R e Chapter 3 Introduction to MR32R Explains about the ideas involved in MR32R operations and defines some relevant terms e Chapter 4 Applications Development Procedure Overview Outlines the applications program development procedure for the MR32R e Chapter 5 Detailed Applications Details the applications program development procedure for the MR32R e Chapter 7 Using Configurator Desc
54. G CCI2R AA e M en e ren 185 632 Using TMZ cet aie nep 187 Symbols defined in the linker scripts enne nennen nnn nennen nennen 187 633 Sample Linke Script uisa ta e e et a de ni 188 G234 iUsIngDCC M32R sio ebd t t e aen 193 amp 35 SampleLinker Script iiis isse inei nn a aaia ian eE a aaa aa aa nasa EAA E a aeai EULA En 194 84 Editing makefile cem eee ico 197 GAL Using CCa2R oi t e E Eo em e nee 197 BAZ Using D CCIM3ZR ii e nda on tae hes ae DATA a uo ea aged 197 Chapter 9 Application Creation Guide esssssseeeeeeeeeeeneee nennen nennen 199 9 1 Processing Procedures for System Calls from Handlers esses 200 911 System Calls from a Handler That Caused an Interrupt during Task Execution 200 912 System Calls from a Handler That Caused an Interrupt during System Call PLOCESSINID s ii oW d vee D eU RR 201 913 System Calls from a Handler That Caused an Interrupt during Handler Execution 202 9 2 Calculating the Amount of RAM Used by the System ssseene 203 9 3 Stacks isst eed Pe E ee t eee ERE ee ER dee AER tee Rene EE ore e es 205 931 System Stack and User Stack comicios 205 Chapter 10 Apendex luec tie aire eti eee raster di ee actrees 207 10 1 Sample Progra a ion nete hi eimi uui 208 10 1 1 Overview of Sample Program isses eaae rr 208 1012 Program Source Listing o be ie ies e bo as b e A teo o aie de 209 LOL Configuration EMO ip ed reddet eoo ang
55. HUE a 31 352 Module Overview ite a Aog fu haa een go ee RA dan Lean 32 353 Task Management Function isis aiias thea th sias eise rasis ias 34 354 Synchronization functions attached to task ninia 37 BHD EVO IA AS et au niue A 40 3 5 6 SemaplhiOke uu a e Er o n EA i Re d 42 SOF AMADO 2 A as RERBA ts 44 X58 Messagebulfer coii e ER YO RHET ni YE YA E 46 BOG RendezVOUsiiaos eint At E A a UEM aio ctus 51 3510 Interrupt Management Function sienne tnihi tnnt nita aiia siano 55 3511 Memorypool Management Function iss ssi sss seinen innata haa naa anna 57 Fixed size M emorypool Management Function sess eene nenne nre nen 57 Variable size Memorypool Management Function sssssssseeeeeneneen nennen ene nnne 59 3512 Time Management Function es iii siia ainsi thea itae 63 3513 System Management Function ssi si nennen neatis thin aaa eara saisit nian 66 3514 JImplementation Depenatent iisiis ii isi ie einn aiasitn s ith s aaa aiat aaa 67 3515 Implementation Depenaent Mailbox with Priority ees 68 35 16 System Calls That Can Be Issued from Task and Hanalfer ei 69 Chapter 4 Applications Development Procedure Overview eese 73 4 1 General Description essen nennen nennen nnnm nennt entr nn tn nennt tnter tren nnn nns 74 4 2 Development Procedure Example sssssssssseeseeeeeene ennt enne enne 76 421 Applications Pro
56. MR32R performs calculations based on the specified size and selects and allocates the optimum one of four fixed size memory block sizes The MR32R cannot allocate a memory block that is not one of the four sizes The size of the four fixed sized memory block can be calculated as below a max memsize 12 1 96 1 12 b a 2 c a 4 d a 8 System calls the MR32R provides include the following 60 Chapter 3 Introduction to MR32R Create variable size memorypool cre mpl Creates a variable size memorypool with the ID specified by a task Delete variable size memorypool del mpl Deletes a variable size memorypool with the ID specified by a task Get memory block get blk tget_blk Acquires a memory block from a variable size memorypool The four types of block sizes are rounded off to the nearest optimum block size and a block of the rounded size is acquired from the memorypool If no free memory block of the specified size exists in the memorypool the task that issued this system call goes to a wait state so it is queued up in the wait queue 200 bytes TaskA Rounding M emorypool Figure 3 41 pget blk processing Figure 3 41 shows an example where task A is requesting 200 bytes of memory block MR32R rounds off the 200 byte size to 224 bytes separates a 224 byte memory block off the memorypool and allocates it to task A Get memory block pget blk Acquires a memory block from a variable size memorypool The di
57. Name Bytes Interrupt Handler Entry Address Table maximum interrupt handler 1 x4 73 This is the maximum interrupt factor value defined in the maximum item definition of the configuration file 9 3 Stacks 9 3 Stacks 205 9 3 1 System Stack and User Stack The MR32R 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 MR32R it is necessary to furnish the stack area for each task e System Stack This stack is used within the MR32R during system call processing When a system call is issued from a task the MR32R switches the stack from the user stack to the system stack SeeFigure 9 4 The system stack use the interrupt stack SPl Task MR32R system call processing User Stack SPU Save Registers XXX XXX Stack switching System call processing System Stack SPI Task selection Stack switching Restore Registers User Stack SPU Figure 9 4 System Stack and User Stack Chapter 10 Apendex 208 Chapter 10 Apendex 10 1Sample Program 10 1 1 Overview of Sample Program Here is a program as an example of MR32R application that causes the some messages to perform serial output from the M32102 evaluation board Table 10 1 Sample Program Function List Function Name Type ID No Priority Function main Task 1 1 Wakes up task1 and task2 task2
58. 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 defined 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 opti mized 128 Chapter 7 Using Configurator 6 Template file name Definition format Symbol Definition range nothing Specify template file name used The configrator copies the file specified to current directory as timer inc Correspondence between microcomputer and template fileis below Table 7 3 Correspondence between microcomputer and template file Hint HM1 hint1 tpl TO T1 M65439 m65439 tpl TO T1 T2 MSA2000 M32102 m32102 tpl MFTOO MFT001 MFT13 O Definition respective maximum numbers of items Defines maximum number of each definition in applications lt lt Format gt gt Max Definition maxdefine 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 mbf the maximum number of messagebuffer defined max por the maximum number of rendezvous defined max vmbx the maximum number of mailbox with priority max
59. PEND state The SUSPEND state is the condition in which a READY task or currently executed task 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 exe cution 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 E QOVR is returned 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 wai sem or rcv msg system call that task remains in the re quest 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 wait state task by dly tsk tslp tsk system call issuance wakes up upon the period specified by tmout elapsing The request of the task placed in wait state by wai flg wai sem rcv msg snd mbf rcv mbf cal por acp por get blf get blk vrcv mbx system call is fullfilled The WAIT state is forcibly clea
60. R rodata SIZEOF roda ta 158 159 __data_start 160 data 161 gnu linkonce d 162 CONSTRUCTORS 163 data end 164 165 rom data LOADADDR data 166 167 We want the small data sections together so single instruction offsets 168 can access them all and initialized data all before uninitialized so 169 we can shorten the on disk segment size 170 171 The start address of sdata is defined 17 2 173 sdata ADDR data SIZEOF data AT LOADADDR data SIZEOF data 174 175 Sdata start 176 sdata 177 Sdata end 178 179 rom sdata LOADADDR sdata 180 181 The start address of MR ROM is defined 182 183 MR ROM ADDR Sdata SIZEOF sdata AT LOADADDR sdata SIZEOF sdata yi 184 185 mr rom start 186 MR ROM 187 INTERRUPT VECTOR 188 mr rom end 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 21 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 Zod 228 229 230 231 232 233 234 235 236 23T 238 239 24 24 24 24 24 24 24 24 24 24 250 251 252 253 o 0 J3J00H4S CQ ho F2 Ke 8 3 Customizing the Section File rom mr rom LOADADDR MR ROM _edata PROVIDE edata The start address of SYS STACK is defined SYS STACK Interrupt stack sections
61. R abbreviated as CC32R M32R Family GNU Cross tool M3T TW32R abbreviated as TW32R When these related products are used increased program development efficiency is ob tained Document List The following sets of documents are supplied with the MR32R Release Note Presents a software overview and describes the corrections to the Users Manual and Ref erence Manual Users Manual PDF file Describes the procedures and precautions to observe when using the MR32R for program ming purposes Reference Manual PDF file Describes the MR32R 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 MR32R 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 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 ITRON Specification By his consent the MR32R is produced in compilance with the ITRON Specification Contents i Contents Chapter 1 User s Manual Organization
62. SUBISHI ELECTRIC SEMICONDUCTOR APPLICATION ENGINEERING CORPORATION All Rights Reserved MR32R version V 3 40 Release 1 A gt Figure 4 4 Configurator Execution 4 2 4 System generation Execute the make command to generate the system C make f makefile as32R g crtOmr ms CC32R c task c lnk32R 1nk32R sub C Figure 4 5 System Generation 4 2 5 Writing ROM Using the LMC32R for CC32R or m32r elf objcopy for TW32R 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 2 Itis possible for MR32R to use only make command compatible to UNIX standard To use MS DOS use make com mand 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 82 Chapter 5 Detailed Applications 5 1 Program Coding Procedure in C Language This chapter details the applications program development procedures in C language 5 1 1 Task Description Procedure Note the items as below when a task written in C language 1 Describe the task as a function To register the task for the MR32R enter its function name in the configuration file When for insta
63. 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 generation 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 pITRON specifications V 3 0 The uITRON specifications V 3 0 provides en hanced connection functions by integrating ITRON specifications V 2 0 and ITRON specifications MR32R is a real time operating system developed for the M32R of 32 bit microprocessors according to the uITRON specification 4 The pITRON specifications V 3 0 has its system calls classified into level R level S level E and level C MR32R 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 MR2R specifications are outlined inTable 2 1 Static object generation Dynamic object generation MR32R V 3 40 conforms to ulTRON Specifications V 3 0 2 2 Relationship between TRON Specification and MR32R Table 2 1 MR32R Specifications Overview Item Specifications Target microprocessor M32R Family Maximum number of tasks 32767 Task priorit
64. TACK INT USR STACK 110 MR HEAP MR HEAP 111 HEAP START 112 gt in raml 113 114 GROUP 115 EXT_MR_RAM EXT MR RAM 116 EXT USR STACK EXT USR STACK 117 EXT MR HEAP EXT MR HEAP 118 in ram2 119 120 121 122 Some required symbols are defined 123 124 __ROM_data addr START UP sizeof START UP 125 ROM_MR_ROM ROM data sizeof data 126 BSS START START bss EA BSS_END END_bss 196 Chapter 8 How to Customize 128 DATA ROM ROM data 129 DATA RAM START data 130 DATA END END data 131 132 HEAP END addr in ram2 sizeof in ram2 133 Figure 8 6 The memory image of a sample linker script file 8 4 Editing makefile 197 8 4 Editing makefile 8 4 1 Using CC32R Here you edit makefile the configurator generated and set compilation options libraries and so on The procedure for setting them is given below 1 cc32R command options You define command options of the C compiler in CFLAGS Be sure to define the c op tion 2 as32R command options You define command options of the assembler in ASFLAGS 3 Ink32R command options You define command options of the linker in LDFLAGS There are no particular options you need to specify 4 Specifying libraries To appoint a library first put echo L library path gt gt Ink32R sub in the library path line Next put echo library
65. TACK Section EXT MR RAM MR HEAP EXT MR HEAP Section b The following sections cannot be mapped into areas beyond address 1000000H MR RAM MR ROM INTERRUPT VECTOR MR Dbg RAM Section MR KERNEL MR KERNEL2 Section Or it is not supporting EVB EIT vector base register the processing shown below is required of the microcomputer which cannot set EVB as the domain exceeding 16MB You have to arrange MR KERNEL and MR KERNEL2 in relative 16MB space Whether the code sections such as P and text and data sections such as B D and C or bss data and rodata that applications use are mapped or not is compiler dependent Fur thermore it might be necessary for the mapping to change compiler options and linking stan dard libraries as well as reconfigure standard libraries For details refer to your compiler s manual 6 10 Memory mapping 111 6 10 4 Arrangement to Space Exceeding 16MB of Kernel Area In MR32R the TRAP command is used for the call of a system call However since there is only 4 bytes of entry TRAP cannot be jumped to the space which exceeds 16MB directly therefore on using the microcomputer which cannot set EVB EIT vector base register as the area exceeding 16MB or it is not supporting EVB it is necessary to once jump in 16MB space and to jump by jmp and jl command to the space which exceeds 16MB from there The example of the TRAP7 used in system call processing in the case of having arranged the MR32R ke
66. TFIFO maximum priority x the number of maxi mum mailbox with priority the number of mailbox with priority defined in the configuration file Task Management Area 37 x maximum task Forced exception function is unused 43 x maximum task Forced exception function is used Eventflag Management Area 11 x maximum eventflag maximum eventflag 1 8 4 Semaphore Management Area 8 x maximum semaphore maximum semaphore 1 8 4 Mailbox Management Area 17 x maximum mailbox maximum mailox 1 8 4 Mailbox Area total mailbox buffer size Message buffer Management Area 21 x maximum message buffer maximum message buffer 1 8 4 Message buffer Area total message buffer size Rendezvous port Management Area 6 x maximum rendezvous port maximum rendezvous port 1 8 4 Mailbox with priority Management Area 8 x the number of maximum mailbox with priority the num ber of maximum mailbox with priority 1 8 4 Fixed size Memorypool Management Area 9 x maximum fixed size memorypoo maximum fixed size memorypool 1 8 4 Variable size Memorypool ment Area Manage 81 x maximum variable size memorypool maximum vari able size memorypool 1 8 4 Cyclic handler Management Area 5 x maximum cyclic handler Alarm handler Management Area 1 Task Management Area dynamic creatio
67. Task e Image expansion task Printer engine task Centronics interface interrupt handler This program uses the following MR32R library functions e 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 flo Waits until the eventflag is set up In the example this function is used to wait until one page of data is entered into the buffer via the Centronics interface wup_tsk Wakes up a specified task from the WAIT state This function is used to start the printer en gine task e sip _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 e set flg 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 8 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 77 include mr32r h include id h void main main task printf LBP start simulation Xn sta tsk ID idle 1 activate idle task Sta tsk ID image 1 activate image expansion task sta tsk ID printer 1 activate
68. Task 2 2 Outputs message1 task3 Task 3 3 Outputs message2 alh1 Handler Sends message 1 to the mailbox chy1 Handler Wakes up task2 Message1 Hello World Message2 MR32R is a Real Time OS for M32R Here follows explanation as to how the process works The task main initializes the serial port starts up task1 and task2 and terminates itself Task works in the following sequence 1 Receives message1 from the mailbox mbx1 and receives the size of message1 from the mailbox mbx2 2 Outputs received messages to serial port 3 Gets into the wait state to wait for the system clock to count 100 returns to the execution state to terminate the periodical startup handler then gets into the wait state to wait for the system clock to count 100 a second time 4 Returns to the execution state outputs message1 then resumes the periodical startup han dler and clears the period counter simultaneously 5 Repeats steps 3 and 4 Task2 works in the following sequence 1 Gets into the wait state and waits until the periodical startup handler wakes it up 2 When woken up attempts to secure as much memory as the size of message2 If successful copies message2 to the area secured 3 Outputs message2 copied 4 Releases the area that held message2 in step with the output of message2 5 Repeats steps 1 though 4 alh1 sends message1 to mbx1 and its size to mbx2 e cyhl1 starts up every
69. 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 2 NE S AS 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 gr
70. 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 85 5 1 2 Writing Interrupt Handler When describing the interrupt handler in C language observe the following precautions 1 2 Describe the interrupt handler as a function Be sure to use the void type to declare the interrupt handler start function return value and argument At the beginning of file be sure to include mr32r h which is in the system direc tory as well as id h which is in the current directory The static declared functions can not be registered as an interrupt handler include lt mr32r h gt include id h void int_handler void process iwup tsk ID main Figure 5 3 Example of Interrupt Handler 9A configuration file is used to define the relationship between handlers and functions 86 Chapter 5 Detailed Applications 5 1 3 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in C language observe the following precautions 1 2 Describe the cyclic or alarm handler as a function Be sure to declare the return value and argument of the interrupt handler start function as a void type At
71. Warning test c line 13 can t find XXXX The include file XXXX cannot be found Check the file name and whether the file actually exists Chapter 8 How to Customize 156 Chapter 8 How to Customize 8 1 Interruption Control Program 8 1 1 In MR32R the portion related to a setup of the ICU or a setup of a timer is not contained in OS kernel as Figure 6 2 The procedure for running the interrupt handler shows About these setup it carries out by the ipl ms or ipl s file In MR32R as there is 6 8 2 Automatic system clock settings there is a template corresponding to some microcomput ers and the template can be used However when there is no template corresponding to the microcomputer currently used a user needs to create a ipl ms or ipl s file By the contents interruption processing The program of processing of an interruption control program it is a table The assembler routine of the label shown in Table 8 1 The functions needed in ipl ms is de scribed It explains below what processing each assembler routine needs to describe Table 8 1The functions needed in ipl ms Label Outline Register assurance Sys timer init nitializes the timer Unnecessary SAVE IPL to STACK Saves an interrupt level int stack Necessary RESTORE PL from STACK Restores an interrupt level from the stack Necessary Set ipl Sets an interrupt priority level at the time Unnecessary of s
72. _clock Timer clock timer Timers mode IPL System clock interrupt priority level unit time Unit time of system clock initial_time Initial value of system time file_name Template file name of timer setting 7 1 Configuration File Creation Procedure 127 lt lt Content gt gt 1 Timer clock Definition format Frequency in MHz Definition range None Define the timer operating clock frequency You can also use mpu clock for compatibility 2 Timer Definition format Symbol Definition range OTHER NOTIMER or other symbol Define timer mode by use of OTHER NOTIMER or other symbol Use NOTIMER in using no timer The symbol defined here is output in mr32r inc as a symbol definition and is used for Macro expansion in the initial definition of timer inc 3 System clock interrupt priority level Definition format Numeric value Definition range 1 6 Define the priority level of the system clock timer interrupt Interrupts whose priority levels are below the interrupt level defined here are not accepted during system clock interrupt handler processing 4 Unit time of system clock Definition format Time in ms Definition range 0 1ms or more Define the unit time of the system clock system clock interrupt generation intervals in ms 5 Initial value of system time Definition format Time of day Definition range 0 0 0 0x7FFF OxFFFF
73. age wait time out state mailbox with priority function e Acquiring Its Own ID get tid Acquires its own task ID number When this system call is issued from a handler O zero is obtained instead of the ID number Referencing a task s status ref tsk Referencing a task s status or priority etc 3 5 MR32R Kernel Structure 37 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 MR32R offers the following task incorporated synchronization system calls e Placing a Task in the SUSPEND State sus tsk isus tsk Restarting a Task Placed in SUSPEND State rsm 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 38 Placing a Task in the WAIT State slp tsk tslp tsk Waking up wait state task wup tsk iwup tsk Chapter 3 Introduction to MR32R Wakes up a task that has been placed in a WAIT state by the slp tsk tslp tsk system call No task can be waked up unless
74. ai sem trcv msg tsnd mbf trcv mbf tcal por tacp por tget_blf tget blk vtrcev mbx system call mean slp tsk wai flg wai sem rcv msg snd mbf rcv mbf cal por acp por get bIf get blk vrcv mbx system call with time out speci fication The task is moved to WAIT state by these system calls issue In this case the task is moved to READY state if their conditions are satisfied or the period specified by tmout elapses without conditions When the task enters the WAIT state and waits to be requested upon the issuance of the wai flg wai sem rcv msg snd mbf rcv mbf cal por acp porget blf get blk system call 12 Upon ichg pri system call For the information on the ready queue see the next chapter 14 Upon chg pri system call 1 Upon ichg pri system call Upon slp tsk dly tsk wai flg wai sem or rcv msg system call 3 3 Task 23 e Eventflag Queue e Semaphore Queue e Mailbox Queue e Send Messagebuffer Queue e Receive Message Buffer Queue e Call Wait Queu e Accept Rendezvous Queue e Fixed size memory Allocation Queue e X Variable size memory Allocation Queue e Mailbox Queue with Priority 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 situa tion it goes into the WAIT SUS
75. anted 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 equipment 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 required 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 b
76. ate to an executable state If no task exists that is kept waiting for acceptance at the specified port or although there is a task waiting for acceptance rendezvous establishment condition is not met the task that is sued cal por or tcal por is placed in a call wait state so it is queued up in the call waiting queue Make rendezvous call to port pcal por 52 Chapter 3 Introduction to MR32R Performs the same processing as with the cal por and tcal por system calls except that if no task exists that is kept waiting for acceptance at the specified port or although there is a task waiting for acceptance rendezvous establishment condition is not met the issuing task only returns error code without going to a call wait state Accept rendezvous call from port acp por tacp por Issues a acp por or tacp por system call to check whether rendezvous with the task in the call wait state at the specified port will be established When rendezvous is established the task kept in the call wait state is removed from the call wait queue and goes to an end of rendezvous wait state Note that the task on the rendezvous acceptance side the task that issued acp por can perform multiple rendezvous sessions simultaneously Figure 3 35 shows multiple rendezvous sessions at different ports It is also possible to perform multiple rendezvous sessions at the same port If no task exists that is kept waiting for call at the specified port or although th
77. ave 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 24 NEC SAS C 7 D Im 7 lt D C M3 T MR32R V 3 50 User s Manual Real time OS for M32R Family Renesas Electronics com Rev 1 00 2003 06 www renesas co Microsoft MS DOS Windows and Windows NT are registered trademarks of Microsoft Corporation in the U S and other countries IBM and AT are registered trademarks of International Business Machines Corporation Intel and Pentium are registered trademarks of Intel Corporation Adobe Acrobat and Acrobat Reader are trademarks of Adobe Systems Incorporated All other brand and product names are trademarks registered trademarks or service marks of their respective holders Keep safety first in your circuit designs Renesas Technology Corporation and Renesas Solutions Corporation put the maximum effort into making semiconductor products better and more reliable but there is always the possibility that trouble may occur with them Trouble with semicon ductors may lead to personal injury fire or property damage Remember to give due consideration to safety when making your circuit designs with appropriate measures such as i placement of substitutive auxilia
78. ax_memsize Maximum size of messagebuffer to be created all memsize Size of dynamically creating messagebuffer area internal RAM y lt lt Content gt gt 1 Maximum size of messagebuffer to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of messagebuffer size among those created by issuing the cre mbf system call For this value specify the largest size among messagebuffers for which the internal RAM has been specified 2 Size of dynamically creating messagebuffer area internal RAM Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating messagebuffer area The area of the specified size here is necessary to allocate a messagebuffer area internal RAM when issuing the cre mbf system call A size of memory required for the messagebuffer specified by the cre mbf system call is al located from this dynamically creating messagebuffer area O Dynamically creating message buffer area definition external RAM lt lt Format gt gt ext_memmbf max_memsize Maximum size of messagebuffer to be created all memsize Size of dynamically creating messagebuffer area external RAM y 124 Chapter 7 Using Configurator lt lt Content gt gt 1 2 Maximum size of messagebuffer to be created Definition format Numeric value Definition range 1 or
79. bers are omitted the omitted numbers are regarded as 0 For instance 12 is equivalent to 0 0 12 7 1 Configuration File Creation Procedure 119 7 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 Dynamically creating user stack area definition Dynamically creating mailbox area definition Dynamically creating message buffer area definition Dynamically creating fixed size memory pool area definition Dynamically creating variable size memory pool area definition Task definition Eventflag definition Semaphore definition Mailbox definition Messagebuffer definition Rendezvous definition Fixed size Memorypool definition Variable size Memorypool definition Cyclic handler definition Alaram handler definition Interrupt vector definition Mailbox with priority definition 2 All items except task definition can omitted If omitted definitions in the default configuration file are referenced 120 Chapter 7 Using Configurator O System Definition Procedure lt lt Format gt gt System Definition system stack_size System stack size priority Maximum value of priority exc_handler Interrupt handler debug Debug function debug buffer Buffer size for debug function y lt lt Content gt gt 1 System stack size D
80. called from the startup routine 32 at the time when the timer is used 33 34 AIF amp XUSE TIMER 35 sys timer init 36 37 Initialize the system time Please do not change this portion 38 st r14 r15 39 1d24 c4 __D_Sys_TIME_H 40 lduh r5 r4 41 1d24 r6 __Sys_time 42 sth r5 r6 43 1d24 c4 __D_Sys_TIME_L 1 44 ld r5 r4 45 st r5 2 r6 46 47 The initial cofiguration of the timer used for the system clock of OS is 48 performed 49 50 MET control register setting 51 seth r1 tshigh MFTCR 52 ld r0 Low MFTCR r1 53 1d24 r2 __write_bit 54 or r0 r2 55 st rO G low MFTCR rl1 56 MFT mode register setting 57 seth r1 tshigh MFTMOD 58 1d24 r0 40x8000 59 or3 rO r0 ft timer div 60 st r0 low MFTMOD r1 61 MFT reload register setting 62 seth rl 4shigh MFTRLD 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 T21 122 123 124 125 126 8 1 Interruption Control Program 159 1d24 rO 4 timer count st r0 G low MFTRLD r1 MFT interrupt control register setting IEN 1 ILEVEL 3 seth r1 tshigh ICUCR idi r0 0x1100 or3 r0 r0 3 st r0 low ICUCR r1 MFT control register setting seth r1 shigh MFTCR ld r0 low MFTCR r1 1d24 v2 __write_b
81. cessary to introduce a new system named real time OS To answer the above mentioned demand Mitsubishi Electric has developed a real time operating sys tem tradenamed MR32R for use with the M32R 32 bit one chip microcomputers When the MR32R 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 allocated 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 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 observing the small modules 2 1 Ob
82. changes into a different state when any of the following condi tions occurs e 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 Upon ext tsk system call a Upon slp tsk tslp tsk dly tsk wai flg twai flg wai sem twai sem rcv msg or trcv msg system call Upon chg pri system call 22 Chapter 3 Introduction to MR32R 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 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 cur rently 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
83. configuration file 90 Chapter 5 Detailed Applications 5 2 2 Writing 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 mr32r inc which is in the system di rectory 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 mrS32r rnc aR 1 global inth 2 2 inth Registers used are saved on a stack 3 iwup tsk ID taskl process Registers used are restored m X ret int b 4 4 Figure 5 8 Example of interrupt handler Use the GLOBAL pseudo directive 5 2 Program Coding Procedure in Assembly Language 91 5 2 3 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in Assembly Language observe the following precau tions 1 At the beginning of file be sure to include mr32r inc which is in the system di rectory 2 For the symbol indicating the handler start address make the external declara tion 3 Always use the jmp instruction to return from cyclic handlers and alarm handlers For examples include mr32r inc 1 global eychand 2 cychand
84. d by def_exc For this value specify the largest stack size among tasks for which external RAM has been specified for use as the stack 2 Size of the task creating user stack area external RAM Definition format Numeric value Definition range 192 or more Specify the size of the user stack area that is used to create tasks 122 Chapter 7 Using Configurator The area of the specified size here is necessary to allocate the stack area external RAM for tasks that are required when creating the task A size of memory required for the stack specified by the cre tsk system call is allocated from this user stack area O Dynamically creating mailbox area definition internal RAM lt lt Format gt gt int_memmbx max_memsize Maximum size of mailbox to be created all_memsize Size of the dynamically creating mailbox area internal RAM y lt lt Content gt gt 1 Maximum size of mailbox to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of mailbox size among those created by issuing the cre_mbx system call For this value specify the largest size among mailboxes for which the internal RAM has been specified 2 Size of the dynamically creating mailbox area internal RAM Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating mailbox area The area of the specified size he
85. d to care what libraries must be linked Chapter 3 Introduction to MR32R 10 Chapter 3 Introduction to MR32R 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 Figure 3 1 shows the relationship between the program size and required development time program development difficulty This figure is nothing more than a schematic diagram However it indicates that the development pe riod 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 Development Period Kbyte Program Size Figure 3 1 Relationship between Program Size and Development Period Under these circumstances it is necessary to adopt a method by which large size programs can be developed within a short period of time One way to achieve this purpose is to use a large number of microcomputers 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 On condition that the ROM program burning step need not be pe
86. database file sys ram inc mr32r inc template file mr32r inc Section definition file section or m32r cmd makefile template file makefile ews or makefile dos MR32R version file version Startup file crtOmr ms starut ms or crtOmr s Interrupt control program ipl msor ipl s The template files for initializing timer XXX tpl 148 Chapter 7 Using Configurator 7 2 3 Configurator Start Procedure Start the configurator as indicated below A cfg32r vmiVR Configuration file name Normally use the extension cfg for the configuration file name Command Options v Option Displays the command option descriptions and detailed information on the version V Option Displays the information on the files generated by the command R Option Select this option to put a C written function to the pass by register manner With the TW32R or DCC M32R used this option is not available i Option A timer initialization file timer inc is generated automatically This file is not generated if it already exists 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 and the section definition file are not in the current directory the configu rator copys them to the current directory form the directory indicated by the environment variable LIB32R UNIX standard
87. dler in configuration file when the system clock is used For example if there are 64 factor of interrupts from factor number 0 to 63 and factor number 16 is a system clock you must describe as below interrupt vector 16 Sys timer Precautions about system clock handler e When timer initializing template file m32160 tpl for the M32160 group MCUs is used When timer initializing template file m32160 tpl for the M32160 group MCUs is used timer interrupt share the same interrupt entry So the judgement program which timer interrupt occured is needed It is the interrupt handler defined in the item of the interrupt handler in configurationfile The system clock interrupt handler must be called from the judgement program when a sys tem clock interrupt occurred bl instruction must be used bra instruction must not be used when w sys timer is called The external interrupt must be disabled clear IE bit of PSW register when the system clock interrupt handler is called 6 8 2 Automatic system clock settings The structure of system clock settings MR32R supports automatic system clock settings e q timer initialize ICU settings for several kind of M32R microcomputers The following is the structure of system clock settings At first the template file name the timer name interval of timer interrupt and the timer operating clock frequency are describe in the configuration file Then the configurator copies template fil
88. dress 35 In this case Cast to the data of argument of the system call to convert into pointer types 36 First in first out 3 5 MR32R Kernel Structure 45 Message queue Figure 3 30 Message queue Size The MR32R kernel offers the following mailbox system calls Creates a mailbox cre mbx Creates a mailbox having an ID some other task appoints e Deletes a mailbox del mbx Deletes a mailbox having an ID some other task appoints e Transmitting a Message snd msg isnd msg Sends a message or puts a message into the mailbox e Receiving a Message rcv msg trcv 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 code without incurring the WAIT state if the message is not found in the mail box Referencing the mailbox s status ref mbx Checks whether tasks are present that are waiting for a message to be sent in the relevant mailbox and references the first message in the mailbox 46 Chapter 3 Introduction to MR32R 3 5 8 Messagebuffer The messagebuffer accomplishes synchronization and communication simultaneously by passing messages as in the case of the mailbox function The difference with the mailbox is that it is a copy of the message content that is tra
89. e from the directory specified LIB32R environment variable to the current directory as timer inc and outputs the timer name the interval of timer interrupt and the timer operating clock frequency defined as symbols in mr32r inc timer inc file is included by ipl ms file and the system timer is initial ized by using the symbol definitions in mr32r inc You can re use ipl ms file used as before The template file name and the kind of supported micro computers are shown in the Fig 6 3 If your micro computer is not supported please make this file as ipl ms Precautions about automatic timer settings When automatic timer settings function is used Execute configurator with I option sommand The configurator does not copy timer inc when timer inc file already exists in current direc tory The configurator does not check the overflow of the timer count value e When automatic timer settings function is not used Make an interrupt control program ipl ms when TM is not used and the configurator is exe cuted with m command option If you don t make it compile error may occure after makefile generated See sample ipl ms in the sample program directory 104 Chapter 6 Notes of developing user program 6 9 Precautions about depending on compiler 6 9 1 When CC32R is used The procedure of using CC32R base register function on MR32R The following is the procedure of using CC32R base register funct
90. e 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 devel opment 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 essential that communication be properly maintained among the team members 3 To enhance software production efficiency so as to increase the volume of possible software development per engineer One way to achieve this target would be to educate engineers to raise their level of skill An other 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 ef ficiency by promoting modular software development However the conventional methods are not adequate for the purpose of solving the problems Under these circumstances it is ne
91. e 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 MR32R Program executi on Program execution interrupt resumed Key input Task Duringthis interval it Remot t cci EM 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 microcomputer is halted while another task assumes execution control Task execution restarts at the point of last interruption as the register contents prevailing at the time of the last interruption are recovered In other words task switching refers to the action performed to save the currently executed task register contents into the associated task management memory area and recover the register contents for the task to switch to To establish the real time OS therefore it is only necessary to manage the register for each task and change the register contents upon each task switching so that it looks as if a number of micro computers exist See Figure 3 6
92. ea INITIALIZE The initialization fot the OS debugging function is performed Lf Dbg flg 1d24 rl t Dbg buffer start 1424 r0 __Dbg_addr st ri ro 1d24 rl t Dbg cnt idi r0 0 st r0 rl 1d24 rl t Dbg mode ldb r0 rl ldi r2 1 or rO r2 stb r0 rl endif Set ipl in ipl ms is called and the initial cofiguration of an interrupt priority level is performed bl Set ipl When using a timer X sys timer init in ipl ms is called and the initialization for the timer is performed ifdef USE TIMER B Sys timer init endif gt bl init abort Start task An initial starting task is started Please do not change this portion ldi R4 2 start_task 1d24 R5 4 D INIT START add R5 R4 lduh R1 Q 2 R5 8 2 How to Customize the MR32R Startup Program 128 beqz Rl start_task_end 129 ldi R2 NULL 130 ldi RO ISTA_TSK 131 TRAP 8 T32 addi R4 2 133 bra start_task 134 start_task_end T35 Tar R5 NULL 136 1d24 R4 __eng_dsp 137 stb R5 R4 138 bra Start up exit 139 140 global _ init 141 init 142 jmp r14 143 144 Please do not change this portion 145 146 if __Dbg_flg 147 Section MR KERNEL ax 148 align 4 149 global Dbg idle 150 global Dbg RUNtsk Dbg int entry Dbg int exit 151 global Dbg ent handler Dbg ext handler Dbg int exit2 152 global Dbg sys exit Dbg sys exit2 Dbg sys timer 153 Dbg idle 154 Dbg RUNtsk 155 Dbg
93. ect Settings 3 Select Path button and specify the MR32R kernel library path The MR32R library is installed lib32rg directory under the directory specified in installing When MR32R is installed to c mtool c mtool lib32rg corresponding to the directory When D CC M32R is used Precaution about the output of the dependence The configurator outputs warnings because it can t output dependence of system include files when it is executed with m command option Workaround 1 Copy the MR32R kernel include file mr32r h to the system include directory of D CC M32R e q copy INC32RG mr32r h DIABLIB include 2 Change the environment variable INC32RG to the system include directory of D CC M32R e q set INC32RG DIABLIB include 106 Chapter 6 Notes of developing user program 6 10 Memory mapping 6 10 1 Memory Allocation when Using CC32R Here follows explanation as to the sections the OS uses when using CC32R O Sections used when C is in use e P Section This section is allocated for user application programs e B Section This section is allocated for non initial valued data This section must be allocated to RAM area C Section This section is allocated for constant data e D Section This section is allocated for initial valued data This section must be transferred from ROM area to RAM area Sections for use with MR32R e SYS STACK Section This section is allocated fo
94. ed to make an exclusive use of one timer for the MR32R 3 5 MR32R Kernel Structure 65 1 System clock setup reading 2 Cyclic handler 3 Alarm handler 4 dly tsk system call 5 The system calls specified time out value Figure 3 46 Cyclic Handler rev orp LS TCY ON AA 9 S a Figure 3 47 Cyclic Handler TCY_ON Selected as Activity Status TCY OFF act cyc TCY ON a p a TCY_INI_ON Figure 3 48 Cyclic Handler TCY_INI_ON Selected as Activity Status set tim get tim systemcall si tslp tsk twai_flg twai_flg trcv msg tsnd mbf trcv mbf tcal por tacp por tget_blf tget blk etc 66 3 5 13 Chapter 3 Introduction to MR32R System Management Function Gets information of the MR32R version get ver The information on the MR32R version can be obtained using the get ver system call The 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 Mitsubishi Electric 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 MR32R version number Product Control Information Product release number release date and o
95. edet 91 D Debug fundion ssssssssssreresrrssrsrarenrnresturenernrenen 120 OEE EXC E 66 def ME S dcos eerte ote rre dee Read 55 default erit 145 del flg ien ees 40 del Mbit es een e ers 48 del N O 45 del Puri centres 57 del pliciter etn 60 A ob ia o bre us 51 fo Semi ettet ederent rie n ee ete arte 42 del tek ceci rre prr ne tire 34 delay dispatching sseeeeee 94 dis dsp nett me rete meer oreet 94 dispatchilhig rra 13 ou A E a 63 DORMANT catador dass 24 E A rre e REX Pr ER ERES 94 enable or disable interrupts 98 eventflag tex epar be rat Mo gs 40 Eventflag definition esss 132 Eventflag Queue ssseeeeneee nennen 23 eXCentl ON aii D oen deat egens 67 O itte desert ree erster metre eR IRAE 34 uc qr m 34 F Fixed size memorypool definition 137 Fixed size M emorypool Management 57 A seen 120 forced exception ssesseeeeese 87 92 Forced exception attribute 66 forced exception handler 67 Forced exception handler cece 66 Forced exception handler start address 66 frequency a reap Ee pg PUR 117 function NAM ccccccccnccnononannnona non nno nc rn nc rn corner 117 o A ee ed e Uere e rue e 52 G get blTs riii eto e tdt nes 57 get blk nate rtt emeret 60 get tid iie tI ege pene ind e 36 get timi ineo ec rU ete ey
96. ee 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 Semaphore x 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 MR32R kernel offers the following semaphore synchronization system calls e Creates a semaphore cre sem Creates a semaphore having an ID some other task appoints e Deletes a semaphore del sem Deletes a semaphore having an ID some other task appoints e Signaling 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 3 5 MR32R Kernel Structure 43 semaphores service e 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 e Acquiring the Semaphore preq sem Acquires the semaphore If there is no semaphore to acquire an error code is returned and the WAIT state does not prevail Referencing the semaphore s status re
97. efinition format Numeric value Definition range 1 or more Define the total stack size used in system call and interrupt processing 2 Maximum value of priority value of lowest priority Definition format Numeric value Definition range 1 255 Define the maximum value of priority used in MR32R s application programs This must be the value of the highest priority used 3 Exception handler Definition format Symbol Definition range YES or NO If a forced exception handler is defined in application program set YES in this section If not defined set NO in this section 4 Debug function Definition format Symbol Definition range YES or NO If you use MR trace function or system call issuance function in a debugger which supports OS debug function ex PD32R set YES in this section If not use set NO in this section By setting YES MR32R calls the hook routines to support OS debug function 5 Buffer size for OS debug function Definition format Numeric value Definition range 0 or more multiple of four Specify the buffer size for OS debug functio If you secure 4096 bytes about 60 times dis patching or more can be traced 7 1 Configuration File Creation Procedure 121 Dynamically creating user stack area definition internal RAM lt lt Format gt gt int_memstk max_memsize Maximum size of task stack to be created all memsize Size of the task creating use
98. elete all object files extension o or mo and execute the make command In this case an error may occur during linking e Do not modify the strartup program name and the section definition file name Otherwise an error may be encountered when executing the configurator The configurator cfg32r can only generate UNIX standard makefile or one conforming to UNIX standards Namely it does not generate MS DOS standard makefile 7 2 Configurator Execution Procedures 151 7 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 cfg32r Error syntax error near line 16 test cfg There is an syntax error in the configuration file cfg32r Error not enough memory Memory is insufficient cfg32r Error illegal option gt lt x gt The configurator s command option is erroneous cfg32r Error illegal argument gt xx The configurator s startup format is erroneous cfg32r Error can t write open lt XXXX gt The XXXX file cannot be created Check the directory attribute and the remaining disk ca pacity available cfg32r Error can t open lt XXXX gt The XXXX file cannot be accessed Check the attributes of the XXXX file and whether it ac tually exists cfg32r Error can t open version file The MR32R version file
99. em 3 be sure to omit specification of this item 3 Section name Definition format Symbol Definition range None Define the section name allocated memorypool Be sure to allocate this section in your sec tion file If you specify mpf area in item 2 be sure to omit specification of this item 138 Chapter 7 Using Configurator 4 Number of block Definition format Numeric value Definition range 1 32 Define all Number of block for memorypool 5 Size Definition format Numeric value Definition range 1 or more Define the size of one memorypool block When this definition is formulated the RAM ca pacity of the memorypool is set to number of blocks x size O Variabel size memorypool definition lt lt Format gt gt Variable Size Memory Pool Definition variable_memorypool ID No name Name mpl_area Variable size Memorypool location max_memsize The maximum memory block size to be allocated heap_size Memorypool size The ID number must be in the range of 1 to 32766 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt 1 Name Definition format Symbol Definition range None Define the name with which a memorypool is specified in a program 2 The maximum memory block size to be allocated Defi
100. em data definition files sys rom inc and sys ram inc include files mr32r inc and id h and system generation procedure description file makefile 5 System Generation Generate the system by executing the make command 6 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 MR32R System Generation Detail Flowchart The make command comes the UNIX standard and UNIX compatible 4 1 General Description 75 Application Configuration C source file C compiler Configurator Assembler System data Source definition file Relocatable Assembler Application MR32R object Library Linkage Editor System generation procedure Absolute module Load module converter ROM write format Figure 4 1 MR32R System Generation Detail Flowchart 76 Chapter 4 Applications Development Procedure Overview 4 2 Development Procedure Example This chapter outlines the development procedures on the basis of a typical MR32R application exam ple 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
101. entation Dependent Mailbox with Priority Mailbox with priority has a message queue for storing the messages which were sent and a message wait queue to which the task waiting any message is connected Differences to the former bailbox OS kernel manages message queue as link list You must prepare a header area called as Mes sage header This message header and the area used in the application program are called as Mes sage packet OS kernel rewrite the message header to manage mailbox function You can t modify it MR32R defined the message packet data types as below T MSG message header of the mailbox T MSG PRI message header for message with priority of the mailbox The number of the message which is able to be connected to the message queue is not limited be cause of the application program securing the header area Also the task does not become to send wait state The task can receive the higer priority message from the mailbox by spcifying its attibute as TA MPRI The higher priority task can receive the message from the mailbox by spcifying its attibute as TA TPRI Creates a mailbox with priority vcre mbx Creates a mailbox with priority for the specified ID number of the mailbox e Deletes a mailbox with priority vdel mbx Deletes a mailbox with priority for the specified ID number of the mailbox e Sends a message vsnd mbx visnd mbx Sends a message The task can receive the higer priority message from the mailbox by
102. ere is a task waiting for call rendezvous establishment condition is not met the task that issued acp por or tacp por is placed in an acceptance wait state so it is queued up in the acceptance wait queue TaskA TaskB TaskC Rendezvous Rendezvous call wait call wait Rendezvous established Message transfer acp por End of rendezvous Rendezvous established z Message transfer z End of acp_por m rendezvous ugit z LI LI LI m LI LI z Port 1 Port2 LI Figure 3 36 Multiple rendezvous sessions e Accept rendezvous call from port pacp por Performs the same processing as with the acp por and tacp por system calls except that if no task exists that is kept waiting for call at the specified port or although there is a task wait ing for call rendezvous establishment condition is not met the issuing task only returns error code without going to an acceptance wait state Forward rendezvous to port fwd por When this system call fwd por is issued the task currently in rendezvous session with the 3 5 MR32R Kernel Structure 53 calling task is released from the rendezvous state and a rendezvous call is made to a speci fied another port This system call must always be issued after executing the acp por tacp port or pacp por system call After rendezvous forwarding the same processing as with the cal por tcal por or pcal por system call is performed TaskA TaskB TaskC
103. est Cancellation 40 Chapter 3 Introduction to MR32R 3 5 5 Eventflag The eventflag is an internal facility of MR32R that is used to synchronize the execution of multiple tasks The eventflag uses a flag wait pattern and a 32 bit pattern to control task execution A task is kept waiting until the flag wait conditions set are met The MR32R kernel offers the following eventflag system calls e Create eventflag cre flg Creates an eventflag with the ID specified by a task e Delete eventflag del flg Deletes an eventflag with the ID specified by a task e Setting the Eventflag set flg iset flg Sets the eventflag so that a task waiting the eventflag is released from the WAIT state e Clearing the Eventflag clr flg Clearing the Eventflag e 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 OR wait 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 Obtaining the eventflag s status ref flg References the bit pattern of the relevant eventflag and checks whether a waiting task is present Figure 3 24 shows an example of
104. etan on 211 Contents List of Figures V List of Flgures 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 Flgure 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 3 40 Figure 3 41 Figure 3 42 Figure 3 43 Figure 3 44 Figure 3 45 Figure 3 46 Figure 3 47 Figure 3 48 Figure 4 1 Figure 4 2 Figure 4 3 Relationship between Program Size and Development Period 10 Microcomputer based System E xample Audio E quipment sess 11 Example System Configuration with Real time OS Audio Equipment 12 Time division Task Operation sse eene 13 Task Execution Interruption and Resumption s sese 14 Task Switching tercer rette e etre nte te e tr Pe Bei Bere lucha retest ade ERR e ar 14 Task Register Area er tinet gene Hie bte pee tintin 15 Actual Register and Stack Area Management sss 16 System Calli eae qe rete ABI ED RH HEC E etr e RE Pen e la atts 17 System Call Processing Flowchart essent 18 Task
105. ether or not to initiate task execution This results in accomplishing synchronization between tasks Semaphore Reads the semaphore counter value controlled within the MR32R and then deter mines 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 e Extended synchronization and communication This function is provided to synchronize operation between tasks and perform intertask com munication Following two functional modules are available Messagebuffer Performs intertask synchronization and communication simultaneously Unlike the mailbox this function allows variable size messages to be copied before being trans mitted or received Rendezvous Adjusts timing between tasks by keeping messages waiting as necessary 31 This handler actuates once only at preselected times 32 This handler periodically actuates 3 5 MR32R Kernel Structure e Memorypool Management Function Provides dynamic allocation or release of a memory area used by a task or a handler e Inplementation Dependent Function Provides forced exception function and resetting OS resources Function e Inplementation Dependent Function mailbox with priority Provides mailbox with priority Function 33 34 Chapter 3 Introduction to MR32R 3 5 3 Task Management Function The task management function is used to perform tas
106. f_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 systemcalls Tu wai sem sig sem as o wai_sem Task wai sem Task wai_sem Task e Semaphore 3 2 1 0 Counter Figure 3 27 Task Execution Control by Semaphore 44 Chapter 3 Introduction to MR32R 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 P TaskA Figure 3 28 Mailbox The messages that can be placed into this mailbox are 32 bit data Standard specifications are such that MR32R uses this data as the start address of a message packet However this data can be used simply as ordinary data y Mas Message Packet Figure 3 29 Meaning of Message The mailbox is capable of storing messages Stored messages are retrieved on the FIFO ba sis 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 ES According to the standard stated in ITRON Specification this data is to be used as the message packet first ad
107. fference with get bIk and tget blk is that when no memory block of the specified size exists in the memorypool the is suing task only returns error code without going to a wait state 3 5 MR32R Kernel Structure 61 Release memory block rel blk Releases the memory block that has been acquired by get blk tget blk or pget blk If there is no task waiting for the memory block of the specified memorypool the memory block is re turned to the memorypool TaskA M emorypool M emorypool rel blk gt top of address Free Free Figure 3 42 rel blk processing If when releasing a memory block there is any task waiting for the memory block of the target memorypool the required size is examined beginning with the first task in the wait queue and when condition is met memory of the required size is separated off the memorypool and allocated to the task with the task status changed from the wait state to an executable READY state Then the required size of the next task in the queue is compared with the remaining size of the released memory If the condition is not met for any task in the queue memory block allocation is finished at that point in time lt means that the condition is the case the required memory size is lesser than the freed memory size 62 Chapter 3 Introduction to MR32R get blk 200 Task A Task B Task C Task D Wait queue Release 500 bytes memory block Wait queue Figure 3 43 Release Memory b
108. finition range None Define the name with which an eventflag is specified in a program 7 1 Configuration File Creation Procedure 133 Semaphore definition lt lt Format gt gt Semaphore Definition semaphore ID No name Name max_count Maximum value of semaphore counter initial count Initial value of semaphore counter y The ID number must be in the range of 1 to 32766 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 Maximum value of semaphore counter Definition format Numeric value Definition range 0 Ox7FFFFFFF Define the maximum value of the semaphore counter 3 Initial value of semaphore counter Definition format Numeric value Definition range 0 Maximum value of semaphore counter Define the initial value of the semaphore counter Mailbox definition lt lt Format gt gt Mailbox Definition mailbox ID No name Name mbx_area Mailbox location buffer_size Maximum number of mailbox messages The ID number must be in the range of 1 to 32766 The ID number can be omitted
109. fy for end section the tail address of the downloading target and specify for rom section the first address of the downloading Source Usually symbols set in the linker script file m32r cmd are used for these addresses Here is a macro to transfer the text area described as shown below in m32r cmd by use of registers RO R1 R2 R3 START data data LOAD ROM data data END data DOWNLOAD RO R1 R2 R8 START data END data ROM data 170 Chapter 8 How to Customize 8 2 2 How to Stop Transmission to RAM from ROM The section without the necessity of transmitting to RAM from ROM cancels transmission process ing The section with the necessity of transmitting and the section without the necessity of transmit ting are as follows Section which is needed to be transferred ROM area to RAM area e D sdata data Data section with initial value Section which is not needed to be transferred ROM area to RAM area e P text User program section e C rodata Constant data section e MR_KERNEL MR_KERNEL OS kernel section Transferring depends on the condition e MR_ROM MR_ROM OS data section If you use dynamic task creation or OS object creation function it need to transfer ROM area to RAM area e INTERRUPT VECTOR INTERRUPT VECTOR _ Interrupt vector table section You must delete transferring process description in start up program if you must allocate this section on ROM Flash ROM area EIT Vecto
110. g entryl KHOR DPA PR OR 20h OK ct t nop section balign 4 global int entry bra int entry if MR EXC HANDLER global DEF EXC HDR DEF EXC HDR vret exc endif Int Vector Dbg_entry0 __Dbg_entryl Section RESET align 4 reset n bra START Figure 8 4 _V CT ax EIT Vector awx TRA TRA TRA TRA TRA TRA TRA TRA TRA TRA TRA TRA TRA TRA TRA TRA PO Pl P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 Chapter 8 How to Customize EA FAXRKRKHRKAKAKAKKAKAKXK KK KAR Startup Program for C Language for DCC M32R 8 3 Customizing the Section File 185 8 3 Customizing the Section File 8 3 1 Using CC32R This subsection describes the way of laying out memory for application program data To lay out mem ory you use the section file section that comes with the MR32R This file is delivered to the linker as the linker s section allocating option Allocate sections and set the start addresses in conformity with your system Usually write section namessubsequent to SEC To transfer the data to the built in DRAM from an external ROM precede the target section names with an An example is given below Arrow in the figure stand for transfer in the arrow direction from ROM to RAM SEC RESET_VECTOR EIT_Vector 40 I
111. g vali able size memorypool function EXT MR HEAP Section This is the external RAM heap area used by MR32R This section used when using vali able size memorypool function EXT MR HEAP Section This is the external RAM heap area used by MR32R This section used when using vali able size memorypool function 6 10 Memory mapping 109 O Sections related to interrupt vectors e int Vector Section EIT Vector Section This section is used for storing the EIT vector area e RESET VECT Section This section is used for the reset vector area e INTERRUPT VECT Section This section is used for interrupt vector table This section must be transfer ROM area to RAM area when def int system call is used 110 Chapter 6 Notes of developing user program 6 10 3 Memory Model In MR32R there are two kinds of following memory models Large model It is the model which can arrange the kernel area and data area of MR32R to the space ex ceeding 16MB Only the M3 T CC32R correspondence kernel is preparing the large model There is the following restriction about the section arrangement at the time of large model correspondence Or it is not supporting EVB EIT vector base register the processing shown below is required of the microcomputer which cannot set EVB as the domain exceeding 16MB None large model a The following sections can be mapped into areas beyond address 1000000H INT USR STACK EXT USR STACK SYS S
112. ge this portion 1321 129 An initial starting task is started Chapter 8 How to Customize Dbg int exit 180 Dbg buffer end 181 Dbg addr space 1 4 189 global Dbg buffer start 182 Dbg cnt space 1 4 183 Dbg sys iss Space 7 4 184 Dbg mode space 1 185 else 186 section MR_Dbg_RAM aw 187 align 4 188 global __Dbg_mode global Dbg ent handler Dbg ext handler Dbg int exit2 132 Idi RA 2 133 start task 134 1d24 R5 4 D INIT START 135 add R5 R4 136 lduh R1 2 R5 137 beqz Rl start_task_end 138 ldi R2 NULL 139 ldi RO ISTA_TSK 140 TRAP 8 141 addi RA 42 142 bra start task 143 start task end 144 1di R5 4 NULL 145 1d24 R4 f enq dsp 146 stb R5 R4 147 bra Start up exit 148 149 Please do not change this portion 150 T5 if __Dbg_flg 152 Section MR KERNEL ax 153 align 4 154 global Dbg idle 155 global Dbg RUNtsk Dbg int entry 156 157 global Dbg sys exit Dbg sys exit2 Dbg sys timer 158 Dbg idle 159 Dbg RUNtsk 160 Dbg int entry 161 Dbg int exit 62 Dbg int exit2 163 Dbg ent handler 164 Dbg ext handler 165 Dbg sys exit 166 Dbg sys exit2 167 Dbg sys timer 168 endif 169 70 SE Dbg flg 71 Section MR Dbg RAM aw 72 align 4 T3 global Dbg_mode 74 global Dbg buffer start TS global _ Dbg_buffer_end 76 global X Dbg cnt TT global _ Dbg addr
113. gement Mail Box Semaphore management MR32R kernel TEP M emorypool Exception Synchronization Eventflag management Management System Message Management buffer Rendezvous mailbox with Interrupt oneal priority Management Hardware M32R Family micro computer Figure 3 17 9 For details See 3 5 10 MR32R Structure 32 Chapter 3 Introduction to MR32R 3 5 2 Module Overview The MR32R kernel modules are outlined below e Scheduler Forms a task processing queue based on task priority and controls operation so that the high priority task at the beginning in that queue task with small priority value is executed Task Management Module Exercises the management of various task states such as the RUN READY WAIT and SUS PEND state Task Synchronization Module Accomplishes inter task synchronization by changing the task status from a different task e Interrupt Management Module Makes a return from the interrupt handler e Time Management Module Sets up the system timer used by the MR32R kernel and starts the user created alarm han dle and cyclic handler System Management Module Reports the MR32R kernel version number or other information e Sync Communication Module This is the function for synchronization and communication among the tasks The following three functional modules are offered Eventflag Checks whether the flag controlled within the MR32R is set up and then determines wh
114. gram Coding esi si seinen theta th siano insita 76 422 Configuration File Preparation ooiiiiiniiiniin ici 78 42 Configurator EXCCUliON oociiiinninninininiin miii 80 4 24 System GOL az To s BREED 80 ALDO WEDQAOM zusenden dte ene arad AA E A 80 Chapter 5 Detailed ApplicatioNS ooonccconncnonicinnconconccnnoccncnncnn none cnnnrn cnn nnne nenne nnns 81 ii Contents 5 1 Program Coding Procedure in C Language esses 82 5 1 1 Task Description Procedure ise seinen etnia aita stats tasas eaae ansia saa 62 5 1 2 Writing Interrupt Handler sien ntn aane eia eiae tasas aiia naa 85 5 1 3 Writing Cyclic Handler Alarm Handler nennt 86 5 14 Writing Exception forced exception hanaller ient 67 5 2 Program Coding Procedure in Assembly Language seen 88 521 WHALING T ISE Er RR PAR HR BP EE ER 68 522 Writing Interrupt Handler si se einen eia sitae 90 523 Writing Cyclic Handler Alarm Handler iieri nnn 91 524 Writing Exception forced exception handler sientan 92 Chapter 6 Notes of developing user program nnne nnn nnne nnns 93 6 1 MR32R has four system calls related to delay dispatching ssesssuss 94 6 2 Regarding Initially Activated Task sssssssssesseeeeene enne nennen nennen 95 6 3 Anoteon using alarm handler sesssessssseseeene enne nnne nennen nnne nns 95 6 4 About dynamic generation and deletion
115. he data to the built in DRAM from an external ROM such as an EIT vector entry a program area or the like Initializing variables in C written programs crtOmr ms crtOmr s only Setting the system timer Initializing the MR32R s data areas Copy these start up programs to the current directory from the directory that the environment vari able LIB32R points at If necessary modify or add the startup file 5 68 With the startup program absent from the current directory executing the configurator taking in the optionm copies the startup program to the current directory from the directory that the environment variable LIB32R points at 168 Chapter 8 How to Customize 8 2 1 Transferring the data to the built in DRAM from an external In MR32R a DOWNLOAD macro which is defined by the file mr32r inc can be used and trans mission processing to RAM from ROM can be performed By the start up routine of product appending transmission processing of the data area with initilal value and the MR ROM or MR ROM section is performed The following paragraph explains the change method and the description method of the section file section m32r cmd at the time of using the macro for download With CC32R in use DOWNLOAD reg1 reg2 reg3 section ROM_section Specify registers to be used in the macro for reg1 reg2 reg3 Specify for section a section name to be downloaded and specify for ROM section a name that precedes with ROM
116. ial start ON entry_address task1 stack size 0x1000 stack area MR INT priority 23 y task 2 entry_address task2 stack_size 0x1000 Stack section TASK2_STK priority 3 y task 3 entry_address task3 stack_size 0x1000 Stack area __MR_EXT priority 4 e Event Flag Definition flag 1 name flgl 7 1 Configuration File Creation Procedure y Semaphore Definiton semaphore 1 name seml max count ORTE initial count 0x0 y MailBox Definition mailbox 1 name mbx1 mbx_area _ MR_EXT buffer_size 0x10 y MessageBuffer Definition message_buffer 1 name mbf mbf_area __MR_INT buffer_size 0x10 y Rendezvous Definition rendezvous 1 name porl y Fixed Memory pool Definition memorypool 1 name mpfl mpf area MR EXT num_block 4 siz_block 0x100 memorypool 2 name mpf2 section MPF2_ POOL num_block qe siz_block 0x100 y Variable Memory pool Definition variable_memorypool name mpll mpl area __MR_INT max_memsize 0x500 heap size 0x6000 y systemcall cre_tsk NO del_tsk NO sta_tsk YES ter_tsk YES chg pri E YES rot rdq VES rel_wai YES ena_dsp YES sus_tsk YES rsm tsk YES slp_tsk YES wup_tsk YES set_flg NES wai flg YES sig_sem YES wai_sem YES snd_msg YES rcv msg YES snd_mbf
117. ic han dler activity is to be changed determine whether or not to validate a preset cyclic handler 3 Alarm Handler This handler starts at preselected times 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 This transfer is called dispatching or switching act cyc system call 3 4 Handler 29 Task System dock interrupt handler Cydic handler Alarm handler Subroutine call Timer interrupt Figure 3 16 Cyclic Handler Alarm Handler Activation 30 Chapter 3 Introduction to MR32R 3 4 1 System Calls Exclusive for Handlers In the MR32R 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 1System Calls Issuable from only Handlers System call name Function ichg pri Change Task Priority Changes the task priority irot rdq Rotate Ready Queue Rotates the task ready queue irel wai Release Task Wait Forcibly clears the task WAIT state isus tsk S
118. ies 255 Maximum number of eventflags 32766 Eventflag width 32 bits Maximum number of semaphores 32766 Semaphore type Counter type Maximum number of mailboxes 32766 Message size 32 bits Buffer size of Mailbox more tha 4bytes Maximum number of Messagebuffer 32765 Maximum number of port for rendezvous 32765 Maximum number of Fixed size Memorypool 32766 Maximum number of Variable size Memorypool 32766 Number of system calls 115 OS nucleus code size OS nucleus data size Approx 4 K to 50 K bytes 81 bytes min 44 byte increment per task OS nucleus language C and Assembly language The sum of the number of eventflags the highest priority the number of semaphores the number of mailbox with priority the number of the maximum milbox with priority the number of mailbox with priority defined in the configuration file the number of mailbox with priority defined in the configura tion file and specified as TA TPRI X the highest priority value of tasks and number of mailboxes is not to exceed 32766 8 Chapter 2 General Information 2 3 MR32R Features The MR32R offers the following features Real time operating system conforming to the uITORN Specification The MR32R 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 u ITRON Specification is a subset of
119. igure5 2 Example Task Terminating with ext tsk Described in C Language 83 Figure5 3 Example of Interrupt Handler sessssssssseeseseeeeeneenneenne nnne nnne 85 Figure5 4 Example Cyclic Handler Written in C Languagge ssessseseeeenen 86 Figure5 5 Example Exception Handler Written in C Language see 87 Figure5 6 Example Infinite Loop Task Described in Assembly Language 88 Figure5 7 Example Task Terminating with ext tsk Described in Assembly Language 88 Figure5 8 Example of interrupt handler sessssssssseseeeeeenee enne nnne 90 Figure5 9 Example Cyclic Handler Written in Assembly Language esee 91 Figure5 10 Example exception handler Written in Assembly Language 92 Figure6 1 Interrupt control in a System Call that can be Issued ssssssese 98 Figure6 2 The procedure for running the interrupt handler esses 99 Figure6 3 Allocate OS kernel tothe over LOMB area sesseeeeneeneeenneneenns 111 Figure7 1 The operation of the Configurator sesssssssseseseeesene enne 146 Figure8 1 The stack status of interrupt control program 157 Figure8 2 Startup Program for C Language for CC32R ssssseeeeneenneenneene 175 Figure8 3 Startup Program for C Language for TW32R
120. ilt in RAM data area of MR32R e START OF EXT OF RAM Stands for the start address of the external RAM data domain of MR32R e RESET Stands for the start address of the reset vector 188 Chapter 8 How to Customize 8 3 3 Sample Linker Script Ju 2 m32r cmd Linker script for M32R amp MTM 3 This script is based on m32r elf lib ldscripts m32relf x 4 Q 4 m32r cmd 1 280 4 99 03 16 5 Id m32r cmd v 1 2 2001 04 18 06 24 31 inui Exp 6 7 8 System Calls You selected 9 10 Users are not allowed to remove and modify the below 11 blocks because MTM should handle these blocks T2 E MTM INPUT 13 MTM SEARCH DIR 14 MTM GROUP I5 16 Since TM uses this portion please do not correct 17 18 M INPUT TOP 19 MTM INPUT END 20 M SEARCH DIR TOP 21 22 M SEARCH DIR END 23 MTM GROUP TOP 24 MTM GROUP END 25 26 27 OUTPUT FORMAT elf32 m32r elf32 m32r elf32 m32r 28 OUTPUT ARCH m32r 29 ENTRY START 30 Do we need any of these for elf 31 DYNAMIC 0 32 33 Memory Layout 34 This layout is just example Applying this example it 39r E is able to check a linking process exactly 36 343 x 38 MEMORY 39 40 in rom org 0 len 4M 41 in ram1 org 0xf00000 len 64K 42 out_raml org 0x1000000 len 4M 43 44 45 Section Lay
121. imer init 35 36 Initialize the system time Please do not change this portion 37 38 st R14 R15 39 1d24 R4 __D_Sys_TIME_H 40 ldh R5 R4 41 1d24 R6 __Sys_time 42 sth R5 R6 1 43 1d24 R4 __D_Sys_TIME_L 44 ld R5 R4 45 st R5 2 R6 46 47 The initial cofiguration of the timer used for the system clock of OS is 48 performed 49 50 1d24 R10 __timer_count 51 1di R12 4 timer div 52 MFT control register setting 295 1d24 r1 MFTCR 54 ld r0 rl 55 1d24 v2 __write_bit 56 or r0 r2 57 st r0 rl 58 MFT mode register setting 59 1d24 rl METMOD 60 1d24 r0 0x8000 61 or t05 r12 62 st r0 rl 8 1 Interruption Control Program 165 63 MFT port output status register setting 64 1d24 rl MFTOS 65 ldi r0 0 66 st r0 rl 67 MFT reload register setting 68 1d24 rl MFTRLD 69 addi r10 4 1 70 st rl10 Gr1 71 72 MFT interrupt control register setting IEN 1 ILEVEL 3 73 1d24 rl 41CUCR 74 Idi r0 40x1100 75 or3 r0 r0 __stmr_ipl 76 st r0 rl 77 78 MFT control register setting 79 1d24 rl MFTCR 80 1d24 r2 __write_bit ena_bit 81 or r r2 82 st r0 rl 83 84 id r14 r15 85 jmp r14 86 endif 87 88 An interruption control register is saved the jump place address of 89 interruption is saved on a stack and it returns to OS kernel 90 Since it is called from OS kernel by interruption entry processing 91 please do not change this
122. 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 li cense from the Japanese government and cannot be imported into a country other than the approved destination Any diver sion or reexport contrary to the export control laws and regulations of Japan and or the country of destination is prohibited Please contact Renesas Technology Corporation or Renesas Solutions Corporation for further details on these materials or the products 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 XSUPPORTXProduct nameXSUPPORT TXT Renesas Tools Homepage http www renesas com en tools Preface The M3T MR32R abbreviated as MR32R is a real time operating system 1for the M32R micro computers The MR32R conforms to the ITRON Specification This manual describes the procedures and precautions to observe when you use the MR32R for pro gramming purposes For the detailed information on individual system call procedures refer to the MR32R Reference Manual Requirements for MR32R Use When creating programs based on the MR32R it is necessary to purchase the following product of Mitsubishi Electric or third party products e M32R Family Compiler DCC M32R Windriver systems Inc M32R Family Cross tool M3T CC32
123. 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 The template file used for the EWS version is makefile ews and that for the DOS version is makefile dos 9 This makefile is a System generation procedure description file that can be processed by UNIX standard make commands or those conforming to UNIX standards 146 Chapter 7 Using Configurator Configuration File xxx cfg Default Configuration File default cfg System Data Difinition File 7 sys_rom inc sys_ram inc System generation File makefile Template File makefile ews makefile dos ns cfg32r makefile M akefile makefile mr32r inc and sys ram inc i Include File Template File mr32r inc sys ram inc mr32r inc MR32R Version File version Figure 7 1 The operation of the Configurator 7 2 Configurator Execution Procedures 147 7 2 2 Setting Configurator Environment Before executing the configurator check to see if the environment variable LIB32R is set correctly The configurator cannot be executed normally unless the following files are present in the directory indicated by the environment variable LIB32R Default configuration file default cfg This file can be copied to the current directory for use In this case the file in the current di rectory is given priority System RAM area definition
124. ined as follows in the configuration file flag 1 name abc y To designate this eventflag proceed as follows set flg ID abc amp setptn 9 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 10 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 program which actuates before MR32R startup 11 The task executed when the MR32R system starts up is setup 12 The variable storage classification is described below The MR32R treats the C language variables as indicated in Table 5 1 The configurator generates the id h file which converts the task ID number to the associated character string for task desig nation 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 51 Started beginning with the task start function at the initial priority level and with the wake up count cleared 84 Chapter 5 Detailed Applications Table 5 1C Language
125. int entry 156 Dbg int exit 157 Dbg int exit2 158 Dbg ent handler 159 Dbg ext handler 160 Dbg sys exit 161 Dbg sys exit2 62 Dbg sys timer 163 endif 164 165 2s Dbg flg 166 Section MR Dbg RAM aw 167 align 4 168 global Dbg mode 169 global Dbg buffer start L70 global Dbg buffer end All global Dbg cnt T72 global Dbg addr 173 Dbg buffer start 174 space _ Dbg buffer size 175 Dbg buffer end 176 Dbg addr space 1 4 177 Dbg cnt Space 1 4 178 Dbg sys iss Space 7 4 179 Dbg mode space 1 180 else 181 Section MR Dbg RAM aw 182 align 4 183 global Dbg mode 184 global Dbg buffer start 185 global __Dbg_buffer_end 186 Global X Dbg cnt 187 global Dbg addr 188 global Dbg sys iss 189 Dbg buffer start 190 _ Dbg buffer end 191 Dbg addr 183 184 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 24 24 24 24 24 24 24 24 24 24 250 291 252 o 0 10015 CQ NE o Dbg cnt Dbg mode Dbg sys iss endif Ckckckckckckck ck ck ck kk kk EIT Vector AR EIT vector area is set up Section align 4 oO KHOA BA BR BR BARB HK ct if __Dbg_flg __SYSCALLO __SYSCALL1 else global bra bra endif Dbg entryO Db
126. internal RAM Specify MR INT Tolocate the user stack in external RAM Specify MR EXT If this item is omitted _ MR INT is set by default If you specify stack section in item 4 be sure to omit specification of this item 132 Chapter 7 Using Configurator 4 Stack section name Definition format Symbol Definition range None Specify the section name in which you want to locate the task stack The sections defined here must always be located using the section file If you specify stack area in item 3 be sure to omit specification of this item 5 lnitial 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 MR32R s priority the lower the value the higher the priority 6 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 O Eventflag definition lt lt Format gt gt Event Flag Definition flag ID No 1 name Name un The ID number must be in the range of 1 to 32766 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 De
127. ion on MR32R 1 Define base address 2 Generate access control file 3 Define base symbols The base symbols are defined in start up routine lt e q gt R11 0x00FC8000 R12 0x00F88000 R13 unused Modify start up routine as below line 48 to line 66 global _ REL BASE11 global _ REL BASE12 global _ REL BASE13 REL BASE11 equ 0x00FC8000 lt 1 define base sumbols REL BASE12 equ 0x00F88000 REL BASE13 equ 0 START rl f amp high Sys Sp rl rl1 41ow Sys Sp r1 4 r1 SPI SPI initialize rl SPU r0 1 r0 rl r0 NULL r0 PSW PSW initialize R11 high __REL_BASE11 lt 2 Set the value to base registers R11 R11 low __REL_BASE11 when C function is called from R12 high __REL_BASE12 start up routine R12 R12 410w REL BASE12 R13 high __REL_BASE13 R13 R13 410w REL BASE13 Caution You need not to base register settings at the start of the tasksthe interrupt handlers and the cyclic handlers You must define the base symbols when base register function is not used In this case base register value is your discretion 4 Comple and link your program 6 9 Precautions about depending on compiler 105 6 9 2 e 6 9 3 When TW32R is used Precaution about using with TM The default library search path for MR32R kernel library is not registered It must be reg ister to TM clearly 1 Select Project Settings from Environment of TM menu 2 Select LIBRARY tab of the Proj
128. it ena_bit or r0 r2 st r0 low MFTCR r1 ld r14 r15 jmp r14 aendi An interruption control register is saved the jump place address of interruption is saved on a stack Since it is called from OS kernel by in and it returns to OS kernel terruption entry processing please do not change this label name global SAVE IPL to STACK INT VECTOR SAVE IPL to STACK An interruption control register is saved on a stack and an interruption factor number is read addi r15 4 8 st r14 r15 st r4 r15 st r5 8 rlb5 st r6 r15 seth v4 shigh ICUISTS ld r5 low ICUISTS r4 st r5 D 20 r15 srli r5 20 Table reference is carried out from __INT_V address is saved on a stack This table is by configurator as an INTERRUPT VECTOR sect arbitrary addresses by it 1d24 r6 4 INT VECTOR add YO 15 ld r6 r6 st r6 16 4r15 ld r6 r1l5 ld r5 r1l5 ld r4 r15 ld r14 r15 jmp r14 An interruption control register is return Since i please do not c hange this label name global RESTORE IPL from STACK RESTORE IPL from STACK st r14 r15 st r4 r15 st r5 rlb5 ld r5 12 115 ECTOR and interruption jump place outputted to a sys rom inc file ion and can be arranged to d and it returns to OS kernel is called from OS kernel by interruption exit processing 160 127 128 129 130 131 132 133 134 135 136
129. ite of having specified NO by the system call definition of a 162 configuration file 163 164 global SYS DUMMY 165 SYS DUMMY 166 jmp r14 167 164 Chapter 8 How to Customize 8 1 4 Interrupt Control Program for DCC M32R PRR RRR RRR RRR KKK KKK RR KEK hock KKK RRR KKK KKK KEK KR KKK KKK KEK KR KKK KKK KEK kc kk ke ke ck kc ke ke ke ke e ke ke e Copyright 2001 MITSUBISHI ELECTRIC CORPORATION and MITSUBISHI ELECTRIC SEMICONDUCTOR APPLICATION ENGIN All Rights Reserved T I ERING CORPORATION SId ipl s v 1 3 2001 04 18 06 24 30 inui Exp ck Ck Ok ck Ck Ck Ck Ck ck Ck Ck C Sk ck Ck KKK ck ck Sk KK KKK KKK ck kk ck kk ck kk AS 0 J3 0 014 0N FO i000 120 O1 iS CO IND ES include mrz32r ince Section MR KERNEL ax equ TCUTSTS 0x00F7F004 equ ICUIMASK 0x00F7F01C equ MFTCR 0x00F7CO000 equ MFTMOD 0x00F7C080 equ MFTOS 0x00F7C088 19 equ MFTRLD 0x00F7CO8C 20 equ ICUCR 0x00F7F23C 21 equ _ write bit 0x8000 22 equ ena bit 0x0080 23 24 equ timer count 0x6596 25 equ timer div 0x3 26 27 Use the label sys timer init 28 sys timer init to initialize the timer is called from the startup routine 29 at the time when the timer is used 30 ifdef USE TIMER 31 global Sys timer init stmr ipl stmr src stmr cnt 32 global D Sys TIME H Sys time stmr ctr 33 34 sys t
130. 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 3 WAIT state It exits the RUN state and enters the WAIT state The WAIT state is usually used as the con dition in which the completion of I O device I O operation or the processing of some other task is awaited The task goes into the 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 explic itly by some other task The task enters and remains 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 rcv msg snd mbf rcv mbf cal por acp por get blf get blk vrcv mbx 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 tslp_tsk wai flg tw
131. ity 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 Priority TCB TCB TCB TCB i TCB l l al TCB TCB Figure 3 19 Priority Change 36 Chapter 3 Introduction to MR32R e Rotating the Ready Queue rot rdq irot rdq This system call establishes the TSS time sharing system That is if the ready queue is ro tated at regular intervals round robin scheduling required for the TSS is accomplished See Figure 3 20 Priority E a a 4 ba Move the end of the queue Figure 3 20 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 9999999 99 Time out wait state Time out wait state by slp tsk Eventflag wait time out state Semaphore wait time out state Message wait time out state Send message wait time out state message buffer Recieve message wait time out state message buffer Call wait time out state rendezvous Recieve wait time out state rendezvous Memory block allocation wait time out state fixed size or variable size Mess
132. jective of MR32R Development 5 4 Timer control is made easier To perform processing at 10 msec 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 microcomputer 5 Software maintainability is enhanced When the real time OS is put to use the developed software consists of small program modules called tasks Therefore increased software maintainability is provided because de veloped 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 crocom
133. k e Delete messagebuffer del mbf Deletes a messagebuffer with the ID specified by a task Send message snd mbf tsnd mbf Transmits a message to the messagebuffer Namely a message is copied to the message buffer The messages transferred to the messagebuffer come in varying sizes Depending on the free space in the messagebuffer messages may be or may not be transferred If the free space in the messagebuffer is insufficient the message is kept waiting for transmission See Figure 3 33 Message Task A Message copy OK gt free block Task B Message copy NG Message buffer Send message wait Figure 3 33 Send Message e Send message psnd_mbf Transmits a message to the messagebuffer The difference with snd mbf and tsnd mbf is that when the free space in the messagebuffer is insufficient this system call returns error code without keeping the message waiting for transmission 37 An error code E TMOUT is returned 3 5 MR32R Kernel Structure 49 Receive message rcv mbf trcv mbf Receives a message A message is retrieved from the messagebuffer If no message exists in the messagebuffer this system call goes to a receive wait state When a message is received from the messagebuffer the free space in the messagebuffer increases that much If there is any task kept waiting for transmission and the size of the message to be transmitted by that task is smaller than the free space in the messageb
134. k operations such as task start stop and task pri ority updating The MR32R kernel offers the following task management function system calls Creates a task cre tsk Creates a task having an ID some other task appoints e Delete aTask del tsk Deletes a task having an ID some other task appoints The state of the task deleted is Switched from dormant to nonexistent and releases the stack area e Terminates and deletes a task itself exd tsk Puts a task itself to normal termination and deletes it That is puts a task itself in the nonex istent state and releases the stack area e Starting the Task sta tsk Starts the task changing its status from DORMANT to either READY or RUN e 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 e 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 terminates 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 3 5 MR32R Kernel Structure ter tsk B sta tsk B Figure 3 18 35 TaskB Terminated Reseting TaskB Task Resetting Changing the Task Prior
135. l Set ipl When using a timer X sys timer init in ipl ms is called and the initialization for the timer is performed O Os 0100 001 aa O01 O1 ROO JAI NR ALE XY amp USE TIMER gt 0 bl Sys timer init AENDI 62 global _ init abort 163 BL Lnst abort 164 1di r4 2 L65 166 167 Start task 168 169 70 An initial starting task is started 71 Please do not change this portion 72 73 start task 74 1d24 r5 4 D INIT STARI 2 75 add r5 r4 76 lduh r1 r5 FL beqz rl start task end 78 ldi v2 NULL 179 ldi rO ISTA_TSK 180 TRAP 8 181 addi r4 2 182 bra start_task 183 184 start task end 185 1di r5 NULL 186 1d24 r4 f4t enq dsp 187 stb r5 r4 188 bra Start up exit 189 190 Please do not change this portion 191 174 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 24 24 24 24 24 24 24 24 24 24 250 291 252 253 254 255 256 o 0 100145 CQ NR oO AIF section align 4 Chapter 8 How to Customize XY amp Dbg_flg eq 0 K MR_KERN global __Dbg_idle global Dbg RUNtsk EL code align 4 Dbg int entry Dbg int exit global Dbg ent handler Dbg ext handler Dbg int exit2 global Dbg sys exit
136. l value is carried out RAM C RAM C This macro is defined by mr32r inc and a user can also use it freely EAR RO R1 R2 sbss start sbss end EAR RO R1 R2 bss start bss end It transmits to a built in RAM area from an external ROM area A user can also use this broad view freely DOWNLOAD DOWNLOAD DOWNLOAD RO RI RZ R3 mr rom start mr rom end rom mr rom RO R1 R2 R3 data start data end rom data RO R1 R2 R3 sdata start sdata end rom sdata The standard library of the C language is initialized initialize C language library global bl bl init mem init stdio OS INIT init mem init stdio OS is initialized OS INIT Initialize OS system area INITIALIZE The initializa if 1d24 1d24 stb endif tion fot the OS debugging function is performed Dbg_flg rl ro Dbg buffer start Dbg addr r1 er0 ri ro Dbg cnt 0 r0 rl rl Dbg mode r0 rl TZ 1 r0 r2 r0 rl Set ipl in ipl ms is called and the initial cofiguration of an interrupt priority level is performed bl When using a Set ipl timer sys timer init in ipl ms is called and the initialization for the timer is performed ifdef bl endif bl US TIMER Sys timer init init abort 178 125 5 126 Start task Ld 128 130 Please do not chan
137. lained here As for the details of how to describe linker scripts see the documents attached to the DCC M32R 194 Chapter 8 How to Customize 8 3 5 Sample Linker Script 1 2 m32r cmd Linker script for M32R 3 m32r cmd 1 0 2000 05 18 4 Id m32r cmd v 1 2 2001 04 18 06 24 30 inui Exp 5 6 7 Memory Layout gi This layout is just example Applying this example it 9 is able to check a linking process exactly E or ex 11 12 13 Define the size and start address of each area such as in roml and in rom2 14 1 5 16 MEMORY 17 18 in roml1 org 0x0 len 0x10 19 in_rom2 org 0x40 len 0x40 20 in rom3 org 0x80 len 0x10 21 in_rom4 org 0x100 len Ox3fff00 22 in_raml org 0xf00000 len 0x10000 23 out_raml org 0x1000000 len 0x400000 24 25 26 Section Layout 27 287 E lt section name gt lt placed in gt lt placed in while executing gt 29 x reset ROM ROM 30 EIT Vector ROM ROM 3k Int Vector ROM ROM Su c text ROM ROM 39 K data ROM RAM 34 bss RAM RAM 35 heap RAM RAM 96 7 9 spu stack RAM RAM aq Spi stack RAM RAM 38 39 40 Section arrangement is performed 41 42 SECTIONS 43 44 GROUP 45 RESET VECT EIT Vector 46 gt in_roml 47 48 GROUP 49 EIT Vector EIT Vector 5O gt in_rom2 51 52 GROUP 53 Int Vector
138. ll is allocated from this dynamically creating variable size memorypool area O Dynamically creating variable size memory pool area definition external RAM lt lt Format gt gt ext memmpl y max memsize Maximum size of variable size memorypool to be created all memsize Size of dynamically creating variable size memorypool area external RAM lt lt Content gt gt 1 Maximum size of variable size memorypool to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of variable size memorypool size among those created by issu ing the cre_mpl system call For this value specify the largest size among variable size memorypools for which external RAM has been specified 2 Size of dynamically creating variable size memorypool area external RAM Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating variable size memorypool area The area of the specified size here is necessary to allocate a variable size memorypool area external RAM when issuing the cre_mpl system call A size of memory required for the variable size memorypool specified by the cre_mpl system call is allocated from this dynamically creating variable size memorypool area System Clock Definition Procedure lt lt Format gt gt System Clock Definition clock timer
139. lock e Referencing the memory pool size ref mpl References the aggregate size of blank areas in the memory pool and the maximal blank area size immediately acquirable 3 5 MR32R Kernel Structure 63 3 5 12 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 MR32R kernel makes an exclusive use of one M32R Family microcomputer hardware timer as the system timer The configuration file is used to determine which timer is to be employed as the system timer The MR32R kernel offers the following time management system calls Placing a task in wait state for certain time dly_tsk Keeps a task waiting for a certain time Figure 3 44shows an example in which task execution is kept waiting for 10 ms by the dly_tsk system call dly tsk 10msec Task o eS ee se 10msec Figure 3 44 dly tsk system call You can specify time out value for the system call below tslp tsk twai flg twai sem trcv msg tsnd mbf trcv mbf tcal por tacp portget blf tget blk If the time elapses without the wait cancellation condition being satisfied an error E TMOUT is returned and the wait state is canceled If the wait cancellation condition is satisfie an error E OKis returned A unit of time out value is the tick of MR32R s
140. lowing is entered in a program the programmer is constantly re quired 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 MR32R provides means of specifying the task by name function or symbol name The program named configurator cfg32r which is supplied with the MR32R then automatically converts the task name to the task ID number This task identification system is schematized in Figure 3 11 sta tsk Task name Starting the task having the designated cupro m gt ID number 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 should also be noted that task name to ID number conversion is effected at the time of program generation Therefore the processing speed does not decrease due to this conversion feature 20 Chapter 3 Introduction to MR32R 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
141. lt length i 107 while SIO0STS amp 0x0001 108 SIOOTXB message 109 110 111 10 nd 0 10 01 COO r2 OO i000 JO O1 iS CO IND O dd Ad 01010101010101 01 01 O1 4S PHP ds ds ds uS ds ds uS Y C C C C CO CO CO CO CO PO PO PO PO PO PO PO PO PD OD Nr 0 00 0 1O0 01 C Fr C 000 1001 CO Or 0 000 10 01 4S CO PO Ir OO 000 12 OY O1 4S Q0 PD ES O 10 1 Sample Program 1 3 Configuration File J BRK KK kk kk kk kk kk kk kk kk kk kk Ck Ck kk kk Ck Ck kk kk kk kk kk kk c kk k ck k ck k ck k ck k ck k ck k ck k ck ck ck ck ck ck ck ck oko ITSUBISHI ELECTRIC CORPORATION ELECTRIC SEMICONDUCTOR APPLICATION ENGIN ERING CORPORATION Exp J RK KK kk kk kk kk kk kk kk kk kk kk I kk kk kk kk Ck RRA RRA ck k ck k ck k ck k ck k ck k ck k ck ck ck k ck ck ck I kk Copyright 2001 AND MITSUBISHI F Tf MR32R System Configuration File smp cfg ff SId smp cfg v 1 2 2001 04 18 06 24 29 inui system stack_size 0x1000 priority 4 exc_handler NO debug NO debug_buffer 0 y Ll maxdefine max_task 137 max_int 32 max_alh 1 clock mpu clock 33 3MHz hf IPL 3 unit_time 100ms mode OTHER mode MFT00 file name m32102 tpl initial time 0 0 0 y Ll task entry_address main stack_size 0x1000 stack_area INTERNAL priority 1 initial_start
142. 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 7 2 Configurator Execution Procedures 149 7 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 ms or s in the current directory respec tively to be the C language and the assembly language files the configurator examines the dependency relationship of the files to be included by those Consequently observe 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 ms or s for the assembly language source file 2 Write the file dependency relationship to makefile Using makefile or Makefile in the current directory or makefile ews or makefile dos in the directory indicated by the environment variable LIB32R as a template file the configu rator creates makefile in the current directory 150 Chapter 7 Using Configurator 7 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 d
143. more Specify the maximum value of messagebuffer size among those created by issuing the cre_mbf system call For this value specify the largest size among messagebuffers for which external RAM has been specified Size of dynamically creating messagebuffer area external RAM Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating messagebuffer area The area of the specified size here is necessary to allocate a messagebuffer area external RAM when issuing the cre_mbf system call A size of memory required for the messagebuffer specified by the cre_mbf system call is al located from this dynamically creating messagebuffer area Dynamically creating fixed size memory pool area definition internal RAM lt lt Format gt gt int_memmpf y max_memsize Maximum size of fixed size memorypool to be created all memsize Size of dynamically creating fixed size memorypool area internal RAM lt lt Content gt gt 1 2 Maximum size of fixed size memorypool to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of fixed size memorypool size among those created by issuing the cre_mpf system call For this value specify the largest size among fixed size memory pools for which the internal RAM has been specified Size of dynamically creating fixed size memorypool area internal RAM
144. mpf the maximum number of fixed size memorypools defined max mpl the maximum number of variable size memorypools defined max cyh the maximum number of cyclic handlers defined max alh the maximum number of alarm handlers defined max int the maximum number of interrupt handlers defined The maximum number of OS objects must be defined when the system call which generate a task or OS objects cre xxx 7 1 Configuration File Creation Procedure 129 lt lt Contents gt gt 1 The maximum number of tasks defined Definition format Numeric value Definition range 1 32767 Define the maximum number of tasks defined 2 The maximum number of eventflags defined Definition format Numeric value Definition range 1 32766 Define the maximum number of eventflags defined 3 The maximum number of mailboxes defined Definition format Numeric value Definition range 1 32766 Define the maximum number of mailboxes defined 4 The maximum number of semaphores defined Definition format Numeric value Definition range 1 32766 Define the maximum number of semaphores defined 5 The maximum number of messagebuffer defined Definition format Numeric value Definition range 1 32765 Define the maximum number of messagebuffer defined 6 The maximum number of rendezvous defined Definition format Numeric value Definition range 1
145. n Internal RAM External RAM Mailbox Management Area dynamic creation Internal RAM Message buffer Management Area dynamic creation Internal RAM External RAM Fixed size memorypool Management 68 68 72 72 External RAM 72 72 72 Internal RAM This is the value defined in the maximum item definition of the configuration file If this item is not defined it means the value staticaly defined in the configuration file 721t is secured when dynamic generation of OS objects cre tsk del tsk cre mbx is used 204 Chapter 9 Application Creation Guide Area dynamic creation 72 External RAM Variable size memorypool Manage 72 Internal RAM ment Area dynamic creation 72 External RAM Note System management area is always secured If you specify the maximum number definition for other items as 0 or you omit the maximum number definition the area of corresponding items is not secured For example If you specify max sem 0 and does not define semaphore the Semaphore management area does not use any memory Table 9 2 The Size of MR ROM Section Area Name Bytes 4 bytes alignment regulation is needed for each section System time Management Area 6 System Management Area Initial start task 1 x2 Task Management Area 16 x maximum task Eventflag Management Area maximum eventflas 1
146. n 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 MR32R 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 MR32R kernel offers the following Fixed size memorypool management system calls e Creates a fixed size memorypool cre mpf Creates a fixed size memorypool having an ID some other task appoints e Deletes a fixed size memorypool del mpf Deletes a fixed size memorypool having an ID some other task appoints e Get memory block get blf tget_blf Acquires a memory block from the fixed size memorypool of the specified ID If no free memory block exists in the specified fixed size memorypool the task that issued this system call goes to a wait state so it is queued up in the wait queue e Get memory block pget bif Acquires a memory block from the fixed size memorypool of the specified ID The difference with get blf and tget blf is that when no free memory block exists in the memorypool the issuing task only returns error code without going to a wait state M emory Block 1 TaskA aos Memory block acquisition M emory Block 2 request Memory Block 3 Memory block acquisition Memory block acquisition request th
147. name gt gt Ink32R sub in the library appointing line An example is given below that appoints smp lib held in the director smp32r lnk32r sub makefile echo o PROGRAM gt 1nk32R sub echo L LIB32R gt gt 1nk32R sub echo 1 c32Rmr lib gt gt lnk32R sub echo 1 mr32R lib gt gt lnk32R sub Here follow steps to appoint a library Appoint a library path echo L c mtool mr32r smp32r gt gt lnk32R sub echo 1 smp lib gt gt lnk32R sub 8 4 2 Using D CC M32R Here you edit makefile the configurator generated and set compilation options libraries and so on The procedure for setting them is given below 1 DCC command options You define command options of the C compiler in CFLAGS Be sure to define the c op tion 2 DAS command options You define command options of the assembler in ASFLAGS 3 DLD command options You define command options of the linker in LDFLAGS 4 Specifying libraries To appoint a library first put echo L library path gt gt tmp cmd in the library path line Next put echo library name gt gt tmp cmd in the library appointing line An example is given below that appoints smp lib held in the director smp32r 198 Chapter 8 How to Customize PROGRAM x S ALLOBJS makefile m32r cmd echo LDFLAGS gt tmp cmd Specify library Specify library path echo L c mtool mr32r smp32r gt gt tmp cmd echo 1 smp lib gt gt tmp cmd echo LDFLAGS g
148. nce 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 y 2 At the beginning of file be sure to include mr32r h which is in system directory as well as id h which is in the current directory That is be sure to enter the fol lowing two lines at the beginning of file include mr32r h 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 is necessary to describe ext_tsk at the exit of task start function 6 It is also possible to describe the task startup function using the infinite loop include lt mr32r h gt include id h void task void process Figure 5 1 Example Infinite Loop Task Described in C Language 5 1 Program Coding Procedure in C Language 83 include lt mr32r h gt include id h void task void for 77 process Figure 5 2 Example Task Terminating with ext_tsk Described in C Language 7 When designating a task use a character string consisting of ID and task func tion name wup tsk ID main 8 When designating an eventflag semaphore mailbox or memorypool use a char acter string consisting of ID and the name defined in the configuration file Suppose that the eventflag is def
149. ng is initiated after the system returns to the interrupted system call process ing See Figure 9 2 TaskA OS Interrupt handler wup tsk SaveRegisters SP System WM Interrupt Save Registers iset flg Restore Registers system call processing Task selection ret int SP lt User Restore Registers TaskB Figure 9 2 Processing Procedure for a System Call from a Handler that caused an interrupt during System Call Processing 202 Chapter 9 Application Creation Guide 9 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 system 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 9 3 TaskA Interrupt handler A Interrupt handler A Interrupt Save Registers OS SP lt System Save Registers Interrupt System call processing Restore Register Restore Register Task selection ret int SP lt User Restore Registers
150. nition format Numeric value Definition range 0 or more Specify within an application program the maximum memory block size to be allocated 3 Variable size Memorypool location Definition format Symbol Definition range MR INTor MR EXT Specify the location of the variable size memorypool Specifically this means specifying whether you want the variable size memorypool to be located in the internal RAM or in ex ternal RAM Tolocate the variable size memorypool in the internal RAM 7 1 Configuration File Creation Procedure 139 Specify MR INT Tolocate the variable size memorypool in external RAM Specify MR EXT If this item is omitted MR INT is set by default 4 Memorypool size Definition format Numeric value Definition range 192 or more Specify a memorypool size The numerical value you specify will be rounded to a multiple of four O Cyclic handler definition lt lt Format gt gt Cyclic Handlar Definition cyclic_hand ID No interval_counter Intervals mode Mode entry_address Start address y The ID number must be in the range of 1 to 32767 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 Defi
151. nition of a configuration file in the INTERRUPT VECTOR or the INTERRUPT VECTOR section the head label is defined by _ INT_VECTOR For example when max_int 63 is specified the area of 64 is prepared from the interrup tion factor number 0 to the factor number 63 Moreover the entry address of the interrupt handler corresponding to the item of an interrupt factor number in interrupt handler definition of a configuration file is outputted For example when it is specified as interrupt vector 16 sys timer the label of Sys timer is embedded for the entry of the interruption factor number 16 Therefore the entry address of the interrupt handler corresponding to a factor number can be acquired by 8 1 Interruption Control Program 157 reading INT VECTOR an interruption factor number e RESTORE IPL from STACK The interruption status saved on the stack is restored and it returns to OS processing shown as Figure 8 1 The stack status of interrupt control program This routine is called from OS interruption entry processing shown by Figure 5 8 Example of interrupt handler when interruption occurs X set ipl An interruption mask level is set up This routine is called from a start up routine e Int Dummy This routine is called when interruption which is not registered as an interrupt handler occurs e _ SYS DUMMY This routine is called when the system call defined as not using it by system call definition
152. nition range 1 to 65535 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 system clock definition item If the system clock s unit time is 10 ms and you want the cy clic handler to be activated at 10 second intervals for example the intervals here must be set to 1000 2 Mode Definition format Symbol Definition range TCY_ON or TCY_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 140 Chapter 7 Using Configurator 3 Start Address Definition format Symbol or Function Name Definition range None Define the start address of the cyclic handler O Alarm handler definition lt lt Format gt gt Alarm Handlar Definition alarm hand ID No time Startup time entry address Start address y The ID number must be in the range of 1 to 32767 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 1 Startup time Definition format Time of da
153. ns equipment test and measurement equipment audio and visual equipment home electronic appliances machine tools personal electronic equipment and industrial robots High Quality Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems safety equipment and medical equipment not specifically designed for life support Specific Aircraft aerospace equipment submersible repeaters nuclear reactor control systems medical equipment 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 conditions Fur
154. nsmitted to the receiving task Copy sOy M essagebuffer Message Nee ae i Message TaskA Tb Figure 3 31 Messagebuffer As shown in Figure 3 31 the messagebuffer has messages stored in it in the same way as with the mailbox The stored messages are retrieved sequentially in order of FIFO When sending a message using message buffer functions M3T MR32R writes 4 byte size informa tion first and then the message body into the ring buffer If the previously transmitted message did not end at a 4 byte boundary the size info of the message next to be sent is written from the next 4 byte boundary So a transmit message consumes alignment adjust 4 byte size info message body in bytes in the buffer memory Note that no receive messages contain size information 3 5 MR32R Kernel Structure 47 Example When message B of 12 bytes wide is sent after message A that was not completed at a 4 byte bound ary the size info of message B is first written from the next 4 byte boundary and then the body of message B is written successively Alignment adjust plus 16 bytes Message Message B A 12 bytes The beginning of the buffer area hee e L means alignment adjust area Figure 3 32 The example of send message 48 Chapter 3 Introduction to MR32R There are following messagebuffer system calls that are provided by the MR32R kernel Create messagebuffer cre mbf Creates a messagebuffer with the ID specified by a tas
155. nt_Vector 80 MR_KERNEL 100 MR_KERNEL2 START_UP OS _DEBUGP D C MR_ROM INTERRUPT_VECTOR MR_RAM 0F00000 MR_ROM INTERRUPT_ VECTOR MR_Dbg_RAM SYS_STACK INT_USR_STACK MR_HEAP B D EXT_MR_RAM 1000000 EXT_USR_STACK EXT_MR_HEAP 7 CC32R User s Manual discribes details 186 Figure 8 5 Chapter 8 How to Customize H 00000000 RESET VECT EIT Vector H 00000040 H 00000080 lint Vector MR KERNEL MR KERNEL2 START UP OS DEBUG ROM D H 00000100 ROM MR ROM ron wrennuer_vecron H OOF00000 MR RAM EXT MR RAM EXT USR STACK EXT MR HEAP H 01000000 The memory image of a sample section file 8 3 Customizing the Section File 187 8 3 2 Using TW32R To lay out memory you use the linker script m32r cmd that comes with the MR32R This file is used when executing the linker m32r elf Id Symbols defined in the MR32R and the contents of the sample files attached to the product are explained here As for the details of how to describe linker scripts see User s Guide attached to the TW32R or the on line documents as to the linker m32r elf Id Symbols defined in the linker scripts e EIT OF RAM Stands for the start address of the area to be used by TRAP Subject to invariance e Int OF RAM Stands for the start address of the interrupt vector area START OF RAM Stands for the start address of the RAM area assigned no initial values START OF MR RAM Stand for the start address of the bu
156. nui Exp LAGOOEASOR EAE AIR IIA ROGER IIA IR AAR O 10 11 12 include mr32r inc 13 Section MR KERNEL ax 14 15 equ ICULSTS OxOOF7F004 16 equ ICUIMASK OxO00F7FO1C 17 equ MFTCR 0x00F7CO000 18 equ MFTMOD 0x00F7C080 19 equ MFTOS 0x00F7C088 20 equ MFTRLD 0x00F7C08C 24d equ ICUCR 0x00F7F23C 22 equ _ write bit 0x8000 23 equ ena bit 0x0080 24 25 equ timer count 0x6596 26 equ timer div 0x3 27 28 Use the label __sys_timer_init 29 __sys_timer_init to initialize the timer is called from the startup routine stmr_ipl stmr src stmr ent Sys time stmt air ase do not change this portion 1 The initial cofiguration of the timer used for the system clock of OS is 30 at the time when the timer is used 31 ifdef USE TIMER 32 global Sys timer init 33 global D Sys TIME H 34 35 sys timer init 36 37 Initialize the system time Pl 38 st R14 R15 39 1d24 R4 __D_Sys_TIME_H 40 ldh R5 R4 41 1d24 R6 __Sys_time 42 sth R5 R6 43 1d24 R4 __D_Sys_TIME_L 44 ld R5 R4 45 st R5 2 R6 46 47 48 performed 49 50 1d24 R10 4 timer count 51 ldi R12 4 timer div 52 MFT control register setting 53 1d24 rl MFTCR 54 ld r0 rl 55 1d24 r2 __write_bit 56 or TO EZ a st r0 rl 58 MFT mode register setting 59 1d24 rl METMOD 60 1d24 r0 0x8000 61 or TO EL2 62 st r0 rl 162 Chapter 8 How to Customi
157. of a configuration file is used 6 6 R5 R4 2 5 Handler address R14 4 IMASK IMASK 1 SAVE IPL to STACK RESTORE IPL from STACK Figure 8 1 The stack status of interrupt control program 7 As for interruption of the interruption factor number which is not registered as an interrupt handler Int Dummy is embed ded on an interrupt handler address table 158 Chapter 8 How to Customize 8 1 2 Interrupt Control Program for CC32R 1 ARA RIERA OK OR KEE SDN AREA RSS NR KERRE RREK ode RREK KONG IRS de S o eoe AE RON Ee 2 3 Copyright 2001 MITSUBISHI ELECTRIC CORPORATION 4 and MITSUBISHI ELECTRIC SEMICONDUCTOR APPLICATION ENGINEERING CORPORATION 9 All Rights Reserved 6 3 3 Id ipl ms v 1 2 2001 04 18 06 24 29 inui Exp o A A E E E pet E E E E A A A AAA 10 11 include mr32r inc 12 Section MR KERNEL code 13 14 ICUISTS equ OxOOEFFO004 15 ICUIMASK equ OxOOEFFO1C 16 MFTCR equ 0xOOEFCOOO0 17 MFTMOD equ Ox00EFC100 18 MFTRLD equ Ox00EFC10C 19 ICUCR equ Ox00EFF23C 20 write bit equ 0x8000 21 ena bit equ 0x0080 22 _ timer div equ 0x3 23 timer count equ 0x6596 24 25 global Sys timer init stmr ipl stmr src stmr cnt 26 global D Sys TIME H Sys time stmr ctr 27 global D Sys TIME L 28 29 30 Use the label sys timer init 31 sys timer init to initialize the timer is
158. ollar and underscore begins with a non numeric character and ends with The following shows an example of a function name written in the C language e main e func When written in the assembly language the start label of a module is assumed to be a func tion name Frequency ime The frequency is indicated by a character string that consist of numerals and period and ends with MHz The numerical values are significant up to six decimal places Also note that the frequency can be entered using decimal numbers only Frequency entry examples are presented below e 16MHz e 8 1234MHz It is also well to remember that the frequency must not begin with period The time is indicated by a character string that consists of numerals and period and ends with ms or s The time values are effective up to three decimal places when the character string is terminated with ms or up to six decimal places when the character string is termi nated with s Also note that the time can be entered using decimal numbers only 118 Chapter 7 Using Configurator e 0 23s e 10ms e 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 numbers joined with colon as shown in the example below 23 0x02 100B If one or two high order numbers of a total of three num
159. on item XXXX is omitted in the configuration file cfg32r Warning task x XXXX is not defined near line 32 test cfg The task definition item XXXX in ID number is omitted cfg32r Warning Already definition XXXX near line 20 test cfg XXXX has already been defined The defined content is ignored check to delete the extra definition cfg32r Warning specified variable memorypool max memsize 120 test cfg cfg32r specified max memsize of the variable size memorypool as 120 because you speci fied less than 120 cfg32r 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 cfg32r Warning interrupt vector x s default is not defined near line 213 test cfg The interrupt vector of vector number x in the configuration file is not defined in the default configuration file cfg32r 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 Other messages The following message are a warning message that is output only when generating makefile The configurator skips the sections that have caused such a warning as it generates makefile test c line 11 include format error The file read format is incorrect Rewrite it to the correct format cfg32r Warning test c line 12 can t find lt XXXX gt cfg32r
160. out 46 47 lt section name gt lt placed in gt lt placed in while executing gt 48 reset RO RO 49 EIT Vector RO RO DU Int Vector RO RO gl text RO RO 52 rodata RO RO Does data RO RA 54 Sdata RO RA DOY E Sbss RA RA 56 bss RA RA 34 5 vh heap RA RA Dg e spu stack RAM RAM 59 Spi stack RAM RAM 60 61 62 SECTIONS 63 64 T 65 66 67 68 69 70 T1 72 73 74 75 76 77 78 T9 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 8 3 Customizing the Section File d SE NNNHE res reset RESE F IT_OF_ROM NT_OF_ROM 0 0x40 0x80 _OF_ROM 0x100 OF RAM 0xf00000 Jul A A A F OF EXT Location counter is set to R ESET RAM 0x1000000 189 he symbol which determines memory allocation is defined ESET t vector sections The s T RESET VECT EIT Vector tart address of EIT OF ROM eit start me EIT Vector _ eit end 0 PROVIDE EIT Vector The s Int Vector INT OF ROM Int start Int Vector Int end
161. pointer connection pointer Rendezvous wait bit pattern Exception Mask Figure 3 15 TCB Task control block TCB 27 28 Chapter 3 Introduction to MR32R 3 4 Handler Difference between Tasks and Handlers The tasks are program units that the MR32R executes and controls Each task has its own independ ent context program counter stack pointer status register and other registers Therefore to transfer execution from one task to another 27 it is necessary to effect context switching This processing operation takes time Interrupt processing which requires high speed response can be carried out by the MR32R 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 han dler uses the interrupted task context registers as is it is always necessary to save the interrupted task context into memory at the beginning of the handler and put the saved context back into the original position when returning to the task 1 Interrupt Handler A program that starts upon hardware interruption is called the interrupt handler MR32R ac tivates interrupt handler after interrupt entry process Interrupt entry process is done in the MR32R kernel So you can only register interrupt handlers in the configuration file 2 Cyclic Handler This handler is a program that starts cyclically at preselected time intervals The cycl
162. port for rendezvous is specified in a program 136 Chapter 7 Using Configurator O Mailbox definition with priority lt lt Format gt gt Mailbox Definition vmailbox ID No name Name wait_queue The order of receiving message message queu The order of sending message maxpri Maximum priority of mailbox messages Hu The ID number must be in the range of 1 to 32765 The ID number can be omitted 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 in a program 2 Name Definition format Symbol Definition range None Define the name with which a mailbox is specified in a program 3 The order of receiving message Definition format Symbol Definition range FIFO or PRI Specify the order of receiving message e FIFO Connects the task in FIFO order e PRI Connects the task in priority order If this item is omitted FIFO is set by default 4 The order of sending message Definition format Symbol Definition range FIFO or PRI Specify the order of sending message e FIFO Connects the message in FIFO order e PRI Connects the message in priority order If this item is omitted FIFO is set by default 5 The maximum priority of messages Definition format Numeric Value Definition range 1 255
163. preq_sem NO 121 isnd_msg YES 122 prcv_msg YES 123 set_tim NO 124 get_tim NO 125 act_cyc YES 126 get_ver NO 127 ret_int YES 128 129 130 131 132 133 134 135 136 137 10 1 Sample Program dis_dsp NO loc_cpu NO ext_tsk YES exd_tsk NO y interrupt_vector 16 __sys_timer End of Configuraton 213 214 Chapter 10 Apendex Index A Accept Rendezvous QUEUE 23 ap PO RE 52 lado jc 64 alarma dla prre rr 86 Alarm Handler ssseeseenenneenn 28 Alarm handler definition sessss 140 alarm handlers ssseeeeeenee 91 AND Wallet erectae en T ee TR 40 ASBQR E aiaia e aa A e aE i 197 C CAL PON cipi c p a REP 51 Call Wait Queue seem 23 Cari WUD estetica te id iens 38 CC32 Ri eit oem Deben fet eed adia ir NIETS 8 197 a ob YA t 19 A esr etr enmt ene 34 Clear specification 40 CLT une cat cerro eter e rie Ferr rera ust 40 configuration file eene 142 configurator eect tees 19 80 147 148 150 A Ee RU RN ient 40 CEG mDf a acne tee i rtr eri aec ta e 48 COL IMD gai Y 45 crectpf zou ea eae deg 57 A a ie tere ATTI Rr Reed 60 a m mu a a 51 cre sem i sec emen ede e e 42 Cre tele ii ooa etes ERE 34 cyclic handler i cene teme 86 Cydic Hand et sciatic rte e dit vec 28 Cyclic handler definition sss 139 cydic handlers ose
164. puter based products With the real time OS it is possible to decrease the number of unnecessary microcomputer operations such as l 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 MR32R 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 Saka mura at Faculty of Science University of Tokyo As one item of this TRON Project the ITRON Specification 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 require 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
165. r EIT Vector EIT vector section You must delete transferring process description in start up program if you must allocate this section on ROM Flash ROM area e Int Vector Int Vector Interrupt vector section You must delete transferring process description in start up program if you must allocate this section on ROM Flash ROM area Below is the procedure of cancel of transferring process 1 Delete needless section in start up program if using CC32R The sectios to be deleted are the sections added ROM letters to these section name ROM P ROM C etc 2 Delete DOWNLOAD MACROS of the section which is not transferred in start up program 3 Modify section file section or linker script m32r cmd See the cross tool manual how to modify section file or linker script 8 2 How to Customize the MR32R Startup Program 171 8 2 3 0 J3 0 014 QUO r2 OO i000 120 O1 iS CO IND ES BG 4S Y Y Y CO CO Y CO CO CO CO PO POPO PO PO PO PO PO PO PO Nr 0 000 1O0 01 5 C 0r C 000 10 01 i C0 I RO 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 Startup Program for C Language for CC32R crtOmr ms PRR RRR RRR KR ERR KKK KERR KEK KKK KK RK KKK KKK KK RK KEK KKK KK RK KEK KKK KK EK kc kk ke ke kc ke koc ke ke ke ke ke ke ke ke MR32R start up program for C language for CC32R Copyright 2001 and MITSUBISHI ITSUBISHI EL ECTRIC CORPORATION T ELECTRIC SE All Rights
166. r tasks are not switched over until delayed dispatch is cleared The task to be executed after delayed disabled dispatch is re enabled is linked to the ready queue rot rdq irot rdq during delayed dispatch When rot rdq TPRI RUN 0 is issued during delayed dispatch 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 al ways be linked to the ready queue Such as when isus tsk is issued to the executed task during delayed dispatch 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 or loc 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 issuing dis dsp several times The above status transition can be summarized in the table below 6 2 Regarding Initially Activated Task Table 6 1Interrupt and Dispatch Status Transition by dis dsp and loc cpu Status Contents of Statusdis dis dsp is ena dsp loc cpu is unl cpu is No Interrupt Dispatch executed is exe executed executed cuted 1 Enabled Enabled 2 1 3 gt 1 Enabled Disabled gt 2 gt 1 gt 3 gt 1 3 Disabled Disabled x x 3 1
167. r Slavemode initialize Power management initialize B9 s 100 101 The zero clearance of the data without initial value is carried out 102 This macro is defined by mr32r inc and a user can also use it freely 103 104 RAM CLEAR r0 r1 r2 B 105 106 It transmits to a built in RAM area from an external ROM area 107 A user can also use this broad view freely 108 109 DOWNLOAD r0 r1 r2 r3 D ROM_D 110 111 The standard library of the C language is initialized 112 3 T13 114 Initialize standard library LES 3 116 LAT global init mem init stdio 118 bl init mem 119 bl init stdio 120 121 global OS INIT 122 123 OS is initialized 124 OS INIT 125 126 DOWNLOAD r0 r1 r2 r3 MR ROM ROM MR ROM 127 DOWNLOAD r0 ri r2 r3 INTERRUPT VECTOR ROM INTERRUPT VECTOR 8 2 How to Customize the MR32R Startup Program 173 Initialize OS system area 128 129 130 131 132 INITIALIZE 183 134 The initialization fot the OS debugging function is performed 135 136 AIF XY amp Dbg flg gt O 137 1d24 rl t Dbg buffer start 138 1d24 r0 __Dbg_addr 139 st r1 r0 140 1d24 r1 __Dbg_cnt 141 idi roO 0 142 st r0 rl 143 1d24 rl t Dbg mode 144 ldb r0 rl 145 ldi r2 1 146 or LO 62 147 stb r0 rl 148 aendi 149 150 set ipl in ipl ms is called and the initial cofiguration of an interrupt priority level is performed b
168. r Start Procedure ient innata h hana ananas natat 148 7 2 4 makefile generate Function sienten inni n natn nana nata a anat a natant nh 149 7Z25 Precautions on Executing Conf guratar i siiis nni 150 7 2 6 Configurator Error Indications and Remedfes iii nnn 151 Error messages a datae fid 151 Warning Messages is ur epe it mto ird tp d 153 Other Messages rm 153 Chapter 8 How to CUSOMIZE nussii inniinn aeiaai aaa nnnm nnne nnne nnn aae n nnne nnns 155 8 1 Interruption Control Program sssessssseeeeeenneene ennemi enn nnns 156 8 1 1 Bythecontents interruption processing iiis aenean neta et att 156 8 1 2 Interrupt Control Program for COB2R iccessscsesssssnsscscssssenssesnsssssnssseusssssvssesnasseessessasss 158 8 1 3 Interrupt Control Program for T WR esent nnne annia nant 161 8 14 Interrupt Control Program for DOCM 32R sisse sene 164 8 2 How to Customize the MR32R Startup Program sssseeseeeeeeneen nennen 167 amp 21 Transferring the data to the built in DRAM from an external sess 168 82 2 HowtoStop Transmission to RAM from ROM ssi tnter innt 170 amp 23 Startup Program for C Language for CC32R art mr ms isis sene 171 824 Startup Program for C Language for TW32RJ art mr s esee 176 amp 25 Startup Program for C Language for DCC M 32R ICrtOMAS iociiociincinnicinicicicccinacnnrons 181 8 3 Customizing the Section File ennemi enn nnns 185 GBD USIN
169. r stack area internal RAM y lt lt Content gt gt 1 Maximum size of task stack to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of stack size among tasks created by issuing the cre_tsk system call or the exception handlers defined by def_exc For this value specify the largest stack size among tasks for which the internal RAM has been specified for use as the stack 2 Size of the task creating user stack area internal RAM Definition format Numeric value Definition range 192 or more Specify the size of the user stack area that is used to create tasks The area of the specified size here is necessary to allocate the stack area internal RAM for tasks that are required when creating the task A size of memory required for the stack specified by the cre_tsk system call is allocated from this user stack area Dynamically creating user stack area definition external RAM lt lt Format gt gt ext_memstk max_memsize Maximum size of task stack to be created all_memsize Size of the task creating user stack area external RAM y lt lt Content gt gt 1 Maximum size of task stack to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of stack size among tasks created by issuing the cre_tsk system call or the exception handlers define
170. r the system stack area Some inner members of the kernel the interrupt handlers and the like use this section This section must be allocated to RAM area e NT USR STACK Section This is user stack area in the internal RAM e EXT USR STACK Section This is user stack area in the external RAM e MR KERNEL MR KERNEL2 Section The OS s kernel uses this section MR RAM Section This is the internal RAM data area used by MR32R e EXT MR RAM Section This is the external RAM data area used by MR32R MR ROM Section This section is allocated for fixed data the OS uses This section must be transfer ROM area to RAM area when dynamic creation function is used e MR HEAP Section This is the internal RAM heap area used by MR32R This section used when using vali able size memorypool function e EXT MR HEAP Section This is the external RAM heap area used by MR32R This section used when using vali able size memorypool function e MR Dbg RAM This is the RAM area used by MR32R when OS debug function is used 6 10 Memory mapping 107 O Sections related to interrupt vectors int Vector Section ElT_ Vector Section This section is used for storing the EIT vector area RESET VECT Section This section is used for the reset vector area e NTERRUPT VECT Section This section is used for interrupt vector table This section must be transfer ROM area to RAM area when def int system call is used 108 6 10 2 Chapter
171. re is necessary to allocate a mailbox area internal RAM when issuing the cre_mbx system call A size of memory required for the mailbox specified by the cre mbx system call is allocated from this dynamically creating mailbox area O Dynamically creating mailbox area definition external RAM lt lt Format gt gt ext memmbx max memsize Maximum size of mailbox to be created Size of the dynamically creating mailbox area external RAM all memsize y lt lt Content gt gt 1 Maximum size of mailbox to be created Definition format Numeric value Definition range 1 or more Specify the maximum value of mailbox size among those created by issuing the cre_mbx system call For this value specify the largest size among mailboxes for which external RAM has been specified 7 1 Configuration File Creation Procedure 123 2 Size of the dynamically creating mailbox area external RAM Definition format Numeric value Definition range 192 or more Specify the size of a dynamically creating mailbox area The area of the specified size here is necessary to allocate a mailbox area external RAM when issuing the cre mbx system call A size of memory required for the mailbox specified by the cre mbx system call is allocated from this dynamically creating mailbox area Dynamically creating message buffer area definition internal RAM lt lt Format gt gt int_memmbf m
172. red by the rel wai or irel wai system call When the SUSPEND state clear request 17 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 possibly occur 17 rsm_tsk irsm tsk systemcall 24 Chapter 3 Introduction to MR32R 6 DORMANT This state refers to the condition in which a task is registered in the MR32R 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 7 NON EXISTENT The NON EXISTENT state is a state in which no task is registered in the MR32R system as it is before a task is generated or as it is after a task has been deleted A task if generated 2 is registered in the MR32R system and is put in the dormant state This state is brought in two instances given below Aninstance in which a task in the dormant state is deleted by another task a e Aninstance in which a task under execution terminates and deletes itself 1 ext tsk systemcall ter tsk systemcall cre tsk systemcall del tsk systemcall exd tsk systemcall 3 3 Task 25 3 3 2 Task Priority and Ready Queue In the real time OS several tasks may simultaneously request to be executed In such a case it is necessary to determine which ta
173. ref alm get ver ref sys def exc vclr ems vset ems vras fex vcre mbx vdel mbx vsnd mbx visnd mbx vrcv mbx vtrcv mbx vprcv m bx vrst mbx vref mbx O Interrupt vector definition lt lt Format gt gt Interrupt Vector Definition interrupt vector Vector No Start address lt lt Content gt gt 1 Start address Definition format Symbol or function name Definition range None Specify the interrupt handler s start address Put an interrupt factor number in square brack ets If you use system clock for MR32R you must define the system clock interrupt handler in cfg file as sys timer Ex interrupt vector 20 2 sys timer 142 Chapter 7 Using Configurator 7 1 3 Configuration File Example The following is the configuration file example Copyright c 1998 1999 MITSUBISHI ELECTRIC CORPORATION And MITSUBISHI SEMICONDUCTOR SYSTEMS CORPORATION MR32R Sample Configurator File I System Definition system stack_size 0x5000 priority 10 exc_handler NO y Max Definition maxdefine max_task D max flag 1 max_mbx Ts max sem Ls max mem ls max cyh 2 max alh T5 max int 16 y System Clock Definition clock timer_clock 33 3MHz IPL 4 unit time lms timer MFT00 file name m32102 tpl initial time 1 0x10ffff y Task Definition task 1 init
174. rformed 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 under 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 7 In the case presented in Figure 3 2 for instance the remote control microcomp
175. ribes the method for writing a configuration file and the method for using the configura tor in detail Chapter 8 How to Customize This chapter explains how to customize the startup file the interrupt control program section file and makefile so as to make them conform to a user s system e Chapter 9 Application Creation Guide Presents useful information and precautions concerning applications program development with MR32R Chapter 10 Apendex Describes the MR32R sample applications program which is included in the product in the form of a source file Chapter 2 General Information 4 Chapter 2 General Information 2 1 Objective of MR32R Development In line with recent rapid technological advances in microcomputers the functions of microcom puter based products have become complicated In addition the microcomputer program size has in creased Further as product development competition has been intensified manufacturers are com pelled to develop their microcomputer based products within a short period of time In other words engineers engaged in microcomputer software development are now required to de velop larger size programs within a shorter period of time To meet such stringent requirements it is necessary to take the following considerations into account 1 To enhance software recyclability to decrease the volume of software to be developed One way to provide for software recyclability is to divide softwar
176. ribute The information of whether the stack area of the task is allocated in internal RAM or in ex ternal RAM storage area e Extended information Extended information of the task storage area Task register information and other data storage stack area pointer current SP register value e Wake up counter Task wake up request storage area e Memory block size The request size of memory block storage area when the task is variable size memory bloc wait state e Rendezvous wait bit pattern For rendezvous calls the calling side select condition bit pattern is stored in this area When in an acceptance wait state the acceptance select condition bit pattern is stored in this area e Flag wait mode This is a wait mode during event flag wait e Wait flag pattern If in a flag wait state the flag s wait pattern is stored in this area Time out queue connection pointer Time out queue connection pointer used for time out queue formation Time out counter When a task is in a time out wait state the remaining wait time is stored Exception mask Stores an exception mask value This area is not allocated unless a forced exception handler is used The task control block is schematized in Flgure 3 15 2 Called the task context 2 Define whether forced exception handler is used or not in the system definition of the configuration file 3 3 Task TCB Extended information Task attribute Task connection
177. rnel area H 2000000 henceforth is shown in the following figure H 00000000 bra sram eit trap tbl It jumps in es Manor H OOF00000 jmp r0 __jmp_trap7 H 01000000 It jumps in over 16MB space H 02000000 bra SYSCALLO It jumps in OS kernel Figure 6 3 Allocate OS kernel to the over 16MB area 112 Chapter 6 Notes of developing user program 1 A start up routine is changed and the jump place of TRAP and El vector is changed global sram eit trap7 tbl sram eit trap8 tbl sram eit trap7 tbl 7 bra bra sram_eit_trap8_tbl Section Int Vector code align 4 st r0 0 r15 seth rO 4high jmp ei or3 r0 r0 tflow jmp ei jmp ro 2 The code for the 2nd step jump is added to a start up routine This section is arranged in 16MB space section section export ROM MR EIT code align 4 MR EIT code align 4 sram eit trap 7 tbl sram eit trap7 tbl SE seth or3 jmp export r0 0 r15 r0O t4high jmp trap r0 r0 tf 1ow jmp trap ro sram eit trap8 tbl sram eit trap8 tbl st seth or3 jmp r0 0 r15 r0 high _jmp_trap8 r0 r0 low _jmp_trap8 ro TRAP7 TRAP8 6 10 Memory mapping 113 3 The code for the 3rd step jump is added to a start up routine This section is taken as the same section MR KERNEL as OS kernel area Section MR KERNEL _jmp_trap7 AIF XY amp Dbg flg eq O global SYSCALLO id r
178. rs 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 When using any or all of the information contained in these materials including product data diagrams charts programs and algorithms 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 circumstances in which human life is potentially at stake Please contact Renesas Technology Corporation Renesas Solu tions Corporation or an authorized Renesas Technology product distributor when considering the use of a product contained herein for any specific purposes such as apparatus or systems for transportation vehicular medical aerospace nuclear or undersea repeater use The prior written approval of Renesas Technology Corporation and Renesas Solutions Corporation is necessary to reprint or reproduce
179. ry circuits ii use of nonflamma ble material or iii prevention against any malfunction or mishap Notes regarding these materials These materials are intended as a reference to assist our customers in the selection of the Renesas Technology product best suited to the customer s application they do not convey any license under any intellectual property rights or any other rights belonging to Renesas Technology Corporation Renesas Solutions Corporation or a third party Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage or infringe ment 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 Cor poration and Renesas Solutions Corporation without notice due to product improvements or other reasons It is therefore recommended that customers contact Renesas Technology Corporation Renesas Solutions Corporation or an authorized Renesas Technology product distributor for the latest product information before purchasing a product listed herein The in formation described here may contain technical inaccuracies or typographical erro
180. s TaskD No free block Fixed size Memorypool i WAIT state Figure 3 40 Fixed size Memorypool Management 58 Chapter 3 Introduction to MR32R e Releasing a Memory Block rel bif Releases the memory block obtainedby the task If there is a task being memory block alloca tion wait state rel blf system call allocates memory block to the task which is top of the queue In this case the task is moved to ready state Also If there is no task being memory block allocation wait state rel blf system call release memory block e Referencing the memorypool s status ref mpf References the number of blank blocks of the relevant memorypool and their sizes 3 5 MR32R Kernel Structure 59 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 MR32R manages memory in terms of four fixed size memory block sizes The MR32R calculates the size of individual blocks based on the maximum memory block size to be acquired You specify the maximum memory block size using the configuration file e g variable _memorypool 03 5403 0899 max memsize 400 Maximum size heap size 5000 y Defining a variable size memorypool as shown above causes four fixed size memory block sizes to become 60 bytes 120 bytes 240 bytes and 480 bytes in compliance with max_memsize In the case of user requested memory the
181. s as follows to a configuration file it will not become the shortage of a memory 6 5 The Use of TRAP Instruction 97 Description of a configuration file ext memstk max memsize all memsize 1024 1584 However if it describes in this way 304 bytes of useless memory area will be made In order to reduce a useless memory area it is necessary to adjust max_memsize For example it is set to max memsize 1048 then a 144 b 288 c 576 d 1152 demand size real use size useless size TaskA 256 288 32 TaskB 1024 1152 128 Total 1280 1440 160 If it does in this way it is possible to reduce useless size 6 4 2 A note on using dynamic generation deletion 1 By this system fragmentation may be generated although it has been hard coming to generate Therefore keep in mind that a memory block may not be allocated although there is size of enough of an empty memory area 2 A part for the memory size which specified the variable size memory pool generated by cre_mpl system call at the time of generation is not necessarily used A part for the size of the memory block which OS allocated is used as a memory pool area Therefore when the value specified as memory pool size by the configuration file is made into the argument of cre_mpl the memory pool size for which those who used cre_mpl are actually used may become large 6 5 The Use of TRAP Instruction MR32R has TRAP instruction interrup
182. s function keeps a task call and a task accept waiting each other through a window called the port and when rendezvous is established exchanges messages between the tasks Es tablishment of rendezvous means that when the AND ed result of the calling side bit pattern and re ceiving side bit pattern is not 0 rendezvous is assumed to have been established This function is useful for server and client implementation on the real time OS Rendezvous Task A established Task B call pattern 000 001 ARE Rende s e ZVOU accept pattern 001 001 acceptance 2CP_por Message transfer tacp_por Rendezvous m cal por call request inr tcal por pcal_por i i a End of rendezvous wait p es of rpl rdv rendezvous Message transfer result n Processing restarted Reply message Port Figure 3 35 Rendezvous There are following rendezvous system calls that are provided by the MR32R kernel e Create rendezvous port cre por Creates a rendezvous port with the ID specified by a task e Delete rendezvous port del por Deletes a rendezvous port with the ID specified by a task Make rendezvous call to port cal por tcal por Issues a cal por or tcal por system call to check whether rendezvous with the task in the acceptance wait state at the specified port will be established When rendezvous is estab lished a message is transferred to the task in the acceptance wait state and the task goes from the acceptance wait st
183. sk stack_area User stack area of task stack_area User stack section name of task priority Initial priority of task initial start Initial startup status The ID number must be in the range of 1 to 32767 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 at the beginning of the function name you have defined User stack size of task Definition format Numeric value Definition range 80 or more Define the user stack size for each task The user stack means a stack area used by each individual task MR32R requires that a user stack area be allocated for each task which amount to at least 80 bytes Also If the forced exception handler is defined for a task by this definition it needs further 96 The numerical value you specify will be rounded to a multiple of four Stack location Definition format Symbol Definition range MR INTor MR EXT Specify the location of the user stack Specifically this means specifying whether you want the user stack to be located in the internal RAM or in external RAM Tolocate the user stack in the
184. sk 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 quickly tasks related to processing operations that need to be performed immediately should be given higher priorities The MR32R permits giving the same priority to several tasks To provide proper control over the READY task execution order the system generates a task execution queue call ed ready queue The ready queue structure is shown in Figure 3 14 The ready queue is provided and controlled for each priority level The first task in the ready queue having the highest priority is placed in the RUN state Priority TCB TCB TCB 4 TCB TCB TCB il Figure 3 14 Ready Queue Execution Queue The TCB task control block is described in the next chapter 2 The task in the RUN state remains in the ready queue 26 Chapter 3 Introduction to MR32R 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 MR32R manages the following task information as the task control block e Task connection pointer Task connection pointer used for ready queue formation or other purposes Task status Task priority e Task att
185. spci fying its attibute as TA MPRI e Receive a message vrcv mbx vtrcv mbx vprcv mbx Receive a message The higher priority task can receive the message from the mailbox by spcifying its attibute as TA TPRI e Clears a mailbox vrst mbx Clears a mailbox e Referencing the mailbox s status vref mbx Checks whether tasks are present that are waiting for a message to be sent in the relevant mailbox and references the first message in the mailbox 3 5 MR32R Kernel Structure 69 3 5 16 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 2List of the system call can be issued from the task and handler System Call Task Interrupt handler Exception handler Cyclic handler Alarm handler cre tsk del tsk sta tsk ista tsk ext tsk exd tsk ter tsk dis dsp ena dsp chg pri ichg pri rot rdq irot rdq rel wai irel wai get tid ref tsk sus tsk isus tsk rem tsk irsm tsk slp tsk tslp tsk wup tsk iwup tsk can wup cre flg del flg set flg iset flg clr fig wai flg twai flg pol flg ref flg x OjlOlOoOjOo xjoo ojoxjooo ix joxooo ixj o ixo ixjo oooojo ix ooo OlO Ix Ix OJO x x x OIOIx x x O x Ox
186. ssssssseeseeeereneneen nnns 180 Figure8 4 Startup Program for C Language for DCC M 32R sss 184 Figure85 The memory image of a sample section file ssssseeenene 186 Figure8 6 The memory image of a sample linker script file sees 196 Figure9 1 Processing Procedure for a System Call a Handler that caused an interrupt during TaskExequtlon 3 aie eBlen dee hag eC ete c ROT CHR ee deeds 200 Figure9 2 Processing Procedure for a System Call from a Handler that caused an interrupt during System Call Processing sess nnne nnne nennt nnne nnns 201 Figure9 3 Processing Procedure for a system call from a Multiplex interrupt Handler 202 Figure9 4 System Stack and User Stack ssssssssssssessseeeeeeneen enne nene 205 List of Tables Table2 1 MR32R Specifications Overview ssssssssseseeeeeene enne enne enne 7 Table3 1 X System Calls Issuable from only Handlers sse 30 Table3 2 List of the system call can be issued from the task and handler 69 Table5 1 C Language Variable Treatment sse nne 84 Table6 1 Interrupt and Dispatch Status Transition by dis dsp and loc cpu 95 Table 6 2 Dynamic generation deletion system call list sssssseeeeeeee 96 Table6 3 Interrupt Number Assignment eene 97 Table7 1 Numerical Value
187. st R14 R15 handler process ld R14 R15 jmp R14 3 Figure 5 9 Example Cyclic Handler Written in Assembly Language Use the GLOBAL pseudo directive 92 Chapter 5 Detailed Applications 5 2 4 Writing Exception forced exception handler When writing exception handlers in the assembly language pay attention to the following 1 At the beginning of file be sure to include mr32r inc which is in the system di rectory For the symbol indicating the handler start address make the external declaration 3 Use the vret exc system call to terminate the handler 60 When the vret exc system call is issued processing is transferred to the task for which the exception handler was called The parameters passed to the exception handler at invocation have been set in the following registers Register Name Value RO T EXC pk exc R1 T REGS pk regs R2 T EIT pk eit include mr32r inc 1 global exc handler 2 exc handler handler process vret exc 40 J A7 3 Figure 5 10 Example exception handler Written in Assembly Language ext tsk system call can be issued when forced exception handler ends In this case the task corresponding to the forced exception handler is moved to DORMANT state Chapter 6 Notes of developing user program 94 Chapter 6 Notes of developing user program 6 1 MR32R has four system calls related to delay
188. sued from task can be issued from forced exception handler So If it needs task dispatching the forced exception handler is dispatched to other task MR32R supports the system calls of exception management function as below Starts a forced exception vras_fex Starts a forced exception handler for the specified ID number of the task Clears a forced exception mask vclr ems Clears a forced exception mask for the specified ID number of the task Sets a forced exception mask vset_ems Sets a forced exception mask for the specified ID number of the task Returns from the forced exception handler to the task vret exc Returns from the forced exception handler to the task Clears a mailbox vrst msg Clears a mailbox Clears a message buffer vrst mbf Clears a message buffer If there is the send wait state task its wait state is canceled and an error code EV RST is returned Resets a fixed size memory pool vrst blf Resets a fixed size memory pool If there is the wait state task its wait state is canceled and an error code EV RST is returned Resets a variable size memory pool vrst blk Resets a variable size memory pool If there is the wait state task its wait state is canceled and an error code EV RST is returned Forced exception handler only can bedefined The other exception handler cannot be defined 45 When a extraordinary is detected in the whole system 68 Chapter 3 Introduction to MR32R 3 5 15 Implem
189. t Content gt gt Define the name with which a messagebuffer is specified in a program 1 Name Definition format Symbol Definition range None Define the name with which a messagebuffer is specified in a program 7 1 Configuration File Creation Procedure 135 2 Messagebuffer location Definition format Symbol Definition range MR INTor MR EXT Specify the location of the messagebuffer Specifically this means specifying whether you want the messagebuffer to be located in the internal RAM or in external RAM Tolocate the messagebuffer in the internal RAM Specify MR INT Tolocate the messagebuffer in external RAM Specify MR EXT If this item is omitted _ MR INT is set by default 3 Maximum number of messagebuffer Definition format Numeric Value Definition range 0 or more Specify a messagebuffer size The numerical value you specify will be rounded to a multiple of four O Rendezvous definition lt lt Format gt gt Rendezvous Definition rendezvous ID No name Name e The ID number must be in the range of 1 to 32765 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the name with which a port for rendezvous is specified in a program 1 Name Definition format Symbol Definition range None Define the name with which a
190. t tmp cmd echo OBJS1 gt gt tmp cmd echo OBJS2 gt gt tmp cmd Chapter 9 Application Creation Guide 200 Chapter 9 Application Creation Guide 9 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 system call 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 Asystem call from a handler that caused an interrupt during task execution 2 Asystem 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 9 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 9 1 TaskA Interrupt handler OS Interrupt Save Registers system call processing iset flg Pd Restore Registers ret int Task selection TaskB Restore Registers Figure 9 1 Processing Procedure for a System Call a Handler that caused an interrupt during Task Execution Scheduler 9 1 Processing Procedures for System Calls from Handlers 201 9 1 2 System Calls from a Handler That Caused an Interrupt during System Call Processing Scheduling task switchi
191. t numbers reserved for issuing system calls as listed in Table 6 3 For this reason when using software interrupts in a user application do not use interrupt numbers 7 and 8 and be sure to use some other numbers Table 6 3Interrupt Number Assignment TRAP No System calls Used 7 System calls that can be issued from only task 8 System calls that can ce issued from only handlers System calls that can be issued from both tasks and handlers Reserved for future extension 98 Chapter 6 Notes of developing user program 6 6 Regarding Interrupts 6 6 1 Controlling Interrupts To enable or disable interrupts within a system call you manipulate the PSW s IE bit The IE bit within a system call has been cleared to disable interrupts Interrupts caused by the interrupt hander have been disabled In a situation in which every interrupt can be enabled the IE bit is re turned to the status as it was when a system call was issued Here follows the status of the interrupt enabling flag within a system call For system calls that can be issued from only task When thelE flag before issuing a system call is O Task or Task or Handler System call issue System call issue Handler IE bit 1 gt 0 pa Lle 0 a4 1 l l l When thelE flag before issuing a system call is 1 Task or System call issue System call issue System call Handler issue IE bit O ae M M
192. t value as each symbol When not using a base register function it is necessary to set up value with a dummy also about the register not to use global REL BASE11 global X REL BASE12 global REL BASE13 global REL BASE EL BASE11 equ 0 EL BASE12 equ 0 EL BASE equ 0 EL BASE13 equ c R EL BASE A start up program is started from here 172 Chapter 8 How to Customize 63 START 64 65 A system stack pointer is set up 66 67 seth rl f4high Sys Sp 68 or3 rl rl tflow Sys Sp 69 addi rl s4 4 70 mvtc rl SPI SPI initialize Yu mvtc r1 SPU 72 Tdi r0 1 73 st r0 rl 74 ldi r0 NULL 75 mvtc r0 PSW PSW initialize 76 77 When a base register function is used and when calling the function 78 written in C language from the start up routine R11 R13 registers must be 79 set up 80 81 seth R11 high __REL_BASE11 92 5 or3 R11 R11 low __REL_BASE11 83 seth R12 high __REL_BASE12 84 or3 R12 R12 low __REL_BASE12 85 5 seth R13 high __REL_BASE13 86 or3 R13 R13 low __REL_BASE13 87 88 AIF XY amp Dbg_flg gt 0 89 1d24 rl 4 Dbg mode 90 ldi r2 0 91 ldi r2 4 92 stb 12 Url 93 AENDI 94 95 Perform a setup in the mode of a microcomputer of operation etc 96 IT 3 Description below if you need 98 ex Maste
193. tartup Int Dummy A dummy interrupt routine Necessary __ SYS DUMMY A dummy system call routine Unnecessary Sys timer init This routine is called within a start up routine and performs setup of system time and ini tialization of a system clock interruption It is not dependent on a microcomputer and the setting portion of system time is described like the portion of 1 in the sample program from the following paragraph It is described that interruption generates initialization of a timer at arbitrary intervals according to the timer to use In case a user describes timer initialization OTHER is specified to be item timer of a system clock definition of a configuration file At that time the value specified to be timer clock IPL file name and unit time is disregarded SAVE IPL to STACK The entry address and the interruption status is saved on the stack area like Figure 8 1 The stack status of interrupt control program and it returns to OS processing This routine is called from OS interruption entry processing shown by a figure Figure 6 2 The procedure for running the interrupt handler when interruption occurs The entry address of an interrupt handler is read from the address table outputted by the configurator The preparation of the address table is carried out from the interruption factor 0 to the value of the interruption factor which was specified by max int of the maximum item defi
194. 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 queue 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 and task E are removed from the queue How ever since task E is waiting in clear specification the flag is cleared when task E is remove from the queue Therefore task F is not removed from the queue 3 5 MR32R Kernel Structure 41 Flag queue TaskA TaskB TaskC TaskD TaskE TaskF Flag pattern 0 Wait pattern OxOF OxFF OxOF OxFF OxFF OxOF Wait mode OR AND AND AND CLR OR CLR OR set_flg y TaskB TaskD TaskF l M E T R a E e A as CA cda ba l l Flag pattern l l OxOF l 4 l E l gt Flag pattern OxOF 0 Figure 3 24 Task Execution Control by the Eventflag 42 Chapter 3 Introduction to MR32R 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 require the use of them When for instance four tasks simultaneously try to acquire a total of only thr
195. te TRAP1 nop rte TRAP2 nop rte TRAP3 nop rte TRAP4 nop rte TRAP5 nop rte TRAP6 nop AIF XY amp Dbg flg eq O bra SYSCALLO TRAP7 bra SYSCALL1 TRAP8 AELSE global Dbg entry0O Dbg entryl bra Dbg entryO IRAP7 bra Dbg_entryl TRAP8 AENDI rte TRAPY nop rte TRAP1O nop rte TRAP11 nop rte TRAP12 nop rte TRAP13 nop rte TRAP14 nop rte TRAP15 nop Section Int_Vector code align 4 bra int entry SECTION RESET_VECT code align 4 i bra __ START end Figure 8 2 Startup Program for C Language for CC32R 175 176 Chapter 8 How to Customize 8 2 4 Startup Program for C Language for TW32R crtOmr s Figure 8 3 shows details about the startup program for C language for TW32R PRR RRR RRR KEK RRR KK RK koc kk hock KKK RK KKK KKK KK RK KK KK KKK KEK KKK KKK KK RK koc kk ko ke ck kc ke ke ke ke e ke ke 7 MR32R start up program for C language for TW32R Copyright 2001 MITSUBISHI ELECTRIC CORPORATION and MITSUBISHI ELECTRIC SEMICONDUCTOR APPLICATION ENGIN 7 All Rights Reserved I I ERING CORPORATION Id crtOmr s v 1 4 2001 04 23 07 05 18 inui Exp PRR RRR RRR KEK KKK KK kk kc EK KKK KK RK KR KK ke kk ke ko kk KKK ke kk KEK KR KKK ke kk KEK kc kk ko ko RK kc kk ke ke e ke ke A file required to incorporate OS is included Please do not change this portion 0 120014 QU 0r OO i000 120 01 iS CO IND ES
196. tem call function and the precautions about it The procedure of using OS debug functions Modify the item of system definition in configuration file Details are discribed in 6 1 Configuration File Creation Procedure Link your program with the library of the hook routine mrdbg lib for CC32R or libmrdbg a for TW32R D CC M32R Map the hook routine section OS DEBUG and the buffer area for OS debugging sec tion MR dbg RAM to any address Specify YES keyword in the system call definition item of the configuration file when using issuing system call function Modify from sys timer to Dbg sys timer in the interrupt handler definitionof the configuration file Dbg sys timer is the hook routine for issuing system call function Precautions in using OS debug functions Please set the system clock interval in 10ms Because the debugger cannot display the time line of MR trace window correctly when the system clock interval is over 10 ms but it display the factor and order of task switching correctly You cannot use task trace function system call trace function and issuing system call function when the debugger does not support these function The system calls issued from interrupt handler can use in issuing system call function except get tid system call The system calls issued from task cannot be used The processing time and interrupt disable time are longer when using OS debug func tions To control the
197. teshere de pepe Ud 139 template file sse 145 ter TSK sciat ose Ue nae e osten 34 COST DV MEE 60 63 The maximum number of alarm handler defined Sia cad a Bel e req per E eos wile ohh ce sian eve ss 130 The maximum number of cyclic activation handlers defined sese 130 The maximum number of eventflags defined 129 The maximum number of fixed size memorypools defined 5 dere can i Creer orte 130 The maximum number of interrupt handler defined cs ene ies 130 The maximum number of mailbox with priority defined eee 130 The maximum number of mailboxes defined 129 The maximum number of messagebuffer defined C 129 The maximum number of messages 134 The maximum number of rendezvous defined 129 The maximum number of semaphores defined 129 The maximum number of tasks defined 129 The maximum number of variable size memorypools defined sssss 130 The maximum priority of messages 136 The time of day 118 c 117 TIMEOUT ci da ct ttes 36 Mi ico api ba 127 Timer cod iaa t 127 TO Mii rre rte trn et 49 63 SA A cuente eges 45 63 TRON Specification sesser 6 O neret 38 63 A OO 48 63 IWS2R a e delta ae med 8 Wal Mia epi qe anao 40 63 tWal Serisi ae metre rere tiene 43 63 Type Numboer eene 66 U Unit time of system dock sesser 127 UN EQU cirio tt ita 55
198. th ext tsk Described in Assembly Language 4 The initial register values except PC PSW and following registers are indetermi nate For M32R Family Cross Tool CC32R A start code is stored R2 and R4 register For M32R Family Cross Tool TW32R D CC M32R A start code is stored RO and R2 register 5 When designating a task use a character string consisting of ID and task func tion name 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 y To specify this semaphore write your specification as follows 5 Use the GLOBAL pseudo directive The configurator generates pseudo directive to convert from the strings to the ID No of the task in mr32r inc file 5 2 Program Coding Procedure in Assembly Language 89 Sig sem ID abc 7 When specifying a cyclic handler or alarm handler use a character string that con 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 MR32R system startup in the configuration file 9 The relationship between task ID numbers and tasks program is defined in the
199. the ITRON Specification 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 MR32R with comparative ease High speed processing is achieved MR32R enables high speed processing by taking full advantage of the microcomputer architecture Only necessary modules are automatically selected to constantly build up a system of the minimum size The MR32R is supplied in the form of a M32R family microcomputer objective library Therefore the Linkage Editor functions are activated so that only necessary modules are automatically selected from numerous MR32R 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 NC308 it is possible to develop application programs in C lan guage When the C compiler cc32R or TW32R is used MR32R application programs can be devel oped in C language Also note that an interface library is supplied on software disk to permit calling up the MR32R 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 created by giving simple definitions Therefore there is no particular nee
200. the beginning of file be sure to include mr32r h which is in the system direc tory as well as id h which is in the current directory The static declared functions cannot be registered as a cyclic handler or alarm handler The cyclic handler and alarm handler are invoked by a subroutine call from a sys tem clock interrupt handler include lt mr32r h gt include id h void cychand void process Figure 5 4 Example Cyclic Handler Written in C Language The handler to function name correlation is determined by the configuration file 5 1 Program Coding Procedure in C Language 87 5 1 4 Writing Exception forced exception handler When writing exception handlers in C language pay attention to the following 1 Write the exception handler as a function 2 Declare the return value of the function using the void type 3 For the function argument specify the pointer to the exception information packet T EXC pk exo the pointer to the register information packet to be referenced when an exception occurs T REGS pk regs or the pointer to the EIT information packet T EIT pk eit 4 Atthe beginning of the file always be sure to include mr32r h that is stored in the system directory and id h that is stored in the current directory 5 The functions that have been static declared cannot be registered as an exception handler 6 Use the vret exc system call to terminate the handler When the
201. the section name speci fied for the aforesaid section A macro description to transfer the PROGRAM section using registers RO R1 R2 R3 is given here DOWNLOAD RO R1 R2 R3 DATA ROM DATA With TW32R in use DOWNLOAD reg1 reg2 reg3 reg4 start section end section rom section Specify registers to be used in the macro for reg1 reg2 reg3 reg4 Specify for start section the first address of the downloading target specify for end section the tail address of the downloading target and specify for rom section the first address of the downloading Source Usually symbols set in the linker script file m32r cmd are used for these addresses Here is a macro to transfer the text area described as shown below in m32r cmd by use of registers RO R1 R2 R3 data ADDR MR RAM SIZEOF MR RAM AT LOADADDR rodata SIZEOF rodata data start data gnu linkonce d CONSTRUCTORS data end rom data LOADADDR data DOWNLOAD RO R1 R2 R3 data start data end rom data In this instance the ROM PROGRAM section is automatically generated By the linker and the section needs to be defined in the startup file 8 2 How to Customize the MR32R Startup Program 169 With D CC M32R in use DOWNLOAD reg1 reg2 reg3 reg4 start section end section rom section Specify registers to be used in the macro for reg1 reg2 reg3 reg4 Specify for start section the first address of the downloading target speci
202. ther 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 or if you h
203. ther associated data MPU Information Number representing the M32R Family Microcomputer Variation Descriptor Number of the function set available for use with the MR32R Refers system status ref_sys Refers CPUand OS status as below System status It tells whether the task is running or the handler is running And whether dispatching is enable or not and whther interrupt is enable or not if the task is running ID number of the RUN state task The priority of the RUN state task PSW value of the RUN state task or the handler Defines forced exception handler def exc Defines forced exception handler The contents of forced exception handler are below Forced exception attribute Specify whether the internal RAM is used for stack or the external RAM is used for stack e Forced exception handler start address Specify start address of forced exception handler The ID number of the task Specify the ID number of the task for the forced exception Stack size Specify the stack size used by the forced exception handler 3 5 MR32R Kernel Structure 67 3 5 14 Implementation Dependent Extended function is not specified in JITRON V 3 0 specification but MR32R support it as its own func tion Exception Management function means that the forced exception handler is defined and executed if an exception is occurred in task processing A forced exception handler is defined for each task Also all system calls can be is
204. they have been placed in a WAIT state by Y If tasks that have been placed in a WAIT state for other conditions than the slp tsk or tslp tsk system call or tasks in other states except one that is in a DORMANT state are waked up by the wup tsk or iwup tsk system call it results in only wakeup requests being accumulated Therefore if a wakeup request is issued for a task in executing state for example that wake up request 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 Canceling a Task Wake up Request can wup Clears the stored wake up reques See Figure 3 23 wup tsk wup tsk wup tsk sip tsk Task ECC eR Wake up count 0 0 Figure 3 22 95 If the task is WAIT state it is not waked up in any condition as below 9999 999999 Eventflag waiting Semaphore Waiting Message waiting Timeout waiting Fixed size memoryblock waiting Variable size memorypool waiting Port accept waiting Port call waiting Rendesvouz waiting Message buffer receive waiting Message buffer send waiting Message waiting for mailbox with priority sip tsk Wake up Request Storage 3 5 MR32R Kernel Structure 39 wup_tsk wup tsk can wup sip tsk sip tsk Task RE tq q s Wake up count 0 0 1 0 0 Figure 3 23 Wake up Requ
205. time the system clock counts 100 to wake task2 up 10 1 Sample Program 209 10 1 2 Program Source Listing 1 J KCKCKCKCKCKCk kk kk kk kk kk I kk kk kk kk kk kk I RRA RRA ck k ck k ck k ck k ck k ck k ck k ck I I AI A OK Z MR32R smaple program 3 4 Copyright 2001 MITSUBISHI ELECTRIC CORPORATION 5 AND MITSUBISHI ELECTRIC SEMICONDUCTOR APPLICATION ENGINEERING CORPORATION 6 All Rights Reserved Y 8 SId smp c v 1 2 2001 04 18 06 24 29 inui Exp 9 KCKCkCKCkCk Ck kk kk kk I kk Ck Ck kk Ck Ck kk kk kk k ck k ck k ck k ck k ck k ck k ck ck ck ck ck ck ck ck ck ok sk kk f 10 11 include lt mr32r h gt 12 include id h 13 14 void OutputMessage char INT 15 16 define P5MOD volatile UH 0x00EF106A 17 define SIOOCR volatile UH Ox00EFDO002 18 define SIOOMODO volatile UH 0x00EFDO06 19 define SIOOMOD1 volatile UH 0x00EFDO0A 20 define SIOUSTS volatile UH 0xOOEFDOOE 21 define SIOOTRCR volatile UH 0xOOEFDO12 22 define SIOOBAUR volatile UH 0x00EFDO16 23 ld define SIOORBAUR volatile UH 0x00EFDO1A 24 M define SIOOTXB volatile UB 0x00EFDO1F 25 26 void main void 27 28 P5MOD 0x00ff 0 0x5500 29 SIOOCR 0x0300 30 STOOMODO 0x0100 31 SIOOMOD1 0x0800 32 SIOOBAUR 34 33 SIOORBAUR 12 34 SIOOTRCR 0x0000 35 SIOOCR 0x0303 36 34 sta tsk ID task
206. uffer the message is sent to the messagebuffer and the task goes to an execution RUN or ex ecutable READY state Task A 1 Message Recieve 2 Message Task B Send free block Message Message Send e buffer message wait state Figure 3 34 Receive Message When task A is in the execution RUN state and task B is in wait state as in Figure 3 34 1 Task A receives a message from the messagebuffer As a message is received from the messagebuffer the free space in the messagebuffer in creases that much Task B transmits a message to the messagebuffer Task B which has been kept waiting for transmission because the free space in the mes sagebuffer was insufficient now transmits a message to the messagebuffer as task A has re ceived a message The status of task B changes from the transmit wait state to an executable state Receive message prcv mbf Receives a message The difference with rcv mbf and trcv mbf is that when no message exists in the messagebuffer this system call returns error code without going to a receive wait state Reference messagebuffer status ref_mbf 3 An error code E TMOUT is returned 50 Chapter 3 Introduction to MR32R Checks the target messagebuffer to see if there is any task kept waiting for transmission or waiting for reception as well as find the size of the next message to be received 3 5 MR32R Kernel Structure 51 3 5 9 Rendezvous The rendezvou
207. ugging sections stab 0 stab Stabstr 0 stabstr Stab excl 0 stab excl Stab exclstr 0 stab exclstr stab index 0 stab index Stab indexstr 0 stab indexstr comment 0 comment DWARF debug sections Symbols in the DWARF debugging sections are relative to the beginning of the section so we begin them at 0 DWARF 1 debug 0 debug line 0024 d Lines 1 GNU DWARF 1 extensions debug_srcinfo 0 debug srcinfo debug sfnames 0 debug sfnames DWARF 1 1 and DWARF 2 debug aranges 0 debug aranges debug pubnames 0 debug_pubnames DWARF 2 debug info 0 debug abbrev 0 debug line 0 debug frame 0 s 0 0 debug info debug abbrev debug line debug frame debug str debug str debug loc debug_loc debug macinfo 0 debug_macinfo SGI MIPS DWARF 2 extensions debug weaknames 0 debug weaknames debug funcnames 0 debug funcnames debug typenames 0 debug typenames debug varnames 0 debug varnames 8 3 Customizing the Section File 193 8 3 4 Using DCC M32R To lay out memory you use the linker script m32r cmd that comes with the MR32R This file is used when executing the linker dld Symbols defined in the MR32R and the contents of the sample files attached to the product are exp
208. uspend 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 visnd mbx Send Message Sends a message 2 It isn t necessary to write this system call when specifying the interrupt handler as pragma INTHANDLER in C language 3 5 MR32R Kernel Structure 31 3 5 MR32R Kernel Structure 3 5 1 Module Structure The MR32R kernel consists of the modules shown inFigure 3 17Each of these modules is composed of functions that exercise individual module features The MR32R 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 However the scheduler module part of the task management module and part of the time management module are linked at all times because they are essential feature functions The applications program is a program created by the user It consists of tasks interrupt handler alarm handler and cyclic handler Y User program Application Program Task E Time Mana
209. ut Renesas 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 product s quality grade as indicated below You must check the quality 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 quality 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 equipment communicatio
210. uter can be used for other products without being modified 12 Chapter 3 Introduction to MR32R Key input Remote control Task Task real time OS LED illumination Task Volume control Monitor Mechanical Task Task control Task Figure 3 3 Example System Configuration with Real time OS Audio Equipment In other words the real time OS is the software that makes a one microcomputer system look like op erating 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 num ber of microcomputers You should be wondering how the real time OS makes a one microcomputer system function like a number of microcomputers As shown in Figure 3 4 the real time OS runs a number of tasks according to the time division system That is it changes the task to execute at fixed time intervals so that a number of tasks appear to be executed 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 b
211. version cannnot be found in the directory indicated by the envi ronment variable LIB32R cfg32r Error can t open default configuration file The default configuration file cannnot be accessed default cfg is needed in the current directory or directory LIB32R specifying cfg32r Error can t open configuration file lt test cfg gt The configuration file cannot be accessed Check that the file name has been properly des ignated cfg32r Error illegal XXXX xx near line 212 test cfg The value or ID number in definition item XXXX is incorrect Check the valid range of defi nition cfg32r Error Unknown XXXX gt xx near line 23 test cfg The symbol definition in definition item XXXX is incorrect Check the valid range of definition cfg32r Error too big XXXX s ID number gt 6 test cfg A value is set to the ID number in XXXX definition that exceeds the total number of objects defined The ID number must be smaller than the total number of objects cfg32r Error too big task x s priority gt lt 16 gt test cfg The initial priority in task definition of ID number x exceeds the priority in system definition cfg32r Error system timer s vector lt x gt conflict A different vector is defined for the system clock timer interrupt vector Confirm the vector 152 Chapter 7 Using Configurator No x for interrupt vector definition cfg32r Error XXXX is not defined test cfg XXXX item must be set
212. voee tht 46 The example of send message sssssssssssseeseeeenee enne enne 47 Send Message derit deer tte Fire a Pup esce pase Ree E E 48 Receive Message tete ee od A A ERR ute a 49 O 51 Multiple rendezvous sessions sssssssseeeeeeeneee nennen 52 Rendezvous forwarding esses nnne enne nnn 53 Reridezvous reply a tete to eter rn 54 Interrupt process flow tette E Ee Ree YR Cre DER died en 56 Fixed size M emorypool Management sssssssseseeeneeeeneenneennenn nnn 57 poet DIK processing ciet etr eee Eee Rete Renee Ee eene d 60 rel bik pEOCeSSITIQ ei receiving ie YD 61 Release Memory A 62 dly tsk system call dadas 63 Timeout Processing d cedes rre eterne ET EE eee Ree EE ene an 64 Gyclic Handler Mp 65 Cyclic Handler TCY ON Selected as Activity Status ccc eeeeeeeseeeeteeeteeetees 65 Cyclic Handler TCY_INI_ON Selected as Activity Status 65 MR32R System Generation Detail FlOWCh art cece ceeeseeeeeeeeeeeeeeeeeeaeenaeeeeeeaees 75 Program E xample 2 2 ota cored e ee ek oh eee Tene aaa ete 77 Configuration File Example sss enne 79 vi List of Figures Figure 4 4 Configurator Execution ssssssssssseeeeeeeeennee nennen nnne trennt nnne nnne tnnt 80 Figure4 5 System Generation eene nennen nennen nnns tnra nnne nnne tnnt 80 Figure5 1 Examplelnfinite Loop Task Described in C Language sseeeee 82 F
213. y Definition range 0 0 0x7FFF OXFFFFFFFF Define the startup time of the alarm handler 2 Start address Definition format Symbol or Function Name Definition range None Define the start address of the alarm handler Systemcall definition lt lt Format gt gt Systemcall Definition systemcall Systemcall Name YES or NO y Define a system call to be used in an application program as given below 7 1 Configuration File Creation Procedure 141 lt lt Content gt gt 1 Used system call Definition format Symbol Definition range YES or NO Define a system call to be used in an application program as given below cre_tsk del_tsk sta_tsk ista_tsk ext_tsk exd_tsk ter_tsk dis_dsp ena_dsp chg_pri ichg_pri rot rdq irot_rdq rel_wai irel_wai get_tid ref_tsk sus_tsk isus_tsk rsm_tsk irsm_tsk slp_tsk wup_t sk iwup_tsk can_wup cre_flg del_flg set_flg iset_flg clr_flg wai_flg twai_flg pol_flg ref_flg cre sem del sem sig sem isig sem wai sem twai sem preq sem ref sem cre mbx del mbx s nd msg isnd msg rcv msg trcv msg prcv msg ref mbx cre mbf del mbf snd mbf tsnd mb fppsnd mbf rcv mbf trcv mbf prcv mbf ref mbf cre por del por cal por tcal por pcal por ac p portacp por pacp porfwd por rpl rdv ref por def int ret intjloc cpu unl cpu cre mpf del mpf get blf tget blf pget blf rel blf ref mpf cre mpl del mpl get blk tget blk pget blk rel b IK ref mpl set tim get tim dly tsk act cyc ref cyc
214. ystem clock get tim system call 41 Set tim system call 64 Chapter 3 Introduction to MR32R tslp tsk 50 E TMOUT READY state WAIT state Timeout value tslp tsk 50 E OK l l l l iwup_tsk Figure 3 45 Timeout Processing e Setting the System Time set tim e Setting the System TimeReading 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 e Define a cyclic handler def cyc Define a cyclic handlerr e Controlling the Cyclic Handler Activity act cyc The cyclic handler is a program running at fixed time intervals See Figure 3 46 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 47 or TCY INI ON may be se lected to initialize the handler count See Figure 3 48 Referencing the cyclic handler s status ref cyc References the relevant cyclic handler s startup status and checks the time remaining until the next startup Referencing the alarm handler s status ref alm References the time remaining until the relevant alarm handler s startup 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 ne
215. ze 63 MFT port output status register setting 64 1d24 r1 MFTOS 65 ldi x0 0 66 st r0 rl 67 MFT reload register setting 68 1d24 vl MFTRLD 69 addi r10 4 1 70 st rl10 Gr1 71 72 MFT interrupt control register setting IEN 1 ILEVEL 3 73 1d24 rl 41CUCR 74 ldi r0 40x1100 75 or3 r0 r0 __stmr_ipl 76 st r0 rl 77 78 MFT control register setting 79 1d24 rl 4MFTCR 80 1d24 r2 t4 write bit ena bit 81 or r0 r2 82 st r0 rl 83 84 ld v14 r15 85 jmp r14 86 endif 87 88 An interruption control register is saved the jump place address of 89 interruption is saved on a stack and it returns to OS kernel 90 Since it is called from OS kernel by interruption entry processing 91 please do not change this label name 92 93 94 global SAVE IPL to STACK INT VECTOR 95 SAVE IPL to STACK gt 1 96 addi R15 4 8 J b 2 97 st R14 R15 98 st R4 R15 99 st R5 R15 100 st R6 R15 101 102 An interruption control register is saved on a stack and an interruption 103 factor number is read 104 1 05 1d24 v4 ICUISTS 2 2 2 2 1 1 1 1 3 106 ld r5 r4 107 st r5 0 20 r15 108 srli r5 420 109 110 Table reference is carried out from _ INT VECTOR and interruption jump place 111 address is saved on a stack This table is 112 by configurator as an INTERRUPT VECTOR sect 113 arbitrary addresses by

Download Pdf Manuals

image

Related Search

Related Contents

LCD TV - Grundig  CK32 I-Safe Handheld Computer User`s Manual  Tender Notice  Samsung B1930HD Керівництво користувача  Chieftec BA-01B-B-B computer case  ReadyNAS Surveillance Add-On-Handbuch  USER`S MANUAL  Tristar SZ-1909 vacuum cleaner  Lenovo ThinkStation S20  Bosch HWD57 Product data  

Copyright © All rights reserved.
Failed to retrieve file