Home
MR8C/4 V.1.01 User`s Manual
Contents
1. 7 Detailed Applications 150 GLB init flg 151 SR W init flg 152 ENDIF 153 154 IF NUM SEM 155 GLB init sem 156 JSR W init sem 157 ENDIF 158 159 IF NUM DTO 160 GLB init dtq 161 JSR W init dtq 62 ENDIF 163 164 IF ALARM HANDLER 165 GLB init alh 166 JSR W init alh 167 ENDIF 168 169 170 IF CYCLIC HANDLER 171 GLB init cyh 12 JSR W init cyh TE ENDIF 174 175 For PD30 176 LAST INITIAL 177 178 END INIT LEO s 180 Start initial active task 181 182 START TASK 183 184 glb rdyq search 185 jmp W rdyq search 186 187 188 Define Dummy 189 190 glb SYS DMY INH 191 _ SYS DMY INH 192 reit 193 194 IF CUSTOM SYS END 195 5 196 Syscall exit rouitne to customize UE 198 GLB Sys end 199 sys end 200 Customize here 201 REIT 202 ENDIF 203 204 205 exit function 206 t 207 glb exit S exit 208 exit 209 Sexit 210 jmp exit 211 212 7 213 3 System down routine 214 215 GLB __vsys_dwn 216 vsys dwn 217 JMP B __vsys_dwn 218 219 220 if USE_TIMER 221 7 222 System clock interrupt handler 229 4 4 224 SECTION MR_KERNEL CODE ALIGN 225 glb SYS STMR INH SYS TIMEOUT 226 glb DBG MODE SYS_TSS R20UT0657EJ0101 Rev 1 01 Page 135 of 178 Sep 16 2011 RENESAS MR8C 4 227 SYS STMR INH 228 process
2. 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 1234 0x23 e 23 4 3 2 100B 08H Symbol The symbols are indicated by a character string that consists of numerals upper and lower case alphabetical letters underscore and and begins with a non numeric character Example symbols are presented below e _TASK1 e IDLE3 Function Name The function names are indicated by a character string that consists of numerals upper and lower case alpha betical letters dollar and underscore begins with a non numeric character and ends with The following shows an example of a function name written in the C language main e func When written in the assembly language the start label of a module is assumed to be a function name R20UT0657EJ0101 Rev 1 01 Page 140 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator Freguency 8 1 2 The following definitions 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 freguency can be entered us ing decimal numbers only Freguency entry examples are presente
3. Functional description This service call changes the priority of the task indicated by tskid to the value indicated by tskpri and performs resched uling based on the result of that priority change Therefore if this service call is executed on a task enqueued in a ready queue including one that is in an executing state or a task in a waiting queue in which tasks are enqueued in order of pri ority the target task is moved to behind the tail of a relevant priority part of the queue Even when the same priority as the previous one is specified the task is moved to behind the tail of the queue The smaller the number the higher the task priority with 1 assigned the highest priority The minimum value specifiable as priority is 1 The specifiable maximum value of priority is the maximum value of priority specified in a configuration file providing that it is within the range 1 to 255 For example if system specification in a configuration file is as follows system 0x100 137 stack size priority l then priority can be specified in the range 1 to 13 IfTSK SELF is specified the priority of the issuing task is changed If TSK SELF is specified for tskid in non task con text operation of the service call cannot be guaranteed If TPRI INI is specified the task has its priority changed to the initial priority that was specified when the task was created The changed task priority remains effective until the task is terminat
4. lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM AO rsm_tsk ID_TASK2 R20UT0657EJ0101 Rev 1 01 Sep 16 2011 2tENESAS 5 Service call reference Page 75 of 178 MR8C 4 5 Service call reference dly tsk Delay task C Language API ER ercd dly tsk RELTIM dlytim Parameters RELTIM dlytim Delay time e Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc dly tsk RELTIM Parameters RELTIM Delay time Register contents after service call is issued Register name Content after service call is issued RO Error code RI Delay time 16 low order bits R3 Delay time 16 high order bits Error code E RLWAI Forced release from waiting Functional description This service call temporarily stops execution of the issuing task itself for a duration of time specified by dlytim to place the task from RUNNING state into WAITING state In this case the task is released from the WAITING state at the first time tick after the time specified by dlytim has elapsed Therefore if specified dlytim 0 the task is placed into WAITING state briefly and then released from the WAITING state at the first time tick The task placed into WAITING state by invocation of this service call is released from the WAITING state in the following cases Note that when released from WAITING state the task th
5. 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 attached to the end be sure to add 0 to the beginning Note that the system does not distinguish between the upper and lower case alphabetical characters A F used as numerical values 2 Decimal Number Use an integer only as in 23 However it must not begin with 0 3 Octal Numbers Add 0 to the beginning of a numerical value of O or o to end 4 Binary Numbers Add B or b to the end of a numerical value It must not begin with 0 Table 8 1 Numerical Value Entry Examples 5 The System distinguishes between the upper and lower case letters except for the numbers A F and a f R20UT0657EJ0101 Rev 1 01 Page 139 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator 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 8 2 Operators lists the operators available Table 8 2 Operators
6. The task is normally terminated by ext tsk service call or forcibly terminated by ter tsk service call R20UT0657EJ0101 Rev 1 01 Page 22 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel 3 4 2 Task Priority and Ready Queue In the kernel several tasks may simultaneously request to be executed In such a case it is necessary to determine which task the system should execute first To properly handle this kind of situation the system 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 MR8C 4 permits giving the same priority to several tasks To provide proper control over the READY task execution order the kernel generates a task execution queue called ready queue The ready queue structure is shown in Figure 3 17 The ready queue is provided and controlled for each priority level The first task in the ready queue having the highest priority is placed in the RUNNING state Priority 3 gt TCB TCB TCB TCB TCB Figure 3 17 Ready Queue Execution Queue 12 The TCB task control block is described in the next chapter 13 The task in the RUNNING state remains in the ready queue R20UT0657EJ0101 Rev 1 01 Page 23 of 178 Sep 16 2011 32 NE SAS
7. 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the cyclic handler is specified in a program 2 Activation cycle Definition format Numeric value Definition range 1 to Ox7 FFFFFFF Default value None Define the activation cycle at which time the cyclic handler is activated periodically The activation cycle here must be defined in the same unit of time as the system clock s unit time that is defined in system clock defini tion item If you want the cyclic handler to be activated at 1 second intervals for example the activation cycle here must be set to 1000 3 TA STA attribute Definition format Symbol Definition range ON or OFF Default value OFF Specify the TA STA attribute of the cyclic handler If ON is selected the TA STA attribute is added if OFF is selected the TA STA attribute is not added R20UT0657EJ0101 Rev 1 01 Page 150 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator 4 TA PHS attribute Definition format Symbol Definition range ON or OFF Default value OFF Specify the TA PHS attribute of the cyclic handler If ON is selected the TA PHS attribute is added if OFF is selected the TA PHS attribute is not added 5 Activation phase Definition format Numeric value Definition range 0 to Ox7FFFFFFF Default value None Define the activation pha
8. Example program statement Example statement in C language include lt itron h gt include lt kernel h gt include kernel id h void task BOOL stat stat sns_loc lt lt Example statement in assembly language gt gt include mr8c inc GLB task task sns loc R20UT0657EJ0101 Rev 1 01 Page 116 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference sns dsp Reference dispatching state C Language API BOOL state sns dsp e Parameters None Return Parameters BOOL state TRUE Dispatching disabled state FALSE Dispatching enabled state Assembly language API include mr8c inc sns dsp e Parameters None Register contents after service call is issued Register name Content after service call is issued RO TRUE Dispatching disabled state FALSE Dispatching enabled state Error code None Functional description This service call returns TRUE when the system is in a dispatching disabled state or returns FALSE when the system is in a dispatching enabled state This service call can also be invoked from a CPU locked state Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task BOOL stat stat sns dsp lt lt Example statement in assembly language gt gt include mr8c inc GLB task task
9. PUSHM A0 prov dtq ID DTO2 PUSHM AO rov dtq ID DTQ2 R20UT0657EJ0101 Rev 1 01 Page 97 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference 5 6 Time Management Function Table 5 11 List of Time Management Function Service Call No Service Call Function System State T N E D U L 1 isig tim S Supply a time tick O O o O Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 0 99999 R20UT0657EJ0101 Rev 1 01 Page 98 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference isig tim Supply a time tick Functional description This service call updates the system time The isig tim is automatically started every tick time interval ms if the system clock is defined by the configuration file The application cannot call this function because it is not implementing as service call When a time tick is supplied the kernel is processed as follows 1 Updates the system time 2 Starts an alarm handler 3 Starts a cyclic handler 4 Processes the timeout processing of the task put on W
10. Semaphore 3 2 1 0 x 0 Counter Figure 4 10 Task Execution Control by Semaphore The MR8C 4 kernel offers the following semaphore synchronization service calls Release Semaphore Resource sig sem isig sem Releases one resource to the semaphore This service call wakes up a task that is waiting for the semaphores ser vice or increments the semaphore counter by 1 if no task is waiting for the semaphores service Acquire Semaphore Resource wai sem Waits for the semaphores service If the semaphore counter value is 0 zero the semaphore cannot be acquired Therefore the WAITING state prevails Acquire Semaphore Resource pol sem Acquires the semaphore resource If there is no semaphore resource to acquire an error code is returned and the WAITING state does not prevail R20UT0657EJ0101 Rev 1 01 Page 44 of 178 Sep 16 2011 132 N SAS MR8C 4 4 Kernel 4 2 4 Synchronization and Communication Function Eventflag The eventflag is an internal facility of MR8C 4 that is used to synchronize the execution of multiple tasks The eventflag uses a flag wait pattern and a 16 bit pattern to control task execution A task is kept waiting until the flag wait conditions set are met It is possible to determine whether multiple waiting tasks can be engueued in one eventflag waiting gueue by specifying the eventflag attribute TA WSGL orTA WMUL Furthermore it is possible to clear the eventflag bit pattern to 0 when the e
11. je we em 2 3x je je ww 2 je je Fam e am jm je n 2 je je he 3 x je Je R20UT0657EJ0101 Rev 1 01 Page 177 of 178 Sep 16 2011 RENESAS MR8C 4 13 Appendix Synchronization amp Communication Function RetumPararreter ServiceCall INTNo FuncCode R2 R3 FuncCode wasem PAE M CHE UNE L FN EAN EN M CR sem 2 o jee jee 1L se s eo jee jee C ham 2 aw jemm jee _ jen mw s fmm jem m fea _ jen ham 2 jemm e Fem oa jemm ea am s e jamm les ma x one aad fea mas x ne le je T hl m E E C lm C a weta 2 sel TT oi led oaj j System Status Management Function Parameter ReturnPararreter 7 m SE E e R R O CY me 1 es hum 3 6 jee me 3 i je I me 3 je mae a 56 je Time Management Function Parameter ReturnParameter ServiceCall INTNo E ncCode A1 R1 R3 A0 RO FuncCode has s js je moe s o jee je saam a jam jam ams fea Imam m dame les System Configuration Management Function R20UTO657EJO0101 Rev 1 01 Page 178 of 178 Sep 16 2011 RENESAS Real time OS for R8C Family MR8C 4 V 1 01 User s Manual Publication Date September 16 2011 Rev 1 01 Published by Renesas Electroni
12. Parameters None e Return Parameters ER ercd Terminated normally E_OK Assembly language API include mr8c inc ena_dsp Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Functional description This service call frees the system from a dispatching disabled state that was set by the dis dsp service call As a result task scheduling is resumed when the system has entered a task execution state Invoking this service call from a task execution state does not cause an error in which case task queuing is not performed however This service call can be issued only from task context It cannot be issued from non task context Example program statement Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task ena dsp lt lt Example statement in assembly language gt gt include mr8c inc GLB task task ena_dsp R20UT0657EJ0101 Rev 1 01 Page 114 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference sns ctx Reference context C Language API BOOL state sns ctx e Parameters None e Return Parameters BOOL state TRUE Non task context FALSE Task context Assembly language API include mr8c inc sns ctx e Parameters None Register contents after service c
13. sns_dsp R20UT0657EJ0101 Rev 1 01 Page 117 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference 5 10Interrupt Management Function Table 5 17 List of Interrupt Management Function Service Call No Service Call Function System State E D ojo N U 1 ret_int Returns from an interrupt O O handler Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 99999 R20UT0657EJ0101 Rev 1 01 Page 118 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference ret int Returns from an interrupt handler when written in assembly language C Language API This service call cannot be written in C language Assembly language API include mr8c inc ret int e Parameters None Error code Not return to the interrupt handler that issued this service call Functional description This service call performs the processing necessary to return from an interrupt handler Depending on return processing it activates the scheduler to switch tasks from one to another If this service call is execut
14. ER ercd iset flg ID flgid FLGPTN setptn e Parameters ID flgid ID number of the eventflag to be set FLGPTN setptn Bit pattern to be set Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc set flg FLGID SETPTN iset flg FLGID SETPTN Parameters FLGID ID number of the eventflag to be set SETPTN Bit pattern to be set Register contents after service call is issued Register name Content after service call is issued RO Error code R3 Bit pattern to be set A0 Eventflag ID number Error code None Functional description Of the 16 bit eventflag indicated by flgid this service call sets the bits indicated by setptn In other words the value of the eventflag indicated by flgid is OR d with setptn If the alteration of the eventflag value results in task awaking conditions for a task that has been kept waiting for the eventflag by the wai flg or twai flg service call becoming satisfied the task is released from WAITING state and placed into READY or RUNNING state Task awaking conditions are evaluated sequentially beginning with the top of the waiting queue If TA WMUL is specified as an eventflag attribute multiple tasks kept waiting for the eventflag can be released from WAITING state at the same time by one set flg or iset_flg service call issued Furthermore if TA CLR is specified for the attribute of the target event flag all bit patterns of the
15. MR8C 4 3 Introduction to Kernel 3 4 3 Task Priority and Waiting Oueue In The standard profiles in uITRON 4 0 Specification support two waiting methods for each object In one method tasks are placed in a waiting queue in order of priority TA TPRI attribute in another tasks are placed in a waiting queue in order of FIFO TA TFIFO MR8C 4 supports only TA TFIFO attribute Figure 3 19 depict the manner in which tasks are placed in a waiting queue in order of taskD taskC taskA and taskB ID No taskD EN taskC taskA 1 taskB Priority 9 Priority 6 Priority 1 Priority 5 DE Figure 3 18 Waiting gueue of the TA TFIFO attribute R20UT0657EJ0101 Rev 1 01 Page 24 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel 3 4 4 Task Control Block TCB The task control block TCB refers to the data block that the real time OS uses for individual task status priority and oth er control purposes The MR8C 4 manages the following task information as the task control block Task connection pointer Task connection pointer used for ready gueue formation or other purposes Task status Task priority Task register information and other data storage stack area pointer current SP register value Wake up counter Task wake up request storage area Flag wait pattern This area is used when using the timeout function This area stores the flag wait pattern
16. Return Parameters ER ercd Terminated normally E OK or error code VP INT p data Pointer to the start of the area in which received data is stored Assembly language API include mr8c inc rcv dtq DTOID prcv dtq DTOID Parameters DTQID ID number of the data queue from which to receive Register contents after service call is issued Register name Content after service call is issued RO Error code R1 Received data A0 Data gueue ID number Error code E RLWAI Forced release from waiting E TMOUT Polling failure R20UT0657EJ0101 Rev 1 01 Page 95 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference Functional description This service call receives data from the data queue indicated by dtqid and stores the received data in the area pointed to by p data If data is present in the target data queue the data at the top of the queue or the oldest data is received This results in creating a free space in the data queue area so that a task enqueued in a transmission waiting queue is released from WAITING state and starts sending data to the data queue area If no data exist in the data queue and there is any task waiting to send data 1 e data bytes in the data queue area 0 data for the task at the top of the data transmission waiting queue is received As a result the task kept waiting to send that data is released from WAITING state On the other hand if rcv dtq is issued for the data
17. 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 Timer control is made easier To perform processing at 10 ms intervals the microcomputer timer function was formerly used to periodically in itiate an interrupt However as the number of usable microcomputer timers was limited timer insufficiency was compensated for by for instance using one timer for a number of different processing operations When the real time OS is introduced however it is possible to create programs for performing processing at fixed time intervals making use of the real time OS time management function without paying special attention to the microcomputer timer function At the same time programming can also be done in such a manner as to let the programmer take that numerous timers are provided for the microcomputer Software maintainability is enhanced When the real time OS is put to use the developed software consists of small program modules called tasks Therefore increased software maintainability is provided because developed software maintenance can be carried out simply by maintaining small tasks Increased software reliability is assured The introduction of the real time OS makes it possible to carry out program evaluation
18. __Sys_Sp amp OFFFFH fb 91 92 93 94 Initialize standard I O 95 96 glb init 97 jsr a init 98 99 3 100 Set System IPL 101 and 102 Set Interrupt Vector 103 104 mov b 0 ROL 105 mov b __SYS_IPL ROH 106 ldc RO FLG set system IPL 107 ldc INT VECTOR gt gt 16 amp OFFFFH INTBH 108 ldc INT VECTOR amp OFFFFH INTBL 109 10 IF USE TIMER ll 12 System timer interrupt setting 13 fe 114 mov b stmr mod val stmr mod reg set timer mode 115 mov b stmr int IPL stmr int reg set timer IPL 116 mov b stmr cnt lower stmr ctr reg set interval count 17 mov b stmr cnt upper stmr pre reg set interval count 118 mov b 0 stmr ioc reg 119 IF USE TIMER RB 120 mov b 0 stmr ct2 reg 121 mov b 0 stmr one reg 22 ENDIF 23 or b stmr bit l1 stmr start system timer start 24 ENDIF 25 26 245 System timer initialize 28 129 IF USE SYSTEM TIME 130 MOV W D Sys TIME L Sys time 4 131 MOV W D Sys TIME M Sys time 2 132 MOV W D Sys TIME H Sys time 133 ENDIF 134 Leo 136 User Initial Routine if there are 137 zb I38 5 1 39 40 jmp MR INIT for Separate ROM 141 L42 43 Initalization of System Data Area 44 s L45 GLB init sys init tsk END INIT 146 JSR W init sys 47 JSR W init tsk 148 49 IF NUM FLG R20UT0657EJ0101 Rev 1 01 Page 134 of 178 Sep 16 2011 RENESAS MR8C 4
19. sssssseeeeeemneennns 127 Figure 7 5 Example Cyclic Handler Written in C Language nennen nennen nennen enne nnns 128 Figure 7 6 Example Infinite Loop Task Described in Assembly Language ssssssesssissrsisrisiisrnsririnsinnintintnnnnsnnnnrnnninna 129 Figure 7 7 Example Task Terminating with ext tsk Described in Assembly Language eene 129 Figure 7 8 Example of kernel OS depend interrupt handler AE 130 Figure 7 9 Example of Non kernel OS independent Interrupt Handler of Specific Lee 131 Figure 7 10 Example Handler Written in Assembly L anoua0ge nennen enne nnne 131 Figure 7 11 C Language Startup Program ort mr a201 nennen nennen enne enne enne 136 Figure 8 1 The operation of the Configurator EEN 157 Figure 11 1 System Stack and User Stack A 166 Figure 11 2 ayout of Stacks 3 5 nop d ted pcc dz apa apelin d abet age a agat ge ad Dev ap ed ana tab k 167 Figure 11 3 Example of Use Stack Size Calculation sssssseseeeeeeeeennee KK K KE K E K RK EK EK nnne nnns 169 Figure 11 4 System Stack Calculation Method 171 Figure 11 5 Stack size to be used by Kernel Interrupt Handler AA 172 vi List of Tables Table 3 1 Task Context and Non task Context enne enne enne nnne nennen en nre nne nennen nnns 27 Table 3 2 Invocable Service Calls in a CPU Locked Gtate AAA 29 Table 3 3 CPU Locked and Dispatch Disabled State Transitions Relating to dis dsp and loc cpu ee 29 Table 5 1 Specifications of the Task
20. 5 rel wai S B Releases task from waiting O O O O 6 irel wai S B O O O O 7 sus_tsk S B Suspends task O O O O 8 rem tsk S B Resumes suspended task O O O O 9 dv tsk S B Delays task O O O Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T 99999 L N E D U Can be called from task context Can be called from non task context Can be called from dispatch enabled state Can be called from dispatch disabled state Can be called from CPU unlocked state Can be called from CPU locked state R20UT0657EJ0101 Rev 1 01 Sep 16 2011 132 N SAS Page 63 of 178 MR8C 4 5 Service call reference slp tsk Put task to sleep C Language API ER ercd slp tsk Parameters None e Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc slp tsk e Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code Error code E RLWAI Forced release from waiting R20UT0657EJ0101 Rev 1 01 Page 64 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference Functional description This service call places the issuing task itself from RUNNING state into sleeping wait state The task placed into WAIT ING state by execution of this service call is released from
21. MR8C 4 R20UT0657EJ0101 Sep 16 2011 6 Applications Development Procedure Overview Configuration file i E Standard MR8C 4 indude file Configurator eader file kernel h cfg8c Indude file kernel_id h kernel sysint h Application Indude file System data definition file include file mr8cinc Sys ram inc sys_rom inc Y Y Y Application Startup program Assembler source start a30 atOmr a30 Application C source J amp table file mrtable a30 Create amp table utility mr8ctbl file mrc MR8C 4 Library Relocatable Assembl er as30 C standard Library y Apel cation m Linkage Editor In30 Absolute module Load module converter Imc30 ROM write format E Figure 6 1 MR8C 4 System Generation Detail Flowchart Rev 1 01 Page 124 of 178 132 N SAS T Detailed Applications 7 1 Program Coding Procedure in C Language 7 1 1 Task Description Procedure 1 Describe the task as a function To register the task for the MR8C 4 enter its function name in the configuration file When for instance the function name task is to be registered as the task ID number 3 proceed as follows task 3 name ID_task entry_address task stack_size 100 priority 3 l 2 At the beginning of file be sure to include itron h kernel h which is in system directory as well as kern
22. RUNNIG state WAITING state RUNNING state Figure 3 15 Task Status The MR8C 4 controls the following six different states including the RUNNING and WAITING states 1 RUNNING state 2 READY state 3 WAITING state 4 SUSPENDED state 5 WAITING SUSPENDED state 6 DORMANT state Every task is in one of the above six different states Figure 3 16 shows task status transition R20UT0657EJ0101 Rev 1 01 Page 19 of 178 Sep 16 2011 132 NE SAS MR8C 4 READY state MPU exedusive right acguisi tion 3 Introduction to Kernel MPU execlusi ve right relinguishment RUNNING state Entering the WAITING state WAITING state SUSPENDED state clear SUSPEND request Forced Terminate from other task Fa et cee from other task request from other task WAITING SUSPENDED state WAITING state WAITING state dear SUSPENDED state DORMANT state Figure 3 16 MR8C 4 Task Status Transition SUSPEND request from other task SUSPENDED state dear reguest Forced termination reguest from other task Task acti vati on 1 RUNNING state In this state the task is being executed Since only one microcomputer is used it is natural that only one task is being executed The currently executed task changes into a different state when any of the following conditions occurs The task has normally terminated itself by ext tsk service call The task has place
23. SAS 4 Kernel MR8C 4 R20UT0657EJ0101 Rev 1 01 Sep 16 2011 Suspend task sus tsk Resume suspended task rsm tsk These service calls forcibly keep a task suspended for execution or resume execution of a task If a suspend re quest is issued to a task in READY state the task is placed into SUSPENDED state if issued to a task in WAIT state the task is placed into WAIT SUSPENDED state Since MR8C 4 allows only one forcible wait request to be nested if sus tsk is issued to a task in a forcible wait state the error E QOVR is returned See Figure 4 6 E QOVR sus tsk sus tsk rsm tsk Tak y E RUNNING SUSPENDED READY state state state WAITING WAITING state SUSPENDED WAITING state state Number of suspension 0 1 1 0 request Figure 4 6 Forcible wait of a task and resume Page 41 of 178 132 NE SAS MR8C 4 4 Kernel Release task from waiting rel wai rel wai Forcibly frees a task from WAITING state A task is freed from WAITING state by this service call when it is in one of the following wait states Delay wait state Wait state entered by slp tsk service call Event flag wait state Semaphore wait state Data transmission wait state Data reception wait state 99999 e Delay task dly tsk Keeps a task waiting for a finite length of time Figure 4 7 shows an example in which execution of a task is kept waiting for 10 ms by the dly tsk service call The delay time value should be specified
24. guarantee or permit the exercise of the right of software use 1 Hereinafter abbreviated real time OS uITRON4 0 Specification is the open real time kernel specification upon which the TRON association decided The specification document of uI TRONA 0 specification can come to hand from a TRON association homepage http www assoc tron org The copyright of uITRONA 0 specification belongs to the TRON association Contents Requirements for M R8C 4 Use ENEE i Document SE aire ipea epp nequam pa Cn prede hated iin rr epp pr Re i Right of Software U EE i le LUS ii IRC ge ga ele vi LASE OF TAD OSs LER vii 1 User s EivlfClelre CIE Le EE 1 2 General dt ge ge VE 2 2 1 Objective of MR8C 4 Development AA 2 2 2 Relationship between TRON Specification and MROCH 4 23 udi E s v m 5 3 Introduction to Kernel ET 6 3 1 e e e Zelle WEE Ce KC 6 3 L1 Why Realime pishNeeesary nnne nr enne nre sensere nnns 6 3 12 Operating Principles of Kernel eesssssssssseseeeesee enne KK KKK AKA nns nennen eene 9 3 2 Service UE 12 3 21 Service Call Processing essssssssssseesseeeeenee enne KA KEE KK KKK KK KKK A KKK KK nns tesi tes nn nennt 13 3 2 2 Processing Procedures for Service Calls from Handlers sse 14 Service Calls from a Handler That Caused an Interrupt during Task Esvection eee eee eee eee 15 Service Calls from a Handler That Caused an Interrupt durin
25. 1 The operation of the Configurator 8 2 2 Setting Configurator Environment Before executing the configurator check to see if the environment variable LIB8C is set correctly The configurator cannot be executed normally unless the following files are present in the directory indicated by the en vironment variable LIB8C Default configuration file default cfg This file can be copied to the current directory for use In this case the file in the current directory is given priority e System RAM area definition database file sys ram inc mr8c inc template file mr8c inc Section definition file c sec inc or asm sec inc e Startup file crtOmr a30 or start a30 MR8C 4 version file version Service call information file kernel sysint h 8 2 3 Configurator Start Procedure Start the configurator as indicated below C cfg8c vV Configuration file name Normally use the extension cfg for the configuration file name R20UT0657EJ0101 Rev 1 01 Page 157 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator 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 Error messages cfg8c Error syntax error near line xxx xxxx cfg There is an syntax error in the configuration file cfg8c Error not enough memory Memory is insufficient cfg8c Error ille
26. 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 in creased ROM capacity of 32K bytes As such large ROM capacity microcomputers are introduced their program development is not easily carried out by con ventional 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 period increases expo nentially 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 4 8 16 32 Kbyte Program Size Figure 3 1 Relationship between Program Size and Development Period Under these circumstances it is necessary to adopt a method by which large size programs can be developed within a short period of time One way to achieve this purpose is to use a large number of microcomputers 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 performed R20UT0657EJ0101 Rev 1 01 Page 6 of 178 Sep 16 2011 134 NE SAS MR8C 4 3 Introductio
27. ID tskid Parameters ID tskid ID number of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc rsm tsk TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code AO ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is not a forcible wait state Functional description If the task indicated by tskid has been aborted by sus tsk this service call resumes the target task from SUSPENDED state In this case the target task is linked to behind the tail of the ready queue If a request is issued while the target task is not in SUSPENDED state including DORMANT state the error code E OBJ is returned to the service call issuing task The rsm tsk service call each operate the same way because the maximum number of forcible wait requests that can be nested is 1 This service call can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 74 of 178 Sep 16 2011 132 N SAS MR8C 4 Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void taskl if rsm_tsk ID_main E_OK printf Can t resume main n
28. Ox7fffffff time tick If any value exceeding this limit is specified the service call may not operate correctly If 0 is specified for almtim the alarm handler is started at the next time tick This service call can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 104 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task sta alm ID alm1 100 lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 sta alm ID_ALM1 100 R20UT0657EJ0101 Rev 1 01 Page 105 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference stp alm Stop alarm handler operation C Language API ER ercd stp alm ID almid Parameters ID almid ID number of the alarm handler to be stopped Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc stp alm ALMID e Parameters ALMID ID number of the alarm handler to be stopped Register contents after service call is issued Register name Content after service call is issued RO Error code A0 ID number of the alarm handler to be stopped Error code None Functional description This service call places the alarm han
29. RAM data used by MR8C 4 146 173 in Figure 7 11 Sets the bit which shows the end of start up processing 176 in Figure 7 11 Activate the initial startup task 182 in Figure 7 11 10 This is a system clock interrupt handler 221 236 in Figure 7 11 R20UT0657EJ0101 Rev 1 01 Sep 16 2011 Page 136 of 178 132 NE SAS MR8C 4 7 Detailed Applications 7 4 Memory Allocation This section describes how memory is allocated for the application program data The sections which are used by MR8C 4 is describe in c sec inc or asm sec inc To set the memory arrangement it changes on High performance Embedded Workshop MR8C 4 comes with the following two types of section files asm sec inc This file is used when you developed your applications with the assembly language c sec inc This file is used when you developed your applications with the C language c sec inc is derived from asm sec inc by adding sections generated by C compiler NC30 Modify the section allocation and start address settings in this file to suit your system R20UT0657EJ0101 Rev 1 01 Page 137 of 178 Sep 16 2011 ENESAS MR8C 4 7 Detailed Applications 7 4 1 Sections that kernel uses The section allocation of the sample startup program for the assembly language start a30 is defined in asm sec inc The section allocation of the sample startup program for the C language crtOmr a30 is defined in c sec inc It explains each section that MR8
30. Rev 1 01 Page 169 of 178 Sep 16 2011 132 N SAS MR8C 4 11 Stack Size Calculation Method 11 1 2 System Stack Calculation Method The system stack is most often consumed when an interrupt occurs during service call processing followed by the occur rence of multiple interrupts The necessary size the maximum size of the system stack can be obtained from the fol lowing relation Necessary size of the system stack a Xfi y The maximum system stack size among the service calls to be used When sta_tsk ext_tsk slp_tsk and dly_tsk are used for example according to the Table 11 1 Stack Sizes Used by Service Calls Issued from Tasks in bytes each of system stack size is the following Service Call name System Stack Size sta_tsk 2bytes ext_tsk Obytes slp_tsk 2bytes dly_tsk 4bytes Therefore the maximum system stack size among the service calls to be used is the 8 bytes of dly_tsk epi The stack size to be used by the interrupt handler The details will be described later ey Stack size used by the system clock interrupt handler This is detailed later 38 After switchover from user stack to system stack 3 Refer from Table 11 1 Stack Sizes Used by Service Calls Issued from Tasks in bytes to Table 11 3 Stack Sizes Used by Service Calls Issued from Tasks and Handlers in bytes for the system stack size used for each individual service call OS dependent interrupt handler
31. Symbol Definition range None Default value stack Define the section name in which the stack is located The section defined here must always have an area allo cated for it in the section file asm sec inc or c sec inc If no section names are defined the stack is located in the stack section 7 TA ACT attribute initial startup state 8 Definition format Symbol Definition range ON or OFF Default value OFF Define the initial startup state of a task If this attribute is specified ON the task goes to a READY state at the initial system startup time The task startup code of the initial startup task is 0 One or more tasks must have TA ACT attribute Extended information Definition format Numeric value Definition range 0 to OXFFFF Default value 0 Define the extended information of a task This information is passed to the task as argument when it is re started by a gueued startup reguest for example Eventflag definition This definition is necessary to use Eventflag function lt lt Format gt gt Eventflag Definition flag ID No II name Name initial pattern Initial value of the event flag wait multi Multi wait attribute clear attribute Clear attribute The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequen
32. This symbol cannot be omitted cfg8c Error start up file XXXX not found The start up file XXXX cannot be found in the current directory The startup file start a30 or crtOmr a30 is required in the current directory cfg8c Error bad start up file XXXX There is unnecessary start up file in the current directory cfg8c Error no source file No source file is found in the current directory cfg8c Error zero divide error near line xxx xxxx cfg A zero divide operation occurred in some arithmetic expression cfg8c Error task X stack size must set XX or more near line xxx xxxx cfg You must set more than XX bytes in task x stack size R20UT0657EJ0101 Rev 1 01 Page 159 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator cfg8c Error RO and R1 must exist in task x context near line xxx xxxx cfg You must select RO and RI register in task x context cfg8c Error can t define address match interrupt definition for Task Pause Functio n near line xxx xxxx cfg Another interrupt is defined in interrupt vector definition needed by Task Pause Function cfg8c Error Set system timer system timeout YES near line xxx xxxx cfg Set clock timer symbol except NOTIMER cfg8c Error Initial Start Task not defined No initial startup task is defined in the configuration file R20UT0657EJ0101 Rev 1 01 Page 160 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator Warning messages T
33. by Service Calls Issued from Tasks in bytes Service call Stack size Service call Stack size User stack System User stack System stack stack sta tsk 0 2 sta cyc 10 0 ext tsk 0 0 stp cyc 10 0 ter tsk 0 4 sta alm 10 0 chg pri 0 4 stp alm 10 0 slp tsk 0 2 get tid 10 5 0 wup tsk 0 2 loc cpu 4 0 can wup 10 0 unl cpu 0 0 rel wai 0 4 ref ver 12 0 sus tsk 0 2 dis dsp 4 0 rsm tsk 0 2 ena dsp 0 0 dv tsk 0 4 snd dtq 0 4 sig sem 0 2 psnd dtq 0 2 wal sem 0 2 rev dtq 5 2 pol_sem 10 0 prev dtg 5 2 set flg 0 6 clr flg 10 0 wai flg 5 2 pol flg 10 5 0 Stack sizes used by service call in C programs Tabl e 11 2 Stack Si zes Used by Servi ce Cal s ssued f romHandl ers i n bytes lists the stack sizes system stack used by service calls that can be issued from handlers Table 11 2 Stack Sizes Used by Service Calls Issued from Handlers in bytes Service call Stack size Service call Stack size iwup tsk 14 iset flg 22 irel wai 14 ipsnd dtq 6 1sig sem 4 ret int 10 ista tsk 14 Stack sizes used by service call in C programs Table 11 3 Stack Si zes Used by Servi ce Calls Issued fromTasks and Handi ers i n bytes lists the stack sizes system stack used by service calls that can be issued from both tasks and handlers If the service call issued from task system uses user stack If the service call issued from
34. from a CPU locked state that was set by the loc cpu service call If the unl cpu service call is issued from a dispatching enabled state task scheduling is performed The CPU locked state and the dispatching disabled state are managed independently of each other Therefore the system cannot be freed from a dispatching disabled state by the unl cpu service call unless the ena dsp service call is used This service call can only be issued from task context and cannot be issued from non task context Example program statement Example statement in C language include lt itron h gt include lt kernel h gt include kernel id h void task unl cpu lt lt Example statement in assembly language gt gt include mr8c inc GLB task task unl_cpu R20UT0657EJ0101 Rev 1 01 Page 111 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference dis dsp Disable dispatching C Language API ER ercd dis dsp Parameters None e Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc dis dsp Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Funcional description This service call places the system into a dispatching disabled state The features of a dispatching disabled state are outlined below 1 Since task s
35. from data gueue o O O O polling Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 99999 R20UT0657EJ0101 Rev 1 01 Sep 16 2011 132 N SAS Page 91 of 178 MR8C 4 5 Service call reference snd dtg Send to data gueue psnd dtg Send to data gueue polling ipsnd dtg Send to data gueue polling handler only C Language API ER ercd snd dtq ID dtqid VP INT data ER ercd psnd dtq ID dtqid VP INT data ER ercd ipsnd dtq ID dtgid VP INT data e Parameters ID dtqid ID number of the data queue to which transmitted VP INT data Data to be transmitted e Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc snd dtq DTOID DTODATA psnd dtq DTOID DTODATA ipsnd dtq DTOID DTODATA e Parameters DTQID ID number of the data queue to which transmitted DTQDATA Data to be transmitted Register contents after service call is issued Register name Content after service call is issued RO Error code RI Data to be transmitted A0 ID number of the data gueue
36. generates the file kernel id h that is used to convert the ID number of a task into the string to be specified This means that the define declaration necessary to convert the string specified in the task definition item name into the ID number of the task is made in kernel id h The same applies to the cyclic and alarm handlers 5 The task starts from its start function with the initial priority in a wakeup counter cleared state R20UT0657EJ0101 Rev 1 01 Page 126 of 178 Sep 16 2011 13 NE SAS MR8C 4 7 Detailed Applications 7 1 2 Writing a Kernel OS Dependent Interrupt Handler When describing the kernel OS dependent interrupt handler in C language observe the following precautions 1 Describe the kernel OS dependent interrupt handler as a function 2 Be sure to use the void type to declare the interrupt handler start function return value and argument 3 At the beginning of file be sure to include itron h kernel h which is in the system di rectory as well as kernel id h which is in the current directory Do not use the ret int service call in the interrupt handler 5 The static declared functions can not be registered as an interrupt handler include lt itron h gt include lt kernel h gt include kernel id h void inthand void process iwup_tsk ID_main Figure 7 3 Example of Kernel OS dependent Interrupt Handler 7 1 3 Writing Non kernel OS independent Interrupt Handl
37. handler system uses system stack Table 11 3 Stack Sizes Used by Service Calls Issued from Tasks and Handlers in bytes R20UT0657EJ0101 Service call Stack size Service call Stack size sns ctx 10 sns loc 10 sns dsp Rev 1 01 10 132 NE SAS Page 174 of 178 12 Note 12 1The Use of INT Instruction MR8C 4 has INT instruction interrupt numbers reserved for issuing service calls as listed in Table 12 1 Interrupt Number Assignment For this reason when using software interrupts in a user application do not use interrupt numbers 63 through 48 and be sure to use some other numbers Table 12 1 Interrupt Number Assignment Interrupt No Service calls Used 32 Service calls that can be issued from only task context 33 Service calls that can be issued from only non task context Service calls that can be issued from both task context and non task context 34 ret int service call 35 dis dsp service call 36 loc cpu iloc cpu service call 37 ext tsk service call 38 Reserved for future extension 39 Reserved for future extension 40 Reserved for future extension 12 2The Use of registers of bank The registers of bank is 0 when a task starts on MR8C 4 MR8C 4 does not change the registers of bank in processing kernel You must pay attention to the followings Don t change the regisers of bank in processing a task e If an interru
38. handler or the time event handler is ter minated If either handler terminates while the system is in a CPU locked state handler operation cannot be guaranteed Note that the system is always in a CPU unlocked state when these handlers start Invoking this service call again while the system is already in a CPU locked state does not cause an error in which case task queuing is not performed however This service call can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 109 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task loc cpu lt lt Example statement in assembly language gt gt include mr8c inc GLB task task ian ed R20UT0657EJ0101 Rev 1 01 Page 110 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference unl cpu Unlock the CPU C Language API ER ercd unl cpu Parameters None Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc unl cpu e Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Funcional description This service call frees the system
39. in ms units and not in time tick units dly tsk 10 Task 9 HM Se SS Se 44 10msec _______ Figure 4 7 dly_tsk service call R20UT0657EJ0101 Rev 1 01 Page 42 of 178 Sep 16 2011 2tENESAS MR8C 4 4 Kernel 4 2 3 Synchronization and Communication Function Semaphore The semaphore is a function executed to coordinate the use of devices and other resources to be shared by several tasks in cases where the tasks simultaneously reguire the use of them When for instance four tasks simultaneously try to acguire a total of only three communication lines as shown in Figure 4 8 communication line to task connections can be made without incurring contention Communication Line Communication Line Communication Line Semaphore x Figure 4 8 Exclusive Control by Semaphore The semaphore has an internal semaphore counter In accordance with this counter the semaphore is acguired or released to prevent competition for use of the same resource See Figure 4 9 Acauired Returned after use Figure 4 9 Semaphore Counter R20UT0657EJ0101 Rev 1 01 Page 43 of 178 Sep 16 2011 134 N SAS MR8C 4 4 Kernel Figure 4 10 shows example task execution control provided by the wai sem and sig sem service calls wai sem sig sem Task oo wai sem Task l e l wai_sem Task E GE ol wai sem Task WAIT state e l
40. 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 Preface The MR8C 4 is a real time operating system for R8C Family microcomputers The MR8C 4 conforms to the uITRON Specification This manual describes the procedures and precautions to observe when you use the MR8C 4 for programming purposes For the detailed information on individual service call procedures refer to the MR8C 4 Reference Manual Requirements for MR8C 4 Use When creating programs based on the MR8C 4 it is necessary to purchase the following product of Renesas C compiler package M3T NC30WA abbreviated as NC30 for the M16CSeries and R8C Family micro computers Document List The following sets of documents are supplied with the MR8C 4 Release Note Presents a software overview and describes the corrections to the Users Manual and Reference Manual e Users Manual PDF file Describes the procedures and precautions to observe when using the MR8C 4 for programming purposes Right of Software Use The right of software use conforms to the software license agreement You can use the MR8C 4 for your product develop ment purposes only and are not allowed to use it for the other purposes You should also note that this manual does not
41. issue system call 229 For PD30 230 ISSUE SYSCALL 231 232 233 System timer interrupt handler 234 STMR hdr 239 ret int 236 endif 237 238 end 7 Detailed Applications Figure 7 11 C Language Startup Program crtOmr a30 The following explains the content of the C language startup program crtOmr a30 E SES a 46 185 in Figure 7 11 Incorporate a section definition file 11 in Figure 7 11 Incorporate an include file for MR8C 4 12 in Figure 7 11 Incorporate a system ROM area definition file 13 in Figure 7 11 Incorporate a system RAM area definition file 14 in Figure 7 11 This is the initialization program SYS INITIAL that is activated immediately after a reset Setting the System Stack pointer 50 in Figure 7 11 9999 o Setting the processor mode register 52 54 in Figure 7 11 Setting the SB FB register 55 57 in Figure 7 11 Initial set the C language 76 92 in Figure 7 11 Setting OS interrupt disable level 104 106 in Figure 7 11 Setting the address of interrupt vector table 107 and 108 in Figure 7 11 Set MR8C 4 s system clock interrupt 114 124 in Figure 7 11 Initialization of standard I O function 96 97 in Figure 7 11 When using no standard input output functions remove the lines 96 and 97 in Figure 7 11 Initial set MR8C 4 s system timer 129 133 in Figure 7 11 o OND Initial set parameters inherent in the application 140 in Figure 7 11 Initialize the
42. language startup program crtOmr a30 if no standard I O function is used R20UT0657EJ0101 Rev 1 01 Page 132 of 178 Sep 16 2011 2tENESAS MR8C 4 7 3 1 Figure 7 11 shows the C language startup program crtOmr a30 C Language Startup Program crtOmr a30 7 Detailed Applications 1 gt ck ck ck ck ck ck Sk ck ke ck ck A AA Ck ck A KA XK A AX KA ck ck ck KA X ck ck A A KA X AZ A ZA AX KA ck ck ck KA ck ck ck ck ck ck ko Sk ke kx kx ko 2 33 MR8C start up program for C language 4 MR8C 4 Realtime Operating System based on Micro ITRON Spec Dis Copyright C 2009 2011 Renesas Electronics Corporation 6 and Renesas Solutions Corp All Rights Reserved 7 D 8 ck ck ck ck 0k ck KKK KKK KKK KKK KKK KKK KKK KA KK KKK AX KA KK AKA KKK KKK KA KA K KK Sk A ko ko ko 9 Id crtOmr a30 519 2006 04 24 13 36 302 inui 10 11 list OFF 12 include c sec inc 13 include mr8c inc 14 include sys rom inc 15 include sys ram inc 16 list ON 17 18 19 SBDATA area definition 20 21 glb _ SB 22 B __ SB 23 24 25 Initialize Macro declaration 26 27 N_BZERO smacro TOP_ SECT_ 28 mov b 00H ROL 29 mov w TOP_ amp OFFFFH Al 30 mov w sizeof SECT R3 31 sstr b 32 endm 33 34 N BCOPY macro FROM TO SECT 35 mov w FROM_ amp OFFFFH A0 36 mov b FROM 16 R1H 37 mov w STO Al 38 m
43. lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 stp cyc ID_CYC1 R20UT0657EJ0101 Rev 1 01 Page 102 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference 5 8 Time Management Function Alarm Handler Specifications of the alarm handler function of MR8C 4 are listed in Table 5 14 The alarm handler description languages in item No 4 are those specified in the GUI configurator They are not output to a configuration file nor are the MR8C 4 kernel concerned with them Table 5 14 Specifications of the Alarm Handler Function No Item Content 1 Alarm handler ID 1 255 2 Activation time O 7fffffff ms 3 Extended information 16 bits 4 Alarm handler attribute TA HLNG Handlers written in high level language TA ASM Handlers written in assembly language Table 5 15 List of Alarm Handler Function Service Call No Service Call Function System State NE D 1 sta_alm Starts alarm handler operation o o 2 stp alm Stops alarm handler operation O o o OO Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be cal
44. means of specifying the task by name function or symbol name The program named configurator cfg8c which is supplied with the MR8C 4 then automatically converts the task name to the task ID number This task identification system is schematized in Figure 3 14 sta tsk Task name Starting the task having the designated Name gt ID number ID number Configurator Program Real time OS Figure 3 14 Task Identification sta tsk ID task stacd This example specifies that a task corresponding to ID task be invoked It should also be noted that task name to ID number conversion is effected at the time of program generation Therefore the processing speed does not decrease due to this conversion feature R20UT0657EJ0101 Rev 1 01 Page 18 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel 3 4 Task This section describes how tasks are managed by MR8C A 3 4 1 Task Status The real time OS monitors the task status to determine whether or not to execute the tasks Figure 3 15 shows the relationship between key input task execution control and task status When there is a key input the key input task must be executed That is the key input task is placed in the execution RUNNING state While the system waits for key input task execution is not needed In that situation the key input task in the WAITING state Key input Task Key input Waiting for Key input processing key input processing
45. name ID name initial_count Initial value of semaphore counter max_count Maximum value of the semaphore counter l The ID number must be in the range of 1 to 255 The ID number can be omitted R20UT0657EJ0101 Rev 1 01 Page 147 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator If omitted numbers are automatically assigned seguentially beginning with the smallest lt lt Content gt gt Define the following for each semaphore ID number 1 ID Name Definition format Symbol Definition range None Default value None Define the name with which a semaphore is specified in a program 2 Initial value of semaphore counter Definition format Numeric value Definition range 0 to 65535 Default value 1 Define the initial value of the semaphore counter 3 Maximum value of the semaphore counter Definition format Numeric value Definition range 1 to 65535 Default value 1 Define the maximum value of the semaphore counter Data queue definition This definition must always be set when the data queue function is to be used lt lt Format gt gt Dataqueue Definition dataqueue ID No name ID name buffer size Number of data queues D I The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are automatically assigned in order of n
46. nter inerenti semestre nre 39 Figure 4 4 Wakeup Request Gtorage AEN 40 Figure 4 5 Wakeup Request Cancellatton AANEREN 40 Figure 4 6 Forcible wait of a task and reeume enne nnne nenne nennen nen nennen nnns 4 Figure4 dl tsk servi ce calls trt ends O ev iere este ae ir ere b e d Rs 42 Figure 4 8 Exclusive Control by Gemapbore nennen eene enne nenne nnne tenete nennen nen nennen nnns 43 Fig re4 9 Semaphore Counter ior eese ecce EE reto eeu DM E DU EE Edu LR 43 Figure 4 10 Task Execution Control by Gematpbore ener enne nennen nen nennen nennen 44 Figure 4 11 Task Execution Control by hetventflag AAA 45 Figure 4 12 Data queue miona iiaiai inaina etn tee tine tea n e er e ERR cce d reet Ee rebos 47 Figure 4 13 Cyclic handler operation in cases where the activation phase is soe 49 Figure 4 14 Cyclic handler operation in cases where the activation phase is not saved 49 Figure 4 15 Typical operation of the alarm handler 2 s eee eens eee eee eee eee eee nene eene nennen nennen nennen nnns 50 Figure Te interrupt process EE 52 Figure 6 1 MR8C 4 System Generation Detail Flowchart essen nennen nennen nnne nnns 124 Figure 7 1 Example Infinite Loop Task Described in C Language nennen 125 Figure 7 2 Example Task Terminating with ext tsk Described in C Language 126 Figure 7 3 Example of Kernel OS dependent Interrupt Handler A 127 Figure 7 4 Example of Non kernel OS independent Interrupt Handler
47. of whether it is explicitly written when terminated Terminate Task ter tsk Other tasks in other than DORMANT state are forcibly terminated and placed into DORMANT state If startup requests are accumulated task startup processing is performed again In that case the task behaves as if it was re set See Figure 4 2 Startup request count gt 0 TaskB ter tsk B Terminated Task B reset Figure 4 2 Task Resetting Change Task Priority chg pri If the priority of a task is changed while the task is in READY or RUNNING state the ready queue also is up dated See Figure 4 3 R20UT0657EJ0101 Rev 1 01 Page 38 of 178 Sep 16 2011 132 NE SAS MR8C 4 4 Kernel Priority 1 X TaskA Cp Task B H U 3 Task C Task B gt Task D l L 4 n L TaskE gt Task F When the priority of task B has been changed from 3 to 1 Figure 4 3 Alteration of task priority Reference task status simple version ref tst iref tst Refers to the state of the target task Reference task status ref tsk iref tsk Refers to the state of the target task and its priority etc R20UT0657EJ0101 Rev 1 01 Page 39 of 178 Sep 16 2011 132 N SAS MR8C 4 4 Kernel 4 2 2 Task Dependent Synchronization Function The task dependent synchronization functions attached to task is used to accomplish synchroniza
48. system startup in the configuration file 7 2 2 Writing Kernel OS dependent Interrupt Handler When describing the kernel OS dependent interrupt handler in assembly language observe the following precautions 1 At the beginning of file be sure to include mr8c inc which is in the system directory 2 For the symbol indicating the interrupt handler start address make the external declara tion Global declaration 3 Make sure that the registers used in a handler are saved at the entry and are restored after use 4 Return to the task by ret int service call INCLUDE mr8c inc 1 GLB inth 2 inth Registers used are saved to a stack 3 iwup tsk d4ID taskl process Registers used are restored 3 ret int 4 Figure 7 8 Example of kernel OS depend interrupt handler 7 2 3 Writing Non kernel OS independent Interrupt Handler 1 For the symbol indicating the interrupt handler start address make the external declaration public declaration 2 Make sure that the registers used in a handler are saved at the entry and are restored after use 3 Be sure to end the handler by REIT instruction No service calls can be issued from a non kernel an OS independent interrupt handler NOTE If this restriction is not observed the software may malfunction 31 The relationship between task ID numbers and tasks program is defined in the configuration file Use th
49. target task Error code E OBJ Object status invalid task indicated by tskid is not DOMANT state R20UT0657EJ0101 Rev 1 01 Page 55 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference Functional description This service call starts the task indicated by tskid In other words it places the specified task from DORMANT state into READY state or RUNNING state This service call does not enqueue task activation requests Therefore if a task activa tion request is issued while the target task is not DORMANT state the error code E OBJ is returned to the service call is suing task This service call is effective only when the specified task is in DORMANT state The task start code stacd is 16 bits long This task start code is passed as parameter to the activated task If a task is restarted that was once terminated by ter tsk or ext tsk the task performs the following as it starts up 1 Initializes the current priority of the task 2 Clears the number of queued wakeup requests 3 Clears the number of nested forcible wait requests If this service call is to be issued from task context use sta tsk if issued from non task context use ista tsk Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task ER ercd VP_INT stacd 0 ercd sta_tsk ID_task2 stacd void task2 VP_INT msg
50. the wait state in the following cases When a task wakeup service call is issued from another task or an interrupt The error code returned in this case is E OK When a forcible awaking service call is issued from another task or an interrupt The error code returned in this case is E RLWAI If the task receives sus tsk issued from another task while it has been placed into WAITING state by this service call it goes to WAITING SUSPENDED state In this case even when the task is released from WAITING state by a task wakeup service call it still remains in SUSPENDED state and its execution cannot be resumed until rsm tsk is issued This service call can only be issued from task context and cannot be issued from non task context Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if slp_tsk E_OK error Forced wakeup n lt lt Example statement in assembly language gt gt include mr8c inc GLB task task slp tsk R20UT0657EJ0101 Rev 1 01 Page 65 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference wup tsk Wakeup task iwup tsk Wakeup task handler only C Language API ER ercd wup tsk ID tskid ER ercd iwup tsk ID tskid e Parameters ID tskid ID number of the target task e Return Parameters ER ercd Terminated normally E OK or err
51. to which transmitted Error code E RLWAI Forced release from waiting E TMOUT Polling failure Functional description This service call sends the 2 byte data indicated by data to the data queue indicated by dtgid If any task is kept waiting for reception in the target data queue the data is not stored in the data queue and instead sent to the task at the top of the recep tion waiting queue with which the task is released from the reception wait state On the other hand if snd dtq is issued for a data queue that is full of data the task that issued the service call goes from RUNNING state to a data transmission wait state and is enqueued in transmission waiting queue kept waiting for the data queue to become available In that case if the attribute of the specified data queue is TA TFIFO the task is enqueued in order of FIFO For psnd dtq and ipsnd dtq the task returns immediately and responds to the call with the error code E TMOUT If there are no tasks waiting for reception nor is the data queue area filled the transmitted data is stored in the data queue The task placed into WAITING state by execution of the snd dtg service call is released from WAITING state in the fol lowing cases When the rcv dtq or prov dtq service call is issued with task awaking conditions thereby satis fied The error code returned in this case is E OK When the task is forcibly released from WAITING state by the rel wai or irel wai ser
52. tsk ID main 8 To specify an event flag semaphore or data queue use the respective strings defined in the configuration file For example if an event flag is defined in the configuration file as shown below flag 1 name ID_abc D I To designate this eventflag proceed as follows set flg ID abc amp setptn 9 To specify a cyclic or alarm handler use the string written in the cyclic or alarm handler definition item name of the configuration file sta cyc ID cyo 10 When a task is reactivated by the sta tsk service call after it has been terminated by the ter tsk service call the task itself starts from its initial state However the external va riable and static variable are not automatically initialized when the task is started The ex ternal and static variables are initialized only by the startup program crtOmr a30 which actuates before MR8C 4 startup 11 The task executed when the MR8C 4 system starts up is setup 12 The variable storage classification is described below The MR8C 4 treats the C language variables as indicated in Table 7 1 C Language Variable Treatment Table 7 1 C Language Variable Treatment Variable storage class Treatment Global Variable Variable shared by all tasks Non function static variable Variable shared by the tasks in the same file Auto Variable Register Variable Variable for specific task Static variable in function The configurator
53. 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 but Renesas E
54. uses interrupt stack ISP Task M8 4 Servi ce Call Processi ng Posi ti on Register save Stack switching User Stack System Stack XXX XXX ES interruput stack Task Seledion Stack switching Register return User Stack Figure 11 1 System Stack and User Stack The sections of the system stack and user stack each are located in the manner shown below However the diagram shown R20UTO657EJO0101 Rev 1 01 Page 166 of 178 Sep 16 2011 RENESAS MR8C 4 11 Stack Size Calculation Method below applies to the case where the stack areas for all tasks are located in the stack section during configuration System Stack User satck of Taskl D No 1 User satck of Taskl D No 2 User satck of Taskl D No n Stack Section Figure 11 2 Layout of Stacks R20UT0657EJ0101 Rev 1 01 Page 167 of 178 Sep 16 2011 132 N SAS MR8C 4 11 Stack Size Calculation Method 11 1 1 User Stack Calculation Method User stacks must be calculated for each task The following shows an example for calculating user stacks in cases when an application is written in the C language and when an application is written in the assembly language When an application is written in the C language Using the stack caliculation utility calculate the stack size of each task The necessary stack size of a task is the sum of the stack size output by STK Viewer plus a context storage area of 20 bytes The following shows
55. wait condition for a task in the WAITING SUSPENDED state is cleared that task goes into the SUS PENDED 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 service call issuance Ke Depends on dly tsk slp tsk wai flg wai sem snd dro and rcv dro service call If a forcible wait request is issued to a task currently in a wait state the task goes to a WAITING SUSPENDED state R20UT0657EJ0101 Rev 1 01 Page 21 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel The task placed in the WAITING state by the dly tsk service call wakes up after the specified time elapse The request of the task placed in the WAITING state by the wai flg wai sem snd do or rcv do service call is fulfilled The WAITING state is forcibly cleared by the rel wai or irel wai service call When the SUSPENDED state clear request by rsm tsk or irsm tsk is made to a task in the WAIT ING SUSPENDED state that task goes into the WAITING state Since a task in the SUSPENDED state cannot request to be placed in the WAITING state status change from SUSPENDED to WAITING SUSPENDED does not possibly occur 6 DORMANT This state refers to the condition in which a task is registered in the MR8C 4 system but not activated This task state prevails when either of the following two conditions occurs The task is waiting to be activated
56. 0 1 Overview of Sample Program As an example application of MR8C 4 the following shows a program that outputs a string to the standard output device from one task and another alternately Table 10 1 Functions in the Sample Program Function Type ID No Priority Description Name main Task 1 1 Starts task and task2 task1 Task 2 2 Outputs task1 running task2 Task 3 3 Outputs task2 running cyhl Handler 1 Wakes up task1 The content of processing is described below e The main task starts task1 task2 and cyh1 and then terminates itself task1 operates in order of the following 1 Gets a semaphore 2 Goes to a wakeup wait state 3 Outputs task1 running 4 Frees the semaphore e task2 operates in order of the following 1 Gets a semaphore 2 Outputs task2 running 3 Frees the semaphore cyhl starts every 100 ms to wake up task1 R20UTO657EJO0101 Rev 1 01 Page 163 of 178 Sep 16 2011 RENESAS MR8C 4 10 Sample Program Description 10 2Program Source Listing a P e k ok ok ok kk k ok k ok k ok k E kk kk kkk oko ok ok kok kok kok kok kk kk kk kok kok kok k k kok kok kok kok kok kok k k k kk 2 MR8C 4 smaple program 3 4 Copyright C 2009 2011 Renesas Electronics Corporation 5 and Renesas Solutions Corp All rights reserved 6 7 8 Id demo c 496 2006 04 05 06 28 56Z inui 9 K kk kk kk kk kk kk kk kk kk kk kk kk kk kk k kk
57. 0 ID number of the eventflag to be cleared R3 Bit pattern to be cleared Error code None Funcional description Of the 16 bit eventflag indicated by flgid this service call clears the bits whose corresponding values in clrptn are 0 In other words the eventflag bit pattern indicated by flgid is updated by AND ing it with clrptn If all bits specified in clrptn are 1 no operation will be performed for the target eventflag in which case no errors are assumed however This service call can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 86 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task void clr flg ID flg FLGPTN 0xf0f0 lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 R3 clr fig ID_FLG1 0f0f0H R20UT0657EJ0101 Rev 1 01 Page 87 of 178 Sep 16 2011 131 N SAS MR8C 4 5 Service call reference wai flg Wait for eventflag pol flg Wait for eventflag polling C Language API ER ercd wai flg ID flgid FLGPTN waiptn MODI ER ercd pol flg ID flgid FLGPTN waiptn MODI e Parameters wfmode FLGPTN p flgptn wfmode FLGPTN p flgptn Di u ID flg
58. 0x0000 52 wait multi TA WMUL 53 clear attribute YES 54 j 55 semaphore 1 56 name SEM_ID1 57 initial_count 0 58 59 60 interrupt_vector 22 61 os_int YES 62 entry_address inth 63 64 65 66 End of Configuration 67 R20UT0657EJ0101 Rev 1 01 Page 155 of 178 Sep 16 2011 132 N SAS MR8C 4 8 Using Configurator 8 2 Configurator Execution Procedures 8 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 8 1 outlines the operation of the configurator When used on High performance Embedded Workshop the configurator is automatically started and an application pro gram is built 1 Executing the configurator requires the following input files Configuration file XXXX cfg This file contains description of the system s initial setup items It is created in the current directory Default configuration file default cfg This file contains default values that are referenced when settings in the configuration file are omitted This file is placed in the directory indicated by environment variable LIB8C or the current directory If this file exists in both directories the file in the current directory is prioritized over the other include template file mr8c inc sys ram inc kernel sysint h This file serves as the template file of include file mr8c inc k
59. 11 132 N SAS MR8C 4 5 Service call reference 5 3 Synchronization amp Communication Function Semaphore Specifications of the semaphore function of MR8C 4 are listed in Table 5 5 Table 5 5 Specifications of the Semaphore Function No Item Content 1 Semaphore ID 1 255 Maximum number of resources 1 65535 3 Semaphore attribute TA FIFO Tasks engueued in order of FIFO Table 5 6 List of Semaphore Function Service Call No Service Call Function System State D O O 1 sig_sem S B Releases semaphore 2 isig sem S B resource 3 wai_sem S B Acquires semaphore resource 4 pol_sem S B Acquires semaphore resource polling O O IO o O ololjojm O Ololo c Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 99999 R20UT0657EJ0101 Rev 1 01 Page 78 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference sig sem Release semaphore resource isig sem Release semaphore resource handler only C Language API ER ercd sig sem ID semid ER ercd isig sem I
60. 424 NEC SAS C CD D o lt D C v MR8C 4 V 1 01 User s Manual Real time OS for R8C Family All information contained in these materials including products and product specifications represents information on the product at the time of publication and is subject to change by Re nesas Electronics Corporation without notice Please review the latest information published by Renesas Electronics Corporation through various means including the Renesas Electronics Corporation website http www renesas com Renesas Electronics Rev 1 01 September 2011 WWW renesas com 8 10 11 12 Notice All information included in this document is current as of the date this document is issued Such information however is subject to change without any prior notice Before purchasing or using any Renesas Electronics products listed herein please confirm the latest product information with a Renesas Electronics sales office Also please pay regular and careful attention to additional and different information to be disclosed by Renesas Electronics such as that disclosed through our website Renesas Electronics does not assume any liability for infringement of patents copyrights or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document No license express implied or otherwise is granted hereby
61. 57EJ0101 Rev 1 01 Page 158 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator number must be smaller than the total number of objects cfg8c Error too big task x s priority gt xx near line xxx xxxx cfg The initial priority in task definition of ID number x exceeds the priority in system definition cfg8c Error too big IPL gt xx near line xxx xxxx cfg The system clock interrupt priority level for system clock definition item exceeds the value of IPL within ser vice call of system definition item cfg8c Error system timer s vector lt x gt conflict near line xxx A different vector is defined for the system clock timer interrupt vector Confirm the vector No x for interrupt vector definition cfg8c Error XXXX is not defined xxxx cfg XXXX item must be set in your configuration file cfg8c Error system s default is not defined These items must be set int the default configuration file cfg8c Error double definition lt XXXX gt near line xxx xxx cfg XXXX is already defined Check and delete the extra definition cfg8c Error double definition XXXX x near line xxx default cfg cfg8c Error double definition XXXX x near line xxx xxxx cfg The ID number in item XXXX is already registered Modify the ID number or delete the extra definition cfg8c Error you must define XXXX near line xxx xxxx cfg XXXX cannot be omitted cfg8c Error you must define SYMBOL near line xxx xxxx cfg
62. 57EJO0101 Rev 1 01 Page 127 of 178 Sep 16 2011 RENESAS MR8C 4 7 Detailed Applications 7 1 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in C language observe the following precautions 1 Describe the cyclic or alarm handler as a function 2 Be sure to declare the return value and argument of the interrupt handler start function as a void type 3 At the beginning of file be sure to include itron h kernel h which is in the system di rectory as well as kernel id h which is in the current directory The static declared functions cannot be registered as a cyclic handler or alarm handler 5 The cyclic handler and alarm handler are invoked by a subroutine call from a system clock interrupt handler include itron h include lt kernel h gt include kernel id h void cychand void process Figure 7 5 Example Cyclic Handler Written in C Language The handler to function name correlation is determined by the configuration file R20UT0657EJ0101 Rev 1 01 Page 128 of 178 Sep 16 2011 2tENESAS MR8C 4 7 Detailed Applications 7 2 Program Coding Procedure in Assembly Language This section describes how to write an application using the assembly language 7 2 1 Writing Task This section describes how to write an application using the assembly language 1 Be sure to include mr8c inc at the beginning of file 2 For the symbol indicating the task start ad
63. 6 List of System Status Management Function Service Call 107 Table 5 17 List of Interrupt Management Function Service Call 118 Table 5 18 List of System Configuration Management Function Service Call eee 120 TableilCLanguagevartaleTreatrment sene enne en nennen nnne en K K SE EKK K AKE E EEK HE E EEK nennen nnn 126 Table 8 1 Numerical Value Entry Examples AAA 139 RER ee ge CEET 140 Table 8 3 Correspondence of fixed vector interrupt factor and vector number 154 Table 10 1 Functions in the Sample bro am 163 Table 11 1 Stack Sizes Used by Service Calls I ssued from Tasks in Dwteel sse 174 Table 11 2 Stack Sizes Used by Service Calls I ssued from Handlers in bytes AE 174 Table 11 3 Stack Sizes Used by Service Calls Issued from Tasks and Handlers in Dwtes AAA 174 Table 12 1 Interrupt Number Assignments nirisan sess nene nennen nne nne nen nne 175 vii 1 User s Manual Organization The MR8C 4 User s Manual consists of nine chapters and thee appendix e 2 General Information Outlines the objective of MR8C 4 development and the function and position of the MR8C 4 e 3 Introduction to Kernel Explains about the ideas involved in MR8C 4 operations and defines some relevant terms e 4Kernel Outlines the applications program development procedure for the MR8C A e 5 Service call reference Details MR8C 4 service call API 6 Applications Development Procedure Overview Details the applications program development procedure for t
64. AITING state by dly tsk service call with time out R20UT0657EJ0101 Rev 1 01 Page 99 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference 5 7 Time Management Function Cyclic Handler Specifications of the cyclic handler function of MR8C 4 are listed in Table 5 12 The cyclic handler description languages in item No 4 are those specified in the GUI configurator They are not output to a configuration file nor are the MR8C 4 kernel concerned with them Table 5 12 Specifications of the Cyclic Handler Function No Item Content 1 Cyclic handler ID 1 255 2 Activation cycle O 7fffffff ms 3 Activation phase O 7fffffff ms 4 Extended information 16 bits 5 Cyclic handler attribute TA HLNG Handlers written in high level language TA ASM Handlers written in assembly language TA STA Starts operation of cyclic handler TA PHS Saves activation phase Table 5 13 List of Cyclic Handler Function Service Call No Service Call Function System State N E D 1 sta cyc SI B Starts cyclic handler O olo operation 2 stp_cyc S B Stops cyclic handler O o o 0 operation 4 U o Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled
65. C 4 uses as follows MR RAM DBG section This section is stored MR30 s debug function RAM data This section must be mapped in the Internal RAM area MR RAM section This section is where the RAM data MR8C 4 s system management data is stored that is referenced in absolute addressing This section must be mapped between 0 and FFFFH near area stack section This section is provided for each task s user stack and system stack This section must be mapped between 0 and FFFFH near area MR HEAP section This section stores the variable size memorypool e MR KERNEL section This section is where the MR8C 4 kernel program is stored MR CIF section This section stores the MR8C A C language interface library MR ROM section This section stores data such as task start addresses that area referenced by the MR8C 4 kernel NTERRUPT VECTOR section e FIX INTERRUPT VECTOR section This section stores interrupt vectors R20UT0657EJ0101 Rev 1 01 Page 138 of 178 Sep 16 2011 132 NE SAS 8 Using Configurator 8 1 Configuration File Creation Procedure When applications program coding and startup program modification are completed it is then necessary to register the applications program in the MR8C 4 system This registration is accomplished by the configuration file 8 1 1 Configuration File Data Entry Format This chapter describes how the definition data are entered in the configuration file
66. D semid Parameters ID semid Semaphore ID number to which returned e Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc Sig sem SEMID isig sem SEMID Parameters SEMID Semaphore ID number to which returned Register contents after service call is issued Register name Content after service call is issued RO Error code A0 Semaphore ID number to which returned Error code E OOVR Oueuing overflow Functional description This service call releases one resource to the semaphore indicated by semid If tasks are engueued in a waiting gueue for the target semaphore the task at the top of the gueue is placed into READY state Conversely if no tasks are enqueued in that waiting queue the semaphore resource count is incremented by 1 If an attempt is made to return resources sig sem or isig sem service call causing the semaphore resource count value to ex ceed the maximum value specified in a configuration file maxsem the error code E QOVR is returned to the service call issuing task with the semaphore count value left intact If this service call is to be issued from task context use sig sem if issued from non task context use isig sem R20UT0657EJ0101 Rev 1 01 Page 79 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt it
67. ITRON Specification is a subset of 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 conforming to the ITRON Specification can be transferred to the MR8C 4 with comparative ease 2 High speed processing is achieved MR8C 4 enables high speed processing by taking full advantage of the microcomputer architecture 3 Only necessary modules are automatically selected to constantly build up a system of the minimum size MR8C 4 is supplied in the object library format of the RSC Family Therefore the Linkage Editor LN30 functions are activated so that only necessary modules are automatically se lected from numerous MR8C 4 functional modules to generate a system Thanks to this feature a system of the minimum size is automatically generated at all times 4 An upstream process tool named Configurator is provided to simplify development proce dures A configurator is furnished so that various items including a ROM write form file can be created by giving simple definitions Therefore there is no particular need to care what libraries must be linked In addition a GUI version of the configurator is available It helps the user to create a configuration file without the need to learn how to write it R20UT0657EJ0101 Rev 1 01 Page 5 of 178 Sep 16 2011 131 N SAS 3 Introduction to Kernel
68. In the former case the cyclic handler is started relative to the point in time at which it was generated In the latter case the cyclic handler is started relative to the point in time at which it started operating Figure 4 13 and Figure 4 14 show typical operations of the cyclic handler If the startup cycle is shorter than the time tick interval the cyclic handler is started only once every time tick supplied processing eguivalent to isig tim For example if the time tick interval is 10 ms and the startup cycle is 3 ms and the cy clic handler has started operating when a time tick is supplied then the cyclic handler is started every time tick Start operating Stop operating Cyclic handler created Activation Activation Activation Activation I Activation i I I phase i cyde cyde cyde cyde v v v Handler does Handler does Handler starts Handler starts Handler does not start not start not start Figure 4 13 Cyclic handler operation in cases where the activation phase is saved Stop operating Start operating I I Activation Activation i Activation Activation Activation i phase i cycle i cyde cyde cycle i v v v Handler does Handler does Handler starts Handler starts Handler does not start not start not start Figure 4 14 Cyclic handler operation in cases where the activation phase is not saved e Start Cyclic Handler Operation sta cyc Causes the cyclic handler with the sp
69. Management Function sssssssseseeeeeeneeneee nennen nennen en nen nennen nnns 54 Table 5 2 List of Task Management Function Service Call sssesseeeeee eene nennen nennen nennen nen nn 54 Table 5 3 Specifications of the Task Dependent Synchronization Function essssseeeee ene 63 Table 5 4 List of Task Dependent Synchronization Service Call 63 Table 5 5 Specifications of the Semaphore FUNCION nennen nen nennen nennen nennen nnns 78 Table 5 6 List of Semaphore Function Service Call sseseeeeeee eene enne nnne KE K KEE K EK REK nennen nn 78 Table 5 7 Specifications of the Eventflag Function esses eee eee Kane nennen nenne nnn nennen nennen nnns 83 Table5 8 List of Eventflag Function Service Call 83 Table 5 9 Specifications of the Data Queue Function 4 44 lt 4 seen nennen enne E KERR K EEK K KR REK nnne nnn 91 Table 5 10 List of Dataqueue Function Gervicertall eee ieee eene nnn nena 91 Table 5 11 List of Time Management Function Service Call 98 Table 5 12 Specifications of the Cyclic Handler Funcd on nennen nennen enne nnns 100 Table 5 13 List of Cyclic Handler Function Service Call seseeeeeeeenene nnne ennemis 100 Table 5 14 Specifications of the Alarm Handler Function sese enne enne nnne nnne nnne nnn nennen nnn 103 Table 5 15 List of Alarm Handler Function Service Call nennen nennen enne nnne ns 103 Table 5 1
70. OS independent interrupt handlers and kernel OS dependent interrupt handlers where the kernel mask level OS interrupt disable level is set to 3 3 6 2 Kernel mask level OS Interrupt disable level Kernel Non kernel OS dependent OS independent Interrupt handler Interrupt handler Figure 3 21 Interrupt handler IPLs The Use of Non maskable Interrupt An NMI interrupt and Watchdog Timer interrupt have to use be a non kernel OS independent interrupt handler If they are a kernel OS dependent interrupt handler the program will not work normally R20UT0657EJ0101 Rev 1 01 Page 30 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel 3 6 3 Controlling Interrupts Interrupt enable disable control in a service call is accomplished by IPL manipulation The IPL value in a service call is set to the kernel mask level OS interrupt disable level system IPL in order to disable interrupts for the kernel OS dependent interrupt handler In sections where all interrupts can be enabled it is returned to the initial IPL value when the service call was invoked For service calls that can be issued from only task context When thel flag before issuing a service call is 1 Task Service call issued Service call processing I l I flag 1 D 4 1 1 lt system IPL gt lt 0 l l I 1 IPL O s lt system IPL 0 When thel flag before issuing a serv
71. R20UT0657EJ0101 Rev 1 01 Page 27 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel Task System dock interrupt handler Cydic handler Alarm handler Subroutine call Timer interrupt Figure 3 20 Cyclic Handler Alarm Handler Activation R20UT0657EJ0101 Rev 1 01 Page 28 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel 3 5 2 Dispatch Enabled Disabled States The system assumes either a dispatch enabled state or a dispatch disabled state In a dispatch disabled state no task sched uling is performed Nor can service calls be invoked that may cause the service call issuing task to enter a wait state The system can be placed into a dispatch disabled state or a dispatch enabled state by the dis dsp or ena dsp service call respectively Whether the system is in a dispatch disabled state can be known by the sns dsp service call 3 5 3 CPU Locked Unlocked States The system assumes either a CPU locked state or a CPU unlocked state In a CPU locked state all external interrupts are disabled against acceptance and task scheduling is not performed either The system can be placed into a CPU locked state or a CPU unlocked state by the loc cpu iloc cpu or unl cpu iunl cpu service call respectively Whether the system is in a CPU locked state can be known by the sns loc service call The service calls that can be issued from a CPU locked state are limited to those that are listed in Tab
72. R8C 4 guarantees that as stipulated in uITRON specification timeout processing is not performed until a time equal to or greater than the specified timeout value elapses More specifically timeout processing is performed with the following timing 1 If the delay time value is 0 for only dly tsk The task times out at the first time tick after the service call is issued 2 Ifthe delay time value is a multiple of time tick interval The timer times out at the timeout value time tick interval first time tick For example if the time tick interval is 10 ms and the specified timeout value is 40 ms then the timer times out at the fifth oc currence of the time tick Similarly if the time tick interval is 5 ms and the specified timeout value is 15 ms then the timer times out at the fourth occurrence of the time tick 3 If the delay time value is not a multiple of time tick interval The timer times out at the timeout value time tick interval second time tick For example if the time tick interval is 10 ms and the specified timeout value is 35 ms then the timer times out at the fifth oc currence of the time tick R20UT0657EJ0101 Rev 1 01 Page 48 of 178 Sep 16 2011 132 NE SAS MR8C 4 4 Kernel 4 2 7 Cyclic Handler Function The cyclic handler is a time event handler that is started every startup cycle after a specified startup phase has elapsed The cyclic handler may be started with or without saving the startup phase
73. Singapore Pte Ltd 1 harbourFront Avenue 06 10 keppe l Bay Tower Singapore 098632 Tel 65 6213 0200 Fax 65 6278 8001 Renesas Hectronics Malaysia Sdn Bhd Unit 906 Block B Menara Amcorp Amcorp Trade Centre No 18 Jn Persiaran Barat 46050 Petaling Jaya Selangor Darul Ensan Malaysia Tel 60 3 7955 9390 Fax 60 3 7955 9510 Renesas Hectronics Korea Co Lid 11F Samik Lavied or Bldg 720 2 Yeoksam Dong Kangnam Ku Seoul 135 080 Korea Tel 82 2 558 3737 Fax 82 2 558 5141 2011 Renesas Electronics Corporation and Renesas Solutions Corp All rights reserved Colophon 1 0 Real time OS for R8C Family MR8C 4 V 1 01 User s Manual 2E N ESAS R20UT0657EJ0101 Renesas Electronics Corporation
74. YES or NO Define whether the handler is a kernel OS dependent interrupt handler If it is a kernel OS dependent inter rupt handler specify YES if it is a non kernel OS independent interrupt handler specify No If this item is defined as YES the declaration statement shown below is output to the kernel id h file pragma INTHANDLER V4 function name If this item is defined as NO the declaration statement shown below is output to the kernel id h file pragma INTERRUPT V4 function name 2 Start address Definition format Symbol or function name Definition range None Default value SYS DMY INH Define the entry address of the interrupt handler When written in the C language add at the end or at the beginning of the function name you have defined 3 Switch passed to PRAGMA extended function Definition format Symbol Definition range E orB Default value None Specify the switch to be passed to pragma INTHANDLER or pragma INTERRUPT If E is specified the E switch is assumed in which case multiple interrupts another interrupt within an interrupt are enabled If B is specified the B switch is assumed in which case register bank 1 is specified Two or more switches can be specified at the same time For kernel OS dependent interrupt handlers how ever only the E switch can be specified For non kernel OS independent interrupt handlers the E E
75. a rtc i cec du slates SEENEN EENS AE e 152 Interrupt vector definition Il ENEE 153 8 13 Configuration File Evample AA 155 8 2 Configurator Execution Procedures enne nK P KK KA P AP RA KK R Kek 156 8 2 1 Configurator ODverven eee eee eee een nnne tnter KKK EKK A EK KEE KEE EEA aana dana 156 8 22 Setting Configurator Environment 2 2 eeeeee eee eee ee ee enne enne en KA RA nennen sn nnns 157 8 23 Configurator Start PrOCEdUre e s eee eee ee nenene KKK enn K A KKK KA AP A P K K KKK 157 Error Messages PEE 158 Hd rue Run E EE 161 H Table Generation Utility ZEE 162 SCH HEITEN beer deed hegedt Eed ege EE a h dku K Saeed ese taseadt a n HEISST 162 92 Environment Setup Seed bre e a Sr OR eu Y Roe r hou k NEA ork Re ER RR ne cn 162 9 3 Table Generation Utility Start Procechure ener nnne nennen nnns 162 o oc EE 162 10 Sample Program Description lessen eene enne enne nnne KKK nianu nina K seas R KRKA KRK aea 163 10 1 Overview of Sample Program 163 10 2 Program Beie ee e aiio tete trie ur te E et HG Pre ar Ee n c n euis 164 10 3 Configuration Files mt ren aria e Qe n tt ETE tee bud ae Te A aa a ehe ta dee 165 11 Stack Size Calculation Method seeeeeeeeneenenenennnnnnnne nnne nnne nnne nnn nnn 166 11 1 Stack Size Calculation M eT O snnm nnne nnne nn nnn KA ener ee enne n 166 11 1 1 User Stack Calculation Method 2 2 eee eee eee eee ee eee
76. ai sem snd dro or rcv dig service call the task is queued to one of the following waiting queues depending on the request Event flag waiting queue Semaphore waiting queue e Data queue data transmission waiting queue e Data queue data reception waiting queue 4 SUSPENDED state When the sus tsk service call is issued from a task in the RUNNING state the READY task designated by the service call or the currently executed task enters the SUSPENDED state If a task in the WAITING state is placed in this situation it goes into the WAITING SUSPENDED state The SUSPENDED state is the condition in which a READY task or currently executed task is 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 execution queue Note that no queue is formed for the suspend request Therefore the suspend request can only be made to the tasks in the RUNNING READY or WAITING state If the suspend request is made to a task in the SUS PENDED state an error code is returned 5 WAITING SUSPENDED If a suspend request is issued to a task currently in a WAITING state the task goes to a WAITING SUSPENDED state If a suspend request is issued to a task that has been placed into a WAITING state for a wait request by the slp tsk wai flg wai sem snd dtq or rcv dtq service call the task goes to a WAITING SUSPENDED state When the
77. all is issued Register name Content after service call is issued RO TRUE Non Task context FALSE Task context Error code None Functional description This service call returns TRUE when it is invoked from non task context or returns FALSE when invoked from task con text This service call can also be invoked from a CPU locked state Example program statement Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task BOOL stat stat sns_ctx lt lt Example statement in assembly language gt gt include mr8c inc GLB task task sns ctx R20UT0657EJ0101 Rev 1 01 Page 115 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference sns loc Reference CPU state C Language API BOOL state sns loc e Parameters None e Return Parameters BOOL state TRUE CPU locked state FALSE CPU unlocked state Assembly language API include mr8c inc sns loc e Parameters None Register contents after service call is issued Register name Content after service call is issued RO TRUE CPU locked state FALSE CPUCPU unlocked state Error code None Functional description This service call returns TRUE when the system is in a CPU locked state or returns FALSE when the system is in a CPU unlocked state This service call can also be invoked from a CPU locked state
78. and B switches can be specified subject to a limitation that E and B cannot be specified at the same R20UT0657EJ0101 Rev 1 01 Page 153 of 178 Sep 16 2011 134 N ESAS MR8C 4 8 Using Configurator time Precautions 1 Regarding the method for specifying a register bank A kernel OS dependent interrupt handler that uses register bank 1 cannot be written in C language Such an interrupt handler can only be written in assembly language When writing in assembly language make sure the statements at the entry and exit of the interrupt handler are written as shown below Always be sure to clear the B flag before issuing the ret int service call Example interrupt fset B fclr B ret int Internally in the MR8C 4 kernel register banks are not switched over 2 Do not use watchdog timer interrupts in the kernel OS dependent interrupt The interrupt factors and the vector number of a fixed vector are shown as follows below Please refer to the hardware manual of the microcomputer that is use for a changeable vector Table 8 3 Correspondence of fixed vector interrupt factor and vector number Interrupt Factor Vector number Section Name Undefined instruction 247 FIX INTERRUPT VECTOR Overflow 248 FIX INTERRUPT VECTOR BRK instruction 249 FIX INTERRUPT VECTOR Addres match 250 FIX INTERRUPT VECTOR Single step 251 FIX INTERRUPT VECTOR Watchdog 252 FIX INTERRUPT VECTOR Ad
79. and if the semaphore count value is 0 the wai sem service call invoking task is enqueued in a waiting queue for that semaphore in order of FIFO For the pol sem service call the task returns immediately and responds to the call with the error code E TMOUT The task placed into WAITING state by execution of the wai sem service call is released from the WAITING state in the following cases When the sig sem or isig sem service call is issued with task awaking conditions thereby sat isfied The error code returned in this case is E OK When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI These service calls can only be issued from task context and cannot be issued from non task context Example program statement Example statement in C language include lt itron h gt include lt kernel h gt include kernel id h void task if wai_sem ID_sem E_OK printf Forced wakeup n if pol_sem ID_sem E_OK printf Timeout n lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM f A0 pol sem ID SEMI PUSHM l A0 wai sem ID SEM2 R20UT0657EJ0101 Rev 1 01 Page 82 of 178 Sep 16 2011 131 N SAS MR8C 4 5 Service call reference 5 4 Synchronization amp Communication Function Eventflag Spe
80. and testing in the unit of a small module called task This feature facilitates evaluation and testing and increases software reliability The microcomputer performance can be optimized to improve the performance of microcom puter based products With the real time OS it is possible to decrease the number of unnecessary microcomputer operations such as I O waiting It means that the optimum capabilities can be obtained from microcomputers and this will lead to mi crocomputer based product performance improvement R20UT0657EJ0101 Rev 1 01 Page 3 of 178 Sep 16 2011 131 N SAS MR8C 4 2 General Information 2 2 Relationship between TRON Specification and MR8C 4 MR8C 4 is the real time operating system developed for use with the RSC Family of 16 bit microcomputers compliant with UITRON 4 0 Specification uITRON 4 0 Specification stipulates standard profiles as an attempt to ensure software port ability Of these standard profiles MR8C 4 has implemented in it many useful service calls R20UT0657EJ0101 Rev 1 01 Page 4 of 178 Sep 16 2011 131 N SAS MR8C 4 2 General Information 2 3 Features The MR8C 4 offers the following features 1 Real time operating system conforming to the uITORN Specification The MR8C 4 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
81. anged its own priority by chg pri service call 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 WAITING state When a task in the RUNNING state requests to be placed in the WAITING state it exits the RUNNING state and enters the WAITING state The WAITING state is usually used as the condition in which the completion of I O device I O operation or the processing of some other task is awaited The task goes into the WAITING state in one of the following ways The task enters the WAITING state simply when the slp tsk service call is issued In this case the task does not go into the READY state until its WAITING state is cleared explicitly by some other task The task enters and remains in the WAITING state for a specified time period when the dly tsk service call is issued In this case the task goes into the READY state when the specified time has elapsed or its WAITING state is cleared explicitly by some other task The task is placed into WAITING state for a wait request by the wai flg wai sem snd dtq or rcv do service call In this case the task goes from WAITING state to READY state when the re quest is met or WAITING state is explicitly canceled by another task If the task is placed into WAITING state for a wait request by the wai flg w
82. ask goes to a data transmission wait state e Send to Data Queue psnd dtq ipsnd_dtq The data is transmitted to the data queue If the data queue is full of data the task returns error code without going to a data transmission wait state Receive from Data Queue rcv dtq The data is retrieved from the data queue If the data queue has no data in it the task is kept waiting until data is transmitted to the data queue Receive from Data Queue prov dtq The data is received from the data queue If the data queue has no data in it the task returns error code without going to a data reception wait state 9 First In First Out R20UT0657EJ0101 Rev 1 01 Page 47 of 178 Sep 16 2011 132 NE SAS MR8C 4 4 Kernel 4 2 6 Time Management Function The time management function provides system time management and the functions of the alarm handler which actuates at preselected times and the cyclic handler which actuates at preselected time intervals The MR8C 4 kernel requires one timer for use as the system clock There are following time management service calls that are provided by the MR8C 4 kernel Note however that the system clock is not an essential function of MR8C 4 There fore if the service calls described below and the time management function of the MR8C 4 are unused a timer does not need to be occupied for use by MR8C A e Place a task in a finite time wait state by specifying a timeout value M
83. ask void ext tsk lt lt Example statement in assembly language gt gt INCLUDE mr8c inc GLB task task ext tak R20UT0657EJ0101 Rev 1 01 Page 58 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference ter tsk Terminate task C Language API ER ercd ter tsk ID tskid e Parameters ID tskid ID number of the forcibly terminated task Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc ter tsk TSKID Parameters TSKID ID number of the forcibly terminated task Register contents after service call is issued Register name Content after service call is issued RO Error code A0 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is an inactive state E ILUSE Service call improperly used task indicated by tskid is the issuing task itself Functional description This service call terminates the task indicated by tskid If a task specifies its own task ID or TSK SELF an E ILUSE error is returned If the specified task was placed into WAITING state and has been enqueued in some waiting queue the task is dequeued from it by execution of this service call However the semaphore and other resources the specified task had acquired pre viously are not released If the task indicated by tskid is in DORMANT state it returns the error code E OBJ as a return val
84. at issued the service call is removed from the timeout waiting queue and linked to a ready queue When the first time tick occurred after dlytim elapsed The error code returned in this case is E OK When the rel wai or irel wai service call is issued before dlytim elapses The error code returned in this case is E RLWAI Note that even when the wup_tsk or iwup tsk service call is issued during the delay time the task is not released from WATTNG state The delay time dlytim is expressed in ms units Therefore if specified as dly tsk 50 the issuing task is placed from RUNNING state into a delayed wait state for a period of 50 ms The values specified for dlytim must be within Ox7fffffff time tick If any value exceeding this limit is specified the ser vice call may not operate correctly This service call can be issued only from task context It cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 76 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference L Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if dly_tsk E_OK error Forced wakeup n lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM R1 R3 MOV W 500 R1 MOV W 0 R1 dly tsk R20UT0657EJ0101 Rev 1 01 Page 77 of 178 Sep 16 20
85. ce Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task UINT flgptn if wai flg ID flg2 FLGPTN 0x0ff0 TWF ANDW amp flgptn E OK error Wait Released n if pol flg ID flg2 FLGPTN 0x0ff0 TWF ORW sflgptn E OK printf Not set EventFlag Nn lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM AO R1 R3 wai flg ID_FLG1 0003H TWF_ANDW PUSHM AO R1 R3 pol flg ID_FLG2 0008H TWF_ORW R20UT0657EJ0101 Rev 1 01 Sep 16 2011 2tENESAS Page 90 of 178 MR8C 4 5 Service call reference 5 5 Synchronization amp Communication Function Data Queue Specifications of the data queue function of MR8C 4 are listed in Table 5 9 Table 5 9 Specifications of the Data Queue Function No Item Content 1 Data queue ID 1 255 2 Capacity data bytes in data queue area 0 65535 3 Data size 16 bits 4 Data queue attribute TA_TFIFO Waiting tasks enqueued in order of FIFO Table 5 10 List of Dataqueue Function Service Call No Service Call Function System State T N E D U L 1 snd_dtq S Sends to data queue O O O 2 psnd dtq S Sends to data queue O O O O 3 ipsnd dtg S polling O O O O 4 rcv dtq S Receives from data queue O O O 5 prev dtq S Receives
86. ce polling nnne nnns 81 5 4 Synchronization amp Communication Function Eventflao nennen 83 set flg Set eventtlag iae nei ee raid eate e ber m dd eter ab atm IRE die a ly 84 iset flg Set eventflag handler ov 84 ta de le WE ee aim 86 wai flg Wait for eventflagi i issin i anii iet e ia aaae e E nennen anh nennen than te entis entren tns RA ERA nt nen 88 pol flg Wait for eventflag polling esses nennen nnne nnne nnne nnne 88 5 5 Synchronization amp Communication Function DataOueuel lt lt lt s lt cssc erns 91 snd dro Gendtodataoueue ANEREN 92 psnd do Send to data queue polling esses enne nnne nennen en 92 ipsnd dro Send to data queue polling handler only 92 rcv dtq Receive from dataoueie eee ena nnn nnne AK AK tnn nnn nter nnn KKK KRKA nnn tnn na 95 prcv dtq Receive from data queue polling sess 95 5 6 Time Management Euncion ee ee enne tene KK AKA tnter nenne enne sens etn 98 istg tim Supply a tm EIC sooo reote ine eee rp tree ete ete ere ope o au teg eter aetas Dep exte rete 99 5 7 Time Management Function Cyclic Handler sese enne nnns 100 sta cyc Start cyclic handler operation ener nnne 101 stp cyc Stops cyclic handler operation ennemis 102 5 8 Time Management Function Alarm Handler 103 sta alm Start alarm handler operation enne nennen nennen 104 stp alm Stop alarm handler operation ess
87. ce Call a Handler that caused an interrupt during Task Execution 15 Figure 3 12 Processing Procedure for a Service Call from a Handler that caused an interrupt during Service Call Processing 16 Figure 3 13 Processing Procedure for a service call from a Multiplex interrupt Handler AAA 17 Figure 3 14 Task Identification e eo quet Vedi ed et quet iet dal Seaplane ue cae a Lc 18 Re lee bota Ns E ae e aE ETETE hspehacaeineeenibte tenen nix 19 Figure 3 16 MR8C A Task Status Transition 20 Figure 3 17 Ready Queue Execution Queue nennen nennen nnne nennen nennen EEK nnne nen nennen nn 23 Figure 3 18 Waiting queue of the TA TEIEO attribute enne nnne nnne nennen nen nennen nnns 24 Figure 3 19 Task control block uer ado rn Re eer eter tenebo rere TOENE e re Feb en bad ln ree WPA EI Edere eina ote 26 Figure 3 20 Cyclic Handler Alarm Handler Activation ssssssseeeeneenenneenen enne nennen nennen enne 28 Figure3 21 Interrupt handler LEE 30 Figure 3 22 Interrupt control in a Service Call that can be Issued from only a Task ssssssseeeeeee 31 Figure 3 23 Interrupt control in a Service Call that can be Issued from a Task independent ssssss 32 Figure 3 24 System Stack and User Stack ANEREN 35 Figure 4 1 M R8C A ga pu re pte cent quos eate e ied ereqe dace Chad elias dde geen idees 36 Figure 4 2 Task eae Ee eer E PM dtp eser rp ber MIRA 38 Figure 4 3 Alteration of task Prrori tysia ennemi enne
88. ce during the exe cution of the service call ret int service call returned from handler B but is effected by the ret int service call from han dler A See Figure 3 13 TaskA Interrupt handler A NM Interrupt handler A Interrupt Save Registers SP lt System OS Save Registers Interrupt Service call processing Restore Register Restore Register Task selection ret int SP lt User Restore Registers TaskB ret int Figure 3 13 Processing Procedure for a service call from a Multiplex interrupt Handler R20UT0657EJ0101 Rev 1 01 Page 17 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel 3 3 Object The object operated by the service call of a semaphore a task etc is called an object An object is identified by the ID number 3 3 1 The specification method of the object in a service call Each task is identified by the ID number internally in MR8C 4 For example the system says Start the task having the task ID number 1 However if a task number is directly written in a program the resultant program would be very low in readability If for instance the following is entered in a program the programmer is constantly required to know what the No 2 task is sta tsk 1 stacd Further if this program is viewed by another person he she does not understand at a glance what the No 1 task is To avoid such inconvenience the MR8C 4 provides
89. cheduling is not performed anymore no tasks other than the issuing task itself will be placed into RUNNING state 2 Interrupts are accepted 3 No service calls can be invoked that will place tasks into WAITING state If one of the following operations is performed during a dispatching disabled state the system status returns to a task exe cution state a Invocation of the ena dsp service call b Invocation of the ext tsk service call Transitions between dispatching disabled and dispatching enabled states occur only when the dis dsp ena dsp or ext tsk service call is invoked Invoking this service call again while the system is already in a dispatching disabled state does not cause an error in which case task queuing is not performed however This service call can be issued only from task context It cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 112 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task dis dsp lt lt Example statement in assembly language gt gt include mr8c inc GLB task task dis dsp R20UT0657EJ0101 Rev 1 01 Page 113 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference ena dsp Enables dispatching C Language API ER ercd ena dsp
90. cifications of the eventflag function of MR8C 4 are listed in Table 5 7 Table 5 7 Specifications of the Eventflag Function No Item Content 1 EventOflag ID 1 255 2 Number of bits comprising 16 bits eventflag 3 Eventflag attribute TA TFIFO Waiting tasks enqueued in order of FIFO TA WSGL Multiple tasks cannot be kept waiting TA WMUL Multiple tasks can be kept waiting TA CLR Bit pattern cleared when waiting task is released Table 5 8 List of Eventflag Function Service Call No Service Call Function System State T N E D U L 1 set flg SI B Sets eventflag O O O O 2 iset flg S B O O O O 3 clr flg S B Clears eventflag O O O O 4 wai flg S B Waits for eventflag O O O 5 pol flg S B Waits for eventflag O O O O polling Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Canbe called from CPU unlocked state L Canbecalled from CPU locked state R20UT0657EJ0101 Rev 1 01 Page 83 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference set flg Set eventflag iset flg Set eventflag handler only C Language API ER ercd set flg ID flgid FLGPTN setptn
91. cs Corporation Edited by Renesas Solutions Corp 44 NCESAS SALES OFHCES Renesas Electronics Corporation http www renesas com Refer to http www renesas com for the latest and detailed information Renesas Hectronics America Inc 2880 Scott Boulevard Santa Clara CA 95050 2554 U SA Tel 1 408 588 6000 Fax 1 408 588 6130 Renesas Hectronics Canada Limited 1101 Nicholson Road Newmarket Ontario L3Y 9C3 Canada Tel 1 905 898 5441 Fax 1 905 898 3220 Renesas Hectronics Europe Limited Dukes Meadow Millboard Road Bourne End Buckinghamshire SL8 5FH U K Tel 44 1628 585 100 Fax 44 1628 585 900 Renesas Hectronics Europe GmbH Arcadiastrasse 10 40472 D sseldorf Germany Tel 49 211 65030 Fax 49 211 6503 1327 Renesas Hectronics China Co Ltd 7th Hoor Quantum Plaza No 27 ZhiChunLu Haidian District Beijing 100083 PRChina Tel 86 10 8235 1155 Fax 86 10 8235 7679 Renesas Hectronics Shanghai Co Lid Unit 204 205 AZIA Center No 1233 Lujiazui Ring Fu Pudong District Shanghai 200120 China Tel 86 21 5877 1818 Fax 86 21 6887 7858 7898 Renesas Hectronics Hong Kong Limited Unit 1601 1613 16 F Tower 2 Grand Century Place 193 Prince Edward Road West Mongkok Kowloon Hong Kong Tel 852 2886 931 8 Fax 852 2886 9022 9044 Renesas Hectronics Taiwan Co Lid 7F No 363 Fu Shing North Road Taipei Taiwan Tel 886 2 8175 9600 Fax 886 2 81 75 9670 Renesas Hectronics
92. d below 16MHz 8 1234MHz It is also well to remember that the freguency must not begin with period Configuration File Definition Items 36 are to be formulated in the configuration file System definition System clock definition Task definition Eventflag definition Semaphore definition Data gueue definition Cyclic handler definition Alarm handler definition Interrupt vector definition System Definition Procedure lt lt Format gt gt System Definition system stack size System stack size priority Maximum value of priority system IPL Kernel mask level OS interrupt disable level tic deno Time tick denominator tic nume Time tick numerator 36 All items except task definition can omitted If omitted definitions in the default configuration file are referenced R20UT0657EJ0101 Rev 1 01 Page 141 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator lt lt Content gt gt 1 System stack size Definition format Numeric value Definition range 4 to OxFFFF Default value 400H Define the total stack size used in service call and interrupt processing 2 Maximum value of priority value of lowest priority Definition format Numeric value Definition range 1 to 255 Default value 63 Define the maximum value of priority used in MR8C 4 s application programs This must be th
93. d itself in the WAITING Since the service call was issued from the RUNNING state task the WAITING state of another task with a priority higher than the RUNNING state task is cleared 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 by chg pri service call so that the priority of another READY task is rendered higher When any of the above conditions occurs rescheduling takes place so that the task having the highest priority among those in the RUNNING or READY state is placed in the RUNNING state and the execution of that task starts 2 READY state The READY state refers to the situation in which the task that meets the task execution conditions is still waiting for execution because a different task having a higher priority is currently being executed When any of the following conditions occurs the READY task that can be executed second according to the ready queue is placed in the RUNNING state A currently executed task has normally terminated itself by ext tsk service call By issuing dly tsk slp tsk wai flg wai sem snd dtq and rcv do service call R20UT0657EJ0101 Rev 1 01 Page 20 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel Acurrently executed task has placed itself in the WAITING state A currently executed task has ch
94. dependent Interrupt Handler eee eee een 127 7 14 Writing Cyclic Handler Alarm H ander 128 7 2 ProoramCodingbrocechureinAseertlvl anoua0ge 22 202 eeee eee eee ee eee nenene 129 K Ee elle WEE EE 129 7 2 2 Writing Kernel OS dependent Interrupt Handler 130 7 243 Writing Non kernel OS independent Interrupt Handler AAA 130 7 2 4 Writing Cyclic Handler Alarm H ander 131 7 3 Modifying MR8C A Startup Program u eee eee eee eee enne nennen KA K KK A KA enne enn nnns 132 7 341 C Language Startup Program r m a20 nennen nennen nnns 133 AA Eug elt ege EE 137 7 4 10 Sections that kernel uses A 138 8 Using Configurfator es 139 8 1 Configuration File Creation Procechure 2222 eee eee eee eee teen nene nK nennen nnne nennen 139 8 1 1 ConfiourationEileDataEntrvFormet nennen rennen nnn tnnt nennen nns 139 Operator srei T I TM EH 140 Direction of compllEaEIOn EE 140 8 12 Configuration File Definition Irems ennt nennen nnne nennen 141 CSystem Definition Procedure ice epic tha cepa echan mcg ee aa c Ra ERR CER EL RU a d 141 System Clock Definition Procedure UNENEE 143 C Task definition REENEN 144 CEventflag definiti on eren rnc icr dere rre ea cen irre din lr Rh 146 Semaphore definitlon rt re Cet retten ri rere eae Fr rd t Rv nete E ee ure E A c ea RT 147 Data queue definition H 148 IG Cydichandler definfti ob creta teh ay ete ete nut tret eer dee Eeer batt e eus 150 KAlarm handler definition lest
95. dler indicated by almid into a non operational state This service call can only be issued from task context and cannot be issued from non task context Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task stp alm ID alml lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 stp alm ID_ALM1 R20UT0657EJ0101 Rev 1 01 Page 106 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 9 System Status Management Function Table 5 16 List of System Status Management Function Service Call 5 Service call reference No Service Call Function System State T N E D U L 3 get tid S B References task ID in the O olojo RUNNING state 5 loc_cpu S B Locks the CPU O O 0 0 0 7 unl cpu S B Unlocks the CPU O O 0 0 0 9 dis dsp S B Disables dispatching O O OO 10 ena dsp S B Enables dispatching O O 0 O 11 sns_ctx S References context O 0 0 0 01 0 12 sns loc S References CPU state O 0 0 0 0 0 13 sns dsp S References dispatching state O O O O O O Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning 99999 R20UT0657EJ0101 Rev 1 01 Sep 16 2011 T Can be called fro
96. dress make the external declaration Be sure that an infinite loop is formed for the task or the task is terminated by the ext tsk service call INCLUDE mr8c inc 1 GLB task 2 task process jmp task 3 Figure 7 6 Example Infinite Loop Task Described in Assembly Language INCLUDE mr8c inc GLB task task process ext tsk Figure 7 7 Example Task Terminating with ext tsk Described in Assembly Language 4 The initial register values at task startup are indeterminate except the PC SB RO and FLG registers 5 To specify a task use the string written in the task definition item name of the configura tion file wup tsk ID task 6 To specify an event flag semaphore or data queue use the respective strings defined in the configuration file For example if a semaphore is defined in the configuration file as shown below semaphore 1 name abc D I To specify this semaphore write your specification as follows sig sem 4 ID abc 7 To specify a cyclic or alarm handler use the string written in the cyclic or alarm handler definition item name of the configuration file For example if you want to specify a cyclic handler cyc write your specification as follows 3 Use the GLB pseudo directive R20UT0657EJ0101 Rev 1 01 Page 129 of 178 Sep 16 2011 132 NE SAS MR8C 4 7 Detailed Applications sta cyc d ID cyc 8 Set a task that is activated at MR8C 4
97. e GLB peudo directive R20UT0657EJ0101 Rev 1 01 Page 130 of 178 Sep 16 2011 132 NE SAS MR8C 4 7 Detailed Applications 5 If you want multiple interrupts to be enabled in a non kernel an OS independent interrupt handler always make sure that the non kernel OS independent interrupt handler is as signed a priority level higher than other non kernel OS dependent interrupt handlers GLB inthand 1 inthand Registers used are saved to a stack 2 interrupt process Registers used are restored 2 REIT 2 2 sg 20 La 3 Figure 7 9 Example of Non kernel OS independent Interrupt Handler of Specific Level 7 2 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in Assembly Language observe the following precautions 1 At the beginning of file be sure to include mr amp c inc which is in the system directory For the symbol indicating the handler start address make the external declaration Always use the RTS instruction subroutine return instruction to return from cyclic han dlers and alarm handlers For examples INCLUDE mES G Amen 1 GLB cychand 2 cychand handler process ECS se 3 Figure 7 10 Example Handler Written in Assembly Language 85 If you want the non kernel OS independent interrupt handler to be assigned a priority level lower than kernel OS dependent interrupt handlers change t
98. e value of the highest priority used 3 Kernel mask level OS interrupt disable level Definition format Numeric value Definition range 1to7 Default value 7 Set the IPL value in service calls that is the OS interrupt disable level 4 Time tick denominator Definition format Numeric value Definition range Fixed to 1 Default value 1 Set the denominator of the time tick 5 Time tick numerator Definition format Numeric value Definition range 1 to 65 535 Default value 1 Set the numerator of the time tick The system clock interrupt interval is determined by the time tick denomi nator and numerator that are set here The interval is the time tick numerator divided by time tick denominator ms That is the time tick numerator ms R20UT0657EJ0101 Rev 1 01 Page 142 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator System Clock Definition Procedure lt lt Format gt gt System Clock Definition clock mpu clock MPU clock timer Timers used for system clock IPL System clock interrupt priority level l lt lt Content gt gt 1 MPU clock Definition format Frequency in MHz Definition range None Default value 20MHz Define the MPU operating clock frequency of the microcomputer in MHz units 2 Timers used for system clock Definition format Symbol Definiti
99. ecified ID to operational state Stop Cyclic Handler Operation stp cyc Causes the cyclic handler with the specified ID to non operational state R20UT0657EJ0101 Rev 1 01 Page 49 of 178 Sep 16 2011 134 N SAS MR8C 4 4 Kernel 4 2 8 Alarm Handler Function The alarm handler is a time event handler that is started only once at a specified time Use of the alarm handler makes it possible to perform time dependent processing The time of day is specified by a relative time Figure 4 15 shows a typical operation of the alarm handler Start operating Start operating Stop operating Alarm handler created Activation Activation time time v Handler starts Handler does not start Figure 4 15 Typical operation of the alarm handler e Start Alarm Handler Operation sta alm Causes the alarm handler with the specified ID to operational state Stop alarm Handler Operation stp alm Causes the alarm handler with the specified ID to non operational state R20UT0657EJ0101 Rev 1 01 Page 50 of 178 Sep 16 2011 132 N SAS MR8C 4 4 2 9 System Status Management Function Reference task ID in the RUNNING state get_tid References the ID number of the task in the RUNNING state Lock the CPU loc_cpu Places the system into a CPU locked state Unlock the CPU unl cpu Frees the system from a CPU locked state Disable dispatching dis dsp Places the
100. ed in an interrupt handler task switching does not occur and task switching is postponed until the interrupt handler terminates However if the ret int service call is issued from an interrupt handler that was invoked from an interrupt that occurred within another interrupt the scheduler is not activated The scheduler is activated for interrupts from a task only When writing this service call in assembly language be aware that the service call cannot be issued from a subroutine that is invoked from an interrupt handler entry routine Always make sure this service call is executed in the entry routine or entry function of an interrupt handler For example a program like the one shown below may not operate normally include mr8c inc NG GLB intr intri jsr b func func ret int Therefore write the program as shown below include mr8c inc OK GLB intr intr jsr b func ret int func rts Make sure this service call is issued from only an interrupt handler If issued from a cyclic handler alarm handler or a task this service call may not operate normally 2 If the starting function of an interrupt handler is declared by pragma INTHANDLER the ret int service call is automatically issued at the exit of the function R20UT0657EJ0101 Rev 1 01 Page 119 of 178 Sep 16 2011 13 NE SAS MR8C 4 5 11System Configuration Management Function 5 Service call reference Table 5 18 List of System Conf
101. ed or this service call is executed again If the task indicated by tskid is in DORMANT state it returns the error code E OBJ as a return value for the service call Since the MR8C 4 does not support the mutex function in no case will the error code E ILUSE be returned If this service call is to be issued from task context use chg pri Example program statement lt lt Example statement in C language include itron h include kernel h include kernel id h void task chg pri ID task2 2 lt lt Example statement in assembly language gt gt Include mr8c inc GLB task task pushm A0 R3 chg pri ID_TASK3 1 R20UT0657EJ0101 Rev 1 01 Page 62 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 2 Task Dependent Synchronization Function Specifications of the task dependent synchronization function are listed in below 5 Service call reference Table 5 3 Specifications of the Task Dependent Synchronization Function No Item Content 1 Maximum value of task wakeup request count 15 2 Maximum number of nested forcible task wait requests count 1 Table 5 4 List of Task Dependent Synchronization Service Call No Service Call Function System State T N E D U L 1 slp_tsk S B Puts task to sleep O O O 2 wup_tsk S B Wakes up task O O O O 3 iwup tsk S B O O O O 4 can wup Cancels wakeup reguest O O O O
102. ee en nana K P nen nnne tnnt tnnt 168 11 1 2 System Stack Calculation Method AAA 170 EL Necessary Stack S 26 iure n e i o be det Pc e i lo te ao kbr bene 174 MQ Ko EE 175 121 The Use of INT Instruction cede tdt eet re dU ct eoe RE Ree Ee trea ence EE ge 175 12 2 TheUsSse of deele Ce de CIE 175 12 3 Regarding Delay Dispatching 176 12 4 Regarding Initially Activated Task nnne nennen nnne nnne nnne nennen 176 p E loe ro b ERE ER 177 13 1 Assembly Language Interface nennen tenente nnne EK nnne nnne nnne nnns 177 List of Figures Figure 3 1 Relationship between Program Size and Development Period 6 Figure 3 2 Microcomputer based System E xample Audio Equipment sse 7 Figure 3 3 Example System Configuration with Real time OS Audio Equipment sssseeeeeeeeenees 8 Figure 3 4 Time division Task Operation e terret cbe Pe pede ap ee epa cte te Padre RR nets 9 Figure 3 5 Task Execution Interruption and Resumption ssssssseseeenee enne nennen nennen nennen nnns 10 Figure 3 6 Task ee ln WEE 10 Figure 3 7 Task Register Area ct eec inei ce e Pea dr e Ea e PR e ua Ta et el e e e e ane 11 Figure 3 8 Actual Register and Stack Area Management nennen nennen nennen nen nennen nnns 12 Figure3 9 UE 12 Figure 3 10 Service Call Processing Flowchart eseesssssseeeeseeeneene eene nnne nennen KK AK KESK AE RAK RAK nennen enne nnns 13 Figure 3 11 Processing Procedure for a Servi
103. efver blkb 6 task PUSHM AO ref_ver _refver R20UT0657EJ0101 Rev 1 01 Page 122 of 178 Sep 16 2011 2tENESAS 6 Applications Development Procedure Overview 6 1 Overview Application programs for MR8C 4 should generally be developed following the procedure described below 1 Generating a project When using High performance Embedded Workshop create a new project using MR8C 4 on High performance Embedded Workshop Coding the application program Write the application program in code form using C or assembly language If necessary correct the sample star tup program crtOmr a30 and section definition file c sec inc or asm sec inc Creating a configuration file Create a configuration file which has defined in it the task entry address stack size etc by using an editor The GUI configurator available for MR8C 4 may be used to create a configuration file Executing the configurator From the configuration file create system data definition files sys rom inc sys ram inc and include files mr8c inc kernel id h kernel sysint h System generation Execute the make command or execute build on High performance Embedded Workshop to generate a system Writing to ROM Using the ROM programming format file created write the finished program file into the ROM Or load it into the debugger to debug Figure 6 1 shows a detailed flow of system generation R20UTO657EJO0101 Rev 1 01 Page 123 of 178 Sep 16 2011 RENESAS
104. el id h which is in the current directory That is be sure to enter the fol lowing two lines at the beginning of file include lt itron h gt include lt kernel h gt include kernel id h 3 No return value is provided for the task start function Therefore declare the task start function as a void function A function that is declared to be static cannot be registered as a task 5 It isn t necessary to describe ext tsk at the exit of task start function If you exit the task from the subroutine in task start function please describe ext tsk in the subroutine 6 Itis also possible to describe the task startup function using the infinite loop include lt itron h gt include lt kernel h gt include kernel id h void task void process Figure 7 1 Example Infinite Loop Task Described in C Language The task is ended by ext tsk automatically if pramga TASK is declared in the MR8C 4 Similarly it is ended by ext tsk when returned halfway of the function by return sentence R20UTO657EJO0101 Rev 1 01 Page 125 of 178 Sep 16 2011 RENESAS MR8C 4 7 Detailed Applications include lt itron h gt include lt kernel h gt include kernel id h void task void for process Figure 7 2 Example Task Terminating with ext_tsk Described in C Language 7 To specify a task use the string written in the task definition item name of the configura tion file wup
105. er When describing the non kernel OS independent interrupt handler in C language observe the following precautions 1 Be sure to declare the return value and argument of the interrupt handler start function as a void type 2 No service call can be issued from a non kernel an OS independent interrupt handler NOTE If this restriction is not observed the software may malfunction 3 Afunction that is declared to be static cannot be registered as an interrupt handler If you want multiple interrupts to be enabled in a non kernel an OS independent interrupt handler always make sure that the non kernel OS independent interrupt handler is as signed a priority level higher than other kernel OS dependent interrupt handlers include lt itron h gt include lt kernel h gt include kernel id h void inthand void process Figure 7 4 Example of Non kernel OS independent Interrupt Handler 28 A configuration file is used to define the relationship between handlers and functions 27 When an kernel OS dependent interrupt handler is declared with pragma INTHANDLER code for the ret_int service call is automati cally generated If you want the non kernel OS independent interrupt handler to be assigned a priority level lower than kernel OS dependent interrupt handlers change the description of the non kernel OS independent interrupt handler to that of the kernel OS dependent interrupt handler R20UTO6
106. er is specified in a program 2 Start address Definition format Symbol or Function Name Definition range None Define the start address of the alarm handler The function name defined here causes the following declaration statement to be output in the kernel id h file 3 Extended information Definition format Numeric value Definition range 0 to OXFFFF Default value 0 Define the extended information of the alarm handler This information is passed as argument to the alarm handler when it starts R20UT0657EJ0101 Rev 1 01 Page 152 of 178 Sep 16 2011 132 N SAS MR8C 4 8 Using Configurator Interrupt vector definition This definition is necessary to use Interrupt function lt lt Format gt gt Interrupt Vector Definition interrupt vector Vector No J os int Kernel managed OS dependent interrupt handler entry address Start address pragma switch Switch passed to PRAGMA extended function l The vector number can be written in the range of 0 to 63 and 247 to 255 However whether or not the defined vector number is valid depends on the microcomputer used Configurator can t create an Initialize routine interrupt control register interrupt causes etc for this defined interrupt You need to create that lt lt Content gt gt 1 Kernel OS dependent interrupt handler Definition format Symbol Definition range
107. erent sequence is followed if the issued service call does not evoke task switching R20UT0657EJ0101 Rev 1 01 Page 13 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel 3 2 2 Processing Procedures for Service Calls from Handlers When a service call is issued from a handler task switching does not occur unlike in the case of a service call from a task However task switching occurs when a return from a handler 7 is made The processing procedures for service calls from handlers are roughly classified into the following three types 1 Aservice call from a handler that caused an interrupt during task execution 2 Aservice call from a handler that caused an interrupt during service call processing 3 A service call from a handler that caused an interrupt multiplex interrupt during handler exe cution 7 The service call can t be issued from OS independent handler Therefore The handler described here does not include the OS independent handler R20UT0657EJ0101 Rev 1 01 Page 14 of 178 Sep 16 2011 131 N SAS MR8C 4 3 Introduction to Kernel Service Calls from a Handler That Caused an Interrupt during Task Execution Scheduling task switching is initiated by the ret int service call See Figure 3 11 TaskA Interrupt handler OS Interrupt Save Registers Service call processing iset flg Restore Registers Task selection SP lt User Scheduler TaskB Restore Regis
108. ernel sysint h and sys ram inc It resides in the directory indicated by environment variable LIB8C e MR8C 4 version file version This file contains description of MR8C 4 s version It resides in the directory indicated by environment vari able LIB8C The configurator reads in this file and outputs MR8C 4 s version information to the startup message 2 When the configurator is executed the files listed below are output Do not define user data in the files output by the configurator Starting up the configurator after entering data definitions may result in the user defined data being lost e System data definition file sys rom inc sys ram inc This file contains definition of system settings Include file mr8c inc This is an include file for the assembly language D number definition file kernel id h The ID numbers of kernel objects are defined Service call information file kernel sysint h This is the include file of the service call usage information R20UT0657EJ0101 Rev 1 01 Page 156 of 178 Sep 16 2011 13 NE SAS MR8C 4 8 Using Configurator Configuration File xxx cfg Default Configuration File default cfg System Data Difinition File sys ram inc sys rom inc kernel sysint h Template File kernel sysint h I cfg8c Template File N IndudeFile sys ram inc mr8c inc mr8c inc kernel id h kernel sysint h MR8C 4 Version File version Figure 8
109. errupt stack ISP Task MR8C 4 service call User Stack Save Registers XXX XXX Stack switching Service cal processing System Stack Task selection Stack switching Restore Registers User Stack Figure 3 24 System Stack and User Stack Switchover from user stack to system stack occurs when an interrupt of vector numbers 0 to 31 or 247 to 255 is generated Consequently all stacks used by the interrupt handler are the system stack R20UT0657EJ0101 Rev 1 01 Page 35 of 178 Sep 16 2011 132 NE SAS 4 Kernel 4 1 Module Structure The MR8C 4 kernel consists of the modules shown in Figure 4 1 Each of these modules is composed of functions that ex ercise individual module features The MR8C 4 kernel is supplied in the form of a library and only necessary features are linked at the time of system genera tion More specifically only the functions used are chosen from those which comprise these modules and linked by means of the Linkage Editor LN30 However the scheduler module part of the task management module and part of the time management module are linked at all times 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 Application Program Task Time Task dependent Management Semaphore Management synchronization Sy
110. es enne enn nnn enne 106 5 9 System Status Management Funcion ennemis nnne nnns 107 get tid Reference task ID in the RUNNING state nennen 108 oeg a eU MM on du UT ETT 109 unl cpu Unlock the CPU aui eter eene edle t dert ec ir Ee t s cid 111 dis dsp Disable dispatching sess eene enne AK AK trennen nnns tret tnnt eaaa A RKK tns na 112 ena dsp NEI EE e e ln DEE 114 Shs ctx Reference context eden dei e pene rrt nr n e rh Rn Me eg e gn ERR ge rk d 115 snsloc Reference CPU stateis cde ee RR e RR OR nk Y dnd ERR Gn e dn kr ER Re T RR ENEE 116 sns dsp Reference dispatching estate 117 5 10 Interrupt Management FUNCTION ener nnne inns P KK KARA KK nennen 118 ret int Returns from an interrupt handler when written in assembly language 119 5 11 System Configuration Management Funcion enne enne 120 ref ver Reference version information ENEE 121 6 Applications Development Procedure Overview EEN 123 EMO iU E ares 123 Te Detailed Applications 1 reete einrichten LEE n ERR I e a ba FER Miva dcn ea EUREN ru aa nS 125 7 1 Program Coding Procedure in C Lanoage nennen nne nennen nnne enne nnns 125 7 11 Task Description Procedure esessssssssseeseeeeenee tne KARA nnn nnnm tnn rennen enses 125 7 12 Writing a Kernel OS Dependent Interrupt Handler sseseeeeenee 127 7 13 Writing Non kernel OS in
111. ev 1 01 Page 108 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference loc cpu Lock the CPU C Language API ER ercd loc cpu Parameters None e Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc loc cpu e Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Funcional description This service call places the system into a CPU locked state thereby disabling interrupts and task dispatches The features of a CPU locked state are outlined below 1 No task scheduling is performed during a CPU locked state 2 No external interrupts are accepted unless their priority levels are higher than the kernel interrupt mask level defined in the configurator 3 Only the following service calls can be invoked from a CPU locked state If any other service calls are invoked operation of the service call cannot be guaranteed ext tsk loc cpu unl cpu sns ctx sns loc ene den The system is freed from a CPU locked state by one of the following operations a Invocation of the unl cpu service call b Invocation of the ext tsk service call Transitions between CPU locked and CPU unlocked states occur only when the loc cpu unl cpu or ext tsk service call is invoked The system must always be in a CPU unlocked state when the interrupt
112. eventflag are cleared with which processing of the service call is terminated If all bits specified in setptn are 0 no operation will be performed for the target eventflag in which case no errors are as sumed however If this service call is to be issued from task context use set flg if issued from non task context use iset flg R20UT0657EJ0101 Rev 1 01 Page 84 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task void set flg ID flg FLGPTN Oxff00 lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 R3 set flg ID FLG3 40ff00H R20UT0657EJ0101 Rev 1 01 Page 85 of 178 Sep 16 2011 131 N SAS MR8C 4 5 Service call reference cir fig Clear eventflag C Language API ER ercd clr flg ID flgid FLGPTN clrptn Parameters ID flgid ID number of the eventflag to be cleared FLGPTN clrptn Bit pattern to be cleared Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc clr flg FLGID CLRPTN e Parameters FLGID ID number of the eventflag to be cleared CLRPTN Bit pattern to be cleared Register contents after service call is issued Register name Content after service call is issued RO Error code A
113. g Service Call Processing eee 16 Service Calls from a Handler That Caused an Interrupt during Handler Execution 2 eee 17 3 3 ODect sis Iu 18 3 3 1 The specification method of the object in a service call seen 18 C MEN rcc HM P P PR PO PR O O POE DL OLE POOR O OE PO IP E od E R PE O LT O OT P OV OE 19 SC E ee EE EE 19 3 4 2 Task Priority and Ready Queue ennt nennen enne nsns tentent 23 3 4 3 Task Priority and Waiting Oueue 2 2 2222 tee eee eee eee ee eee nene eae nnn nnne nennen entrent 24 3 440 Task Control BIock EGB undtesictisuntibeertiel aa exis tr ani bra re Po Qe bara Roe Dr a i CR n 25 3 5 gt Systemi States ica iicet uera dat o Pk dok sega cre RET ties Re Ee Ere OE Rud aiaa rara SSe aeai de eigaran 27 3 51 Task Context and Non task Contest 27 3 5 2 Dispatch Enabled Disabled Gtates AAA 29 3 5 3 CPU Locked Unlocked StateS 2 2 2222 eee eee eee ee nene Ke KK K KKK KA K nnne nnne nennen 29 3 5 4 Dispatch Disabled and CPU Locked StateS 2 2 eeeeee eee eee eee eee een nana tn 29 3 6 Regarding Int rrupts mete dene tete mede RC EE data se nae 30 3 6 1 Types of Interrupt Handers 22 2 22 eee eee ee eee eee nenene nennen nnne trennen tnn nnne nennt tnn 30 3 6 2 TheUseof Non maskable I nterrupt essent nnne nnne nennen nnn 30 ER GE e vie geil ele Hie Lee 31 3 6 4 Permission and prohibition of interrupt nennen nennen nnne nnne 33 When prohibiting in
114. g ena dsp once after issuing dis dsp several times The above status transition can be summarized in Table 3 3 12 4 Regarding Initially Activated Task MR8C 4 allows you to specify a task that starts from a READY state at system startup This specification is made by set ting the configuration file Refer to 8 1 2 for details on how to set R20UT0657EJ0101 Rev 1 01 Page 176 of 178 Sep 16 2011 132 NE SAS 13 Appendix 13 1 Assembly Language Interface When issuing a service call in the assembly language you need to use macros prepared for invoking service calls Processing in a service call invocation macro involves setting each parameter to registers and starting ex ecution of a service call routine by a software interrupt If you issue service calls directly without using a ser vice call invocation macro your program may not be guaranteed of compatibility with future versions of MR8C 4 The table below lists the assembly language interface parameters The values set forth in uITRON specifica tions are not used for the function code Task Management Function Rama ServiceCall INTNo FuncCode FuncCode E mp oje je o M M lt E R EE hem 3 je je mm e jee ss je em L 1 Lb P E Task Dependent Synchronization Function Parameter ReturrParameter ServiceCall INTNO FuncCode i M M M CS we s 2 jee je aw 2 2
115. gal option gt x The configurator s command option is erroneous cfg8c Error illegal argument gt xx The configurator s startup format is erroneous cfg8c Error can t write open lt XXXX gt The XXXX file cannot be created Check the directory attribute and the remaining disk capacity available cfg8c Error can t open lt XXXX gt The XXXX file cannot be accessed Check the attributes of the XXXX file and whether it actually exists cfg8c Error can t open version file The MR8C 4 version file version cannot be found in the directory indicated by the environment variable LIBSC cfg8c Error can t open default configuration file The default configuration file cannot be accessed default cfg is needed in the current directory or directory LIB8C specifying cfg8c Error can t open configuration file lt xxxx cfg gt The configuration file cannot be accessed Check that the file name has been properly designated cfg8c Error illegal XXXX xx near line xxx xxxx cfg The value or ID number in definition item XXXX is incorrect Check the valid range of definition cfg8c Error Unknown XXXX gt xx near line xx xxxx cfg The symbol definition in definition item XXXX is incorrect Check the valid range of definition cfg8c Error too big XXXX s ID number gt xx xxxx cfg A value is set to the ID number in XXXX definition that exceeds the total number of objects defined The ID R20UT06
116. guage gt gt include mr8c inc GLB task task PUSHM A0 can wup ID TASK3 R20UT0657EJ0101 Rev 1 01 Page 69 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference rel wai Release task from waiting irel wai Release task from waiting handler only C Language API ER ercd rel wai ID tskid ER ercd irel wai ID tskid e Parameters ID tskid ID number of the target task e Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc rel wai TSKID irel wai TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code A0 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is not an wait state Functional description This service call forcibly release the task indicated by tskid from waiting except SUSPENDED state to place it into READY or RUNNING state The forcibly released task returns the error code E RLWAI If the target task has been en queued in some waiting queue the task is dequeued from it by execution of this service call If this service call is issued to a task in WAITING SUSPENDED state the target task is released from WAITING state and goes to SUSPENDED state If the target task is not in WAITING state the error code E OBJ is returned This service ca
117. h a start code nennen nre nnne 55 ista tsk Activate task with a start code handler only 55 ext tsk Terminate invoking task sariri eniai dani aada eala a aia aaan aa Ea ada ai Tana i aiaa alagi 57 ter tsk Terminatetask oinensis n Eara EEEa ENEE EN cus ee ntn Ehe EI en Da 59 chg pri Change task Drioritv nennen nnne tenen nnne tenens KE K KE REKREA KRK tnnt 61 5 2 Task Dependent Synchronization Funchon eene nnne ens 63 slp tsk Put task to sleep utet te dee EE tem det rene The ees 64 wup tsk Wakeup task ee e mete eet ca Pe OD ER C EP LEE dare aa 66 iwup tsk Wakeup task handler only 66 can wup Cancel wakeup request sse cage KK KA K A K KKK KA KK KARA RK RK RK KA 68 rel wai Release task from walting ENNEN 70 ire wai Release task from waiting handler ov 70 sus tsk S sperid task urbe etr E ee e nt ER aE Ao nat kakaa ER den EE Rr ne E Een e Don ne aaae 72 rsm tsk Resume suspended task eesssesesseeeeeeen innen nnne interim KE KA KARA natn nennen nene 74 dly tsk Ee EA oec nte e Reed De vate EE Ser EORR LY ERR ERR 76 5 3 Synchronization amp Communication Function Semaphore lt lt lt lt seo rrns 78 sig sem Release semapborereeource cae eee nene nene K KK RK RK tnnt entere 79 isig sem Release semaphore resource handler only sse aan een 79 wai sem Acquire semaphore reSOUrCE e ee eeeeeee4 eee eee NENNEN 81 pol sem Acquire semaphore resour
118. h task and change the register contents upon each task switching so that it looks as if a number of microcomputers exist See Figure 3 6 Key input Remote control Task Task Ro LM s Register Register Figure 3 6 Task Switching The example presented in Figure 3 7 indicates how the individual task registers are managed In reality it is necessary to provide not only a register but also a stack area for each task R20UT0657EJ0101 Rev 1 01 Page 10 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel Memory map Register i i I SCH Remote control Task Key input ien RO l LED illumination Ld Task PC SP l i I Real time Figure 3 7 Task Register Area Figure 3 8 shows the register and stack area of one task in detail In the MR8C 4 the register of each task is stored in a stack area as shown in Figure 3 8 This figure shows the state prevailing after register storage R20UT0657EJ0101 Rev 1 01 Page 11 of 178 Sep 16 2011 131 N SAS MR8C 4 3 Introduction to Kernel Key input task Key input Register stored SFR Figure 3 8 Actual Register and Stack Area Management 3 2 Service Call How does the programmer use the kernel functions in a program First it is necessary to call up kernel function from the program in some way or other Calling a kernel function is referred to as a
119. he MR8C A e 7 Detailed Applications Presents useful information and precautions concerning applications program development with MR8C 4 e 8 Using Configurator Describes the method for writing a configuration file and the method for using the configurator in detail e 10 Sample Program Description Describes the MR8C 4 sample applications program which is included in the product in the form of a source file 11 Stack Size Calculation Method Describes the calculation method of the task stack size and the system stack size 12 Note Presents useful information and precautions concerning applications program development with MR8C 4 13 Appendix Data type and assembly language interface R20UT0657EJ0101 Rev 1 01 Page 1 of 178 Sep 16 2011 2tENESAS 2 General Information 2 1 Objective of MR8C 4 Development In line with recent rapid technological advances in microcomputers the functions of microcomputer based products have become complicated In addition the microcomputer program size has increased Further as product development competi tion has been intensified manufacturers are compelled to develop their microcomputer based products within a short period of time In other words engineers engaged in microcomputer software development are now required to develop larger size pro grams within a shorter period of time To meet such stringent requirements it is necessary to take the following considera tions into acc
120. he description of the non kernel OS independent interrupt handler to that of the kernel OS dependent interrupt handler 3 Use the GLB pseudo directive R20UT0657EJ0101 Rev 1 01 Page 131 of 178 Sep 16 2011 132 NE SAS MR8C 4 7 Detailed Applications 7 3 Modifying MR8C A Startup Program MR8C 4 comes with two types of startup programs as described below Sstart a30 This startup program is used when you created a program using the assembly language crtOmr a30 This startup program is used when you created a program using the C language This program is derived from start a30 by adding an initialization routine in C language The startup programs perform the following Initialize the processor after a reset Initialize C language variables crtOmr a30 only Set the system timer Initialize MR8C 4 s data area Copy these startup programs from the directory indicated by environment variable LIB8C to the current directory If necessary correct or add the sections below Setting processor mode register Set a processor mode matched to your system to the processor mode register 53th line in crtOmr a30 Adding user required initialization program When there is an initialization program that is required for your application add it to the 140th line in the C lan guage startup program crtOmr a30 e Initialization of the standard I O function Comment out the 96th 97th line in the C
121. he following message are a warning A warning can be ignored providing that its content is understood cfg8c Warning system is not defined xxxx cfg cfg8c Warning system XXXX is not defined xxxx cfg System definition or system definition item XXXX is omitted in the configuration file cfg8c Warning task x XXXX is not defined near line xxx xxxx cfg The task definition item XXXX in ID number is omitted cfg8c Warning Already definition XXXX near line xxx xxxx cfg XXXX has already been defined The defined content is ignored check to delete the extra definition cfg8c 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 cfg8c Warning interrupt vector x s default is not defined near line xxx xxxx cfg The interrupt vector of vector number x in the configuration file is not defined in the default configuration file cfg8c Warning system stack size is an uneven number near line xxx cfg8c Warning task x stack size is an uneven number near line xxx Please set even size in system stack size or task x stack size R20UT0657EJ0101 Rev 1 01 Page 161 of 178 Sep 16 2011 32 NESAS 9 Table Generation Utility 9 1 Summary The utility mr8ctbl is a command line tool that after collecting service call information used in the application generates service call tables and interrupt vector tables In kernel sys
122. hen determines whether or not to initi ate task execution This results in accomplishing synchronization between tasks e Semaphore Reads the semaphore counter value controlled within the MR8C 4 and then determines whether or not to initiate task execution This also results in accomplishing synchronization between tasks Data queue Performs 16 bit data communication between tasks 7 This handler actuates once only at preselected times 18 This handler periodically actuates R20UT0657EJ0101 Rev 1 01 Page 37 of 178 Sep 16 2011 132 N SAS MR8C 4 4 Kernel 4 2 1 Task Management Function The task management function is used to perform task operations such as task start stop and task priority updating The MR8C 4 kernel offers the following task management function service calls Activate Task sta tsk ista tsk Activates the task changing its status from DORMANT to either READY or RUNNING In this service call unlike in act tsk iact tsk startup requests are not accumulated but startup code can be specified Terminate Invoking Task ext tsk When the issuing task is terminated its state changes to DORMANT state The task is therefore not executed until it is restarted If startup requests are accumulated task startup processing is performed again In that case the is suing task behaves as if it were reset If written in C language this service call is automatically invoked at return from the task regardless
123. how to calculate a stack size using e When an application is written in the assembly language User stack size Sections used in user program size of registers used size of registers which are written as task context in cfg file 6 bytes PC FLG register size Sections used in MR8C 4 Sections used in user program The necessary stack size of a task is the sum of the stack size used by the task in subroutine call plus the size used to save registers to a stack in that task Sections used in MR8C A The sections used in MR8C 4 refer to a stack size that is used for the service calls issued When issuing multiple service calls include the maximum value of the stack sizes used by those service calls as the sections used by MR8C 4 as you calculate the necessary stack size Figure 3 1 shows an example for calculating a user stack In the example below the registers used by the task are RO RI R2 and AQ 5 f written in the C language this size is fixed R20UT0657EJ0101 Rev 1 01 Page 168 of 178 Sep 16 2011 132 N SAS MR8C 4 11 Stack Size Calculation Method Stack growing direction ss When use register RO R1 R2 A0 8bytes 2bytes jsr sub 12bytes PC FL G size of registers used gt sta tsk 16bytes P C LG 4size of registers used stack size used by prev msg prev dtq 18bytes Figure 11 3 Example of Use Stack Size Calculation R20UT0657EJ0101
124. ice call is O Task Service call issued Service call processing I I l flag Dal 0 ln 11 _________ 0 I l IPL 0 lt system IPL 0 gt lt systemiPL lt 0 I l Figure 3 22 Interrupt control in a Service Call that can be Issued from only a Task R20UT0657EJ0101 Rev 1 01 Page 31 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel For service calls that can be issued from only non task context or from both task context and non task context When thel flag before issuing a service call is 1 Loud Servi II issued service call processin Task or Handler ervice call issu p g Handler T m l flag Luis 0 4 1 lt 1 l IPL 4 ej4 system PL l lt 4 gt lt systemIPL lt 4 I I i When the flag before issuing a service call is 0 Jeka Servi II issued service call processin Task or I flag 0 D la 0 I lt system PL gt lt 4 IPL 4 i lt system IPL 4 Figure 3 23 Interrupt control in a Service Call that can be Issued from a Task independent R20UT0657EJ0101 Rev 1 01 Page 32 of 178 Sep 16 2011 2tENESAS MR8C 4 3 Introduction to Kernel 3 6 4 Permission and prohibition of interrupt The I flag and IPL are changed in the service call as shown in Figure 3 22 and Figure 3 23 Therefore please correspond as follows when you control the permission prohibition of interr
125. id ID number of the eventflag waited for FLGPTN waiptn Wait bit pattern MODE wfmode Wait mode FLGPTN p_flgptn Pointer to the area to which bit pattern is returned when released from wait Return Parameters ER ercd Terminated normally E OK or error code FLGPTN p flgptn Pointer to the area to which bit pattern is returned when released from wait Assembly language API include mr8c inc wai flg FLGID WAIPTN WFMODE pol flg FLGID WAIPTN WFMODE e Parameters FLGID ID number of the eventflag waited for WAIPTN Wait bit pattern WFMODE Wait mode Register contents after service call is issued Register name Content after service call is issued RO Error code RI Wait mode R2 bit pattern is returned when released from wait R3 Wait bit pattern A0 ID number of the eventflag waited for Error code E RLWAI Forced release from waiting E TMOUT Polling failure E ILUSE Service call improperly used Tasks present waiting for TA WSGL attribute eventflag R20UT0657EJ0101 Rev 1 01 Page 88 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference Functional description This service call waits until the eventflag indicated by flgid has its bits specified by waiptn set according to task awaking conditions indicated by wfmode Returned to the area pointed to by p flgptn is the eventflag bit pattern at the time the task is released from WAITING state If the target eventflag has
126. if msg 0 lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 R1 R3 sta_tsk ID_TASK4 012345678H R20UT0657EJ0101 Rev 1 01 Page 56 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference ext tsk Terminate invoking task C Language API ER ercd ext tsk Parameters None e Return Parameters Not return from this service call Assembly language API include mr8c inc ext tsk Parameters None Register contents after service call is issued Not return from this service call Error code Not return from this service call Functional description This service call terminates the invoking task In other words it places the issuing task from RUNNING state into DOR MANT state However This service call is designed to be issued automatically at return from a task In the invocation of this service call the resources the issuing task had acquired previously e g semaphore are not re leased This service call can only be used in task context This service call can be used even in a CPU locked state but cannot be used in non task context R20UT0657EJ0101 Rev 1 01 Page 57 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void t
127. iguration Management Function Service Call formation No Service Call Function System State T N E D U L 1 ref ver S References version in O olojo Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning 99999 R20UT0657EJ0101 Sep 16 2011 Rev 1 01 T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 132 N SAS Page 120 of 178 MR8C 4 5 Service call reference ref ver Reference version information C Language API ER ercd ref ver T RVER pk rver Parameters T RVER pk rver Pointer to the packet to which version information is returned Contents of pk rver typedef struct t rver UH maker 0 2 Kernel manufacturer code UH prid 2 2 Kernel identification number UH spver 4 2 ITRON specification version number UH prver 6 2 Kernel version number UH prno 4 8 2 Kernel product management information T RVER Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc ref ver PK VER Parameters PK VER Pointer to the packet to which version information is returned Register contents after service call is iss
128. int h that is included by kernel h it is so defined that when service call functions are used the service call information will be output to the mrc file by the assert control instruction Using these service call information files as its input mr8ctbl generates a service call table in such a way that only the service calls used in the system will be linked Furthermore mkritbl generates an interrupt vector table based on the vector table template files output by cfg8c and the mrc file 9 2 Environment Setup Following environment variables need to be set e LIB8C Installation directory gt lib8c 9 3 Table Generation Utility Start Procedure The table generation utility is started in the form shown below C gt mr8ctbl directory name or file name gt For the parameter normally specify the directory that contains the mrc file that is generated when compiled Multiple directories or files can be specified Note that the mrc file present in the current directory is unconditionally selected for input Also it is necessary that vector tpl generated by cfg8c be present in the current directory 9 4 Notes Please specify mrc files generated by compilation of application without omission When there is an omission in the specification of mrc files some service call modules might not be build into the load module R20UT0657EJ0101 Rev 1 01 Page 162 of 178 Sep 16 2011 32 NESAS 10 Sample Program Description 1
129. is abled and CPU locked states Stack User stack System stack The processes executed in non task context include the following 1 Interrupt Handler A program that starts upon hardware interruption is called the interrupt handler The MR8C 4 is not concerned in interrupt handler activation Therefore the interrupt handler entry address is to be directly written into the interrupt vector table There are two interrupt handlers Non kernel interrupts OS independent interrupts and kernel interrupts OS dependent interrupts For details about each type of interrupt refer to Section 3 6 The system clock interrupt handler isig tim is one of these interrupt handlers 2 Cyclic Handler The cyclic handler is a program that is started cyclically every preset time The set cyclic handler may be started or stopped by the sta cyc or stp cyc service call 3 Alarm Handler The alarm handler is a handler that is started after the lapse of a specified relative time of day The alarm handler startup time of day is determined by a time of day relative to the time of day set by sta alm The cyclic and alarm handlers are invoked by a subroutine call from the system clock interrupt timer interrupt handler Therefore cyclic and alarm handlers operate as part of the system clock interrupt handler Note that when the cyclic or alarm handler is invoked it is executed in the interrupt priority level of the system clock interrupt
130. k Operation As indicated above the kernel changes the task to execute at fixed time intervals This task switching may also be referred to as dispatching 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 inter ruption See Figure 3 5 R20UT0657EJ0101 Rev 1 01 Page 9 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel Program execution Program execution interrupt resumed Key input Task Remote control Task l During this interval it 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 kernel therefore it is only necessary to manage the register for eac
131. k k k k k k k k K K K A A kc k k ck ck ckck ck ck ck ck ck sk kc k e ke X ke 10 11 include lt itron h gt 12 include lt kernel h gt 13 include kernel id h 14 15 16 void main VP INT stacd 17 18 sta tsk ID task1 0 19 sta tsk ID task2 0 20 sta cyc ID cyhl 21 22 void task1 VP INT stacd 23 1 24 while 1 25 wai sem ID seml 26 slp tsk 27 sig sem ID seml 28 29 3 30 31 void task2 VP_INT stacd 32 33 while 1 34 wai sem ID seml 39 sig sem ID seml 36 37 38 39 void cyhl VP INT exinf 40 41 iwup tsk ID taskl 42 R20UT0657EJ0101 Rev 1 01 Page 164 of 178 Sep 16 2011 132 N SAS MR8C 4 10 3 Configuration File t J RK HK HK kk kk kk kk kk kk kk kk kk kk ck kk kk kk kk kk kk kk Sk kk Sk ke kk kkk kkk kk kk kc k kc k kk kk k k k k Copyright C 2009 2011 Renesas and Renesas Solutions Corp All rights reserved MR8C 4 System Configuration File SId smp cfg 496 2006 04 05 06 28 56Z inui 2 3 4 5 6 7 8 9 10 Sample Program Description Electronics Corporation J RK HK kk kk kk kk kk kk kk kk ke kk kk kk kk kk kk kk kk kk kk kk kk Sk ke kk kkk kkk kk kc k kc kok kk kk k e k k 10 System Definition 11 system 12 stack size 200 13 priority 10 14 system IPL 4 5 tic nume 1 16 tic_deno Il 17 18 System Clock Definition 19 clock 20 mpu_clock 20MH
132. le 3 2 Table 3 2 Invocable Service Calls in a CPU Locked State loc cpu sns loc unl cpu sns Cl ext tsk sns dsp 3 5 4 Dispatch Disabled and CPU Locked States In uITRON 4 0 Specification the dispatch disabled and the CPU locked states are clearly discriminated Therefore if the unl cpu service call is issued in a dispatch disabled state the dispatch disabled state remains intact and no task scheduling is performed State transitions are summarized in Table 3 3 Table 3 3 CPU Locked and Dispatch Disabled State Transitions Relating to dis dsp and loc cpu State Content of state dis dsp ena dsp loc cpu unl cpu number CPU locked Dispatch disabled executed executed executed executed state state 1 O X X X gt 1 gt 3 2 O O X X gt 2 gt 4 3 X X gt 4 gt 3 gt 1 gt 3 4 X O gt 4 gt 3 gt 2 gt 4 15 If a service call not issuable is issued when dispatch disabled MR8C 4 doesn t return the error and doesn t guarantee the operation 1 MR8C 4 does not return an error even when an uninvocable service call is issued from a CPU locked state in which case however its operation cannot be guaranteed R20UT0657EJ0101 Sep 16 2011 Rev 1 01 134 NE SAS Page 29 of 178 MR8C 4 3 Introduction to Kernel 3 6 Regarding Interrupts 3 6 1 Types of Interrupt Handlers MR8C 4 s interrupt handlers consist of kernel OS dependent interrupt handlers a
133. lectronics 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 communications equipme
134. led from CPU unlocked state L Can be called from CPU locked state 99999 R20UT0657EJ0101 Rev 1 01 Page 103 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference sta alm Start alarm handler operation C Language API ER ercd sta alm ID almid RELTIM almtim Parameters ID almid ID number of the alarm handler to be operated RELTIM almtim Alarm handler startup time relative time Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc sta alm ALMID ALMTIM e Parameters ALMID ID number of the alarm handler to be operated ALMTIM Alarm handler startup time relative time Register contents after service call is issued Register name Content after service call is issued RO Error code RI Alarm handler startup time relative time A0 ID number of the alarm handler to be operated Error code None Functional description This service call sets the activation time of the alarm handler indicated by almid as a relative time of day after the lapse of the time specified by almtim from the time at which it is invoked and places the alarm handler into an operational state If an already operating alarm handler is specified the previously set activation time is cleared and updated to a new activa tion time If almtim 0 is specified the alarm handler starts at the next time tick The values specified for almtim must be within
135. ll forbids specifying the issuing task itself for tskid If this service call is to be issued from task context use rel wai if issued from non task context use irel wai This means that tasks cannot be resumed from SUSPENDED state by this service call Only the rsm tsk irsm tsk frsm tsk and ifrsm tsk service calls can release them from SUSPENDED state R20UT0657EJ0101 Rev 1 01 Page 70 of 178 Sep 16 2011 134 NE SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if rel wai ID main E OK error Can t rel wai main n lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM AO rel_wai ID_TASK2 R20UT0657EJ0101 Rev 1 01 Page 71 of 178 Sep 16 2011 2tENESAS MR8C 4 5 Service call reference sus tsk Suspend task C Language API ER ercd sus tsk ID tskid e Parameters ID tskid ID number of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc sus tsk TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code A0 ID number of the target task Error code E OBJ Object
136. m task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 132 N SAS Page 107 of 178 MR8C 4 5 Service call reference get tid Reference task ID in the RUNNING state C Language API ER ercd get tid ID p tskid Parameters ID p tskid Pointer to task ID Return Parameters ER ercd Terminated normally E_OK ID p tskid Pointer to task ID Assembly language API include mr8c inc get tid e Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code A0 Acguired task ID Error code None Functional description This service call returns the task ID currently in RUNNING state to the area pointed to by p tskid If this service call is issued from a task the ID number of the issuing task is returned This service call can only be issued from task context and cannot be issued from non task context Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task ID tskid get tid amp tskid lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM AO get_tid R20UT0657EJ0101 R
137. n to Kernel Key input Remote control microcomputer microcomputer I I I I I I I I I I I I I I I I I I I I I Arbiter l microcomputer I I I I I I I I I I I I I I I I I I I I LED illumination microcomputer Volume control Monitor Mechanical microcomputer microcomputer control microcomputer Figure 3 2 Microcomputer based System Example Audio Eguipment Using independent microcomputers for various functions as indicated in the above example offers the following advan tages 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 devel opment can easily be conducted by a number of engineers On the other hand there are the following disadvantages 1 The number of parts used increases thereby raising the product cost 2 Hardware design is complicated 3 Product physical size is enlarged Therefore if you employ the real time OS in which a number of programs to be operated by a number of microcomputers are placed under software control of one microcomputer making it appear that the programs run on separate microcomput ers you can obviate all the above disadvantages while retaining the above mentioned advantages Figure 3 3 shows an example system that will be obtained if the real time OS is incorporated in the system indicated in Figu
138. nction System State TN E DV U L 1 sta tsk B Starts task and specifies start code O oloo 2 ista_tsk 0 0 0 0 3 ext tsk S B Exits current task O O0 0 0 O0O 4 ter tsk S B Forcibly terminates a task O oloo 5 chg pri S B Changes task priority O olojo Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state R20UT0657EJ0101 Rev 1 01 Page 54 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference sta tsk Activate task with a start code ista tsk Activate task with a start code handler only C Language API ER ercd sta tsk ID tskid VP INT stacd ER ercd ista tsk ID tskid VP INT stacd e Parameters ID tskid ID number of the target task VP INT stacd Task start code e Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc sta tsk TSKID STACD ista tsk TSKID STACD e Parameters TSKID ID number of the target task STATCD Task start code Register contents after service call is issued Register name Content after service call is issued RO Error code RI Task start code A0 ID number of the
139. nd non kernel OS independent interrupt handlers The following shows the definition of each type of interrupt handler Kernel OS dependent interrupt handler An interrupt handler whose interrupt priority level is lower than a kernel interruption mask level OS interrupt prohibition level is called kernel OS dependent interrupt handler That is interruption priority level is from 0 to system IPL A service call can be issued within a kernel OS dependent interrupt handler However interrupt is delayed until it becomes receivable the kernel management OS dependence interrupt handler generated during service call processing kernel management OS dependence interruption Non kernel OS independent interrupt handler An interrupt handler whose interrupt priority level is higher than a kernel interrupt mask level OS interrupt pro hibition level is called non kernel interrupt handler OS independent handler That is interruption priority level is from system IPL 1 to 7 A service call cannot be published within an interruption OS independence kernel management outside hair drier However the kernel management generated during service call processing outside even if it is the section where interruption cannot receive a kernel management OS dependence interrupt handler OS independence it is possible to receive interruption kernel management outside OS independence Figure 3 21 shows the relationship between the non kernel
140. ne the user stack size for each task The user stack means a stack area used by each individual task MR8C 4 requires that a user stack area be allocated for each task which amount to at least 8 bytes Initial priority of task Definition format Numeric value Definition range 1 to maximum value of priority in system definition Default value 1 Define the priority of a task at startup time As for MR8C 4 s priority the lower the value the higher the priority 5 Regisers Used Definition format Symbol Symbol Definition range Selected from RO R1 R2 R3 A0 A1 SB FB Default value All registers Define the registers used in a task MR8C 4 handles the register defined here as a context Specify the RO and R1 register because task startup code is set in R1 when the task starts and return parameter is returned in RO However the registers used can only be selected when the task is written in the assembly language Select all registers when the task is written in the C language When selecting a register here be sure to select all regis ters that store service call parameters used in each task MR8C 4 kernel does not change the registers of bank If this definition is omitted it is assumed that all registers are selected R20UT0657EJ0101 Rev 1 01 Page 145 of 178 Sep 16 2011 132 N SAS MR8C 4 8 Using Configurator 6 Section name in which the stack is located Definition format
141. not including the system clock interrupt handler here and OS independent interrupt handler R20UT0657EJ0101 Rev 1 01 Page 170 of 178 Sep 16 2011 134 NE SAS MR8C 4 11 Stack Size Calculation Method o The maximum system stack size among the service calls to be used 2 gt BuThe system stack size to be used by the interrupt handler Interrupt Interrupt The necessary system stack Figure 11 4 System Stack Calculation Method R20UT0657EJ0101 Rev 1 01 Page 171 of 178 Sep 16 2011 132 N SAS MR8C 4 11 Stack Size Calculation Method Stack size Bi used by interrupt handlers The stack size used by an interrupt handler that is invoked during a service call can be calculated by the eguation below The stack size Bi used by an interrupt handler is shown below C language Using the stack caliculation utility calculate the stack size of each interrupt handler Refer to the manual of STK Viewer for detailed use of STK Viewer Assembly language The stack size to be used by OS dependent interrupt handler register to be used user size stack size to be used by service call The stack size to be used by OS independent interrupt handler register to be used user size User size is the stack size of the area written by user YVA Context 20bytes L gt Interrupt 2bytes lt jsr func 20bytes iset flg ret int SS 42bytes Context 20 bytes when written in C language When wri
142. nt 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 Further Renesa
143. ntflag e Wait for Eventflag wai flg Waits until the eventflag is set to a certain pattern There are two modes as listed below in which the eventflag is waited for AND wait Waits until all specified bits are set OR wait Waits until any one of the specified bits is set e Wait for Eventflag polling pol flg Examines whether the eventflag is in a certain pattern In this service call tasks are not placed in WAITING state R20UT0657EJ0101 Rev 1 01 Page 46 of 178 Sep 16 2011 132 NE SAS MR8C 4 4 Kernel 4 2 5 Synchronization and Communication Function Data Queue The data queue is a mechanism to perform data communication between tasks In Figure 4 12 for example task A can transmit data to the data queue and task B can receive the transmitted data from the data queue Task A Task B ezed ejed GE Figure 4 12 Data queue Data in width of 16 bits can be transmitted to this data queue The data queue has the function to accumulate data The accumulated data is retrieved in order of FIFO However the number of data that can be accumulated in the data queue is limited If data is transmitted to the data queue that is full of data the service call issuing task goes to a data transmission wait state There are following data queue service calls that are provided by the MR8C 4 kernel Send to Data Queue snd_dtq The data is transmitted to the data queue If the data queue is full of data the t
144. odular software development However the conventional methods are not adequate for the purpose of solving the problems Under these circumstances it is necessary to introduce a new system named real time OS To answer the above mentioned demand Renesas has developed a real time operating system tradenamed MR8C 4 for use with the R8C Family of 16 bit microcomputers When the MR8C 4 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 depend ent 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 engi neers can be allocated to individual tasks so that all steps from development to debugging can be conducted inde pendently for each task Further the introduction of the real time OS makes it easy to start debugging some already finished tasks even if the entire program is not completed yet Since engineers can be allocated to individual tasks work assignment is easy 3 OS Operating System R20UT0657EJ0101 Rev 1 01 Page 2 of 178 Sep 16 2011 132 NE SAS MR8C 4 2 General Information 3
145. of the target task Error code E OBJ Object status invalid task indicated by tskid is an inactive state Functional description This service call clears the wakeup reguest count of the target task indicated by tskid to 0 This means that because the tar get task was in either WAITING state nor WAITING SUSPENDED state when an attempt was made to wake it up by wup tsk or iwup_tsk before this service call was issued the attempt resulted in only accumulating wakeup requests and this service call clears all of those accumulated wakeup requests Furthermore the wakeup request count before being cleared to 0 by this service call i e the number of wakeup requests that were issued in vain wupcnt is returned to the issuing task If a wakeup request is issued while the target task is in DORMANT state the error code E OBJ is returned If TSK SELF is specified for tskid it means specifying the issuing task itself This service call can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 68 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task ER_UINT wupcnt wupcnt can wup ID main if wup cnt gt 0 printf wupcnt din wupcnt lt lt Example statement in assembly lan
146. on range RA RB OTHER NOTIMER Default value NOTIMER Define the hardware timers used for the system clock If you do not use a system clock define NOTIMER l Initialize the timer in start up routine The cfg8c outputs following macros to the kernel id h Please initialize the timer based on this infor mation MR MPUCLOCK MPU operating frequency described in the cfg file MR UNITTIME The interrupt interval of the system clock was expressed with us MR TIMER IPL The IPL value of the system clock interrupt 2 Define the relocatable interrupt vector as follows interrupt vector Vector number gt entry address RI SYS STMR INH os int YES h 3 System clock interrupt priority level Definition format Numeric value Definition range 1 to Kernel mask OS interrupt disable level in system definition Default value 4 Define the priority level of the system clock timer interrupt The value set here must be smaller than the kernel mask OS interrupt disable level R20UT0657EJ0101 Rev 1 01 Page 143 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator Interrupts whose priority levels are below the interrupt level defined here are not accepted during system clock interrupt handler processing Task definition lt lt Format gt gt Tasks Definition task ID No name ID name entry address Star
147. or code Assembly language API include mr8c inc wup tsk TSKID iwup tsk TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code A0 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is an inactive state E OOVR Oueuing overflow Functional description If the task specified by tskid has been placed into WAITING state by slp tsk this service call wakes up the task from WAITING state to place it into READY or RUNNING state Or if the task specified by tskid is in WAIT ING SUSPENDED state this service call awakes the task from only the sleeping state so that the task goes to SUS PENDED state If a wakeup request is issued while the target task remains in DORMANT state the error code E OBJ is returned to the service call issuing task If TSK SELF is specified for tskid it means specifying the issuing task itself If TSK SELF is specified for tskid in non task context operation of the service call cannot be guaranteed If this service call is issued to a task that has not been placed in WAITING state or in WAITING SUSPENDED state by execution of slp tsk the wakeup request is accumulated More specifically the wakeup request count for the target task to be awakened is incremented by 1 in which way wakeup requests are accumulated The maximum value of the wakeup reque
148. ount 1 To enhance software recyclability to decrease the volume of software to be developed One way to provide for software recyclability is to divide software into a number of functional modules wherever possible This may be accomplished by accumulating a number of general purpose subroutines and other program segments and using them for program development In this method however it is difficult to reuse programs that are dependent on time or timing In reality the greater part of application programs are dependent on time or tim ing 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 development 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 es sential that communication be properly maintained among the team members 3 To enhance software production efficiency so as to increase the volume of possible software development per engineer One way to achieve this target would be to educate engineers to raise their level of skill Another way would be to make use of a structured descriptive assembler C compiler or the like with a view toward facilitating program ming It is also possible to enhance debugging efficiency by promoting m
149. ov w sizeof SECT R3 39 smovf b 40 endm 41 42 Interrupt section start 43 44 glb SYS INITIAL 45 section MR KERNEL CODE ALIGN 46 SYS INITIAL 47 48 after reset this program will start 49 50 ldc ZIL Sys Sp amp OFFFFH ISP set initial ISP 51 52 mov b 2H OAH 53 mov b 00 PMOD Set Processor Mode Regsiter 54 mov b 0H OAH 55 ldc 00H FLG 56 ldc ZIL Sys Sp amp OFFFFH fb 57 ldc SB sb 58 59 60 t 61 ISSUE SYSTEM CALL DATA INITIALIZE 62 63 For PD30 64 INIT ISSUE SYSCALL 65 66 f t 613 MR RAM DATA O zero clear 68 t 69 N BZERO MR RAM top MR RAM 70 71 72 NEAR area initialize R20UT0657EJ0101 Sep 16 2011 Rev 1 01 132 NE SAS Page 133 of 178 MR8C 4 7 Detailed Applications SCH 74 bss zero clear T5 s 76 N BZERO TOPOF bss SE bss SE 77 N BZERO TOPOF bss SO bss SO 78 N BZERO TOPOF bss NE bss NE 79 N BZERO TOPOF bss NO bss NO 80 81 82 initialize data section 83 84 N BCOPY TOPOF data SEI TOPOF data SE data SE 85 N BCOPY TOPOF data SOI TOPOF data SO data SO 86 N BCOPY TOPOF data NEI TOPOF data NE data NE 87 N BCOPY TOPOF data NOI TOPOF data NO data NO 88 89 Ide Sys Sp amp OFFFFH sp 90 ldc
150. over the kernel doesn t take part in the power control function and note the following points especially 1 About the stop and the start of the system clock The kernel doesn t stop and start the timer interrupt used as a system clock to transit the operational mode Please program the stop and the start processing in the user program if necessary 2 About the time out processing and the start processing of the time event handler The change of clock supply for the timer used as a system clock or the stopping it are needed for the transition of the operational mode Please note the following kernel operation The cyclic handler and the alarm handler don t start nor those start are delayed The late waiting release by dv tsk are processed nor the waiting release is delayed behind speci fied time R20UT0657EJ0101 Rev 1 01 Page 34 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel 3 8 Stacks 3 8 1 System Stack and User Stack The MR8C 4 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 MR8C 4 it is necessary to furnish the stack area for each task System Stack This stack is used within the MR8C 4 during service call processing When a service call is issued from a task the MR8C 4 switches the stack from the user stack to the system stack See Figure 3 24 The system stack use the int
151. pt handler with regisers of bank 1 have multiple interrupts of an interrupt handler with regis ers of bank 1 the program can not execute normally R20UTO657EJO0101 Rev 1 01 Page 175 of 178 Sep 16 2011 RENESAS MR8C 4 12 Note 12 3Regarding Delay Dispatching MR8C 4 has four service calls related to delay dispatching dis dsp ena dsp loc cpu unl cpu The following describes task handling when dispatch is temporarily delayed by using these service calls 1 When the execution task in delay dispatching should be 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 dispatch is being delayed Task under execution is in a RUNNING 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 Precautions No service call e g slp tsk wai sem can be issued that may place the own task in a wait state while in a state where dispatch is disabled by dis dsp loc cpu or iloc cpu ena dsp and dis dsp cannot be issued while in a state where interrupts and dispatch are disabled by loc cpu iloc cpu Disabled dispatch is re enabled by issuin
152. queue which has no data stored in it the task that issued the service call goes from RUNNING state to a data reception wait state and is enqueued in a data reception waiting queue At this time the task is enqueued in order of FIFO For the prev dtq service calls the task returns immediately and responds to the call with the error code E TMOUT The task placed into a wait state by execution of the rcv dtq service call is released from the wait state in the following cases When the rcv dtq or prov dtq service call is issued with task awaking conditions thereby satis fied The error code returned in this case is E OK When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI These service calls can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 96 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task VP_INT data if rcv dtq ID dtq amp data E RLWAI error forced wakeup Nn if prcv dtq ID dtq amp data E TMOUT error Timeout n lt lt Example statement in assembly language gt gt include mr8c inc GLB task task
153. re 3 2 R20UT0657EJ0101 Rev 1 01 Page 7 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel Key input Task Remote control Task LED illumination Task real time OS Volume control Mechanical 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 operating a number of microcomputers In the real time OS the individual programs which correspond to a number of microcomputers used in a conventional sys tem are called tasks R20UT0657EJ0101 Rev 1 01 Page 8 of 178 Sep 16 2011 131 N SAS MR8C 4 3 Introduction to Kernel 3 1 2 Operating Principles of Kernel A kernel is the core program of real time OS The kernel is the software that makes a one microcomputer system look like operating a number of microcomputers You should be wondering how the kernel makes a one microcomputer system function like a number of microcomputers As shown in Figure 3 4 the kernel 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 ra Time Figure 3 4 Time division Tas
154. ress break 253 FIX INTERRUPT VECTOR Reserved 254 FIX INTERRUPT VECTOR Reset 255 FIX INTERRUPT VECTOR R20UT0657EJ0101 Rev 1 01 Page 154 of 178 Sep 16 2011 32 NESAS MR8C 4 8 1 3 Configuration File Example The following is the configuration file example 8 Using Configurator 1 KK IK Ck kk ok ok ok kok o oko oko oko oko oko ok A ok ok ok ok ok I ok kok kok kok kok kok kok kok kok ke ke ke k 2 3 COPYRIGHT C 2009 RENESAS TECHNOLOGY CORPORATION 4 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVE 5 MR8C A4 V 1 00 6 7 MR8C A System Configuration File S Oe eae EA ATELE E E A 10 system 11 stack_size 0x400 12 priority 16 13 system_IPL 7 14 tic_deno 1 15 tic nume 1 16 17 System Clock Definition 18 clock 19 mpu_clock 20MHz 20 timer RB 21 IPL 5 22 23 Task Definition 24 task 1 25 name TASK_ID1 26 initial_start ON 27 entry_address task1 28 stack_size 0x80 29 priority 95 30 exinf 0x1234 31 F 32 task 2 33 name TASK_ID2 34 initial_start OFF 35 entry address task2 36 stack size 0x80 37 priority 2 38 exinf 0x8000 39 40 task 3 41 name TASK ID3 42 initial start OFF 43 entry address task3 44 stack size 0x80 45 priority 3 46 exinf 0x1234 47 j 48 event flag default added 49 flag 1 50 name FLG ID1 DL initial pattern
155. ron h gt include lt kernel h gt include kernel id h void task if sig sem ID sem E QOVR error Overflow Nn lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 sig sem ID SEM2 R20UT0657EJ0101 Rev 1 01 Page 80 of 178 Sep 16 2011 131 N SAS MR8C 4 5 Service call reference wai sem Acguire semaphore resource pol sem Acguire semaphore resource polling C Language API ER ercd wai semi ID semid ER ercd pol sem ID semid e Parameters ID semid Semaphore ID number to be acquired e Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc wai sem SEMID pol sem SEMID Parameters SEMID Semaphore ID number to be acquired Register contents after service call is issued Register name Content after service call is issued RO Error code A0 Semaphore ID number to be acguired Error code E RLWAI Forced release from waiting E TMOUT Polling failure R20UT0657EJ0101 Rev 1 01 Page 81 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference Functional description This service call acguires one semaphore resource from the semaphore indicated by semid If the semaphore resource count is egual to or greater than 1 the semaphore resource count is decremented by 1 and the service call issuing task continues execution On the other h
156. s 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 Blectronics 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 have any other
157. s specified by pragma INTHANDLER R20UT0657EJ0101 Rev 1 01 Page 52 of 178 Sep 16 2011 13 NE SAS MR8C 4 4 Kernel 4 2 11 System Configuration Management Function This function inspects the version information of MR8C 4 References Version Information ref ver The ref ver service call permits the user to get the version information of MR8C 4 This version information can be obtained in the standardized format of uITRON specification R20UT0657EJ0101 Rev 1 01 Page 53 of 178 Sep 16 2011 132 N SAS 5 Service call reference 5 1 Task Management Function Specifications of the task management function of MR8C 4 are listed in Table 5 1 below The task description languages in item No 4 are those specified in the GUI configurator They are not output to a configuration file nor are the MR8C 4 kernel concerned with them The task stack permits a section name to be specified for each task individually Table 5 1 Specifications of the Task Management Function No Item Content 1 Task ID 1 255 2 Task priority 1 255 3 Maximum number of activation request count 15 TA HLNG Tasks written in high level language 4 Task attribute TA ASM Tasks written in as sem bly language TA ACT Startup attribute 5 Task stack Section specifiable Table 5 2 List of Task Management Function Service Call No Service Call Fu
158. se of the cyclic handler The time representing this startup phase must be defined in ms units 6 Start Address Definition format Symbol or Function Name Definition range None Default value None Define the start address of the cyclic handler Note that the function name defined here will have the declaration statement shown below output to the ker nel id h file pragma CYCHANDLER function name 7 Extended information Definition format Numeric value Definition range 0 to OXFFFF Default value 0 Define the extended information of the cyclic handler This information is passed as argument to the cyclic handler when it starts R20UT0657EJ0101 Rev 1 01 Page 151 of 178 Sep 16 2011 13 NE SAS MR8C 4 8 Using Configurator Alarm handler definition This definition is necessary to use Alarm handler function lt lt Format gt gt Alarm Handlar Definition alarm hand ID No name ID name entry address Start address exitf Extended information l The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each alarm handler ID number 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the alarm handl
159. service call Task activation and other processing operations can be initiated by such a service call See Figure 3 9 Key input Remete onto Task Service call Task switching Figure 3 9 Service call This service call is realized by a function call when the application program is written in C language as shown below sta tsk ID main 3 Furthermore if the application program is written in assembly language it is realized by an assembler macro call as shown below sta tsk ID_main 3 R20UT0657EJ0101 Rev 1 01 Page 12 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel 3 2 1 Service Call Processing When a service call is issued processing takes place in the following seguence 1 The current register contents are saved 2 The stack pointer is changed from the task type to the real time OS system type 3 Processing is performed in compliance with the request made by the service call 4 The task to be executed next is selected 5 The stack pointer is changed to the task type 6 The register contents are recovered to resume task execution The flowchart in Figure 3 10 shows the process between service call generation and task switching Key input Task Register Save Service call issuance SP z OS Processing Task Selection Task gt SP LED illumination Task Register Restore Figure 3 10 Service Call Processing Flowchart A diff
160. ssued from task context and cannot be issued from non task context Example program statement Example statement in C language include itron h include lt kernel h gt include kernel id h void task sta cyc ID cycl lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM A0 sta cyc ID CYC1 R20UT0657EJ0101 Rev 1 01 Page 101 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference stp cyc Stops cyclic handler operation C Language API ER ercd stp cyc ID cycid Parameters ID cycid ID number of the cyclic handler to be stopped Return Parameters ER ercd Terminated normally E OK Assembly language API include mr8c inc stp cyc CYCNO e Parameters CYCNO ID number of the cyclic handler to be stopped Register contents after service call is issued Register name Content after service call is issued RO Error code A0 ID number of the cyclic handler to be stopped Error code None Functional description This service call places the cyclic handler indicated by cycid into a non operational state This service call can only be issued from task context and cannot be issued from non task context Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task stp cyc ID cycl
161. st count is 15 If while the wakeup request count 15 a new wakeup request is generated exceeding this limit the error code E QOVR is returned to the task that issued the service call with the wakeup request count left intact If this service call is to be issued from task context use wup tsk if issued from non task context use iwup tsk R20UT0657EJ0101 Rev 1 01 Page 66 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if wup_tsk ID_main E_OK printf Can t wakeup main n lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM AO wup_tsk ID_TASK1 R20UT0657EJ0101 Rev 1 01 Page 67 of 178 Sep 16 2011 2tENESAS MR8C 4 5 Service call reference can wup Cancel wakeup reguest C Language API ER UINT wupcnt can wup ID tskid Parameters ID tskid ID number of the target task Return Parameters ER UINT wupcnt gt 0 Canceled wakeup reguest count wupcnt lt 0 Error code Assembly language API include mr8c inc can wup TSKID e Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code Canceled wakeup reguest count A0 ID number
162. state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 99999 R20UT0657EJ0101 Rev 1 01 Page 100 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference sta cyc Start cyclic handler operation C Language API ER ercd sta cyc ID cycid Parameters ID cycid ID number of the cyclic handler to be operated Return Parameters ER ercd Terminated normally E_OK Assembly language API include mr8c inc sta_cyc CYCNO e Parameters CYCNO ID number of the cyclic handler to be operated Register contents after service call is issued Register name Content after service call is issued RO Error code AO ID number of the cyclic handler to be operated Error code None Functional description This service call places the cyclic handler indicated by cycid into an operational state If the cyclic handler attribute of TA_PHS is not specified the cyclic handler is started every time the activate cycle elapses start with the time at which this service call was invoked If while TA_PHS is not specified this service call is issued to a cyclic handler already in an operational state it sets the time at which the cyclic handler is to start next If while TA_PHS is specified this service call is issued to a cyclic handler already in an operational state it does not set the startup time This service call can only be i
163. status invalid task indicated by tskid is an inactive state E OOVR Oueuing overflow Functional description This service call aborts execution of the task indicated by tskid and places it into SUSPENDED state Tasks are resumed from this SUSPENDED state by the rsm tsk service call If the task indicated by tskid is in DORMANT state it returns the error code E OBJ as a return value for the service call The maximum number of suspension requests by this service call that can be nested is 1 If this service call is issued to a task which is already in SUSPENDED state the error code E QOVR is returned This service call forbids specifying the issuing task itself for tskid This service call can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 72 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if sus tsk ID main E OK printf Can t suspend task main n lt lt Example statement in assembly language gt gt include mr8c inc GLB task task PUSHM AO sus_tsk ID TASK2 R20UT0657EJ0101 Rev 1 01 Page 73 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference rsm tsk Resume suspended task C Language API ER ercd rsm tsk
164. stem stae Interrupt Eventfl ag Management Data queue Management System configuration Management Scheduler R8C Microcomputer Figure 4 1 MR8C 4 Structure R20UT0657EJ0101 Rev 1 01 Sep 16 2011 132 N SAS User Module MR8C 4 kernel Hardware Page 36 of 178 MR8C 4 4 Kernel 4 2 Module Overview The MR8C 4 kernel modules are outlined below Scheduler Forms a task processing queue based on task priority and controls operation so that the high priority task at the beginning in that queue task with small priority value is executed Task Management Module Exercises the management of various task states such as the RUNNING READY WAIT and SUSPENDED state Task Dependent Synchronization Module Accomplishes inter task synchronization by changing the task status from a different task Interrupt Management Module Makes a return from the interrupt handler Time Management Module Sets up the system timer used by the MR8C 4 kernel and starts the user created alarm handler and cyclic han der 1 System Status Management Module Gets the system status of MR8C A System Configuration Management Module Reports the MR8C 4 kernel version number or other information Sync Communication Module This is the function for synchronization and communication among the tasks The following three functional modules are offered Eventflag Checks whether the flag controlled within the MR8C 4 is set up and t
165. system into a dispatching disabled state Enable dispatching ena dsp Frees the system from a dispatching disabled state Reference context sns ctx Gets the context status of the system Reference CPU state sns loc Gets the CPU lock status of the system Reference dispatch disabling state sns den Gets the dispatch disabling status of the system R20UT0657EJ0101 Rev 1 01 Sep 16 2011 132 N SAS 4 Kernel Page 51 of 178 MR8C 4 4 Kernel 4 2 10 Interrupt Management Function The interrupt management function provides a function to process reguested external interrupts in real time The interrupt management service calls provided by the MR8C 4 kernel include the following e Returns from interrupt handler ret int The ret int service call activates the scheduler to switch over tasks as necessary when returning from the interrupt handler When using the C language this function is automatically called at completion of the handler function In this case therefore there is no need to invoke this service call Figure 4 16 shows an interrupt processing flow Processing a series of operations from task selection to register restoration is called a scheduler TaskA NN Interrupt Save Registers Handler Processing iwup tsk pragma INTHANDLER Declare C language TaskB Task Selection Figure 4 16 Interrupt process flow n the case that the interruput handler i
166. t task of address stack size User stack size of task priority Initial priority of task context Registers used stack section Section name in which the stack is located initial start TA ACT attribute initial startup state exinf Extended information The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each task ID number 1 Task ID name Definition format Symbol Definition range None Default value None Define the ID name of a task Note that the function name defined here is output to the kernel id h file as shown below define Task ID Name task ID R20UT0657EJ0101 Rev 1 01 Page 144 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator 2 Start address of task 3 4 Definition format Symbol or function name Definition range None Default value None Define the entry address of a task When written in the C language add at the end or at the beginning of the function name you have defined The function name defined here causes the following declaration statement to be output in the kernel id h file pragma TASK Function Name User stack size of task Definition format Numeric value Definition range 8 or more Default value 256 Defi
167. terrupt in the task AAA 33 When permitting interrupt in the interrupt handler When accepting multiple interrupt cece eee 33 3 7 About the power control of R8C and the operation of the kernel AAA 34 EH SLACKS M ET ME 35 3 81 System Stack and User Stack eene enn entente enne testen nnn 35 LE Cape 36 a E Oe ege Ten le 36 42 Mod leOv rvl W EE 37 4 2 1 Task Management Function sse eee nn en PK K nnne nnne KK AK KK nennt nennen nnn 38 4 2 2 Task Dependent Synchronization Funcion enne 40 4 2 3 Synchronization and Communication Function Germatphborel lt lt lt 43 4 2 4 Synchronization and Communication Function E ventflag eese 45 4 2 5 Synchronization and Communication Function Data Queue lt lt 47 4 26 Time Management Funchton cece enne nnne nen KK KK KK RK AK tnter nnne 48 427 Cyclic Handler FUNTION uie eee e peer d reir ede p RR eere n 49 4 2 8 Alarm Handler Function ied etd ee te derit ien Dee acie edu an EE ee ER eta vn 50 4 2 9 System Status Management Funclon nennen nnne nnn nnne nnns 51 4 2 10 Interrupt Management Function tenete nennen nennen entretien nennen nne 52 4 2 11 System Configuration Management Function sssssssssesseseneeee ener 53 Service call reference EE 54 5 1 Task Management Function eene nnne nennen KK K tnnt PAKA entren nennt innen nnns 54 sta tsk Activate task wit
168. ters Figure 3 11 Processing Procedure for a Service Call a Handler that caused an interrupt during Task Execution The ret int service call is issued automatically when OS dependent handler is written in C language when pragma INTHANDLER speci fied R20UT0657EJ0101 Rev 1 01 Page 15 of 178 Sep 16 2011 132 NE SAS MR8C 4 3 Introduction to Kernel Service Calls from a Handler That Caused an Interrupt during Service Call Processing Scheduling task switching is initiated after the system returns to the interrupted service call processing See Figure 3 12 TaskA OS Interrupt handler NN Interrupt f Service call processing iset flg Restore Registers Task selection SP lt User Restore Registers ret int TaskB Figure 3 12 Processing Procedure for a Service Call from a Handler that caused an interrupt during Service Call Processing R20UT0657EJ0101 Rev 1 01 Page 16 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel Service Calls from a Handler That Caused an Interrupt during Handler Execution Let us think of a situation in which an interrupt occurs during handler execution this handler is hereinafter 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 service call task switching does not take pla
169. the TA WSGL attribute and there are already other tasks waiting for the eventflag the error code E ILUSE is returned If task awaking conditions have already been met when this service call is invoked the task returns immediately and re sponds to the call with E OK If task awaking conditions are not met and the invoked service call is wai flg the task is enqueued in an eventflag waiting queue in order of FIFO For the pol flg service call the task returns immediately and responds to the call with the error code E TMOUT The task placed into a wait state by execution of the wai flg service call is released from WAITING state in the following cases When task awaking conditions are met before the tmout time elapses The error code returned in this case is E OK When the task is forcibly released from WAITING state by the rel wai or irel wai service call issued from another task or a handler The error code returned in this case is E RLWAI The following shows how wfmode is specified and the meaning of each mode wfmdoe wait mode Meaning TWF ANDW Wait until all bits specified by waiptn are set wait for the bits AND ed TWF ORW Wait until one of the bits specified by waiptn is set wait for the bits OR ed These service calls can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 89 of 178 Sep 16 2011 131 N SAS MR8C 4 5 Service call referen
170. tially beginning with the smallest R20UT0657EJ0101 Rev 1 01 Page 146 of 178 Sep 16 2011 32 NESAS MR8C 4 8 Using Configurator lt lt Content gt gt Define the following for each eventflag ID number 1 ID Name Definition format Symbol Definition range None Default value None Define the name with which an eventflag is specified in a program 2 Initial value of the event flag Definition format Numeric value Definition range 0 to OXFFFF Default value 0 Specify the initial bit pattern of the event flag 3 Multi wait attribute Definition format Symbol Definition range TA WMUL or TA WSGL Default value TA WSGL Specify whether multiple tasks can be enqueued in the eventflag waiting queue If TA WMUL is selected the TA WMUDL attribute is added permitting multiple tasks to be enqueued If TA WSGL is selected the TA WSGL attribute is added prohibiting multiple tasks from being enqueued 4 Clear attribute Definition format Symbol Definition range YES or NO Default value NO Specify whether the TA CLR attribute should be added as an eventflag attribute If YES is selected the TA CLR attribute is added If NO is selected the TA CLR attribute is not added Semaphore definition This definition is necessary to use Semaphore function lt lt Format gt gt Semaphore Definition semaphore ID No
171. tion between tasks by placing a task in the WAIT SUSPENDED or WAIT SUSPENDED state or waking up a WAIT state task The MR8C 4 offers the following task incorporated synchronization service calls Put Task to sleep slp tsk Wakeup task wup tsk iwup tsk Wakeups a task that has been placed in a WAITING state by the slp tsk service call No task can be waked up unless they have been placed in a WAITING state by If a wakeup request is issued to a task that has been kept waiting for conditions other than the slp tsk service call or a task in other than DORMANT state by the wup tsk or iwup_tsk service call that wakeup request only will be accumulated Therefore if a wakeup request is issued to a task RUNNING state for example this wakeup request is temporar ily stored in memory Then when the task in RUNNING state is going to be placed into WAIT state by the slp tsk service call the accumulated wakeup request becomes effective so that the task continues executing again with out going to WAIT state See Figure 4 4 Cancel Task Wakeup Requests can wup Clears the stored wakeup request See Figure 4 5 wup tsk wup tsk wup tsk slp tsk slp tsk Task E n Wakeup request count 0 0 1 2 1 Figure 4 4 Wakeup Request Storage wup tsk wup tsk can wup slp tsk slp tsk Task p EEN STERN Wakeup request count 0 0 1 0 0 Figure 4 5 Wakeup Request Cancellation R20UT0657EJ0101 Rev 1 01 Page 40 of 178 Sep 16 2011 134 N
172. tten in assembly language Context size of registers written as task context in cfgfile 4 PC F LG bvtes Figure 11 5 Stack size to be used by Kernel Interrupt Handler R20UT0657EJ0101 Rev 1 01 Page 172 of 178 Sep 16 2011 132 NE SAS MR8C 4 11 Stack Size Calculation Method System stack size y used by system dock interrupt handler When you do not use a system timer there is no need to add a system stack used by the system clock interrupt handler The system stack size y used by the system clock interrupt handler is whichever larger of the two cases below 24 4 maximum size used by cyclic handler 24 maximum size used by alarm handler C language Using the stack caliculation utility calculate the stack size of each Alarm or Cyclic handler Assembly language The stack size to be used by Alarm or Cyclic handler register to be used user size stack size to be used by service call If neither cyclic handler nor alarm handler is used then y 14bytes When using the interrupt handler and system clock interrupt handler in combination add the stack sizes used by both R20UT0657EJ0101 Rev 1 01 Page 173 of 178 Sep 16 2011 132 N SAS MR8C 4 11 Stack Size Calculation Method 11 2Necessary Stack Size Table 11 1 Stack Sizes Used by Service Calls Issued from Tasks in bytes lists the stack sizes system stack used by service calls that can be issued from tasks Table 11 1 Stack Sizes Used
173. ue for the service call This service call can only be used in task context and cannot be used in non task context R20UT0657EJ0101 Rev 1 01 Page 59 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task ter tsk ID main lt lt Example statement in assembly language gt gt INCLUDE mr8c inc GLB task task PUSHM A0 ter_tsk ID_TASK3 R20UT0657EJ0101 Rev 1 01 Page 60 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference chg pri Change task priority C Language API ER ercd chg pri ID tskid PRI tskpri Parameters ID tskid ID number of the target task PRI tskpri Priority of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr8c inc chg pri TSKID TSKPRI e Parameters TSKID ID number of the target task TSKPRI Priority of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code R3 Priority of the target task A0 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is an inactive state R20UT0657EJ0101 Rev 1 01 Page 61 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference
174. ued Register name Content after service call is issued RO Error code A0 Pointer to the packet to which version information is returned Error code None R20UT0657EJ0101 Rev 1 01 Page 121 of 178 Sep 16 2011 RENESAS MR8C 4 5 Service call reference Functional description This service call reads out information about the version of the currently executing kernel and returns the result to the area pointed to by pk rver The following information is returned to the packet pointed to by pk rver maker The code H 115 denoting Renesas Electrinics Corporation is returned prid The internal identification code IDH 0016 of the MR8C 4 is returned spver The code H 5402 denoting that the kernel is compliant with uITRON Specification Ver 4 02 00 is returned prver The code H 0100 denoting the version of the MR8C 4 is returned prno prno 0 Reserved for future extension prno 1 Reserved for future extension prno 2 Reserved for future extension prno 3 Reserved for future extension This service call can only be issued from task context and cannot be issued from non task context Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T_RVER pk_rver ref_ver amp pk_rver lt lt Example statement in assembly language gt gt include mr8c inc GLB task _ r
175. umbers beginning with the smallest lt lt Content gt gt For each data gueue ID number define the items described below R20UT0657EJ0101 Rev 1 01 Page 148 of 178 Sep 16 2011 ENESAS MR8C 4 8 Using Configurator 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the data gueue is specified in a program 2 Number of data Definition format Numeric Value Definition range 0 to Ox3FFF Default value 0 Specify the number of data that can be transmitted What should be specified here is the number of data and not a data size R20UT0657EJ0101 Rev 1 01 Page 149 of 178 Sep 16 2011 ENESAS MR8C 4 8 Using Configurator Cyclic handler definition This definition is necessary to use Cyclic handler function lt lt Format gt gt Cyclic Handlar Definition cyclic hand ID No name ID name interval counter Activation cycle start TA STA attribute phsatr TA PHS attribute phs_counter Activation phase entry_address Start address exitf Extended information l The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each cyclic handler ID number
176. upt in the task and the interrupt handler When prohibiting interrupt in the task 1 Interrupt control register SFR of the interrupt to be prohibited is changed 2 loc cpu unl cpu is used The interrupt that can be controlled is only kernel OS dependent interrupt according to the loc cpu ser vice call Please go by the method by 1 or 3 when you control the non kernel OS independent interrupt 3 flag is operated The service call call cannot be called from clearing flag to the set of flag when this method is used When permitting interrupt in the interrupt handler When accepting multiple interrupt 1 E switch is added to the interrupt handler definition Multiple interrupt can be permitted by setting pragma switch E in the interrupt handler definition 2 flag is operated There is no limitation in the operation of flag in the interrupt handler 3 Interrupt control register SFR of the interrupt to be prohibited is changed R20UT0657EJ0101 Rev 1 01 Page 33 of 178 Sep 16 2011 132 N SAS MR8C 4 3 Introduction to Kernel 3 7 About the power control of R8C and the operation of the kernel The kernel doesn t take part in the function of the power control supported by R8C Therefore it is necessary to process the transition processing of the operational mode by the user program Please process it according to the document of the mi crocomputer when the operational mode changes in the user program More
177. ventflag meets wait conditions by specifying TA CLR for the eventflag attribute Figure 4 11 shows an example of task execution control by the eventflag using the wai flg and set flg service calls The eventflag has a feature that it can wake up multiple tasks collectively at a time In Figure 4 11 there are six tasks linked one to another task A to task F When the flag pattern is set to OxF by the set flg service call the tasks that meet the wait conditions are removed sequentially from the top of the queue In this diagram the tasks that meet the wait conditions are task A task C and task E Out of these tasks task A task C and task E are removed from the queue If this event flag has a TA CLR attribute when the waiting of Task A is canceled the bit pattern of the event flag will be set to 0 and Task C and Task E will not be removed from queue Flag queue TaskA TaskB TaskC TaskD TaskE TaskF Flag pattern Wait pattern OxOF OxFF OxOF OxFF OxFF 0x10 Wait mode OR AND AND AND OR OR set flg TaskB TaskD TaskF Flag pattern 0x0F Figure 4 11 Task Execution Control by the Eventflag R20UT0657EJ0101 Rev 1 01 Page 45 of 178 Sep 16 2011 134 N SAS MR8C 4 4 Kernel There are following eventflag service calls that are provided by the MR8C 4 kernel Set Eventflag set flg sei flg Sets the eventflag so that a task waiting the eventflag is released from the WAITING state Clear Eventflag cl flg Clears the Eve
178. vice call is sued from another task or a handler R20UT0657EJ0101 Rev 1 01 Page 92 of 178 Sep 16 2011 132 NE SAS MR8C 4 5 Service call reference The error code returned in this case is E RLWAI These service calls can only be issued from task context and cannot be issued from non task context R20UT0657EJ0101 Rev 1 01 Page 93 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h VP INT data 10 void task void if snd drot ID dro data 0 E RLWAI error Forced released n if Gand dtq ID dro data 1 E TMOUT error Timeout n lt lt Example statement in assembly language gt gt include mr8c inc GLB task g dtq LWORD 12345678H task PUSHM R1 R3 A0 psnd dtq ID DTOQ2 40FFFFH PUSHM R1 R3 A0 snd dtq ID DTQ3 f4 0ABCDH R20UT0657EJ0101 Rev 1 01 Page 94 of 178 Sep 16 2011 132 N SAS MR8C 4 5 Service call reference rev dtg Receive from data gueue prev dtg Receive from data gueue polling C Language API ER ercd rcv dtq ID dtqid VP INT p data ER ercd prcv dtq ID dtqid VP INT p data e Parameters ID dtqid ID number of the data queue from which to receive VP INT p data Pointer to the start of the area in which received data is stored
179. when using the eventflag wait service call with the timeout function No flag wait pattern area is allocated when the eventflag is not used Flag wait mode This is a wait mode during eventflag wait Delay time counter Delay time counter when dly_tsk is called Extended task information Extended task information that was set during task generation is stored in this area 14 Called the task context R20UT0657EJ0101 Rev 1 01 Page 25 of 178 Sep 16 2011 132 N SAS MR8C 4 The task control block is schematized in Figure 3 19 TCB Task Connection pointer Status Priority SP Wake up counter Flag wait mode Time out counter Flag wait pattern Figure 3 19 Task control block R20UT0657EJ0101 Rev 1 01 Sep 16 2011 TCB TCB 2tENESAS 3 Introduction to Kernel Page 26 of 178 MR8C 4 3 Introduction to Kernel 3 5 System States 3 5 1 Task Context and Non task Context The system runs in either context state task context or non task context The differences between the task content and non task context are shown in Table 3 1 Task Context and Non task Context Table 3 1 Task Context and Non task Context Task context Non task context Invocable service call Those that can be invoked from Those that can be invoked from task context non task context Task scheduling Occurs when the queue state has It does not occur changed to other than dispatch d
180. z 21 timer RA 22 IPL 4 23 24 Task Definition 25 77 26 task 2 entry address main 28 name ID main 29 stack size 100 30 priority 1 31 initial start ON 32 exinf 0 33 34 task 39 entry address task1 36 name ID taskl 37 stack size 100 38 priority 2 39 exinf 0 40 4l 42 task 43 entry address task2 44 name ID task2 45 stack size 100 46 priority 3 47 exinf 0 48 49 50 51 semaphore 52 name ID_seml 53 max_count 1 54 initial_count 1 55 wait_queue TA_TFIFO 56 57 cyclic_hand 1 58 name ID_cyhl 59 interval_counter 100 60 start OFF 61 phsatr OFF 62 phs_counter 0 63 entry_address cyhl 64 exinf 1 65 R20UT0657EJ0101 Rev 1 01 Page 165 of 178 Sep 16 2011 RENESAS 11 Stack Size Calculation Method 11 1Stack Size Calculation Method The MR8C 4 provides two kinds of stacks the system stack and the user stack The stack size calculation method differ between the stacks User stack This stack is provided for each task Therefore writing an application by using the MR8C 4 requires to allocate the stack area for each stack e System stack This stack is used inside the MR8C 4 or during the execution of the handler When a task issues a service call the MR8C 4 switches the user stack to the system stack See Figure 11 1 System Stack and User Stack The system stack
Download Pdf Manuals
Related Search
Related Contents
Estufa de Exterior Philips HR1853 Home Decorators Collection 1590000410 Instructions / Assembly Castle GA131 Pro-DX Vocis Sound Level Meter Capítulo 1 User Manual DMS Buick Rendezvous 2005 User's Manual T。SHーBA 東芝 トランジスタメガホン取扱説明書 Copyright © All rights reserved.
Failed to retrieve file