Home
RI78V4 Real-Time Operating System User`s Manual: Coding
Contents
1. Service Call For Service Call poe eri by For System Stack Internal Arguments Service Call Processing Task Management Functions act_tsk iact_tsk 0 10 6 can_act 0 10 6 sta_tsk ista_tsk 0 10 6 ext_tsk 0 10 12 ter_tsk 0 10 12 chg_pri ichg_pri 0 10 16 ref_tsk 0 10 6 Task Dependent Synchronization Functions slp_tsk 0 10 12 tslp_tsk 0 10 14 wup_tsk iwup_tsk 0 10 6 can_wup ican_wup 0 10 6 rel_wai irel_wai 0 10 8 sus_tsk isus_tsk 0 10 12 rsm_tsk irsm_tsk 0 10 6 frsm_tsk ifrsm_tsk 0 10 6 dly_tsk 0 10 14 Synchronization and Communication Functions Semaphores sig_sem isig_sem 0 10 6 wai_sem 0 10 12 pol_sem 0 10 12 twai_sem 0 10 12 ref_sem 0 10 6 Synchronization and Communication Functions Eventflags set_flg iset_flg 0 10 6 clr_flg 0 10 6 wai_flg 8 10 16 pol_flg 0 10 16 twai_flg 4 10 16 ref_flg 0 10 6 Synchronization and Communication Functions Data queues snd_dtq 0 10 16 psnd_dtq ipsnd_dtq 0 10 16 tsnd_dtq 4 10 16 snd_mbx 0 10 6 fsnd_diq ifsnd_dtq 0 10 14 rcv_dtq 0 10 14 R20UT3375EJ0100 Rev 1 00 7tENESAS Page 145 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Service Call For Service Call poe Pega by For System Stack Internal Arguments Service Call Processi
2. 1 Invoking task RUNNING state tskpri Task A Task C READY state READY state maxtpri Task B READY state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 133 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER A priority is changed by issuing the following service call from the processing program chg_pri ichg_pri This service call changes the priority of the task specified by parameter tskid current priority to a value specified by parameter tskpri The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable PRI tskpri 9 Declares and initializes variable fE codec bho e chg_pri tskid tskpri Change task priority Note If the target task is in the RUNNING or READY state after this service call is issued this service call re queues the task at the end of the ready queue corresponding to the priority specified by parameter tskpri following priority change processing R20UT3375EJ0100 Rev 1 00 2tENESAS Page 134 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 5 Scheduling Disabling The RI78V4 provides a function to disable scheduler activation by referencing the system state from the processing program and explic
3. CRE MBX ID_mbxA TA_TFIFO TA_MFIFO 0 NULL CRE_MBX ID_mbxB A_TFIFO A_MPRI 0 MULL CRE_MPF ID_mpfA TA_TFIFO 10 8 kernel_work1 NULL CRE_MPF ID_mpfB TA_TFIFO 8 16 NULL CRE_CYC ID_cycA TA_HLNG TA_STA 0 func_cychdrA 1 0x50 CRE_CYC ID_cycB TA_ASM 0 func_cychdrB 2 0x100 DEF_INH INTPO A_HLNG TA_FAR inthdr0O DEF_INH INTP1 TA_HLNG TA_NEAR inthdrl R20UT3375EJ0100 Rev 1 00 tENESAS Page 278 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 14 CONFIGURATOR CF78V4 CHAPTER 14 CONFIGURATOR CF78V4 This chapter explains configurator CF78V4 which is provided by the RI78V4 as a utility tool useful for system construction 14 1 Outline To build systems load module that use functions provided by the RI78V4 the information storing data to be provided for the RI78V4 is required Since information files are basically enumerations of data it is possible to describe them with various editors Information files however do not excel in descriptiveness and readability therefore substantial time and effort are required when they are described To solve this problem the RI78V4 provides a utility tool configurator CF78V4 that converts a system configuration file which excels in descriptiveness and readability into information files The CF78V4 reads the system configuration file as a input file and then outputs information files T
4. Macro Value Description E OK 0 Normal completion Forced release from the WAITING state E_RLWAI 49 Accept rel_wai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 2tENESAS Page 207 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS psnd_dtq ipsnd_dtq Outline Send to data queue polling C format ER psnd_dtq ID dtqid VP_INT data ER ipsnd_dtq ID dtqid VP_INT data Assembly format OVW DE LOWW _datat 0x00002 OVW BC LOWW _data OV A dtqid CALL _psnd_dtq OVW DE LOWW _data 0x00002 OVW BC LOWW _data OV A dtqid CALL _ipsnd_dtq Parameter s 0 Parameter Description l ID dtqid ID number of the data queue to which the data element is sent l VP_INT data Data element to be sent to the data queue Explanation These service calls write data specified by parameter data to the data queue area of the data queue specified by parameter dtqid If there is no available space for writing data in the data queue area of the target data queue when either of these service calls is issued data is not written but E_TMOUT is returned If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from the reception wait queue and moves from
5. state Receiving WAITING State for a Data Queue Cancel Operation Return Value Data was written to the data queue area of the target data queue as a result of issuing E OK snd_dtq _ Data was written to the data queue area of the target data queue as a result of issuing E OK psnd_dtq E Data was written to the data queue area of the target data queue as a result of issuing E OK ipsnd_dtq z Data was written to the data queue area of the target data queue as a result of issuing E OK tsnd_dtq _ Data was written to the data queue area of the target data queue as a result of issuing E OK fsnd_dtq Data was written to the data queue area of the target data queue as a result of issuing E OK ifsnd_dtq Forced release from waiting accept rel_wai while waiting E_RLWAI Forced release from waiting accept irel_wai while waiting E_RLWAI The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void task VP_INT exinf ER ercd Declares variable ID dtqid 1 Declares and initializes variable VP_INT p data Declares variable PE a gae panaan ay ercd rcv_dtq dtqid amp p data Receive from data queue waiting forever if ercd E_OK LE EE ae s Normal termination processing else if ercd E_RLWAI TR ae we R A Fo
6. Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 182 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E OBJ Object state error specified task is neither in the SUSPENDED state nor WAITING SUSPENDED state R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 183 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Forcibly resume suspended task C format ER frsm_tsk ID tskid ER ifrsm_tsk ID tekid Assembly format MOV A tskid CALL L frsm_tsk MOV A tskid CALL _ifrsm_tsk Parameter s 0 Parameter Description l ID tskid ID number of the task to be resumed Explanation These service calls set the suspend request counter for the task specified by parameter tskid to 0x1 f and then forcibly cancel the SUSPENDED state of the target task As a result the target task is moved from the SUSPENDED state to the READY state or from the WAITING SUSPENDED state to the WAITING state Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 This service call does not perform queuing of forced cancellation requests If the target task is in a state other
7. Assembly format MOVW BC stacd_lo MOVW DE stacd_hi MOV A tskid CALL sta_tsk MOVW BC stacd_lo MOVW DE stacd_hi MOV A tskid CALL rt sta tsk Parameter s 0 Parameter Description l ID tskid ID number of the task to be activated l VP_INT stacd Start code of the task Explanation These service calls move a task specified by parameter tskid from the DORMANT state to the READY state As a result the target task is queued at the end on the ready queue corresponding to the initial priority and becomes subject to scheduling by the RI78V4 Note 1 This service call does not perform queuing of activation requests If the target task is in a state other than the DORMANT state the counter manipulation processing is therefore not performed but E_OBJ is returned Note 2 A start code staca is passed to the task activated by issuing this service call Return value Macro Value Description E_OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 165 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E OBJ Object state error specified task is not in the DORMANT state R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 166 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Terminate invoking task C format void ext_tsk void
8. Undo Cancels the previous edit operation of the value of the property While editing the value of the property cuts the selected characters and copies Cut f them to the clip board Copy Copies the selected characters of the property to the clip board Paste While editing the value of the property inserts the contents of the clip board Delete While editing the value of the property deletes the selected character string While editing the value of the property selects all the characters of the selected Select All property Restores the configuration of the selected item to the default configuration of the project Reserto Derault For the Individual Assemble Options tab restores to the configuration of the general option Restores all the configuration of the current tab to the default configuration of the project For the Individual Assemble Options tab restores to the configuration of the general option Reset All to Default R20UT3375EJ0100 Rev 1 00 2tENESAS Page 292 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE RI78V4 tab Outline This tab shows the detailed information on the RI78V4 to be used categorized by the following Version Information Display image Property 4 RI78V4 Property y e 4 4 Version Information 2 00 00 Install folder C Program Files 86 Renesas Hectronics CS CC RI78V4 Memory model Medium model Kernel version T
9. Assembly format BR ext_tsk Parameter s None Explanation This service call moves an invoking task from the RUNNING state to the DORMANT state As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject If an activation request has been queued to the invoking task the activation request counter is not set to 0x0 when this service call is issued this service call moves the task from the RUNNING state to the DORMANT state decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter and then moves the task from the DORMANT state to the READY state Note 1 This service call does not return the OS resource that the invoking task acquired by issuing a service call such as sig_sem or get_mpf The OS resource have been acquired must therefore be returned before issuing this service call Note 2 When moving a task from the RUNNING state to the DORMANT state this service call initializes the following information to values that are set during task creation Priority current priority Wakeup request count Suspension count Interrupt status Note 3 If the return instruction is written in a task it executes the same operation as this service call Note 4 In the RI78V4 code efficiency is enhanced by coding the return instruction as a Terminate invoking task Return value None R20UT3375EJ0100 Rev 1 00 2tENESAS Page 167 of
10. Note To call the service calls provided by the RI78V4 from a processing program the header files listed below must be coded include processing kernel inc Standard header file for assembly language kernel_id inc System information header file for assembly language R20UT3375EJ0100 Rev 1 00 2tENESAS Page 143 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 3 Amount of Stack Used by Service Calls The RI78V4 saves restores the values of registers PC PSW and HL to from the stack of the processing program that issued the relevant service call task stack or system stack during preprocessing postprocessing of the service call The stack of the processing program that issued a service call is used for storing the service call arguments and the system stack is used as the stack area required for executing internal processing of the service call When securing the task stack and system stack areas the stack amount consumed upon issuance of a service call must therefore be considered The following lists the stack sizes required upon issuance of a service call Synchronization and Communication Functions Data queues snd_dtq psnd_dtq ipsnd_dtq tsnd_dtq fsnd_dtq ifsnd_dtq rcv_dtq prcv_dtq prev_dtq trcv_dtq ref_dtq Table 12 1 Stack Amount Used by Service Call Unit Bytes R20UT3375EJ0100 Rev 1 00 2tENESAS Page 144 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS
11. mpfid amp blk Standard header file definition Acquire fixed sized memory block if ercd E_OK PM ap Ara E Kof Normal termination processing Release fixed sized memory block rel_mpf mpfid bik lse if ercd E_RLWAI Pe E E E EE Forced termination processing PE ists aie eres a aa wef Note 1 If the first task of the wait queue is moved to the READY state after this service call is issued this service call Note 2 also re queues the task at the end of the ready queue corresponding to the priority of the task The RI78V4 does not clear the memory blocks before returning them The contents of the returned memory blocks are therefore undefined R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 87 of 309 RI78V4 V2 00 00 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS 6 2 5 Reference fixed sized memory pool state A fixed sized memory pool status is referenced by issuing the following service call from the processing program ref_mp f Stores fixed sized memory pool state packet such as existence of waiting tasks of the fixed sized memory pool specified by parameter mpfid in the area specified by parameter pk_rmpf The following describes an example for coding this service call inc inc void lude lt kernel h gt lude lt kernel_id h gt func_task VP_INT exinf ID mpfid ID_mpfA T_RMPF pk_rmpf ID wtskid U
12. wtskid rsem_wtskid Stores information whether a task is queued to the wait queue TSK_NONE No applicable task Value ID number of the task at the head of the wait queue sement rsem_sement Stores the current resource count of the semaphore R20UT3375EJ0100 Rev 1 00 2tENESAS Page 153 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 3 Eventflag state packet The following shows eventflag state packet T_RFLG used when issuing ref_flg Definition of eventflag state packet T_RFLG is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rflg ID wtskid ID number of the task at the head of the wait queue FLGPTN flgptn Current bit pattern T_RFLG packet inc rflg_wtskid EQU 0x00 ID number of the task at the head of the wait queue rflg_flgptn EQU 0x02 Current bit pattern The following shows details on eventflag state packet T_RFLG wiskid rflg_wtskid Stores information whether a task is queued to the wait queue TSK_NONE No applicable task Value ID number of the task at the head of the wait queue flgptn rflg_flgptn Stores the current bit pattern of the eventflag R20UT3375EJ0100 Rev 1 00 2tENESAS Page 154 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 4 Data queue state packet T
13. Activation enabled by sta_cyc Activation enabled by sta_cyc Activation disabled by stp_cyc Creation TA_STA attribute R20UT3375EJ0100 Rev 1 00 2tENESAS Page 238 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 239 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Stop cyclic handler operation C format ER stp_cyc ID cycid Assembly format MOV A cycid CALL _stp_cyc Parameter s 0 Parameter Description ID cycid ID number of the cyclic handler operation to be stopped Explanation This service call moves the cyclic handler specified by parameter cycid from the operational state STA state to non operational state STP state As a result the target cyclic handler is excluded from activation targets of the RI78V4 until issuance of sta_cyc Note This service call does not perform queuing of stop requests If the target cyclic handler has been moved to the non operational state STP state therefore no processing is performed but it is not handled as an error Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 240 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Refere
14. R20UT3375EJ0100 Rev 1 00 2015 03 25 Invoking tasks are queued to the transmission wait queue of the target data queue in the order defined during configuration FIFO order 7tENESAS Page 66 of 309 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS Note 3 TMO_FEVR is specified for wait time tmout processing equivalent to snd_dtq will be executed When TMO_POL is specified processing equivalent to psnd_dtq ipsnd_dtgq will be executed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 67 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 4 3 Forced send to data queue Data is forcibly transmitted by issuing the following service call from the processing program fsnd_dtq ifsnd_dtq These service calls write data specified by parameter data to the data queue area of the data queue specified by parameter digid If there is no available space for writing data in the data queue area of the target data queue when either of these service calls is issued the service call overwrites data to the area with the oldest data that was written If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from the reception wait queue and moves from the WAITING state data reception wait state to the READY state or from the WA
15. Release semaphore resource y Delayed period return R20UT3375EJ0100 Rev 1 00 2tENESAS Page 138 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 7 Idle Routine The idle routine is a routine dedicated to idle processing that is extracted as a user own coding module to utilize the standby function provided by the CPU to achieve the low power consumption system and is called from the scheduler when there no longer remains a task subject to scheduling by the RI78V4 task in the RUNNING or READY state in the system 11 7 1 Define idle routine In the RI78V4 the method of registering an idle routine is limited to static registration by the Kernel Initialization Module Idle routines therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static define Static idle routine registration is realized by coding idle routines by using the prescribed function name idle_handler The RI78V4 executes idle routine registration processing based on relevant symbol information using the Kernel Initialization Module and handles the registered idle routines as management targets 11 7 2 Undefine idle routine In the RI78V4 idle routines registered statically by the Kernel Initialization Module cannot be unregistered dynamically using a method such as issuing a service call from a processing program 11 7 3 Basic form of idle routine Write idle routines usi
16. 81 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS 82 6 1 Outline 82 6 2 Fixed Sized Memory Pool 82 6 2 1 Create fixed sized memory pool 83 6 2 2 Delete fixed sized memory pool 83 6 2 3 Acquire fixed sized memory block 83 6 2 4 Release fixed sized memory block 87 6 2 5 Reference fixed sized memory pool state 88 CHAPTER 7 TIME MANAGEMENT FUNCTIONS 89 7 1 Outline 89 7 2 Timer Handler 89 7 2 1 Define timer handler 89 7 3 Delayed Wakeup 90 7 4 Timeout 90 7 5 Cyclic Handlers 91 7 5 1 Create cyclic handler 91 7 5 2 Delete cyclic handler 91 7 5 3 Basic form of cyclic handlers 91 7 5 4 Internal processing of cyclic handler 91 7 5 5 Start cyclic handler operation 93 7 5 6 Stop cyclic handler operation 95 7 5 7 Reference cyclic handler state 96 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 97 8 1 Outline 97 8 2 Rotate Task Precedence 97 8 3 Reference Task ID in the RUNNING State 99 8 4 Lock the CPU 100 8 5 Unlock the CPU 102 8 6 Disable Dispatching 103 8 7 Enable Dispatching 105 8 8 Reference Contexts 106 8 9 Reference CPU State 107 8 10 Reference Dispatching State 108 8 11 Reference Dispatch Pending State 109 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 110 9 1 Outline 110 9 2 Interrupt Entry Processing 110 9 2 1 Basic form of interrupt entry processing 111 9 2 2 Internal p
17. Macro Value Description E OK 0 Normal completion E_RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting E_ TMOUT 50 Polling failure or timeout R20UT3375EJ0100 Rev 1 00 tENESAS Page 226 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference mailbox state C format ER ref_mbx ID mbxid T_RMBX pk_rmbx Assembly format MOVW BC LOWW _pk_rmbx MOV A mbxid CALL _ref_mbx Parameter s 1 0 Parameter Description l ID mbxid ID number of the mailbox to be referenced O T_RMBX pk_rmbx Pointer to the packet returning the mailbox state Explanation Stores mailbox state packet such as existence of waiting tasks of the mailbox specified by parameter mbxid in the area specified by parameter pk_rmbx Note For details about the mailbox state packet refer to 12 5 6 Mailbox state packet Return value Macro Value Description E_OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 227 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 12 Memory Pool Management Functions The following lists the service calls provided by the RI78V4 as the memory pool management functions Table 12 14 Memory Pool Management Functions Service Call Function Origin of Service Call get_mpf Acquire fixed sized memory block waiting forever Task
18. lse if ercd FALSE PPP baie OA ee eee x CPU unlocked state JE eee eae a Note The system enters the CPU locked state when loc_cpu or iloc_cpu is issued and enters the CPU unlocked state when unl_cpu or iunl_cpu is issued R20UT3375EJ0100 Rev 1 00 2tENESAS Page 107 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 10 Reference Dispatching State The dispatching state is referenced by issuing the following service call from the processing program sns_dsp This service call acquires the system status type when this service call is issued dispatching disabled state or dispatching enabled state When this service call is terminated normally the acquired system state type TRUE dispatching disabled state FALSE dispatching enabled state is returned The following describes an example for coding this service call ercd sns_dsp include lt kernel h gt include lt kernel_id h gt void func sub void BOOL ercd Po ath EE TEET EE a if ercd TRUE PP te aren tet wee a lse if ercd FALSI JET brad Cee ion vA JE EERE ENE Ef Standard header file definition System information header file definition Declares variable Reference dispatching state Dispatching disabled state Dispatching enabled state Note The system enters the dispatching disabled state when dis_d
19. As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for a semaphore resource The waiting state for a semaphore state is cancelled in the following cases and then moved to the READY state Waiting State for a Semaphore State Cancel Operation Return Value The resource was returned to the target semaphore as a result of issuing sig_sem E OK The resource was returned to the target semaphore as a result of issuing isig_sem E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID semid ID_semA Declares and initializes variable a ne eee af ercd wai_sem semid Acquire semaphore resource waiting forever if ercd E_OK Ro Rk e eE ee aA Normal termination processing else if ercd E_RLWAI ER Ma rele areata ais 8 caf Forced termination processing PR ake Sacer a Ef R20UT3375EJ0100 Rev 1 00 tENESAS Page 50 of 309 2015 03 25 CHAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS
20. ID semid Assembly format MOV A semid CALL wai_sem Parameter s 0 Parameter Description ID semid ID number of the semaphore from which resource is acquired Explanation This service call acquires a resource from the semaphore specified by parameter semid subtracts 0x1 from the semaphore counter If a resource could not be acquired from the target semaphore semaphore counter is set to 0x0 when this service call is issued the counter manipulation processing is not performed but the invoking task is queued to the target semaphore wait queue in the order of resource acquisition request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for a semaphore state Waiting State for a Semaphore State Cancel Operation Return Value The resource was returned to the target semaphore as a result of issuing sig_sem E OK The resource was returned to the target semaphore as a result of issuing isig_sem E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Return value Macro Value Description E OK 0 Normal completion E_RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 2tENESAS Page 189 of 309 2015 03 25
21. PR wennen egs my Timeout processing fb heavens Gites ef R20UT3375EJ0100 Rev 1 00 2tENESAS Page 72 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS Note 1 Invoking tasks are queued to the reception wait queue of the target data queue in the order of the data reception request Note 2 If the data reception wait state is cancelled because rel_wai or irel_wai was issued or the wait time elapsed the contents in the area specified by parameter p_data become undefined Note 3 TMO_FEVR is specified for wait time tmout processing equivalent to rcv_dtq will be executed When TMO_POL is specified processing equivalent to prcv_diq will be executed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 73 of 309 2015 03 25 RI78V4 V2 00 00 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION FUNCTIONS 5 4 5 A data queue status is referenced by issuing the following service call from the processing program ref_dtq Reference data queue state These service calls store the detailed information of the data queue existence of waiting tasks number of data elements in the data queue etc specified by parameter dfgid into the area specified by parameter pk_rdtg The following describes an example for coding this service call include lt kernel h gt include lt kernel_id h gt void task VP_INT exinf ID dtqid 1 T_RDTQ pk_rdtq ID stskid ID rtskid UINT sdtqcnt ATR dtqatr
22. RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Acquire semaphore resource polling C format ER pol_sem ID semid Assembly format MOV A semid CALL _ pol_sem Parameter s 0 Parameter Description ID semid ID number of the semaphore from which resource is acquired Explanation This service call acquires a resource from the semaphore specified by parameter semid subtracts 0x1 from the semaphore counter If a resource could not be acquired from the target semaphore semaphore counter is set to 0x0 when this service call is issued the counter manipulation processing is not performed but E_TMOUT is returned Return value Macro Value Description E OK 0 Normal completion E TMOUT 50 Polling failure R20UT3375EJ0100 Rev 1 00 7tENESAS Page 190 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Acquire semaphore resource with timeout C format ER twai_sem ID semid TMO tmout Assembly format MOVW BC tmout_lo MOVW DE tmout_hi MOV A semid CALL _ twai_sem Parameter s 0 Parameter Description l ID semid ID number of the semaphore from which resource is acquired Specified timeout unit ticks I TMO tmout TMO_FEVR Waiting forever TMO_POL Polling Value Specified timeout Explanation This service call acquires a resource from the sema
23. UINT dtqcnt EPO Aid ices ref_dtq dtqid amp pk_rdtq stskid pk_rdtq stskid rtskid pk_rdtq rtskid sdtqcent pk_rdtq sdtqcent dtgatr pk_rdtq dtqatr dtqent pk_rdtq dtqcent E goiania Standard header file definition System information header file definition Declares and initializes variable Declares data structure Declares Declares Declares Declares Declares variable variable variable variable variable Reference data queue state Acquires existence of tasks waiting for data transmission Acquires existence of tasks waiting for data reception Reference the number of data elements in data queue Reference attribute Referene data count Note For details about the data queue state packet refer to 12 5 4 Data queue state packet R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 74 of 309 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 5 Mailboxes The RI78V4 provides a mailbox as a communication function between tasks that hands over the execution result of a given processing program to another processing program The following shows a processing flow when using a mailbox Figure 5 4 Processing Flow Mailbox Task Task Priority High Priority Low Receive from mailbox Reception wait period Send to mailbox 5 5 1 Create mailbox In the RI78V4 the m
24. Value Specified timeout R20UT3375EJ0100 Rev 1 00 7tENESAS Page 202 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Explanation This service call checks whether the bit pattern specified by parameter waiptn and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid If the bit pattern that satisfies the required condition has been set to the target eventtflag the bit pattern of the target eventtflag is stored in the area specified by parameter p_flgptn If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued the invoking task is queued to the target eventflag wait queue As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for an eventflag The waiting state for an eventflag is cancelled in the following cases and then moved to the READY state Waiting State for an Eventflag Cancel Operation Return Value A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing set_flg A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing iset_flg Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E R
25. _can_wup MOV A tskid CALL _ican_wup Parameter s 1 0 Parameter Description ID number of the task for cancelling wakeup requests f ID tskidj TSK_SELF Invoking task Value ID number of the task for cancelling wakeup requests Explanation These service calls cancel all of the wakeup requests queued to the task specified by parameter tskid the wakeup request counter is set to 0x0 When this service call is terminated normally the number of cancelled wakeup requests is returned Return value Macro Value Description E OBJ 41 Object state error specified task is in the DORMANT state Normal completion wakeup request count positive value or 0 R20UT3375EJ0100 Rev 1 00 7tENESAS Page 178 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS rel_ wai irel_ wai Outline Release task from waiting C format ER rel_wai ID tskid ER irel_wai ID tskid Assembly format MOV A tskid CALL rel_wai MOV A tskid CALL irel_wai Parameter s 0 Parameter Description l ID tskid ID number of the task to be released from waiting Explanation These service calls forcibly cancel the WAITING state of the task specified by parameter tskid As a result the target task unlinked from the wait queue and is moved from the WAITING state to the READY state or from the WAITING SUSPEND
26. than the SUSPENDED or WAITING SUSPENDED state E_OBu is therefore returned Return value Macro Value Description E OK 0 Normal completion E OBJ At Object state error specified task is neither in the SUSPENDED state nor WAITING SUSPENDED state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 184 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS dly_tsk Outline Delay task C format ER dly_tsk RELTIM dlytim Assembly format MOVW BC dlytim_hi MOVW AX dlytim_lo CALL _ dly_tsk Parameter s 0 Parameter Description l RELTIM dlytim Amount of relative time to delay the invoking task unit ticks Explanation This service call moves the invoking task from the RUNNING state to the WAITING state delayed state As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject The delayed state is cancelled in the following cases and then moved to the READY state Delayed State Cancel Operation Return Value Delay time specified by parameter dlytim has elapsed E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Return value Macro Value Description E OK 0 Normal completion E_RLWAI 49 Forced release from waiting accept rel_w
27. 133 Scheduling Disabling 135 11 5 1 Disable dispatching 136 11 5 2 Enable dispatching 137 Delay of Scheduling 138 Idle Routine 139 11 7 1 Define idle routine 139 11 7 2 Undefine idle routine 139 11 7 3 Basic form of idle routine 139 11 7 4 Internal processing of idle routine 140 CHAPTER 12 SERVICE CALLS 141 12 1 12 2 12 3 12 4 12 5 Outline 141 Call Service Call 142 12 2 1 C language 142 12 2 2 Assembly language 143 Amount of Stack Used by Service Calls 144 Data Macros 147 12 4 1 Datatypes 147 12 4 2 Current state 148 12 4 3 WAITING types 148 12 4 4 Return value 150 12 4 5 Conditional compile macro 150 12 4 6 Others 150 Packet Formats 151 12 5 1 Task state packet 151 12 5 2 Semaphore state packet 153 12 5 3 Eventflag state packet 154 12 5 4 Data queue state packet 155 12 5 5 Message packet 156 12 5 6 Mailbox state packet 157 12 5 7 Fixed sized memory pool state packet 158 12 5 8 Cyclic handler state packet 159 12 5 9 Version information packet 160 12 6 Task Management Functions 161 12 7 Task Dependent Synchronization Functions 172 12 8 Synchronization and Communication Functions Semaphores 186 12 9 Synchronization and Communication Functions Eventflags 194 12 10 Synchronization and Communication Functions Data queues 205 12 11 Synchronization and Com
28. Declares data structure a eee ee af Receive from mailbox polling ercd prcv_mbx mbxid amp ppk_msg if ercd E_OK PPS ine ae dian diets Ba Polling success processing else if ercd E_TMOUT PO aE inane KJ Polling failure processing E aauina epa a Note For details about the message packet refer to 12 5 5 Message packet R20UT3375EJ0100 Rev 1 00 2tENESAS Page 79 of 309 2015 03 25 RI78V4 V2 00 00 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION FUNCTIONS trcv_m bx This service call receives a message from the mailbox specified by parameter mbxid and stores its start address in the area specified by parameter ppk_msg If the message could not be received from the target mailbox no messages were queued in the wait queue when this service call is issued message reception processing is not executed but the invoking task is queued to the target mailbox wait queue in the order of message reception request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state receiving waiting for a mailbox The receiving waiting for a mailbox is cancelled in the following cases and then moved to the READY state Receiving Waiting for a Mailbox Cancel Operation Return Value A message was transmitted to the target mailbox as a result of issuing snd_mbx E OK Forced release fr
29. F Buil FE lon Fa Set FB Ste Fit Ste Fi Jump R20UT3375EJ0100 Rev 1 00 2tENESAS Page 285 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Explanation of each area 1 Menu bar Displays the menus relate to realtime OS Contents of each menu can be customized in the User Setting dialog box View The View menu shows the cascading menu to start the tools of realtime Realtime OS OS Opens the Realtime OS Resource Information panel pesource miormaton Note that this menu is disabled when the debug tool is not connected Opens the Task Analyzer window Task Analyzer Note that this menu is disabled when the debug tool is not connected 2 Toolbar Displays the buttons relate to realtime OS Buttons on the toolbar can be customized in the User Setting dialog box You can also create a new toolbar in the same dialog box Realtime OS toolbar Opens the Realtime OS Resource Information panel Note that this button is disabled when the debug tool is not connected Task Analyzer fd it Opens the Realtime OS Task Analyzer panel Note that this button is disabled when the debug tool is not connected 3 Panel display area The following panels are displayed in this area Project Tree panel Property panel Output panel See the each panel section for details of the contents of the display Note See CS Integrated Development Use
30. Non task iunl_cpu Unlock the CPU Task Non task dis_dsp Disable dispatching Task ena_dsp Enable dispatching Task sns_ctx Reference contexts Task Non task sns_loc Reference CPU state Task Non task sns_dsp Reference dispatching state Task Non task sns_dpn Reference dispatch pending state Task Non task R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 242 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Rotate task precedence C format ER rot_rdq PRI tskpri ER irot_rdq PRI tskpri Assembly format MOV A tskpri CALL Lt rot rdg MOV A tskpri CALL tt irot rdg Parameter s 1 0 Parameter Description Priority of the tasks whose precedence is rotated l PRI tskpri TPRI_SELF Current priority of the invoking task Value Priority of the tasks whose precedence is rotated Explanation This service call re queues the first task of the ready queue corresponding to the priority specified by parameter tskpri to the end of the queue to change the task execution order explicitly Note 1 This service call does not perform queuing of rotation requests If no task is queued to the ready queue corresponding to the relevant priority therefore no processing is performed but it is not handled as an error Note 2 Round robin scheduling can be implemented by issuing this service call via a cyclic handler in a constant cycle Note 3
31. and processing to switch to the stack for the switch destination processing program system stack or task stack when regaining control from the idle routine The user is therefore not required to code processing related to stack switching in idle routines Interrupt status Maskable interrupt acknowledgement is prohibited in the RI78V4 when control is passed to the idle routine The user is therefore not required to write the code related to maskable interrupt acknowledgment in idle routines Service call issuance The RI78V4 prohibits issuance of service calls in idle routines The following lists processing that should be executed in idle routines Effective use of standby function provided by the CPU R20UT3375EJ0100 Rev 1 00 2tENESAS Page 140 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS CHAPTER 12 SERVICE CALLS This chapter describes the service calls supported by the RI78V4 12 1 Outline The service calls provided by the RI78V4 are service routines provided for indirectly manipulating the resources tasks semaphores etc managed by the RI78V4 from a processing program The service calls provided by the RI78V4 are listed below by management module Task Management Functions act_tsk iact_tsk can_act sta_tsk ista_tsk ext_tsk ter_tsk chg_pri ichg_pri ref_tsk Task Dependent Synchronization Functions slp_tsk tslp_tsk wup_tsk iwup_tsk can_wup ican_wup rel_wai irel_wai sus_tsk i
32. ind kernel_id inc kernel_int_define c 9 Save the project Save the setting information of the project to the project file Note See CS Integrated Development Environment User s Manual Start for details about saving the project R20UT3375EJ0100 Rev 1 00 2tENESAS Page 24 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 2 7 Embedding System If the output of hex files are set in 4 of 2 6 Creating Load Module hex files are created After that embed the modules to the system by using a flash programmer R20UT3375EJ0100 Rev 1 00 2tENESAS Page 25 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS CHAPTER3 TASK MANAGEMENT FUNCTIONS This chapter describes the task management functions performed by the RI78V4 3 1 Outline The task control functions provided by the RI78V4 include a function to reference task statuses in addition to a function to manipulate task statuses 3 2 Tasks A task is processing program that is not executed unless it is explicitly manipulated via service calls provided by the RI78V4 unlike other processing programs cyclic handler and interrupt handler and is called from the scheduler Note The execution environment information required for a task s execution is called task context During task execution switching the task context of the task currently under execution by the RI78V4 is saved and the task context of the next
33. task contexts task The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_sub void BOOL ercd Declares variable JE aaea tee acter dons ad ercd snes ctz Reference contexts if ercd TRUE Ry eth adeeb Non task contexts lse if ercd FALSE JE eck ee Sica ie eee ef Task contexts JE aama he BAe R20UT3375EJ0100 Rev 1 00 tENESAS Page 106 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 9 Reference CPU State The CPU locked state is referenced by issuing the following service call from the processing program sns_loc This service call acquires the system status type when this service call is issued CPU locked state or CPU unlocked state When this service call is terminated normally the acquired system state type TRUE CPU locked state FALSE CPU unlocked state is returned The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_sub void BOOL ercd Declares variable E EET EEEE EE a ercd sns_loc Reference CPU state if ercd TRUE VE ee eee y CPU locked state
34. the allocation destinations section names of management objects modularized for each function are specified The following lists the section names prescribed in the RI78V4 kernel_system section Area where the RI78V4 s core processing part and main processing part of service calls provided by the RI78V4 are to be allocated kernel_system_timer_n section Area where the interrupt fo system timer and information of FAR branch are to be allocated kernel_info section Area where information items such as the RI78V4 version are to be allocated kernel_const kernel_const_f section Area where initial information items related to OS resources that do not change dynamically are allocated as system information tables and interrupt information definition file kernel_stack section Area where the system stack and the task stack are to be allocated kernel_data section Area where information items required to implement the functionalities provided by the RI78V4 and information items related to OS resources that change dynamically are allocated as management objects kernel_data_init section Area where initial information items of RI78V4 are to be allocated kernel_workO kernel_work1 kernel_work2 kernel_work3 section Area where data of data queue and fixed sized memory pools are to be allocated kernel_data_trace_n section Area where the trace data are to be allocated kernel_const_trace_f section Area w
35. 00 2tENESAS Page 15 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION Relocation si Section Name ROM RAM Attribute Description Area where information items to get trace data are to kernel_const_tra Code flash CONSTF be allocated ce_f area The start can be aligned at an even address that does not span a 64K 1 boundary Area where the processing part to get trace data are to kernel_system_t Code flash TEXTF be allocated race_f area The start can be aligned at an even address in the area from 0x000c0 to Oxeffff SADDR area where the RI78V4 s core processing are to be allocated kernelLsbss BAMarea SRS The start can be aligned at an even address in the saddr area Note 1 Specification of kernel_work0 kernel_work1 kernel_work2 and kernel_work3 is required only when the relevant section names are specified in Data queue information and Fixed sized memory pool information Note 2 The RI78V4 occupies the 8 byte area from the saddr area Oxffe20 to Oxfff1f Therefore the available saddr area for the user is up to 247 bytes Note 3 The section for RI78V4 is set automatically on CS When you want to change the start address of section changes in the linker setting For details about the directive file refer to CS Integrated Development Environment User s Manual RL78 Building Note 4 For details about the directive file refer to CS Integrated Development
36. 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Terminate task C format ER ter_tsk ID tskid Assembly format MOV A tskid CALL _ter_tsk Parameter s 0 Parameter Description ID tskid ID number of the task to be terminated Explanation This service call forcibly moves a task specified by parameter tskid to the DORMANT state As a result the target task is excluded from the RI78V4 scheduling subject If an activation request has been queued to the target task the activation request counter is not set to 0x0 when this service call is issued this service call moves the task to the DORMANT state decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter and then moves the task from the DORMANT state to the READY state Note 1 This service call does not return the OS resource that the target task acquired by issuing a service call such as sig_sem or get_mpf The OS resource have been acquired must therefore be returned before issuing this service call Note 2 When moving a task to the DORMANT state this service call initializes the following information to values that are set during task creation Priority current priority Wakeup request count Suspension count Interrupt status Return value Macro Value Description E OK 0 Normal completion E OBJ 41 Object state error specifi
37. 9 3 Settable Interrupt Level Enabling Multiple Interrupts from User Application Interrupt Handler Interrupt Servicing Interrupt level 0 Not available Available Interrupt level 1 Not available Available Interrupt level 2 Available Not available Interrupt level 3 Available Not available If a user application disables multiple interrupts then it is necessary to set the interrupt level of the interrupt handler process to one of the patterns shown below Pattern 1 Set the level of all interrupt handlers and interrupt processes to 2 Pattern 2 Set the level of all interrupt handlers and interrupt processes to 3 Pattern 3 Set the level of all interrupt handlers and to 2 and the level of all interrupt processes to either 2 or 3 Interrupts are disabled during an interrupt process with an interrupt level of 3 IE 0 Table 9 4 Settable Interrupt Level Disabling Multiple Interrupts from User Application Pattern 1 Pattern 2 Pattern 3 Interrupt Interrupt Interrupt Interrupt Interrupt Interrupt Handler Servicing Handler Servicing Handler Servicing Interrupt level 0 Not available Not available Not available Not available Not available Not available Interrupt level 1 Not available Not available Not available Not available Not available Not available Interrupt level 2 Available Available Not available Not available Available Available Interrupt
38. A wakeup request was issued as a result of issuing wup_tsk E OK A wakeup request was issued as a result of issuing iwup_tsk E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Polling failure or timeout E TMOUT Note When TMO_FEVR is specified for wait time tmout processing equivalent to slp_tsk will be executed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 174 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Return value Macro Value Description E OK 0 Normal completion E_RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting E TMOUT 50 Polling failure or timeout R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 175 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Wakeup task C format ER wup_tsk ID tskid ER iwup_tsk ID tskid Assembly format MOV A tskid CALL wup_tsk MOV A tskid CALL _ iwup_tsk Parameter s 1 0 Parameter Description ID number of the task to be woken up l ID tskid TSK_SELF Invoking task Value ID number of the task to be woken up Explanation These service calls cancel the WAITING state sleeping state of the task specified by parameter tskid As a result the target task is moved from the sleeping state to the READY state or
39. C format snd_mbx ID mbxid T_MSG pk_msg Assembly format SUBW SP 0x06 MOVW SP 0x02 AX MOVW AX BC MOVW SP 0x04 AX MOVW AX SP MOVW BC AX MOV A mbxid CALL II snd mbx Parameter s 1 0 Parameter Description ID mbxid ID number of the mailbox to which the message is sent l T_MSG pk_msg Start address of the message packet to be sent to the mailbox Explanation This service call transmits the message specified by parameter pk_msg to the mailbox specified by parameter mbxid queues the message in the wait queue If a task is queued to the target mailbox wait queue when this service call is issued the message is not queued but handed over to the relevant task first task of the wait queue As a result the relevant task is unlinked from the wait queue and is moved from the WAITING state receiving waiting for a mailbox to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Note 1 Note 2 Note 3 Note 4 If the first task of the wait queue is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Messages are queued to the target mailbox wait queue in the order defined by Attribute queuing method mbxatr during configuration FIFO order or priority order With the RI78V4 mailbox only the start address
40. Cancel Task Wakeup Requests A wakeup request is cancelled by issuing the following service call from the processing program can_wup ican_wup These service calls cancel all of the wakeup requests queued to the task specified by parameter tskid the wakeup request counter is set to 0x0 When this service call is terminated normally the number of cancelled wakeup requests is returned The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER_UINT ercd Declares variable ID tskid ID_tskA Declares and initializes variable E EEE EEE a ercd can_wup tskid Cancel task wakeup requests if ercd gt 0x0 a a ea ee Lvs Normal termination processing ae ee ee a aes R20UT3375EJ0100 Rev 1 00 tENESAS Page 42 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS 4 5 Release Task from Waiting The WAITING state is forcibly cancelled by issuing the following service call from the processing program rel_wai irel_wai These service calls forcibly cancel the WAITING state of the task specified by parameter tskid As a result the target task unlinked from the wait queue and is moved from the WAITING state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED sta
41. E_RLWAI PEP Bice ikon ate a they Forced termination processing LT a E E EE gA R20UT3375EJ0100 Rev 1 00 tENESAS Page 47 of 309 2015 03 25 CHAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS CHAPTER5 SYNCHRONIZATION AND COMMUNICA TION FUNCTIONS This chapter describes the synchronization and communication functions performed by the RI78V4 5 1 Outline The synchronization and communication functions of the RI78V4 consist of Semaphores Eventflags and Mailboxes that are provided as means for realizing exclusive control queuing and communication among tasks 5 2 Semaphores In the RI78V4 non negative number counting semaphores are provided as a means exclusive control function for preventing contention for limited resources hardware devices library function etc arising from the required conditions of simultaneously running tasks The following shows a processing flow when using a semaphore Figure 5 1 Processing Flow Semaphore Task Acquire semaphore resource Exclusive control period Release semaphore resource 5 2 1 Create semaphore In the RI78V4 the method of creating a semaphore is limited to static creation by the Kernel Initialization Module Semaphores therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static create Static semaphore creation is realized by defining Semaphore information in the
42. Module and handles the created tasks as management targets 3 2 4 Delete task In the RI78V4 tasks created statically by the Kernel Initialization Module cannot be deleted dynamically using a method such as issuing a service call from a processing program R20UT3375EJ0100 Rev 1 00 2tENESAS Page 29 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 2 5 Basic form of tasks When coding a task use a void function with one VP_INT argument any function name is fine The extended information specified with Task information or the start code specified when sta_tsk or ista_tsk is issued is set for the exinf argument The following shows the basic form of tasks C Language include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf LOR Sewer tsa sit datas ay Main processing ext_tsk Terminate invoking task Note The the pragma rtos_task directive is defined in the file kernel_id h CF78V4 outputs automatically Therefore please the file kernel_id h be sure to do include Assembly Language S INCLUDE kernel inc Standard header file definition S INCLUDE kernel_id inc System information header file definition PUBLIC _func task SECTION text TEXT _func_task PUSH BC Stores the higher 2 bytes of argum
43. No It does not register the file that is added to the project ni in the Generate a file property is selected Output folder Default BuildModeName How io Directly enter to the text box or edit by the Browse For Folder dialog box which appears when clicking the change button Restriction Up to 247 characters R20UT3375EJ0100 Rev 1 00 tENESAS Page 298 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Specify the system information table file name If the file name is changed the name of the file displayed on the project tree Use the extension asm If the extension is different or omitted asm is automatically added This property is not displayed when No It does not register the file that is File name added to the project ni in the Generate a file property is selected Default sit asm ROW to Directly enter to the text box change Restriction Up to 259 characters R20UT3375EJ0100 Rev 1 00 tENESAS Page 299 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE 2 System Information Header File for C Language The detailed information on the system information header file for C language are displayed and the configuration can be changed Select whether to generate a system information header file for C language and whether to update the file when the system configuration file is changed D
44. Origin of Service Call sta_cyc Start cyclic handler operation Task Non task stp_cyc Stop cyclic handler operation Task Non task ref_cyc Reference cyclic handler state Task Non task R20UT3375EJ0100 Rev 1 00 tENESAS Page 237 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Start cyclic handler operation C format ER sta_cyc ID cycid Assembly format MOV A cycid CALL II sta cyc Parameter s 1 0 Parameter Description l ID cycid ID number of the cyclic handler operation to be started Explanation This service call moves the cyclic handler specified by parameter cycid from the non operational state STP state to operational state STA state As a result the target cyclic handler is handled as an activation target of the RI78V4 Note This service call does not perform queuing of start requests If the target cyclic handler has been moved to the operational state STA state only activation cycle re set processing is executed The relative time interval from the output of this service call until the first activation request is output is always the activation phase activation cycle cyctim using the output of this service call as the reference point Cyclic handler activation image r Start r Start Start Start Start cyctim w cyctin w cyctim w cyctim w cyctim cyctim w cyctim cyctim A A A
45. R20UT3375EJ0100 Rev 1 00 7tENESAS Page 122 of 309 2015 03 25 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT RI78V4 V2 00 00 FUNCTIONS PUBLIC _boot EXTERN _ kernel_start _hdwinit __init_ri_stackarea SECTION stack_bss BSS Sets stack section _stackend DS 0x100 _stacktop _ boot VECTOR 0x0000 SECTION text TEXT _ pect SE RBO Sets register bank MOVW SP LOWW _stacktop Sets stack pointer SP CALL reset Clears initial information items of RI78V4 SIZI Jump to Kernel Initialization Module MOVW HL LOWW STARTOF kernel_data_init MOVW AX LOWW STARTOF kernel_data_init BR L2_ KERNEL DATA 1_KERNEL_DATA MOV HL 0 0 INCW HL 2_ KERNEL DATA CMPW AX HL BNZ L1_ KERNEL DATA CALL o init _ri_stackarea Clears RAM area BR kernel start CLRW AX exit BR Sexit EOF kernel_data_init R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 123 of 309 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT RI78V4 V2 00 00 FUNCTIONS 10 2 3 Internal processing of boot processing Boot processing is a routine dedicated to initialization processing called from Interrupt Entry Processing without using the RI78V4 Therefore note the following points when coding boot processing Coding method Code boot processing in assembly language Stack switching Settin
46. Sleeping State Cancel Operation Return Value A wakeup request was issued as a result of issuing wup_tsk E OK A wakeup request was issued as a result of issuing iwup_tsk E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI Polling failure or timeout E_TMOUT The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable TMO tmout 3600 Declares and initializes variable LE bea wae Pa ercd tslp_tsk tmout Put task to sleep with timeout if ercd E_OK TP pae 4 ae Ss Bee ef Normal termination processing else if ercd E_RLWAI Pe ais A E EE of Forced termination processing lse if ercd E_TMOUT PP Sie tetas tats hoe atte a Timeout processing PO Me Sil cae ateihos ad Note When TMO_FEVR is specified for wait time tmout processing equivalent to slp_tsk will be executed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 40 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS 4 3 Wakeup Task A task is woken up by issuing the following service call from the processing program wup_tsk iwup_tsk These service calls
47. The ready queue is a hash table that uses priority as the key and tasks that have entered an executable state READY state or RUNNING state are queued in FIFO order Therefore the scheduler realizes the RI78V4 s Scheduling System by executing task detection processing from the highest priority level of the ready queue upon activation and upon detection of queued tasks giving the CPU use right to the first task of the proper priority level R20UT3375EJ0100 Rev 1 00 2tENESAS Page 243 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 244 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS get_tid iget_tid Outline Reference task ID in the RUNNING state C format ER get_tid ID p_tskid ER iget_tid ID p_tskid Assembly format SUBW SP 0x06 MOVW SP 0x02 AX MOVW AX BC MOVW SP 0x04 AX MOVW AX SP CALL _get_tid SUBW SP 0x06 MOVW SP 0x02 AX MOVW AX BC MOVW SP 0x04 AX MOVW AX SP CALL _iget_tid Parameter s O Parameter Description O ID p_tskid ID number of the task in the RUNNING state Explanation These service calls store the ID of a task in the RUNNING state in the area specified by parameter p_tskid Note This service call stores TSK_NONE in the area speci
48. a high speed compact OS capable of being stored in and run from the ROM of a target system 1 1 1 Real time OS Control equipment demands systems that can rapidly respond to events occurring both internal and external to the equipment Conventional systems have utilized simple interrupt handling as a means of satisfying this demand As control equipment has become more powerful however it has proved difficult for systems to satisfy these requirements by means of simple interrupt handling alone In other words the task of managing the order in which internal and external events are processed has become increasingly difficult as systems have increased in complexity and programs have become larger Real time OS has been designed to overcome this problem The main purpose of a real time OS is to respond to internal and external events rapidly and execute programs in the optimum order 1 1 2 Multi task OS A task is the minimum unit in which a program can be executed by an OS Multi task is the name given to the mode of operation in which a single processor processes multiple tasks concurrently Actually the processor can handle no more than one program instruction at a time But by switching the processor s attention to individual tasks on a regular basis at a certain timing it appears that the tasks are being processed simultaneously A multi task OS enables the parallel processing of tasks by switching the tasks to be executed as de
49. a service call from a processing program R20UT3375EJ0100 Rev 1 00 2tENESAS Page 54 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 3 3 Set eventflag A bit pattern is set by issuing the following service call from the processing program set_flg iset_flg These service calls set the result of ORing the bit pattern of the eventflag specified by parameter flgid and the bit pattern specified by parameter sefptn as the bit pattern of the target eventtflag If the required condition of the task queued to the target eventflag wait queue is satisfied when this service call is issued the relevant task is unlinked from the wait queue at the same time as bit pattern setting processing As a result the relevant task is moved from the WAITING state waiting state for an eventflag to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID flgid ID_fl1gA Declares and initializes variable FLGPTN setptn 0B1010 Declares and initializes variable ee ee xy set_flg flgid setptn Set eventflag Note 1 If the task linked in the wait queue is moved to the READY state after this service call is issued this service
50. an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf Cee eee oy dis_dsp Disable dispatching JE hee die now eat ad Dispatching disabled state sna dsp J Enable dispatching JF arbos ii amas Ry Note 1 This service call does not perform queuing of disable requests If the system is in the dispatching disabled state therefore no processing is performed but it is not handled as an error R20UT3375EJ0100 Rev 1 00 stENESAS Page 103 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS Note 2 The dispatching disabled state changed by issuing this service call must be cancelled before the task that issued this service call moves to the DORMANT state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 104 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 7 Enable Dispatching The dispatching disabled state is cancelled by issuing the following service call from the processing program ena_dsp This service call changes the system status to the dispatching enabled state As a result dispatch processing task scheduling that has been disabled by issuing dis_dsp is enabled If a service call chg_pri sig_sem etc accompanying dispatch processing is issued during the interval from when dis
51. arash aren aie ads Note When TMO_FEVR is specified for wait time tmout processing equivalent to get_mpf will be executed When TMO_POL is specified processing equivalent to pget_mpf will be executed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 86 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS 6 2 4 Release fixed sized memory block A memory block is returned by issuing the following service call from the processing program rel_mpf This service call returns the memory block specified by parameter blk to the fixed sized memory pool specified by parameter mpfid If a task is queued to the target fixed sized memory pool wait queue when this service call is issued memory block return processing is not performed but memory blocks are returned to the relevant task first task of wait queue As a result the relevant task is unlinked from the wait queue and is moved from the WAITING state waiting state for a fixed sized memory block to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call void ER ID VP ercd get_mpf include include func_task lt kernel h gt lt kernel_id h gt System information header file definition VP_INT exinf ercd Declares variable mpfid ID_mpfA Declares and initializes variable blk Declares variable
52. as get_mpf and pget_mpf for messages Note The RI78V4 uses the message start area as a link area during queuing to the wait queue for mailbox messages Therefore if the memory area for messages is secured from other than the memory area controlled by the RI78V4 it must be secured from 4 byte aligned addresses Basic form of messages In the RI78V4 the message contents and length are prescribed as follows according to the attributes of the mailbox to be used When using a mailbox with the TA_MFIFO attribute The contents and length past the first 4 bytes of a message system reserved area msgque are not restricted in particular in the RI78V4 Therefore the contents and length past the first 4 bytes are prescribed among the processing programs that exchange data using the mailbox with the TA_MFIFO attribute The following shows the basic form of coding TA_MFIFO attribute messages in C Message packet for TA_MFIFO attribute typedef struct t_msg struct t_msg _ near msgque Reserved for future use T_MSG When using a mailbox with the TA_MPRI attribute The contents and length past the first 5 bytes of a message system reserved area msgque priority level msgpri are not restricted in particular in the RI78V4 Therefore the contents and length past the first 5 bytes are prescribed among the processing programs that exchange data using the mailbox with the TA_MPRI attribute The following shows the basic form of
53. cancel the WAITING state sleeping state of the task specified by parameter tskid As a result the target task is moved from the sleeping state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state If the target task is in a state other than the sleeping state when this service call is issued this service call does not move the state but increments the wakeup request counter by added 0x1 to the wakeup request counter The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable LP EEEE aba Ef wup_tsk tskid Wakeup task JE sp awwa wwe eae Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 The wakeup request counter managed by the RI78V4 is configured in 7 bit widths If the number of wakeup requests exceeds the maximum count value 127 as a result of issuing this service call the counter manipulation processing is therefore not performed but E_QOVR is returned R20UT3375EJ0100 Rev 1 00 2tENESAS Page 41 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS 4 4
54. communications equipment test and measurement equipment audio and visual equipment home electronic appliances machine tools personal electronic equipment and industrial robots High Quality Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems safety equipment and medical equipment not specifically designed for life support Specific Aircraft aerospace equipment submersible repeaters nuclear reactor control systems medical equipment or systems for life support e g artificial life support devices or systems surgical implantations or healthcare intervention e g excision etc and any other applications or purposes that pose a direct threat to human life You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics especially with respect to the maximum rating operating supply voltage range movement power voltage range heat radiation characteristics installation and other product characteristics Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges Although Renesas Electronics endeavors to improve the quality and reliability of its products semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use
55. definition void func_task VP_INT exinf ER ercd Declares variable ID mbxid ID_mbxA Declares and initializes variable T_MSG ppk_msg Declares data structure E ele wt ace Gh head Receive from mailbox waiting forever ercd rcv_mbx mbxid amp ppk_msg j if ercd E_OK IE eee en aerate f Normal termination processing else if ercd E_RLWAI JE gina eia Forced termination processing LO sash arash arar ai ads Note For details about the message packet refer to 12 5 5 Message packet R20UT3375EJ0100 Rev 1 00 2tENESAS Page 78 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS prcv_mbx This service call receives a message from the mailbox specified by parameter mbxid and stores its start address in the area specified by parameter ppk_msg If the message could not be received from the target mailbox no messages were queued in the wait queue when this service call is issued message reception processing is not executed but E_TMOUT is returned The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID mbxid ID_mbxA Declares and initializes variable T_MSG ppk_msg
56. error specified task is in the DORMANT state R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 170 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference task state C format ER ref_tsk ID tskid T_RTSK pk_rtsk Assembly format MOVW BC LOWW _pk_rtsk MOV A tskid CALL _ref_tsk Parameter s 1 0 Parameter Description ID number of the task to be referenced ID tskid TSK_SELF Invoking task Value ID number of the task to be referenced O T_RTSK pk_rtsk Pointer to the packet returning the task state Explanation Stores task state packet such as current status of the task specified by parameter tskid in the area specified by parameter pk_rtsk Note For details about the task state packet refer to 12 5 1 Task state packet Return value Macro Value Description E_OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 171 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 7 Task Dependent Synchronization Functions The following lists the service calls provided by the RI78V4 as the task dependent synchronization functions Table 12 9 Task Dependent Synchronization Functions Service Call Function Origin of Service Call slp_tsk Put task to sleep waiting forever Task tslp_tsk Put task to sleep with timeout
57. following format Consequently cyclic handler names can be used in the place of IDs by including the relevant system information header file using the processing program Output format to system information header file for C define cycid ID Output format to system information header file for assembly language cycid EQU ID 2 Attribute coding language initial activation status saving activation phase cycatr Specifies the attributes coding language initial activation status of the cyclic handler The keywords that can be specified for cycatr are TA_HLNG TA_ASM and TA_STA TA_PHS Coding language TA_HLNG Start a processing unit through a C language interface TA_ASM Start a processing unit through an assembly language interface Initial operation status TA_STA Cyclic handler is in an operational state after the creation Saving activation phase TA_PHS Saves activation phase Note If specification of TA_STA is omitted the cyclic handler initial activation status is set to non operational state STP state 3 System reserved area exinf System reserved area Values that can be specified for exinf are limited to 0 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 271 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 4 Start address cychdr Specifies the start address of the cyclic handler Values that can be specified for cychdr are symbol name
58. from the WAITING SUSPENDED state to the SUSPENDED state If the target task is in a state other than the sleeping state when this service call is issued this service call does not move the state but increments the wakeup request counter by added 0x1 to the wakeup request counter Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 The wakeup request counter managed by the RI78V4 is configured in 7 bit widths If the number of wakeup requests exceeds the maximum count value 127 as a result of issuing this service call the counter manipulation processing is therefore not performed but E_QOVR is returned R20UT3375EJ0100 Rev 1 00 7tENESAS Page 176 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Return value Macro Value Description E OK 0 Normal completion E OBJ 41 Object state error specified task is in the DORMANT state E _QOVR 43 Queue overflow overflow of wakeup request count 127 R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 177 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS can_wup ican_wup Outline Cancel task wakeup requests C format ER_UINT can_wup ID tskid ER_UINT ican_wup ID tskid Assembly format MOV A tskid CALL
59. func_task VP_INT exinf ee a eee bar dis_dsp Disable dispatching VA es a ee af Dispatching disabled state ena_dsp Enable dispatching E whet ee cles Note 1 This service call does not perform queuing of disable requests If the system is in the dispatching disabled state therefore no processing is performed but it is not handled as an error Note 2 The dispatching disabled state changed by issuing this service call must be cancelled before the task that issued this service call moves to the DORMANT state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 136 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 5 2 Enable dispatching The dispatching disabled state is cancelled by issuing the following service call from the processing program ena_dsp This service call changes the system status to the dispatching enabled state As a result dispatch processing task scheduling that has been disabled by issuing dis_dsp is enabled If a service call chg_pri sig_sem etc accompanying dispatch processing is issued during the interval from when dis_dsp is issued until this service call is issued the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until this service call is issued upon which the actual dispatch processing is performed in batch The following describes an example for coding this service c
60. is in a state other than the SUSPENDED or WAITING SUSPENDED state E_OBu is therefore returned R20UT3375EJ0100 Rev 1 00 2tENESAS Page 46 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS 4 8 Delay Task A task is moved to the delayed state by issuing the following service call from the processing program dly_tsk This service call moves the invoking task from the RUNNING state to the WAITING state delayed state As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject The delayed state is cancelled in the following cases and then moved to the READY state Delayed State Cancel Operation Return Value Delay time specified by parameter dlytim has elapsed E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable RELTIM dlytim 3600 Declares and initializes variable a ee eee ee at ercd dly_tsk dlytim Delay task if ercd E_OK OP BA shat EEE ates a Normal termination processing else if ercd
61. items constituting the task information are as follows 1 Task name tskid Specifies the task name An object name can be specified for tskid Note The CF78V4 outputs to the system information header file the correspondence between the task names and IDs in the following format Consequently task names can be used in the place of IDs by including the relevant system information header file using the processing program Output format to system information header file for C define tskid ID Output format to system information header file for assembly language tskid EQU ID 2 Attribute coding language initial activation status initial interrupt status tskatr Specifies the attributes coding language initial activation status initial interrupt status of the task The keywords that can be specified for tskatr are TA_HLNG TA_ASM TA_ACT TA_ENAINT and TA_DISINT Coding language TA_HLNG Start a processing unit through a C language interface TA_ASM Start a processing unit through an assembly language interface Initial activation status TA_ACT Task is activated after the creation R20UT3375EJ0100 Rev 1 00 ztENESAS Page 262 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE Initial interrupt status TA_ENAINT Enables acknowledgment of maskable interrupts TA_DISINT Disables acknowledgment of maskable interrupts Note 1 If specificati
62. level 3 Not available Not available Available Available Not available Available Interrupts are disabled during this interrupt process IE 0 R20UT3375EJ0100 Rev 1 00 2015 03 25 7tENESAS Page 120 of 309 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT RI78V4 V2 00 00 FUNCTIONS CHAPTER 10 SYSTEM CONFIGURATION MANAGE MENT FUNCTIONS This chapter describes the system configuration management functions performed by the RI78V4 10 1 Outline The system configuration management functions of the RI78V4 provides system initialization processing which is required from the reset interrupt output until control is passed to the task and version information referencing processing The following shows a processing flow from when a reset interrupt occurs until the control is passed to the task Reset interrupt N Interrupt Entry Processing l System initialization Figure 10 1 Processing Flow System Initialization Boot Processing p Kernel Initialization Module Initialization Routine a C iCdrt SCHEDULER ma Task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 121 of 309 2015 03 25 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT RI78V4 V2 00 00 FUNCTIONS 10 2 Boot Processing Boot processing is a routine dedicated to initialization processing that is extracted as a user own coding module to initialize the minimum req
63. needed description Property panel gt Task Analyzer tab gt Trace gt Selection of trace mode R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 125 of 309 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT RI78V4 V2 00 00 FUNCTIONS 10 3 Initialization Routine The initialization routine is a routine dedicated to initialization processing that is extracted as a user own coding module to initialize the hardware dependent on the user execution environment such as the peripheral controller and is called from the Kernel Initialization Module 10 3 1 Define initialization routine In the RI78V4 the method of registering an initialization routine is limited to static registration by the Kernel Initialization Module Initialization routines therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static define Static initialization routine registration is realized by coding initialization routines by using the prescribed function name init_handler The RI78V4 executes initialization routine registration processing based on relevant symbol information using the Kernel Initialization Module and handles the registered initialization routines as management targets 10 3 2 Undefine initialization routine In the RI78V4 initialization routines registered statically by the Kernel Initialization Module cannot be unregistered dynamically using a method such as issuing a s
64. of the message is handed over to the receiving processing program but the message contents are not copied to a separate area The message contents can therefore be rewritten even after this service call is issued For details about the message packet refer to 12 5 5 Message packet R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 220 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 221 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS rcv_mbx Outline Receive from mailbox waiting forever C format ER rcev_mbx ID mbxid T_MSG ppk_msg Assembly format MOVW BC LOWW _ppk_msq MOV A mbxid CALL _rev_mbx Parameter s 1 0 Parameter Description l ID mbxid ID number of the mailbox from which a message is received O T_MSG ppk_msg Start address of the message packet received from the mailbox Explanation This service call receives a message from the mailbox specified by parameter mbxid and stores its start address in the area specified by parameter ppk_msg If the message could not be received from the target mailbox no messages were queued in the wait queue when this service call is issued message reception processing is not executed but the invoking task is queued to the target mailbox wait que
65. on the using task analyzer in RI78V4 package Figure 2 4 Task Analyzer Tab A RI78V4 Property 4 Trace Selection of trace mode Not tracing Selection of trace mode Selects the buffer holding trace and information to acquire by trace Hardware trace mode Hold the trace to debugging tool with trace memory Software trace mode Hold the trace to target RAM Flac made ws eadeciad the monitor control taking trace is linked automatically Trace chart Take in the trace chart and the CPU usage rate The analyzable time is short Long statistics Take in the CPU usage rate Not take in the trace chart The analyzable time is long It can use only by software trace mode 7 Set build options Set the options for the compiler assembler linker and the like Note See CS Integrated Development Environment User s Manual RL78 Build for details about setting build options R20UT3375EJ0100 Rev 1 00 2tENESAS Page 23 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 8 Runa build Run a build to create a load module Note See CS Integrated Development Environment User s Manual RL78 Build for details about runnig a build Figure 2 5 Project Tree Panel After Running Build ate oe gt 8 J RSFLOOSL Microcontroller Ay CC RL Build Tool iM RIT8V4 Realtime OS og RL78 Simulator Debug Tool 6 0 File a g Build tool generated files A kernel id h
66. or trev_dtq TTW_MBX A task enters this state if cannot receive a message from the relevant mailbox upon the issuance of a rcv_mbx or trcv_mbx TTW_MPF A task enters this state if it cannot acquire a fixed sized memory block from the relevant fixed sized memory pool upon the issuance of a get_mpf or tget_mpf wobjid rtsk_wobjid Stores the object ID number for which the task is waiting lefttmo rtsk_lefttmo System reserved area actent rtsk_actcnt Stores the activation request count of the task wupcnt rtsk_wupcnt Stores the wakeup request count of the task suscnt rtsk_suscnt Stores the suspention count of the task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 152 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 2 Semaphore state packet The following shows semaphore state packet T_RSEM used when issuing ref_sem Definition of semaphore state packet T_RSEM is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rsem ID wtskid ID number of the task at the head of the wait queue UINT sement Current resource count T_RSEM packet inc rsem_wtskid EQU 0x00 ID number of the task at the head of the wait queue rsem_semcnt EQU 0x02 Current resource count The following shows details on semaphore state packet T_RSEM
67. order to quickly complete the processing in the cyclic handler during the interval until the processing in the cyclic handler ends the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until a return instruction is issued by the cyclic handler upon which the actual dispatch processing is performed in batch R20UT3375EJ0100 Rev 1 00 2tENESAS Page 92 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS 7 5 5 Start cyclic handler operation Moving to the operational state STA state is implemented by issuing the following service call from the processing program sta_cyc This service call moves the cyclic handler specified by parameter cycid from the non operational state STP state to operational state STA state As a result the target cyclic handler is handled as an activation target of the RI78V4 The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID cycid ID_cycA Declares and initializes variable PP Cet aks Ree SESE ff sta yG cycid Start cyclic handler operation JE bate had oes A Note The relative interval from when either of this service call is issued until the first activation request is issued varies depe
68. pget_mpf Acquire fixed sized memory block polling Task Non task tget_mpf Acquire fixed sized memory block with timeout Task rel_mpf Release fixed sized memory block Task Non task ref_mpf Reference fixed sized memory pool state Task Non task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 228 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Acquire fixed sized memory block waiting forever C format ER get_mpf ID mpfid VP p_blik Assembly format MOVW BC LOWW _p blk MOV A mpfid CALL _ get_mpf Parameter s 0 Parameter Description ID number of the fixed sized memory pool from which a memory block ID mpfid is acquired O VP p_ blk Start address of the acquired memory block Explanation This service call acquires the memory block from the fixed sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_bik If a memory block could not be acquired from the target fixed sized memory pool no available memory blocks exist when this service call is issued memory block acquisition processing is not performed but the invoking task is queued to the target fixed sized memory pool wait queue in the order of memory block acquisition request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for a fix
69. pol_sem This service call acquires a resource from the semaphore specified by parameter semid subtracts 0x1 from the semaphore counter If a resource could not be acquired from the target semaphore Semaphore counter is set to 0x0 when this service call is issued the counter manipulation processing is not performed but E_TMOUT is returned The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID semid ID_semA Declares and initializes variable JE thee E gA rcd pol_sem semid Acquire semaphore resource polling if ercd E_OK YP aoaaa aa KJ Polling success processing else if ercd E_TMOUT RT a E E EAA R Polling failure processing E a te iat oak RS a R20UT3375EJ0100 Rev 1 00 tENESAS Page 51 of 309 2015 03 25 CHAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS twai_sem This service call acquires a resource from the semaphore specified by parameter semid subtracts 0x1 from the semaphore counter If a resource could not be acquired from the target semaphore semaphore counter is set to 0x0 when this service call is issued the counter manipulation processing is not performed but the invoking task is queued to the target
70. queue a Initialization Tou ifsnd_dtq Forced send to data queue Som ier IAI eauon ToU rcv_dtq Receive from data queue waiting forever Task prev_dtq Receive from data queue polling og Nonitask Initialization rou prev_dtq Receive from data queue polling hig Nonztask Initialization rou trev_dtq Receive from data queue with timeout Task ref_dtq Reference data queue state i Ponriaer mitali ation Tou R20UT3375EJ0100 Rev 1 00 RENESAS 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Send to data queue waiting forever C format snd_dtq ID dtqid VP_INT data Assembly format MOVW DE LOWW _datat 0x00002 MOVW BC LOWW _data MOV A dtqid CALL _ snd_dtq Parameter s 1 0 Parameter Description ID dtqid ID number of the data queue to which the data element is sent l VP_INT data Data element to be sent to the data queue Explanation This service call writes data specified by parameter data to the data queue area of the data queue specified by parameter dtqid If there is no available space for writing data in the data queue area of the target data queue when this service call is issued this service call does not write data but queues the invoking task to the transmission wait queue of the target data queue and moves it from the RUNNING state to the WAITING state data transmission wait state The sending WAITING state for a data
71. regardless of whether the required condition is satisfied once the given length of time has elapsed A timeout is implemented by issuing the following service call from the processing program Table 7 2 Timeout Service Call Function tslp_tsk Put task to sleep twai_sem Acquire semaphore resource twai_flg Wait for eventflag tsnd_dtq Send to data queue trev_dtq Receive from data queue trcv_mbx Receive from mailbox tget_mpf Acquire fixed sized memory block R20UT3375EJ0100 Rev 1 00 2tENESAS Page 90 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS 7 5 Cyclic Handlers The cyclic handler is a routine dedicated to cycle processing that is activated periodically at a constant interval activation cycle and is called from the Timer Handler The RI78V4 handles the cyclic handler as a non task module independent from tasks Therefore even if a task with the highest priority in the system is being executed the processing is suspended when a specified activation cycle has come and the control is passed to the cyclic handler 7 5 1 Create cyclic handler In the RI78V4 the method of creating a cyclic handler is limited to static creation by the Kernel Initialization Module Cyclic handlers therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static create Static cyclic handler creation is realized by de
72. required condition of the target eventflag TA_CLR attribute is satisfied R20UT3375EJ0100 Rev 1 00 2tENESAS Page 59 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS twai_fig This service call checks whether the bit pattern specified by parameter waiptn and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid If the bit pattern that satisfies the required condition has been set to the target eventflag the bit pattern of the target eventtflag is stored in the area specified by parameter p_flgptn If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued the invoking task is queued to the target eventflag wait queue As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for an eventtflag The waiting state for an eventflag is cancelled in the following cases and then moved to the READY state Waiting State for an Eventflag Cancel Operation Return Value A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing set_flg A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing iset_flg Forced release from waiting accept rel_w
73. section The following shows an expression required for estimating the kernel_const_trace_f section size unit bytes When the trace mode is Not tracing const_trace_n 6 When the trace mode is Takes in trace chart by hardware trace mode const_trace_n 64 When the trace mode is Takes in trace chart by software trace mode const_trace_n 70 When the trace mode is Takes in long statistics by software trace mode const_trace_n 70 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 19 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 2 6 Creating Load Module Run a build on the CS for files created in sections from 2 2 Coding of Processing Program to 2 5 Start address of section and library files provided by the RI78V4 and C compiler package to create a load module The following lists the files required for creating load modules 1 Create or load a project Create a new project or load an existing one Note See RI Series Real Time Operating System User s Manual Start or CS Integrated Development Environment User s Manual Start for details about creating a new project or loading an existing one Set a build target project When making settings for or running a build set the active project If there is no subproject the project is always active Note See CS Integrated Development Environment User s Manual Build for details about setting the ac
74. service call from a processing program Static data queue creation means defining of data queues using static API CRE_DTQ in the system configuration file For details about the static API CRE_DTQ refer to 13 4 4 Data queue information R20UT3375EJ0100 Rev 1 00 2tENESAS Page 63 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 4 2 Send to data queue A data is transmitted by issuing the following service call from the processing program snd_diq This service call writes data specified by parameter data to the data queue area of the data queue specified by parameter digid If there is no available space for writing data in the data queue area of the target data queue when this service call is issued this service call does not write data but queues the invoking task to the transmission wait queue of the target data queue and moves it from the RUNNING state to the WAITING state data transmission wait state The sending WAITING state for a data queue is cancelled in the following cases and then moved to the READY state Sending WAITING State for a Data Queue Cancel Operation Return Value Available space was secured in the data queue area of the target data queue as a result of E OK issuing rcv_dtq Available space was secured in the data queue area of the target data queue as a result of E OK issuing prcv_dtq a Available space was secured in the data queue a
75. service call from the processing program ref_cyc Stores cyclic handler state packet such as current status of the cyclic handler specified by parameter cycid in the area specified by parameter pk_rcyc The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID cycid ID_cycA Declares and initializes variable T_RCYC pk_rcyc Declares data structure STAT cycstat Declares variable RELTIM lefttim Declares variable ne ee See ee ee ay ref_cyc cycid amp pk_rcyc Reference cyclic handler state cycstat pk_rcyc cycstat Reference cyclic handler operational state lefttim pk_rcyc lefttim Reference time left before the next activation Note For details about the cyclic handler state packet refer to 12 5 8 Cyclic handler state packet R20UT3375EJ0100 Rev 1 00 2tENESAS Page 96 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS CHAPTER 8 SYSTEM STATE MANAGEMENT FUNC TIONS This chapter describes the system state management functions performed by the RI78V4 8 1 Outline The system state control functions of the RI78V4 include in addition to functions to manipulate the state of the system such as transition to the CPU locked state and transition to the
76. target data queue in the order defined during configuration FIFO order R20UT3375EJ0100 Rev 1 00 2tENESAS Page 64 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS psnd_dtq ipsnd_dtq These service calls write data specified by parameter data to the data queue area of the data queue specified by parameter diqid If there is no available space for writing data in the data queue area of the target data queue when either of these service calls is issued data is not written but E_TMOUT is returned If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from the reception wait queue and moves from the WAITING state data reception wait state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void task VP_INT exinf ER ercd Declares variable ID dtqid 1 Declares and initializes variable VP_INT data 123 Declares and initializes variable E E ee ae Send to data queue polling ercd psnd_dtq dtqid data if ercd E_OK SE Bie cede deat ans Polli
77. the estimation of the system stack size refer to See 13 5 1 System stack size R20UT3375EJ0100 Rev 1 00 2tENESAS Page 259 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 3 2 Task priority information Define the following items as task priority information 1 Priority range maxtpri The number of task priority information items that can be specified is defined as being within the range of 0 to 1 The following shows the task priority information format MAX_PRI maxtpri The items constituting the task priority information are as follows 1 Priority range maxtpri Specifies the priority range of a task maximum value of Initial priority itskpri or maximum value of priority specified when issuing chg_pri A value between 1 and 15 can be specified for maxtpri Note If definition of this information is omitted the task priority range is set to 15 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 260 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 3 3 Clock timer interrupt source Define the following items as clock timer interrupt source information 1 Clock timer interrupt source tim_intno Only one information item can be defined as clock timer interrupt source information The following shows the clock timer interrupt source information format CLK_INTNO tim_intno The items constituting clock timer interrupt source inf
78. to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 If the bit pattern set to the target eventtflag is B 1100 and the bit pattern specified by parameter setptn is B 1010 when this service call is issued the bit pattern of the target eventflag is set to B 1110 Return value R20UT3375EJ0100 Rev 1 00 7tENESAS Page 195 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 196 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Clear eventflag C format ER clr_flg ID flgid FLGPTN clrptn Assembly format MOVW BC clrptn MOV A flgid CALL tI clr fig Parameter s 1 0 Parameter Description l ID flgid ID number of the eventflag to be cleared l FLGPTN clrptn Bit pattern to clear 16 bits Explanation This service call sets the result of ANDing the bit pattern set to the eventflag specified by parameter flgid and the bit pattern specified by parameter cirptn as the bit pattern of the target eventtlag Note 1 This service call does not perform queuing of clear requests If the bit pattern has been cleared therefore no processing is performed but it is not handled as an error Note 2 If the bit p
79. was issued as a result of issuing iwup_tsk E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Return value Macro Value Description E OK 0 Normal completion E_RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 tENESAS Page 173 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Put task to sleep with timeout C format ER tslp_tsk TMO tmout Assembly format MOVW BC tmout_hi MOVW AX tmout_lo CALL _ tslp_tsk Parameter s O Parameter Description Specified timeout unit ticks TMO tmout TMO_FEVR Waiting forever TMO_POL Polling Value Specified timeout Explanation This service call moves an invoking task from the RUNNING state to the WAITING state sleeping state As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject If a wakeup request has been queued to the target task the wakeup request counter is not set to 0x0 when this service call is issued this service call does not move the state but decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter The sleeping state is cancelled in the following cases and then moved to the READY state Sleeping State Cancel Operation Return Value
80. 0 2tENESAS Page 20 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION The following information files are appeared under the Realtime OS generated files node However these files are not generated at this point in time System information table file System information header file for C language System information header file for assembly language Interrupt Information definition file Figure 2 2 Project Tree Panel After Adding sys cfg Project Tree x gt D 8 Ay CC RL Build Tool A RIT8V4 Realtime OS se RL78 Simulator Debug Tool File am kernel_id h seen 8 kernel_id inc i a kernel_int_define c Note 2 When replacing the system configuration file first remove the added system configuration file from the project then add another one again Note 3 Although it is possible to add more than one system configuration files to a project only the first file added is enabled Note that if you remove the enabled file from the project the remaining additional files will not be enabled you must therefore add them again R20UT3375EJ0100 Rev 1 00 7tENESAS Page 21 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 4 Set the output of information files Select the system configuration file on the project tree to open the Property panel On the System Configuration File Related Information tab set the output of information files syste
81. 0 and the bit pattern specified by parameter clrptn is B 1010 when this service call is issued the bit pattern of the target eventflag is set to B 1110 Note 3 This service call does not cancel tasks in the waiting state for an eventtflag R20UT3375EJ0100 Rev 1 00 2tENESAS Page 56 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 3 5 Wait for eventflag A bit pattern is checked waiting forever polling or with timeout by issuing the following service call from the processing program wai_flg This service call checks whether the bit pattern specified by parameter waiptn and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid If a bit pattern that satisfies the required condition has been set for the target eventflag the bit pattern of the target eventtflag is stored in the area specified by parameter p_flgptn If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued the invoking task is queued to the target eventflag wait queue As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for an eventflag The waiting state for an eventflag is cancelled in the following cases and then moved to the READY state Waiting State for an Even
82. 0UT3375EJ0100 Rev 1 00 2tENESAS Page 280 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 14 CONFIGURATOR CF78V4 ndc Disables output of the system information header file for C language If omitted If omitted the CF78V4 interprets it that dcAkernel_id h is specified daA lt ASM header file gt Specifies the system information header file for assembly language name to be output If omitted If omitted the CF78V4 interprets it that daAkernel_id inc is specified Note Specify the output file name lt ASM header file gt within 255 characters including the path name nda Disables output of the system information header file for assembly language If omitted If omitted the CF78V4 interprets it that daAkernel_id inc inc is specified V Outputs version information for the CF78V4 to the standard output Note If this activation option is specified the CF78V4 handles other activation options as invalid options and suppresses outputting of information files help Outputs the usage of the activation options for the CF78V4 to the standard output Note If this activation option is specified the CF78V4 handles other activation options as invalid options and suppresses outputting of information files lt CF file gt Specifies the system configuration file name to be input Note 1 Specify the input file name lt CF file gt within 255 characters including the path name Note 2 This input file name can be omitted only wh
83. 100 Rev 1 00 2015 03 25 2tENESAS Page 150 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 Packet Formats This section explains the data structures task state packet semaphore state packet or the like used when issuing a service call provided by the RI78V4 12 5 1 Task state packet The following shows task state packet T_RTSK used when issuing ref_tsk Definition of task state packet T_RTSK is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rtsk STA tskstat Task current state PRI tskpri Task current priority PRI tskbpri Reserved for future use STA tskwait Reason for waiting ID wobjid Object ID number for which the task is waiting TMO lefttmo Reserved for future use UINT actcnt Activation request count UINT wupcent Wakeup request count UINT suscnt Suspension count T_RTSK packet inc rtsk_tskstat EQU 0x00 Task current state rtsk_tskpri EQU 0x02 Task current priority rtsk_tskbpri EQU 0x03 Reserved for future use rtsk_tskwait EQU 0x04 Reason for waiting rtsk_wobjid EQU 0x06 Object ID number for which the task is waiting rtsk_lefttmo EQU 0x08 Reserved for future use rtsk_actent EQU 0x0c Activation request count rtsk_wupcnt EQU Ox0e Wake
84. 33 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Release fixed sized memory block C format ER rel_mpf ID mpfid VP blk Assembly format MOVW BC LOWW _blk MOV A mpfid CALL _ rel_mpf Parameter s V O Parameter Description ID number of the fixed sized memory pool to which the memory block is l ID mpfid released VP blk Start address of the memory block to be released Explanation This service call returns the memory block specified by parameter bik to the fixed sized memory pool specified by parameter mpfid If a task is queued to the target fixed sized memory pool wait queue when this service call is issued memory block return processing is not performed but memory blocks are returned to the relevant task first task of wait queue As a result the relevant task is unlinked from the wait queue and is moved from the WAITING state waiting state for a fixed sized memory block to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Note 1 If the first task of the wait queue is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 The RI78V4 does not clear the memory blocks before returning them The contents of the returned memory blocks are therefore undefined R20UT3375EJ0100 Rev 1 00 7
85. 3375EJ0100 Rev 1 00 7tENESAS Page 14 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 2 5 Start address of section Specifies the start address of section by the user to fix the address allocation done by the linker In the RI78V4 the allocation destinations section names of management objects modularized for each function are specified The following lists the section names prescribed in the RI78V4 Table 2 1 RI78V4 Section Relocation ey Section Name ROM RAM Attribute Description Area where the RI78V4 s core processing part and Code flash main processing part of service calls provided by the kernel_system ared TEXTF RI78V4 are to be allocated The start can be aligned at an even address in the area from 0x000c0 to Oxeffff Area where the interrupt for system timer and kernel_system_t Code flash information of FAR branch are to be allocated TEXT imer_n area The start can be aligned at an even address in the area from 0x000c0 to OxOffff Area where information items such as the RI78V4 Code flash version are to be allocated ome Land area CONSIE The start can be aligned at an even address that does not span a 64K 1 boundary Area where initial information items related to OS resources that do not change dynamically are allocated kernel_const Code flash as system information tables and Interrupt infomation CONSTF a aerate kernel_const_f area definition file The s
86. 75EJ0100 Rev 1 00 2tENESAS Page 161 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Activate task queues an activation request C format ER act_tsk ID tskid ER iact tsk ID tskid j Assembly format MOV A tskid CALL act_tsk MOV A tskid CALL iact_tsk Parameter s 1 0 Parameter Description ID number of the task to be activated l ID tskid TSK_SELF Invoking task Value ID number of the task to be activated Explanation These service calls move a task specified by parameter tskid from the DORMANT state to the READY state As a result the target task is queued at the end on the ready queue corresponding to the initial priority and becomes subject to scheduling by the RI78V4 If the target task has been moved to a state other than the DORMANT state when this service call is issued this service call does not move the state but increments the activation request counter by added 0x1 to the wakeup request counter Note 1 The activation request counter managed by the RI78V4 is configured in 7 bit widths If the number of activation requests exceeds the maximum count value 127 as a result of issuing this service call the counter manipulation processing is therefore not performed but E_QOVR is returned Note 2 An extended infomration Extended information exinf is passed to the task activated by issuing this service call
87. C O D aes Cp lt 5 D CtENESAS RI78V4 V2 00 00 Real Time Operating System User s Manual Coding Target Device RL78 Family All information contained in these matenals including products and product specifications represents information on the product at the time of publication and is subject to change by Renesas Electronics Corp without notice Please review the latest information published by Renesas Electronics Corp through various means including the Renesas Electronics Corp website http www renesas com Renesas Electronics www renesas com Rev 1 00 Mar 2015 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
88. DOW REFERENCE Property panel Outline This panel is used to display the detailed information on the Realtime OS node system configuration file or the like that is selected on the Project Tree panel by every category and change the settings of the information This panel can be opened as follows On the Project Tree panel select the Realtime OS node system configuration file or the like and then select the View menu gt Property or the Property from the context menu Note When either one of the Realtime OS node system configuration file or the like on the Project Tree panel while the Property panel is opened the detailed information of the selected node is displayed Display image Property x 4 RI78V4 Property e le 4 Version Information V2 00 00 Install folder C Program Files x86 Renesas Hectronics CS CC RI78V4 Memory model Medium model Kernel version This is the version of the RI78V4 to be used in this project RI78V4 A Task Analyzer Explanation of each area 1 Selected node area Display the name of the selected node on the Project Tree panel When multiple nodes are selected this area is blank 2 Detailed information display change area In this area the detailed information on the Realtime OS node system configuration file or the like that is selected on the Project Tree panel is displayed by every category in the list And the settings of the information can be change
89. Data element to be sent to the data queue Explanation These service calls write data specified by parameter data to the data queue area of the data queue specified by parameter dtqid If there is no available space for writing data in the data queue area of the target data queue when either of these service calls is issued the service call overwrites data to the area with the oldest data that was written If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from the reception wait queue and moves from the WAITING state data reception wait state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 212 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Receive from data queue waiting forever C format ER rcev_dtq ID dtqid VP_INT p_data Assembly format MOVW BC LOWW _data MOV A dtqid CALL tl rev dtg Parameter s 1 0 Parameter Description l ID dtqid ID number of the data queue from which a data element is received O VP_INT p data Data element received from the data queue Explanation This service
90. ED state to the SUSPENDED state E_RLWA is returned from the service call that triggered the move to the WAITING state slp_tsk wai_sem or the like to the task whose WAITING state is cancelled by this service call Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 This service call does not perform queuing of forced cancellation requests If the target task is in a state other than the WAITING or WAITING SUSPENDED state E_OBu is returned Return value Macro Value Description E OK 0 Normal completion E OBJ 41 Object state error specified task is neither in the WAITING state nor WAITING E SUSPENDED state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 179 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Suspend task C format ER sus_tsk ID tskid ER isus_tsk ID tskid Assembly format MOV A tskid CALL H sus_tsk MOV A tskid CALL isus_tsk Parameter s 1 0 Parameter Description ID number of the task to be suspended l ID tskid TSK_SELF Invoking task Value ID number of the task to be suspended Explanation These service calls add 0x1 to the suspend request counter for the task specified by parameter tskid and then move the target task from
91. ESAS Page 149 of 309 2015 03 25 RI78V4 V2 00 00 12 4 4 Return value The following lists the values returned from service calls CHAPTER 12 SERVICE CALLS Macro definition of the return value is performed by standard header file lt ri_root gt include kernel h Table 12 5 Return Value Macro Value Description E OK 0 Normal completion E_ILUSE 28 Illegal service call use E OBJ 41 Object state error E_QOVR 43 Queue overflow E_RLWAI 49 aa from waiting accept rel_wai irel_wai while E_TMOUT 50 Polling failure or timeout FALSE 0 False TRUE 1 True 12 4 5 Conditional compile macro The RI78V4 header files are conditionally compiled by the following macro Table 12 6 Conditional Compile Macro Classification Macro Description C compiler package _ REL __ The CC RL is used 12 4 6 Others The following lists other macros used when issuing a service call Macro definition of other macros is performed by standard header file lt ri_root gt include kernel h Table 12 7 Others Macro Value Description TSK_SELF 0 Invoking task TPRI_INI 0 Initial priority of the task TMO_FEVR 1 Waiting forever TMO_POL 0 Polling TWF_ANDW 0x00 AND waiting condition TWF_ORW 0x01 OR waiting condition TPRI_SELF 0 Current priority of the invoking task TSK_NONE 0 No applicable task NULL 0 No applicable message R20UT3375EJ0
92. Environment User s Manual RL78 Coding 2 5 1 The size of the kernel_system section is approximately 1 KB to 9 KB depends on the service calls used in the processing program 2 5 2 kernel_system section kernel_system_timer_n section The following shows an expression required for estimating the kernel_system_timer_n section size unit bytes system_timer_n 16 inthnum_FAR 8 inthnum_FAR Total amount of Interrupt handler information with TA_FAR attribute 2 5 3 kernel_system_trace_f section The following shows an expression required for estimating the kernel_system_trace_f section size unit bytes When the trace mode is Not tracing system_trace_f 0 When the trace mode is Takes in trace chart by hardware trace mode system_trace_f 184 When the trace mode is Takes in trace chart by software trace mode system_trace_f 706 R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 16 of 309 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION When the trace mode is Takes in long statistics by software trace mode system_trace_f 590 2 5 4 kernel_info section The size of the kernel_info section is approximately 16 bytes 2 5 5 kernel_const section The following shows an expression required for estimating the kernel_const section size unit bytes const tsknum 10 semnum flgnum dtgnum 5 mpfnum 8 cyenum 12 k
93. INT fblkcnt J LEDERE ates z7 ref_mpf mpfid amp pk_rmpf Referenc wtskid pk_rmpf wtskid fblkcnt pk_rmpf fblkcnt Standard header file definition System information header file definition Declares Declares Declares Declares and initializes variable data structure variable variable Reference ID number of the task at the head of the wait Referenc fixed sized memory pool state queue number of free memory blocks Note For details about the fixed sized memory pool state packet refer to 12 5 7 Fixed sized memory pool state packet R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 88 of 309 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS CHAPTER 7 TIME MANAGEMENT FUNCTIONS This chapter describes the time management functions performed by the RI78V4 7 1 Outline The time management functions of the RI78V4 include Delayed Wakeup Timeout and Cyclic Handlers that use timer interrupts created as fixed intervals as means for realizing time dependent processing Note The RI78V4 does not execute initialization of hardware that creates timer interrupts clock controller etc This initialization processing must therefore be coded by the user in the Boot Processing or Initialization Routine 7 2 Timer Handler The timer handler is a dedicated time control processing routine that consists of the processing required to realize delayed wa
94. ITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void task VP_INT exinf ID dtqid 1 Declares and initializes variable VP_INT data 123 Declares and initializes variable E E EEE EA fsnd_dtq dtqid data Forced send to data queue JE ceckoa macdyacigs R20UT3375EJ0100 Rev 1 00 2tENESAS Page 68 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 4 4 Receive from data queue A data is received waiting forever polling or with timeout by issuing the following service call from the processing program rcv_dtq This service call reads data in the data queue area of the data queue specified by parameter diqid and stores it to the area specified by parameter p_data If no data could be read from the data queue area of the target data queue no data has been written to the data queue area when this service call is issued the service call does not read data but queues the invoking task to the reception wait queue of the target data queue and moves it from the RUNNING state to the WAITING state data reception wait state The receiving WAITING state for a data queue is cancelled in the following cases and then moved to the READY
95. Kernel Initialization Module cannot be deleted dynamically using a method such as issuing a service call from a processing program 6 2 3 Acquire fixed sized memory block A memory block is acquired waiting forever polling or with timeout by issuing the following service call from the processing program get_mpf This service call acquires the memory block from the fixed sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_bik If a memory block could not be acquired from the target fixed sized memory pool no available memory blocks exist when this service call is issued memory block acquisition processing is not performed but the invoking task is queued to the target fixed sized memory pool wait queue in the order of memory block acquisition request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for a fixed sized memory block The waiting state for a fixed sized memory block is cancelled in the following cases and then moved to the READY state Waiting State for a Fixed sized Memory Block Cancel Operation Return Value A memory block was returned to the target fixed sized memory pool as a result of issuing E OK rel_mpf Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E
96. LWAI Polling failure or timeout E TMOUT The following shows the specification format of required condition wfmode wimode TWF_ANDW Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag wfmode TWF_ORW Checks which bit among bits to which 1 is set by parameter waiptn is set as the target eventflag Note 1 In the RI78V4 the number of tasks that can be queued to the eventtflag wait queue is one If this service call is issued for the eventflag to which a task is queued therefore E_ILUSE is returned regardless of whether or not the required condition is immediately satisfied Note 2 The RI78V4 performs bit pattern clear processing 0x0 setting when the required condition of the target eventflag TA_CLR attribute is satisfied Note 3 When TMO_FEVR is specified for wait time tmout processing equivalent to wai_flg will be executed When TMO_POL is specified processing equivalent to pol_flg will be executed Return value Macro Value Description E OK 0 Normal completion E ILUSE 28 Illegal service Call use there is already a task waiting for an eventflag with the TA_WSGL attribute E_RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting E_ TMOUT 50 Polling failure or timeout R20UT3375EJ0100 Rev 1 00 2tENESAS Page 203 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Refe
97. R20UT3375EJ0100 2015 03 25 Rev 1 00 2tENESAS Page 162 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Return value Macro Value Description E OK 0 Normal completion E QOVR 43 Queue overflow overflow of activation request count 127 R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 163 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Cancel task activation requests C format ER_UINT can_act ID tskid Assembly format MOV A tskid CALL II can act Parameter s 1 0 Parameter Description ID number of the task for cancelling activation requests ID tskid TSK_SELF Invoking task Value ID number of the task for cancelling activation requests Explanation This service call cancels all of the activation requests queued to the task specified by parameter tskid sets the activation request counter to 0x0 When this service call is terminated normally the number of cancelled activation requests is returned Return value Macro Value Description Normal completion activation request count positive value or 0 R20UT3375EJ0100 Rev 1 00 7tENESAS Page 164 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Activate task does not queue an activation request C format ER sta_tsk ID tskid VP_INT stacd ER ista_tsk ID tskid VP_INT stacd
98. R20UT3375EJ0100 Rev 1 00 ztENESAS Page 124 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT FUNCTIONS 10 2 4 System dependence information System dependence information is the header file as the user own cording part which need for RI78V4 processing file name usrown h Basic form of system dependence information When describes system dependence information uses the prescribed file name usrown h the prescribed macro name KERNEL_USR_TMCNTREG KERNEL_USR_TMCMPREG The following shows the basic form of system dependent information using C language include define define lt kernel_id h gt System information header file definition KERNEL_USR_TMCNTREG 0x0180 I O address KERNEL_USR_TMCMPREG Oxff18 I O address The following shows the list of the information which should be defined as system dependence information Definition of system information header file The inclusion of system information header file output by CF78V4 Note Only the case selected Taking in long statistics by software trace mode is needed description Property panel gt Task Analyzer tab gt Trace gt Selection of trace mode Information of the clock timer Macro definition of the I O address of the clock timer and the I O address of the compare register Note Only the case selected Taking in long statistics by software trace mode is
99. RLWAI The following describes an example for coding this service call R20UT3375EJ0100 Rev 1 00 tENESAS Page 83 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void ER ID VP ercd get_mpf mpfid amp p_blk func_task VP_INT exinf ercd Declares variable mpfid ID_mpfA Declares and initializes variable p blk Declares variable if ercd E_OK BO E E ETE rel_mpf mpfid p blk else if ercd E E E E aene dkaram aa Acquire fixed sized memory block wait forever Normal termination processing Release fixed sized memory block RLWAI Forced termination processing R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 84 of 309 RI78V4 V2 00 00 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS pget_mpf This service call acquires the memory block from the fixed sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_bik If a memory block could not be acquired from the target fixed sized memory pool no available memory blocks exist when this service call is issued memory block acquisition processing is not performed but E_TMOUT is returned The following describes an example f
100. Ready Queue The RI78V4 uses a ready queue to implement task scheduling The ready queue is a hash table that uses priority as the key and tasks that have entered an executable state READY state or RUNNING state are queued in FIFO order Therefore the scheduler realizes the RI78V4 s scheduling method priority level or FCFS by executing task detection processing from the highest priority level of the ready queue upon activation and upon detection of queued tasks giving the CPU use right to the first task of the proper priority level The following shows the case where multiple tasks are queued to a ready queue Figure 11 1 Implementation of Scheduling Method Priority Level Method or FCFS Method Ready queue Priority High 1 Invoking task RUNNING state tskpri Task A Task B Task C READY state READY state READY state maxtpri Priority Low 11 4 1 Create ready queue In the RI78V4 the method of creating a ready queue is limited to static creation by the Kernel Initialization Module Ready queues therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static create Static ready queue creation is realized by defining Task priority information in the system configuration file The RI78V4 executes ready queue creation processing based on data stored in information files using the Kernel Initialization Module and ha
101. S Page 283 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE APPENDIX A WINDOW REFERENCE This appendix explains the window panels that are used when the activation option for the CF78V4 is specified from the integrated development environment platform CS A 1 Description The following shows the list of window panels Table A 1 List of Window Panels Window Panel Name Function Description Main window This is the first window to be open when the CS is launched Project Tree panel This panel is used to display the project components in tree view This panel is used to display the detailed information on the Realtime OS node system configuration file or the like that is selected on the Project Tree panel and change the settings of the information Property panel R20UT3375EJ0100 Rev 1 00 2tENESAS Page 284 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Outline This is the first window to be open when the CS is launched This window is used to control the user program execution and open panels for the build process This window can be opened as follows Select Windows start gt All programs gt Renesas Electronics CS gt CS Display image RSFLOOSL Microcontroller a CC RL Build Tool 4 amp 2 RIT8V4 Realtime OS l RL78 Simulator Debug Tool Sh File F Op F Ren_ F2 Fin F Rep e Go F amp Buil
102. SAS Page 60 of 309 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS Note 1 In the RI78V4 the number of tasks that can be queued to the eventflag wait queue is one If this service call is issued for the eventflag to which a task is queued therefore E_ILUSE is returned regardless of whether or not the required condition is immediately satisfied Note 2 The RI78V4 performs bit pattern clear processing 0x0 setting when the required condition of the target eventflag TA_CLR attribute is satisfied Note 3 When TMO_FEVR is specified for wait time tmout processing equivalent to wai_flg will be executed When TMO_POL is specified processing equivalent to pol_flg will be executed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 61 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 3 6 Reference eventflag state An eventflag status is referenced by issuing the following service call from the processing program ref_fig Stores eventflag state packet such as existence of waiting tasks of the eventflag specified by parameter figid in the area specified by parameter pk_rfig The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID flgid ID_f1gA Declares and initializes variabl
103. T3375EJ0100 Rev 1 00 tENESAS Page 263 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE Specifies the stack size in bytes of the task A value between 0 and 65534 aligned to a 2 byte boundary can be specified for stksz Note 1 The task stack is allocated to the kernel_stack section Note 2 For details about the estimation of the stack size of the task refer to See 13 5 2 Stack size of the task 7 System reserved area stk System reserved area Values that can be specified for stk are limited to NULL characters R20UT3375EJ0100 Rev 1 00 2tENESAS Page 264 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 2 Semaphore information Define the following items as semaphore information Semaphore name semid 1 2 Attribute queuing method sematr 3 Initial resource count isemcnt 4 System reserved area maxsem The number of semaphore information items that can be specified is defined as being within the range of 0 to 127 The following shows the semaphore information format CRE_SEM semid sematr isemcnt maxsem The items constituting the semaphore information are as follows 1 Semaphore name semid Specifies the semaphore name An object name can be specified for semid Note The CF78V4 outputs to the system information header file the correspondence between the semaphore names and IDs in the following format Conse
104. TER 2 SYSTEM CONSTRUCTION CHAPTER 2 SYSTEM CONSTRUCTION This chapter describes how to build a system load module that uses the functions provided by the RI78V4 2 1 Outline System building consists in the creation of a load module using the files kernel library etc installed on the user development environment host machine from the RI78V4 s supply media The following shows the procedure for organizing the system Figure 2 1 Example of System Construction System Configuration File Programs Task Cyclic Handler y Interrupt Handler C Configurator p User own Coding Interrupt entry process y Initialize routine Information file idle routine System information table file boot process System information header file System dependent information Trace information file Library Files C C Compiler Assembler Kernel Library C Compiler Standard Library x Math Library Object Files etc i q T Load Module R20UT3375EJ0100 Rev 1 00 2tENESAS Page 12 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 2 2 Coding of Processing Program Code the processing that should be implemented in the system In the RI78V4 the processing program is classified into the following three types in accordance with the types and purposes of the processing that should be implemented Tasks A ta
105. TER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 5 5 Receive from mailbox A message is received waiting forever polling or with timeout by issuing the following service call from the processing program rcv_mbx This service call receives a message from the mailbox specified by parameter mbxid and stores its start address in the area specified by parameter ppk_msg If the message could not be received from the target mailbox no messages were queued in the wait queue when this service call is issued message reception processing is not executed but the invoking task is queued to the target mailbox wait queue in the order of message reception request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state receiving waiting for a mailbox The receiving waiting for a mailbox is cancelled in the following cases and then moved to the READY state Receiving Waiting for a Mailbox Cancel Operation Return Value A message was transmitted to the target mailbox as a result of issuing snd_mbx E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file
106. TMOUT 50 Polling failure or timeout R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 192 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference semaphore state C format ER ref_sem ID semid T_RSEM pk_rsem Assembly format MOVW BC LOWW _pk_rsem MOV A semid CALL _ref_sem Parameter s 1 0 Parameter Description l ID semid ID number of the semaphore to be referenced O T_RSEM pk_rsem Pointer to the packet returning the semaphore state Explanation Stores semaphore state packet such as existence of waiting tasks of the semaphore specified by parameter semid in the area specified by parameter pk_rsem Note For details about the semaphore state packet refer to 12 5 2 Semaphore state packet Return value Macro Value Description E_OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 193 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 9 Synchronization and Communication Functions Eventflags The following lists the service calls provided by the RI78V4 as the synchronization and communication functions event flags Table 12 11 Synchronization and Communication Functions Eventtflags Service Call Function Origin of Service Call set_flg Set eventtflag Task Non task iset_flg Set eventtflag Task Non task clr_flg Clea
107. T_MSG_PRI used when issuing snd_mbx rcv_mbx prcv_mbx or trcv_mbx Definition of message packet T_ MSG and T_MSG_PRI is performed by header file lt ri_root gt include types h which is called from standard header file lt ri_root gt include kernel h Message packet for TA_MFIFO attribute typedef struct t_msg struct t_msg __ near msgque T_MSG Reserved for future use Message packet for TA_MPRI attribute T_MSG_PRI typedef struct t_msg_pri struct t_msg near msgque Reserved for future use PRI msgpri Message priority The following shows details on message packet T_MSG and T_MSG_PRI msgque System reserved area msgpri Stores the priority of the message Note 1 In the RI78V4 a message having a smaller priority number is given a higher priority Note 2 Values that can be specified for the priority of a message are limited from 1 to 31 R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 156 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 6 Mailbox state packet The following shows mailbox state packet T_RMBX used when issuing ref_mbx Definition of mailbox state packet T_RMBxX is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rmbx ID wtskid ID numb
108. Task wup_ tsk Wakeup task Task Non task iwup_tsk Wakeup task Task Non task can_wup Cancel task wakeup requests Task Non task ican_wup Cancel task wakeup requests Task Non task rel_wai Release task from waiting Task Non task irel_wai Release task from waiting Task Non task sus_tsk Suspend task Task Non task isus_tsk Suspend task Task Non task rsm_tsk Resume suspended task Task Non task irsm_tsk Resume suspended task Task Non task frsm_tsk Forcibly resume suspended task Task Non task ifrsm_tsk Forcibly resume suspended task Task Non task dly_tsk Delay task Task R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 172 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Put task to sleep waiting forever C format ER slp_tsk void Assembly format CALL _ slp_tsk Parameter s None Explanation As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject If a wakeup request has been queued to the target task the wakeup request counter is not set to 0x0 when this service call is issued this service call does not move the state but decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter Sleeping State Cancel Operation Return Value A wakeup request was issued as a result of issuing wup_tsk E OK A wakeup request
109. VR 43 Queue overflow overflow of suspension count 127 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 181 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Resume suspended task C format ER rsm_tsk ID tskid ER irsm_tsk ID tskid Assembly format MOV A tskid CALL _rsm tsk MOV A tskid CALL _irsm_ tsk Parameter s 1 0 Parameter Description l ID tskid ID number of the task to be resumed Explanation This service call subtracts 0x1 from the suspend request counter for the task specified by parameter tskid and then cancels the SUSPENDED state of the target task As a result the target task is moved from the SUSPENDED state to the READY state or from the WAITING SUSPENDED state to the WAITING state If a suspend request is queued subtraction result is other than 0x0 when this service call is issued the counter manipulation processing is not performed but only the suspend request counter decrement processing is executed Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 This service call does not perform queuing of cancellation requests If the target task is in a state other than the SUSPENDED or WAITING SUSPENDED state E_OBu is therefore returned Return value
110. _dsp is issued until this service call is issued the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until this service call is issued upon which the actual dispatch processing is performed in batch The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf LE ee ae ee x7 dis_dsp Disable dispatching VP Fag as EE a Dispatching disabled state ena_dsp Enable dispatching a Note This service call does not perform queuing of enable requests If the system is in the dispatching enabled state therefore no processing is performed but it is not handled as an error R20UT3375EJ0100 Rev 1 00 2tENESAS Page 105 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 8 Reference Contexts The context type is referenced by issuing the following service call from the processing program sns_ctx This service call acquires the context type of the processing program that issued this service call non task context or task context When this service call is terminated normally the acquired context type TRUE non task context FALSE task context is returned Non task contexts cyclic handler interrupt handler
111. _wtskid EQU 0x00 ID number of the task at the head of the wait queue rmpf_fblkcnt EQU 0x02 Number of free memory blocks The following shows details on fixed sized memory pool state packet T_RMPF wtskid rmpf_wtskid Stores information whether a task is queued to the wait queue TSK_NONE No applicable task Value ID number of the task at the head of the wait queue folkent rmpf_folkent Stores the number of free memory blocks R20UT3375EJ0100 Rev 1 00 2tENESAS Page 158 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 8 Cyclic handler state packet The following shows cyclic handler state packet T_ RCYC used when issuing ref_cyc Definition of cyclic handler state packet T_RCYC is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rcyc STAT cycstat Cyclic handler operational state RELTIM lefttim Time left before the next activation 7 RCYC3 packet inc rceyc_cycstat EQU 0x00 Cyclic handler operational state reyc_lefttim EQU 0x02 Time left before the next activation The following shows details on cyclic handler state packet T_RCYC cycstat rcyc_cycstat Stores the operational state of the cyclic handler TCYC_STP Operational state TCYC_STA Non operational state lefttim rcyc_leftti
112. able file sit_file asm is output to a folder in C Program Files tmp system information header file C_header h for C is output to a folder in C tmp system information header file ASM_header inc for assembly language is output to a folder in C tmp Figure 14 1 Example of Command File Description Command File i C Program Files tmp sit_file asm dc C tmp C_header h da C tmp ASM_header inc CF_file cfg R20UT3375EJ0100 Rev 1 00 2tENESAS Page 282 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 14 CONFIGURATOR CF78V4 14 2 4 Command input examples The following shows the CF78V4 command input examples In these examples C gt indicates the command prompt A indicates the space key input and lt Enter gt indicates the ENTER key input 1 After loading command file cmd_file from the current folder the activation option defined in cmd_file is executed C gt cf78v4 exe A cmd_file lt Enter gt 2 After loading system configuration file CF_file cfg from the current folder system information table file sit_file asm the system information header file C_header h for C and system information header file ASM_header inc for assembly language are output to the current folder specified device name is R5F10A6A and the path for device file is C Program Files Renesas Electronics CS CC Device RL78 Devicefile C gt cf78v4 exe A cpu A R5F10A6A A devpath C Program F
113. accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Polling failure or timeout E TMOUT Note 1 Invoking tasks are queued to the reception wait queue of the target data queue in the order of the data reception request Note 2 If the data reception wait state is cancelled because irel_wai or irel_wai was issued or the wait time elapsed the contents in the area specified by parameter p_data become undefined Note 3 TMO_FEVR is specified for wait time tmout processing equivalent to rcv_diq will be executed When TMO_POL is specified processing equivalent to prcv_dtq will be executed Return value Macro Value Description E OK 0 Normal completion Forced release from the WAITING state E RLWAI 49 Accept rel_wai irel_wai while waiting Timeout E TMOUT 50 Polling failure or timeout R20UT3375EJ0100 Rev 1 00 tENESAS Page 217 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference data queue state C format ER ref_dtq ID dtqid T_RDTQ pk_rdtq Assembly format MOVW BC LOWW _pk_rdtq MOV A dtqid CALL _ ref_dtq Parameter s O Parameter Description ID dtqid ID number of the data queue to be referenced O T_RDTQ pk_rdtq Pointer to the packet returning the data queue state Data queue state packet T_RDTQ typedef struct t_rdt
114. acquired by issuing a service call such as sig_sem or get_mpf The OS resource have been acquired must therefore be returned before issuing this service call Note 2 When moving a task to the DORMANT state this service call initializes the following information to values that are set during task creation Priority current priority Wakeup request count Suspension count Interrupt status R20UT3375EJ0100 Rev 1 00 2015 03 25 ztENESAS Page 36 of 309 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 6 Change Task Priority The priority is changed by issuing the following service call from the processing program chg_pri ichg_pri These service calls change the priority of the task specified by parameter tskid current priority to a value specified by parameter tskpri The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable PRI tskpri 15 Declares and initializes variable JE EER hte A chg_pri tskid tskpri Change task priority Note If the target task is in the RUNNING or READY state after this service call is issued this service call re queues the task at the end of the ready queue corresponding to the priority specified by parameter
115. ader file definition void func_task VP_INT exinf ID mpfid ID_mpfA Declares and initializes variable VP p_blk Declares variable char xp Declares variable ID mbxid ID_mbxA Declares and initializes variable T_MSG_PRI pk_msgj Declares data structure uee eee ard get_mpf mpfid amp p_blk Secures memory area for message Initializes variable p char p_ blk sizeof T_MSG_PRI j while expr ADIT S aha ea Creates message contents Initializes data structure T_MSG_PRI p_blk gt msgpri 8 Send to mailbox snd_mbx mbxid T_MSG_PRI p_blk Note 1 If the first task of the wait queue is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 Messages are queued to the target mailbox wait queue in the order defined by Attribute queuing method mbxatr during configuration FIFO order or priority order Note 3 With the RI78V4 mailbox only the start address of the message is handed over to the receiving processing program but the message contents are not copied to a separate area The message contents can therefore be rewritten even after this service call is issued Note 4 For details about the message packet refer to 12 5 5 Message packet R20UT3375EJ0100 Rev 1 00 2tENESAS Page 77 of 309 2015 03 25 CAP
116. ai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 tENESAS Page 185 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 8 Synchronization and Communication Functions Semaphores The following lists the service calls provided by the RI78V4 as the synchronization and communication functions sema phores Table 12 10 Synchronization and Communication Functions Semaphores Service Call Function Origin of Service Call sig_sem Release semaphore resource Task Non task isig_sem Release semaphore resource Task Non task wai_sem Acquire semaphore resource waiting forever Task pol_sem Acquire semaphore resource polling Task Non task twai_sem Acquire semaphore resource with timeout Task ref_sem Reference semaphore state Task Non task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 186 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS sig sem isig sem Outline Release semaphore resource C format ER sig_sem ID semid ER isig_sem ID semid Assembly format MOV A semid CALL _ sig_sem MOV A semid CALL _isig_sem Parameter s 0 Parameter Description l ID semid ID number of the semaphore to which resource is released Explanation These service calls return the resource to the semaphore specified by parameter semid adds 0x1 to the semaphore counter If a task is queued in th
117. ai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Polling failure or timeout E TMOUT The following shows the specification format of required condition wfmode wimode TWF_ANDW Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag wfmode TWF_ORW Checks which bit among bits to which 1 is set by parameter waiptn is set as the target eventflag The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID flgid ID_fl1gA Declares and initializes variable FLGPTN waiptn 0B1110 Declares and initializes variable ODE wfmode TWF_ANDW Declares and initializes variable FLGPIN p_flgptn Declares variable TMO tmout 3600 Declares and initializes variable i ee ee ee ard Wait for eventflag with timeout ercd twai_flg flgid waiptn wfmode amp p_flgptn tmout if ercd E_OK PP ik EEE Normal termination processing lse if ercd E_RLWAI PO Seca a atest le tees Forced termination processing lse if ercd E_TMOUT oO 3 Nor ae DRA an hate ay Timeout processing R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENE
118. all include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf TE EAE Meee EAR dis_dsp Disable dispatching JE pease abd j Dispatching disabled state ena_dsp Enable dispatching F J dees ghee tad va Note This service call does not queue enable requests If the system is in the dispatching enabled state therefore no processing is performed but it is not handled as an error R20UT3375EJ0100 Rev 1 00 2tENESAS Page 137 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 6 Delay of Scheduling If a service call ichg_pri isig_sem etc accompanying dispatch processing task scheduling processing is issued in order to quickly complete the processing in a non task cyclic handler interrupt handler etc during the interval until the processing in the non task ends the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until a return instruction is issued by the non task upon which the actual dispatch processing is performed in batch The following shows a processing flow when a service call that involves dispatch processing in a non task is issued Figure 11 5 Delay of Scheduling Task Task Priority High Priority Low Interrupt handler Acquire semaphore resource o al
119. aphore state packet refer to 12 5 2 Semaphore state packet R20UT3375EJ0100 Rev 1 00 2tENESAS Page 53 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 3 Eventflags The RI78V4 provides 16 bit eventflags as a queuing function for tasks such as keeping the tasks waiting for execution until the results of the execution of a given processing program are output The following shows a processing flow when using an eventtflag Figure 5 2 Processing Flow Eventflag Task Task Priority High Priority Low Wait for eventtflag Queuing period Set eventflag 5 3 1 Create eventflag In the RI78V4 the method of creating an eventtlag is limited to static creation by the Kernel Initialization Module Eventflags therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static create Static eventflag creation is realized by defining Eventflag information in the system configuration file The RI78V4 executes eventflag creation processing based on data stored in information files using the Kernel Initialization Module and handles the created eventflags as management targets Note In the RI78V4 0x0 is the initial bit pattern for eventflag creation processing 5 3 2 Delete eventflag In the RI78V4 eventflags created statically by the Kernel Initialization Module cannot be deleted dynamically using a method such as issuing
120. arameter s None Explanation This service call acquires the system status type when this service call is issued CPU locked state or CPU unlocked state When this service call is terminated normally the acquired system state type TRUE CPU locked state FALSE CPU unlocked state is returned Note The system enters the CPU locked state when loc_cpu or iloc_cpu is issued and enters the CPU unlocked state when unl_cpu or iunl_cpu is issued Return value Macro Value Description TRUE 1 Normal completion CPU locked state FALSE 0 Normal completion CPU unlocked state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 252 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference dispatching state C format BOOL sns_dsp void Assembly format CALL _ sns_dsp Parameter s None Explanation This service call acquires the system status type when this service call is issued dispatching disabled state or dispatching enabled state When this service call is terminated normally the acquired system state type TRUE dispatching disabled state FALSE dispatching enabled state is returned Note The system enters the dispatching disabled state when dis_dsp is issued and enters the dispatching enabled state when ena_dsp is issued Return value Macro Value Description TRUE 1 Normal completion dispatching disabled st
121. area or to the far area The following shows examples for coding interrupt entry processing When the relevant processing Interrupt Handlers Boot Processing or the like is allocated to the near area PUBLIC _func_inthdr _func_inthdr VECTOR 0x002C Jump to boot processing SECTION text TEXT Vector table address setting _func_inthar ip aes tee Main processing When the relevant processing Interrupt Handlers Boot Processing or the like is allocated to the far area EXTERN _intent_RESET Declares symbol external referenc EXTERN _intent_INTTMOO Declares symbol external referenc SECTION vecttable TEXT Vector table section setting _intent_RESET VECTOR 0x0000 Vector table address setting _intent_INTTMOO VECTOR 0x002C Vector table address setting SECTION textf TEXTF Vector table section setting _intent_RESET BR LI boot Jump to boot processing _intent_INTTMOO BR func_inthdr Jump to interrupt handler 9 2 2 Internal processing of interrupt entry processing Interrupt entry processing is a routine dedicated to processing of entries called without using the RI78V4 when an interrupt occurs Therefore note the following points when coding interrupt entry processing Coding method Code interrupt entry processing in assembly language in formats compliant with the assembler s function calling rules Stack switching No s
122. as Electronics Malaysia Sdn Bhd Unit 1207 Block B Menara Amcorp Amcorp Trade Centre No 18 Jin Persiaran Barat 46050 Petaling Jaya Selangor Darul Ehsan Malaysia Tel 60 3 7955 9390 Fax 60 3 7955 9510 Renesas Electronics India Pvt Ltd No 777C 100 Feet Road HALII Stage Indiranagar Bangalore India Tel 91 80 67208700 Fax 91 80 67208777 Renesas Electronics Korea Co Ltd 12F 234 Teheran ro Gangnam Gu Seoul 135 080 Korea Tel 82 2 558 3737 Fax 82 2 558 5141 2015 Renesas Electronics Corporation All rights reserved Colophon 4 0 RI78V4 V2 00 00 tENESAS Renesas Electronics Corporation R20UT3375EJ0100
123. ate FALSE 0 Normal completion dispatching enabled state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 253 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference dispatch pending state C format BOOL sns_dpn void Assembly format CALL sns_dpn Parameter s None Explanation This service call acquires the system status type when this service call is issued whether in dispatch pending state or not When this service call is terminated normally the acquired system state type TRUE dispatch pending state FALSE dispatch not pending state is returned Note The dispatch pending state designates the state in which explicit execution of dispatch processing task scheduling processing is prohibited by issuing either the dis_dsp loc_cpu or iloc_cpu service call as well as the state during which processing of a non task is being executed Return value Macro Value Description TRUE 1 Normal completion dispatch pending state FALSE 0 Normal completion other state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 254 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 15 System Configuration Management Functions The following lists the service calls provided by the RI78V4 as the system configuration management functions Table 12 17 System Configuration Management Functions Service Call Function Orig
124. ate sns_dpn Reference dispatch pending state The following shows a processing flow when using this service call Figure 8 2 Lock the CPU Task Interrupt handler mr S n CPU Suppressed period Unlock the CPU return R20UT3375EJ0100 Rev 1 00 2tENESAS Page 100 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf PP ares Bleed a ee l c_ epu Lock the CPU AE E E EA EE E ts CPU locked state unl_cpu Unlock the CPU PE agadir 2 Note 1 The CPU locked state changed by issuing this service call must be cancelled before the processing program that issued this service call ends Note 2 This service call does not perform queuing of lock requests If the system is in the CPU locked state therefore no processing is performed but it is not handled as an error Note 3 The RI78V4 implements disabling of maskable interrupt acknowledgment bu manipulating the interrupt mask flag register MKxx and the in service priority flag ISPx of the program status word PSW Therefore manipulating of these registers from the processing program is prohibited from when this service call is issued until unl_cpu or iunl_cpu
125. ation table file R20UT3375EJ0100 Rev 1 00 ztENESAS Page 115 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 9 3 3 Internal processing of interrupt handler The RI78V4 handles the interrupt handler as a non task Moreover the RI78V4 executes original pre processing when passing control to the interrupt handler as well as original post processing when regaining control from the interrupt handler Therefore note the following points when coding interrupt handlers Coding method Code interrupt handlers using C or assembly language in the format shown in 9 3 2 Basic form of interrupt handlers Stack switching When the interrupt handler is described by C language the user does not have to describe to switch to the system stack calls _kernel_int_entry because of the C compiler outputing this code automatically When the interrupt handler is described by assembly language saves AX register and stores the vector table address when an interrupt occurs calls processing to switch to the system stack function name _kernel_int_entry and then call end processing at the end of the interrupt handler function name _kernel_int_exit Saving storing of data in register When the interrupt handler is described by C language the user does not have to describe to switch to the system stack calls _kernel_int_entry because of the C compiler outputing this code automatically When the interrupt handle
126. attern set to the target eventflag is B 1100 and the bit pattern specified by parameter clrptn is B 1010 when this service call is issued the bit pattern of the target eventflag is set to B 1110 Note 3 This service call does not cancel tasks in the waiting state for an eventtflag Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 7tENESAS Page 197 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Wait for eventflag waiting forever C format ER wai_ flg ID flgid FLGPIN waiptn MODE wfmode FLGPIN p_flgptn Assembly format MOVW DE LOWW _p_flgptn MOVW BC waiptn MOVW AX flgid wfmode CALL _ wai_flg Parameter s 0 Parameter Description l ID flgid ID number of the eventflag wait for l FLGPTN waiptn Wait bit pattern 16 bits Wait mode l MODE wfmode TWF_ANDW AND waiting condition TWF_ORW OR waiting condition O FLGPTN p_flgptn Bit pattern causing a task to be released from waiting Explanation This service call checks whether the bit pattern specified by parameter waiptn and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid If a bit pattern that satisfies the required condition has been set for the target eventflag the bit pattern of the target eventtflag i
127. c form of initialization routine Stack switching The RI78V4 executes processing to switch to the system stack when passing control to the initialization routine and processing to switch to the stack for the Kernel Initialization Module when regaining control from the initialization routine The user is therefore not required to code processing related to stack switching in initialization routines Interrupt status Maskable interrupt acknowledgement is prohibited in the RI78V4 when control is passed to the initialization routine Kernel Initialization Module is not completed at the point when control is passed to the initialization routine The system may therefore hang up when acknowledgment of maskable interrupts is explicitly enabled within the initialization routine Therefore enabling maskable interrupt acknowledgment in the initialization routine is prohibited in the RI78V4 Service call issuance The RI78V4 prohibits issuance of service calls in initialization routines The following lists processing that should be executed in initialization routines Initialization of internal units and peripheral controllers Initialization of RAM area initialization of memory area without initial value copying of initialization data Returning of control to Kernel Initialization Module 10 4 Kernel Initialization Module The kernel initialization module is a dedicated initialization processing routine provided for initializing the minim
128. call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 If the bit pattern set to the target eventflag is B 1100 and the bit pattern specified by parameter setptn is B 1010 when this service call is issued the bit pattern of the target eventflag is set to B 1110 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 55 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 3 4 Clear eventflag A bit pattern is cleared by issuing the following service call from the processing program clr_fig This service call sets the result of ANDing the bit pattern set to the eventflag specified by parameter figid and the bit pattern specified by parameter cirptn as the bit pattern of the target eventtlag The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID flgid ID_flgA Declares and initializes variable FLGPTN clrptn 0B1010 Declares and initializes variable a ne ee ae clr_flg flgid clrptn Clear eventflag Note 1 This service call does not perform queuing of clear requests If the bit pattern has been cleared therefore no processing is performed but it is not handled as an error Note 2 If the bit pattern set to the target eventflag is B 110
129. call reads data in the data queue area of the data queue specified by parameter dtqid and stores it to the area specified by parameter p_data If no data could be read from the data queue area of the target data queue no data has been written to the data queue area when this service call is issued the service call does not read data but queues the invoking task to the reception wait queue of the target data queue and moves it from the RUNNING state to the WAITING state data reception wait state The receiving WAITING state for a data queue is cancelled in the following cases and then moved to the READY state Receiving WAITING State for a Data Queue Cancel Operation Return Value Data was written to the data queue area of the target data queue as a result of issuing snd_dtq E_OK Data was written to the data queue area of the target data queue as a result of issuing psnd_diq Ee Data was written to the data queue area of the target data queue as a result of issuing ipsnd_dtq E OK Data was written to the data queue area of the target data queue as a result of issuing tsnd_dtq E_OK Data was written to the data queue area of the target data queue as a result of issuing tsnd_dtq E_OK Data was written to the data queue area of the target data queue as a result of issuing ifsnd_dtq BOK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting a
130. ccept irel_ wai while waiting E RLWAI R20UT3375EJ0100 Rev 1 00 ztENESAS Page 213 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Note 1 Invoking tasks are queued to the reception wait queue of the target data queue in the order of the data reception request Note 2 If the receiving for a data queue is forcibly released by issuing rel_wai or irel_wai the contents of the area specified by parameter p_daia will be undefined Return value Macro Value Description E OK 0 Normal completion Forced release from the WAITING state E RLWAI 49 Accept rel_wai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 214 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Receive from data queue polling C format ER prcev_dtq ID dtgid VP_INT p data Assembly format MOVW BC LOWW _data MOV A dtqid CALL 1 prev_dtq Parameter s O Parameter Description l ID dtqid ID number of the data queue from which a data element is received O VP_INT p data Explanation s Data element received from the data queue These service calls read data in the data queue area of the data queue specified by parameter dtqid and stores it to the area specified by parameter p_data If no data could be read from the data queue area of the target data queue no data has been written to the data que
131. ce mode Hold the trace to target RAM If this mode is perik the monitor control taking trace is linked automatically Trace chart Take in the trace chart and the CPU usage rate The analyzable time is short Long statistics Take in the CPU usage rate Not take in the trace chart The analyzable time is long It can use only by software trace mode RI78V4 Task Analyzer z How to open First selects the Real time OS in Project Tree panel after selecting a real time OS node selects view menu gt property or selects context menu gt property Note When a property panel opens already if you select a real time OS node on project tree panel detail informa tion is displayed Explanation of each area 1 Trace Sets up the trace mode of task analyzer Select trace mode of Realtime OS Task Analyzer Selection of trace mode Default Not tracing mene Select from the drop down list change R20UT3375EJ0100 Rev 1 00 RENESAS Page 294 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Restriction Not tracing Taking in trace chart by hardware trace mode Can not use Realtime OS Task Analyzer The trace information is collected in the trace memory which emulator or simulator has Taking in trace chart by software trace mode The trace information is collected in the trace buffer secured on the user memory area To use this mode implemen
132. ce object ID number for which the task is waiting Reference activation request count R rence wakeup request count R rence suspension count Hh Fh Note For details about the task state packet refer to 12 5 1 Task state packet R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 38 of 309 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS This chapter describes the task dependent synchronization functions performed by the RI78V4 4 1 Outline The RI78V4 provides several task dependent synchronization functions 4 2 Put Task to Sleep A task is moved to the sleeping state waiting forever or with timeout by issuing the following service call from the processing program slp_tsk As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject If a wakeup request has been queued to the target task the wakeup request counter is not set to 0x0 when this service call is issued this service call does not move the state but decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter The sleeping state is cancelled in the following cases and then moved to the READY state Sleeping State Cancel Operation Return Value A wakeup request was issued as a result of issuing wup_tsk E OK A wakeup request was issued as a resu
133. cified by parameter ppk_msg If the message could not be received from the target mailbox no messages were queued in the wait queue when this service call is issued message reception processing is not executed but the invoking task is queued to the target mailbox wait queue in the order of message reception request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state receiving waiting state for a mailbox The receiving waiting state for a mailbox is cancelled in the following cases and then moved to the READY state Receiving Waiting State for a mailbox Cancel Operation Return Value A message was transmitted to the target mailbox as a result of issuing snd_mbx E OK Forced release from waiting accept rel_wai while waiting E RLWAI R20UT3375EJ0100 Rev 1 00 tENESAS Page 225 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Receiving Waiting State for a mailbox Cancel Operation Return Value Forced release from waiting accept irel_wai while waiting E RLWAI Polling failure or timeout E TMOUT Note 1 When TMO_FEVR is specified for wait time tmout processing equivalent to rcv_mbx will be executed When TMO_POL is specified processing equivalent to prcv_mbx will be executed Note 2 For details about the message packet refer to 12 5 5 Message packet Return value
134. coding TA_MPRI attribute messages in C Message packet for TA_MPRI attribute typedef struct struct PRI T_MSG_PRI t_msg_pri t_msg msgpri Reserved for future use Message priority near msgque Note 1 Note 2 A value between 1 and 31 can be specified for message priority In the RI78V4 a message having a smaller priority number is given a higher priority Note 3 For details about the message packet refer to 12 5 5 Message packet 2tENESAS 2015 03 25 Page 76 of 309 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 5 4 Send to mailbox A message is transmitted by issuing the following service call from the processing program snd_mbx This service call transmits the message specified by parameter pk_msg to the mailbox specified by parameter mbxid queues the message in the wait queue If a task is queued to the target mailbox wait queue when this service call is issued the message is not queued but handed over to the relevant task first task of the wait queue As a result the relevant task is unlinked from the wait queue and is moved from the WAITING state receiving waiting state for a mailbox to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information he
135. conditions Further Renesas Electronics products are not subject to radiation resistance design Please be sure to implement safety measures to guard them against the possibility of physical injury and injury or damage caused by fire in the event of the failure of a Renesas Electronics product such as safety design for hardware and software including but not limited to redundancy fire control and malfunction prevention appropriate treatment for aging degradation or any other appropriate measures Because the evaluation of microcomputer software alone is very difficult please evaluate the safety of the final products or system manufactured by you Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances including without limitation the EU RoHS Directive Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations This document may not be reproduced or duplicated in any form in whole or in part without prior written consent of Renesas Electronics Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics produc
136. ct from the drop down list change The trace buffer is allocated in Kernel buffer A p kernel_data_trace_n section Restriction Another buffer The trace buffer is allocated from specified address R20UT3375EJ0100 Rev 1 00 2015 03 25 stENESAS Page 295 of 309 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Specify the start address of the trace buffer This item is displayed only when Another buffer is selected Buffer address Default Oxf0000 How to Directly enter to the text box change Restriction Oxf0000 Oxffff4 Specifies whether the timer interrupt is traced or not This item is displayed when Taking in trace chart by hardware trace mode or Taking in trace chart by software trace mode is selected Trace the timer interrupt peal nernel tunar for Realtime QS How to Select from the drop down list change Es Yes The timer interrupt is traced ee No The timer interrupt is not traced R20UT3375EJ0100 Rev 1 00 ztENESAS Page 296 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE System Configuration File Related Information tab Outline This tab shows the detailed information on the using system configuration file categorized by the following and the configuration can be changed System information table file System information header file for C language System information header file for a
137. d directly Mark E indicates that all the items in the category are expanded Mark H indicates that all the items are collapsed You can expand collapse the items by clicking these marks or double clicking the category name See the section on each tab for the details of the display setting in the category and its contents 3 Property description area Display the brief description of the categories and their contents selected in the detailed information display change area R20UT3375EJ0100 Rev 1 00 7tENESAS Page 290 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE 4 Tab selection area Categories for the display of the detailed information are changed by selecting a tab In this panel the following tabs are contained see the section on each tab for the details of the display setting on the tab When the Realtime OS node is selected on the Project Tree panel RI78V4 tab When the system configuration file is selected on the Project Tree panel System Configuration File Related Information tab File Information tab When the Realtime OS generated files node is selected on the Project Tree panel Category Information tab When the system information table file is selected on the Project Tree panel Build Settings tab Individual Assemble Options tab File Information tab When the system information header file is selected on the Project Tree panel File Informatio
138. de kernel h Table 12 4 WAITING Types Macro Value Description A task enters this state if the counter for the task register ing the number of times the wakeup request has been TTW_SLP 0x000 issued indicates 0x0 upon the issuance of a slp_tsk or tslp_tsk TTW_DLY 0x0002 A task enters this state upon the issuance of a dly_tsk A task enters this state if it cannot acquire a TTW_SEM 0x0004 resource from the relevant semaphore upon the issuance of a wai_sem or twai_sem A task enters this state if a relevant eventflag does TTW_FLG 0x0008 not satisfy a predetermined condition upon the issu ance of a wai_flg or twai_flg A task enters this state if cannot send a data to the TTW_SDTQ 0x0010 relevant data queue upon the issuance of a snd_dtq or tsnd_dtq A task enters this state if cannot receive a data from TTW_RDTQ 0x0020 the relevant data queue upon the issuance of a rcv_dtq or trcv_dtq A task enters this state if cannot receive a message TTW_MBX 0x0040 from the relevant mailbox upon the issuance of a rcv_mbx or trcv_mbx R20UT3375EJ0100 Rev 1 00 2tENESAS Page 148 of 309 2015 03 25 CHAPTER 12 SERVICE CALLS RI78V4 V2 00 00 Macro Value Description A task enters this state if it cannot acquire a fixed TTW_MPF 0x2000 sized memory block from the relevant fixed sized memory pool upon the issuance of a get_mpf or tget_mpf R20UT3375EJ0100 Rev 1 00 2tEN
139. dispatching disabled state functions for referencing the state of the system such as context type referencing and CPU locked state referencing 8 2 Rotate Task Precedence A ready queue is rotated by issuing the following service call from the processing program rot_rdq irot_rdq This service call re queues the first task of the ready queue corresponding to the priority specified by parameter tskpri to the end of the queue to change the task execution order explicitly The following shows the status transition when this service call is used Figure 8 1 Rotate Task Precedence Ready queue 1 Invoking task RUNNING state Task A Task B Task C READY state READY state READY state tskpri maxtpri rot_rdq tskpri Ready queue 1 Invoking task RUNNING state tskpri Task B Task C Task A READY state READY state READY state maxtpri R20UT3375EJ0100 Rev 1 00 2tENESAS Page 97 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_cychdr void PRI tskpri 8 Declares and initializes variable E ensais ie teats 7 irot_rdq tskpri Rotate task prec
140. e T_RFLG pk_rflg Declares data structure ID wt skid Declares variable FLGPIN flgptn Declares variable PRO SB Bd lod ye Perec ref_flg flgid amp pk_rflg Reference eventflag state wtskid pk_rflg wtskid Reference ID number of the task at the head of the wait queue flgptn pk_rflg flgptn Reference current bit pattern a ee ee ee my Note For details about the eventflag state packet refer to 12 5 3 Eventflag state packet R20UT3375EJ0100 Rev 1 00 2tENESAS Page 62 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 4 Data Queues Multitask processing requires the inter task communication function data transfer function that reports the processing result of a task to another task The RI78V4 therefore provides the data queues that have the data queue area in which data read write is enabled for transferring the prescribed size of data The following shows a processing flow when using a data queue Figure 5 3 Processing Flow Data Queue Task A Task B Priority High Priority Low Receive from data queue Reception wait period Send to data queue Note Data units of 4 bytes are transmitted or received at a time 5 4 1 Create data queue In the RI78V4 the method of creating a deta queue is limited to static creation Data queues therefore cannot be created dynamically using a method such as issuing a
141. e definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID tskid ID_tskA Declares and initializes variable ercd act_tsk tskid Call service call ext_tsk Call service call Note To call the service calls provided by the RI78V4 from a processing program the header files listed below must be coded include processing kernel h Standard header file for C language kernel_id h System information header file for C language R20UT3375EJ0100 Rev 1 00 ztENESAS Page 142 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 2 2 Assembly language By calling with the CALL instruction after performing the parameter settings according to the assembler s function calling rules the service call parameters are handed over to the RI78V4 and the relevant processing is executed Assembly Language SINCLUDE kernel inc Standard header file definition SINCLUDE kernel_id inc System information header file definition SECTION bss BSS erca DS 2 Secures area for storing return value PUBLIC _func_task SECTION textf TEXTF _func_task MOV A ID_tskA Parameter setting CALL _act_tsk Call service call MOVW LOWW _ercd AX Return value setting CALL 1t ext tsk Call service call BR __ kernel_int_exit Jump to end of processing
142. e definition void func_task VP_INT exinf ID semid ID_semA Declares and initializes variable LP EEE EEN a Ef sig_sem semid Release semaphore resource JE sunitai iea Note 1 If the first task linked in the wait queue is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 The semaphore counter managed by the RI78V4 is configured in 7 bit widths If the number of resources exceeds the maximum count value 127 as a result of issuing this service call the counter manipulation processing is therefore not performed but E_QOVR is returned R20UT3375EJ0100 Rev 1 00 2tENESAS Page 49 of 309 2015 03 25 CHAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 2 4 Acquire semaphore resource A resource is acquired waiting forever polling or with timeout by issuing the following service call from the processing program wai_sem This service call acquires a resource from the semaphore specified by parameter semid subtracts 0x1 from the semaphore counter If a resource could not be acquired from the target semaphore Semaphore counter is set to 0x0 when this service call is issued the counter manipulation processing is not performed but the invoking task is queued to the target semaphore wait queue in the order of resource acquisition request FIFO order
143. e if ercd E_TMOUT EPO Sista ETE T af Timeout processing JE eB etd ad cee Sides Note When TMO_FEVR is specified for wait time tmout processing equivalent to wai_sem will be executed When TMO_POL is specified processing equivalent to pol_sem will be executed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 52 of 309 2015 03 25 CHAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 2 5 Reference semaphore state A semaphore status is referenced by issuing the following service call from the processing program ref_sem Stores semaphore state packet such as existence of waiting tasks of the semaphore specified by parameter semid in the area specified by parameter pk_rsem The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID semid ID_semA Declares and initializes variable T_RSEM pk_rsem Declares data structure ID wt skid Declares variable UINT semcnt Declares variable a Oy a eee ae k ref_sem semid amp pk_rsem Reference semaphore state wtskid pk_rsem wtskid Reference ID number of the task at the head of the wait queue semcnt pk_rsem semcnt Reference current resource count LP neue bende eta 7 Note For details about the sem
144. e interrupt mask flag register MKxx and the in service priority flag ISPx of the program status word PSW Therefore manipulating of these registers from the processing program is prohibited from when loc_cpu or iloc_cpu is issued until this service call is issued R20UT3375EJ0100 Rev 1 00 2tENESAS Page 102 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 6 Disable Dispatching A task is moved to the dispatching disabled state by issuing the following service call from the processing program dis_dsp This service call changes the system status to the dispatching disabled state As a result dispatch processing task scheduling is disabled from when this service call is issued until ena_dsp is issued If a service call chg_pri sig_sem etc accompanying dispatch processing is issued during the interval from when this service call is issued until ena_dsp is issued the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until ena_dsp is issued upon which the actual dispatch processing is performed in batch The following shows a processing flow when using this service call Figure 8 3 Disable Dispatching Task Task Priority High Priority Low Acquire semaphore resource Disable Dispatching Release semaphore resource Suppressed period Enable Dispatching The following describes
145. e start address in the area specified by parameter p_bik If a memory block could not be acquired from the target fixed sized memory pool no available memory blocks exist when this service call is issued memory block acquisition processing is not performed but E_TMOUT is returned Return value Macro Value Description E OK 0 Normal completion E TMOUT 50 Polling failure R20UT3375EJ0100 Rev 1 00 7tENESAS Page 231 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Acquire fixed sized memory block with timeout C format ER tget_mpf ID mpfid VP p_blk TMO tmout Assembly format MOVW AX tmout_hi PUSH AX MOVW AX tmout_lo PUSH AX MOVW BC LOWW _p_blk MOV A mpfid CALL _tget_mpf ADDW SP 0x0004 Parameter s 0 Parameter Description ID number of the fixed sized memory pool from which a memory block l ID mpfid is acquired O VP p_ blk Start address of the acquired memory block Specified timeout unit ticks TMO tmout TMO_FEVR Waiting forever TMO_POL Polling Value Specified timeout Explanation This service call acquires the memory block from the fixed sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_bik If a memory block could not be acquired from the target fixed sized memory pool no available memory blocks ex
146. e wait queue of the target semaphore when this service call is issued the counter manipulation processing is not performed but the resource is passed to the relevant task first task of wait queue As a result the relevant task is unlinked from the wait queue and is moved from the WAITING state waiting state for a semaphore resource to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Note 1 If the first task linked in the wait queue is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 The semaphore counter managed by the RI78V4 is configured in 7 bit widths If the number of resources exceeds the maximum count value 127 as a result of issuing this service call the counter manipulation processing is therefore not performed but E_QOVR is returned Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 7tENESAS Page 187 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E_QOVR Queue overflow release will exceed maximum resource count 127 R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 188 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Acquire semaphore resource waiting forever C format ER wai_sem
147. eader file definition Declares Declares Declares Declares Declares Declares Reference version information Referenc data structure variable variable variable variable variable Kernel maker s code Reference identification number of the kernel Reference version number of the ITRON Specification Reference version number of the kernel Referenc product management information of the kernel version type Referenc product management information of the kernel memory model Note For details about the version information packet refer to 12 5 9 Version information packet R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 128 of 309 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER CHAPTER 11 SCHEDULER This chapter describes the scheduler of the RI78V4 11 1 Outline The scheduling functions provided by the RI78V4 consist of functions manage decide the order in which tasks are executed by monitoring the transition states of dynamically changing tasks so that the CPU use right is given to the optimum task 11 2 Driving Method The RI78V4 employs the Event driven system in which the scheduler is activated when an event trigger occurs Event driven system Under the event driven system of the RI78V4 the scheduler is activated upon occurrence of the events listed below and dispatch processing task scheduling processing is execu
148. eased If a maskable interrupt is created during the interval from when either loc_cpu or iloc_cpu is issued until this service call is issued the RI78V4 delays transition to the relevant interrupt processing interrupt handler until this service call is issued Note 1 This service call does not perform queuing of cancellation requests If the system is in the CPU unlocked state therefore no processing is performed but it is not handled as an error Note 2 The RI78V4 implements enabling of maskable interrupt acknowledgment bu manipulating the interrupt mask flag register MKxx and the in service priority flag ISPx of the program status word PSW Therefore manipulating of these registers from the processing program is prohibited from when loc_cpu or iloc_cpu is issued until this service call is issued Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 248 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Disable dispatching C format ER dis_dsp void Assembly format CALL _dis_dsp Parameter s None Explanation This service call changes the system status to the dispatching disabled state As a result dispatch processing task scheduling is disabled from when this service call is issued until ena_dsp is issued If a service call chg_pri sig_sem etc accompanying dispatch processin
149. ectronics 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
150. ed sized memory block The waiting state for a fixed sized memory block is cancelled in the following cases and then moved to the READY state Waiting State for a Fixed sized Memory Block Cancel Operation Return Value A memory block was returned to the target fixed sized memory pool as a result of issuing E OK rel_mpf Forced release from waiting accept rel_wai while waiting E_RLWAI Forced release from waiting accept irel_wai while waiting E_RLWAI Return value R20UT3375EJ0100 Rev 1 00 tENESAS Page 229 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E OK E_RLWAI 49 Normal completion Forced release from waiting accept rel_wai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 230 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Acquire fixed sized memory block polling C format ER pget_mpf ID mpfid VP p_blk Assembly format MOVW BC LOWW _p blk MOV A mpfid CALL _pget_mpf Parameter s 0 Parameter Description ID number of the fixed sized memory pool from which a memory block ID mpfid is acquired O VP p_ blk Start address of the acquired memory block Explanation This service call acquires the memory block from the fixed sized memory pool specified by parameter mpfid and stores th
151. ed sized memory pool to the kernel_work1 section kernel_work2 Allocates the fixed sized memory pool to the kernel_work2 section kernel_work3 Allocates the fixed sized memory pool to the kernel_work3 section Note If specification of seg_nam is omitted the fixed sized memory pool is allocated to the kernel_work0O section 6 System reserved area mpf System reserved area Values that can be specified for mpf are limited to NULL characters R20UT3375EJ0100 Rev 1 00 2tENESAS Page 270 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 7 Cyclic handler information Define the following items as cyclic handler information Cyclic handler name cycid Attribute coding language initial activation status saving activation phase cycatr System reserved area exinf Start address cychdr Activation cycle cyctim Activation phase cycphs The number of cyclic handler information items that can be specified is defined as being within the range of 0 to 127 The following shows the cyclic handler information format CRE_CYC cycid cycatr exinf cychdr cyctim cycphs The items constituting the cyclic handler information are as follows 1 Cyclic handler name cycid Specifies the cyclic handler name An object name can be specified for cycid Note The CF78V4 outputs to the system information header file the correspondence between the cyclic handler names and IDs in the
152. ed task is in the DORMANT state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 168 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS chg_pri ichg_pri Outline Change task priority C format ER chg pri ID tskid PRI tskpri ER ichg_pri ID tskid PRI tskpri Assembly format MOVW AX tskid tskpri CALL L ehg pri MOVW AX tskid tskpri CALL t4 _ichg pri Parameter s V O Parameter Description ID number of the task whose priority is to be changed ID tskid TSK_SELF Invoking task Value ID number of the task whose priority is to be changed New current priority of the task l PRI tskpri TPRI_INI Initial priority of the task Value New current priority of the task Explanation These service calls change the priority of the task specified by parameter tskid current priority to a value specified by parameter tskpri Note If the target task is in the RUNNING or READY state after this service call is issued this service call re queues the task at the end of the ready queue corresponding to the priority specified by parameter tskpri following priority change processing Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 169 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E OBJ Object state
153. ed to the far area Calls processing to switch to the system stack function name _kernel_int_entry and then call end processing at the end of the interrupt handler function name _kernel_int_exit A far attribute section is specified as an allocated section of the interrupt handler S INCLUDE kernel inc Standard header file definition S INCLUDE kernel_id inc System information header file definition PUBLIC _func_inthdr _func_inthdr VECTOR 0x002C SECTION textf TEXTF Interrupt handler _func_inthadr CALL __ kernel_int_entry Switchs to the system stack and saves registers EEEE EE Main processing BR l _ kernel_int_exit Terminate interrupt handler Restores registers Note 1 The TA_ASM attribute and the TA_FAR attribute are specified in a definition of a interrupt handler in the system configuration file DEF_INH R20UT3375EJ0100 Rev 1 00 ztENESAS Page 114 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS Note 2 When allocating a interrupt handler in far area the far branch information is needed In other words it jumps from the vector table address to far branch information and jumps to a interrupt handler from there CF78V4 outputs this far branch information automatically in a system information table file Note 3 CF78V4 outputs processing code that saves AX register and sets the vector table address of the factor automatically in a system inform
154. edence PR vised elastics sapiens return Terminate cyclic handler Note 1 This service call does not perform queuing of rotation requests If no task is queued to the ready queue corresponding to the relevant priority therefore no processing is performed but it is not handled as an error Note 2 Round robin scheduling can be implemented by issuing this service call via a cyclic handler in a constant cycle Note 3 The ready queue is a hash table that uses priority as the key and tasks that have entered an executable state READY state or RUNNING state are queued in FIFO order Therefore the scheduler realizes the RI78V4 s Scheduling System by executing task detection processing from the highest priority level of the ready queue upon activation and upon detection of queued tasks giving the CPU use right to the first task of the proper priority level R20UT3375EJ0100 Rev 1 00 2tENESAS Page 98 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 3 Reference Task ID in the RUNNING State A RUNNING state task is referenced by issuing the following service call from the processing program get_tid iget_tid These service calls store the ID of a task in the RUNNING state in the area specified by parameter p_tskid The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System informati
155. efault Yes It updates the file when the cfg file is changed dc POW 9 Select from the drop down list change Yes It Generates a system information header file updates the and displays it on the project tree file when the If the system configuration file is changed cfg file is when there is already a system information changed header file then the system information i dc header file is updated Generate a file Yes lt does Does not update the system information not update f f header file when the system configuration the file when ae Restriction the cfg file file is changed is i An error occurs during build if this item is selected when the system information changed i header file does not exist ndc No It does Does not generate a system information i header file and does not display it on the not register s the file to the Project tree If this item is selected when there is already project i ndc a system information header file then the file itself is not deleted Specify the folder for outputting the system information header file for C language If a relative path is specified the reference point of the path is the project folder If an absolute path is specified the reference point of the path is the project folder unless the drives are different The following macro name is available as an embedded macro BuildModeName Replaces with the build mode name If this field is lef
156. en V or help is specified 14 2 2 Activating from CS This is started when the CS performs a build in accordance with the setting on the Property panel on the System Configuration File Related Information tab R20UT3375EJ0100 Rev 1 00 2tENESAS Page 281 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 14 CONFIGURATOR CF78V4 14 2 3 Command file The CF78V4 performs command file support from the objectives that eliminate specified probable activation option character count restrictions in the command lines Description formats of the command file are described below 1 Comment lines Lines that start with are treated as comment lines 2 Dilimiting activation options Delimit activation options using a space code tab code or a linefeed code Note For activation options consist of the xxx part and parameter part like iA lt SIT file gt dcA lt C header file gt and daA lt ASM header file gt delimit the xxx part and parameter part using a space code tab code or a linefeed code When specifying a folder name that includes a space code in the parameter part enclose the parameter part using double quotation marks as shown in Figure 14 1 3 Maximum number of characters Up to 50 lines and up to 4 096 characters per line can be coded in a command file The following shows an example of activation option coding whereby system configuration file CF_file cfg is loaded from the current folder system information t
157. ent exinf into stack PUSH AX Stores the lower 2 bytes of argument exinf into stack RSet tore ean eee Main processing BR _ext_tsk Terminate invoking task R20UT3375EJ0100 Rev 1 00 tENESAS Page 30 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 2 6 Internal processing of task In the RI78V4 original dispatch processing task scheduling is executed during task switching Therefore note the following points when coding tasks Coding method Code tasks using C or assembly language in the format shown in 3 2 5 Basic form of tasks Stack switching In the RI78V4 switching to the stack for the switching destination task task stack is executed during task switching The user is therefore not required to code processing related to stack switching in tasks Interrupt status In the RI78V4 the initial interrupt state specified in Task information when a task is switched from the READY state to the RUNNING state To change disable or enable the interrupt status in the task calling of the _ DI or __El function are therefore required Service call issuance Service calls that can be issued in tasks are limited to the service calls that can be issued from tasks Note For details on the valid issuance range of each service call refer to Table 12 8 to Table 12 17 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 31 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 3 Activate Ta
158. er of the task at the head of the wait queue T_MSG __ near pok_msg Start address of the message packet at the head of the message queue T_RMBX packet inc rmbx_wtskid EQU 0x00 ID number of the task at the head of the wait queue rmbx_pk_msg EQU 0x02 Start address of the message packet at the head of the message queu The following shows details on mailbox state packet T_RMBX wtskid rmbx_wtskid Stores information whether a task is queued to the wait queue TSK_NONE No applicable task Value ID number of the task at the head of the wait queue pk_msg rmbx_pk_msg Stores information whether a message is queued to the message queue NULL No applicable message Value Start address of the message packet at the head of the message queue R20UT3375EJ0100 Rev 1 00 2tENESAS Page 157 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 7 Fixed sized memory pool state packet The following shows fixed sized memory pool state packet T_RMPF used when issuing ref_mpf Definition of fixed sized memory pool state packet T_RMPF is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rmpf ID wtskid ID number of the task at the head of the wait queue UINT fblkcent Number of free memory blocks T_RMPF packet inc rmpf
159. errupt depending on whether the interrupt handler is allocated to the near area or to the far area The following shows the basic form of coding interrupt handlers in assembly language When the interrupt handler is allocated to the near area Saves AX register and stores the vector table address when an interrupt occurs calls processing to switch to the system stack function name _kernel_int_entry and then call end processing at the end of the interrupt handler function name _kernel_int_exit A near attribute section is specified as an allocated section of the interrupt handler When the interrupt handler is allocated to the near area in assembly language SINCLUDE SINCLUDE PUB _func_int SEC _func_int MOV BR LIC hdr TION har PUSH AX AX _func_inthdr VECTOR 0x002C Switches to system stack Saves registers kernel inc Standard header file definition kernel_id inc System information header file definition text TEXT Interrupt handler Saves AX register 0x002C Stores the vector table address when an interrupt occurs Switchs to the system stack and saves registers Main processing kernel_int_exit Terminate interrupt handler Restores registers Note The TA_ASM attribute and the TA_NEAR attribute are specified in a definition of a interrupt handler in the system configuration file DEF_INH When the interrupt handler is allocat
160. errupt entry processing which corresponds to an interrupt request name automatically Boot Processing A routine dedicated to initialization processing that is extracted from the SYSTEM CONFIGURATION MANAGEMENT FUNCTIONS as a user own coding module to initialize the minimum required hardware for the RI78V4 to perform processing It is called from Interrupt Entry Processing that is assigned to the vector table address to which the CPU forcibly passes the control when a reset interrupt occurs Note For details about the boot processing refer to 10 2 Boot Processing Initialization Routine A routine dedicated to initialization processing that is extracted from the SYSTEM CONFIGURATION MANAGEMENT FUNCTIONS as a user own coding module to initialize the hardware dependent on the user execution environment such as the peripheral controller and is called from the Kernel Initialization Module Note For details about the initialization routine refer to 10 3 Initialization Routine Idle Routine A routine dedicated to idle processing that is extracted from the SCHEDULER as a user own coding module to utilize the standby function provided by the CPU to achieve the low power consumption system and is called from the scheduler when there no longer remains a task subject to scheduling by the RI78V4 task in the RUNNING or READY state in the system Note For details about the idle routine refer to 11 7 Idle Routine R20UT
161. ervice call from a processing program 10 3 3 Basic form of initialization routine Write initialization routines using void type functions that do not have arguments function init_handler The following shows the basic form of initialization routine C Language include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void init_handler void PO etd eth brite amp Sia a ea Main processing return Terminate initialization routine Assembly Language SINCLUDE kernel inc Standard header file definition S INCLUDE kernel_id inc System information header file definition PUBLIC _init_handler SECTION textf TEXTF _init_handler bs sah sabes a Biever Main processing RET Terminate initialization routine R20UT3375EJ0100 Rev 1 00 2tENESAS Page 126 of 309 2015 03 25 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT RI78V4 V2 00 00 FUNCTIONS 10 3 4 Internal processing of initialization routine Moreover the RI78V4 executes original pre processing when passing control to the initialization routine as well as original post processing when regaining control from the initialization routine Therefore note the following points when coding initialization routines Coding method Code initialization routines using C or assembly language in the format shown in 10 3 3 Basi
162. ethod of creating a mailbox is limited to static creation by the Kernel Initialization Module Mailboxes therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static create Static mailbox creation is realized by defining Mailbox information in the system configuration file The RI78V4 executes mailbox creation processing based on data stored in information files using the Kernel Initialization Module and handles the created mailboxes as management targets 5 5 2 Delete mailbox In the RI78V4 mailboxes created statically by the Kernel Initialization Module cannot be deleted dynamically using a method such as issuing a service call from a processing program R20UT3375EJ0100 Rev 1 00 2tENESAS Page 75 of 309 2015 03 25 RI78V4 V2 00 00 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION FUNCTIONS 5 5 3 Message The information exchanged among processing programs via the mailbox is called messages Messages can be transmitted to any processing program via the mailbox but it should be noted that in the case of the synchronization and communication functions of the RI78V4 only the start address of the message is handed over to the receiving processing program but the message contents are not copied to a separate area R20UT3375EJ0100 Rev 1 00 Securement of memory area In the case of the RI78V4 it is recommended to use the memory area secured by issuing service calls such
163. evant data queue upon the issuance of a rcv_dtq or trev_dtq A task enters this state if cannot receive a message from the Receiving waiting state for a mailbox relevant mailbox upon the issuance of a rcv_mbx or trev_mbx A task enters this state if it cannot acquire a fxed sized mem Waiting state for a fixed sized memory block ory block from the relevant memory pool upon the issuance of a get_mpf or tget_mpf SUSPENDED state State in which processing execution has been suspended forcibly Resumption of processing from the SUSPENDED state starts from the point where the processing execution was suspended The value of information required for resumption such as task context immediately before suspension is therefore restored WAITING SUSPENDED state State in which the WAITING and SUSPENDED states are combined R20UT3375EJ0100 Rev 1 00 stENESAS Page 27 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS A task enters the SUSPENDED state when the WAITING state is cancelled or enters the WAITING state when the SUSPENDED state is cancelled R20UT3375EJ0100 Rev 1 00 2tENESAS Page 28 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 2 2 Task priority A priority level that determines the order in which that task will be processed in relation to the other tasks is assigned to each task As a result in the RI78V4 the task that has the highest priority level
164. f interrupts used by stack in interrupts of level x Size used by user in interrupts allsvc 18 Expression 8 Total size used by system calls used in interrupt allsvc For service call arguments For internal processing by program issued the service call For system stack internal processing Specify the system stack size in the system configuration file Note however that the size that is actually secured is the value specified in the configurator 2 bytes Consequently the value that is actually specified in the system configuration file is the sys_stk value calculated in expression 1 minus 2 bytes We recommend specifying a system stack size higher than the estimate in order to reduce the danger of a stack overflow The example is shown below Conditions Execute a pol_flg service call from task task1 Execute a snd_mbx service call from task task2 Interrupt intO is a level O interrupt process not managed by the OS The stack is not used in the interrupt Interrupt int2 is a level 2 OS interrupt handler Execute the snd_mbx service call and use 12 bytes of stack in the interrupt Interrupt int3A is a level 3 OS interrupt handler Execute the pol_flg service call and use 16 bytes of stack in the interrupt Interrupt int3B is a level 3 OS interrupt handler Execute Timer_Handler the stack is not used in the interrupt Idle idl does not use the stack The initialization routine ini uses 24 bytes o
165. f stack in the routine R20UT3375EJ0100 Rev 1 00 7tENESAS Page 275 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE Expression tsksvc ll MAX size of system stack used by pol_flg size of system stack used by snd_mbx MAX 16 8 16 bytes int0 0 0 0 byte inti undefined 0 byte int2 12 0 6 4 18 40 bytes int3 MAX int3A int3B MAX 56 32 56 bytes int3A 16 0 6 16 18 56 bytes int3B 0 0 0 14 18 32 bytes tsksvc intO inti int2 int3 16 0 0 40 56 112 bytes sys_stkA ll Note This is the max in sys_stkA B C so after this size or greater is secured sys_stkB Stack size used by user in idle routine 0 byte sys_stkC Stack size used by user in initialization routine 20 bytes sys stk MAX sys_stkA sys_stkB sys _stkC 2 MAX 112 0 20 112 2 114 bytes The system stack size will be the 112 bytes of sys_stkA The size specified in the system configuration file will be 112 bytes Note Below is shown the stack size used in service calls functions used in the example For Service Call For Internal Processing For System Stack by Program Issued the Arguments Internal Processing Service Call pol_flg 0 6 16 twai_flg 4 6 16 snd_mbx 0 6 4 Timer_Handler function 0 14 13 5 2 Stack size of the task The formula for calculating the stack size of the task is shown below Expression 1 N
166. fied by parameter p_tskid if no tasks that have entered the RUNNING state exist all tasks in the IDLE state Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 245 of 309 2015 03 25 RI78V4 V2 00 00 loc_cpu illoc_cpu Outline Lock the CPU C format ER loc_cpu void ER iloc_cpu void Assembly format CALL tl Log cpu CALL _iloc_ cpu Parameter s None Explanation These service calls change the system status type to the CPU locked state As a result maskable interrupt acknowledgment processing is prohibited during the interval from this service call is issued until unl_cpu or iunl_cpu is issued and service call issuance is also restricted If a maskable interrupt is created during the interval from this service call is issued until unl_cpu or iunl_cpu is issued the RI78V4 delays transition to the relevant interrupt processing interrupt handler until either unl_cpu or iunl_cpu is issued The service calls that can be issued in the CPU locked state are limited to the one listed below Service Call Function loc_cpu iloc_cpu Lock the CPU unl_cpu iunl_cpu Unlock the CPU sns_ctx Reference contexts sns_loc Reference CPU state sns_dsp Reference dispatching state sns_dpn Reference dispatch pending state Note 1 The CPU locked state changed by issuing
167. find the one that uses the most stack Pattern A size used by user for function A service call argument size twai_flg 6 20 12 4 6 420 42 bytes Pattern B size used by user for function B service call argument size snd_mbx 6 20 20 0 6 20 26 bytes Compare pattern B with pattern A The pattern that uses the most stack is pattern A at 42 bytes The size specified in the system configuration file will be the above minus 6 bytes which equals 36 bytes R20UT3375EJ0100 Rev 1 00 tENESAS Page 277 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 6 Description Examples The following describes an example for coding the system configuration file Figure 13 2 Example of System Configuration File System Information description SYS_STK 256 MAX PRI 15 Static API Information description CRE_TSK ID_tsk TA_HLNG TA_ACT TA_DISINT Oxa func_task 1 256 NULL CRE_TSK ID_tskA TA_HLNG TA_ACT 0x14 func_taskA 2 256 NULL CRE_TSK ID_tskB TA_ASM TA_ENAINT Oxle func_taskB 3 512 NULL CRE_SEM ID_semA TA_TFIFO 0 127 CRE_SE ID_semB TA_TFIFO 127 127 CRE_FLG ID_flgA TA_TFIFO TA_WSGL TA_CLR 0 CRE_FLG ID_flgB TA_TFIFO TA_WSGL 0 CRE_DTQ ID_DTQ1 TA_TFIFO 20 kernel_work1l NULL
168. fining Cyclic handler information in the system configuration file The RI78V4 executes cyclic handler creation processing based on data stored in information files using the Kernel Initialization Module and handles the created cyclic handlers as management targets 7 5 2 Delete cyclic handler In the RI78V4 cyclic handlers created statically by the Kernel Initialization Module cannot be deleted dynamically using a method such as issuing a service call from a processing program 7 5 3 Basic form of cyclic handlers Write cyclic handlers using void type functions that do not have arguments function any The following shows the basic form of cyclic handlers C Language include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_cychdr void LP EE E amp om Zf Main processing return Terminate cyclic handler Assembly Language SINCLUDE kernel inc Standard header file definition SINCLUDE kernel_id inc System information header file definition PUBLIC _func_cychdr SECTION text TEXT _func_cychar Po Seth aati aaa eee Main Processing RET Terminate cyclic handler 7 5 4 Internal processing of cyclic handler R20UT3375EJ0100 Rev 1 00 2tENESAS Page 91 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS The RI78V4 handles the cyclic
169. g is issued during the interval from when this service call is issued until ena_dsp is issued the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until ena_dsp is issued upon which the actual dispatch processing is performed in batch Note 1 This service call does not perform queuing of disable requests If the system is in the dispatching disabled state therefore no processing is performed but it is not handled as an error Note 2 The dispatching disabled state changed by issuing this service call must be cancelled before the task that issued this service call moves to the DORMANT state Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 249 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Enable dispatching C format ER ena_dsp void Assembly format CALL _ena_dsp Parameter s None Explanation This service call changes the system status to the dispatching enabled state As a result dispatch processing task scheduling that has been disabled by issuing dis_dsp is enabled If a service call chg_pri sig_sem etc accompanying dispatch processing is issued during the interval from when dis_dsp is issued until this service call is issued the RI78V4 executes only processing such as queue manipulation cou
170. g of stack pointer SP is not executed at the point when control is passed to boot processing To use a boot processing dedicated stack setting of stack pointer SP must therefore be coded at the beginning of the boot processing Interrupt status The Kernel Initialization Module is not executed at the point when control is passed to boot processing The system may therefore hang up when an interrupt is created before the processing is completed To avoid this explicitly prohibit acknowledgment of maskable interrupts by manipulating interrupt enable flag IE of program status word PSW during boot processing Register bank setting The RI78V4 prohibits switching of a register bank that was set before __urx_start is called in boot processing to another register bank except for the case when interrupt servicing not managed by the RI78V4 Service call issuance The RI78V4 prohibits issuance of service calls in boot processing The following lists processing that should be executed in boot processing Setting of stack pointer SP Setting of interrupt enable flag IE Initialization of internal units and peripheral controllers Initialization of RAM area initialization of memory area without initial value copying of initialization data Passing of control to Kernel Initialization Module function name _urx_start Note Setting of stack pointer SP is required only when a stack dedicated to boot processing is used in boot processing
171. ge 17 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 2 5 8 kernel_data section The following shows an expression required for estimating the kernel_data section size unit bytes The expression varies depending on whether or not Semaphore information is defined in the system configuration file When semaphore information is defined data align2 maxtpri 1 align2 tsknum 24 semnum 2 1 align2 flgnum 3 align2 dtqnum 4 1 mbxnum 8 align2 primbx mpfnum 4 cycnum 8 20 When semaphore information is not defined data align2 maxtpri 1 tsknum 24 align2 flgnum 3 align2 dtqnum 4 1 mbxnum 8 align2 primbx mpfnum 4 cycnum 8 20 maxtpri Priority range specified in Task priority information tsknum Total amount of Task information semnum Total amount of Semaphore information filgnum Total amount of Eventflag information dtqnum Total amount of Data queue information mbxnum Total amount of Mailbox information primbx Total amount of Mailbox information for which the priority is specified for the attribute message queuing method mpfnum Total amount of Fixed sized memory pool information cycnum Total amount of Cyclic handler information 2 5 9 kernel_data_init section The size of the kernel_data_init section is approximately 2 bytes 2 5 10 kernel_work0O kernel_work1 ker
172. handler as a non task Moreover the RI78V4 executes original pre processing when passing control to the cyclic handler as well as original post processing when regaining control from the cyclic handler Therefore note the following points when coding cyclic handlers Coding method Code cyclic handlers using C or assembly language in the format shown in 7 5 3 Basic form of cyclic handlers Stack switching The RI78V4 executes processing to switch to the system stack when passing control to the cyclic handler and processing to switch to the stack for the switch destination processing program system stack or task stack when regaining control from the cyclic handler The user is therefore not required to code processing related to stack switching in cyclic handlers Interrupt status Maskable interrupt acknowledgement is prohibited in the RI78V4 when control is passed to the cyclic handler To change enable the interrupt status in the cyclic handler calling of the __ El function are therefore required Service call issuance The RI78V4 handles the cyclic handler as a non task Service calls that can be issued in cyclic handlers are limited to the service calls that can be issued from non tasks Note 1 For details on the valid issuance range of each service call refer to Table 12 8 to Table 12 17 Note 2 If a service call ichg_pri isig sem etc accompanying dispatch processing task scheduling processing is issued in
173. he RUNNING state to the WAITING state waiting state for a fixed sized memory block The waiting state for a fixed sized memory block is cancelled in the following cases and then moved to the READY state Waiting State for a Fixed sized memory Block Cancel Operation Return Value A memory block was returned to the target fixed sized memory pool as a result of issuing E OK rel_mpf Forced release from waiting accept rel_wai while waiting E_RLWAI Forced release from waiting accept irel_wai while waiting E_RLWAI Polling failure or timeout E_TMOUT The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID mpfid ID_mpfA Declares and initializes variable VP p_blk Declares variable TMO tmout 3600 Declares and initializes variable TP Fats ce anaana a Acquire fixed sized memory block with timeout ercd tget_mpf mpfid amp p_blk tmout if ercd E_OK PPO Sch E E eA Normal termination processing Release fixed sized memory block rel_mpf mpfid p_ bik else if ercd E_RLWAI DP cee Saeco mf Forced termination processing lse if ercd E_TMOUT JE Bena e aes f Timeout processing Le dasd
174. he data queue area of the target data queue when this service call is issued the service call does not write data but queues the invoking task to the transmission wait queue of the target data queue and moves it from the RUNNING state to the WAITING state with time data transmission wait state The sending WAITING state for a data queue is cancelled in the following cases and then moved to the READY state Sending WAITING State for a Data Queue Cancel Operation Return Value An available space was secured in the data queue area of the target data queue as a result of E OK issuing rcv_dtq An available space was secured in the data queue area of the target data queue as a result of E OK issuing prcv_dtq R20UT3375EJ0100 Rev 1 00 tENESAS Page 210 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Sending WAITING State for a Data Queue Cancel Operation Return Value An available space was secured in the data queue area of the target data queue as a result of E OK issuing trcv_diq Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI Polling failure or timeout E TMOUT If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from t
175. he following shows data queue state packet T_RDTQ used when issuing ref _dtq or iref_dtq Definition of data queue state packet T_RDTQ is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rdtq ID stskid Existence of tasks waiting for data transmission ID rtskid Existence of tasks waiting for data reception UINT sdtqcnt number of data elements in the data queue T_RDTOQ packet inc rdtq_stskid EQU 0x00 Existence of tasks waiting for data transmission rdtq_rtskid EQU 0x01 Existence of tasks waiting for data reception rdtq_sdtqent EQU 0x02 number of data elements in the data queue The following shows details on data queue state packet T_RDTQ stskid Stores whether a task is queued to the transmission wait queue of the data queue TSK_NONE No applicable task Value ID number of the task at the head of the wait queue rtskid Stores whether a task is queued to the reception wait queue of the data queue TSK_NONE No applicable task Value ID number of the task at the head of the wait queue sdtqent Stores the number of data elements in data queue R20UT3375EJ0100 Rev 1 00 2tENESAS Page 155 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 5 Message packet The following shows message packet T_MSG and
176. he information files output from the CF78V4 are explained below System information table file An information file that stores data required for the operation of the RI78V4 System information header file An information file that stores matching between ID numbers and object names e g task and semaphore names described in the system configuration file The CF78V4 can output two types of system information header files for C and assembly languages Interrupt information definition file An information file that stores related interrupt handler described in the system configuration file R20UT3375EJ0100 Rev 1 00 2tENESAS Page 279 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 14 CONFIGURATOR CF78V4 14 2 Activation Method 14 2 1 Activating from command line The following is how to activate the CF78V4 from the command line Note that in the examples below C gt indicates the command prompt A indicates pressing of the space key and lt Enter gt indicates pressing of the enter key The activation options enclosed in can be omitted C gt cf 78v4 exe A command file A cpuA lt name gt A devpath path A i A lt SIT file gt ni A dce A lt C header file gt ndc A da A lt ASM header file gt nda A v A help A lt CF file gt lt Enter gt The details of each activation option are explained below command file Specifies the command file name to be input If omit
177. he reception wait queue and moves from the WAITING state data reception wait state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Note 1 Data is written to the data queue area of the target data queue in the order of the data transmission request Note 2 Invoking tasks are queued to the transmission wait queue of the target data queue in the order defined during configuration FIFO order Note 3 TMO_FEVR is specified for wait time tmout processing equivalent to snd_dtq will be executed When TMO_POL is specified processing equivalent to psnd_dtq ipsnd_dtq will be executed Return value Macro Value Description E OK 0 Normal completion Forced release from the WAITING state E RLWAI 49 Accept rel_wai irel_wai while waiting Timeout E TMOUT 50 Polling failure or timeout R20UT3375EJ0100 Rev 1 00 tENESAS Page 211 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS fsnd_dtq ifsnd_dtq Outline Forced send to data queue C format ER fsnd_dtq ID dtqid VP_INT data Assembly format OVW DE LOWW _datat 0x00002 OVW BC LOWW _data OV A dtqid CALL _ fsnd_dtq OVW DE LOWW _datat 0x00002 OVW BC LOWW _data OV A dtqid CALL _ifsnd_dtq Parameter s V O Parameter Description l ID dtqid ID number of the data queue to which the data element is sent l VP_INT data
178. here information items to get trace data are to be allocated kernel_system_trace_f section Area where the processing part to get trace data are to be allocated kernel_sbss section SADDR area where the RI78V4 s core processing are to be allocated 6 2 Fixed Sized Memory Pool R20UT3375EJ0100 Rev 1 00 2tENESAS Page 82 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS When a dynamic memory manipulation request is issued from a processing program in the RI78V4 the fixed sized memory pool is provided as a usable memory area Dynamic memory manipulation of the fixed sized memory pool is executed in fixed size memory block units 6 2 1 Create fixed sized memory pool In the RI78V4 the method of creating a fixed sized memory pool is limited to static creation by the Kernel Initialization Module Fixed sized memory pools therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static create Static fixed sized memory pool creation is realized by defining Fixed sized memory pool information in the system configuration file The RI78V4 executes fixed sized memory pool creation processing based on data stored in information files using the Kernel Initialization Module and handles the created fixed sized memory pools as management targets 6 2 2 Delete fixed sized memory pool In the RI78V4 fixed sized memory pools created statically by the
179. his is the version of the RI78 V4 to be used in this project RI78V4 Task Analyzer Explanation of each area 1 Ver The sion Information detailed information on the version of the RI78V4 are displayed Display the version of the RI78V4 to be used Note that the version is set permanently when the project is created and cannot be changed Kerel version Default Using the RI78V4 version How fo Changes not allowed change Display the folder in which the RI78V4 to be used is installed with the absolute path Install folder Default The folder in which the RI78V4 to be used is installed How fo Changes not allowed change Display the memory model set in the project Display the same value as the value of the Memory model type property of the build tool Memory meade Default The memory model selected in the property of the build tool FOW lo Changes not allowed change R20UT3375EJ0100 Rev 1 00 tENESAS Page 293 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Task Analyzer tab Outline This tab shows the detailed information on the using task analyzer in RI78V4 package Display image Property Eg A RI78V4 Property 4 Trace Selection of trace mode Not tracing Selection of trace mode Selects the buffer holding trace and information to acquire by ay ey Hardware trace mode Hold the trace to debugging tool with trace Software tra
180. hows the eventtflag information format CRE_FLG flgid flgatr iflgptn The items constituting the eventflag information are as follows 1 Eventflag name figid Specifies the eventflag name An object name can be specified for flgid Note The CF78V4 outputs to the system information header file the correspondence between the eventtlag names and IDs in the following format Consequently eventflag names can be used in the place of IDs by including the relevant system information header file using the processing program Output format to system information header file for C define flgid ID Output format to system information header file for assembly language flgid EQU ID 2 Attribute queuing method queuing count bit pattern clear flgatr Specifies the attributes queuing method queuing count clear of the eventflag The keywords that can be specified for flgatr are TA_TFIFO TA_WSGL and TA_CLR Queuing method TA_TFIFO If the bit pattern of the eventflag does not satisfy the required condition when wai_flg or twai_flg is issued the task is queued to the eventflag wait queue Queuing count TA_WSGL Only one task is allowed to be in the waiting state for the eventflag Bit pattern clear TA_CLR Bit pattern is cleared when a task is released from the waiting state for that eventflag Note If specification of TA_CLR is omitted not clear bit pa
181. ication Application Note that this menu is disabled when multiple files are selected Open Folder with Explorer Opens the folder that contains the selected file with Explorer Add Shows the cascading menu to add files and category nodes to the project Opens the Add Existing File dialog box to add the selected file to the Add File project R20UT3375EJ0100 Rev 1 00 tENESAS Page 288 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Opens the Add File dialog box to create a file with the selected file type and AOE MENE IS add to the project Adds a new category node at the same level as the selected file You can rename the category This menu is disabled while the build tool is running and if categories are nested 20 levels Add New Category Removes the selected file from the project Remove from Project The file itself is not deleted from the file system Note that this menu is disabled when the build tool is in operation Copies the selected file to the clipboard Copy When the file name is in editing the characters of the selection are copied to the clipboard Paste This menu is always disabled You can rename the selected file Rename rae The actual file is also renamed Property Displays the selected file s property on the Property panel R20UT3375EJ0100 Rev 1 00 tENESAS Page 289 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WIN
182. iles Renesas Electronics CS CC Device RL78 Devicefile A iAsit_file asm A dc A C_header h A da A ASM_header inc A CF_file cfg lt Enter gt 3 After loading system configuration file CF_file cfg from the current folder system information table file sit asm the system information header file kernel_id h for C and system information header file kernel_id inc for assembly language are output to the current folder C gt cf78v4 exe A CF_file cfg lt Enter gt 4 After loading system configuration file CF_file cfg from a folder in C tmp system information table file sit_file asm the system information header file C_header h for C is output to a folder in C tmp C gt cf 78v4 exe A i A C tmp sit_file asm A dc A C tmp C_header h A nda A C tmp CF_file cfg lt Enter gt 5 After loading system configuration file CF_file cfg from a folder in C tmp the system information table file sit_file asm is output to a folder in C Program Files tmp C gt cf 78v4 exeA i A C Program Files tmp sit_file asm A ndc A nda A C tmp CF_file cfg lt Enter gt 6 CF78V4 version information is output to the standard output C gt cf78v4 exe A V lt Enter gt 7 Information related to the CF78V4 activation option type usage or the like is output to the standard output C gt cf78v4 exe A help lt Enter gt R20UT3375EJ0100 Rev 1 00 2tENESA
183. in of Service Call ref_ver Reference version information Task Non task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 255 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE CHAPTER 13 SYSTEM CONFIGURATION FILE This chapter explains the coding method of the system configuration file required to output information files system information table file system information header file and interrupt information definition file that contain data to be provided for the RI78V4 13 1 Notation Method The following shows the notation method of system configuration files Character code Create the system configuration file using ASCII code The CF78V4 distinguishes lower cases a to z and upper cases A to Z Note For japanese language coding Shit JIS codes can be used only for comments Comment In a system configuration file parts between and and parts from two successive slashes to the line end are regarded as comments Numeric In a system configuration file words starting with a numeric value 0 to 9 are regarded as numeric values The CF78V4 distinguishes numeric values as follows Octal Words starting with 0 Decimal Words starting with a value other than 0 Hexadecimal Words starting with Ox or 0X Note Elements of a word are limited to numeric values 0 to 9 Object name In a system configuration file words starting with a letter of a to z A to Z or underscore _ within 24 character
184. indnum 4 16 tsknum Total amount of Task information semnum Total amount of Semaphore information filgnum Total amount of Eventflag information dtqnum Total amount of Data queue information mpfnum Total amount of Fixed sized memory pool information kindnum Total number of types defined in the system configuration file among five types of information related to OS resources Semaphore information Eventflag information Data queue information Mailbox information Fixed sized memory pool information and Cyclic handler information 2 5 6 kernel_const_f section The following shows an expression required for estimating the kernel_const_f section size unit bytes When the trace mode is Not tracing const_f 0 When the trace mode is Takes in trace chart by hardware trace mode const_f 0 When the trace mode is Takes in trace chart by software trace mode const_f 0 When the trace mode is Takes in long statistics by software trace mode const_f 63 2 5 7 kernel_stack section The following shows an expression required for estimating the kernel_stack section size unit bytes tsknum stack stksz k 20 sys_stksz 2 k 1 tsknum Total amount of Task information StkSZ x Stack size specified in Task information sys_stksz Stack size specified in System stack information When multiple interrupt occurs adds 18 bytes every one time R20UT3375EJ0100 Rev 1 00 tENESAS Pa
185. ing else if ercd E_RLWAI YOR Be case wih eave he ae Forced termination processing R20UT3375EJ0100 Rev 1 00 tENESAS Page 57 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS Note 1 In the RI78V4 the number of tasks that can be queued to the eventflag wait queue is one If this service call is issued for the eventflag to which a task is queued therefore E_ILUSE is returned regardless of whether or not the required condition is immediately satisfied Note 2 The RI78V4 performs bit pattern clear processing 0x0 setting when the required condition of the target eventflag TA_CLR attribute is satisfied R20UT3375EJ0100 Rev 1 00 2tENESAS Page 58 of 309 2015 03 25 RI78V4 V2 00 00 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION FUNCTIONS pol_flg This service call checks whether the bit pattern specified by parameter waipin and the bit pattern that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid If the bit pattern that satisfies the required condition has been set to the target eventflag the bit pattern of the target eventtlag is stored in the area specified by parameter p_figptn If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued E_ TMOUT is returned The following shows the specification format of required condition wfm
186. is issued R20UT3375EJ0100 Rev 1 00 2tENESAS Page 101 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 5 Unlock the CPU The CPU locked state is cancelled by issuing the following service call from the processing program unl_cpu iunl_cpu These service calls change the system status to the CPU unlocked state As a result acknowledge processing of maskable interrupts prohibited through issuance of either loc_cpu or iloc_cpu is enabled and the restriction on service call issuance is released If a maskable interrupt is created during the interval from when either loc_cpu or iloc_cpu is issued until this service call is issued the RI78V4 delays transition to the relevant interrupt processing interrupt handler until this service call is issued The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf PE aE E loe cpu 3 Lock the CPU DP sips ace ennaa sf CPU locked state unl_cpu Unlock the CPU a ee Note 1 This service call does not perform queuing of cancellation requests If the system is in the CPU unlocked state therefore no processing is performed but it is not handled as an error Note 2 The RI78V4 implements enabling of maskable interrupt acknowledgment bu manipulating th
187. ist when this service call is issued memory block acquisition processing is not performed but the invoking task is queued to the target fixed sized memory pool wait queue in the order of memory block acquisition request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for a fixed sized memory block The waiting state for a fixed sized memory block is cancelled in the following cases and then moved to the READY state R20UT3375EJ0100 Rev 1 00 7tENESAS Page 232 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Waiting State for a Fixed sized Memory Block Cancel Operation Return Value A memory block was returned to the target fixed sized memory pool as a result of issuing E OK rel_mpf Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Polling failure or timeout E TMOUT Note When TMO_FEVR is specified for wait time tmout processing equivalent to get_mpf will be executed When TMO_POL is specified processing equivalent to pget_mpf will be executed Return value Macro Value Description E OK 0 Normal completion E_ RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting E TMOUT 50 Polling failure or timeout R20UT3375EJ0100 Rev 1 00 tENESAS Page 2
188. itly prohibiting dispatch processing task scheduling processing The following shows a processing flow when using the scheduling suppressing function Figure 11 4 Scheduling Suppression Function Task Task Priority High Priority Low Acquire semaphore resource Disable dispatching Release semaphore resource Suppressed period Enable dispatching R20UT3375EJ0100 Rev 1 00 2tENESAS Page 135 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 5 1 Disable dispatching A task is moved to the dispatching disabled state by issuing the following service call from the processing program dis _dsp This service call changes the system status to the dispatching disabled state As a result dispatch processing task scheduling is disabled from when this service call is issued until ena_dsp is issued If a service call chg_pri sig_sem etc accompanying dispatch processing is issued during the interval from when this service call is issued until ena_dsp is issued the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until ena_dsp is issued upon which the actual dispatch processing is performed in batch The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void
189. keup of tasks timeout during the WAITING state and cyclic handler activation and is called from the interrupt handler that is activated upon output of a timer interrupt Note The timer handler is part of the functions provided by the RI78V4 The user therefore need not code the processing contents of the timer handler 7 2 1 Define timer handler Timer handler registration is registerd by CF78V4 based on the clock timer interrupt source in system configuration file So it is not necessory to discribe the timer handler by user R20UT3375EJ0100 Rev 1 00 2tENESAS Page 89 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS 7 3 Delayed Wakeup Delayed wakeup the operation that makes the invoking task transit from the RUNNING state to the WAITING state during the interval until a given length of time has elapsed and makes that task move from the WAITING state to the READY state once the given length of time has elapsed Delayed wakeup is implemented by issuing the following service call from the processing program Table 7 1 Delayed Wakeup Service Call Function dly_tsk Delay task 7 4 Timeout Timeout is the operation that makes the target task move from the RUNNING state to the WAITING state during the interval until a given length of time has elapsed if the required condition issued from a task is not immediately satisfied and makes that task move from the WAITING state to the READY state
190. lt of issuing iwup_tsk E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable EP Bie ein ates ercd slp_tsk Put task to sleep waiting forever if ercd E_OK PR eb EE EE E tf Normal termination processing else if ercd E_RLWAI OE ED EE E S Kj Forced termination processing PE ae a eleva KY R20UT3375EJ0100 Rev 1 00 tENESAS Page 39 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS tslp_tsk This service call moves an invoking task from the RUNNING state to the WAITING state sleeping state As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject If a wakeup request has been queued to the target task the wakeup request counter is not set to 0x0 when this service call is issued this service call does not move the state but decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter The sleeping state is cancelled in the following cases and then moved to the READY state
191. m Refer to http www renesas com for the latest and detailed information Renesas Electronics America Inc 2801 Scott Boulevard Santa Clara CA 95050 2549 U S A Tel 1 408 588 6000 Fax 1 408 588 6130 Renesas Electronics Canada Limited 9251 Yonge Street Suite 8309 Richmond Hill Ontario Canada L4C 9T3 Tel 1 905 237 2004 Renesas Electronics Europe Limited Dukes Meadow Millboard Road Bourne End Buckinghamshire SL8 5FH U K Tel 44 1628 585 100 Fax 44 1628 585 900 Renesas Electronics Europe GmbH Arcadiastrasse 10 40472 Dusseldorf Germany Tel 49 211 6503 0 Fax 49 211 6503 1327 Renesas Electronics China Co Ltd Room 1709 Quantum Plaza No 27 ZhiChunLu Haidian District Beijing 100191 P R China Tel 86 10 8235 1155 Fax 86 10 8235 7679 Renesas Electronics Shanghai Co Ltd Unit 301 Tower A Central Towers 555 Langao Road Putuo District Shanghai P R China 200333 Tel 86 21 2226 0888 Fax 86 21 2226 0999 Renesas Electronics Hong Kong Limited Unit 1601 1611 16 F Tower 2 Grand Century Place 193 Prince Edward Road West Mongkok Kowloon Hong Kong Tel 852 2265 6688 Fax 852 2886 9022 Renesas Electronics Taiwan Co Ltd 13F No 363 Fu Shing North Road Taipei 10543 Taiwan Tel 886 2 8175 9600 Fax 886 2 8175 9670 Renesas Electronics Singapore Pte Ltd 80 Bendemeer Road Unit 06 02 Hyflux Innovation Centre Singapore 339949 Tel 65 6213 0200 Fax 65 6213 0300 Renes
192. m Stores the time unit tick left before the next activation The contents of this member become an undefined value if the target cyclic handler is in the non operational state STP state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 159 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 5 9 Version information packet The following shows version information packet T_RVER used when issuing ref_ver Definition of version information packet T_RVER is performed by header file lt ri_root gt include os packet h packet inc which is called from standard header file lt ri_root gt include kernel h kernel inc packet h typedef struct t_rver UH maker Kernel maker s code UH prid Identification number of the kernel UH spver Version number of the ITRON Specification UH prver Version number of the kernel UH prno 4 Management information of the kernel product T_RVER packet inc verinf_maker EQU 0x00 Kernel maker s code verinf_prid EQU 0x02 Identification number of the kernel verinf_spver EQU 0x04 Version number of the ITRON Specification verinf_prver EQU 0x06 Version number of the kernel verinf_prno EQU 0x08 Management information of the kernel product The following shows details on version information packet T_RVER maker verinf_maker Stores the kernel maker s code 0x011b Renesas Electronics Co Ltd prid verinf_prid Stores the iden
193. m information table file and system information header files Figure 2 3 Property Panel System Configuration File Related Information Tab ef sys cig Property 4 System Information Table File EE Yes tt updates the file when the cfg file is changed i Output folder BuildModeName File name sit asm System Information Header File for C Language Generate a file Yes It updates the file when the cfg file is changed dc Output folder BuildModeName File name kemel_id h System Information Header File for Assembly Language Generate a file Yes lt updates the file when the cfg file is changed da Output folder BuildModeName File name kemel_id inc Interrupt Information Definition File Output folder BuildModeName File name kemel_int_define c Generate a file Select whether to make a System Information Table File which is output from a system configuration file This file includes information of system initialization System Configuration File Related Information File Information 5 Specify the output of a load module file Set the output of a load module file as the product of the build Note See CS Integrated Development Environment User s Manual RL78 Build for details about specifying the output of a load module file R20UT3375EJ0100 Rev 1 00 CENESAS Page 22 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 6 Set trace information Set the detailed information
194. m information header file for assembly language inc System information header file for C language h This node and files displayed under this node cannot be deleted directly This node and files displayed under this node will no longer appear if you remove the system configuration file from the project The following information files appear directly below the node Realtime OS related files referred to as Realtime OS Trace information file trcinf c related files node This node and files displayed under this node cannot be deleted Context menu 1 When the Realtime OS node or Realtime OS generated files node is selected Property Displays the selected node s property on the Property panel 2 When the system configuration file or an information file is selected Assembles the selected assembler source file Note that this menu is only displayed when a system information table file is selected Note that this menu is disabled when the build tool is in operation Assemble Opens the selected file with the application corresponds to the file Open extension Note that this menu is disabled when multiple files are selected Opens the selected file with the Editor panel Cpe wahaniemell Enos Note that this menu is disabled when multiple files are selected Opens the Open with Program dialog box to open the selected file with the Open with selected designated appl
195. main types System Information This information consists of fundamental data required for the RI78V4 operation System stack information Task priority information Clock timer interrupt source Static API Information This information consists of data for management objects required to implement the functions probided by the RI78V4 Task information Semaphore information Eventflag information Data queue information Mailbox information Fixed sized memory pool information Cyclic handler information Interrupt handler information 13 2 1 Cautions The following describes a system configuration file description format Figure 13 1 System Configuration File Description Format System Information System stack information etc descriptin LE Sanpaesiean ncn Ap Static API Information Task information etc description JM oe iecdcsdswite laine ay Note Up to 40 000 lines and up to 1 000 characters per line can be written in a system configuration file R20UT3375EJ0100 Rev 1 00 2tENESAS Page 257 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SERVICE CALLS ref_ver Outline Reference version information C format ER ref_ver T_RVER pk_rver Assembly format MOVW AX LOWW _pk_rver CALL _ref_ver Parameter s VO Parameter Description O T_RVER pk_rver Pointer to the packet returning the version informa
196. mprihd The items constituting the mailbox information are as follows 1 Mailbox name mbxid Specifies the mailbox name An object name can be specified for mbxid Note The CF78V4 outputs to the system information header file the correspondence between the mailbox names and IDs in the following format Consequently mailbox names can be used in the place of IDs by including the relevant system information header file using the processing program Output format to system information header file for C define mbxid ID Output format to system information header file for assembly language mbxid EQU ID 2 Attribute queuing method mbxatr Specifies the attributes task queuing method message queuing method of the mailbox The keywords that can be specified for mbxatr are TA_TFIFO TA_MFIFO and TA_MPRI Task queuing method TA_TFIFO If the message could not be received from the mailbox no messages were queued in the wait queue when rcv_mbx or trcv_mbx is issued the task is queued to the mailbox wait queue in the order of message reception request Message queuing method TA_MFIFO If a task is not queued to the mailbox wait queue when snd_mbx is issued the message is queued to the mailbox wait queue in the order of message transmission request TA_MPRI If a task is not queued to the mailbox wait queue when snd_mbx is issued the message is queued to the mailbox wait queue i
197. munication Functions Mailboxes 219 12 12 Memory Pool Management Functions 228 12 13 Time Management Functions 237 12 14 System State Management Functions 242 12 15 System Configuration Management Functions 255 CHAPTER 13 SYSTEM CONFIGURATION FILE 256 13 1 Notation Method 256 13 2 Configuration Information 257 13 2 1 Cautions 257 13 3 System Information 259 13 3 1 System stack information 259 13 3 2 Task priority information 260 13 3 3 Clock timer interrupt source 261 13 4 Static API Information 262 13 4 1 Task information 262 13 4 2 Semaphore information 265 13 4 3 Eventflag information 266 13 4 4 Data queue information 267 13 4 5 Mailbox information 268 13 4 6 Fixed sized memory pool information 269 13 4 7 Cyclic handler information 271 13 4 8 Interrupt handler information 273 13 5 Stack Size Estimation 275 13 5 1 System stack size 275 13 5 2 Stack size of the task 276 13 6 Description Examples 278 CHAPTER 14 CONFIGURATOR CF78V4 279 14 1 Outline 279 14 2 Activation Method 280 14 2 1 Activating from command line 280 14 2 2 Activating from CS 281 14 2 3 Command file 282 14 2 4 Command input examples 283 APPENDIX A WINDOW REFERENCE 284 A 1 Description 284 APPENDIX B CAUTIONS 305 B 1 Resiriction of Compiler Option 305 B 2 Handling Register Bank 305 RI78V4 V2 00 00 CHAP
198. n tab When the interrupt information definition file is selected on the Project Tree panel File Information tab When the trace information file trcinf c is selected on the Project Tree panel File Information tab Note1 See CS Integrated Development Environment User s Manual RL78 Build for details about the File Information tab Category Information tab Build Settings tab and Individual Assemble Options tab Note2 When multiple components are selected on the Project Tree panel only the tab that is common to all the components is displayed If the value of the property is modified that is taken effect to the selected components all of which are common to all Edit menu only available for the Project Tree panel Undo Cancels the previous edit operation of the value of the property While editing the value of the property cuts the selected characters and copies Cut them to the clip board Copy Copies the selected characters of the property to the clip board Paste While editing the value of the property inserts the contents of the clip board Delete While editing the value of the property deletes the selected character string Select All While editing the value of the property selects all the characters of the selected property Context menu R20UT3375EJ0100 Rev 1 00 tENESAS Page 291 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE
199. n header file for assembly language and whether to update the file when the system configuration file is changed Default Yes It updates the file when the cfg file is changed da POW 9 Select from the drop down list change Yes It Generates a system information header file updates the and displays it on the project tree file when the If the system configuration file is changed cfg file is when there is already a system information changed header file then the system information i da header file is updated Generate a file Yesilt goes Does not update the system information not update f f header file when the system configuration the file when ae Restriction the cfg file file is changed is i An error occurs during build if this item is selected when the system information changed i header file does not exist nda No It does Does not generate a system information i header file and does not display it on the not register s the file to the Project tree If this item is selected when there is already project i nda a system information header file then the file itself is not deleted Specify the folder for outputting the system information header file for assembly language If a relative path is specified the reference point of the path is the project folder If an absolute path is specified the reference point of the path is the project folder unless the drives are diffe
200. n list change Generates a new system information table Yes It f i file and displays it on the project tree updates the nae If the system configuration file is changed file when the F d ate when there is already a system information cfg file is changed i table file then the system information table file is updated Generate a file Yestlt does Does not update the system information not update ee table file when the system configuration file the file when Restriction the cfg file iS changed ees An error occurs during build if this item is is i selected when the system information table changed ni file does not exist Does not generate a system information No It does table file and does not display it on the not register project tree the file to the If this item is selected when there is already project ni a system information table file then the file itself is not deleted Specify the folder for outputting the system information table file If a relative path is specified the reference point of the path is the project folder If an absolute path is specified the reference point of the path is the project folder unless the drives are different The following macro name is available as an embedded macro BuildModeName Replaces with the build mode name If this field is left blank macro name BuildModeName will be displayed This property is not displayed when
201. n the order of message priority 3 System reserved area maxmpri System reserved area Values that can be specified for maxmpri are limited to 0 4 System reserved area mprihd System reserved area The keywords that can be specified for mprihd are NULL R20UT3375EJ0100 Rev 1 00 2tENESAS Page 268 of 309 2015 03 25 RI78V 4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 6 Fixed sized memory pool information Define the following items as fixed sized memory pool information 1 Fixed sized memory pool name mpfid 2 Attribute queuing method mpfatr 3 Total number of memory blocks blkcnt 4 Memory block size blksz 5 Section name sec_nam 6 System reserved area mpf The number of fixed sized memory pool information items that can be specified is defined as being within the range of 0 to 127 The following shows the fixed sized memory pool information format CRE_MPF mpfid mpfatr blkcnt blksz sec_nam mpf The items constituting the fixed sized memory pool information are as follows 1 Fixed sized memory pool name mpfid Specifies the fixed sized memory pool name An object name can be specified for mpfid Note The CF78V4 outputs to the system information header file the correspondence between the fixed sized memory pool names and IDs in the following format Consequently fixed sized memory pool names can be used in the place of IDs by includi
202. n two register banks are to be used in the task process then when changing the register banks the general register of the register bank before the change must be retired If it is not retired then the register bank could be corrupted in the task that is switched to Interrupt servicing not managed by an OS When changing a register bank in an interrupt process not matched by the OS restore the register bank number of the interrupt source when the interrupt ends Routines where changing the register bank is disabled Interrupt handler Interrupt handlers inherit the register bank number of the source of the interrupt Cyclic handler Cyclic handlers inherit the register bank number of the source of the timer handler interrupt Idle routine In the idle routine the initial register bank number is set permanently to 0 Initialization routine In the initialization routine the initial register bank number is set permanently to 0 It is overwritten by register bank 0 regardless of the register bank set before OS initialization before the call to the __ urx_start function R20UT3375EJ0100 Rev 1 00 7tENESAS Page 305 of 309 2015 03 25 Revision Record Description Rev Mar 25 2015 aa First Edition issued RI78V4 V2 00 00 User s Manual Coding Publication Date Rev 1 00 Mar 25 2015 Published by Renesas Electronics Corporation tENESAS SALES OFFICES Renesas Electronics Corporation http Avww renesas co
203. nc_inthdr void Note 2 When a interrupt handler is in written in assembly language as shown below the value specified by this item is func_inthdr R20UT3375EJ0100 Rev 1 00 2tENESAS Page 273 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE SINC SINC _func_inthdr JUDE UDE LIC SEC kernel inc kernel_id inc _func_in ION text TI thdr EXT R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 274 of 309 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 5 Stack Size Estimation 13 5 1 System stack size The formula for calculating the system stack size is shown below Expression 1 System stack size sys_stk MAX sys_stkA sys_stkB sys_stkC 2 bytes Expression 2 System stack size use pattern A sys_stkA tsksvc intO int1 int2 int3 Expression 3 System stack size use pattern B sys_stkB Size used by user in idle routine Expression 4 System stack size use pattern C sys_stkC Size used by user in initialization routine Expression 5 Maximum size of system stack used during service call executed by task Maximum size of system stack used during service call executed by task Expression 6 Size of intO int1 Intx Maximum size of interrupts used by stack in interrupts of level x Size used by user in interrupts Expression 7 Size of int2 int2 intx Maximum size o
204. nce cyclic handler state C format ER ref_cyc ID cycid T_RCYC pk_rcyc Assembly format MOVW BC LOWW _pk_rcyc MOV A cycid CALL _ref_cyc Parameter s 0 Parameter Description l ID cycid ID number of the cyclic handler to be referenced O T_RCYC pk_rcyc Pointer to the packet returning the cyclic handler state Explanation Stores cyclic handler state packet such as current status of the cyclic handler specified by parameter cycid in the area specified by parameter pk_rcyc Note For details about the cyclic handler state packet refer to 12 5 8 Cyclic handler state packet Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 241 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 14 System State Management Functions The following lists the service calls provided by the RI78V4 as the system state management functions Table 12 16 System State Management Functions Service Call Function Origin of Service Call rot_rdq Rotate task precedence Task Non task irot_rdq Rotate task precedence Task Non task get_tid Reference task ID in the RUNNING state Task Non task iget_tid Reference task ID in the RUNNING state Task Non task loc_cpu Lock the CPU Task Non task iloc_cpu Lock the CPU Task Non task unl_cpu Unlock the CPU Task
205. nding on whether the TA_PHS attribute is specified for the target cyclic handler during configuration Cyclic handler activation image the TA_PHS attribute is specified The target cyclic handler activation timing is set based on the activation phases initial activation phase cycphs and activation cycle cyctim defined during configuration If the target cyclic handler has already been started however no processing is performed even if this service call is issued but it is not handled as an error The following shows a cyclic handler activation timing image m Start m Start m Start m Start cycphs wv cyctim y cyctim v cyctim v pt t Generation processing completed Start cyclic handler operation Start cyclic handler operation Cyclic handler activation image the TA_PHS attribute is not specified The target cyclic handler activation timing is set based on the activation phase activation cycle cyctim when this service call is issued This setting is performed regardless of the operating status of the target cyclic handler The following shows a cyclic handler activation timing image R20UT3375EJ0100 Rev 1 00 2tENESAS Page 93 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS m Start Start Start cyctim i cyctim f cyctim v cyctim cyctim i cyctim i cyctim cycphs i T T T T A A i Start cyclic handler operation Start cyclic handler o
206. ndles the created ready queues as management targets 11 4 2 Delete ready queue In the RI78V4 ready queues created statically by the Kernel Initialization Module cannot be deleted dynamically using a method such as issuing a service call from a processing program R20UT3375EJ0100 Rev 1 00 2tENESAS Page 130 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 4 3 Rotate task precedence The RI78V4 provides a function to change the queuing order of tasks from the processing program explicitly switching the task execution order The following shows the status transition when the task queuing order is changed Figure 11 2 Rotate Task Precedence Ready queue 1 Invoking task RUNNING state Task A Task B Task C READY state READY state READY state tskpri maxtpri rot_rdq tskpri Ready queue 1 Invoking task RUNNING state tskpri Task B Task C Task A READY state READY state READY state maxtpri R20UT3375EJ0100 Rev 1 00 2tENESAS Page 131 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER A ready queue is rotated by issuing the following service call from the processing program rot_rdq irot_rdq These service calls re queue the first task of the ready queue corresponding to the priority specified by parameter tskpri to the end of the queue to change the task execution order ex
207. nel_id h gt System information header file definition void _ near func_inthdr void PE Sette on ee Main processing return Terminate interrupt handler Note 1 The TA_HLNG attribute and the TA_NEAR attribute are specified in a definition of a interrupt handler in the Note 2 system configuration file DEF_INH The the pragma rtos_interrupt directive is defined in the file kernel_id h CF78V4 outputs automatically Therefore please the file kernel_id h be sure to do include When the interrupt handler is allocated to the near area include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void __far func_inthdr void PR Re e A ee eee A Main processing return Terminate interrupt handler Note 1 The TA_HLNG attribute and the TA_FAR attribute are specified in a definition of a interrupt handler in the system configuration file DEF_INH Note 2 The the pragma rtos_interrupt directive is defined in the file kernel_id h CF78V4 outputs automatically Therefore please the file kernel_id h be sure to do include R20UT3375EJ0100 Rev 1 00 2tENESAS 2015 03 25 Page 113 of 309 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS When coding interrupt handlers in assembly language use void type functions that do not have arguments function any The code of int
208. nel_work2 kernel_work3 section The following shows an expression required for estimating the size of the kernel_workO kernel_work1 kernel_work2 and kernel_work3 section unit bytes mpfnum dtqnum workX 2 blkent X blksz amp dtqent x 4 k 1 k 1 mpfnum Total number of section units for Fixed sized memory pool information blkent Number of fixed sized memory blocks specified in Fixed sized memory pool information blksz x Block size specified in Fixed sized memory pool information dtqnum Total number of section units for Data queue information dtqent g Number of datq queue specified in Data queue information 2 5 11 kernel_data_trace_n section The following shows an expression required for estimating the kernel_data_trace_n section size unit bytes When the trace mode is Not tracing data_trace n 0 When the trace mode is Takes in trace chart by hardware trace mode data_trace_n 2 When the trace mode is Takes in trace chart by software trace mode R20UT3375EJ0100 Rev 1 00 7tENESAS Page 18 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION data_trace_n 8 bufsize bufsize Trace buffer size When the trace mode is Takes in long statistics by software trace mode data_trace_n tsknum 1 20 inhnum 1 8 34 tsknum Total amount of Task information inhnum Total amount of Interrupt handler information 2 5 12 kernel_const_trace_f
209. nformation files system information table file system information header file Interrupt information definition file that contain data to be provided for the RI78V4 Note For details about the system configuration file refer to CHAPTER 13 SYSTEM CONFIGURATION FILE R20UT3375EJ0100 Rev 1 00 2tENESAS Page 13 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 2 SYSTEM CONSTRUCTION 2 4 Coding of User Own Coding Module Code the user own coding modules that are extracted to allow the RI78V4 to be supported in various execution environments In the RI78V4 the user own coding module is classified into the following four types in accordance with the types and purposes of the processing that should be implemented Interrupt Entry Processing A routine dedicated to entry processing that is extracted from the INTERRUPT MANAGEMENT FUNCTIONS as a user own coding module to assign instructions to branch to relevant processing such as Interrupt Handlers or Boot Processing to the vector table address to which the CPU forcibly passes the control when an interrupt occurs Note 1 For details about the interrupt entry processing refer to 9 2 Interrupt Entry Processing Note 2 When the interrupt handler is described by C language the TA_HLNG attribute is specified in a interrupt handler definition of the system configuration file DEF_INH the user does not have to describe interrupt entry processing because of the C compiler outputing int
210. ng prev_dtq prev_dtq 4 10 14 trev_dtq 0 10 6 ref_dtq 0 10 16 Synchronization and Communication Functions Mailboxes snd_mbx 0 10 8 rcv_mbx 0 10 12 prcv_mbx 0 10 12 trcv_mbx 4 10 12 ref_mbx 0 10 6 Memory Pool Management Functions get_mpf 0 10 14 pget_mpf 0 10 14 tget_mpf 4 10 14 rel_mpf 0 10 6 ref_mpf 0 10 6 Time Management Functions sta_cyc 0 10 12 stp_cyc 0 10 6 ref_cyc 0 10 6 System State Management Functions rot_rda irot_rdq 0 10 8 get_tid iget_tid 0 10 6 loc_cpu iloc_cpu 0 10 6 unl_cpu iunl_cpu 0 10 8 ena_dsp 0 10 6 dis_dsp 0 10 6 sns_ctx 0 10 6 sns_loc 0 10 6 sns_dsp 0 10 6 sns_dpn 0 10 6 System Configuration Management Functions ref_ver 0 10 6 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 146 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 4 Data Macros This section explains the data macros for data types current state or the like used when issuing a service call provided by the RI78V4 12 4 1 Datatypes The following lists the data types of parameters specified when issuing a service call Macro definition of the data type is performed by header file lt ri_root gt include os types h which is called from standard header file lt ri_root gt include kernel h Table 12 2 Data Types Macro Data Type Description UH unsigned short int Unsigned 16 bit integer VP void __ near Pointer to an unknown data type UINT unsigned int Unsigned 16 bi
211. ng success processing else if ercd E_TMOUT Bate tinea Bases a Polling failure processing PR ee deies Note Data is written to the data queue area of the target data queue in the order of the data transmission request R20UT3375EJ0100 Rev 1 00 ztENESAS Page 65 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS tsnd_dtq This service call writes data specified by parameter data to the data queue area of the data parameter digid queue specified by If there is no available space for writing data in the data queue area of the target data queue when this service call is issued the service call does not write data but queues the invoking task to the transmission wait queue of the target data queue and moves it from the RUNNING state to the WAITING state with time data transmission wait state The sending WAITING state for a data queue is cancelled in the following cases and then moved to the READY state Sending WAITING State for a Data Queue Cancel Operation Return Value An available space was secured in the data queue area of the target data queue as a result E OK of issuing rcv_dtq An available space was secured in the data queue area of the target data queue as a result E OK of issuing prev_dtq An available space was secured in the data queue area of the target data queue as a result E OK of issuing trcv_dtq Forced release f
212. ng the relevant system information header file using the processing program Output format to system information header file for C define mpfid ID Output format to system information header file for assembly language mpfid EQU ID 2 Attribute queuing method mpfatr Specifies the attribute queuing method of the fixed sized memory pool The keywords that can be specified for mpfatr are TA_TFIFO Queuing method TA_TFIFO If a memory block could not be acquired no available memory blocks exist when get_mpf or tget_mpf is issued the task is queued to the fixed sized memory pool wait queue in the order of memory block acquisition request 3 Total number of memory blocks bikent Specifies the total number of memory blocks A value between 1 and 16383 can be specified for bikent 4 Memory block size b ksz Specifies the memory block size in bytes A value between 4 and 65534 aligned to a 2 byte boundary can be specified for biksz R20UT3375EJ0100 Rev 1 00 tENESAS Page 269 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 5 Section name sec_nam Specifies where the fixed sized memory pool is to be allocated Values that can be specified for sec_nam are limited to kernel_workO kernel_work1 kernel_work2 or kernel_work3 Fixed sized memory pool allocation section kernel_workO Allocates the fixed sized memory pool to the kernel_workO section kernel_work1 Allocates the fix
213. ng void type functions that do not have arguments function idle_handler The following shows the basic form of idle routine C Language include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void idle_handler void PP a bth amp tia a ea Main processing return Terminate idle routine Assembly Language SINCLUDE kernel inc Standard header file definition SINCLUDE kernel_id inc System information header file definition PUBLIC _idle_ handler SECTION textf TEXTF _idle_handler Bo E serie Siesta Bs te Main processing RET Terminate idle routine R20UT3375EJ0100 Rev 1 00 2tENESAS Page 139 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 7 4 Internal processing of idle routine The RI78V4 handles the idle routine as a non task module independent from tasks Moreover the RI78V4 executes original pre processing when passing control to the idle routine as well as original post processing when regaining control from the idle routine Therefore note the following points when coding idle routines Coding method Code idle routines using C or assembly language in the format shown in 11 7 3 Basic form of idle routine Stack switching The RI78V4 executes processing to switch to the system stack when passing control to the idle routine
214. nipulation processing is therefore not performed but E_QOVR is returned Note 2 An extended information Extended information exinf is passed to the task activated by issuing this service call R20UT3375EJ0100 Rev 1 00 2tENESAS Page 32 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 3 2 Not queuing an activation request A task not queuing an activation request is activated by issuing the following service call from the processing program sta_tsk ista_tsk These service calls move a task specified by parameter tskid from the DORMANT state to the READY state As a result the target task is queued at the end on the ready queue corresponding to the initial priority and becomes subject to scheduling by the RI78V4 The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable VP_INT stacd 1048575 Declares and initializes variable EM ita wack oes Baa sta_tsk tskid stacd Activate task does not queue an activation request Note 1 This service call does not perform queuing of activation requests If the target task is in a state other than the DORMANT state the counter manipulation processing is therefore not performed but E_OBu is ret
215. nter manipulation etc and the actual dispatch processing is delayed until this service call is issued upon which the actual dispatch processing is performed in batch Note This service call does not perform queuing of enable requests If the system is in the dispatching enabled state therefore no processing is performed but it is not handled as an error Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 250 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference contexts C format BOOL sns_ctx void Assembly format CALL sns_ctx Parameter s None Explanation This service call acquires the context type of the processing program that issued this service call non task context or task context When this service call is terminated normally the acquired context type TRUE non task context FALSE task context is returned Non task contexts cyclic handler interrupt handler Task contexts task Return value Macro Value Description TRUE 1 Normal completion Non task contexts FALSE 0 Normal completion Task contexts R20UT3375EJ0100 Rev 1 00 7tENESAS Page 251 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference CPU state C format BOOL sns_loc void Assembly format CALL sns_loc P
216. ntire system WAITING state State in which processing execution has been suspended because conditions required for execution are not satisfied Resumption of processing from the WAITING state starts from the point where the processing execution was suspended The value of information required for resumption such as task context immediately before suspension is therefore restored In the RI78V4 the WAITING state is classified into the following six types according to their required conditions and managed Table 3 1 Waiting States Waiting States Description A task enters this state if the counter for the task registering Sleeping state the number of times the wakeup request has been issued indicates 0x0 upon the issuance of a slp _tsk or tslp_tsk Delayed state A task enters this state upon the issuance of a dly_tsk A task enters this state if it cannot acquire a resource from Waiting state for a semaphore resource the relevant semaphore upon the issuance of a wai_sem or twai_sem A task enters this state if a relevant eventflag does not satisfy Waiting state for an eventflag a predetermined condition upon the issuance of a wai_flg or twai_flg A task enters this state if cannot send a data to the relevant sending WAITING stat for a data queue data queue upon the issuance of a snd_dtq or tsnd_dtq A task enters this state if cannot receive a data from the Receiving WAITING state for a data queue rel
217. o interrupts generated in task Task stack size size used by user service call argument size 6 bytes Expression 2 Interrupts generated in task Task stack size size used by user service call argument size 6 20 bytes Specify the task stack size in the system configuration file Note however that the size that is actually secured is the value specified in the configurator 6 bytes Consequently the value that is actually specified in the system configuration file is the sys_stk value calculated in expression 1 or expression 2 minus 6 bytes These 6 bytes include the stack size used when system calls are issued Note however that the stack size used when issuing system calls must secure the size used by the user in addition to the 6 bytes of argument stack size The argument stack sized used by each service call is different Table 12 1 summarizes these sizes R20UT3375EJ0100 Rev 1 00 2tENESAS Page 276 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE The task stack size is the largest stack size used in the task in question For this reason if there is a service call with an argument stack of 4 bytes and another with 8 bytes then the pattern that uses the most stack 8 bytes will be secured The above material refers to tasks where interrupts are not accepted all interrupts are disabled An additional 18 bytes must be secured for tasks where interrupts are accepted Note that these 20 by
218. ode wimode TWF_ANDW Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag wfmode TWF_ORW Checks which bit among bits to which 1 is set by parameter waiptn is set as the target eventflag The following describes an example for coding this service call inc inc void lude lt kernel h gt Standard header file definition lude lt kernel_id h gt System information header file definition func_task VP_INT exinf ER ercd Declares variable ID flgid ID_flgA Declares and initializes variable FLGPTN waiptn 0B1110 Declares and initializes variable ODE wfmode TWF_ANDW Declares and initializes variable FLGPTN p_flgptn Declares variable PP God aie aches alan Ky ercd pol_flg flgid waiptn wfmode amp p_flgptn Wait for eventflag polling if ercd E_OK oP A ten wantin ef Polling success processing else if ercd E_TMOUT PoP Bice pna R Polling failure processing PER 08 eres Bessa ema Note 1 In the RI78V4 the number of tasks that can be queued to the eventflag wait queue is one If this service call Note 2 is issued for the eventflag to which a task is queued therefore E_ILUSE is returned regardless of whether or not the required condition is immediately satisfied The RI78V4 performs bit pattern clear processing 0x0 setting when the
219. of all the tasks that have entered an executable state RUNNING state or READY state is selected and given the CPU use right In the RI78V4 the following two types of priorities are used for management purposes Task initial priority Priority set when a task is created Task current priority This is the general term used to describe the priority level of a task from the time it enters the READY state from the DORMANT state until it returns to the DORMANT state Therefore the current priority level of a task that enters the READY state from the DORMANT state has the same value as the initial priority level and the current priority level when the priority level is changed by issuing chg_pri or ichg_pri is the same value as the priority level after change Note 1 In the RI78V4 a task having a smaller priority number is given a higher priority Note 2 The priority that can be specified in a system is in the priority range specified in Task priority information 3 2 3 Create task In the RI78V4 the method of creating a task is limited to static creation by the Kernel Initialization Module Tasks therefore cannot be created dynamically using a method such as issuing a service call from a processing program Static create Static task creation is realized by defining Task information in the system configuration file The RI78V4 executes task creation processing based on data stored in information files using the Kernel Initialization
220. oking task is terminated by issuing the following service call from the processing program ext_tsk This service call moves an invoking task from the RUNNING state to the DORMANT state As a result the invoking task is unlinked from the ready queue and excluded from the RI78V4 scheduling subject If an activation request has been queued to the invoking task the activation request counter is not set to 0x0 when this service call is issued this service call moves the task from the RUNNING state to the DORMANT state decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter and then moves the task from the DORMANT state to the READY state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ext_tsk Terminate invoking task Note 1 This service call does not return the OS resource that the invoking task acquired by issuing a service call such as sig_sem or get_mpf The OS resource have been acquired must therefore be returned before issuing this service call Note 2 When moving a task from the RUNNING state to the DORMANT state this service call initializes the following information to values that are set during task creation Priority current priority Wakeup request count Suspension count Interru
221. om waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI Polling failure or timeout E TMOUT The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID mbxid ID_mbxA Declares and initializes variable T_MSG ppk_msg Declares data structure TMO tmout 3600 Declares and initializes variable E EE E EE k Receive from mailbox with timeout ercd trcv_mbx mbxid amp ppk_msg tmout if ercd E_OK Yo sai A E R wef Normal termination processing else if ercd E_RLWAI PO EEE EES ef Forced termination processing lse if ercd E_TMOUT PoP Bice p a R Timeout processing PP aeea Note 1 When TMO_FEVR is specified for wait time tmout processing equivalent to rcv_mbx will be executed When TMO_POL is specified processing equivalent to prcv_mbx will be executed Note 2 For details about the message packet refer to 12 5 5 Message packet R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 80 of 309 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 5 6 Reference mailbox state A mailbox status is referenced by issuing the following se
222. on This service call receives a message from the mailbox specified by parameter mbxid and stores its start address in the area specified by parameter ppk_msg If the message could not be received from the target mailbox no messages were queued in the wait queue when this service call is issued message reception processing is not executed but E_TMOUT is returned Note For details about the message packet refer to 12 5 5 Message packet Return value Macro Value Description E OK 0 Normal completion E TMOUT 50 Polling failure R20UT3375EJ0100 Rev 1 00 2tENESAS Page 224 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Receive from mailbox with timeout C format trcv_mbx ID mbxid T_MSG ppk_msg TMO tmout Assembly format MOVW AX tmout_hi PUSH AX MOVW AX tmout_lo PUSH AX MOVW BC LOWW _ppk_msq MOV A mbxid CALL trcev_mbx ADDW SP 0x0004 Parameter s V O Parameter Description l ID mbxid ID number of the mailbox from which a message is received O T MSG ppk_msg Start address of the message packet received from the mailbox Specified timeout unit ticks TMO tmout TMO_FEVR Waiting forever TMO_POL Polling Value Specified timeout Explanation This service call receives a message from the mailbox specified by parameter mbxid and stores its start address in the area spe
223. on definition file are displayed Display the folder for outputting the interrupt information definition file Default BuildModeName Output folder HOW t Changes not allowed change Restriction Up to 247 characters Display the interrupt information definition file Default kernel_int_define c File name none Changes not allowed change R20UT3375EJ0100 Rev 1 00 tENESAS Page 304 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX B CAUTIONS APPENDIX B CAUTIONS B 1 Restriction of Compiler Option Systems embedding the RI78V4 cannot use the following compile options Option Meaning This option specifies the notation of the radix for numeric constants Specifies the prefix base_number prefix oration Oxn n B 2 Handling Register Bank Systems embedding the RI78V4 should generally operate with register bank 0 If it is necessary to change the register bank do so in accordance with the specifications below Changing the register bank is enabled for some routines and disabled for others Routines where changing the register bank is enabled Task In the task the initial register bank number is set permanently to 0 When switching tasks in the RI78V4 only the register bank number and one bank s worth of general registers task switching bank are retired restored The remaining three banks of general registers are not retired or restored so if more tha
224. on header file definition void func_cychdr void ID p_tskid Declares variable LP wet de eee ohne af iget_tid amp p_tskid Reference task ID in the RUNNING state PO ated aan st err return Terminate cyclic handler Note This service call stores TSK_NONE in the area specified by parameter p_tskid if no tasks that have entered the RUNNING state exist all tasks in the IDLE state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 99 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 4 Lock the CPU A task is moved to the CPU locked state by issuing the following service call from the processing program loc_cpu iloc_cpu These service calls change the system status type to the CPU locked state As a result maskable interrupt acknowledgment processing is prohibited during the interval from this service call is issued until unl_cpu or iunl_cpu is issued and service call issuance is also restricted If a maskable interrupt is created during this period the RI78V4 delays transition to the relevant interrupt processing interrupt handler until either unl_cpu or iunl_cpu is issued The service calls that can be issued in the CPU locked state are limited to the one listed below Service Call Function loc_cpu iloc_cpu Lock the CPU unl_cpu iunl_cpu Unlock the CPU sns_ctx Reference contexts sns_loc Reference CPU state sns_dsp Reference dispatching st
225. on of TA_ACT is omitted the initial task activation status is set to the DORMANT state Note 2 If specification of TA_ENAINT and TA_DISINT is omitted the initial task interrupt status is set to interrupts acknowledgment enabled Extended information exinf Specifies the extended information of the task Values that can be specified for exinf are from 0 to 1048575 or symbol names written in C Note exinf is passed as an extended information to the target task when the task is activated by act_tsk or iact_tsk The target task can therefore handle exinfin the same manner as handling function parameters 4 Start address task Specifies the start address of the task Values that can be specified for task are symbol names written in C Note 1 When a task is in written in C as shown below the value specified by this item is func_task include lt kernel h gt include lt kernel_id h gt void func_task VP_INT exinf JE sate Broan OL E ext _ tsk Note 2 When a task is in written in assembly language as shown below the value specified by this item is func_task SINCLUDE kernel inc S INCLUDE kernel_id inc PUBLIC _func_task SECTION text TEXT _func_task PUSH BC PUSH AX BR _ext_tsk 5 Initial priority itskpri Specifies the initial priority of the task Values that can be specified for itskpri are limited to 1 to Priority range maxtpri 6 Stack size stksz R20U
226. on processing must therefore be coded by the user in the Boot Processing or Initialization Routine 9 2 Interrupt Entry Processing Interrupt entry processing is a routine dedicated to entry processing that is extracted as a user own coding module to assign instructions to branch to relevant processing such as Interrupt Handlers or Boot Processing to the vector table address to which the CPU forcibly passes the control when an interrupt occurs When the interrupt handler is described by C language the TA_HLNG attribute is specified in a interrupt handler definition of the system configuration file DEF_INH the user does not have to describe interrupt entry processing because of the C compiler outputing interrupt entry processing which corresponds to an interrupt request name automatically When the interrupt handler is described by Assembly language the TA_ASM attribute is specified in a interrupt handler definition of the system configuration file DEF_INH the user has to describe interrupt entry processing Futher it is necessory to describe by an assembly language about branch to boot processing R20UT3375EJ0100 Rev 1 00 2tENESAS Page 110 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 9 2 1 Basic form of interrupt entry processing The code of interrupt entry processing varies depending on whether the relevant processing Interrupt Handlers Boot Processing or the like is allocated to the near
227. or coding this service call ER ID VP include lt kernel h gt include lt kernel_id h gt void func_task VP_INT exinf ercd mpfid ID_mpfA p_b1lk Standard header file definition System information header file definition Declares variable Declares and initializes variable Declares variable Acquire fixed sized memory block polling ercd pget_mpf mpfid amp p_blik Polling success processing Release fixed sized memory block f Polling failure processing ercd E_OK PS wa heer er arin we rel_mpf mpfid p blk lse if ercd E_TMOUT YP tack E R EI EEEE A R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 85 of 309 RI78V4 V2 00 00 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS tget_mpf This service call acquires the memory block from the fixed sized memory pool specified by parameter mpfid and stores the start address in the area specified by parameter p_bik If a memory block could not be acquired from the target fixed sized memory pool no available memory blocks exist when this service call is issued memory block acquisition processing is not performed but the invoking task is queued to the target fixed sized memory pool wait queue in the order of memory block acquisition request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from t
228. ormation are as follows 1 Clock timer interrupt source tim_intno Specifies the interrupt source for a clock timer Only interrupt source names prescribed in the device file or only values from 0x0 to 0x7c can be specified If an interrupt source name is specified for tim_intno the CF78V4 activation option cpu A lt name gt must be specified R20UT3375EJ0100 Rev 1 00 2tENESAS Page 261 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 Static API Information The following describes the format that must be observed when describing the static API information in the system configuration file The GOTHIC FONT characters in following descriptions are the reserved words and italic face characters are the portion that the user must write the relevant numeric value symbol name or keyword Items enclosed by square brackets can be omitted 13 4 1 Task information Define the following items as task information 1 Task name tskid 2 Attribute coding language initial activation status initial interrupt status tskatr 3 Extended information exinf 4 Start address task 5 Initial priority itskpri 6 Stack size stksz 7 System reserved area stk The number of task information items that can be specified is defined as being within the range of 1 to 127 The following shows the task information format CRE_TSK tskid tskatr exinf task itskpri stksz stk The
229. peration Generation processing completed R20UT3375EJ0100 Rev 1 00 2tENESAS Page 94 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS 7 5 6 Stop cyclic handler operation Moving to the non operational state STP state is implemented by issuing the following service call from the processing program stp_cyc This service call moves the cyclic handler specified by parameter cycid from the operational state STA state to non operational state STP state As a result the target cyclic handler is excluded from activation targets of the RI78V4 until issuance of sta_cyc The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID cycid ID_cycA Declares and initializes variable JS ee EE ESA stp eye cycid Stop cyclic handler operation PRO pirigan dete shed 7 Note This service call does not perform queuing of stop requests If the target cyclic handler has been moved to the non operational state STP state therefore no processing is performed but it is not handled as an error R20UT3375EJ0100 Rev 1 00 2tENESAS Page 95 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 7 TIME MANAGEMENT FUNCTIONS 7 5 7 Reference cyclic handler state A cyclic handler status by issuing the following
230. phore specified by parameter semid subtracts 0x1 from the semaphore counter If a resource could not be acquired from the target semaphore semaphore counter is set to 0x0 when this service call is issued the counter manipulation processing is not performed but the invoking task is queued to the target semaphore wait queue in the order of resource acquisition request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for a semaphore resource Waiting State for a Semaphore Resource Cancel Operation Return Value The resource was returned to the target semaphore as a result of issuing sig_sem E OK The resource was returned to the target semaphore as a result of issuing isig_sem E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI Polling failure or timeout E TMOUT R20UT3375EJ0100 Rev 1 00 2tENESAS Page 191 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Note When TMO_FEVR is specified for wait time tmout processing equivalent to wai_sem will be executed When TMO_POL is specified processing equivalent to pol_sem will be executed Return value Macro Value Description E OK 0 Normal completion E_RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting E
231. plicitly The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_cychdr void PRI tskpri 8 Declares and initializes variable TE 6 a iw Sik hla a oe 8 ay irot rdg tskpri Rotate task precedence PP aarep ERNA Ky return Terminate cyclic handler Note 1 This service call does not perform queuing of rotation requests If no task is queued to the ready queue corresponding to the relevant priority therefore no processing is performed but it is not handled as an error Note 2 Round robin scheduling can be implemented by issuing this service call via a cyclic handler in a constant cycle R20UT3375EJ0100 Rev 1 00 2tENESAS Page 132 of 309 2015 03 25 RI78V4 V2 00 00 11 4 4 Change task priority CHAPTER 11 SCHEDULER The RI78V4 provides a function to change the priority level of tasks from the processing program explicitly switching the task execution order The following shows the status transition when this task priority is changed Ready queue Figure 11 3 Change Task Priority 1 Invoking task RUNNING state tskpri Task A READY state Task B READY state Task C READY state maxtpri chg_pri ID_tskB maxtpri Ready queue
232. pt status Note 3 If the return instruction is written in a task it executes the same operation as this service call Note 4 In the RI78V4 code efficiency is enhanced by coding the return instruction as a Terminate invoking task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 35 of 309 2015 03 25 RI78V4 V2 00 00 3 5 2 Terminate task Other tasks are forcibly terminated by issuing the following service call from the processing program ter_tsk This service call forcibly moves a task specified by parameter tskid to the DORMANT state As a result the target task is excluded from the RI78V4 scheduling subject CHAPTER 3 TASK MANAGEMENT FUNCTIONS If an activation request has been queued to the target task the activation request counter is not set to 0x0 when this service call is issued this service call moves the task to the DORMANT state decrements the wakeup request counter by subtracting 0x1 from the wakeup request counter and then moves the task from the DORMANT state to the READY state The following describes an example for coding this service call ter_tsk tskid include lt kernel h gt include lt kernel_id h gt void func_task VP_INT exinf ID tskid ID_tskA Standard header file definition System information header file definition Declares and initializes variable Terminate task Note 1 This service call does not return the OS resource that the target task
233. pted Task When interrupts specified as 0 1 A Interrupts disabled if enabled all interrupt disabled levels accepted When a level 2 interrupt 1 0 1 Interrupts enabled level 0 and level 1 Cyclic occurs levels accepted handler When a level 3 interrupt P E Interrupts enabled level 0 level 1 and occurs level 2 levels accepted When a level 2 interrupt A 0 A Interrupts enabled level 0 and level 1 Interrupt occurs levels accepted handler When a level 3 interrupt 1 1 0 Interrupts enabled level 0 level 1 and occurs level 2 levels accepted When a level 0_ interrupt Interrupts disabled if enabled a lelvel 0 occurs 0 0 0 interrupt accepted When a level 1 interrupt 0 0 0 Interrupts disabled if enabled a lelvel 0 Interrupt occurs interrupt accepted servicing When a level 2 interrupt Interrupts disabled if enabled lelvel 0 occurs 1 and lebel 1 interrupts accepted When a level 3 interrupt 0 A 0 Interrupts disabled if enabled lelvel 0 occurs level 1 and lebel 2 interrupts accepted Note that a separate IE state is maintained for each task If a suspended task is resumed the IE state before suspension is restored R20UT3375EJ0100 Rev 1 00 2tENESAS Page 118 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 9 5 Multiple Interrupts The reoccurrence of an interrupt within an interrupt handler is called multiple interrupt The following shows the flow of the processing for handling multiple interr
234. q ID stskid Existence of tasks waiting for data transmission ID rtskid Existence of tasks waiting for data reception UINT sdtqcnt Number of data elements in data queue T_RDTOQ Explanation These service calls store the detailed information of the data queue existence of waiting tasks number of data elements in the data queue etc specified by parameter dtqid into the area specified by parameter pk_rdtq Note For details about the data queue state packet refer to 12 5 4 Data queue state packet Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 218 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 11 Synchronization and Communication Functions Mailboxes The following lists the service calls provided by the RI78V4 as the synchronization and communication functions mail boxes Table 12 13 Synchronization and Communication Functions Mailboxes Service Call Function Origin of Service Call snd_mbx Send to mailbox Task Non task rcv_mbx Receive from mailbox waiting forever Task prcv_mbx Receive from mailbox polling Task Non task trcv_mbx Receive from mailbox with timeout Task ref_mbx Reference mailbox state Task Non task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 219 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Send to mailbox
235. quently semaphore names can be used in the place of IDs by including the relevant system information header file using the processing program Output format to system information header file for C define semid ID Output format to system information header file for assembly language semid EQU ID 2 Attribute queuing method sematr Specifies the attribute queuing method of the semaphore The keywords that can be specified for sematr are TA_TFIFO Queuing method TA_TFIFO If a resource could not be acquired semaphore counter is set to 0x0 when wai_sem or twai_sem is issued the task is queued to the semaphore wait queue in the order of resource acquisition request 3 Initial resource count isemcnt Specifies the initial resource count of the semaphore A value between 0 and 127 can be specified for isement 4 System reserved area maxsem System reserved area Values that can be specified for maxsem are limited to 127 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 265 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 3 Eventflag information Define the following items as eventflag information 1 Eventflag name flgid 2 Attribute queuing method queuing count bit pattern clear flgatr 3 System reserved area iflgptn The number of eventflag information items that can be specified is defined as being within the range of 0 to 127 The following s
236. queue is cancelled in the following cases and then moved to the READY state Sending WAITING State for a Data Queue Cancel Operation Return Value Available space was secured in the data queue area of the target data queue as a result of E OK issuing rcv_diq Available space was secured in the data queue area of the target data queue as a result of E OK issuing prcv_dtq Available space was secured in the data queue area of the target data queue as a result of E OK issuing trcv_diq Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from the reception wait R20UT3375EJ0100 Rev 1 00 2015 03 25 7tENESAS Page 206 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS queue and moves from the WAITING state data reception wait state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Note 1 Data is written to the data queue area of the target data queue in the order of the data transmission request Note 2 Invoking tasks are queued to the transmission wait queue of the target data queue in the order defined during configuration FIFO order Return value
237. r details on the valid issuance range of each service call refer to Table 12 8 to Table 12 17 Note 2 If a service call ichg_pri isig sem etc accompanying dispatch processing task scheduling processing is issued in order to quickly complete the processing in the interrupt handler during the interval until the processing in the interrupt handler ends the RI78V4 executes only processing such as queue manipulation counter manipulation etc and the actual dispatch processing is delayed until a return instruction is issued by the interrupt handler upon which the actual dispatch processing is performed in batch 9 4 Controlling Enabling Disabling of Interrupts R20UT3375EJ0100 Rev 1 00 2tENESAS Page 116 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 9 4 1 Interrupt level under management of the RI78V4 The microcontroller manages four levels of interrupts level 0 to level 3 On the RI78V4 the interrupt levels at which service calls can be issued from an interrupt are permanently set to levels 2 and 3 these are treated as the interrupt levels managed by the RI78V4 Interrupt levels 2 and 3 are managed by the RI78V4 Service calls can be issued from levels 2 and 3 Interrupt handlers which are interrupts including timer interrupts managed by the RI78V4 must be set to level 2 or 3 Interrupt levels 0 and 1 are not managed by the RI78V4 Service calls cannot be issued from levels 0 or 1 Behavior i
238. r eventtflag Task Non task wai_flg Wait for eventflag waiting forever Task pol_flg Wait for eventflag polling Task Non task twai_flg Wait for eventflag with timeout Task ret_flg Reference eventflag state Task Non task R20UT3375EJ0100 Rev 1 00 2tENESAS Page 194 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS set_fig iset_flg Outline Set eventtflag C format ER set_flg ID flgid FLGPTN setptn ER iset_flg ID flgid FLGPIN setptn Assembly format MOVW BC setptn MOV A flgid CALL _ set_flg MOVW BC setptn MOV A flgid CALL _ iset_flg Parameter s 1 0 Parameter Description l ID flgid ID number of the eventflag to be set FLGPTN setptn Bit pattern to set 16 bits Explanation These service calls set the result of ORing the bit pattern of the eventflag specified by parameter flgid and the bit pattern specified by parameter setptn as the bit pattern of the target eventflag If the required condition of the task queued to the target eventflag wait queue is satisfied when this service call is issued the relevant task is unlinked from the wait queue at the same time as bit pattern setting processing As a result the relevant task is moved from the WAITING state waiting state for an eventflag to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Note 1 If the task linked in the wait queue is moved
239. r is described by assembly language data of general purpose registers AX BC DE HL and registers ES CS is saved and restored in that function execution by explicitly calling register data save processing function name _kernel_int_entry at the beginning of the interrupt handler and calling data restore processing function name _kernel_int_exit at the end of the interrupt handler Note 1 Data of the PSW and PC are automatically saved and stored by the CPU Interrupt status The RI78V4 goes into the following state when passing control to an interrupt handler Consequently after control has passed to an interrupt handler if an interrupt occurs with a higher precedence than the current level then multiple interrupts can be processed Acceptance of maskable interrupts is permitted IE 0 Interrupts with the precedence below are disabled A level 2 interrupt handler process is ongoing ISP1 0 ISPO 1 A level 3 interrupt handler process is ongoing ISP1 1 ISPO 0 Note It is not possible to define level 0 or 1 as an interrupt handler Note Even if the acceptance of maskable interrupts is disabled inside an interrupt handler IE 0 it will be enabled IE 1 after control returns from the interrupt handler Service call issuance The RI78V4 handles the interrupt handler as a non task Service calls that can be issued in interrupt handlers are limited to the service calls that can be issued from non tasks Note 1 Fo
240. r s Manual RL78 Build for details about the Output panel R20UT3375EJ0100 Rev 1 00 2tENESAS Page 286 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Project Tree panel Outline This panel is used to display the project components such as Realtime OS node system configuration file etc in tree view This panel can be opened as follows From the View menu select Project Tree Display image 2 fa o sample Project P R5FLOOSL Microcontroller A CC RL Build Tool Me RIT8V4 Realtime OS gS RL78 Simulator Debug Tool 5 File gi Build tool generated files a a Realtime OS related file J inirtn c c init c A asm initstack asm aa c inthdr c ind kernel_id inc ej kernel_int_define c R20UT3375EJ0100 Rev 1 00 2tENESAS Page 287 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Explanation of each area 1 Project tree area Project components are displayed in tree view with the following given node Node Description RI78V4 Realtime OS referred to as Realtime OS Realtime OS to be used node XXx Cfg System configuration file The following information files appear directly below the node created when a system configuration file is added System information table file asm Realtime OS generated files referred to as Realtime OS generated files node Syste
241. r the eventflag to which a task is queued therefore E_ILUSE is returned regardless of whether or not the required condition is immediately satisfied Note 4 The RI78V4 performs bit pattern clear processing 0x0 setting when the required condition of the target eventflag TA_CLR attribute is satisfied Return value Macro Value Description E OK 0 Normal completion E ILUSE 28 Illegal service Call use there is already a task waiting for an eventflag with the z TA_WSGL attribute E_TMOUT 50 Polling failure R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 201 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Wait for eventflag with timeout C format ER twai_flg ID flgid FLGPIN waiptn MODE wfmode FLGPTIN p_flgptn TMO tmout i Assembly format MOVW AX tmout_hi PUSH AX MOVW AX tmout_lo PUSH AX MOVW DE LOWW _p_flgptn MOVW BC waiptn MOVW AX flgid wfmode CALL twai_flg addw Sp 0x0004 Parameter s 0 Parameter Description l ID flgid ID number of the eventflag wait for l FLGPTN waiptn Wait bit pattern 16 bits Wait mode l MODE wfmode TWF_ANDW AND waiting condition TWF_ORW OR waiting condition O FLGPTN p_flgptn Bit pattern causing a task to be released from waiting Specified timeout unit ticks TMO tmout TMO_FEVR Waiting forever TMO_POL Polling
242. rced termination processing PR OSS we ape os R20UT3375EJ0100 Rev 1 00 tENESAS Page 69 of 309 2015 03 25 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS Note 1 Invoking tasks are queued to the reception wait queue of the target data queue in the order of the data reception request Note 2 If the receiving WAITING state for a data queue is forcibly released by issuing rel_wai or irel_wai the contents of the area specified by parameter p_data will be undefined R20UT3375EJ0100 Rev 1 00 2tENESAS Page 70 of 309 2015 03 25 RI78V4 V2 00 00 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION FUNCTIONS prcv_dtq These service calls read data in the data queue area of the data queue specified by parameter dtqid and stores it to the area specified by parameter p_data If no data could be read from the data queue area of the target data queue no data has been written to the data queue area when either of these service calls is issued the service call does not read data but E_TMOUT is returned The following describes an example for coding this service call include lt kernel ER ercd ID dtqid 1 VP_INT p data if ercd E_OK i a ae zy lse if ercd E ees Sig eaten AE E zj include lt kernel_id h gt System information header file definition void task VP_INT exinf ercd prcv_dtq dtqid amp p_data E_TMOUT h gt S
243. rea of the target data queue as a result of E OK issuing trcv_dtq Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from the reception wait queue and moves from the WAITING state data reception wait state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void task VP_INT exinf ER ercd Declares variable ID dtqid 1 Declares and initializes variable VP_INT data 123 Declares and initializes variable PP Dachig ae tak a ercd snd_dtq dtqid data Send to data queue waiting forever if ercd E_OK J oPO E tars etree ay Normal termination processing else if ercd E_RLWAI ToC a aceeas ey Forced termination processing EE opalio Note 1 Data is written to the data queue area of the target data queue in the order of the data transmission request Note 2 Invoking tasks are queued to the transmission wait queue of the
244. rence eventtflag state C format ER ref_flg ID flgid T_RFLG pk_rflg Assembly format MOVW BC LOWW _pk_rflg MOV A flgid CALL _ ref _flg Parameter s 1 0 Parameter Description l ID flgid ID number of the eventflag to be referenced O T_RFLG pk_rflg Pointer to the packet returning the eventflag state Explanation Stores eventflag state packet such as existence of waiting tasks of the eventflag specified by parameter flgid in the area specified by parameter pk_rflg Note For details about the eventflag state packet refer to 12 5 3 Eventflag state packet Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 204 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 10 Synchronization and Communication Functions Data queues The following shows the service calls provided by the RI78V4 as the synchronization and communication functions data queues Table 12 12 Synchronization and Communication Functions Data Queues Service Call Function Origin of Service Call snd_dtq Send to data queue waiting forever Task psnd_dtq Send to data queue polling a Non task Initialization rou ipsnd_dtq Send to data queue polling i POST Sih Initialization Tou tsnd_dtq Send to data queue with timeout Task fsnd_dtq Forced send to data
245. rent The following macro name is available as an embedded macro BuildModeName Replaces with the build mode name If this field is left blank macro name BuildModeName will be displayed This property is not displayed when No It does not register the file that is added to the project nda in the Generate a file property is selected Output folder Default BuildModeName How to Directly enter to the text box or edit by the Browse For Folder dialog box which appears when clicking the change button Restriction Up to 247 characters R20UT3375EJ0100 Rev 1 00 tENESAS Page 302 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Specify the system information header file for assembly language name If the file name is changed the name of the file displayed on the project tree Use the extension inc If the extension is different or omitted inc is automatically added This property is not displayed when No It does not register the file that is File name added to the project nda in the Generate a file property is selected Default kernel_id inc ROW to Directly enter to the text box change Restriction Up to 259 characters R20UT3375EJ0100 Rev 1 00 tENESAS Page 303 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE 4 Interrupt Information Definition File The detailed information on the interrupt informati
246. ring logic circuits microcontrollers C language and assemblers To understand the hardware functions of the RL78 family gt Refer to the User s Manual of each product Data significance Higher digits on the left and lower digits on the right Note Footnote for item marked with Note in the text Caution Information requiring particular attention Remark Supplementary information Numeric representation Decimal XXXX Hexadecimal OxXXXX Prefixes indicating power of 2 address space and memory capacity K kilo 210 1024 M mega 2 1024 Related Documents The related documents indicated in this publication may include preliminary versions However preliminary versions are not marked as such Document No Document Name Start R20UT0751E RI Series Message R20UT0756E This manual RI78V4 V2 00 00 R20UT3374E Analysis R20UT3373E Caution The related documents listed above are subject to change without notice Be sure to use the latest edition of each document when designing All trademarks or registered trademarks in this document are the property of their respective owners RI78V4 V2 00 00 CHAPTER 1 OVERVIEW CHAPTER1 OVERVIEW 1 1 Outline The RI78V4 is a built in real time multi task OS that provides a highly efficient real time multi task environment to increases the application range of processor control units The RI78V4 is
247. rn that satisfies the required condition specified by parameter wfmode are set to the eventflag specified by parameter flgid If the bit pattern that satisfies the required condition has been set to the target eventtflag the bit pattern of the target eventtflag is stored in the area specified by parameter p_flgptn If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued E_ TMOUT is returned The following shows the specification format of required condition wfmode wimode TWF_ANDW Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag wfmode TWF_ORW Checks which bit among bits to which 1 is set by parameter waiptn is set as the target eventflag Note 1 In the RI78V4 the number of tasks that can be queued to the eventflag wait queue is one If this service call is issued for the eventflag to which a task is queued therefore E_ILUSE is returned regardless of whether or not the required condition is immediately satisfied R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 200 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Note 2 The RI78V4 performs bit pattern clear processing 0x0 setting when the required condition of the target eventflag TA_CLR attribute is satisfied Note 3 In the RI78V4 the number of tasks that can be queued to the eventflag wait queue is one If this service call is issued fo
248. rocessing of interrupt entry processing 111 9 3 Interrupt Handlers 112 9 3 1 Define interrupt handler 112 9 3 2 Basic form of interrupt handlers 113 9 3 3 Internal processing of interrupt handler 116 9 4 Controlling Enabling Disabling of Interrupts 116 9 4 1 Interrupt level under management of the RI78V4 117 9 4 2 Controlling enabling disabling of interrupts in the RI78V4 117 9 4 3 Controlling enabling disabling of interrupts in user processes 118 9 5 Multiple Interrupts 119 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT FUNCTIONS 121 10 1 10 2 10 3 10 4 10 5 Outline 121 Boot Processing 122 10 2 1 Define boot processing 122 10 2 2 Basic form of boot processing 122 10 2 3 Internal processing of boot processing 124 10 2 4 System dependence information 125 Initialization Routine 126 10 3 1 Define initialization routine 126 10 3 2 Undefine initialization routine 126 10 3 3 Basic form of initialization routine 126 10 3 4 Internal processing of initialization routine 127 Kernel Initialization Module 127 Reference Version Information 128 CHAPTER 11 SCHEDULER 129 11 1 11 2 11 3 11 4 11 5 11 6 11 7 Outline 129 Driving Method 129 Scheduling System 129 Ready Queue 130 11 4 1 Create ready queue 130 11 4 2 Delete ready queue 130 11 4 3 Rotate task precedence 131 11 4 4 Change task priority
249. rom waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Polling failure or timeout E TMOUT If a task has been queued to the reception wait queue of the target data queue when this service call is issued this service call does not write data but transfers the data to the task As a result the task is unlinked from the reception wait queue and moves from the WAITING state data reception wait state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void task VP_INT exinf ER ercd Declares variable ID dtqid 1 Declares and initializes variable VP_INT data 123 Declares and initializes variable TMO tmout 3600 Declares and initializes variable FP bh meee tyes Hy Send to data queue with timeout ercd tsnd_dtq dtqid data tmout if ercd E_OK PR RERE hiatal Normal termination processing lse if ercd E_RLWAT A E ares Forced termination processing else if ercd E_TMOUT OO i we A Timeout processing PR GR E E Note 1 Data is written to the data queue area of the target data queue in the order of the data transmission request Note 2
250. rrupt handler to the vector table address to which the CPU forcibly passes control upon occurrence of an interrupt The code of Interrupt Entry Processing varies depending on whether the interrupt handler is allocated to the near area or to the far area When the interrupt handler is described by C language the TA_HLNG attribute is specified in a interrupt handler definition of the system configuration file DEF_INH the user does not have to describe interrupt entry processing because of the C compiler outputing interrupt entry processing which corresponds to an interrupt request name automatically When the interrupt handler is described by Assembly language the TA_ASM attribute is specified in a interrupt handler definition of the system configuration file DEF_INH the user has to describe interrupt entry processing R20UT3375EJ0100 Rev 1 00 ztENESAS Page 112 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 9 3 2 Basic form of interrupt handlers When coding interrupt handlers in C use void type functions that do not have arguments any function name is fine The code of interrupt depending on whether the interrupt handler is allocated to the near area or to the far area The following shows the basic form of coding interrupt handlers in C When the interrupt handler is allocated to the near area include lt kernel h gt Standard header file definition include lt ker
251. rvice call from the processing program ref_mbx Stores mailbox state packet such as existence of waiting tasks of the mailbox specified by parameter mbxid in the area specified by parameter pk_rmbx The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID mbxid ID_mbxA Declares and initializes variable T_RMBX pk_rmbx Declares data structure ID wt skid Declares variable T_MSG pok_msg Declares data structure EE duane eth a a ref_mbx mbxid amp pk_rmbx Reference mailbox state wtskid pk_rmbx wtskid Reference ID number of the task at the head of the wait queue pk_msg pk_rmbx pk_msg Referenc start address of the message packet at the head of the message queue Note For details about the mailbox state packet refer to 12 5 6 Mailbox state packet R20UT3375EJ0100 Rev 1 00 2tENESAS Page 81 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 6 MEMORY POOL MANAGEMENT FUNCTIONS CHAPTER6 MEMORY POOL MANAGEMENT FUNC TIONS This chapter describes the memory pool management functions performed by the RI78V4 6 1 Outline The statically secured memory areas in the Kernel Initialization Module are subject to management by the memory pool management functions of the RI78V4 In the RI78V4
252. s are regarded as object names Note Elements of a word are limited to alphanumeric characters a to z A to Z 0 to 9 and underscore _ Symbol name In a system configuration file words starting with a letter of a to z A to Z or underscore _ within 30 characters are regarded as symbol names Note 1 Elements of a word are limited to alphanumeric characters a to z A to Z 0 to 9 and underscore _ Note 2 The CF78V4 distinguishes the object name and symbol name according to the context in the system configuration file Keywords The words shown below are reserved by the CF78V4 as keywords Using these words for any other purpose specified is therefore prohibited CLK_INTNO CRE_CYC CRE_DTQ CRE_FLG CRE_MBX CRE_MPF CRE_SEM CRE_TSK DEF_INH kernel_workO kernel_work1 kernel_work2 kernel_work3 MAX_PRI null NULL SYS STK TA_ACT TA_ASM TA_CLR TA_DISINT TA_ENAINT TA_FAR TA_HLNG TA_MFIFO TA_MPRI TA_NEAR TA_PHS TA_RSTR TA_STA TA_TFIFO TA_TPRI TA_WMUL TA_WSGL Note The CF78V4 does not call C preprocessors Coding of preprocessing directives include define if or the like in the system configuration file is therefore prohibited R20UT3375EJ0100 Rev 1 00 ztENESAS Page 256 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 2 Configuration Information The configuration information that is described in a system configuration file is divided into the following two
253. s the task at the end of the ready queue corresponding to the priority of the task Note 2 This service call does not perform queuing of cancellation requests If the target task is in a state other than the SUSPENDED or WAITING SUSPENDED state E_OBu is therefore returned R20UT3375EJ0100 Rev 1 00 2tENESAS Page 45 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS frsm_tsk ifrsm_tsk These service calls set the suspend request counter for the task specified by parameter tskid to 0x1 f and then forcibly cancel the SUSPENDED state of the target task As a result the target task is moved from the SUSPENDED state to the READY state or from the WAITING SUSPENDED state to the WAITING state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable PE Fate cece sensu E E a frsm_tsk tskid Forcibly resume suspended task ar eee eee eee aa Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 This service call does not perform queuing of forced cancellation requests If the target task
254. s interrupt handler information 1 Interrupt source inhno 2 Attribute inhatr 3 Start address inthdr The number of items that can be defined as interrupt handler information is limited to one for each interrupt source The following shows the interrupt handler information format iw EF_INH inhno inhatr inthdr The items constituting the interrupt handler information are as follows 1 Interrupt source inhno Specifies the interrupt source for an interrupt handler Only interrupt source names prescribed in the device file or only values from 0x0 to 0x7c can be specified If an interrupt source name is specified for inhno the CF78V4 activation option cpu A lt name gt must be specified 2 Attribute inhatr Specifies the language used to describe an interrupt handler The keyword that can be specified for inhatris TA_HLNG or TA_ASM Coding language TA_HLNG Start an interrupt handler through a C language interface TA_ASM Start an interrupt handler through an assembly language interface Allocation TA_NEAR NEAR allocation TA_FAR FAR allocation 3 Start address inthdr Specifies the start address of the interrupt handler Values that can be specified for inthdr are symbol names written in C Note 1 When a interrupt handler is in written in C as shown below the value specified by this item is func_inthdr include lt kernel h gt include lt kernel_id h gt void fu
255. s not guaranteed if a service call is issued from level 0 or 1 Interrupt processes which are interrupts not managed by the RI78V4 must be set to level O or 1 There is however an exception user applications that disable multiple interrupts See below can set interrupts to level 2 or 3 9 4 2 Controlling enabling disabling of interrupts in the RI78V4 The RI78V4 uses the ISP1 and ISPO bits in the PSW register to enable and disable interrupts Set ISP1 to 0 and ISPO to 1 to disable interrupts in the RI78V4 Set ISP1 to 1 and ISPO to 1 to enable interrupts in the RI78V4 Figure 9 2 ISP1 and ISPO Bits in PSW Register PSW register IE Z RBSB1 AC RBSBO ISP1 ISPO CY i ISP1 ISPO j Interrupt priority in current process 0 0 Enable level 0 interrupts While processing a level 1 or level O interrupt 0 A Enable level 0 and level 1 interrupts While processing a level 2 interrupt 1 0 Enable level 0 level 1 and level 2 interrupts While processing a level 3 interrupt Enable all interrupts Standby for the acceptance of interrupts The IE bit of the RI78V4 s PSW register inherits the value of the service call or RI78V4 function issuer El and DI instructions do not manipulate the IE value As exceptions however there are places in the RI78V4 where El and DI instructions are used Immediately before starting a task specifying interrupts as disabled a DI instruction is
256. s stored in the area specified by parameter p_flgptn If the bit pattern of the target eventflag does not satisfy the required condition when this service call is issued the invoking task is queued to the target eventflag wait queue As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for an eventflag Waiting State for an Eventflag Cancel Operation Return Value A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing set_flg a A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing iset_flg a Forced release from waiting accept rel_wai while waiting E RLWAI R20UT3375EJ0100 Rev 1 00 2015 03 25 ztENESAS Page 198 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Waiting State for an Eventflag Cancel Operation Return Value Forced release from waiting accept irel_wai while waiting E RLWAI The following shows the specification format of required condition wfmode wimode TWF_ANDW Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag wfmode TWF_ORW Checks which bit among bits to which 1 is set by parameter waiptn is set as the target eventflag Note 1 In the RI78V4 the number of tasks that can be queued to the eventflag wait que
257. s written in C Note 1 When the cyclic handler is in written in C as shown below the value specified by this item is func_cychar include lt kernel h gt include lt kernel_id h gt void func_cychdr void Note 2 When the cyclic handler is in written in assembly language as shown below the value specified by this item is func_cychdr SINCLUDE kernel inc S INCLUDE kernel_id inc PUBLIC _func_cychdr SECTION text TEXT _func_cychdr 5 Activation cycle cyctim Specifies the activation cycle unit ticks of the cyclic handler A value between 1 and 4294967295 can be specified for cyctim 6 Activation phase cycphs Specifies the activation phase in millisecond for a cyclic handler A value from 0x1 to Ox7fffffff aligned to clkcyc multiple values can be specified for cycphs Note 1 In the RI78V4 the initial activation phase means the relative interval from when generation of s cyclic handler is completed until the first activation request is issued Note 2 If a value other than an integral multiple of the base clock cycle defined in Clock timer interrupt source is specified for cycphs the CF78V4 assumes that an integral multiple is specified and performs processing R20UT3375EJ0100 Rev 1 00 2tENESAS Page 272 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 8 Interrupt handler information Define the following items a
258. semaphore wait queue in the order of resource acquisition request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state waiting state for a semaphore resource The waiting state for a semaphore resource is cancelled in the following cases and then moved to the READY state Waiting State for a Semaphore Resource Cancel Operation Return Value The resource was returned to the target semaphore as a result of issuing sig_sem E OK The resource was returned to the target semaphore as a result of issuing isig_sem E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_wai while waiting E RLWAI Polling failure or timeout E TMOUT The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ER ercd Declares variable ID semid ID_semA Declares and initializes variable TMO tmout 3600 Declares and initializes variable I bt dwar eta Acquire semaphore resource with timeout ercd twai_sem semid tmout if ercd E_OK E pian aea aA Normal termination processing lse if ercd E_RLWAI E aena i Forced termination processing ls
259. sk The RI78V4 provides two types of interfaces for task activation queuing an activation request queuing and not queuing an activation request 3 3 1 Queuing an activation request A task queuing an activation request is activated by issuing the following service call from the processing program act_tsk iact_tsk These service calls move a task specified by parameter tskid from the DORMANT state to the READY state As a result the target task is queued at the end on the ready queue corresponding to the initial priority and becomes subject to scheduling by the RI78V4 If the target task has been moved to a state other than the DORMANT state when this service call is issued this service call does not move the state but increments the activation request counter by added 0x1 to the wakeup request counter The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable FR tiene AS z act_tsk tekid Activate task queues an activation request PR Pahokee tae I Note 1 The activation request counter managed by the RI78V4 is configured in 7 bit widths If the number of activation requests exceeds the maximum count value 127 as a result of issuing this service call the counter ma
260. sk is processing program that is not executed unless it is explicitly manipulated via service calls provided by the RI78V4 unlike other processing programs cyclic handler and interrupt handler Note For details about the task refer to 3 2 Tasks Cyclic Handlers The cyclic handler is a routine dedicated to cycle processing that is activated periodically at a constant interval activation cycle The RI78V4 handles the cyclic handler as a non task module independent from tasks Therefore even if a task with the highest priority in the system is being executed the processing is suspended when a specified activation cycle has come and the control is passed to the cyclic handler Note For details about the cyclic handler refer to 7 5 Cyclic Handlers Interrupt Handlers The interrupt handler is a routine dedicated to interrupt servicing that is activated when an interrupt occurs The RI78V4 handles the interrupt handler as a non task module independent from tasks Therefore even if a task with the highest priority in the system is being executed the processing is suspended when an interrupt occurs and the control is passed to the interrupt handler Note 1 For details about the interrupt handler refer to 9 3 Interrupt Handlers Note 2 The user must code the interrupt handlers that calls the Timer Handler 2 3 Coding of System Configuration File Code the SYSTEM CONFIGURATION FILE required for creating i
261. sp is issued and enters the dispatching enabled state when ena_dsp is issued R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 108 of 309 RI78V4 V2 00 00 CHAPTER 8 SYSTEM STATE MANAGEMENT FUNCTIONS 8 11 Reference Dispatch Pending State The dispatch pending state is referenced by issuing the following service call from the processing program sns_dpn This service call acquires the system status type when this service call is issued whether in dispatch pending state or not When this service call is terminated normally the acquired system state type TRUE dispatch pending state FALSE dispatch not pending state is returned The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_sub void BOOL ercd Declares variable oP acd tse Geocache class a ercd sns_dpn Reference dispatch pending state if ercd TRUE PP te arian tai wee a Dispatch pending state else if ercd FALSE JET brad Cee ion vA Other state EP E EE EE Ef Note The dispatch pending state designates the state in which explicit execution of dispatch processing task scheduling processing is prohibited by issuing either the dis_dsp loc_cpu or iloc_cpu service call as well as the state during which processing of a non task is being exec
262. ssembly language Display image Property x f sys cfg Property 4 System Information Table File Eel Yes tt updates the file when the cfg file is changed i Output folder BuildModeName File name sit asm System Information Header File for C Language Generate a file Yes It updates the file when the cfa file is changed dc Output folder BuildModeName File name kemel_id h System Information Header File for Assembly Language Generate a file Yes It updates the file when the cfg file is changed da Output folder BuildModeName File name kemel_id inc Interrupt Information Definition File Output folder BuildModeName File name kemel_int_define c Generate a file Select whether to make a System Information Table File which is output from a system configuration file This file includes information of system initialization System Configuration File Related Information R20UT3375EJ0100 Rev 1 00 2tENESAS Page 297 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Explanation of each area 1 System Information Table File The detailed information on the system information table file are displayed and the configuration can be changed Select whether to generate a system information table file and whether to update the file when the system configuration file is changed Default Yes It updates the file when the cfg file is changed i now lp Select from the drop dow
263. st 32 3 3 2 Not queuing an activation request 33 3 4 Cancel Task Activation Requests 34 3 5 Terminate Task 35 3 5 1 Terminate invoking task 35 3 5 2 Terminate task 36 3 6 Change Task Priority 37 3 7 Reference Task State 38 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS 39 4 1 Outline 39 4 2 Put Task to Sleep 39 4 3 Wakeup Task 41 4 4 Cancel Task Wakeup Requests 42 4 5 Release Task from Waiting 43 4 6 Suspend Task 44 4 7 Resume Suspended Task 45 4 8 Delay Task 47 CHAPTER 5 SYNCHRONIZATION AND COMMUNICATION FUNCTIONS 48 5 1 Outline 48 5 2 Semaphores 48 5 2 1 Create semaphore 48 5 2 2 Delete semaphore 48 5 2 3 Release semaphore resource 49 5 2 4 Acquire semaphore resource 50 5 2 5 Reference semaphore state 53 5 3 Eventflags 54 5 3 1 Create eventflag 54 5 3 2 Delete eventflag 54 5 3 3 Set eveniflag 55 5 3 4 Clear eventflag 56 5 3 5 Wait for eventflag 57 5 3 6 Reference eventflag state 62 5 4 Data Queues 63 5 4 1 Create data queue 63 5 4 2 Send to data queue 64 5 4 3 Forced send to data queue 68 5 4 4 Receive from data queue 69 5 4 5 Reference data queue state 74 5 5 Mailboxes 75 5 5 1 Create mailbox 75 5 5 2 Delete mailbox 75 5 5 3 Message 76 5 5 4 Send to mailbox 77 5 5 5 Receive from mailbox 78 5 5 6 Reference mailbox state
264. sus_tsk rsm_tsk irsm_tsk frsm_tsk ifrsm_tsk dly_tsk Synchronization and Communication Functions Semaphores sig_sem isig_sem wai_sem pol_sem twai_sem ref_sem Synchronization and Communication Functions Eventflags set_flg iset_flg clr_flg wai_flg pol_flg twai_flg ref_flg Synchronization and Communication Functions Data queues snd_dtq psnd_dtq ipsnd_dtq tsnd_dtq fsnd_dta ifsnd_dtq rcv_dtq prcv_dtq trcv_dtq ref_dtq Synchronization and Communication Functions Mailboxes snd_mbx rcv_mbx prcv_mbx trcv_mbx ref_mbx Memory Pool Management Functions get_mpf pget_mpf tget_mpf rel_mpf ref_mpf Time Management Functions sta_cyc stp_cyc ref_cyc System State Management Functions rot_rdq irot_rdg get tid iget_tid loc_cpu iloc_cpu unl_cpu iunl_cpu ena_dsp dis_dsp sns_ctx sns_loc sns_dsp sns_dpn System Configuration Management Functions ref_ver R20UT3375EJ0100 Rev 1 00 2tENESAS Page 141 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 2 Call Service Call The method for calling service calls from processing programs coded either in C or assembly language is described below 12 2 1 C language By calling using the same method as for normal C functions service call parameters are handed over to the RI78V4 as arguments and the relevant processing is executed C Language include lt kernel h gt Standard header fil
265. system configuration file The RI78V4 executes semaphore creation processing based on data stored in information files using the Kernel Initialization Module and handles the created semaphores as management targets 5 2 2 Delete semaphore In the RI78V4 semaphores created statically by the Kernel Initialization Module cannot be deleted dynamically using a method such as issuing a service call from a processing program R20UT3375EJ0100 Rev 1 00 2tENESAS Page 48 of 309 2015 03 25 CHAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS 5 2 3 Release semaphore resource A resource is returned by issuing the following service call from the processing program sig_sem isig_ sem These service calls return the resource to the semaphore specified by parameter semid adds 0x1 to the semaphore counter If a task is queued in the wait queue of the target semaphore when this service call is issued the counter manipulation processing is not performed but the resource is passed to the relevant task first task of wait queue As a result the relevant task is unlinked from the wait queue and is moved from the WAITING state waiting state for a semaphore resource to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header fil
266. t blank macro name BuildModeName will be displayed This property is not displayed when No It does not register the file that is added to the project ndc in the Generate a file property is selected Output folder Default BuildModeName How to Directly enter to the text box or edit by the Browse For Folder dialog box which appears when clicking the change button Restriction Up to 247 characters R20UT3375EJ0100 Rev 1 00 tENESAS Page 300 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE Specify the system information header file for C language name If the file name is changed the name of the file displayed on the project tree Use the extension h If the extension is different or omitted h is automatically added This property is not displayed when No It does not register the file that is File name added to the project ndc in the Generate a file property is selected Default kernel_id h ROW to Directly enter to the text box change Restriction Up to 259 characters R20UT3375EJ0100 Rev 1 00 tENESAS Page 301 of 309 2015 03 25 RI78V4 V2 00 00 APPENDIX A WINDOW REFERENCE 3 System Information Header File for Assembly Language The detailed information on the system information header file for assembly language are displayed and the configuration can be changed Select whether to generate a system informatio
267. t integer VP_INT signed long int ald to an unknown data type or a signed 32 bit ID Note unsigned char Object ID number BOOL signed int Boolean value STAT unsigned short int Object state ER signed short int Return value ER_UINT unsigned short int Unsigned 16 bit integer PRI signed char Priority FLGPTN unsigned short int Bit pattern MODE unsigned char Service call operational mode TMO signed long int Timeout unit ticks RELTIM unsigned long int Relative time unit ticks Note The ID type definition in the RI78V4 differs from that of the ulTRON 4 0 specification R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 147 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 4 2 Current state The following lists the status at the point acquired by issuing a service call ref_tsk ref_cyc Macro definition of the current status is performed by standard header file lt ri_root gt include kernel h Table 12 3 Current State Macro Value Description TTS_RUN 0x01 RUNNING state TTS_RDY 0x02 READY state TTS_WAI 0x04 WAITING state TTS_SUS 0x08 SUSPENDED state TTS_WAS Ox0c WAITING SUSPENDED state TTS_DMT 0x10 DORMANT state TCYC_STP 0x00 Non operational state TCYC_STA 0x01 Operational state 12 4 3 WAITING types The following lists WAITING types acquired by issuing a service call ref_tsk Macro definition of the WAITING type is performed by standard header file lt ri_root gt inclu
268. tENESAS Page 234 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 235 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Reference fixed sized memory pool state C format ER ref_mpf ID mpfid T_RMPF pk_rmpf Assembly format MOVW BC LOWW _pk_rmpf MOV A mpfid CALL _ ref_mpf Parameter s 0 Parameter Description l ID mpfid ID number of the fixed sized memory pool to be referenced O T_RMPF pk_rmpf Pointer to the packet returning the fixed sized memory pool state Explanation Stores fixed sized memory pool state packet such as existence of waiting tasks of the fixed sized memory pool specified by parameter mpfid in the area specified by parameter pk_rmpf Note For details about the fixed sized memory pool state packet refer to 12 5 7 Fixed sized memory pool state packet Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 ztENESAS Page 236 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 13 Time Management Functions The following lists the service calls provided by the RI78V4 as the time management functions Table 12 15 Time Management Functions Service Call Function
269. tack requiring switching exists in interrupt entry processing execution The code regarding stack switching during interrupt entry processing is therefore not required Service call issuance The RI78V4 prohibits issuance of service calls in interrupt entry processing The following lists processing that should be executed in interrupt entry processing Vector table address setting Passing of control to relevant processing Interrupt Handlers Boot Processing or the like R20UT3375EJ0100 Rev 1 00 2tENESAS Page 111 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 9 3 Interrupt Handlers The interrupt handler is a routine dedicated to interrupt servicing that is activated when an interrupt occurs and is called from Interrupt Entry Processing The RI78V4 handles the interrupt handler as a non task module independent from tasks Therefore even if a task with the highest priority in the system is being executed the processing is suspended when an interrupt occurs and the control is passed to the interrupt handler The following shows a processing flow from when an interrupt occurs until the control is passed to the interrupt handler Figure 9 1 Processing Flow Interrupt Handler N Interrupt Entry Processing Interrupt handler 9 3 1 Define interrupt handler Interrupt handler registration is realized by coding Interrupt Entry Processing branch instruction to inte
270. tandard header file definition Declares variable Declares and initializes variable Declares variable Receive from data queue polling Polling success processing Polling failure processing Note If no data could be read from the data queue area of the target data queue no data has been written to the data queue area when either of these service calls is issued the contents in the area specified by parameter p_data become undefined R20UT3375EJ0100 Rev 1 00 2015 03 25 ztENESAS Page 71 of 309 CAPTER 5 SYNCHRONIZATION AND COMMUNICATION RI78V4 V2 00 00 FUNCTIONS trev_dtq This service call reads data in the data queue area of the data queue specified by parameter diqid and stores it to the area specified by parameter p_data If no data could be read from the data queue area of the target data queue no data has been written to the data queue area when this service call is issued the service call does not read data but queues the invoking task to the reception wait queue of the target data queue and moves it from the RUNNING state to the WAITING state with time out data reception wait state The receiving WAITING state for a data queue is cancelled in the following cases and then moved to the READY state Receiving WAITING State for a Data Queue Cancel Operation Return Value Data was written to the data queue area of the target data q
271. tart can be aligned at an even address that does not span a 64K 1 boundary Area where the system stack and the task stack are to be allocated kernel_stack RAM area BSS The start can be aligned at an even address in the built in RAM area from Oxf0000 to Oxfffff and that does not span a 64K 1 boundary Area where information items required to implement the functionalities provided by the RI78V4 and information items related to OS resources that change kernel_data RAM area BSS dynamically are allocated as management objects The start can be aligned at an even address in the built in RAM area from 0xf0000 to Oxfffff and that does not span a 64K 1 boundary Area where initial information items of RI78V4 are to be allocated kernel_data_init RAM area BSS The start can be aligned at an even address in the built in RAM area from 0xf0000 to Oxfffff and that does not span a 64K 1 boundary Area where data queues and fixed sized memory pools are to be allocated RAM area BSS The start can be aligned at an even address in the built in RAM area from 0xf0000 to Oxfffff and that does not span a 64K 1 boundary kernel_workO kernel_work1 kernel_work2 kernel_work3 Area where the trace data are to be allocated kernel_data_tra RAM area BSS The start can be aligned at an even address in the ce_n built in RAM area from 0xf0000 to Oxfffff and that does not span a 64K 1 boundary R20UT3375EJ0100 Rev 1
272. task to be executed is loaded 3 2 1 Task state Tasks enter various states according to the acquisition status for the OS resources required for task execution and the occurrence non occurrence of various events In this process the current state of each task must be checked and managed by the RI78V4 The RI78V4 classifies task states into the following six types Figure 3 1 Task State READY state RUNNING state A A A a e WAITING state I WAITING SUSPENDED state gt SUSPENDED state a DORMANT state e R20UT3375EJ0100 Rev 1 00 2tENESAS Page 26 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS DORMANT state State of a task that is not active or the state entered by a task whose processing has ended A task in the DORMANT state while being under management of the RI78V4 is not subject to the RI78V4 scheduling READY state State of a task for which the preparations required for processing execution have been completed but since another task with a higher priority level or a task with the same priority level is currently being processed the task is waiting to be given the CPU s use right RUNNING state State of a task that has acquired the CPU use right and is currently being processed Only one task can be in the running state at one time in the e
273. tate to the SUSPENDED state or from the WAITING state to the WAITING SUSPENDED state If the target task has moved to the SUSPENDED or WAITING SUSPENDED state when this service call is issued the counter manipulation processing is not performed but only the suspend request counter increment processing is executed The SUSPENDED state is cancelled in the following cases and then moved to the READY state SUSPENDED State Cancel Operation Return Value A cancel request was issued as a result of issuing rsm_tsk E OK A cancel request was issued as a result of issuing irsm_tsk E OK Forced release from suspended accept frsm_tsk while suspended E OK Forced release from suspended accept ifrsm_tsk while suspended E OK The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable AE E EA aa sus tsk tskid Suspend task E aiamaa aiiena Note 1 If the target task is the invoking task when this service call is issued it is unlinked from the ready queue and excluded from the RI78V4 scheduling subject Note 2 The suspend request counter managed by the RI78V4 is configured in 7 bit widths If the number of suspend requests exceeds the maximum count value 127 as a res
274. tation of user own coding module and setup of the system configuration file are required Taking in longstatistics by software trace mode The trace information is collected in the RI78V4 s variable secured on the user memory area To use this mode the trace buffer is allocated in kernel_data_trace_n section Select the operation after user up the trace buffer This item is displayed only when Taking in trace chart by software trace mode is selected Default Continue to exection while the buffers overwriting Operation after used up MOWto Select from the drop down list change the buffers Continue to exection It is overwritten sequentially from old while the buffers Pe information Restriction overwriting a the trace taking The RI78V4 stops tracing Specify the size of the trace buffer in bytes Please refer to 15 4 Trace Buffer Size Taking in Trace Chart by Software Trace Mode for the estimate of the size of the trace buffer This item is displayed only when Taking in trace chart by software trace mode is selected Buffer size Default 0x100 How to Directly enter to the text box Only a hexadecimal number can be change entered Restriction Oxa Oxfffe Select the buffer This item is displayed only when Taking in trace chart by software trace mode Select the buffer is selected Default Kernel buffer HOW to Sele
275. te E_RLWAI is returned from the service call that triggered the move to the WAITING state slp_tsk wai_sem or the like to the task whose WAITING state is cancelled by this service call The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable JE i cia kee an Bek Ef rel_wai tskid Release task from waiting JE ieee ware ae Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queues the task at the end of the ready queue corresponding to the priority of the task Note 2 This service call does not perform queuing of forced cancellation requests If the target task is in a state other than the WAITING or WAITING SUSPENDED state E_OBu is returned R20UT3375EJ0100 Rev 1 00 2tENESAS Page 43 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS 4 6 Suspend Task A task is moved to the SUSPENDED state by issuing the following service call from the processing program sus_tsk isus_tsk These service calls add 0x1 to the suspend request counter for the task specified by parameter tskid and then move the target task from the RUNNING state to the SUSPENDED state from the READY s
276. ted Issuance of service call that may cause task state transition Issuance of instruction for returning from non task cyclic handler interrupt handler etc Occurrence of clock interrupt used when achieving TIME MANAGEMENT FUNCTIONS 11 3 Scheduling System As task scheduling methods the RI78V4 employs the Priority level method which uses the priority level defined for each task and the FCFS method which uses the time elapsed from the point when a task becomes subject to the RI78V4 scheduling Priority level method A task with the highest priority level is selected from among all the tasks that have entered an executable state RUNNING state or READY state and given the CPU use right Note In the RI78V4 a task having a smaller priority number is given a higher priority FCFS method The same priority level can be defined for multiple tasks in the RI78V4 Therefore multiple tasks with the highest priority level which is used as the criterion for task selection under the Priority level method may exist simultaneously To remedy this dispatch processing task scheduling processing is executed on a first come first served FCFS basis and the task for which the longest interval of time has elapsed since it entered an executable state READY state is selected as the task to which the CPU use right is granted R20UT3375EJ0100 Rev 1 00 2tENESAS Page 129 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 11 SCHEDULER 11 4
277. ted The activation options specified on the command line is valid Note 1 Specify the input file name command file within 255 characters including the path name Note 2 For the details about the command file refer to 14 2 3 Command file cpu A lt name gt Specifies type specification names of target device If omitted If this activation option is not specified the CF78V4 does not load the device file As a result definitions using interrupt source names defined in the device file can no longer be used in the system configuration file devpath path Retrieves the device file corresponding to the target device specified with cpu A lt name gt from the path folder If omitted The device file is retrieved for the current folder iA lt SIT file gt Specifies the system information table file name to be output If omitted If omitted the CF78V4 interprets it that iAsit asm is specified Note Specify the output file name lt SIT file gt within 255 characters including the path name ni Disables output of the system information table file If omitted If omitted the CF78V4 interprets it that iAsit asm is specified dcA lt C header file gt Specifies the system information header file for C language name to be output If omitted If omitted the CF78V4 interprets it that dcAkernel_id h is specified Note Specify the output file name lt SIT file gt within 255 characters including the path name R2
278. termined by the system One important purpose of a multi task OS is to improve the throughput of the overall system through the parallel processing of multiple tasks R20UT3375EJ0100 Rev 1 00 ztENESAS Page 5 of 309 2015 03 25 TABLE OF CONTENTS CHAPTER 1 OVERVIEW 5 1 1 Outline 5 1 1 1 Real time OS 5 1 1 2 Multi task OS 5 CHAPTER 2 SYSTEM CONSTRUCTION 12 2 1 Outline 12 2 2 Coding of Processing Program 13 2 3 Coding of System Configuration File 13 2 4 Coding of User Own Coding Module 14 2 5 Start address of section 15 2 5 1 kernel_system section 16 2 5 2 kernel_system_timer_n section 16 2 5 3 kernel_system_trace_f section 16 2 5 4 kernel_info section 17 2 5 5 kernel_const section 17 2 5 6 kernel_const_f section 17 2 5 7 kernel_stack section 17 2 5 8 kernel_data section 18 2 5 9 kernel_data_init section 18 2 5 10 kernel_workO kernel_work1 kernel_work2 kernel_work3 section 18 2 5 11 kernel_data_trace_n section 18 2 5 12 kernel_const_trace_f section 19 2 6 Creating Load Module 20 2 7 Embedding System 25 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 26 3 1 Outline 26 3 2 Tasks 26 3 2 1 Task state 26 3 2 2 Task priority 29 3 2 3 Create task 29 3 2 4 Delete task 29 3 2 5 Basic form of tasks 30 3 2 6 Internal processing of task 31 3 3 Activate Task 32 3 3 1 Queuing an activation reque
279. tes include the stack size when the _kernel_int_entry function is called required to be called when an interrupt starts _kernel_int_entry only retires the 20 bytes of data from the stack it does not replace it The data is recovered upon the call to the _kernel_int_exit function which must be called when the interrupt ends Example 1 Task taski uses the twai_flg and snd_mbx service calls and has no other functions or processes that use the stack If interrupts are not accepted in the task interrupts are not accepted in task1 so Expression 1 is the formula for calculating stack usage Because there are no functions or processes that use the stack the size used by the user is 0 When the size of arguments to all service calls is investigated the results are as shown below Service call argument size twai_flg 4 bytes Service call argument size snd_mbx 0 bytes The largest stack size is used in the call to twai_flg so this is specified in Expression 1 Task stack size size used by user service call argument size twai_flg 6 0 4 6 10 bytes The size specified in the system configuration file will be the above minus 6 bytes which equals 4 bytes Example 2 In task task1 function A using 12 bytes of stack makes a twai_flg service call and function B using 20 bytes of stack makes a snd_mbx service call Since interrupts are accepted in the task Expression 2 is used as the calculation formula List the patterns in order to
280. tflag Cancel Operation Return Value A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing set_flg A bit pattern that satisfies the required condition was set to the target eventflag as a result of E OK issuing iset_flg Forced release from waiting accept rel_wai while waiting E_RLWAI Forced release from waiting accept irel_wai while waiting E_RLWAI The following shows the specification format of required condition wfmode wimode TWF_ANDW Checks whether all of the bits to which 1 is set by parameter waiptn are set as the target eventflag wfmode TWF_ORW Checks which bit among bits to which 1 is set by parameter waiptn is set as the target eventflag The following describes an example for coding this service call func_task VP_INT exinf ercd wai_flg flgid waiptn wfmode amp p_flgptn include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void ER ercd Declares variable ID flgid ID_flgA Declares and initializes variable FLGPTN waiptn 0B1110 Declares and initializes variable ODE wfmode TWF_ANDW Declares and initializes variable FLGPIN p_flgptn Declares variable LP aapa aaa Wait for eventflag waiting forever if ercd E_OK oR aA TER Kf Normal termination process
281. the RUNNING state to the SUSPENDED state from the READY state to the SUSPENDED state or from the WAITING state to the WAITING SUSPENDED state If the target task has moved to the SUSPENDED or WAITING SUSPENDED state when this service call is issued the counter manipulation processing is not performed but only the suspend request counter increment processing is executed SUSPENDED State Cancel Operation Return Value A cancel request was issued as a result of issuing rsm_tsk E OK A cancel request was issued as a result of issuing irsm_tsk E OK Forced release from suspended accept frsm_tsk while suspended E OK Forced release from suspended accept ifrsm_tsk while suspended E OK Note 1 If the target task is the invoking task when this service call is issued it is unlinked from the ready queue and excluded from the RI78V4 scheduling subject R20UT3375EJ0100 2015 03 25 Rev 1 00 RENESAS Page 180 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Note 2 The suspend request counter managed by the RI78V4 is configured in 7 bit widths If the number of suspend requests exceeds the maximum count value 127 as a result of issuing this service call the counter manipulation processing is therefore not performed but E_QOVR is returned Return value Macro Value Description E OK 0 Normal completion E OBJ 41 Object state error specified task is in the DORMANT state E _QO
282. the WAITING state data reception wait state to the READY state or from the WAITING SUSPENDED state to the SUSPENDED state Note Data is written to the data queue area of the target data queue in the order of the data transmission request Return value R20UT3375EJ0100 Rev 1 00 7tENESAS Page 208 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E OK 0 Normal completion Polling failure E_TMOUT 50 There is no space in the target data queue R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 209 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Send to data queue with timeout C format tsnd_dtq ID dtqid VP_INT data TMO tmout Assembly format MOVW DE LOWW _datat 0x00002 MOVW BC LOWW _data MOVW AX tmout_hi PUSH AX MOVW AX tmout_lo PUSH AX MOV A dtqid CALL _ tsnd_dtq Parameter s 0 Parameter Description l ID dtqid ID number of the data queue to which the data element is sent l VP_INT data Data element to be sent to the data queue Specified timeout in tick TMO tmout TMO_FEVR Waiting forever TMO_POL Polling Value Specified timeout Explanation This service call writes data specified by parameter data to the data queue area of the data queue specified by parameter dtqid If there is no available space for writing data in t
283. this service call must be cancelled before the processing program that issued this service call ends Note 2 This service call does not perform queuing of lock requests If the system is in the CPU locked state therefore no processing is performed but it is not handled as an error R20UT3375EJ0100 Rev 1 00 RENESAS 2015 03 25 CHAPTER 12 SERVICE CALLS Page 246 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Note 3 The RI78V4 implements disabling of maskable interrupt acknowledgment bu manipulating the interrupt mask flag register MKxx and the in service priority flag ISPx of the program status word PSW Therefore manipulating of these registers from the processing program is prohibited from when this service call is issued until unl_cpu or iunl_cpu is issued Return value Macro Value Description E OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 2tENESAS Page 247 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Unlock the CPU C format ER unl_cpu void ER iunl_cpu void Assembly format CALL _unl_cpu CALL _iunl_cpu Parameter s None Explanation These service calls change the system status to the CPU unlocked state As a result acknowledge processing of maskable interrupts prohibited through issuance of either loc_cpu or iloc_cpu is enabled and the restriction on service call issuance is rel
284. tification number of the kernel 0x0006 Identification number spver verinf_spver Stores the version number of the ITRON Specification 0x5403 L ITRON4 0 Specification Ver 4 03 00 prver verinf_prver Stores the version number of the kernel 0x01 xx Ver 2 xx prno 0 verinf_prno Stores the kernel version type 0x0 V version prno 1 verinf_prno 0x2 Stores the memory model of the kernel 0x2 Medium model prno 2 verinf_prno 0x4 System reserved area prno 3 verinf_prno 0x6 System reserved area R20UT3375EJ0100 Rev 1 00 7tENESAS Page 160 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS 12 6 Task Management Functions The following lists the service calls provided by the RI78V4 as the task management functions Table 12 8 Task Management Functios Service Call Function Origin of Service Call act_tsk Activate task queues an activation request Task Non task iact_tsk Activate task queues an activation request Task Non task can_act Cancel task activation requests Task Non task sta_tsk Activate task does not queue an activation request Task Non task ista_tsk Activate task does not queue an activation request Task Non task ext_tsk Terminate invoking task Task ter_tsk Terminate task Task chg_pri Change task priority Task Non task ichg_pri Change task priority Task Non task ref_tsk Reference task state Task Non task R20UT33
285. tion Explanation The service call stores version information packet such as kernel maker s code to the area specified by parameter pk_rver Note For details about the version information packet refer to 12 5 9 Version information packet Return value Macro Value Description E_OK 0 Normal completion R20UT3375EJ0100 Rev 1 00 ztENESAS Page 258 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 3 System Information The following describes the format that must be observed when describing the system information in the system configuration file The GOTHIC FONT characters in following descriptions are the reserved words and italic face characters are the portion that the user must write the relevant numeric value Items enclosed by square brackets can be omitted 13 3 1 System stack information Define the following item as system stack information 1 System stack size sys_stksz Only one information item can be defined as stack information The following shows the system stack information format SYS_STK sys_stksz The items constituting the system stack information are as follows 1 System stack size sys_stksz Specifies the system stack size in bytes A value between 0 and 65534 aligned to a 2 byte boundary can be specified for sys_stksz Note 1 The system stack is allocated to the kernel_stack section Note 2 For details about
286. tive project Set build target files For the project add or remove build target files and update the dependencies Note See CS Integrated Development Environment User s Manual Build for details about adding or removing build target files for the project and updating the dependencies The following lists the files required for creating a load module C assembly language source files created in 2 2 Coding of Processing Program Tasks Cyclic Handlers Interrupt Handlers System configuration file created in 2 3 Coding of System Configuration File SYSTEM CONFIGURATION FILE Note Specify cfg as the extention of the system configuration file name If the extension is different cfg is automatically added for example if you designate aaa c as a file name the file is named as aaa c cfg C assembly language source files created in 2 4 Coding of User Own Coding Module Interrupt Entry Processing Boot Processing Initialization Routine Idle Routine Directive file created in 2 5 Start address of section Directive file Files provided by the RI78V4 Trace information file Library files provided by the RI78V4 Kernel library Library files provided by the C compiler assembler package Standard library runtime library etc Note 1 If the system configuration file is added to the Project Tree panel the Realtime OS generated files node is appeared R20UT3375EJ0100 Rev 1 0
287. ts or if you have any other inquiries Note 1 Renesas Electronics as used in this document means Renesas Electronics Corporation and also includes its majority owned subsidiaries Note 2 Renesas Electronics product s means any product developed or manufactured by or for Renesas Electronics Readers Purpose Organization How to Read This Manual Conventions How to Use This Manual This manual is intended for users who design and develop application systems using RL78 family microcontrollers products This manual is intended for users to understand the functions of real time OS RI78V4 manufactured by Renesas Electronics described the organization listed below This manual consists of the following major sections CHAPTER 1 CHAPTER 2 CHAPTER 3 CHAPTER 4 CHAPTER 5 CHAPTER 6 CHAPTER 7 CHAPTER 8 CHAPTER 9 CHAPTER 10 CHAPTER 11 CHAPTER 12 CHAPTER 13 CHAPTER 14 APPENDIX A APPENDIX B OVERVIEW SYSTEM CONSTRUCTION TASK MANAGEMENT FUNCTIONS TASK DEPENDENT SYNCHRONIZATION FUNCTIONS SYNCHRONIZATION AND COMMUNICATION FUNCTIONS MEMORY POOL MANAGEMENT FUNCTIONS TIME MANAGEMENT FUNCTIONS SYSTEM STATE MANAGEMENT FUNCTIONS INTERRUPT MANAGEMENT FUNCTIONS SYSTEM CONFIGURATION MANAGEMENT FUNCTIONS SCHEDULER SERVICE CALLS SYSTEM CONFIGURATION FILE CONFIGURATOR CF78V4 WINDOW REFERENCE CAUTIONS It is assumed that the readers of this manual have general knowledge in the fields of electrical enginee
288. tskpri following priority change processing R20UT3375EJ0100 Rev 1 00 2tENESAS Page 37 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 7 Reference Task State A task status is referenced by issuing the following service call from the processing program ref_tsk Stores task state packet such as current status of the task specified by parameter tskid in the area specified by parameter pk_rtsk The following describes an example for coding this service call inc inc void lude lude func_task T_RTSK UINT UINT UINT ref_tsk tskstat tskpri tskwait wobjid actcnt wupcnt suscnt lt kernel h gt lt kernel_id h gt VP_INT exinf tskid ID_tskA pk_rtsk tskstat tskpri tskwait wobjid actcnt wupcnt suscnt tskid amp pk_rtsk pk_rtsk tskstat pk_rtsk tskpri pk_rtsk tskwait pk_rtsk wobjid pk_rtsk actcnt pk_rtsk wupcnt pk_rtsk suscnt Standard header file definition System information header file definition Declares and initializes variable Declares data structure Declares variable Declares variable Declares variable Declares variable Declares variable Declares variable Declares variable Reference task state Reference task current state Reference task current priority Reference reason for waiting Referen
289. tterns if the required condition is satisfied is set 3 System reserved area iflgptn System reserved area Values that can be specified for iflgptn are limited to 0 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 266 of 309 2015 03 25 RI78V 4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 4 Data queue information Define the following items as data qutue information A OU N The The ID number dtqid Attribute dtqatr Data count dtqcnt memory area name sec_nam Reserved for future use dtq number of data queue information items that can be specified is defined as being within the range of 0 to 127 following shows the data queue information format CRI EF DTQ dtqid dtqatr dtqcnt sec_nam dtq The 1 items constituting the data queue information are as follows ID number dtqid Specifies the ID number for a data queue A value from 0x1 to Oxff or a name can be specified for dtgid Note When a name is specified the CF78V4 automatically assigns an ID number The CF78V4 outputs the relationship between a name and an ID number to the system information header file in the following format Output format to system information header file for C define dtgid ID Output format to system information header file for assembly language dtqid EQU ID Attribute dtqatr Specifies the task queuing method for a data queue The ke
290. ue area when either of these service calls is issued the service call does not read data but E_TMOUT is returned Note If no data could be read from the data queue area of the target data queue no data has been written to the data queue area when either of these service calls is issued the contents in the area specified by parameter p_data become undefined Return value Macro Value Description E OK 0 Normal completion Polling failure E TMOUT 50 No data exists in the target data queue R20UT3375EJ0100 Rev 1 00 2015 03 25 7tENESAS Page 215 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Receive from data queue with timeout C format ER trcev_dtq ID dtqid VP_INT p data TMO tmout Assembly format MOVW AX tmout_hi PUSH AX MOVW AX tmout_lo PUSH AX MOVW BC LOWW _data MOV A dtqid CALL LI trev_dtq Parameter s 0 Parameter Description l ID dtqid ID number of the data queue from which a data element is received O VP_INT p data Data element received from the data queue l TMO tmout Specified timeout in tick TMO_FEVR Waiting forever TMO_POL Polling Value Specified timeout Explanation This service call reads data in the data queue area of the data queue specified by parameter dtqid and stores it to the area specified by parameter p_data If no data co
291. ue in the order of message reception request FIFO order As a result the invoking task is unlinked from the ready queue and is moved from the RUNNING state to the WAITING state receiving waiting state for a mailbox Receiving Waiting State for a mailbox Cancel Operation Return Value A message was transmitted to the target mailbox as a result of issuing snd_mbx E OK Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Note For details about the message packet refer to 12 5 5 Message packet Return value R20UT3375EJ0100 Rev 1 00 2tENESAS Page 222 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Macro Value Description E OK E_RLWAI 49 Normal completion Forced release from waiting accept rel_wai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 223 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Receive from mailbox polling C format ER prcv_mbx ID mbxid T_MSG ppk_msg Assembly format MOVW BC LOWW _ppk_msq MOV A mbxid CALL t _prev_mbx Parameter s 1 0 Parameter Description l ID mbxid ID number of the mailbox from which a message is received O T_MSG ppk_msg Start address of the message packet received from the mailbox Explanati
292. ue is one If this service call is issued for the eventflag to which a task is queued therefore E_ILUSE is returned regardless of whether or not the required condition is immediately satisfied Note 2 The RI78V4 performs bit pattern clear processing 0x0 setting when the required condition of the target eventflag TA_CLR attribute is satisfied Return value Macro Value Description E OK 0 Normal completion E ILUSE 28 Illegal service call use there is already a task waiting for an eventflag with the F TA_WSGL attribute E_RLWAI 49 Forced release from waiting accept rel_wai irel_wai while waiting R20UT3375EJ0100 Rev 1 00 2tENESAS Page 199 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Outline Wait for eventtflag polling C format pol_ flg ID flgid FLGPIN waiptn MODE wfmode FLGPTN p_flgptn Assembly format MOVW DE LOWW _p_flgptn MOVW BC waiptn MOVW AX flgid wfmode CALL _pol_flg Parameter s VO Parameter Description ID flgid ID number of the eventflag wait for l FLGPTN waiptn Wait bit pattern 16 bits Wait mode l MODE wfmode TWF_ANDW AND waiting condition TWF_ORW OR waiting condition O FLGPTN p_flgptn Bit pattern causing a task to be released from waiting Explanation This service call checks whether the bit pattern specified by parameter waipin and the bit patte
293. ueue as a result of issuing E OK snd_dtiq _ Data was written to the data queue area of the target data queue as a result of issuing E OK psnd_dtq Data was written to the data queue area of the target data queue as a result of issuing E OK ipsnd_dtq Data was written to the data queue area of the target data queue as a result of issuing E OK tsnd_dtq Data was written to the data queue area of the target data queue as a result of issuing E OK fsnd_dtq Data was written to the data queue area of the target data queue as a result of issuing E OK ifsnd_dtq Forced release from waiting accept rel_wai while waiting E RLWAI Forced release from waiting accept irel_ wai while waiting E RLWAI Polling failure or timeout E TMOUT The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void task VP_INT exinf ER ercd Declares variable ID dtqid 1 Declares and initializes variable VP_INT p data Declares variable TMO tmout 3600 Declares and initializes variable E ei deviate 6 ay Receive from data queue with timeout ercd trev dtg dtgid amp p_data tmout if ercd E_OK E aina eaa ney Normal termination processing else if ercd E_RLWAI a re E Forced termination processing lse if ercd E_TMOUT
294. uired hardware for the RI78V4 to perform processing Boot processing is called from Interrupt Entry Processing that is assigned to the vector table address to which the CPU forcibly passes the control when a reset interrupt occurs 10 2 1 Define boot processing Boot processing registration is realized by coding Interrupt Entry Processing branch instruction to boot processing to the vector table address to which the CPU forcibly passes control upon occurrence of a reset interrupt The code of Interrupt Entry Processing varies depending on whether boot processing is allocated to the near area or to the far area The following shows examples for coding Interrupt Entry Processing When boot processing is allocated to the near area PUBLIC _boot Vector table address setting _boot VECTOR 0x0000 Jump to boot processing _boot When boot processing is allocated to the far area EXTERN _intent_RESET Declares symbol external referenc SECTION vecttable TEXT Vector table section setting _intent_RESET VECTOR 0x0000 Vector table address setting SECTION textf TEXTF Vector table address setting _intent_RESET BR _ boot Jump to boot processing _boot 10 2 2 Basic form of boot processing Write Boot processing as a function that does not include arguments and return values function name any name The following shows the basic form of boot processing
295. uld be read from the data queue area of the target data queue no data has been written to the data queue area when this service call is issued the service call does not read data but queues the invoking task to the reception wait queue of the target data queue and moves it from the RUNNING state to the WAITING state with time out data reception wait state The receiving WAITING state for a data queue is cancelled in the following cases and then moved to the READY state Receiving WAITING State for a Data Queue Cancel Operation Return Value Data was written to the data queue area of the target data queue as a result of issuing snd_dtq E_OK psnd_diq Data was written to the data queue area of the target data queue as a result of issuing E OK R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 216 of 309 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS Receiving WAITING State for a Data Queue Cancel Operation Return Value Data was written to the data queue area of the target data queue as a result of issuing ipsnd_dtq E OK Data was written to the data queue area of the target data queue as a result of issuing tsnd_dtq E_OK Data was written to the data queue area of the target data queue as a result of issuing fsnd_dtq E_OK Data was written to the data queue area of the target data queue as a result of issuing E OK ifsnd_dtq _ Forced release from waiting
296. ult of issuing this service call the counter manipulation processing is therefore not performed but E_QOVR is returned R20UT3375EJ0100 Rev 1 00 RENESAS 2015 03 25 Page 44 of 309 RI78V4 V2 00 00 CHAPTER 4 TASK DEPENDENT SYNCHRONIZATION FUNCTIONS 4 7 Resume Suspended Task The SUSPENDED state is cancelled by issuing the following service call from the processing program rsm_tsk irsm_tsk This service call subtracts 0x1 from the suspend request counter for the task specified by parameter tskid and then cancels the SUSPENDED state of the target task As a result the target task is moved from the SUSPENDED state to the READY state or from the WAITING SUSPENDED state to the WAITING state If a suspend request is queued subtraction result is other than 0x0 when this service call is issued the counter manipulation processing is not performed but only the suspend request counter decrement processing is executed The following describes an example for coding this service call include lt kernel h gt Standard header file definition include lt kernel_id h gt System information header file definition void func_task VP_INT exinf ID tskid ID_tskA Declares and initializes variable EP cele ee eee af rsm_tsk tskid Resume suspended task F aeann iaa awan Note 1 If the target task is moved to the READY state after this service call is issued this service call also re queue
297. um required software for the RI78V4 to perform processing and is called from Boot Processing The following processing is executed in the kernel initialization module Securement of memory area Creating and registering management objects Calling of initialization routine Passing of control to scheduler Note The kernel initialization module is part of the functions provided by the RI78V4 The user therefore need not code the processing contents of the kernel initialization module R20UT3375EJ0100 Rev 1 00 2tENESAS Page 127 of 309 2015 03 25 CHAPTER 10 SYSTEM CONFIGURATION MANAGEMENT RI78V4 V2 00 00 FUNCTIONS 10 5 Reference Version Information Version information is referenced by issuing the following service call from the processing program ref_ver The service call stores version information packet such as kernel maker s code to the area specified by parameter pk_rver The following describes an example for coding this service call include lt kernel h gt include lt kernel_id h gt void func_task VP_INT exinf T_RVER pk_rver UH maker UH prid UH spver UH prver UH prno 4 PP giant eta uf ref_ver amp pk_rver maker pk_rver maker prid pk_rver prid spver pk_rver spver prver pk_rver prver prno 0 pk_rver prno 0 prno 1 pk_rver prno 1 JE ehawaa wien aa Ef Standard header file definition System information h
298. 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 El
299. up request count rtsk_suscnt EQU 0x10 Suspension count The following shows details on task state packet T_RTSK tskstat rtsk_tskstat Stores the current state of the task TTS_RUN RUNNING state TTS_RDY READY state TTS_WAI WAITING state TTS_SUS SUSPENDED state TTS_WAS WAITING SUSPENDED state TTS_DMT DORMANT state tskpri rtsk_tskpri Stores the current priority of the task tskbpri rtsk_tskbpri System reserved area tskwait rtsk_tskwait Stores the reason for waiting TTW_NONE Has not moved to the WAITING state R20UT3375EJ0100 Rev 1 00 2tENESAS Page 151 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 12 SERVICE CALLS TTW_SLP A task enters this state if the counter for the task registering the number of times the wakeup request has been issued indicates 0x0 upon the issuance of a slp_tsk or tslp_tsk TTW_DLY A task enters this state upon the issuance of a dly_tsk TTW_SEM A task enters this state if it cannot acquire a resource from the relevant semaphore upon the issuance of a wai_sem or twai_sem TTW_FLG A task enters this state if a relevant eventflag does not satisfy a predetermined condition upon the issuance of a wai_flg or twai_fig TTW_SDTQ A task enters this state if cannot send a data to the relevant data queue upon the issu ance of a snd_dtg or tsnd_dtq TTW_RDTQ A task enters this state if cannot receive a data from the relevant data queue upon the issuance of a rev_dtq
300. upts Figure 9 3 Multiple Interrupts Interrupt Interrupt Interrupt handler handler servicing Task Level 3 Level 2 Level 1 Interrupt servicing Level 0 lt i of El function E gt return Calling of DI function g return B return B return R20UT3375EJ0100 Rev 1 00 RENESAS 2015 03 25 Page 119 of 309 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS When control moves to an interrupt handler then the state changes to acceptance of maskable interrupts enabled IE 1 For this reason multiple interrupts are generally accepted from interrupt handlers Multiple interrupts are likewise accepted from timer interrupts and cyclic handlers called from them When control moves to an interrupt process then the state changes to acceptance of maskable interrupts disabled because the RI78V4 does not mediate the behavior is in accordance with that of the microcontroller For this reason multiple interrupts are generally not accepted from interrupt processes To enable the acceptance of multiple interrupts it is necessary to call the El function from the interrupt process It is not allowed to accept multiple interrupt handlers from an interrupt process and behavior is not guaranteed if this occurs If a user application enables multiple interrupts then it is necessary to set the interrupt level of the interrupt handler process as shown below Table
301. urned Note 2 An start code staca is passed to the task activated by issuing this service call R20UT3375EJ0100 Rev 1 00 2tENESAS Page 33 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 4 Cancel Task Activation Requests An activation request is cancelled by issuing the following service call from the processing program can_act This service call cancels all of the activation requests queued to the task specified by parameter tskid sets the activation request counter to 0x0 When this service call is terminated normally the number of cancelled activation requests is returned The following describes an example for coding this service call ER_UINT ercd ID tskid if ercd gt 0x0 include lt kernel h gt include lt kernel_id h gt void func_task VP_INT exinf ercd can_act tskid LE ranted oman Rng Standard header file definition System information header file definition Declares variable Declares and initializes variable Cancel task activation requests Normal termination processing R20UT3375EJ0100 Rev 1 00 2015 03 25 2tENESAS Page 34 of 309 RI78V4 V2 00 00 CHAPTER 3 TASK MANAGEMENT FUNCTIONS 3 5 Terminate Task The RI78V4 provides two types of interfaces for task termination termination of invoking task and forced termination of other tasks 3 5 1 Terminate invoking task An inv
302. used to set IE to 0 Immediately before starting a task specifying interrupts as enabled an El instruction is used to set IE to 1 Immediately before starting the idle routine an El instruction is used to set IE to 1 Inside the __kernel_int_entry function which performs interrupt handler start processing IE is set to 1 R20UT3375EJ0100 Rev 1 00 2tENESAS Page 117 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS 9 4 3 Controlling enabling disabling of interrupts in user processes User applications use the El function or El instruction and DI function or DI instruction to manipulate interrupts In a task or other user process using the DI function disables all maskable interrupts from being accepted using the El function enables maskable interrupts to be accepted in accordance with the state of the ISP1 and ISPO bits The RI78V4 sets whether interrupts are enabled or disabled upon start of the user process The states are listed below Table 9 2 States Enabling and Disabling Interrupts upon Process Start Process to Start IE ISP1 ISPO Interrupt Enabled Disabled on Start Interrupts disabled behavior is not Initialization routine 0 1 1 guaranteed when it is enabled by the process idie r tne A A 1 Interrupts enabled all interrupt levels accepted When interrupts specified as A A A Interrupts enabled all interrupt levels enabled acce
303. uted R20UT3375EJ0100 Rev 1 00 ztENESAS Page 109 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 9 INTERRUPT MANAGEMENT FUNCTIONS CHAPTER9Y INTERRUPT MANAGEMENT FUNCTIONS This chapter describes the interrupt management functions performed by the RI78V4 9 1 Outline The RI78V4 provides as interrupt management functions related to the interrupt handlers activated when a maskable interrupt is occurred In the RI78V4 interrupt servicing managed by the RI78V4 is called interrupt handler which is distinguished from interrupt servicing that operates without being managed by the RI78V4 The following lists the differences between interrupt handlers and interrupt servicing Table 9 1 Differences Between Interrupt Handlers and Interrupt Servicing Interrupt Handler Interrupt Servicing Service call issuance Available Not available Maskable interrupt Interrupt type Maskable interrupt Software interrupt Reset interrupt Interrupt priority level Levels 2 3 Levels 0 1 Definition in the re Defines in DEF_INH Not define in DEF_INH system configuration file It is also possible to assign a level of 2 or 3 to an application that disables multiple interrupts Note 1 The interrupt priority level is set using the priority specification flag register of the target CPU Note 2 The RI78V4 does not execute initialization of hardware that creates interrupts clock controller etc This initializati
304. yword that can be specified for dtqatr is TA_TFIFO only TA_TFIFO Task wait queue is in FIFO order Data count dtgent memory area name sec_nam Specifies the maximum number of data units that can be queued to the data queue area of a data queue and the name of the memory area secured for the data queue area Only values from 0x0 to Oxff can be specified for dtqcnt and only memory area name kernel_workO kernel_work1 kernel_work2 kernel_work3 can be specified for sec_nam section for data allocation kernel_work0 allocates data queue to kernel_workO section kernel_work1 allocates data queue to kernel_work1 section kernel_work2 allocates data queue to kernel_work2 section kernel_work3 allocates data queue to kernel_work3 section Reserved for future use dtq System reserved area Values that can be specified for dtq are limited to NULL characters R20UT 3375EJ0100 Rev 1 00 2tENESAS Page 267 of 309 2015 03 25 RI78V4 V2 00 00 CHAPTER 13 SYSTEM CONFIGURATION FILE 13 4 5 Mailbox information Define the following items as mailbox information 1 Mailbox name mbxid 2 Attribute queuing method mbxatr 3 System reserved area maxmpri 4 System reserved area mprihd The number of mailbox information items that can be specified is defined as being within the range of 0 to 127 The following shows the mailbox information format CRE_MBX mbxid mbxatr maxmpri
Download Pdf Manuals
Related Search
Related Contents
SMART5 NJ 290-3.0 Samsung 215TW Priručnik za korisnike スカイウォーカーSW-ⅣPC 取扱説明書 MANUAL DE INSTRUCCIONES para las prensas transfer Secabo Addictive Drums日本語マニュアル Where to Start with NI ELVIS Mode d`emploi LG SU/SZ CHASSIS User's Manual manuel MAXI DMX.indd GH-KS 2440 Copyright © All rights reserved.
Failed to retrieve file