Home

Renesas M3T-MR100 User's Manual

image

Contents

1. sse 188 vrcv dtq Receive from Short data queue ccccccsscscccccsceesessececececcecsesessaeeeeecsesenesssaeeeseesecseneneaaaas 191 vprcv dtq Receive from Short data queue polling sese 191 viprcv dtq Receive from Short data queue polling handler only eee 191 vtrev_dtq Receive from Short data queue with timeout sss nere 191 vref dtq Reference Short data queue status eene nenne nono noncononannnnn nacos 194 viref dtq Reference Short data queue status handler only sese 194 5 16 Extended Function Reset Funcion aa as 196 vrstudta Clear data UE APA lada 197 vrst vdtq Clear Short data queue area ooococcccnnnnonononononcnnonnnnnnonononncnnononnn nono nnnrononnnnn nono eren esten enters 199 vrstimbx Clear mailbox area nonne e He TER RAI cauere ine TER oae usu e dore te Macatee 201 vrst mpf Clear fixed size memory pool area oooonccocococnncnnnnnononnnononnonononnnn nono nononnonnnnn nnne ener nennen nns 208 vrst_mpl Clear variable size memory pool ALVEA cccccccccceceesesssceeececseeessnseceeececseesesetseaeeeeeeseeenees 204 Applications Development Procedure Overview sese 205 0 1 Overview xs acie reser e te ee ER ee debe eer dete ele ee rte eee eee cet eve Erden eure p e bate NRS 205 6 2 Development Procedure Example ooooooococnnccnnnononononnnonocnnnnanononononn
2. esses 57 Figure 4 24 Ready Queue Management by rot rdq Service Call eese 58 Figure 4 25 Interrupt process floW cccccesssssccceceesessnsececcesececeesensececececsesenssseseeeseeesesesenssaeeesenenes 59 Figure 6 1 MR100 System Generation Detail Flowchart esee 206 Tagure 6 2 Program Examiple gre yea er i 208 Figure 6 3 Configuration File Example sosisini anis a A eee enn 209 Figure 6 4 Configurator Execution occcoooccncnonocnnonononnnnnnonononcnononnncnnnnnnnnnnnnnnnnnnnnn nn anno nennen nennen nns 209 Figure 6 5 System Generation cccccccccsssccccssssececesssececssssececeesseeecsssseeeesssseeecnesseeeeeesseeeenesaeeeenaes 210 Figure 7 1 Example Infinite Loop Task Described in C Language eee 211 Figure 7 2 Example Task Terminating with ext tsk Described in C Language 212 Figure 7 3 Example of Kernel Interrupt Handler sess 213 Figure 7 4 Example of Non kernel Interrupt Handler esseeeeeeeennenen 213 Figure 7 5 Example Cyclic Handler Written in C Language eese 214 Figure 7 6 Example Infinite Loop Task Described in Assembly Language sses 215 Figure 7 7 Example Task Terminating with ext tsk Described in Assembly Language 215 Figure 7 8 Example of kernel OS depend interrupt handler
3. No Item Content 1 Fixed size memory pool ID 1 255 2 Number of fixed size memory block 1 65535 3 Size of fixed size memory block 4 65535 4 Supported attributes TA_TFIFO Waiting tasks enqueued in order of FIFO TA_TPRI Waiting tasks enqueued in order of priority 5 Specification of memory pool area Area to be acquired specifiable by a section Table 5 14 List of Fixed size memory pool Function Service Call No Service Call Function System State T N E D U 1 get mpf S B Aquires fixed size memory block O O O 2 pget mpf S B Aquires fixed size memory block O 0 00 3 ipget mpf polling O JO JO O 4 tget_mpf S Aquires fixed size memory block O O O with timeout 5 rel_mpf SIB Releases fixed size memory block O olojo 6 irel mpf OJO JO O 7 ref mpf References fixed size memory pool status O O JO O 8 iref mpf O JO JO O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state U Can be called from CPU unlocked state D Can be called from dispatch disabled state L Can be called from CPU locked state 135 get mpf pget mpf ipget mpf tget mpf C Language API ER ercd get_mpf ER ercd pget_mpf ER ercd ER ercd tget_mpf Parameters ID mpfid VP p blk TMO tmout A
4. on Time Figure 3 4 Time division Task Operation As indicated above the kernel changes the task to execute at fixed time intervals This task switching may also be referred to as dispatching The factors causing task switching dispatching are as follows e Task switching occurs upon request from a task e Task switching occurs due to an external factor such as interrupt When a certain task is to be executed again upon task switching the system resumes its execution at the point of last inter ruption See Figure 3 5 10 Program execution Program execution interrupt resumed Key input Task During this interval it R t trol a O appears that the key input microcomputer is haled Task Figure 3 5 Task Execution Interruption and Resumption In the state shown in Figure 3 5 it appears to the programmer that the key input task or its microcomputer is halted while another task assumes execution control Task execution restarts at the point of last interruption as the register contents prevailing at the time of the last interruption are recovered In other words task switching refers to the action performed to save the currently executed task register contents into the associated task management memory area and recover the register contents for the task to switch to To establish the kernel therefore it is only necessary to manage the register for each task and change the register contents upon each task switch
5. Return Parameters ER ercd Terminated normally E OK T RSEM pk rsem Pointer to the packet to which semaphore status is returned Contents of pk rsem typedef struct t rsem ID wtskid 0 2 ID number of the task at the head of the semaphore s wait queue UINT semcnt 2 4 Current semaphore resource count T_RSEM Assembly language APT include mr100 inc ref sem SEMID PK RSEM iref sem SEMID PK RSEM Parameters SEMID ID number of the target semaphore PK RSEM Pointer to the packet to which semaphore status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target semaphore Al Pointer to the packet to which semaphore status is returned Error code None Functional description This service call returns various statuses of the semaphore indicated by semid wiskid Returned to wtskid is the ID number of the task at the head of the semaphore s wait queue the next task to be dequeued If no tasks are kept waiting TSK_NONE is returned semcnt Returned to semcnt is the current semaphore resource count If this service call is to be issued from task context use ref sem if issued from non task context use iref sem 106 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h vo
6. E OK lt lt Example statement in assembly language gt gt include mr100 inc GLB task _g dtq WORD 1234H task PUSH W R1 PUSH W R2 PUSHM R6R4 vtsnd dtq ID_DTQ1 g dtq 100 PUSH W R1 PUSH W R2 vpsnd dtq ID_DTQ2 0FFFFH PUSH W R1 PUSH W R2 vfsnd dtq ID_DTQ3 0ABCDH 190 vrcv dtq Receive from Short data queue vprcv dtq Receive from Short data queue polling viprcv dtq Receive from Short data queue polling handler only vircv_dtq Receive from Short data queue with timeout C Language API 1 ER ercd vrcv dtq ID dtqid H p data ER ercd vprcv dtq ID dtqid H p data ER ercd viprcv dtq ID dtqid H p data ER ercd vtrcv dtq ID dtqid H p data TMO tmout Parameters ID vdtqid ID number of the Short data queue from which to receive TMO tmout Timeout value vtrev_dtq H p_data Pointer to the start of the area in which received data is stored O Return Parameters ER ercd Terminated normally E_OK or error code H p_data Pointer to the start of the area in which received data is stored Assembly language APT include mr100 inc vrcv dtg VDTOID vprcv dtq VDTOID viprev_dtq VDTQID vtrcv dtq VDTQID TMO Parameters VDTQID ID number of the Short data queue from which to receive TMO Timeout value trev_dtq Register contents after service call is issued vrcv dtq vprcv dtq viprcv dtq Register name Content after service call is issued
7. Parameters VDTQID Short data queue ID to be cleared Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Short data queue ID to be cleared Error code None Functional description 1 This service call clears the data stored in the Short data queue indicated by vdtqid If the Short data queue area has no more areas to be added and tasks are enqueued in a data transmission waiting queue all of the tasks enqueued in the data trans mission waiting queue are released from WAITING state Furthermore the error code EV RST is returned to the tasks that have been released from WAITING state Even when the number of Short data queues defined is 0 all of the tasks enqueued in a data transmission waiting queue are released from WAITING state This service call can be issued only from task context It cannot be issued from non task context 199 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task1 void vrst vdtq ID vdtql Example statement in assembly language include mr100 inc GLB task task PUSH W R2 vrst vdtq ID_VDTQ1 200 vrst mbx Clear mailbox area C Language APT ER ercd vrst_mbx ID mbxid Parameters ID mbxid Mailbox ID to be cleared Return Parameters ER ercd Terminated normal
8. system stack size System stack size priority Maximum value of priority system IPL Kernel mask level tic_deno Time tick denominator tic nume Time tick numerator message pri Maximum message priority value 5 3 All items except task definition can omitted If omitted definitions in the default configuration file are referenced 229 lt lt Content gt gt 1 System stack size Definition format Numeric value Definition range 6 or more Default value 400H Define the total stack size used in service call and interrupt processing 2 Maximum value of priority value of lowest priority Definition format Numeric value Definition range 1 to 255 Default value 32 Define the maximum value of priority used in MR100 s application programs This must be the value of the highest priority used 3 Kernel mask level Definition format Numeric value Definition range 1to7 Default value 7 Set the IPL value in service calls that is the OS interrupt disable level 4 Time tick denominator Definition format Numeric value Definition range Fixed to 1 Default value 1 Set the denominator of the time tick 5 Time tick numerator Definition format Numeric value Definition range 1 to 65 535 Default value 1 Set the numerator of the time tick The system clock interrupt interval is determined by the time
9. eese nennen nennen e ennt nett nr esse eren tenens 25 3 4 8 X Task Priority and Waiting Queue esee eene eene ren ee ennt nennt nnn nns seen tennis 26 SAA Task Control Block hOB dass 27 a AS a DV SECIN SLALES EAE E E E tU TI E AE EE A A 28 3 5 1 Task Context and Non task Context cccccccecccssscescsenececssaececseeesecsesseeecseesaeseesesaeeseneseeeeneaas 28 3 5 2 Dispatch Enabled Disabled States essent eren entere eee en entrare 30 3 5 3 CPU Locked Unlocked States tae r AE A EE EAE a E ESS 30 3 5 4 Dispatch Disabled and CPU Locked States seen eene enne 30 3 6 Regarding Interrupts csi d aana aiii 31 3 6 1 Types of Interrupt Handler en tede rte rie pii eere 31 3 6 2 The Use of Non maskable Interrupt cccoconocononnncnnnonnnonononononononnnnnnononononnonnanonononnnncononannnnonnnos 31 3 6 3 Controlling Interr pts 1 eicere cepere deter dde EE ERR gere Seco og 32 Oil O R a r A TA DM 84 3 7 1 System Stack and User Stack essent enne entere nr neret et en nenne rers en nn 34 4 Kernel A A TON E E E EOE 35 4 1 1 Module Structure A A AAA E 85 7 2 Module Overview ete eret tabaco eria e Hg ee tes 36 4 1 3 Task Management Function ooccccnnnnnnnnnnnononnnnonnanononcnnononnnnononnnnoncononnnnnnnnnnrncononnano nena no cconannnnns 37 4 1 4 Synchronization functions attached to task oo
10. The sections of the system stack and user stack each are located in the manner shown below However the diagram shown below applies to the case where the stack areas for all tasks are located in the stack section during configuration 264 SFR A User satck of TaskID No 1 User satck of TaskID No 2 User satck of TaskID No n Stack Section Figure 10 2 Layout of Stacks 265 10 1 1 User Stack Calculation Method User stacks must be calculated for each task The following shows an example for calculating user stacks in cases when an application is written in the C language and when an application is written in the assembly language When an application is written in the C language Using the stack size calculation utility of NC100 calculate the stack size of each task The necessary stack size of a task is the sum of the stack size output by the stack size calculation utility plus a context storage area of 48 bytes When an application is written in the assembly language Sections used in user program The necessary stack size of a task is the sum of the stack size used by the task in subroutine call plus the size used to save registers to a stack in that task Sections used in MR100 The sections used in MR100 refer to a stack size that is used for the service calls issued MR100 requires that if you issue only the service calls that can be issued from tasks 8bytes of area be allocated for storing
11. Definition format Symbol or function name Definition range None Default value None Define the entry address of a task When written in the C language add at the end or at the beginning of the function name you have defined The function name defined here causes the following declaration statement to be output in the kernel id h file pragma TASK V4 Function Name 234 3 User stack size of task Definition format Numeric value Definition range 12 or more Default value 256 Define the user stack size for each task The user stack means a stack area used by each individual task MR100 requires that a user stack area be allocated for each task which amount to at least 12 bytes 4 Initial priority of task Definition format Numeric value Definition range 1 to maximum value of priority in system definition Default value 1 Define the priority of a task at startup time As for MR100 s priority the lower the value the higher the priority 5 Regisers Used Definition format Symbol Symbol Definition range Selected from R2RO R3R1 R6R4 R7R5 A0 A1 A2 A3 SB FB Default value All registers Define the registers used in a task MR100 handles the register defined here as a context Specify the R2RO reg ister because task startup code is set in it when the task starts However the registers used can only be selected when the task is written in the a
12. include lt itron h gt include lt kernel h gt include kernel id h void task SYSTIME time Time data storing variable get_tim amp time Refers to the system time lt lt Example statement in assembly language gt gt include mr100 inc GLB task Jg systim blkb 6 task PUSHM Al get tim d g systim 154 isig tim Supply a time tick Functional description 1 This service call updates the system time The isig tim is automatically started every tick time interval ms if the system clock is defined by the configuration file The application cannot call this function because it is not implementing as service call When a time tick is supplied the kernel is processed as follows Updates the system time Starts an alarm handler Starts a cyclic handler Processes the timeout processing of the task put on WAITING state by service call with timeout such as tslp tsk SS 1 2 3 4 155 5 10 Time Management Function Cyclic Handler Specifications of the cyclic handler function of MR100 are listed in Table 5 19 The cyclic handler description languages in item No 4 are those specified in the GUI configurator They are not output to a configuration file nor are the MR100 ker nel concerned with them Table 5 19 Specifications of the Cyclic Handler Function No Item Content 1 Cyclic handler ID 1 255 2 Activation cycle 0
13. include lt kernel h gt include kernel id h void inthand void process iwup tsk ID main Figure 7 3 Example of Kernel Interrupt Handler 7 1 3 Writing Non kernel Interrupt Handler When describing the non kernel interrupt handler in C language observe the following precautions 1 Be sure to declare the return value and argument of the interrupt handler start function as a void type 2 No service call can be issued from a non kernel interrupt handler NOTE If this restriction is not observed the software may malfunction 3 Afunction that is declared to be static cannot be registered as an interrupt handler If you want multiple interrupts to be enabled in a non kernel interrupt handler always make sure that the non kernel interrupt handler is assigned a priority level higher than other kernel interrupt handlers include lt itron h gt include lt kernel h gt include kernel id h void inthand void process Figure 7 4 Example of Non kernel Interrupt Handler 7 1 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in C language observe the following precautions SA configuration file is used to define the relationship between handlers and functions When an kernel interrupt handler is declared with pragma INTHANDLER code for the ret int service call is automatically generated qr you want the non kernel interrupt handler to be assigned
14. 0 2 Task ID waiting for memory block to be acquired unused SIZE fmplsz 4 4 Free memory size in bytes UINT fblksz 8 4 Maximum size of memory that can be acquired immediately in bytes T RMPL Assembly language API include mr100 inc ref mpl MPLID PK RMPL iref mpl MPLID PK RMPL Parameters MPLID ID number of the target variable size memory pool PK RMPL Pointer to the packet to which variable size memory pool status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target variable size memory pool Al Pointer to the packet to which variable size memory pool status is returned Error code None Functional description This service call returns various statuses of the message buffer indicated by mplid wtskid Unused fmplsz A free memory size is returned fblksz The maximum size of memory that can be acquired immediately is returned If this service call is to be issued from task context use ref mpl if issued from non task context use iref mpl 148 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RMPL rmpl ER ercd ercd ref mpl ID MPL1 amp rmpl lt lt Example statement in assembly language gt gt include mr100 inc GLB task r
15. 0x1234 205 start OFF 206 phsatr ON 207 interval_counter 0x20 208 phs_counter 0x10 209 210 cyclic_hand 211 entry address cyh3 212 name ID_cyh3 213 exinf OxFFFF 214 start ON 215 phsatr OFF 216 interval_counter 0x20 217 phs_counter 0x0 218 219 cyclic hand 4 220 entry address cyh4 221 name ID cyh4 222 exinf 0x0 223 start ON 224 phsatr ON 225 interval_counter 0x100 226 phs_counter 0x80 227 228 229 alarm hana 230 entry_address alm1 231 name ID_alm1 232 exinf OxFFFF 233 234 alarm_hand 2 252 235 entry address alm2 236 name ID alm2 237 exinf 0x12345678 238 239 240 241 242 End of Configuration 243 253 8 2 Configurator Execution Procedures 8 2 1 Configurator Overview The configurator is a tool that converts the contents defined in the configuration file into the assembly language include file etc Figure 8 1 outlines the operation of the configurator When used on HEW the configurator is automatically started and an application program is built Executing the configurator requires the following input files e Configuration file XXXX cfg This file contains description of the system s initial setup items It is created in the current directory e Default configuration file default cfg This file contains default values that are referenced when settings in the configura
16. If the target task is in a wait state one of the following causes of wait is returned The values of the respective causes of wait are listed below If the task status is other than a wait state TTS_WAI or TTS WAS tskwait is indeterminate e TTW SLP 0x0001 Kept waiting by slp tsk or tslp tsk TTW DLY 0x0002 Kept waiting by dly tsk TTW SEM 0x0004 Kept waiting by wai sem or twai sem TTW FLG 0x0008 Kept waiting by wai flg or twai flg TTW SDTQ 0x0010 Kept waiting by snd dtq or tsnd dtq TTW RDTQ 0x0020 Kept waiting by rcv dtq or trcv dtq TTW_MBxX 0x0040 Kept waiting by rcv mbx or trcv mbx TTW MPF 0x2000 Kept waiting by get mpf or tget mpf TTW VSDTQ 0x4000 Kept waiting by vsnd_dtq or vtsnd_dtg TTW VRDTQ 0x8000 Kept waiting by vrcv_dtq or vtrcv dtq If this service call is to be issued from task context use ref tst if issued from non task context use iref tst Example program statement Example statement in C language include lt itron h gt include lt kernel h gt include kernel id h void task T RTST rtst ER ercd ercd ref tst ID main amp rtst lt lt Example statement in assembly language gt gt refdata blkb 4 include mr100 inc GLB task task PUSH W R2 PUSH L Al ref_tst ID_TASK2 refdata 33 TTW_VSDTQ and TTW_VRDTQ are the causes of wait outside the scope of ITRON 4 0 Specification 83 5 2 Task Dependent Synchronization Function Specifications of the
17. PUSH W R2 PUSH L A1 ref mpf ID MPF1 H refmpf 142 5 8 Memory Pool Management Function Variable size Memory Pool Specifications of the Variable size Memory pool function of MR100 are listed in Table 5 15 The memory pool area to be acquired can be specified by a section name for each memory pool during configuration Table 5 15 Specifications of the Variable size memory Pool Function No Item Content 1 Variable size memory pool ID 1 255 2 Size of Variable size Memory pool 32 67108864 3 Maximum number of memory blocks to 4 65504 be acquired 4 Supported attributes When memory is insufficient task waiting APIs are not sup ported 5 Specification of memory pool area Area to be acquired specifiable by a section Table 5 16 List of Variable size memory pool Function Service Call No Service Call Function System State T N E D UI L 1 pget_mpl Aquires variable size memory block polling O O JO O 2 rel_mpl Releases variable size memory block O O JO O 3 ref_mpl References variable size memory pool status O O JO O 4 iref_mpl OJO O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled sta
18. R2 ID number of the mailbox from which to receive AI Received message trcv mbx Register name Content after service call is issued RO Error code R2 ID number of the mailbox from which to receive R6R4 Timeout value Al Received message Error code E RLWAI Forced release from waiting E TMOUT Polling failure or timeout or timed out 130 Functional description This service call receives a message from the mailbox indicated by mbxid and stores the start address of the received mes sage in the area pointed to by ppk msg T MSG should be specified with a 32 bit address If data is present in the tar get mailbox the data at the top of the mailbox is received On the other hand if rcv mbx or trcv mbx is issued for a mailbox that has no messages in it the task that issued the ser vice call goes from RUNNING state to a message reception wait state and is enqueued in a message reception waiting queue In that case if the attribute of the specified mailbox is TA TFIFO the task is enqueued in order of FIFO if TA TPRI the task is enqueued in order of priority For prev_mbx and iprcv_mbx the task returns immediately and re sponds to the call with the error code E TMOUT For the trcv mbx service call specify a wait time for tmout in ms units The values specified for tmout must be within Ox7FFFFFFF If any value exceeding this limit is specified the service call may not operate correctly If TMO_POL 0 is specified for tmout i
19. Register contents after service call is issued Register name Content after service call is issued R2RO Error code Canceled wakeup request count Error code E OBJ Object status invalid task indicated by tskid is an inactive state Functional description 1 This service call clears the wakeup request count of the target task indicated by tskid to 0 This means that because the tar get task was in either WAITING state nor WAITING SUSPENDED state when an attempt was made to wake it up by wup tsk or iwup tsk before this service call was issued the attempt resulted in only accumulating wakeup requests and this service call clears all of those accumulated wakeup requests Furthermore the wakeup request count before being cleared to 0 by this service call i e the number of wakeup requests that were issued in vain wupcnt is returned to the issuing task If a wakeup request is issued while the target task is in DORMANT state the error code E OBJ is returned If TSK_SELF is specified for tskid it means specifying the issuing task itself If TSK_SELF is specified for tskid in non task context operation of this service call cannot be guaranteed If this service call is to be issued from task context use can wup if issued from non task context use ican_wup 90 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task
20. The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each alarm handler ID number 1 IDname Definition format Symbol Definition range None Default value None Define the name by which the alarm handler is specified in a program 245 2 Start address Definition format Symbol or Function Name Definition range None Define the start address of the alarm handler The function name defined here causes the following declaration statement to be output in the kernel id h file 3 Extended information Definition format Numeric value Definition range 0 to OXFFFFFFFF Default value 0 Define the extended information of the alarm handler This information is passed as argument to the alarm han dler when it starts Interrupt vector definition This definition is necessary to use Interrupt function lt lt Format gt gt Interrupt Vector Definition interrupt vector Vector No i os int Kernel managed OS dependent interrupt handler entry address Start address pragma switch Switch passed to PRAGMA extended function The vector number can be written in the range of 0 to 255 However whether or not the defined vector number is valid de pends on the
21. W R2 PUSHM R6R4 tget_mpf ID_MPF1 200 138 rel mpf Release fixed size memory block irel mpf Release fixed size memory block handler only C Language API ER ercd rel mpf ID mpfid VP blk ER ercd irel mpf ID mpfid VP blk Parameters ID mpfid ID number of the fixed size memory pool to be released VP bIk Start address of the memory block to be returned Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc rel mpf MPFID BLK irel mpf MPFID BLK Parameters MPFID ID number of the fixed size memory pool to be released BLK Start address of the memory block to be returned Register contents after service call is issued Register name Content after service call is issued RO Error code R3RI Start address of the memory block to be returned R2 ID number of the fixed size memory pool to be released Error code None Functional description 1 This service call releases a memory block whose start address is indicated by blk The start address of the memory block to be released that is specified here should always be that of the memory block acquired by get mpf tget mpf pget mpf or ipget mpf If tasks are enqueued in a waiting queue for the target memory pool the task at the top of the waiting queue is dequeued and linked to a ready queue and is assigned a memory block At this time the task changes state from a memory block wa
22. halfway of the function by return sentence 211 include itron h include kernel h include kernel id h void task void or process Figure 7 2 Example Task Terminating with ext_tsk Described in C Language 7 To specify a task use the string written in the task definition item name of the configura tion file wup tsk ID main 8 To specify an event flag semaphore or mailbox use the respective strings defined in the configuration file For example if an event flag is defined in the configuration file as shown below lag 1 name ID abc hi To designate this eventflag proceed as follows set_flg ID_abc amp setptn 9 To specify a cyclic or alarm handler use the string written in the cyclic or alarm handler definition item name of the configuration file sta cyc ID cyc 10 When a task is reactivated by the sta tsk service call after it has been terminated by the ter tsk service call the task itself starts from its initial state However the external va riable and static variable are not automatically initialized when the task is started The ex ternal and static variables are initialized only by the startup program crtOmr a30 which actuates before MR100 startup 11 The task executed when the MR100 system starts up is setup 12 The variable storage classification is described below The MR100 treats the C language variables as indicated in Table 7 1 C La
23. if snd_dtq or tsnd_dtq is issued for a data queue that is full of data the task that issued the service call goes from RUNNING state to a data transmission wait state and is enqueued in transmission waiting queue kept waiting for the data queue to become available In that case if the attribute of the specified data queue is TA TFIFO the task is enqueued in order of FIFO if TA TPRI the task is enqueued in order of priority For psnd_dtq and ipsnd dtq the task re turns immediately and responds to the call with the error code E TMOUT For the tsnd_dtq service call specify a wait time for tmout in ms units The values specified for tmout must be within Ox 7FFFFFFF time tick value If any value exceeding this limit is specified the service call may not operate correctly If TMO POL O is specified for tmout it means specifying 0 as a timeout value in which case the service call operates the same way as psnd dtq Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as snd dtq If there are no tasks waiting for reception nor is the data queue area filled the transmitted data is stored in the data queue The task placed into WAITING state by execution of the snd dtq or tsnd dtq service call is released from WAITING state in the following cases When the rcv dtq trcv dtq prcv_dtq or iprcv dtq service call is issued before the tmout time elapses wi
24. lt Format gt gt Eventflag Definition flag ID No 1 name Name wait queue Selecting an event flag waiting queue initial pattern Initial value of the event flag wait multi Multi wait attribute clear attribute Clear attribute The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each eventflag ID number 1 3 ID Name Definition format Symbol Definition range None Default value None Define the name with which an eventflag is specified in a program Selecting an event flag waiting queue Definition format Symbol Definition range TA TFIFO or TA TPRI Default value TA TFIFO Select a method in which tasks wait for the event flag If TA TFIFO is selected tasks are enqueued in order of FIFO If TA TPRI is selected tasks are enqueued in order of priority beginning with the one that has the highest priority Initial value of the event flag Definition format Numeric value Definition range 0 to OXFFFFFFFF Default value 0 Specify the initial bit pattern of the event flag 236 4 Multi wait attribute Definition format Symbol Definition range TA WMUL or TA WSGL Default value TA WSGL Specify whether multiple ta
25. sess 216 Figure 7 9 Example of Non kernel Interrupt Handler of Specific Level ooocooocccccconocnncnonoss 216 Figure 7 10 Example Handler Written in Assembly Language eee 217 Figure 7 11 C Language Startup Program crtOmr a30 sese 222 Figure 8 1 The operation of the Configurator eese ener en nnne nnns 255 List of Tables Table 3 1 Task Context and Non task Context essesessssseseeeeeeeee nennen eene ener ener nnne 28 Table 3 2 Invocable Service Calls in a CPU Locked State ccoooooccnonocnnononocannnnnnnnnnnonnnnnncnonannncnnnoss 30 Table 3 3 CPU Locked and Dispatch Disabled State Transitions Relating to dis dsp and loc cpu 30 Table 5 1 Specifications of the Task Management Function ooccccnnocnncnononnncnonnnnnononancnnnnnnnnnnnnnnoss 63 Table 5 2 List of Task Management Function Service Call eese 63 Table 5 3 Specifications of the Task Dependent Synchronization Function sssss 84 Table 5 4 List of Task Dependent Synchronization Service Call sees 84 Table 5 5 Specifications of the Semaphore Function esee eene 100 Table 5 6 List of Semaphore Function Service Call esee een 100 Table 5 7 Specifications of the Eventflag FUnction cccccccccccessssssscececececeesssseceeeeeesesensnseaaeees 108 Table 5 8 List of Eventfla
26. sta cyc CYCNO ista cyc CYCNO Parameters CYCNO ID number of the cyclic handler to be operated Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the cyclic handler to be operated Error code None Functional description This service call places the cyclic handler indicated by cycid into an operational state If the cyclic handler attribute of TA PHS is not specified the cyclic handler is started every time the activate cycle elapses start with the time at which this service call was invoked If while TA PHS is not specified this service call is issued to a cyclic handler already in an operational state it sets the time at which the cyclic handler is to start next If while TA PHS is specified this service call is issued to a cyclic handler already in an operational state it does not set the startup time If this service call is to be issued from task context use sta cyc if issued from non task context use ista cyc 157 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task sta cyc ID cycl lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 sta cyc ID_CYC1 158 stp cyc Stops cyclic handler operation istp cyc Stops cyclic handler operation
27. 2 4 This service call returns various statuses of the alarm handler indicat T RALM Assembly language API include mr100 inc ref_alm ALMID PK_RALM iref alm ALMID PK RALM Parameters ALMID ID number of the target alarm handler PK RALM Pointer to the packet to which alarm handler status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target alarm handler Al Pointer to the packet to which alarm handler status is returned Error code None Functional description This service call returns various statuses of the alarm handler indicated by almid almstat The status of the target alarm handler is returned TALM STA Alarm handler is an operational state TALM STP Alarm handler is a non operational state 4 lefttim The remaining time before the target alarm handler will start next is returned This time is expressed in ms units If the target alarm handler is a non operational state the returned value is indeterminate If this service call is to be issued from task context use ref alm if issued from non task context use iref alm 166 Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task T RALM ralm ER ercd ercd ref alm ID ALM1 amp ralm lt lt Example st
28. 4 Figure 4 9 dly_tsk service call o oooooconnnnonononocanonocononanonononnnononononnononononnononnanononononnnononnnnanonacnnnnnnns 42 Figure 4 10 Exclusive Control by Semaphore essere eene enhn 43 Figure 4 11 Semaphore Counter essssssssssssesseeeee eene enne entere nnne entere nnn seen nnns 43 Figure 4 12 Task Execution Control by Semaphore sese nennen enn 44 Figure 4 13 Task Execution Control by the Eventflag cccononooonononnnononnnonanononcnnnononnanananoncnnonanns 46 ligure 4 14 Data quel E A ei e EI e ET 47 Tagure4 15 Ma1bOxX J i srs AAE SE AAE EEEa beoe dee etes da 48 Figure 4 T6 Message queue eter ee re Festa E Te YEA RATE EXER saldra innata ciendo 49 Figure 4 17 Memory Pool Management sess enne ener nin en nnn seines 50 Figure 4 18 pget mpl processing isan riseiras nnne nennen aaa E ai Aaa aieas aiis 52 Figure 4 19 rel mpl processing ccccccceesssssceccesececeesssnecececeesesessseeececsecseeensseceeesecsesenseaeeessenenes 53 Figure 4 20 Timeout ProcessiQ8 ooococcccnonononnonnnononnnnnnnnnonononnnnnnannan no nora nnne ennt EST TEE E o aR SE as 54 Figure 4 21 Cyclic handler operation in cases where the activation phase is saved 56 Figure 4 22 Cyclic handler operation in cases where the activation phase is not saved 56 Figure 4 23 Typical operation of the alarm handler
29. ID semid Parameters ID semid Semaphore ID number to which returned Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr100 inc sig_sem SEMID isig sem SEMID Parameters SEMID Semaphore ID number to which returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Semaphore ID number to which returned Error code E QOVR Queuing overflow Functional description This service call releases one resource to the semaphore indicated by semid If tasks are enqueued in a waiting queue for the target semaphore the task at the top of the queue is placed into READY state Conversely if no tasks are enqueued in that waiting queue the semaphore resource count is incremented by 1 If an attempt is made to return resources sig sem or isig sem service call causing the semaphore resource count value to ex ceed the maximum value specified in a configuration file maxsem the error code E QOVR is returned to the service call issuing task with the semaphore count value left intact If this service call is to be issued from task context use sig sem if issued from non task context use isig sem 101 Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task if sig
30. RO Error code R1 Received data R2 ID number of the Short data queue from which to receive vtrcv dtq Register name Content after service call is issued RO Error code R1 Received data R2 ID number of the Short data queue from which to receive R6R4 Timeout value Error code E_RLWAI Forced release from waiting E_TMOUT Polling failure or timeout or timed out 191 Functional description This service call receives data from the Short data queue indicated by vdtqid and stores the received data in the area pointed to by p data If data is present in the target Short data queue the data at the top of the queue or the oldest data is received This results in creating a free space in the Short data queue area so that a task enqueued in a transmission waiting queue is released from WAITING state and starts sending data to the Short data queue area If no data exist in the Short data queue and there is any task waiting to send data i e data bytes in the Short data queue area 0 data for the task at the top of the data transmission waiting queue is received As a result the task kept waiting to send that data is released from WAITING state On the other hand if vrev_dtq or vtrev_dtq is issued for the Short data queue which has no data stored in it the task that issued the service call goes from RUNNING state to a data reception wait state and is enqueued in a data reception waiting queue At this time the task is enqueued in orde
31. RTST pk rtst Pointer to the packet to which task status is returned Return Parameters ER ercd Terminated normally E OK Contents of pk rtsk typedef struct t rtst STAT tskstat 0 2 Task status STAT tskwait 2 2 Cause of wait T RTST Assembly language APT include mr100 inc ref tst TSKID PK_RTST iref tst TSKID PK RTST Parameters TSKID ID number of the target task PK RTST Pointer to the packet to which task status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code AO ID number of the target task Al Pointer to the packet to which task status is returned Error code None 82 Functional description This service call inspects the status of the task indicated by tskid and returns the current information on that task to the area pointed to by pk rtst as a return value If TSK SELF is specified the status of the issuing task itself is inspected If TSK SELF is specified for tskid in non task context operation of the service call cannot be guaranteed tskstat task status tskstat has one of the following values returned to it depending on the status of the specified task e TTS RUN 0x0001 RUNNING state e TTS RDY 0x0002 READY state e TTS WAI 0x0004 WAITING state e TTS SUS 0x0008 SUSPENDED state e TTS WAS 0x000C WAITING SUSPENDED state e TTS DMT 0x0010 DORMANT state tskwait cause of wait
32. TMOUT 4 When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI When the target Short data queue being waited for is initialized by the vrst vdtq service call is sued from another task The error code returned in this case is EV RST For vfsnd dtq and vifsnd dtq the data at the top of the Short data queue or the oldest data is removed and the transmitted data is stored at the tail of the Short data queue If the Short data queue area is not filled with data vfsnd dtq and vifsnd_dtq operate the same way as vsnd dtq If dtqcnt 0 there is no task in the wait queue and vfsnd dtq or vifsnd dtq service call is issued error code E ILUSE will be returned If this service call is to be issued from task context use vsnd dtq vtsnd dtq vpsnd dtq vfsnd dtq if issued from non task context use vipsnd dtq vifsnd dtq 189 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h H data 10 void task void if vsnd dtq ID dtq data 0 error Forced released n itf vpsnd dtq ID dtq data 1 error Timeout n LE vtsnd dtq ID dtq data 2 error Timeout In if vfsnd dtq ID dtq data 31 error error n E RLWAI E TMOUT 10 E TMOUT
33. The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are automatically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each memory pool ID number define the items described below 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the memory pool is specified in a program 2 Section name 3 Definition format Symbol Definition range None Default value MR_HEAP Define the name of the section in which the memory pool is located The section defined here must always have an area allocated for it in the section file asm_sec inc or c_sec inc If no section names are defined the memory pool is located in the MR_HEAP section Number of block Definition format Numeric value Definition range 1 to 65 535 Default value 1 Define the total number of blocks that comprise the memory pool 241 4 Size in bytes Definition format Numeric value Definition range 4 to 65 535 Default value 256 Define the size of the memory pool per block The RAM size to be used as a memory pool is determined by this definition number of blocks x size in bytes 5 Selecting a memory pool waiting queue Definition format Symbol Definition range TA TFIFO or TA TPRI Default value TA TFIFO Select a method in whic
34. a CPU locked state 2 No external interrupts are accepted unless their priority levels are higher than the kernel interrupt mask level defined in the configurator 3 Only the following service calls can be invoked from a CPU locked state If any other service calls are invoked operation of the service call cannot be guaranteed ext tsk loc cpu iloc cpu unl cpu iunl cpu sns clx sns loc sns dsp sns dpn The system is freed from a CPU locked state by one of the following operations a Invocation of the unl cpu or iunl cpu service call b Invocation of the ext tsk service call Transitions between CPU locked and CPU unlocked states occur only when the loc cpu iloc cpu unl cpu iunl cpu or ext tsk service call is invoked The system must always be in a CPU unlocked state when the interrupt handler or the time event handler is terminated If either handler terminates while the system is in a CPU locked state handler operation cannot be guaranteed Note that the system is always in a CPU unlocked state when these handlers start Invoking this service call again while the system is already in a CPU locked state does not cause an error in which case task queuing is not performed however If this service call is to be issued from task context use loc cpu if issued from non task context use iloc cpu 172 Example program statement 1 lt lt Example statement in C language include lt itron h gt includ
35. a suspend re quest is issued to a task in READY state the task is placed into SUSPENDED state if issued to a task in WAIT ING state the task is placed into WAITING SUSPENDED state Since MR100 allows only one forcible wait re quest to be nested if sus tsk is issued to a task in a forcible wait state the error E QOVR is returned See Figure 4 7 E QOVR sus tsk sus tsk rsm tsk Task 1L We ARA RUNNING SUSPENDED READY state state state WAITING WAITING state SUSPENDED WAITING state state Number of suspension 0 1 1 0 request Figure 4 7 Forcible wait of a task and resume 40 Forcibly resume suspended task frsm tsk ifrsm tsk Clears the number of suspension requests nested to 0 and forcibly resumes execution of a task Since MR100 al lows only one suspension request to be nested this service call behaves the same way as rsm_tsk and irsm tsk See Figure 4 8 sus tsk frsm tsk Task yo READY state SUSPENDED gt READYstate state WAITING WAITING WAITING state SUSPENDED state state Number of suspension 0 1 0 requests Figure 4 8 Forcible wait of a task and forcible resume Release task from waiting rel_wai irel_wai Forcibly frees a task from WAITING state A task is freed from WAITING state by this service call when it is in one of the following wait states Timeout wait state Wait state entered by slp tsk service call timeout included Event flag timeout i
36. amp msg ID mbx E TMOUT error Timeout n if trcv mbx T MSG amp msg ID mbx 10 E TMOUT error Timeout n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 PUSHM R6R4 trcv mbx ID_MBX1 100 PUSH W R2 rcv mbx HID MBX1 PUSH W R2 prcv mbx HID MBX1 132 ref mbx Reference mailbox status iref mbx Reference mailbox status handler only C Language API ER ercd ref mbx ID mbxid T RMBX pk rmbx ER ercd iref mbx ID mbxid T RMBX pk rmbx Parameters ID mbxid ID number of the target mailbox T RMBX pk rmbx Pointer to the packet to which mailbox status is returned Return Parameters ER ercd Terminated normally E OK T RMBX pk rmbx Pointer to the packet to which mailbox status is returned Contents of pk rmbx typedef struct t rmbx ID wtskid 0 2 Reception waiting task ID T MSG pk msg 4 4 Next message packet to be received T_RMBX Assembly language APT include mr100 inc ref_mbx MBXID PK_RMBX iref mbx MBXID PK RMBX Parameters MBXID ID number of the target mailbox PK RMBX Pointer to the packet to which mailbox status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target mailbox Al Pointer to the packet to which mailbox status is returned Error code None Fun
37. amp time Sets the system time lt lt Example statement in assembly language gt gt include mr100 inc GLB task Jg systim WORD 1111H LWORD 22223333H task PUSHM Al set tim _g_systim 152 get tim Reference system time iget tim Reference system time handler only C Language API ER ercd get tim SYSTIM p systim ER ercd iget tim SYSTIM p systim Parameters SYSTIM p systim Pointer to the packet to which current system time is returned Return Parameters ER ercd Terminated normally E OK SYSTIM p systim Pointer to the packet to which current system time is returned Contents of p systim typedef struct t systim UH utime 0 2 16 high order bits UW Itime 4 4 32 low order bits SYSTIM Assembly language API include mr100 inc get tim PK TIM iget tim PK TIM Parameters PK TIM Pointer to the packet to which current system time is returned Register contents after service call is issued Register name Content after service call is issued RO Error code Al Pointer to the packet to which current system time is returned Error code None Functional description This service call stores the current value of the system time in p systim If this service call is to be issued from task context use get tim if issued from non task context use iget tim 153 Example program statement 1 lt lt Example statement in C language gt gt
38. any tasks waiting for data to be entered in the target data queue and refers to the number of the data in the data queue 2 First In First Out 47 4 1 8 Synchronization and Communication Function Mailbox The mailbox is a mechanism to perform data communication between tasks In Figure 4 15 for example task A can drop a message into the mailbox and task B can retrieve the message from the mailbox Since mailbox based communication is achieved by transferring the start address of a message from a task to another this mode of communication is performed at high speed independently of the message size The kernel manages the message queue by means of a link list The application should prepare a header area that is to be used for a link list This is called the message header The message header and the area actually used by the application to store a message are called the message packet The kernel rewrites the content of the message header as it manages the message queue The message header cannot be rewritten from the application The structure of the message queue is shown in Figure 4 16 The message header has its data types defined as shown below T MSG Mailbox message header T MSG PRI Mailbox message header with priority included Messages in any size can be enqueued in the message queue because the header area is reserved on the application side In no event will tasks be kept waiting for transmission Messages can be assigned
39. area Functional description This service call acquires a memory block from the fixed size memory pool indicated by mpfid and stores the start address of the acquired memory block in the variable p_blk The content of the acquired memory block is indeterminate If the fixed size memory pool indicated by mpfid has no memory blocks in it and the used service call is tget_mpf or get_mpf the task that issued it goes to a memory block wait state and is enqueued in a memory block waiting queue In that case if the attribute of the specified fixed size memory pool is TA_TFIFO the task is enqueued in order of FIFO if TA_TPRI the task is enqueued in order of priority If the issued service call was pget_mpf or ipget_mpf the task returns immediately and responds to the call with the error code E TMOUT For the tget mpf service call specify a wait time for tmout in ms units The values specified for tmout must be within Ox7FFFFFFF time tick value If any value exceeding this limit is specified the service call may not operate correctly If TMO POL O is specified for tmout it means specifying 0 as a timeout value in which case the service call operates the same way as pget mpf Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as get mpf The task placed into WAITING state by execution of the get mpf or tget mpf service call is released from WAITING state
40. based on the maximum memory block size to be acquired You specify the maximum memory block size using the configuration file e Equation for calculating four kinds of block sizes max_memsize X 1 X x 8 41 x 8 ax2 ax 4 ax 8 o 00m ll max_memsize the value specified in the configuration file X data size for block control 8 byte e Example of a configuration file variable memorypool max_memsize 400 lt Maximum size heap_size 5000 If a variable size memory pool is defined as shown above the four kinds of fixed length block sizes are obtained from the define value of max_memsize as 56 112 224 and 448 respectively Furthermore the MR100 calculates the memory re quested by the user based on a specified size to select the appropriate size from the four kinds of fixed length block sizes as it allocates the requested memory In no event will a memory block other than these four kinds of size be allocated Small block method Unlike the normal block method where memory is managed in four kinds of fixed length block sizes the small block me thod manages memory in 12 kinds of fixed length block sizes Since the block sizes in this method are prefixed as shown below there is no need to specify a maximum size during configuration as in the normal block method The block sizes managed by the small block method are the following 12 beginning with the smallest 24 bytes 56 bytes 120 bytes 248 bytes 504
41. code E OBJ is returned This service call forbids specifying the issuing task itself for tskid If this service call is to be issued from task context use rel wai if issued from non task context use irel wai This means that tasks cannot be resumed from SUSPENDED state by this service call Only the rsm_tsk irsm_tsk frsm_tsk and ifrsm_tsk service calls can release them from SUSPENDED state 92 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if rel wai ID main E OK error Can t rel wai main Nin j lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 rel wai HID TASK2 93 sus tsk Suspend task isus tsk Suspend task handler only C Language API ER ercd sus tsk ID tskid ER ercd isus tsk ID tskid Parameters ID tskid ID number of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language APT include mr100 inc sus tsk TSKID isus tsk TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is an inactive state E QOVR Queui
42. context use viprcv dtq 192 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task H data if vrcv dtq ID dtg amp data E RLWAI error forced wakeup n if vprcv dtq ID dtq amp data E TMOUT error Timeout n if vtrcv dtq ID dtq amp data 10 E TMOUT error Timeout n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 PUSHM R6R4 vtrcv dtq ID_DTQ1 TMO_POL PUSH W R2 vprcv dtq ID DTO2 PUSH W R2 vrcv dtq HID DTO2 193 vref dtq Reference Short data queue status viref dtq Reference Short data queue status handler only C Language API ER ercd vref dtq ID vdtqid T RDTQ pk rdtq ER ercd viref dtq ID vdtqid T RDTO pk rdtq Parameters ID vdtqid ID number of the target Short data queue T RDTQ pk rdtq Pointer to the packet to which Short data queue status is returned Return Parameters ER ercd Terminated normally E OK or error code T RDTQ pk rdtq Pointer to the packet to which Short data queue status is returned Contents of pk rdtq typedef struct t rdtq ID stskid 0 2 Transmission waiting task ID ID wtskid 2 2 Reception waiting task ID UINT sdtqcnt 4 4 Data bytes contained in Short data queue T_RDTQ Assembly language APT inclu
43. control Task task Service call Task switching Figure 3 9 Service call This service call is realized by a function call when the application program is written in C language as shown below act tsk ID main 3 Furthermore if the application program is written in assembly language it is realized by an assembler macro call as shown below act tsk HID main 14 3 2 1 Service Call Processing When a service call is issued processing takes place in the following sequence 1 2 3 4 5 6 The current register contents are saved The stack pointer is changed from the task type to the real time OS system type Processing is performed in compliance with the request made by the service call The task to be executed next is selected The stack pointer is changed to the task type The register contents are recovered to resume task execution The flowchart in Figure 3 10 shows the process between service call generation and task switching Key input Task Register Save Service call issuance SP lt OS Processing Task Selection Task gt SP LED illumination Task Register Restore Figure 3 10 Service Call Processing Flowchart 6 A different sequence is followed if the issued service call does not evoke task switching 15 3 2 2 Processing Procedures for Service Calls from Handlers When a service call is issued from a handler
44. description of MR100 service call definition 254 8 2 2 Configuration File xxx cfg System Data Difinition File Sys ram inc sys rom inc Default Configuration File Include File default cfg cfg100 e mr100 inc Template File ID Number Definition File sys ram inc mr100 inc kernel id h MR100 Version File Service call Definition File version kernel sysint h Service call Definition File kernel sysint h Figure 8 1 The operation of the Configurator Setting Configurator Environment Before executing the configurator check to see if the environment variable LIB100 is set correctly The configurator cannot be executed normally unless the following files are present in the directory indicated by the envi ronment variable LIB100 Default configuration file default cfg This file can be copied to the current directory for use In this case the file in the current directory is given priority System RAM area definition database file sys ram inc mr100 inc template file mr100 inc Section definition file c sec inc or asm sec inc Startup file crtOmr a30 or start a30 MR100 version file version Service call definition file kernel sysint h 255 8 2 3 Configurator Start Procedure Start the configurator as indicated below C gt cfg100 vV Eipl Wipl Configuration file name Normally use the extension cfg for the configuration file name The file name can includes spac
45. error code E TMOUT This service call can be issued only from task context It cannot be issued from non task context Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h VP p blk void task if pget mpl ID mpl 200 amp p blk E OK error Not enough memory n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 pget mpl HID MPL1 4200 145 rel mpl Release variable size memory block C Language APT ER ercd rel mpl ID mplid VP blk Parameters ID mplid ID number of Variable size Memory pool of the memory block to be released VP Blk Start address of the memory block to be returned Return Parameters ER ercd Terminated normally E_OK or error code Assembly language APT include mr100 inc rel_mpl MPLID BLK Parameters MPLID ID number of Variable size Memory pool of the memory block to be released BLK Start address of the memory block to be returned Register contents after service call is issued Register name Content after service call is issued RO Error code R3R1 Start address of the memory block to be returned R2 ID number of Variable size Memory pool of the memory block to be released Error code None Functional description 1 This service call releases a memory block whose start addres
46. flag before issuing a service call is 1 Task or y Task or Handler Service call issued service call processing Handler T TCT l l l I flag 1 A 0 1 gt 1 l 1 l e 4 system IPL I MN 4 I l IPL 4 s lt system IPL When the I flag before issuing a service call is 0 Task or Servi lli d service call processin Task or Handler SENICE CATARES B g Handler l l I flag 9 N M 0 IPL 4 lt system IPL 4 4 system IPL 4 Figure 3 24 Interrupt control in a Service Call that can be Issued from a Task independent As shown in Figure 3 23 and Figure 3 24 the interrupt enable flag and IPL change in a service call For this reason if you want to disable interrupts in a user application Renesas does not recommend using the method for manipulating the inter rupt disable flag and IPL to disable the interrupts The following two methods for interrupt control are recommended 1 Modify the interrupt control register SFR for the interrupt you want to be disabled 2 Use service calls loc cpu iloc cpu and unl cpu iunl cpu The interrupts that can be controlled by the loc cpu service call are only the kernel interrupt Use method 1 to control the non kernel interrupts 33 3 7 Stacks 3 7 1 System Stack and User Stack The MR100 provides two types of stacks system stack and user stack e User Stack One user stack is provided for each tas
47. from RUNNING state to a data reception wait state and is enqueued in a data reception waiting queue At this time the task is enqueued in order of FIFO For the prev_dtq and iprcv dtq service calls the task returns immediately and responds to the call with the error code E TMOUT For the trcv dtq service call specify a wait time for tmout in ms units The values specified for tmout must be within Ox 7FFFFFFF time tick value If any value exceeding this limit is specified the service call may not operate correctly If TMO POL O is specified for tmout it means specifying 0 as a timeout value in which case the service call operates the same way as prcv dtq Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as rcv dtq The task placed into a wait state by execution of the rcv dtq or trcv_dtq service call is released from the wait state in the following cases When the rcv dtq trcv dtq prcv_dtq or iprcv dtq service call is issued before the tmout time elapses with task awaking conditions thereby satisfied The error code returned in this case is E OK When the first time tick occurred after tmout elapsed while task awaking conditions remain un satisfied The error code returned in this case is E TMOUT When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The err
48. get tim Reference system time ccccccccccccccssssscececececeessnsececeesececsesssseseceeccseeesssaeeeeeeseseeesssaeeeseeeeesenes 153 iget_tim Reference system time handler only oonconnnnncnnonnnnicnnicnnnnnancnno na nann cano nono nn carac rra cnna ranas 153 Isig tim Supply a time tick oomconnonuononononocnonananananonononnnnnanonenononnononnn nono noroononnnnnn none nrcooronanna nena norons 155 5 10 Time Management Function Cyclic Handler onononcnnnnnncnnnnnnnnnnnncnnoncnncnnnc cocaina eene 156 sta cyc Start cyclic handler operation nennen eene ennt ene ettet nnne seen nen 157 ista cyc Start cyclic handler operation handler only sseeeeeeeeeeee enne 157 stp cyc Stops cyclic handler operation coconnooconcncnnnnnonnnnnnnnnnnnnononnnononononnononnn nono nonnnonononnnno no noncnnonanns 159 istp cyc Stops cyclic handler operation handler only 159 ref cyc Reference cyclic handler status ccccccccccccecssssssececesececceesssseaeeececsecesesssseeeeeceseseeensaeeeeees 160 iref cyc Reference cyclic handler status handler only esee 160 5 11 Time Management Function Alarm Handler ener eene 162 sta alm Start alarm handler operation ccccccccccceessssecceceeeceesessnsececececeesessseeeeeececsesesssseaeeeeeesenes 163 ista_alm Start alarm handler operation handler only eee 163 stp alm Stop alarm handler operati
49. handler only C Language API ER ercd stp_cyc ID cycid ER ercd istp_cyc ID cycid Parameters ID cycid ID number of the cyclic handler to be stopped Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc stp cyc CYCNO istp cyc CYCNO Parameters CYCNO ID number of the cyclic handler to be stopped Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the cyclic handler to be stopped Error code None Functional description This service call places the cyclic handler indicated by cycid into a non operational state If this service call is to be issued from task context use stp cyc if issued from non task context use istp cyc Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task stp cyc ID cycl lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 stp cyc ID_CYC1 159 ref cyc Reference cyclic handler status iref cyc Reference cyclic handler status handler only C Language API ER ercd ref cyc ID cycid T RCYC pk rcyc ER ercd iref cyc ID cycid T RCYC pk rcyc Parameters ID cycid ID number of the target cyclic handler T RCYC pk rcyc Pointer t
50. handler only C Language API ER ercd wup tsk ID tskid ER ercd iwup tsk ID tskid Parameters ID tskid ID number of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr100 inc wup tsk TSKID iwup tsk TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is an inactive state E QOVR Queuing overflow Functional description If the task specified by tskid has been placed into WAITING state by slp tsk or tslp tsk this service call wakes up the task from WAITING state to place it into READY or RUNNING state Or if the task specified by tskid is in WAIT ING SUSPENDED state this service call awakes the task from only the sleeping state so that the task goes to SUS PENDED state If a wakeup request is issued while the target task remains in DORMANT state the error code E OBJ is returned to the service call issuing task If TSK SELF is specified for tskid it means specifying the issuing task itself If TSK SELF is specified for tskid in non task context operation of the service call cannot be guaranteed If this service call is issued to a task that has not been placed in WAITING state or in WAITING SUSPENDED state
51. handlers The stack size used by an interrupt handler that is invoked during a service call can be calculated by the equation below The stack size Bi used by an interrupt handler is shown below C language Using the stack size calculation utility of NC100 calculate the stack size of each interrupt handler Refer to the manual of for the stack size calculation utility detailed use of it Assembly language The stack size to be used by kernel interrupt handler register to be used user size stack size to be used by service call The stack size to be used by non kernel interrupt handler register to be used user size User size is the stack size of the area written by user WAG Context 48bytes 6 gt Interrupt 4bytes lt gt jsr func 32bytes iset_flg ret int gt 84bytes Figure 10 5 Stack size to be used by Kernel Interrupt Handler Written in C language 270 System stack size y used by system clock interrupt handler When you do not use a system timer there is no need to add a system stack used by the system clock interrupt handler The system stack size y used by the system clock interrupt handler is whichever larger of the two cases below 48 maximum size used by cyclic handler 48 maximum size used by alarm handler 72 bytes C language Using the stack size calculation utility of NC100 calculate the stack size of each Alarm or Cyclic handler Refer to the manual of the stack size
52. iact_tsk Example program statement lt lt Example statement in C language include lt itron h gt include lt kernel h gt include kernel_id h void task1 VP_INT stacd ER ercd ercd act_tsk ID task2 void task2 VP_INT stacd ext tsk lt lt Example statement in assembly language gt gt INCLUDE mr100 inc GLB task task PUSH W R2 act tsk HID TASK3 66 can act Cancel task activation request ican act Cancel task activation request handler only C Language API ER UINT actcnt can act ID tskid ER UINT actcnt ican act ID tskid Parameters ID tskid ID number of the task to cancel Return Parameters ER UINT actcnt gt 0 Canceled activation request count actent lt 0 Error code Assembly language API include mr100 inc can act TSKID ican act TSKID Parameters TSKID ID number of the task to cancel Register contents after service call is issued Register Content after service call is issued name R2RO Canceled startup request count or error code Error code None Functional description This service call finds the number of task activation requests enqueued for the task indicated by tskid returns the result as a return parameter and at the same time invalidates all of the task s activation requests Specifying tskid TSK_SELF 0 specifies the issuing task itself If TSK SELF is specified for tskid in non t
53. ina ded genae ae a Eoo feed 79 iref tsk Reference task status handler olla HO d War OG HN d 79 ref tst Reference task status simplified version cccccceccsscssesscssecsseesceseceseessceseessesscsscesseeseaeeas 82 iref tst Reference task status simplified version handler only esee 82 5 2 Task Dependent Synchronization Function eese nennen ete en entente nnne 84 sip tsk Put task to sleep ia A oa ge nn 85 tslp_tsk Put task to sleep with Utieotib oie ii india get la ed deter pita uarie ped ss 85 wup isk Wakeup task eet diia 88 iwup_tsk Wakeup task handler only uota e ote d cotes nist ie Rae dra ede ER ads 88 can wup Cancel wakeup request ccccccssssssccecececcsesesssseceeececsesesssaeceecesesensnssaeeeeeceeesesersseaeeeeecsenes 90 ican_wup Cancel wakeup request handler only c ccccccccceccsecssesscssesescssecsssessessceeecssessessccsseseesnens 90 rel wai Release task from waiting eene ee eet nnne seen enne nn nono ncnncnnonnanananannnno 92 irel wai Release task from waiting handler only sese 92 sus tsk Suspenditaski td ete PA A T dali adi 94 isus_tsk Suspend task handler ala dale 94 rsm_tsk Resume suspended task oconcoocononccnnnnoonoooannnnonnonononnononononnononnnnonononnonononnnnnn nn ness esterne tenir annees 96 irsm tsk Resume suspended task handler only iniu uibledeste dad 96 frsm tsk Forcibly resum
54. interrupts are disabled against acceptance and task scheduling is not performed either The system can be placed into a CPU locked state or a CPU unlocked state by the loc cpu iloc cpu or unl cpu iunl cpu service call respectively Whether the system is in a CPU locked state can be known by the sns loc service call The service calls that can be issued from a CPU locked state are limited to those that are listed in Table 3 2 Table 3 2 Invocable Service Calls in a CPU Locked State loc cpu iloc cpu unl cpu iunl cpu ext tsk exd tsk sns tex sns c x sns loc sns dsp sns dpn 3 5 4 Dispatch Disabled and CPU Locked States In uITRON 4 0 Specification the dispatch disabled and the CPU locked states are clearly discriminated Therefore if the unl cpu service call is issued in a dispatch disabled state the dispatch disabled state remains intact and no task scheduling is performed State transitions are summarized in Table 3 3 Table 3 3 CPU Locked and Dispatch Disabled State Transitions Relating to dis dsp and loc cpu State Content of state dis dsp ena dsp loc cpu unl cpu number CPU locked Dispatch disabled executed executed executed executed state state 1 O X X X gt 1 gt 3 2 O O X X gt 2 gt 4 3 X X gt 4 gt 3 gt 1 gt 3 4 X O gt 4 gt 3 gt 2 gt 4 16 If a service call not issuable is issued when dispatch disabled MR100 doesn t return the error and doesn t guar
55. is initiated after the system returns to the interrupted service call processing See Figure 3 12 TaskA OS Interrupt handler wup tsk Save Registers SP System ha Interrupt Service call processing Restore Registers Task selection SP User Restore Registers ret int TaskB Figure 3 12 Processing Procedure for a Service Call from a Handler that caused an interrupt during Service Call Processing 18 Service Calls from a Handler That Caused an Interrupt during Handler Execution Let us think of a situation in which an interrupt occurs during handler execution this handler is hereinafter referred to as handler A for explanation purposes When task switching is called for as a handler hereinafter referred to as handler B that caused an interrupt during handler A execution issued a service call task switching does not take place during the exe cution of the service call ret int service dler A See Figure 3 13 call returned from handler B but is effected by the ret int service call from han TaskA Interrupt handler A NC Interrupt handler A nterrupt Save Registers SP lt System OS NM Save Registers Interrupt Service call processing Restore Register Restore Register ret int Task selection ret int SP User Restore Registers TaskB Figure 3 13 Processing Procedure for a service call from a Mu
56. is omitted in the configuration file cfg100 Warning task x XXXX is not defined near line xxx xxxx cfg The task definition item XXXX in ID number is omitted cfg100 Warning Already definition XXXX near line xxx xxxx cfg XXXX has already been defined The defined content is ignored check to delete the extra definition cfg100 Warning interrupt vector x s default is not defined default cfg The interrupt vector definition of vector number x in the default configuration file is missing cfg100 Warning interrupt vector x s default is not defined near line xxx xxxx cfg The interrupt vector of vector number x in the configuration file is not defined in the default configuration file cfg100 Warning Initial start task is not defined The task of task ID number 1 was defined as the initial startup task because no initial startup task is defined in the configuration file cfg100 Warning system stack size is an uneven number near line xxx cfg100 Warning task x stack size is an uneven number near line xxx Please set even size in system stack size or task x stack size cfg100 Warning system IPL should be 7 When Wipl is specified as the command option of KONFIGYURETA you should make the value of sys rem IPL of a system definition 7 cfg100 Warning Timer counter value is less than your settimg time The error occurred in the operation of a timer count Please check whether an error is permitted cfg100 Warning XXXX
57. near line xxx xxxx cfg The initial priority in task definition of ID number x exceeds the priority in system definition cfg100 Error clock IPL is too large xxx near line xxx xxxx cfg The system clock interrupt priority level for system clock definition item exceeds the value of IPL within service call of system definition item 257 cfg100 Error System timer s vector lt x gt conflict near line xxx A different vector is defined for the system clock timer interrupt vector Confirm the vector No x for interrupt vector definition cfg100 Error XXXX is not defined xxxx cfg XXXX item must be set in your configuration file cfg100 Error System s default is not defined These items must be set int the default configuration file cfg100 Error lt XXXX gt is already defined near line xxx xxxx cfg XXXX is already defined Check and delete the extra definition cfg100 Error XXXX x is already defined near line xxx default cfg cfg100 Error XXXX x is already defined near line xxx xxxx cfg The ID number in item XXXX is already registered Modify the ID number or delete the extra definition cfg100 Error XXXX must be defined near line xxx xxxx cfg XXXX cannot be omitted cfg100 Error SYMBOL must be defined near line xxx xxxxcfg This symbol cannot be omitted cfg100 Error Zero divide error near line xxx xxxx cfg A zero divide operation occurred in some arithmetic expression cfg100 Error ta
58. of the TA TFIFO attribute sess ene nnnnenns 26 Figure 3 20 Task control block vecinita AAA 2224 5 Figure 3 21 Cyclic Handler Alarm Handler Activation esses 29 Figure 3 22 Interrupt handler IPLs esses nennen nnne enne ener nennen 31 Figure 3 23 Interrupt control in a Service Call that can be Issued from only a Task 82 Figure 3 24 Interrupt control in a Service Call that can be Issued from a Task independent 33 Figure 3 25 System Stack and User Stack ssessssssssssseseeeee eere nennen nnne 34 Figure 4 1 MR100 Structule oocoooccnononoconnnonnnonnnonnnnnnnononnnnnnnnnnnnnnnnn nn nono tenni rente nn sientes seen nennen nnne 35 Figure 42 Task Resetting ica ii A aa A a ave ato fa Figure 4 3 Alteration of task Priority cccccccccccccecsessnsecsececeeeceesessececececseeensnseceeeeeeesesenenssaeeeeenenes 38 Figure 4 4 Task rearrangement in a waiting queue sse enne enne enne eene 38 Figure 4 5 Wakeup Request Storage cccccccccssssscesssssececsesececeenseeecseaaeeecsesaeeecsesaeeeesesaeeeesessaeseenegs 39 Figure 4 6 Wakeup Request Cancellation ccccccecsccccesssseseceecececeessececsesseeecesessesecsesseseeseaseeeenaas 39 Figure 4 7 Forcible wait of a task and resume sess 40 Figure 4 8 Forcible wait of a task and forcible resuM occcnnononononnnonnnnnnnonnanonononcnnononnanonanonccnnnns
59. priority so that messages will be received in order of priority beginning with the highest In this case TA MPRI should be added to the mailbox attribute If messages need to be received in order of FIFO add TA MFIFO to the mailbox attribute Furthermore if tasks in a message wait state are to receive a message the tasks can be prioritized in which order they can receive a message beginning with one that has the highest priority In this case add TA TPRI to the mailbox attribute If tasks are to receive a message in order of FIFO add TA TFIFO to the mailbox attrib ute Message Message TaskA TaskB Figure 4 15 Mailbox E It is in the mailbox definition message queue of the configuration file that the TA MPRI or TA MFIFO attribute should be added It is in the mailbox definition wait queue of the configuration file that the TA TPRI or TA TFIFO attribute should be added 48 Message queue Message A Message B Message C Figure 4 16 Message queue There are following data queue service calls that are provided by the MR100 kernel e Send to Mailbox snd mbx isnd mbx Transmits a message Namely a message is dropped into the mailbox e Receive from Mailbox rcv mbx trcv mbx Receives a message Namely a message is retrieved from the mailbox At this time if the mailbox has no mes sages in it the task is kept waiting until a message is sent to the mailbox e Receive from
60. programs can be developed within a short period of time One way to achieve this purpose is to use a large number of microcomputers having a small ROM capacity Figure 3 2 presents an example in which a number of microcomputers are used to build up an audio equipment system 4 On condition that the ROM program burning step need not be performed NT Key input Remote control LED illumination microcomputer microcomputer microcomputer Arbiter microcomputer Volume control Monitor Mechanical microcomputer microcomputer control microcomputer Figure 3 2 Microcomputer based System Example Audio Equipment Using independent microcomputers for various functions as indicated in the above example offers the following advan tages 1 Individual programs are small so that program development is easy 2 Itis very easy to use previously developed software 3 Completely independent programs are provided for various functions so that program devel opment can easily be conducted by a number of engineers On the other hand there are the following disadvantages 1 The number of parts used increases thereby raising the product cost 2 Hardware design is complicated 3 Product physical size is enlarged Therefore if you employ the real time OS in which a number of programs to be operated by a number of microcomputers are placed under software control of one microcomputer making it appear that the programs run on separate microcompu
61. return from an interrupt handler Depending on return processing it activates the scheduler to switch tasks from one to another Tf this service call is executed in an interrupt handler task switching does not occur and task switching is postponed until the interrupt handler terminates However if the ret_int service call is issued from an interrupt handler that was invoked from an interrupt that occurred within another interrupt the scheduler is not activated The scheduler is activated for interrupts from a task only When writing this service call in assembly language be aware that the service call cannot be issued from a subroutine that is invoked from an interrupt handler entry routine Always make sure this service call is executed in the entry routine or entry function of an interrupt handler For example a program like the one shown below may not operate normally include mr100 inc NG GLB intr intr jsr b func func ret int Therefore write the program as shown below include mr100 inc OK GLB intr intr jsr b func ret int func rts Make sure this service call is issued from only an interrupt handler If issued from a cyclic handler alarm handler or a task this service call may not operate normally If the starting function of an interrupt handler is declared by pragma INTHANDLER the ret int service call is automatically issued at the exit of the function 183 5 14System Configu
62. sleep with timeout C Language API ER ercd slp tsk ER ercd tslp tsk TMO tmout Parameters slp tsk None tslp tsk TMO tmout Timeout value Return Parameters ER ercd Terminated normally E OK or error code Assembly language APT include mr100 inc slp_tsk tslp_tsk TMO Parameters TMO Timeout value Register contents after service call is issued tslp tsk Register name Content after service call is issued RO Error code R6R4 Timeout value slp_tsk Register name Content after service call is issued RO Error code Error code E TMOUT Timeout E RLWAI Forced release from waiting 85 Functional description This service call places the issuing task itself from RUNNING state into sleeping wait state The task placed into WAIT ING state by execution of this service call is released from the wait state in the following cases When a task wakeup service call is issued from another task or an interrupt The error code returned in this case is E OK When a forcible awaking service call is issued from another task or an interrupt The error code returned in this case is E RLWAI When the first time tick occurred after tmout elapsed for tslp tsk The error code returned in this case is E TMOUT If the task receives sus tsk issued from another task while it has been placed into WAITING state by this service call it goes to WAITING SUSPENDED state In this case even whe
63. struct t rmpf ID wtskid UINT frbent T RMPF ID number of task at the top of memory acquisition waiting queue Number of memory blocks 280 Formats related to Variable size Memory pool typedef struct t rmpl ID wtskid D number of task at the top of memory acquisition waiting queue SIZE fmplsz Total size of free areas UINT fblksz Maximum memory block size that can be acquired immediately T RMPL Formats related to cyclic handler typedef struct t_rcyc STAT cycstat Operating status of cyclic handler RELTIM lefttim Remaining time before cyclic handler starts T RCYC Formats related to alarm handler typedef structt ralm STAT almstat Operating status of alarm handler RELTIM lefttim Remaining time before alarm handler starts T RALM Formats related to system management typedef struct t_rver UH maker Maker UH prid Type number UH spver Specification version UH prver Product version UH prnol4 Product management information T_RVER 281 12 3Assembly Language Interface When issuing a service call in the assembly language you need to use macros prepared for invoking service calls Processing in a service call invocation macro involves setting each parameter to registers and starting ex ecution of a service call routine by a software interrupt If you issue
64. the PC and FLG registers Also if you issue the service calls that can be issued from both tasks and handlers see the stack sizes listed in Table 10 2 Stack Sizes Used by Service Calls Issued from Handlers in bytes to ensure that the necessary stack area is allocated Furthermore when issuing multiple service calls include the maximum value of the stack sizes used by those service calls as the sections used by MR100 as you calculate the necessary stack size Therefore User stack size Sections used in user program registers used Sections used in MR100 registers used is total size of used registers Figure 2 3 Example of Use Stack Size Calculation shows an example for calculating a user stack In the example below the registers used by the task are R2RO R3R1 and AO If written in the C language this size is fixed 266 Stack growing direction gt When use register R2R0 R3R1 A0 12by tes Abytes lt gt 24byt es PC FLG size of registers used jsr subl stack size used by sta_tsk 36by tes P C F LG size of registers used stack size used by prcv_mbx d__ _ 40by tes Figure 2 3 Example of Use Stack Size Calculation 267 10 1 2 System Stack Calculation Method The system stack is most often consumed when an interrupt occurs during service call processing followed by the occur rence of multiple interrupts The necessary size the maximum size of the system stack can be obtained from the f
65. the function for synchronization and communication among the tasks The following four functional mod ules are offered Eventflag Checks whether the flag controlled within the MR100 is set up and then determines whether or not to initi ate task execution This results in accomplishing synchronization between tasks Semaphore Reads the semaphore counter value controlled within the MR100 and then determines whether or not to ini tiate task execution This also results in accomplishing synchronization between tasks Mailbox Provides inter task data communication by delivering the first data address Data queue Performs 32 bit data communication between tasks e Memory pool Management Module Provides dynamic allocation or release of a memory area used by a task or a handler e Extended Function Module Outside the scope of uITRON 4 0 Specification this function performs reset processing on objects and short data queue function This handler actuates once only at preselected times This handler periodically actuates 36 4 1 3 Task Management Function The task management function is used to perform task operations such as task start stop and task priority updating The MR100 kernel offers the following task management function service calls Activate Task act tsk iact tsk Activates the task changing its status from DORMANT to either READY or RUNNING In this service call un like in sta tsk ista tsk
66. the microcomputer program size has increased Further as product development competi tion has been intensified manufacturers are compelled to develop their microcomputer based products within a short period of time In other words engineers engaged in microcomputer software development are now required to develop larger size pro grams within a shorter period of time To meet such stringent requirements it is necessary to take the following considera tions into account 1 To enhance software recyclability to decrease the volume of software to be developed One way to provide for software recyclability is to divide software into a number of functional modules wherever possible This may be accomplished by accumulating a number of general purpose subroutines and other program segments and using them for program development In this method however it is difficult to reuse programs that are dependent on time or timing In reality the greater part of application programs are dependent on time or tim ing Therefore the above recycling method is applicable to only a limited number of programs 2 To promote team programming so that a number of engineers are engaged in the development of one software package There are various problems with team programming One major problem is that debugging can be initiated only when all the software program segments created individually by team members are ready for debugging It is es sential that communica
67. this case is E OK When the first time tick occurred after tmout elapsed while task awaking conditions remain un satisfied The error code returned in this case is E TMOUT When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI If this service call is to be issued from task context use wai sem twai sem or pol sem if issued from non task context use ipol sem 104 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if wai sem ID sem E OK printf Forced wakeup n LE pol sem ID sem E OK printf Timeout Win if twai sem ID sem 10 E OK printf Forced wakeup or Timeout n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 pol sem HID SEMI PUSH W R2 wai sem ID_ SEM2 PUSH W R2 PUSH L R6R4 twai_sem ID_SEM3 300 105 ref sem Reference semaphore status iref sem Reference semaphore status handler only C Language API ER ercd ref sem ID semid T RSEM pk rsem ER ercd iref sem ID semid T RSEM pk rsem Parameters ID semid ID number of the target semaphore T RSEM pk rsem Pointer to the packet to which semaphore status is returned
68. this service call However the semaphore and other resources the specified task had acquired pre viously are not released If the task indicated by tskid is in DORMANT state it returns the error code E OBJ as a return value for the service call This service call can only be used in task context and cannot be used in non task context 73 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task ter tsk ID main lt lt Example statement in assembly language gt gt INCLUDE mri00 inc GLB task task PUSH W R2 ter tsk ID_TASK3 74 chg pri Change task priority ichg pri Change task priority handler only C Language API ER ercd chg pri ID tskid PRI tskpri ER ercd ichg pri ID tskid PRI tskpri Parameters ID tskid ID number of the target task PRI tskpri Priority of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language API 1 include mr100 inc chg pri TSKID TSKPRI ichg pri TSKID TSKPRI Parameters TSKID ID number of the target task TSKPRI Priority of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code R3 Priority of the target task R2 ID number of the target task Error code E_OBJ Object status invalid task indicated
69. which the task that meets the task execution conditions is still waiting for execution because a different task having a higher priority is currently being executed When any of the following conditions occurs the READY task that can be executed second according to the ready queue is placed in the RUNNING state Acurrently executed task has normally terminated itself by ext tsk service call By issuing dly tsk slp_tsk tslp tsk wai flg twai flg wai sem twai sem rcv mbx trcv mbx snd dtq tsnd dtq rcv dtq trev_dtq vtsnd dtq vsnd dtq vtrcv dtq vrcv dtq get mpf and tget mpf service call 22 Acurrently executed task has placed itself in the WAITING state Aocurrently executed task has changed its own priority by chg pri or ichg pri service call so that the priority of a different READY task is rendered higher Due to interruption or other event occurrence the priority of a currently executed task has been changed so that the priority of a different READY task is rendered higher When the ready queue of the issuing task priority is rotated by the rot rdq or irot rdq service call and control of execution is thereby abandoned 3 WAITING state When a task in the RUNNING state requests to be placed in the WAITING state it exits the RUNNING state and enters the WAITING state The WAITING state is usually used as the condition in which the completion of I O device I O operation or the processing of some other task is aw
70. 0 15 in Figure 7 11 Incorporate a system ROM area definition file 16 in Figure 7 11 Incorporate a system RAM area definition file 17 in Figure 7 11 This is the initialization program SYS INITIAL that is activated immediately after a reset 55 207 in Figure 7 11 9999 Setting the System Stack pointer 56 in Figure 7 11 Setting the SB FB register 61 65 in Figure 7 11 Initial set the C language 72 105 in Figure 7 11 Setting kernel interrupt mask level 111 in Figure 7 11 Setting the address of interrupt vector table 112 in Figure 7 11 Set MR100 s system clock interrupt 114 122 in Figure 7 11 Initial set MR100 s system timer 124 132 in Figure 7 11 9 Initial set parameters inherent in the application 140 in Figure 7 11 10 Initialize the RAM data used by MR100 141 197 in Figure 7 11 11 Activate the initial startup task 201 207 in Figure 7 11 12 This is a system clock interrupt handler 235 248 in Figure 7 11 223 7 4 Memory Allocation This section describes how memory is allocated for the application program data Use the section file provided by MR100 to set memory allocation MR100 comes with the following two types of section files e asm sec inc This file is used when you developed your applications with the assembly language e c sec inc This file is used when you developed your applications with the C language c sec inc is derived from asm sec inc by adding sect
71. 00 DevelopmMent ooooooooonncnnnnnnoononnnonnconononnanononononnononnnnonononronnononnno no nnnnononnnnn none nnnconono 8 2 2 Relationship between TRON Specification and MR10DO0 sess 5 2 9 WER MOORE GAUL ES soul roter aida doo bae 6 3 Introduction to Kernel ie te a AA ae EEEE ER Lo eda e E aei Lee dE ERR E Eae edo eds ae Sal Concept of Realtime OS zen d eee ov bad sta trie ei RI HE FB e e ERE ss 3 1 1 Why Real time OS is Necessary essen ere eene eet ense ee eh nente tern esse sterne tern nn ense 75 3 1 2 Operating Principles of Kernel sees a a a ie iaaii iE 10 aT ISC OAs deett e et EA N 14 3 2 1 Service Call Processing tacos 15 3 2 2 Processing Procedures for Service Calls from HandlerS oooooooooconnncnnonononnonnnononnononnnanononononnono 16 Service Calls from a Handler That Caused an Interrupt during Task Execution seen qr Service Calls from a Handler That Caused an Interrupt during Service Call Processing 18 Service Calls from a Handler That Caused an Interrupt during Handler Execution sss 19 BS Foc BR O 0 EP 20 3 3 1 The specification method of the object in a service call oononnnoconononncononononanannnnconononnn nn nono 20 e E gt SPAS EE E E A E S E T A A E AA 2213 3 4 1 Task SAUS dee Hasina antes hh toa eap 3 4 2 Task Priority and Ready Queue
72. 1 E TMOUT error Timeout n if tsnd dtq ID dtg data 2 10 E TMOUT error Timeout Wn if fsnd dtq ID dtg data 3 E OK error errorWMn lt lt Example statement in assembly language gt gt include mr100 inc GLB g dtq LWORD task USH W USHM snd d ct UU P PUSHM psnd d P P fsnd d USH W USH W ta ta ta task 12345678H R2 R6R4 R3R1 ID DTQ1 g dtq 100 R2 R3R1 ID DTQ2 0FFFFFFFFH R2 R3R1 HID_DTO3 H0ABCDH 121 rcv dtq Receive from data queue prev_dtq Receive from data queue polling iprcv dtq Receive from data queue polling handler only ircv dtq Receive from data queue with timeout C Language API 1 ER ercd rcv dtq ID dtqid VP INT p data ER ercd prcv dtq ID dtqid VP INT p data ER ercd iprcv dtq ID dtqid VP INT p data ER ercd trcv dtq ID dtqid VP INT p data TMO tmout Parameters ID dtqid ID number of the data queue from which to receive TMO tmout Timeout value trev_dtq VP_INT p_data Pointer to the start of the area in which received data is stored Return Parameters ER ercd Terminated normally E OK or error code VP INT p data Pointer to the start of the area in which received data is stored Assembly language APT include mr100 inc rcv dtq DTQID prcv dtq DTOID iprcv dtq DTOID trcv dtq DTQID TMO Parameters
73. 135 get mpf Aquire fixed size memory block oooooooonnnnnonunoooonnonnnononnnnnnonononnononnn nono nonconononnononononncononanns 186 pget mpf Aquire fixed size memory block polling enne 136 ipget mpf Aquire fixed size memory block polling handler only see 136 tget mpf Aquire fixed size memory block with timeout sess 136 rel mpf Release fixed size memory block ooooooooononncnnnonononanononocnonnnnononononnonononn nono nonononnnananonononcnnon 189 irel mpf Release fixed size memory block handler only seen 139 ref mpf Reference fixed size memory pool status ocooconooocononcnnononnononnnononnononananonononcnnonnnnanonanoncnnon 141 iref mpf Reference fixed size memory pool status handler only see 141 5 8 Memory Pool Management Function Variable size Memory Pool see 143 pget mpl Aquire variable size memory block polling 144 rel mpl Release variable size memory block essen emen emen nnne en 146 ref mpl Reference variable size memory pool status ooooooooonnncconnnonononanononnononnnnonnnnnnonnonnnnanonononcnnon 148 iref mpl Reference variable size memory pool status handler only eee 148 5 9 Time Management Function 150 set timo Sebsystem tume os sre E este eer ee orte E aeree metet ee rae 151 iset_tim Set system time andina 151
74. 200 bytes Figure 4 18 pget mpl processing e Release Acquire Variable size Memory Block rel mpl Releases a acquired memory block by pget mpl service call The validity of the address of the memory block to which MR100 is passed as an argument and to release is not judged Therefore op eration at the time of releasing the memory block which is already released or releasing the memory block which has not been gained is not guaranteed 52 Memorypool Memorypool rel mpl top of E address Figure 4 19 rel_mpl processing e Reference Acquire Variable size Memory Pool Status ref_mpl iref_mpl Checks the total free area of the memory pool and the size of the maximum free area that can immediately be acquired 53 4 1 11 Time Management Function The time management function provides system time management time reading time setup and the functions of the alarm handler which actuates at preselected times and the cyclic handler which actuates at preselected time intervals The MR100 kernel requires one timer for use as the system clock There are following time management service calls that are provided by the MR100 kernel Note however that the system clock is not an essential function of MR100 Therefore if the service calls described below and the time management function of the MR100 are unused a timer does not need to be occupied for use by MR100 e Place a task in a finite time wait s
75. 234 CEventilas definition MWietesna ada acti alada ees 236 Semaphore d finition li dni 237 MA AAA tete tree te td ied ertet 238 Short data queue definition esee emen ene reete tret tette enitn etre retreat ense 239 Curl bosode BEOIDRL oe dis cr eee eli IM DE ELEM the UL EI US M LI MU EI EL 240 Fixed size memory pool definition eee nennen ener nne tn cane cn na 241 Variable size memory pool definition lerese a ee eei Eiaa emeret ed an ia trennt 242 Cyclic handler definition A neriie renerien n ERRAT KI e aar paa Enn aT da er RoHS I Da nup OES 244 CAlarm handler definition ara 245 CInterrupt vector definition A a RR te octet econ aee 246 Fixed interrupt vector definition ccccccccccccssessescssescescsesscccsesscsecsessesecsescsecsssacsecsesscsecsesscsesscsecsesacsecsesaseesaeeaes 247 8 1 3 Configuration File Example seeesesseeeeeeeeeeeeeen enne n nennen en een e nnns sten enne tenir ens enn en entren 250 8 2 Configurator Execution Procedures ccccsssssccseceseesensececceeececeesesssaeceeeceeeesenssaeeeeeesecsesensaaeeeeeseceees 254 8 2 1 Config rdtor OVERVIEW A credet te ave e ee a 254 Executing the configurator requires the following input files esssssessseseeeeeeeene enne enne 254 When the configurator is executed the files listed below are output occccconooonononocononanonononononnnnonononcononnnanononononns 254 8 2 2 Setting Configurator Env
76. 4 ID semi ID sem2 ID sem3 ID dtqgl ID_dtq2 ID_dtq3 ID_mbx1 TA TFIFO NO D 0x0000ffff TA TPRI YES D 0x00000008 TA TPRI YES TA WSGL n TA TFIFO 0 ESO D TA TFIFO 5 10 TA TPRI 255 255 D TA TFIFO 10 TA TPRI 5 D TA TFIFO 256 D TA TFIFO TA MFIFO D TA TPRI TA MPRI D TA TFIFO TA MPRI TA TPRI TA MFIFO 251 155 name ID mpfi 156 wait queue TA TFIFO 157 section MR RAM 158 siz block 16 159 num block zb 160 161 memorypool 2 162 name ID mpf2 163 wait queue TA TPRI 164 section MR RAM 165 siz block 2 32 166 num block a4 167 168 memorypool 3 169 name ID_mpf3 170 wait_queue TA_TFIFO 171 section MPF3 172 siz block 64 173 num_block 256 174 175 176 variable memorypool 177 name ID mpl1 178 max memsize 8 179 heap size 16 180 181 variable memorypool 182 name ID mpl2 183 max memsize 64 184 heap size 256 185 186 variable memorypool 3 187 name ID mpl3 188 max memsize 256 189 heap size 1024 190 191 192 cyclic_hand 193 entry address cyhl 194 name ID cyhl 195 exinf 0x0 196 start ON 197 phsatr OFF 198 interval counter 0x1 199 phs_counter 0x0 200 201 cyclic_hand 202 entry address cyh2 203 name ID cyh2 204 exinf
77. 6 24 12 44 12 24 24 56 12 24 24 56 12 32 12 40 12 40 28 60 12 20 12 20 32 68 12 20 16 24 12 20 28 60 28 60 40 64 Service call jact tsk ican_act ista_tsk ichg_pri iget_pri iref_tsk iref_tst iwup_tsk ican_wup irel_wai isus tsk irsm tsk ifrsm tsk isig sem ipol sem iref sem iset flg iclr_flg ipol flg iref flg ipsnd dtq ifsnd_dtq iprev_dtq iref_dtq 12020 iref_mpl 1200 Stack sizes used by service call in Assembly programs Table 10 3 Stack Sizes Used by Service Calls Issued from Tasks and Handlers in bytes lists the stack sizes system stack used by service calls that can be issued from both tasks and handlers If the service call issued from task system uses user stack If the service call issued from handler system uses system stack Table 10 3 Stack Sizes Used by Service Calls Issued from Tasks and Handlers in bytes Service call Stack size Service call Stack size sns ctx 1220 sns loc 12 20 sns_dsp 12 20 sns_dpn Stack sizes used by service call in Assembly programs 273 12 20 11 Note 11 1The Use of INT Instruction MR100 has INT instruction interrupt numbers reserved for issuing service calls as listed in Table 11 1 Interrupt Number Assignment For this reason when using software interrupts in a user application do not use interrupt n
78. 7fffffff ms 3 Activation phase O 7fffffff ms 4 Extended information 32 bits 5 Cyclic handler attribute TA_HLNG Handlers written in high level language TA_ASM Handlers written in assembly language TA_STA Starts operation of cyclic handler TA_PHS Saves activation phase Table 5 20 List of Cyclic Handler Function Service Call No Service Call Function System State T N E D U L 1 sta_cyc SI B Starts cyclic handler operation O O O O 2 ista_cyc O O O O 3 stp_cyc S B Stops cyclic handler operation O O O O 4 istp_cyc O O O O 5 ref_cyc Reference cyclic handler status O O O O 6 iref cyc O O O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 156 sta cyc Start cyclic handler operation Ista cyc Start cyclic handler operation handler only C Language API ER ercd sta cyc ID cycid ER ercd ista cyc ID cycid Parameters ID cycid ID number of the cyclic handler to be operated Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc
79. A TPRI Default value TA TFIFO Select a method in which tasks wait for the semaphore If TA TFIFO is selected tasks are enqueued in order of FIFO If TA TPRI is selected tasks are enqueued in order of priority beginning with the one that has the highest priority 3 Initial value of semaphore counter Definition format Numeric value Definition range 0 to 65535 Default value 1 Define the initial value of the semaphore counter This value must be less than the maximum value of the sema phore counter 4 Maximum value of the semaphore counter Definition format Numeric value Definition range 1 to 65535 Default value 1 Define the maximum value of the semaphore counter Data queue definition This definition must always be set when the data queue function is to be used lt lt Format gt gt Dataqueue Definition dataqueue ID No 1 name ID name buffer size Number of data queues wait queue Select data queue waiting queue The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are automatically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each data queue ID number define the items described below 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the data queue is sp
80. ALMID Parameters ALMID ID number of the alarm handler to be stopped Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the alarm handler to be stopped Error code None Functional description This service call places the alarm handler indicated by almid into a non operational state If this service call is to be issued from task context use stp alm if issued from non task context use istp alm Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task stp alm ID almi lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 stp alm ID_ALM1 165 ref alm Reference alarm handler status iref alm Reference alarm handler status handler only C Language API ER ercd ref alm ID almid T RALM pk ralm ER ercd iref alm ID almid T RALM pk ralm Parameters ID almid ID number of the target alarm handler T RALM pk ralm Pointer to the packet to which alarm handler status is returned Return Parameters ER ercd Terminated normally E OK T RALM pk ralm Pointer to the packet to which alarm handler status is returned Contents of pk ralm typedef struct t ralm STAT almstat 0 2 Operating status of alarm handler RELTIM lefttim
81. DE mr100 inc 1 GLB task 2 task process jmp task 3 Figure 7 6 Example Infinite Loop Task Described in Assembly Language INCLUDE mr100 inc GLB task task process ext tsk Figure 7 7 Example Task Terminating with ext tsk Described in Assembly Language 4 The initial register values at task startup are indeterminate except the PC SB RO and FLG registers 5 To specify a task use the string written in the task definition item name of the configura tion file wup tsk ID_ task 6 To specify an event flag semaphore or mailbox use the respective strings defined in the configuration file For example if a semaphore is defined in the configuration file as shown below semaphore 1 name abc y To specify this semaphore write your specification as follows sig sem ID abc T To specify a cyclic or alarm handler use the string written in the cyclic or alarm handler definition item name of the configuration file For example if you want to specify a cyclic handler cyc write your specification as follows sta cyc HID_cyc 47 Use the GLB pseudo directive 215 8 Seta task that is activated at MR100 system startup in the configuration file 7 2 2 Writing Kernel Interrupt Handler When describing the kernel interrupt handler in assembly language observe the following precautions 1 At the beginning of file be sure to include mr100 inc which is in the syste
82. DTQID ID number of the data queue from which to receive TMO Timeout value trev_dtq Register contents after service call is issued rcv dtq prcv dtq iprcv dtq Register name Content after service call is issued RO Error code R3RI Received data R2 Data queue ID number trcv dtq Register name Content after service call is issued RO Error code R3RI Received data R2 ID number of the data queue from which to receive R6R4 Timeout value Error code E RLWAI Forced release from waiting E TMOUT Polling failure or timeout or timed out 122 Functional description This service call receives data from the data queue indicated by dtqid and stores the received data in the area pointed to by p data If data is present in the target data queue the data at the top of the queue or the oldest data is received This results in creating a free space in the data queue area so that a task enqueued in a transmission waiting queue is released from WAITING state and starts sending data to the data queue area If no data exist in the data queue and there is any task waiting to send data i e data bytes in the data queue area 0 data for the task at the top of the data transmission waiting queue is received As a result the task kept waiting to send that data is released from WAITING state On the other hand if rcv dtq or trcv dtq is issued for the data queue which has no data stored in it the task that issued the service call goes
83. EE 111 iclr_flg Clear eventflag handler only icc cssseiascsrssdsavasssenronssnsssestosnvanesnsend arenes ca onassvonranssevboressuey anents 111 waite Waitforeyventtlag ia A A RH eb 113 pol flg M ent dorceventtlag polling usce ethernet dd dl ni usiirbins 113 ipol_flg Wait for eventflag polling handler only eene 113 twai_flg Wait for eventflag with timeout cccccccecccccessesseescssesssescssccesscssceccssesscssesssesscesecaueessass 113 ref flg Reference eventflag Status cocccononoooonnnnnonononnononononnononnnnonnnnnnnnconononno nono ersten enne tenen esse nennen 116 iref flg Reference eventflag status handler only 116 5 5 Synchronization Communication Function Data Queue sese 118 snd dtq Send to data queue ccccsescccccccecsessssecececececeensseeesceecseeeeseseceeeeeceeserssaeeeeeesesenesssaeeeeeeseeeeees 119 psnd_dtq Send to data queue polling caiste std tb 119 ipsnd dtq Send to data queue polling handler only sss 119 tsnd dtq Send to data queue With timeout ooncnnnnnnnonnnnnninnnnincnnnnnncnnoninann anno ro nono cano nn rana nara 119 fsnd dtq Forced send to data queue ccccssssssccscccecesssssnsecscececssssnsesseascesecsesensseaseesecsenssaauaaeeesecs 119 ifsnd dtq Forced send to data queue handler only sese 119 rev dba Receive from lada UU casio 122 prev dtq Receive from data queue p
84. END request from other task SUSPENDED SUSPENDED state state clear request Forced termination request from other task DORMANT state Task activation Figure 3 16 MR100 Task Status Transition 1 RUNNING state In this state the task is being executed Since only one microcomputer is used it is natural that only one task is being executed The currently executed task changes into a different state when any of the following conditions occurs The task has normally terminated itself by ext tsk service call The task has placed itself in the WAITING Since the service call was issued from the RUNNING state task the WAITING state of another task with a priority higher than the RUNNING state task is cleared Due to interruption or other event occurrence the interrupt handler has placed a different task having a higher priority in the READY state The priority assigned to the task has been changed by chg pri or ichg pri service call so that the priority of another READY task is rendered higher When the ready queue of the issuing task priority is rotated by the rot rdq or irot rdq service call and control of execution is thereby abandoned When any of the above conditions occurs rescheduling takes place so that the task having the highest priority among those in the RUNNING or READY state is placed in the RUNNING state and the execution of that task starts 2 READY state The READY state refers to the situation in
85. ER UINT wupcnt wupcnt can wup ID main if wup cnt gt 0 printf wupent dMn wupcnt lt lt Example statement in assembly language gt gt include mr100 inc GLB task task can wup HID TASK3 91 rel wai Release task from waiting irel wai Release task from waiting handler only C Language API ER ercd rel wai ID tskid ER ercd irel wai ID tskid Parameters ID tskid ID number of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language APT include mr100 inc rel wai TSKID irel wai TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is not an wait state Functional description This service call forcibly release the task indicated by tskid from waiting except SUSPENDED state to place it into READY or RUNNING state The forcibly released task returns the error code E RLWAI If the target task has been en queued in some waiting queue the task is dequeued from it by execution of this service call If this service call is issued to a task in WAITING SUSPENDED state the target task is released from WAITING state and goes to SUSPENDED state If the target task is not in WAITING state the error
86. F 46 exinf 0x0 47 48 task 49 entry address task2 50 name ID task2 Bal stack size 256 52 priority E55 53 initial start ON 54 exinf OxFFFF 55 56 task 31 57 entry address task3 58 name ID task3 59 stack size 256 60 priority Ey 61 initial start OFF 62 exinf 0x0 63 A 64 65 flag 66 name ID flgl 67 initial pattern 0x00000000 68 wait_queue TA TFIFO 69 clear attribute NO 70 wait multi TA WSGL X 72 flag 11 73 name ID flg2 74 initial pattern 0x00000001 250 wait queue clear attribute wait multi bs flag 2 name initial pattern wait queue clear attribute wait multi hi flag name initial pattern wait_queue clear_attribute wait_multi semaphore name wait queue initial count max count A name wait_queue initial_count max_count semaphore 11 name wait queue initial count max count y dataqueue name wait_queue buffer size d ccn qon name wait queue buffer size dataqueue 3 name wait queue buffer size mailbox name wait_queue message_queue max pri 4 mailbox name ID mbx2 wait queue message queue max pri 64 mailbox name ID mbx3 wait queue message queue max pri 5 mailbox 4 name ID_mbx4 wait queue message queue max pri 6 memorypool TA_WMUL ID flg3 TA WMUL ID flg
87. FD8H Kernel reserved area 3 FFFFFFDCH Undefined instruction 4 FFFFFFEOH Overflow 5 FFFFFFE4H BRK instruction 6 FFFFFFE8H Reserved area 7 FFFFFFECH Reserved area 8 FFFFFFFOH Watchdog timer voltage down detection oscillation stop detection 9 FFFFFFF4H Reserved area 10 FFFFFFF8H NMI 11 FFFFFFFCH Reset lt lt Content gt gt 1 Start address Definition format Symbol or function name Definition range None Default value SYS DMY INH Define the entry address to the interrupt handler When written in C language add at the end of the function name or __ at the beginning of it 2 Switch passed to PRAGMA extended function Definition format Symbol Definition range BorR Default value None Specify the switch to be passed to pragma INTERRUPT If B is specified a B switch is selected in which case register bank 1 is selected If R is specified a R switch is selected in which case no codes are output that change the floating number rounding mode of the FLG register to the nearest value Both switches can be specified at the same time 248 Precautions 1 Regarding the method for specifying a register bank No kernel interrupt handlers that use the registers in register bank 1 can be written in C language These handlers can only be written in assembly language When writing in assembly language write the entry and exit to and from the interrupt handler as shown be
88. INCLUDE Sys rom inc 17 INCLUDE Sys ram inc 18 LIST ON 19 20 GLB SYS INITIAL 21 GLB END INIT 22 GLB init sys init tsk 23 24 regoffset EQU 0 25 pp HS NN oe A A SS A cio oe G 27 SBDATA area definition 29 Pe SR SSS SS SSS SSeS eue mec SA See Seas ee SSS eee See SSS See 29 GLB SB 30 SB SB 3 32 22 2 z2 2 z2 2 2 222222222222l22222222l2l2l2ll2l2l2l2l2l2ll2l2l2l2222 2222 2 33 Initialize Macro declaration 34 35 BZERO macro TOP SECT 36 XOR B ROL ROL 37 mov 1 TOP_ A1 38 mov 1 sizeof SECT_ R7R5 39 sstr b 40 endm 41 BCOPY macro FROM TO SECT 42 mov 1 FROM_ AO 43 mov 1 HTO A1 44 mov l sizeof SECT R7R5 45 smovf b 46 endm T yesse Ss S 5s 3 S S 2 HS 35 Se SS8s 8S 48 Interrupt section start AO 1 i erueeieTamcu ee ein eet sect EG I ESOS uH Mura 50 SECTION MR KERNEL CODE ALIGN 51 52 53 after reset this program will start 54 55 SYS INITIAL 56 LDC H_ Sys Sp ISP Set initial ISP 57 58 MOV B 2 0AH 59 MOV B 00 PMOD Set Processor Mode Register 60 MOV B 0 OAH p 61 LDC 00000010H FLG 62 LDC SB SB 63 LDC 00000000H FLG 64 LDC H_ Sys Sp FB 65 LDC SB SB 66 67 s o oooooooooooooooooooooooooooooooooooooooooooooooo o 68 MR RAM zero clear GO Gee Seine reese coc BERE Tie
89. MO Timeout value tsnd_dtq Register contents after service call is issued vsnd_dtq vpsnd_dtq vipsnd_dtq vfsnd_dtq vifsnd_dtq Register name Content after service call is issued RO Error code R1 Data to be transmitted R2 ID number of the Short data queue to which transmitted vtsnd dtq Register name Content after service call is issued RO Error code R1 Data to be transmitted R2 ID number of the Short data queue to which transmitted R6R4 Timeout value 188 Error code E RLWAI Forced release from waiting E TMOUT Polling failure or timeout or timed out E ILUSE Service call improperly used vfsnd dtq or vifsnd dtq is issued for a Short data queue whose dtqcnt 0 EV RST Released from a wait state by clearing of the Short data queue area Functional description This service call sends the signed 2 byte data indicated by data to the Short data queue indicated by vdtqid If any task is kept waiting for reception in the target Short data queue the data is not stored in the Short data queue and instead sent to the task at the top of the reception waiting queue with which the task is released from the reception wait state On the other hand if vsnd dtq or vtsnd dtq is issued for a Short data queue that is full of data the task that issued the ser vice call goes from RUNNING state to a data transmission wait state and is enqueued in a transmission waiting queue kept waiting for the Short data queue to become avail
90. Mailbox polling prcv mbx iprcv mbx Receives a message The difference from the rcv mbx service call is that if the mailbox has no messages in it the task returns error code without going to a wait state e Reference Mailbox Status ref mbx iref mbx Checks to see if there are any tasks waiting for a message to be put into the target mailbox and refers to the mes sage present at the top of the mailbox 49 4 1 9 Memory pool Management Function Fixed size Memory pool A fixed size memory pool is the memory of a certain decided size The memory block size is specified at the time of a con figuration Figure 4 17 is a figure about the example of a fixed size memory pool of operation e Acquire Fixed size Memory Block get mpf tget mpf Acquires a memory block from the fixed size memory pool that has the specified ID If there are no blank mem ory blocks in the specified fixed size memory pool the task that issued this service call goes to WAITING state and is enqueued in a waiting queue e Acquire Fixed size Memory Block polling pget mpf ipget mpf Acquires a memory block from the fixed size memory pool that has the specified ID The difference from the get mpf and tget mpf service calls is that if there are no blank memory blocks in the memory pool the task re turns error code without going to WAITING state M Block 1 EPA eis msec Memory block acquisition Memory Block 2 Used by TaskB request TaskC
91. Memory Block 3 Memory block acquisition Memory block acquisition request lt TaskD No blank memory blocks available i Fixed Length Memorypool Ca wait state Figure 4 17 Memory Pool Management e Release Fixed size Memory Block rel mpf irel mpf Frees the acquired memory block If there are any tasks in a wait state for the specified fixed size memory pool the task enqueued at the top of the waiting queue is assigned the freed memory block In this case the task changes its state from WAITING state to READY state If there are no tasks in a wait state the memory block is returned to the memory pool e Reference Fixed size Memory Pool Status ref mpf iref mpf Checks the number and the size of blank blocks available in the target memory pool 50 4 1 10 Variable size Memory Pool Management Function A variable size memory pool refers to the one in which a memory block of any desired size can be acquired from the mem ory pool The MR100 permits one of the following two memory pool management methods to be selected before the mem ory pool is used 1 Normal block method 2 Small block method Each of these methods are explained below Normal Block Method The technique that allows you to arbitrary define the size of memory block acquirable from the memory pool is termed Va riable size scheme The MR100 manages memory in terms of four fixed size memory block sizes The MR100 calculates the size of individual blocks
92. NT flgptn T RFLG Specifies the issuing task itself Specifies priority of task being executed then Task status Current priority of task Base priority of task Reason for which task is kept waiting Object ID for which task is kept waiting Remaining time before task times out Number of activation requests Number of wakeup requests Number of suspension requests Task status Reason for which task is kept waiting ID number of task at the top of waiting queue Current semaphore count value AND wait OR wait ID number of task at the top of waiting queue Current bit pattern of eventflag Formats related to data queue and short data queue typedef struct t_rdtq ID stskid ID rtskid UINT sdtqent T RDTG Formats related to mailbox typedef struct t_msg VP msghead T MSG typedef structt msg pri T MSG msgque PRI msgpri y T MSG PRI typedef struct t_mbx ID wtskid T_MSG pk msg T RMBX D number of task at the top of transmission waiting queue ID number of task at the top of reception waiting queue Number of data bytes contained in data queue Message header Message header Message priority ID number of task at the top of waiting queue Next message to be received Formats related to fixed size memory pool typedef
93. NT sdtqcnt 4 4 Data bytes contained in data queue T_RDTQ Assembly language APT include mr100 inc ref_dtq DTOID PK_RDTQ iref dtq DTQID PK RDTQ Parameters DTQID ID number of the target data queue PK_RDTQ Pointer to the packet to which data queue status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target data queue Al Pointer to the packet to which data queue status is returned Error code None Functional description This service call returns various statuses of the data queue indicated by dtqid siskid Returned to stskid is the ID number of the task at the top of a transmission waiting queue the next task to be de queued If no tasks are kept waiting TSK_NONE is returned wiskid Returned to wtskid is the ID number of the task at the top of a reception waiting queue the next task to be de queued If no tasks are kept waiting TSK_NONE is returned sdtqcnt Returned to sdtqcnt is the number of data bytes stored in the data queue area If this service call is to be issued from task context use ref dtq if issued from non task context use iref dtq 125 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RDTO rdtq ER ercd Brod ref dtg ID D
94. OR section This section stores interrupt vectors The start address of this section varies with the type of microcomputer used 225 8 Using Configurator 8 1 Configuration File Creation Procedure When applications program coding and startup program modification are completed it is then necessary to register the ap plications program in the MR100 system This registration is accomplished by the configuration file 8 1 1 Configuration File Data Entry Format This chapter describes how the definition data are entered in the configuration file Comment Statement A statement from to the end of a line is assumed to be a comment and not operated on End of statement Statements are terminated by Numerical Value Numerical values can be entered in the following format Hexadecimal Number Add Ox or OX to the beginning of a numerical value or h or H to the end If the value begins with an al phabetical letter between A and F with h or H attached to the end be sure to add 0 to the beginning Note that the system does not distinguish between the upper and lower case alphabetical characters A F used as numerical values Decimal Number Use an integer only as in 23 However it must not begin with 0 e Octal Numbers Add 0 to the beginning of a numerical value of O or o to end e Binary Numbers Add B or b to the end of a numerical value It must not begi
95. R100 is designed in compliance with the uITRON Specification which incorporates a minimum of the ITRON Specification functions so that such functions can be incorporated into a one chip microcomputer As the ITRON Specification is a subset of the ITRON Specification most of the knowledge obtained from published ITRON textbooks and ITRON seminars can be used as is Further the application programs developed using the real time operating systems conforming to the ITRON Specification can be transferred to the MR100 with comparative ease High speed processing is achieved MR100 enables high speed processing by taking full advantage of the microcomputer architecture Only necessary modules are automatically selected to constantly build up a system of the minimum size MR10O is supplied in the object library format of the R32C 100 series Therefore the Linkage Editor functions are activated so that only necessary modules are automatically selected from numerous MR100 functional modules to generate a system Thanks to this feature a system of the minimum size is automatically generated at all times With the C compiler NC100 it is possible to develop application programs in C language Application programs of MR100 can be developed in C language by using the C compiler NC100 Furthermore the interface library necessary to call the MR100 functions from C language is included with the software pack age An upstream process tool named Configura
96. REJ10J1523 0100 Everywhere you imagine y gE NESAS M3T MR100 4 V 1 00 Users Manual Real time OS for R32C 100 Series Rev 1 00 September 16 2007 Renesas Technology WWW renesas com Active X Microsoft MS DOS Visual Basic Visual C Windows and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and other countries IBM and AT are registered trademarks of International Business Machines Corporation Intel and Pentium are registered trademarks of Intel Corporation Adobe Acrobat and Acrobat Reader are trademarks of Adobe Systems Incorporated TRON is an abbreviation of The Real time Operating system Nucleus ITRON is an abbreviation of Industrial TRON ITRON is an abbreviation of Micro Industrial TRON TRON ITRON and ITRON do not refer to any specific product or products All other brand and product names are trademarks registered trademarks or service marks of their respective holders Keep safety first in your circuit designs Renesas Technology Corporation and Renesas Solutions Corporation put the maximum effort into making semiconductor products better and more reliable but there is always the possibility that trouble may occur with them Trouble with semiconductors may lead to personal injury fire or property damage Remember to give due consideration to safety when making your circuit designs with appro priate measures
97. Seo seer SSeS sae See Sa See aes 210 Define Dummy DA ASS SSS ES SS SSS esis SS eS eum e as 212 GLB _ SYS DMY INH 213 SYS DMY INH 214 REIT 215 216 IF CUSTOM SYS END 7A N I a ae a ag ho a oa le aha a A 218 Syscall exit rouitne to customize 219 220 GLB _ sys end 221 sys end 222 Customize here 223 REIT 224 ENDIF 225 226 ADA RARAS A SSeS SS SSS RA SD SSeS E 2283 exit function 228 a ae SSSR SS 229 GLB _exit exit 230 exit 231 Sexit 232 JMP exit 233 234 IF USE TIMER 221 236 System clock interrupt handler 237 238 GLB SYS STMR INH 239 ALIGN 240 SYS STMR INH 241 process issue system call 242 For PD100 243 _ ISSUE SYSCALL 244 245 System timer interrupt handler 246 STMR hdr 247 248 ret int 249 ENDIF 250 251 END 252 253 i kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk 254 COPYRIGHT C 2003 2007 RENESAS TECHNOLOGY CORPORATION 255 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED ELLLLLLLLLLLELLLLLLLLLLLLLLELLLELLLLLLLLLLLLLELLLLLLLLLLLLLLELLLLLLLLLI gt Figure 7 11 C Language Startup Program crtOmr a30 222 The following explains the content of the C language startup program crtOmr a30 OQ NOE mon Incorporate a section definition file 14 in Figure 7 11 Incorporate an include file for MR10
98. TO1 amp rdtq lt lt Example statement in assembly language gt gt refdtg blkb 8 include mr100 inc GLB task task PUSH W R2 PUSH L Al ref dtq ID_DTQ1 refdtq 126 5 6 Synchronization amp Communication Function Mailbox Specifications of the mailbox function of MR100 are listed in Table 5 11 Table 5 11 Specifications of the Mailbox Function No Item Content 1 Mailbox ID 1 255 2 Mailbox priority 1 255 TA_TFIFO Waiting tasks enqueued in order of FIFO TA TPRI Waiting tasks enqueued in order of priority 3 Mailbox attribute TA MFIFO Messages enqueued in order of FIFO TA MPRI Messages enqueued in order of priority Table 5 12 List of Mailbox Function Service Call No Service Call Function System State T N E DU 1 snd_mbx S B Send to mailbox O OO O 2 isnd_mbx O O O O 3 rcv mbx S B Receive from mailbox O O O 4 prev_mbx S B Receive from mailbox polling O OO O 5 iprcv_mbx OJO JO_O 6 trcv mbx S Receive from mailbox with timeout O O O 7 ref mbx Reference mailbox status O O O O 8 iref mbx O O O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispa
99. Task e Image expansion task e Printer engine task e Centronics interface interrupt handler This program uses the following MR100 library functions e sta tsk Starts a task Give the appropriate ID number as the argument to select the task to be activated When the ker nel id h file which is generated by the configurator is included it is possible to specify the task by name char acter string e wai flg Waits until the eventflag is set up In the example this function is used to wait until one page of data is entered into the buffer via the Centronics interface e wup_tsk Wakes up a specified task from the WAITING state This function is used to start the printer engine task e sip_tsk Causes a task in the RUNNING state to enter the WAITING state In the example this function is used to make the printer engine task wait for image expansion e set flg Sets the eventflag In the example this function is used to notify the image expansion task of the completion of one page data input The configurator converts the ID number to the associated name character string in accordance with the information entered int the con figuration file 207 include lt itron h gt include kernel h include kernel id h void main main task printf LBP start simulation An sta tsk ID idle 1 activate idle task sta tsk ID image 1 activate image expansion task Sta tsk ID printer 1 a
100. The section defined here must always have an area allocated for it in the section file asm sec inc or c sec inc If no section names are defined the memory pool is located in the MR HEAP section 9 Memory pool size Definition format Numeric value Definition range 16 to OXFFFFFFFC Default value None Specify a memory pool size Round off a block size you specify to the optimal block size among the four block sizes and acquires memory having the rounded off size from the memory pool The following equations define the block sizes a max_memsize X 1 X x 8 1 x 8 b ax2 c ax4 d ax8 max memsize the value specified in the configuration file X data size for block control 8 byte per a block control Variable size memory pool function needs 8 byte RAM area per a block control Memory pool size needs a size more than a b c or d that can be stored max_memsize 8 10 Select block usage Definition format Symbol Definition range ON OFF Default value OFF This is an option to increase memory efficiency for even small sized memory pools by means of small blocks Memory is managed in 12 fixed length memory pools ranging in size from 24 bytes to 65 528 bytes When this option is turned on the value of max memsize has no effect 243 Cyclic handler definition This definition is necessary to use Cyclic handler function lt lt Format gt gt Cyclic Handlar Def
101. This service call can also be invoked from a CPU locked state Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task BOOL stat stat sns dsp lt lt Example statement in assembly language gt gt include mr100 inc GLB task task sns dsp 180 sns dpn Reference dispatching pending state C Language API BOOL state sns dpn Parameters None Return Parameters BOOL state TRUE Dispatching pending state FALSE Not dispatching pending state Assembly language APT include mr100 inc sns dpn Parameters None Register contents after service call is issued Register name Content after service call is issued RO TRUE Dispatching pending state FALSE Not dispatching pending state Error code None Functional description This service call returns TRUE when the system is in a dispatching pending state or returns FALSE when the system is not in a dispatching pending state More specifically FALSE is returned when all of the following conditions are met other wise TRUE is returned 1 The system is not in a dispatching pending state 2 The system is not in a CPU locked state 3 The object made pending is a task This service call can also be invoked from a CPU locked state It returns TRUE when the system is in a dispatching dis abled state or
102. WAIPTN WFMODE TMO Parameters FLGID ID number of the eventflag waited for WAIPTN Wait bit pattern WFMODE Wait mode TMO Timeout value for twai_flg Register contents after service call is issued wai sem pol sem ipol sem Register name Content after service call is issued RO Error code R3RI bit pattern is returned when released from wait R2 ID number of the eventflag waited for Al Wait bit pattern twai_sem Register name Content after service call is issued RO Error code R3RI bit pattern is returned when released from wait R2 ID number of the eventflag waited for R6R4 Timeout value Al Wait bit pattern 113 Error code E_RLWAI Forced release from waiting E TMOUT Polling failure or timeout or timed out E ILUSE Service call improperly used Tasks present waiting for TA WSGL attribute eventflag Functional description This service call waits until the eventflag indicated by flgid has its bits specified by waiptn set according to task awaking conditions indicated by wfmode Returned to the area pointed to by p flgptn is the eventflag bit pat tern at the time the task is released from WAITING state If the target eventflag has the TA WSGL attribute and there are already other tasks waiting for the eventflag the error code E ILUSE is returned If task awaking conditions have already been met when this service call is invoked the task returns immediately and responds to the cal
103. YSTIM p systim Pointer to the packet that indicates the system time to be set Contents of p systim typedef struct t systim utime 0 2 16 high order bits UW time 4 4 32 low order bits SYSTIM Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc set_tim PK_TIM iset_tim PK_TIM O Parameters PK_TIM Pointer to the packet that indicates the system time to be set O Register contents after service call is issued Register name Content after service call is issued RO Error code Al Pointer to the packet that indicates the system time to be set Error code None Functional description This service call updates the current value of the system time to the value indicated by p_systim The time specified in p_systim is expressed in ms units and not by the number of time ticks The values specified for p_systim must be within 0x7FFF FFFFFFFF If any value exceeding this limit is specified the service call may not operate correctly If this service call is to be issued from task context use set tim if issued from non task context use iset tim 151 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task SYSTIME time Time data storing variable time utime 0 Sets upper time data time ltime 0 Sets lower time data set tim
104. a priority level lower than kernel interrupt handlers change the description of the non kernel interrupt handler to that of the kernel interrupt handler 213 1 Describe the cyclic or alarm handler as a function 2 Be sure to declare the return value and argument of the interrupt handler start function as a void type 3 At the beginning of file be sure to include itron h kernel h which is in the system di rectory as well as kernel id h which is in the current directory The static declared functions cannot be registered as a cyclic handler or alarm handler The cyclic handler and alarm handler are invoked by a subroutine call from a system clock interrupt handler include lt itron h gt include lt kernel h gt include kernel id h void cychand void process Figure 7 5 Example Cyclic Handler Written in C Language 4 The handler to function name correlation is determined by the configuration file 214 7 2 Program Coding Procedure in Assembly Language This section describes how to write an application using the assembly language 7 2 1 Writing Task This section describes how to write an application using the assembly language 1 Be sure to include mr100 inc at the beginning of file 2 For the symbol indicating the task start address make the external declaration Be sure that an infinite loop is formed for the task or the task is terminated by the ext tsk service call INCLU
105. able In that case if the attribute of the specified Short data queue is TA TFIFO the task is enqueued in order of FIFO if TA TPRI the task is enqueued in order of priority For vpsnd dtq and vipsnd dtq the task returns immediately and responds to the call with the error code E TMOUT For the vtsnd_dtq service call specify a wait time for tmout in ms units The values specified for tmout must be within Ox 7FFFFFFF time tick value If any value exceeding this limit is specified the service call may not operate correctly If TMO POL O is specified for tmout it means specifying 0 as a timeout value in which case the service call operates the same way as vpsnd dtq Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as vsnd_dtq If there are no tasks waiting for reception nor is the Short data queue area filled the transmitted data is stored in the Short data queue The task placed into a wait state by execution of the vsnd dtq or vtsnd dtq service call is released from WAITING state in the following cases When the vrcv dtq vtrcv dtq vprcv dtq or viprcv dtq service call is issued before the tmout time elapses with task awaking conditions thereby satisfied The error code returned in this case is E OK When the first time tick occurred after tmout elapsed while task awaking conditions remain un satisfied The error code returned in this case is E
106. ack size 512 priority 4 task 4 name ID idle entry address idle stack size 256 priority 5 Eventflag Definition flag 1 name pagein Interrupt Vector Definition interrupt vector 0x23 os_int YES entry address sent in Figure 6 3 Configuration File Example 6 2 3 Configurator Execution When using HEW select Build all which enables the user to execute the procedures described in 6 2 3 Executing the Configurator and 6 2 4 System Generation Execute the configurator cfg100 to generate system data definition files sys rom inc sys ram inc include files mr100 inc kernel id h and a system generation procedure description file makefile from the configuration file A cfg100 v lbp cfg MR100 system configurator V 1 00 18 Copyright 2003 2005 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED MR100 version V 1 01 Release 01 A gt Figure 6 4 Configurator Execution 6 2 4 System generation Execute the make command to generate the system 209 A make f makefile as100 F Dtest 1 crtOmr a30 nc100 c task c 1n100 1n100 sub A gt Figure 6 5 System Generation 6 2 5 Writing ROM Using the Imc30 load module converter convert the absolute module file into a ROM writable format and then write it into ROM Or read the file into the debugger and debug it 210 T Detailed Applications 7 1 Program Coding Procedure in C Lang
107. ag is an internal facility of MR100 that is used to synchronize the execution of multiple tasks The eventflag uses a flag wait pattern and a 32 bit pattern to control task execution A task is kept waiting until the flag wait conditions set are met It is possible to determine whether multiple waiting tasks can be enqueued in one eventflag waiting queue by specifying the eventflag attribute TA WSGL or TA WMUL Furthermore it is possible to clear the eventflag bit pattern to 0 when the eventflag meets wait conditions by specifying TA CLR for the eventflag attribute There are following eventflag service calls that are provided by the MR100 kernel Set Eventflag set flg iset flg Sets the eventflag so that a task waiting the eventflag is released from the WAITING state Clear Eventflag clr flg iclr flg Clears the Eventflag Wait for Eventflag wai flg twai flg Waits until the eventflag is set to a certain pattern There are two modes as listed below in which the eventflag is waited for AND wait Waits until all specified bits are set OR wait Waits until any one of the specified bits is set Wait for Eventflag polling pol flg ipol flg Examines whether the eventflag is in a certain pattern In this service call tasks are not placed in WAITING state Reference Eventflag Status ref flg iref flg Checks the existence of the bit pattern and wait task for the target eventflag 45 Figure 4 13 shows an example of t
108. aited The task goes into the WAITING state in one of the following ways The task enters the WAITING state simply when the slp tsk service call is issued In this case the task does not go into the READY state until its WAITING state is cleared explicitly by some other task The task enters and remains in the WAITING state for a specified time period when the dly tsk service call is issued In this case the task goes into the READY state when the specified time has elapsed or its WAITING state is cleared explicitly by some other task The task is placed into WAITING state for a wait request by the wai flg wai sem rcv mbx snd dtq rcv dtq vsnd dtq vrcv dtq or get mpf service call In this case the task goes from WAITING state to READY state when the request is met or WAITING state is explicitly canceled by another task The tslp tsk twai flg twai sem trcv mbx tsnd dtq trcv_dtq vtsnd dtq vtrcv dtq and tget mpf service calls are the timeout specified versions of the slp tsk wai flg wai sem rcv mbx snd dtq rcv dtq vsnd dtq vrcv dtq and get mpf service calls The task is placed into WAITING state for a wait request by one of these service calls In this case the task goes from WAITING state to READY state when the request is met or the specified time has elapsed If the task is placed into WAITING state for a wait request by the wai flg wai sem rcv mbx snd dtq rcv dtq vsnd dtq vrcv dtq get mpf twai flg twai sem t
109. all oooooonocccccnnnoccccnonannncnon 168 Table 5 24 List of Interrupt Management Function Service Call esee 182 Table 5 25 List of System Configuration Management Function Service Call 184 Table 5 26 Specifications of the Short Data Queue Function esses 187 Table 5 27 List of Long Dataqueue Function Service Call eese 187 Table 5 28 List of Reset Function Service Call sess 196 Table 7 1 C Language Variable Treatment sese rennen eene n emen enne nnne 212 Table 8 1 Numerical Value Entry Examples ooooonccnnnnnnononconononncononnnnnnonononnononnnnononnnnonconnnnnnonancncnnono 227 WADE 8 2 ODerabtOrSs4 eee A TE E ied BOER voted Rees 228 Table 8 3 List of vector number and vector address essen enne enne 248 Table 9 1 Functions in the Sample Program esee emen enen nennen ener 260 Table 10 1 Stack Sizes Used by Service Calls Issued from Tasks in bytes ses 272 Table 10 2 Stack Sizes Used by Service Calls Issued from Handlers in bytes 273 Table 10 3 Stack Sizes Used by Service Calls Issued from Tasks and Handlers in bytes 273 Table 11 1 Interrupt Number Assignment c cccccccccccsssssscecececeesesssceceeececceesenssaeceseesceesenssaeeeeees 275 xi xii 1 User s Manual Organization T
110. alm 0 12 0 wai sem 0 4 28 ref alm 0 16 0 pol sem 0 8 0 rot rdq 0 4 0 twai sem 0 4 28 get tid 0 8 0 ref sem 0 12 0 loc cpu 0 0 set flg 0 4 24 unl_cpu 0 4 0 clr_flg 0 8 0 ref ver 0 12 0 wai flg 4 28 vsnd dtq 0 4 28 pol flg 0 8 0 vpsnd_dtq 0 4 16 twai_flg 4 28 vtsnd dtq 0 4 28 ref_flg 0 8 0 vfsnd dtq 0 4 16 snd dtq 0 4 28 vrev_dtq 4 16 psnd_dtq 0 4 16 vprev_dtq 4 16 tsnd_dtq 0 4 28 vtrev_dtq 4 16 fsnd_dtq 0 4 16 vref_dtq 0 8 0 rcv_dtq 4 16 vrst_dtq 0 4 48 prev_dtq 4 16 vrst_vdtq 0 4 48 trcv dtq 4 16 vrst_mbx 0 8 0 ref_dtq 0 8 0 vrst_mpf 0 4 48 snd mbx 0 4 12 vrst mpl 0 28 68 dis dsp 0 0 ena dsp 0 4 0 Stack sizes used by service call in Assembly programs 272 Table 10 2 Stack Sizes Used by Service Calls Issued from Handlers in bytes lists the stack sizes system stack used by service calls that can be issued from handlers Table 10 2 Stack Sizes Used by Service Calls Issued from Handlers in bytes Stack size 16 28 12 20 28 32 32 64 12 20 12 20 12 20 12 24 12 20 12 28 12 24 12 24 12 28 12 24 16 20 12 12 20 16 12 24 32 64 32 64 36 64 12 20 24 52 Service call iprcv mbx iref mbx ipget mpf irel mpf iref mpf iset tim iget tim ista cyc istp cyc iref cyc ista alm istp alm iref alm irot_rdq iget_tid iloc_cpu iunl_cpu ret_int iref_ver vipsnd_dtq vifsnd_dtq viprcv dtq viref dtq isnd_mbx Stack size 12 40 12 24 12 40 24 52 1
111. andler that is started after the lapse of a specified relative time of day The alarm handler startup time of day is determined by a time of day relative to the time of day set by sta alm ista alm and is unaffected by a change in the time of day by set tim iset tim The cyclic and alarm handlers are invoked by a subroutine call from the system clock interrupt timer interrupt handler Therefore cyclic and alarm handlers operate as part of the system clock interrupt handler Note that when the cyclic or alarm handler is invoked it is executed in the interrupt priority level of the system clock interrupt 28 Task System clock interrupt handler Cyclic handler Alarm handler Subroutine call Timer interrupt Figure 3 21 Cyclic Handler Alarm Handler Activation 29 3 5 2 Dispatch Enabled Disabled States The system assumes either a dispatch enabled state or a dispatch disabled state In a dispatch disabled state no task sched uling is performed Nor can service calls be invoked that may cause the service call issuing task to enter a wait state The system can be placed into a dispatch disabled state or a dispatch enabled state by the dis dsp or ena dsp service call respectively Whether the system is in a dispatch disabled state can be known by the sns dsp service call 3 5 3 CPU Locked Unlocked States The system assumes either a CPU locked state or a CPU unlocked state In a CPU locked state all external
112. antee the operation 17 MR100 does not return an error even when an uninvocable service call is issued from a CPU locked state in which case however its operation cannot be guaranteed 30 3 6 Regarding Interrupts 3 6 1 Types of Interrupt Handlers MR1005 interrupt handlers consist of kernel interrupt handlers and non kernel interrupt handlers The following shows the definition of each type of interrupt handler e Kernel interrupt handler An interrupt handler whose interrupt priority level is lower than a kernel interruption mask level is called kernel interrupt handler That is interruption priority level is from 1 to system IPL A service call can be issued within a kernel interrupt handler However interrupt is delayed until it becomes re ceivable the kernel interrupt handler generated during service call processing Non kernel interrupt handler An interrupt handler whose interrupt priority level is higher than a kernel interrupt mask level is called non kernel interrupt handler That is interruption priority level is from system IPL 1 to 7 A service call cannot be issued within non kernel interrupt handler However the non kernel interrupt handler is able to be recieved during service call processing even if it is the section where it is not able to receive a kernel interrupt handler Figure 3 22 shows the relationship between the non kernel interrupt handlers and kernel interrupt handlers where the kernel mask level is s
113. apse of the time specified by almtim from the time at which it is invoked and places the alarm handler into an operational state If an already operating alarm handler is specified the previously set activation time is cleared and updated to a new activa tion time If almtim 0 is specified the alarm handler starts at the next time tick The values specified for almtim must be within Ox7FFFFFFF time tick value If any value exceeding this limit is specified the service call may not operate cor rectly If 0 is specified for almtim the alarm handler is started at the next time tick If this service call is to be issued from task context use sta_alm if issued from non task context use ista_alm 163 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task sta alm ID alm1 100 lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 PUSHM R6R4 sta alm ID_ALM1 100 164 stp alm Stop alarm handler operation istp alm Stop alarm handler operation handler only C Language API ER ercd stp alm ID almid ER ercd istp alm ID almid Parameters ID almid ID number of the alarm handler to be stopped Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc Stp alm ALMID istp alm
114. artup programs perform the following e Initialize the processor after a reset e Initialize C language variables crtOmr a30 only e Set the system timer e Initialize MR100 s data area Copy these startup programs from the directory indicated by environment variable LIB100 to the current directory If necessary correct or add the sections below Setting processor mode register Set a processor mode matched to your system to the processor mode register 58 60th line in crtOmr a30 e Adding user required initialization program When there is an initialization program that is required for your application add it to the 140th line in the C language startup program crtOmr a30 e Enable the 138th 139th line in the C language startup program crtOmr a30 if standard I O function is used 218 7 3 1 C Language Startup Program crtOmr a30 Figure 7 11 shows the C language startup program crtOmr a30 T kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk 2 QT MR100 start up program for C language 4 COPYRIGHT C 2003 2006 2007 RENESAS TECHNOLOGY CORPORATION 5 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED 6 MR100 7i 8 i kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk 9 SId crtOmr a30 512 2007 07 09 10 11 36Z inui 10 A1 2005 02 28 for ES 11 GO 2006 06 15 for MR100 4 12 5 13 LIST OFF 14 INCLUDE c sec inc T5 INCLUDE mr100 inc 16
115. ask context operation of this service call cannot be guaranteed This service call can be invoked for a task in DORMANT state as the target task In that case the return parameter is 0 If this service call is to be issued from task context use can act if issued from non task context use ican act 67 Example program statement 1 Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task1i ER UINT actcnt actcnt can act ID task2 void task2 ext tsk lt lt Example statement in assembly language gt gt INCLUDE mri00 inc GLB task task can act HID TASK2 68 sta tsk Activate task with a start code ista tsk Activate task with a start code handler only C Language API ER ercd sta_tsk ID tskid VP_INT stacd ER ercd ista_tsk ID tskid VP_INT stacd Parameters ID tskid ID number of the target task VP_INT stacd Task start code Return Parameters ER ercd Terminated normally E_OK or error code Assembly language APT include mr100 inc sta tsk TSKID STACD ista tsk TSKID STACD Parameters TSKID ID number of the target task STATCD Task start code Register contents after service call is issued Register name Content after service call is issued RO Error code R3RI Task start code R2 ID number of the target task Error code E OBJ Object status invalid task indicated by ts
116. ask execution control by the eventflag using the wai flg and set flg service calls The eventflag has a feature that it can wake up multiple tasks collectively at a time In Figure 4 13 there are six tasks linked one to another task A to task F When the flag pattern is set to OxF by the set flg service call the tasks that meet the wait conditions are removed sequentially from the top of the queue In this diagram the tasks that meet the wait conditions are task A task C and task E Out of these tasks task A task C and task E are removed from the queue If this event flag has a TA CLR attribute when the waiting of Task A is canceled the bit pattern of the event flag will be set to 0 and Task C and Task E will not be removed from queue Flag queue TaskA TaskB TaskC TaskD TaskE TaskF Flag pattern 0 Wait pattern OxOF OxFF OxOF OxFF OxFF 0x10 Wait mode OR AND AND AND OR OR set_flg TaskB TaskD TaskF Flag pattern OxOF Figure 4 13 Task Execution Control by the Eventflag 46 4 1 7 Synchronization and Communication Function Data Queue The data queue is a mechanism to perform data communication between tasks In Figure 4 14 for example task A can transmit data to the data queue and task B can receive the transmitted data from the data queue eged c S ct amp Fi N Task A Task B exe Figure 4 14 Data queue Data in width of 32 bits can be transmitted to this data queue The data queue has the func
117. assembly language gt gt include mr100 inc refdtg blkb 8 GLB task task PUSH W R2 PUSH L A1 vref dtq HID DTO1 4 refdtq 195 5 16 Extended Function Reset Function This function initializes the content of an object This function is outside the scope of uITRON 4 0 Specification Table 5 28 List of Reset Function Service Call No Service Call Function System State T N E D U L 1 vrst_dtq Clear data queue area O O O O 2 vrst_vdtq Clear Short data queue area O O O O 3 vrst_mbx Clear mailbox area O O O O 4 vrst_mpf Clear fixed size memory pool area O O O O 5 vrst_mpl Clear variable size memory pool area O O O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 196 vrst dtq Clear data queue area C Language APT ER ercd vrst dtq ID dtqid Parameters ID dtqid Data queue ID to be cleared Return Parameters ER ercd Terminated normally E OK Assembly language APT include mr100 inc vrst dtq DTQID Parameters DTQID Data queue ID to be cleared Register content
118. atement in assembly language gt gt include mr100 inc GLB task _ refalm blkb 6 task PUSH W R2 PUSH L A1 ref alm ID ALM1 refalm 167 5 12System Status Management Function Table 5 23 List of System Status Management Function Service Call No Service Call Function System State TIN E D U L 1 rot_rdq S B Rotates task precedence O O O0 2 irot rdq S B O 0 0 0 3 get tid SI B References task ID in the RUNNING state O O OJO 4 iget_tid S OJO ojo 5 loc_cpu S B Locks the CPU O O ojojo 6 iloc_cpu S O O OJOJ Oo 7 unl cpu SI B Unlocks the CPU O O OJOJ O 8 iun cpu S OJO olojo 9 dis_dsp SI B Disables dispatching O O ojo 10 ena_dsp SI B Enables dispatching O O olo 11 sns_ctx S References context O O OJO O 12 sns_loc S References CPU state O O OJO O 13 sns_dsp S References dispatching state O O O JO O 14 sns_dpn S References dispatching pending state O Oo OO OO 0 Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 168 rot rdq Rotate task prec
119. ation is returned Register contents after service call is issued Register name Content after service call is issued RO Error code Al Pointer to the packet to which version information is returned Error code None 185 Functional description This service call reads out information about the version of the currently executing kernel and returns the result to the area pointed to by pk rver The following information is returned to the packet pointed to by pk rver maker The code H 0115 denoting Renesas Technology Corporation is returned 9 prid The internal identification code IDH 0014 of the M3T MR100 is returned spver The code H 5403 denoting that the kernel is compliant with uITRON Specification Ver 4 03 00 is returned prver The code H 0100 denoting the version of the M3T MR100 4 is returned prno e pmo 0 Reserved for future extension e pmo l Reserved for future extension pmo 2 Reserved for future extension e pmo 3 Reserved for future extension If this service call is to be issued from task context use ref ver if issued from non task context use iref ver Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task T RVER pk rver ref ver amp pk rver lt lt Example statement in assembly language gt gt include mr100 inc GLB task _ refve
120. bbreviated as NC100 Document List The following sets of documents are supplied with the MR100 Release Note Presents a software overview and describes the corrections to the Users Manual and Reference Manual e Users Manual PDF file Describes the procedures and precautions to observe when using the MR100 for programming purposes Right of Software Use The right of software use conforms to the software license agreement You can use the MR100 for your product develop ment purposes only and are not allowed to use it for the other purposes You should also note that this manual does not guarantee or permit the exercise of the right of software use 1 Hereinafter abbreviated real time OS uITRON4 0 Specification is the open real time kernel specification upon which the TRON association decided The specification document of uITRONA4 0 specification can come to hand from a TRON association homepage http www assoc tron org The copyright of uITRONA 0 specification belongs to the TRON association Contents Requirements for MR1O00Use s 5 nnn sabia getto ii cri e ni duas i Document HASts soci E iii 1 Right of Software User datan 1 ONESIES sas ie vec neve etu eee codi iae Raven Sata ee edet eii loses be AS 111 East OF Rigures eb ee eiat e etu e ede de UD e ee mue viii Last Of Tables tai AA eiii xi 1 User s Manual Organization crol clle ed confor dde el dat dur dd sds PME General Information me 3 2 1 Objective of MR1
121. bjid 8 2 Waiting object ID TMO lefttmo 10 4 Left time before timeout UINT actcnt 14 4 Number of queued activation request counts UINT wupent 418 4 Number of queued wakeup request counts UINT suscnt 422 4 Number of nested suspension request counts T RTSK Assembly language APT include mr100 inc ref_tsk TSKID PK_RTSK iref_tsk TSKID PK_RTSK Parameters TSKID ID number of the target task PK_RTSK Pointer to the packet to which task status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target task Al Pointer to the packet to which task status is returned Error code None 79 Functional description This service call inspects the status of the task indicated by tskid and returns the current information on that task to the area pointed to by pk rtsk as a return parameter If TSK_SELF is specified the status of the issuing task itself is inspected If TSK SELF is specified for tskid in non task context operation of the service call cannot be guaranteed tskstat task status tskstat has one of the following values returned to it depending on the status of the specified task e TTS RUN 0x0001 RUNNING state e TTS RDY 0x0002 READY state e TTS WAI 0x0004 WAITING state e TTS SUS 0x0008 SUSPENDED state e TTS WAS 0x000C WAITING SUSPENDED state e TTS DMT 0x0010 DORMANT state tskpri current
122. box the transmitted message is passed to the task at the top of the waiting queue and the task is released from WAITING state To send a message to a mailbox whose attribute is TA_MFIFO add a T_MSG structure at the beginning of the message when creating it as shown in the example below To send a message to a mailbox whose attribute is TA MPRI add a T MSG PRI structure at the beginning of the message when creating it as shown in the example below Messages should always be created in a RAM area regardless of whether its attribute is TA MFIFO or TA MPRI The T MSG area is used by the kernel so that it cannot be rewritten after a message has been sent If this area is rewritten before the message is received after it was sent operation of the service call cannot be guaranteed If this service call is to be issued from task context use snd mbx if issued from non task context use isnd_mbx 128 lt lt Example format of a message gt gt typedef struct user msg T MSG t msg T MSG structure B data 16 User message data USER MSG Example format of a message with priority included gt gt typedef struct user msg T MSG PRI t msg T MSG PRI structure B data 16 User message data USER MSG Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h typedef struct pri message T MSG PRI
123. by execution of slp_tsk or tslp tsk the wakeup request is accumulated More specifically the wakeup request count for the target task to be awakened is incremented by 1 in which way wakeup requests are accumulated The maximum value of the wakeup request count is 255 If while the wakeup request count 2 255 a new wakeup request is generated exceeding this limit the error code E QOVR is returned to the task that issued the service call with the wakeup request count left intact If this service call is to be issued from task context use wup tsk if issued from non task context use iwup tsk 88 Example program statement 1 Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if wup tsk ID main E OK printf Can t wakeup main n j lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 wup tsk ID_TASK1 89 can wup Cancel wakeup request ican wup Cancel wakeup request handler only C Language API ER UINT wupcnt can wup ID tskid ER UINT wupcnt ican wup ID tskid Parameters ID tskid ID number of the target task Return Parameters ER UINT wupcnt gt 0 Canceled wakeup request count wupcnt lt 0 Error code Assembly language APT include mr100 inc can wup TSKID ican wup TSKID Parameters TSKID ID number of the target task
124. by irot_rdq service call However an error is not returned even if it is specified If the priority of the issuing task itself is specified in this service call the issuing task is relocated to behind the tail of the ready queue in which it is enqueued Note that if the ready queue of the specified priority has no tasks in it no operation is performed If this service call is to be issued from task context use rot rdq if issued from non task context use irot_rdq Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task rot rdq 2 lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R3 rot rdq 2 170 get tid Reference task ID in the RUNNING state iget tid Reference task ID in the RUNNING state handler only C Language API ER ercd get tid ID p tskid ER ercd iget tid ID p tskid Parameters ID p tskid Pointer to task ID Return Parameters ER ercd Terminated normally E OK ID p tskid Pointer to task ID Assembly language APT include mr100 inc get tid iget tid Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Acquired task ID Error code None Functional description This service call returns the task ID
125. by tskid is an inactive state 75 Functional description The priority base priority of the task specified by tskid is changed to the value indicated by tskpri and tasks are resched uled based on the result of change If this service call is executed on a task queued in a ready queue including a task under execution or a task in a wait queue in which tasks are queued in order of priority the object task is moved to the tail end of the tasks of relevant priority in the queue When the same priority as before is specified the object task is moved to the tail end of that queue also The smaller the number the higher the task priority with numeral 1 assigned the highest priority The minimum numeric value specifiable as priority is 1 Furthermore the maximum value of priority is the one specified in a configuration file and the specifiable range of priority is 1 to 255 For example if the following statement is written in a configuration file system stack_size 0x100 priority 13 then the specifiable range of priority is 1 to 13 If TSK SELF is specified the priority base priority of the issuing task is changed If TSK_SELF is specified for tskid in a non task context the program operation cannot be guaranteed If TPRI_INI is specified the priority of a task is changed to its startup priority specified when it is generated The changed task priority base priority remains effective until the task terminates or th
126. bytes 1 016 bytes 2 040 bytes 4 088 bytes 8 184 byte 16 376 bytes 32 760 bytes and 65 528 bytes 51 Comparison of Two Management Methods Processing speed Generally speaking the normal block method is faster in memory allocation deallocation processing than the small block method Memory usage efficiency If the difference between the maximum and minimum sizes of memory to be acquired is 8 times or more the small block method is higher in memory usage efficiency than the other method Ease of configuration For the normal block method it is necessary that the maximum memory size to be acquired be known to the MR100 However this is unnecessary for the small block method The variable length memory pool management service calls provided by the MR100 include the following Geta memory block pget mpl The block size specified by the user is acquired by first rounding it to the optimum block size among the four kinds of block sizes and then acquiring a memory block of the rounded size from the memory pool For example if the user requests 200 bytes of memory the requested size is rounded to 224 bytes so that 224 bytes of memory is acquired If a requested block of memory is successfully acquired the start address of the ac quired memory block and error code E OK are returned If memory acquisition fails error code E TMOUT is returned 200 bytes TaskA Rounding Memorypool pget mpl 224 bytes
127. calculation utilityr for detailed use of it Assembly language The stack size to be used by Alarm or Cyclic handler register to be used user size stack size to be used by service call If neither cyclic handler nor alarm handler is used then y 72 bytes When using the interrupt handler and system clock interrupt handler in combination add the stack sizes used by both 271 10 2Necessary Stack Size Table 10 1 Stack Sizes Used by Service Calls Issued from Tasks in bytes lists the stack sizes system stack used by service calls that can be issued from tasks Table 10 1 Stack Sizes Used by Service Calls Issued from Tasks in bytes Service call Stack size Service call Stack size User stack System User stack System stack stack act tsk 0 4 4 rcv mbx 4 28 can act 0 12 0 prev_mbx 0 16 0 sta tsk 0 4 4 trcv mbx 0 4 28 ext tsk 0 4 ref mbx 0 8 0 ter_tsk 0 4 16 get_mpf 4 28 chg pri 0 4 16 pget mpf 020 0 get pri 0 12 0 tget mpf 4 32 ref tsk 0 32 0 rel mpf 0 4 16 ref tst 0 12 0 ref mpf 0 8 0 slp tsk 0 4 4 pget_mpl 4 74 tslp_tsk 0 4 8 rel mpl 0 4 38 wup tsk 0 4 16 ref mpl 0 20 0 can wup 0 12 0 set tim 0 8 0 rel wai 0 4 16 get tim 0 8 0 sus tsk 0 4 4 sta cyc 0 12 0 rsm tsk 0 4 4 stp cyc 0 8 0 frsm_tsk 0 4 4 ref cyc 0 16 0 dly_tsk 0 4 8 sta_alm 002 0 sig_sem 0 4 16 stp_
128. call is invoked Invoking this service call again while the system is already in a dispatching disabled state does not cause an error in which case task queuing is not performed however This service call can be issued only from task context It cannot be issued from non task context 175 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task dis dsp lt lt Example statement in assembly language gt gt include mr100 inc GLB task task dis dsp 176 ena dsp Enables dispatching C Language APT ER ercd ena_dsp Parameters None Return Parameters ER ercd Terminated normally E_OK Assembly language APT include mr100 inc ena_dsp O Parameters None O Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Functional description This service call frees the system from a dispatching disabled state that was set by the dis_dsp service call As a result task scheduling is resumed when the system has entered a task execution state Invoking this service call from a task execution state does not cause an error in which case task queuing is not performed however This service call can be issued only from task context It cannot be issued from non task context Example p
129. case a FREIT instruction is output at return from the interrupt handler If B is specified a B switch is selected in which case register bank 1 is selected If R is specified a R switch is selected in which case no codes are output that change the floating number rounding mode of the FLG register to the nearest value Multiple switches can be specified at the same time However if a kernel managed interrupt handler is con cerned only the E or R switch can be specified For non kernel managed interrupt handlers the E F and B switches can be specified providing that E and B are not specified at the same time Fixed interrupt vector definition This definition needs to be set when interrupt handlers based on fixed vector table are used lt lt Format gt gt Fixed Interrupt Vector Definition interrupt fvector Vector No entry address Start address pragma switch Switch passed to PRAGMA extended function H The interrupt vector number can be set in the range from 0 to 11 The relationship between the vector numbers and the in terrupts and vector addresses is shown below All these interrupts are handled as non kernel managed interrupt handlers 247 Table 8 3 List of vector number and vector address Vector number Vector address Interrupt 0 FFFFFFDOH Kernel reserved area 1 FFFFFFD4H Kernel reserved area 2 FFFFF
130. cd ifrsm tsk ID tskid Parameters ID tskid ID number of the target task Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr100 inc rsm tsk TSKID irsm tsk TSKID frsm tsk TSKID ifrsm tsk TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is not a forcible wait state Functional description If the task indicated by tskid has been aborted by sus_tsk this service call resumes the target task from SUSPENDED state In this case the target task is linked to behind the tail of the ready queue In the case of frsm_tsk and ifrsm_tsk the task is forcibly resumed from SUSPENDED state If a request is issued while the target task is not in SUSPENDED state including DORMANT state the error code E OBJ is returned to the service call issuing task The rsm_tsk irsm_tsk frsm_tsk and ifrsm_tsk service calls each operate the same way because the maximum number of forcible wait requests that can be nested is 1 If this service call is to be issued from task context use rsm tsk frsm tsk if issued from non task context use irsm_tsk ifrsm_tsk 96 Example program statement 1 lt lt Example statement in C language gt gt i
131. clic handler The operating status of the target cyclic handler and the remaining time before it starts next time are inspected 56 4 1 13 Alarm Handler Function The alarm handler is a time event handler that is started only once at a specified time Use of the alarm handler makes it possible to perform time dependent processing The time of day is specified by a relative time Figure 4 23 shows a typical operation of the alarm handler Start operating Stop operating Start operating Alarm handler created Activation Activation time time Handler starts Handler does not start Figure 4 23 Typical operation of the alarm handler e Start Alarm Handler Operation sta alm ista alm Causes the alarm handler with the specified ID to operational state e Stop alarm Handler Operation stp alm istp alm Causes the alarm handler with the specified ID to non operational state e Reference Alarm Handler Status ref alm iref alm Refers to the status of the alarm handler The operating status of the target alarm handler and the remaining time before it starts are inspected 57 4 1 14 System Status Management Function Rotate Task Precedence rot rdq irot rdq This service call establishes the TSS time sharing system That is if the ready queue is rotated at regular inter vals round robin scheduling required for the TSS is accomplished See Figure 4 24 Prior
132. ctional description This service call returns various statuses of the mailbox indicated by mbxid wtskid Returned to wtskid is the ID number of the task at the top of a reception waiting queue the next task to be de queued If no tasks are kept waiting TSK NONE is returned 9 pk msg Returned to pk msg is the start address of the next message to be received If there are no messages to be re ceived next NULL is returned T MSG should be specified with a 32 bit address If this service call is to be issued from task context use ref mbx if issued from non task context use iref mbx 133 Example program statement 1 Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RMBX rmbx ER ercd ercd ref mbx ID MBX1 amp rmbx lt lt Example statement in assembly language gt gt include mr100 inc GLB task refmbx blkb 6 task PUSH W R2 PUSH L A1 ref mbx ID MBX1 refmbx 134 5 7 Memory Pool Management Function Fixed size Memory Pool Specifications of the fixed size memory pool function of MR100 are listed in Table 5 13 The memory pool area to be acquired can be specified by a section name for each memory pool during configuration Table 5 13 Specifications of the Fixed size memory pool Function
133. ctivate printer engine task void image activate image expansion task while 1 wai flg ID pagein waiptn TWF ANDW amp flgptn wait for 1 page input printf bit map expansion processing In wup_tsk ID printer wake up printer engine task void printer printer engine task while 1 slp tsk printf printer engine operation Mn void sent_in Centronics interface handler Process input from Centronics interface if 1 page input completed iset flg ID pagein setptn Figure 6 2 Program Example 6 2 2 Configuration File Preparation Create a configuration file which has defined in it the task entry address stack size etc Use of the GUI configurator avail able for MR100 helps to create a configuration file easily without having to learn how to write it Figure 6 3 Configuration File Example shows an example configuration file for a laser beam printer simulation program filename Ibp cfg 208 System Definition system stack size 1024 priority E5S System IPL 4 tick nume 10 System Clock Definition clock mpu clock 20MHz timer A0 IPL 4 Task Definition task 1 name ID main entry address main stack size 512 priority 13 initial start ON task 2 name ID_image entry address image stack size 5127 priority 127 task 3 name ID_printer entry_address printer st
134. currently in RUNNING state to the area pointed to by p_tskid If this service call is issued from a task the ID number of the issuing task is returned If this service call is issued from non task context the task ID being executed at that point in time is returned If there are no tasks currently in an executing state TSK_NONE is re turned If this service call is to be issued from task context use get tid if issued from non task context use iget tid Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task ID tskid get_tid amp tskid lt lt Example statement in assembly language gt gt include mr100 inc GLB task task get tid 171 loc cpu Lock the CPU iloc cpu Lock the CPU handler only C Language API ER ercd loc_cpu ER ercd iloc_cpu Parameters None Return Parameters ER ercd Terminated normally E OK Assembly language APT include mr100 inc loc_cpu iloc_cpu O Parameters None O Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Functional description This service call places the system into a CPU locked state thereby disabling interrupts and task dispatches The features of a CPU locked state are outlined below 1 No task scheduling is performed during
135. d tsnd_dtq 249 104 data dtqid tmout ercd 283 Synchronization amp Communication Function Parameter ReturnParameter ARAS erue R3R1 R2 R6R4 Al RO R3R1 Al rev_dtq 249 84 dtqid ercd data prev_dtq 249 86 dtqid ercd data iprcv dtq 250 88 dtqid ercd data trev_dtq 249 90 dtqid tmout ercd data ref_dtq 250 92 dtqid pk_rdtq ercd iref_dtq 250 92 dtqid pk_rdtq ercd snd_mbx 249 94 mbxid pk_msg ercd isnd_mbx 250 96 mbxid pk_msg ercd rcv mbx 249 98 mbxid ercd s pk msg prev_mbx 250 100 mbxid ercd a pk_msg lprcv mbx 250 100 mbxid ercd 3 pk_msg trev_mbx 249 102 mbxid tmout ercd E pk msg ref mbx 250 104 mbxid pk rmbx ercd iref mbx 250 104 mbxid pk rmbx ercd 284 Interrupt Management Functions ServiceCall ret int INTNo 251 Parameter ReturnParameter FuncCode AO RO System State Management Functions Parameter ReturnParameter ServiceCall INTNo FuncCode R3 BG m AO rot_rdq 249 140 tskpri ercd irot_rdq 250 142 tskpri ercd get_tid 250 144 ercd tskid iget_tid 250 144 ercd tskid loc_cpu 253 198 ercd iloc_cpu 253 200 ercd dis_dsp 252 206 ercd ena_dsp 249 150 ercd unl_cpu 249 146 ercd iunl cpu 250 148 ercd sns_ctx 250 152 ercd sns_loc 250 154 ercd sn
136. d size memory pool indicated by mpfid If tasks are enqueued in a memory block wait ing queue all of the tasks enqueued in the memory block waiting queue are released from WAITING state Furthermore the error code EV RST is returned to the tasks that have been released from WAITING state This service call can be issued only from task context It cannot be issued from non task context Example program statement 1 Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task1 void vrst mpf ID mpf1 lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 vrst mpf HID MPF1 203 vrst mpl Clear variable size memory pool area C Language APT ER ercd vrst_mpl ID mplid Parameters ID mplid Variable size memory pool ID to be cleared Return Parameters ER ercd Terminated normally E_OK Assembly language APT include mr100 inc vrst mpl MPLID Parameters MPLID Variable size memory pool ID to be cleared Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Variable size memory pool ID to be cleared Error code None Functional description 1 This service call initializes the variable size memory pool indicated by mplid This service call can be issued only from task context It cannot be is
137. de mr100 inc vref dtq VDTOID PK_RDTO viref dtqVDTOID PK RDTQ Parameters VDTQID ID number of the target Short data queue PK RDTQ Pointer to the packet to which Short data queue status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target Short data queue Al Pointer to the packet to which Short data queue status is returned Error code None 194 Functional description This service call returns various statuses of the Short data queue indicated by vdtqid stskid Returned to stskid is the ID number of the task at the top of a transmission waiting queue the next task to be de queued If no tasks are kept waiting TSK NONE is returned wtskid Returned to wtskid is the ID number of the task at the top of a reception waiting queue the next task to be de queued If no tasks are kept waiting TSK NONE is returned sdtqcnt Returned to sdtqcnt is the number of data bytes stored in the Short data queue area If this service call is to be issued from task context use ref dtq if issued from non task context use iref dtq Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RDTO rdtq ER ercd ercd vref dtq ID DTO1 amp rdtq lt lt Example statement in
138. dicated by semid If the semaphore resource count is equal to or greater than 1 the semaphore resource count is decremented by 1 and the service call issuing task continues execution On the other hand if the semaphore count value is 0 the wai sem or twai sem service call invoking task is enqueued in a waiting queue for that semaphore If the attribute of the semaphore semid is TA TFIFO the task is enqueued in order of FIFO if TA TPRI the task is enqueued in order of priority For the pol sem and ipol sem service calls the task returns immediately and responds to the call with the error code E TMOUT For the twai sem service call specify a wait time for tmout in ms units The values specified for tmout must be within Ox7FFFFFFF time tick value If any value exceeding this limit is specified operation of the service call cannot be guar anteed If TMO_POL 0 is specified for tmout it means specifying O as a timeout value in which case the service call op erates the same way as pol sem Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as wai sem The task placed into WAITING state by execution of the wai sem or twai sem service call is released from the WAITING state in the following cases When the sig sem or isig sem service call is issued before the tmout time elapses with task awaking conditions thereby satisfied The error code returned in
139. dler of Specific Level 7 2 4 Writing Cyclic Handler Alarm Handler When describing the cyclic or alarm handler in Assembly Language observe the following precautions The relationship between task ID numbers and tasks program is defined in the configuration file Use the GLB peudo directive 50 If you want the non kernel interrupt handler to be assigned a priority level lower than kernel interrupt handlers change the description of the non kernel interrupt handler to that of the kernel interrupt handler 216 1 Atthe beginning of file be sure to include mr100 inc which is in the system directory 2 Forthe symbol indicating the handler start address make the external declaration Always use the RTS instruction subroutine return instruction to return from cyclic han dlers and alarm handlers For examples INCLUDE mr100 inc 1 GLB cychand 2 cychand handler process rts D 2 060 2 3 Figure 7 10 Example Handler Written in Assembly Language 5 Use the GLB pseudo directive 217 7 3 Modifying MR100 Startup Program MR100 comes with two types of startup programs as described below start a30 This startup program is used when you created a program using the assembly language crtOmr a30 This startup program is used when you created a program using the C language This program is derived from start a30 by adding an initialization routine in C language The st
140. e lt kernel h gt include kernel id h void task loc cpu lt lt Example statement in assembly language gt gt include mr100 inc GLB task task loc cpu 173 unl cpu Unlock the CPU iunl cpu Unlock the CPU handler only C Language API ER ercd unl cpu ER ercd iunl cpu Parameters None Return Parameters ER ercd Terminated normally E OK Assembly language APT include mr100 inc unl_cpu iunl cpu Parameters None Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Functional description This service call frees the system from a CPU locked state that was set by the loc cpu or iloc cpu service call If the unl cpu service call is issued from a dispatching enabled state task scheduling is performed If the system was put into a CPU locked state by invoking iloc cpu within an interrupt handler the system must always be placed out of a CPU locked state by invoking iunl_cpu before it returns from the interrupt handler The CPU locked state and the dispatching disabled state are managed independently of each other Therefore the system cannot be freed from a dispatching disabled state by the unl cpu or iunl cpu service call unless the ena dsp service call is used If this service call is to be issued from task context use unl cpu if issued from non task context use iu
141. e OS is put to use the developed software consists of small program modules called tasks Therefore increased software maintainability is provided because developed software maintenance can be carried out simply by maintaining small tasks Increased software reliability is assured The introduction of the real time OS makes it possible to carry out program evaluation and testing in the unit of a small module called task This feature facilitates evaluation and testing and increases software reliability The microcomputer performance can be optimized to improve the performance of microcom puter based products With the real time OS it is possible to decrease the number of unnecessary microcomputer operations such as I O waiting It means that the optimum capabilities can be obtained from microcomputers and this will lead to mi crocomputer based product performance improvement 2 2 Relationship between TRON Specification and MR100 MR1O00 is the real time operating system developed for use with the R32C 10 series of 32 bit microcomputers compliant with uITRON 4 0 Specification uITRON 4 0 Specification stipulates standard profiles as an attempt to ensure software portability Of these standard profiles MR100 has implemented in it all service calls except for static APIs and task excep tion APIs 2 3 MR100 Features The MR100 offers the following features 1 Real time operating system conforming to the uITORN Specification The M
142. e character with Command Options v Option Displays the command option descriptions and detailed information on the version V Option Displays the information on the files generated by the command Eipl Option Enable the check function of an IPL value When System IPL 7 in the con figuration file the error message system IPL should be 7 is displayed and the execution of cfg100 is stpped Wipl Option Enable the check function of a IPL value When System IPL 7 in the con figuration file the error message system IPL should be 7 is displayed 8 2 4 Precautions on Executing Configurator The following lists the precautions to be observed when executing the configurator Do not modify the startup program name and the section definition file name Otherwise an error may be encountered when executing the configurator 256 8 2 5 Configurator Error Indications and Remedies If any of the following messages is displayed the configurator is not normally functioning Therefore correct the configu ration file as appropriate and the execute the configurator again Error messages cfg100 Error Syntax error near line xxx xxxx cfg There is an syntax error in the configuration file cfg100 Error Not enough memory Memory is insufficient cfg100 Error Illegal option gt lt x gt The configurator s command option is erroneous cfg100 Error Illegal argument gt lt xx gt T
143. e e x 10 11 include lt itron h gt 12 include lt kernel h gt 13 include kernel id h 14 include lt stdio h gt 15 16 17 i main VP INT stacd 18 19 Sta tsk ID task1 0 20 Sta tsk ID task2 0 21 sta cyc ID cyh1 22 23 void task1 VP INT stacd 24 25 while 1 26 wai sem ID seml 27 slp tsk 28 printf task1 running Wn 29 Sig sem ID seml 30 31 32 33 void task2 VP_INT stacd 34 35 while 1 36 wai sem ID seml 37 printf task2 running Wn 38 Sig sem ID seml 39 40 41 42 ian cyhl1 VP INT exinf 43 44 iwup tsk ID task1l 45 46 261 9 3 Configuration File al J BR RK RK RK ke AAA AA RRA ARA KK RARA RRA k k k ke k k RR RR k k k k RR RR RK KR k k k k k 2 3 COPYRIGHT C 2003 2005 RENESAS TECHNOLOGY CORPORATION 4 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED 5 6 MR100 System Configuration File 7 SId smp cfg v 1 5 2005 06 15 05 41 54 inui Exp 8 9 A Don AP o A A 10 11 System Definition 12 system 13 stack size 1024 14 priority 10 15 System IPL 4 16 tic_nume Eos 17 tic deno T 18 message pri 255 19 20 System Clock Definition 21 clock 22 mpu_clock 20MHz 23 timer AO 24 IPL 4 25 5 26 Task Definition 27 28 task 29 entry address main 30 name ID main 31 stack size 100 32 priority Ee 33 initial start ON 34 35 task 36
144. e startup cycle is shorter than the time tick interval the cyclic handler is started only once every time tick supplied processing equivalent to isig tim For example if the time tick interval is 10 ms and the startup cycle is 3 ms and the cy clic handler has started operating when a time tick is supplied then the cyclic handler is started every time tick Start operating Stop operating Cyclic handler created Activation Activation Activation Activation phase i cycle cycle cycle cycle v v v Handler does Handler does Handler starts Handler starts Handler does not start not start not start Figure 4 21 Cyclic handler operation in cases where the activation phase is saved Start operating Stop operating Cyclic handler created I M gt I a E D I Activation Activation y Activation Activation Activation phase i cycle i cycle cycle cycle i v v v Handler does Handler does Handler starts Handler starts Handler does not start not start not start Figure 4 22 Cyclic handler operation in cases where the activation phase is not saved Start Cyclic Handler Operation sta cyc ista_cyc Causes the cyclic handler with the specified ID to operational state Stop Cyclic Handler Operation stp cyc istp cyc Causes the cyclic handler with the specified ID to non operational state e Reference Cyclic Handler Status ref cyc iref cyc Refers to the status of the cy
145. e suspended task sees eee en nnne ee enter nnne en 96 ifrsm tsk Forcibly resume suspended task handler only sseeeeenes 96 dly tske Delayitask sinas eon Tec unique ECCE este 98 5 3 Synchronization amp Communication Function Semaphore sese 100 sig sem Release semaphore resource ccccccnnonooonnnoncnnnnononnnnononcnnonnnnnn nono nononnononnn nn nn nnnrononnnnn nono nnnnonannnnns 101 isig sem Release semaphore resource handler only sse 101 wal_sem Acquire semaphore resource esssseseseeeeeeenee enne eren et ee tene rers e eese tet ense seen nete nnns 108 polsem Acquire semaphore resource polling esee 108 ipol sem Acquire semaphore resource polling handler only sse 103 twai sem Acquire semaphore resource with timeout esee nnne 103 ref sem Reference semaphore status ooccccconononononanonnnnonnnnnnonnnnnnonnonnnnononononnononnnnonononnnnconononnananannnnos 106 iref sem Reference semaphore status handler only seen 106 5 4 Synchronization amp Communication Function Eventflag ccccccccccsescsssescssesecseesseseeseescssesseeeees 108 set flg Set eventilas ac eo ecce Ae RU coo MERE tren b toad te Baba Eod A back ta Beko do e Boke 109 iset_flg Set eventflag handler only id oda a tide vede ua iata td 109 clecflo Cleareventtlag 5 A A A HP
146. ecified in a program 238 2 Number of data Definition format Numeric Value Definition range 0 to Ox1FFF Default value 0 Specify the number of data that can be transmitted What should be specified here is the number of data and not a data size 3 Selecting a data queue waiting queue Definition format Symbol Definition range TA TFIFO or TA TRPI Default value TA TFIFO Select a method in which tasks wait for data queue transmission If TA_TFIFO is selected tasks are enqueued in order of FIFO If TA TPRI is selected tasks are enqueued in order of priority beginning with the one that has the highest priority Short data queue definition This definition must always be set when the short data queue function is to be used lt lt Format gt gt Vdataqueue Definition vdataqueue ID No name ID name buffer_size Number of data queues wait_queue Select data queue waiting queue Js The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are automatically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each short data queue ID number define the items described below 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the short data queue is specified in a program 2 Number
147. ed See Figure 4 4 37 Priority 1 I r TaskA Task B n TaskE gt Task FE When the priority of task B has been changed from 3 to Figure 4 3 Alteration of task priority ID Number 1 2 FTU Y 3 task taskB taskC taskB Ens 4 Priority 1 Priority 2 Priority 3 Priority 4 n When the priority of Task B is changed into 4 Figure 4 4 Task rearrangement in a waiting queue Reference task priority get pri iget pri Gets the priority of a task Reference task status simple version ref tst iref tst Refers to the state of the target task Reference task status ref tsk iref tsk Refers to the state of the target task and its priority etc 38 4 1 4 Synchronization functions attached to task The task dependent synchronization functions attached to task is used to accomplish synchronization between tasks by placing a task in the WAIT SUSPENDED or WAIT SUSPENDED state or waking up a WAIT state task The MR100 offers the following task incorporated synchronization service calls e Put Task to sleep slp tsk tslp tsk Wakeup task wup tsk iwup tsk Wakeups a task that has been placed in a WAIT state by the slp_tsk or tslp_tsk service call No task can be waked up unless they have been placed in a WAITING state by If a wakeup requ
148. edence irot rdq Rotate task precedence handler only C Language API ER ercd rot rdq PRI tskpri ER ercd irot rdq PRI tskpri Parameters PRI tskpri Task priority to be rotated Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc rot rdq TSKPRI irot rdq TSKPRI Parameters TSKPRI Task priority to be rotated Register contents after service call is issued Register name Content after service call is issued RO Error code R3 Task priority to be rotated Error code None 169 Functional description This service call rotates the ready queue whose priority is indicated by tskpri In other words it relocates the task enqueued at the top of the ready queue of the specified priority by linking it to behind the tail of the ready queue thereby switching over the executed tasks that have the same priority Figure 5 1 depicts the manner of how this is performed Proprity 1 TCB Priority 2 TCB TCB Moved to behind the tail of the queue Figure 5 1 Manipulation of the ready queue by the rot rdq service call By issuing this service call at given intervals it is possible to perform round robin scheduling If tskpriZTPRI SELF is specified when using the rot rdq service call the ready queue whose priority is that of the issuing task is rotated TPRI SELF cannot be specified in the irot rdq service call TPRI SELF cannot be specified
149. eesesersseaeeeeeess 268 10 2 Necessary Stack Size teet rene oe irre ter ee reet aeo cod Tete erbe egeret deed Teva To ed 272 PA AAA An Cn ee E EAS 275 ILL Me Useof INT Instruction ala lola iS 11 2 The Use of registers of bank occcccnnnnooononnncnnnnnonononononnonoonnnnononononnononnnnonononcnnonnnnn tren s sene nennen annis 2765 11 3 Regarding Delay Dispatching 0 cccccccccccccceceesessscecesececeensseceeececceceeseseseeesecsesensaeseeeesesenensaaeess 276 11 4 Regarding Initially Activated Task cccccccccccesssssececcceceesesssseeececseeesssssseeeeeecsesenesssaeeeeeeseneneaaees 277 12 Appendix aia idad 279 I12 T Data PE a ERI 2795 12 2 Common Constants and Packet Format of Structure ccccccccccesesssesseceeececeeeesssseceeeeeceseensaaaees 280 12 8 Assembly Language Interface ccccccccsscscsccecessesssceeecececesesensssecececsceesessaeeececseeeseesssaeeeeeesenensneess 282 vii List of Figures Figure 3 1 Relationship between Program Size and Development Period usss Sm Figure 3 2 Microcomputer based System Example Audio Equipment sse 98 Figure 3 3 Example System Configuration with Real time OS Audio Equipment js Figure 3 4 Time division Task Operation cccccccccssscessssssesecseeeeecsesseeecseseeeceessaeeecsssseseeneseeeeneaas 10 Figure 3 5 Task Execution Interruption and Resumption cccocnno
150. efmpl blkb 10 task PUSH W R2 PUSH L A1 ref mpl ID MPL1 refmpl 149 5 9 Time Management Function Specifications of the time management function of MR100 are listed in Table 5 17 Table 5 17 Specifications of the Time Management Function No Item Content 1 System time value Unsigned 48 bits 2 Unit of system time value 1 ms 3 System time updating cycle User specified time tick updating time ms 4 Initial value of system time at initial startup 000000000000H Table 5 18 List of Time Management Function Service Call No Service Call Function System State T N E D U 1 get tim S Reference system time O O O O 2 iget tim O O O O 3 set_tim S Set system time O Q Q Q 4 iset tim O O O 5 isig_tim S Supply a time tick O O O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 150 set tim Set system time Iset tim Set system time handler only C Language API ER ercd set tim SYSTIM p systim ER ercd iset tim SYSTIM p systim Parameters S
151. entry address task1 37 name ID task1 38 stack size 500 39 priority 2 40 41 task 42 entry address task2 43 name ID task2 44 stack size 500 45 priority E35 46 y 47 48 semaphore 49 name ID sem1 50 max count 1 51 initial count 1 52 wait queue TA TPRI 53 54 55 56 57 cyclic hand 1 58 name ID cyhl 59 interval counter 100 60 start OFF 61 phsatr OFF 62 phs_counter 0 63 entry_address cyh1 64 exinf 21 65 y 262 263 10 Stack Size Calculation Method 10 1Stack Size Calculation Method The MR100 provides two kinds of stacks the system stack and the user stack The stack size calculation method differ be tween the stacks O User stack This stack is provided for each task Therefore writing an application by using the MR100 requires to allocate the stack area for each stack O System stack This stack is used inside the MR100 or during the execution of the handler When a task issues a service call the MR100 switches the user stack to the system stack See Figure 10 1 System Stack and User Stack The system stack uses interrupt stack ISP Task MR100 Service Call Processing Position Register save Stack switching Service call rocessing Task Selection Stack switching Register return User Stack System Stack interruput stack XXX XXX User Stack Figure 10 1 System Stack and User Stack
152. est is issued to a task that has been kept waiting for conditions other than the slp_tsk or tslp tsk service call or a task in other than DORMANT state by the wup tsk or iwup tsk service call that wakeup re quest only will be accumulated Therefore if a wakeup request is issued to a task RUNNING state for example this wakeup request is temporar ily stored in memory Then when the task in RUNNING state is going to be placed into WAITING state by the slp_tsk or tslp tsk service call the accumulated wakeup request becomes effective so that the task continues ex ecuting again without going to WAITING state See Figure 4 5 e Cancel Task Wakeup Requests can wup Clears the stored wakeup request See Figure 4 6 wup tsk wup tsk wup tsk M Spe o slp_tsk Wakeup request count 0 0 1 2 1 Figure 4 5 Wakeup Request Storage wup tsk wup_tsk can wup EA Spe EN slp al i Wakeup request count 0 0 1 0 0 Figure 4 6 Wakeup Request Cancellation 21 Note that tasks in WAITING state but kept waiting for the following conditions are not awaken Eventflag wait state semaphore wait state data transmission wait state data reception wait state timeout wait state fixed length memory pool acquisition wait short data transmission wait or short data reception wait 39 Suspend task sus tsk isus tsk Resume suspended task rsm tsk irsm tsk These service calls forcibly keep a task suspended for execution or resume execution of a task If
153. et to 3 Kernel mask level Kernel Non kernel Interrupt handler Interrupt handler Figure 3 22 Interrupt handler IPLs 3 6 2 The Use of Non maskable Interrupt Non maskable interrupt ex NMI interrupt Watchdog Timer interrupt are treated as a non kernel interrupt handler 31 3 6 3 Controlling Interrupts Interrupt enable disable control in a service call is accomplished by IPL manipulation The IPL value in a service call is set to the kernel mask level OS interrupt disable level system IPL in order to disable interrupts for the kernel interrupt han dler In sections where all interrupts can be enabled it is returned to the initial IPL value when the service call was invoked For service calls that can be issued from only task context When the I flag before issuing a service call is 1 Task Service call issued Service call processing r p l Iflag 1 0 I I 1 1 l 0 system IPL oe 0 IPL 0 PEA system IPL When the I flag before issuing a service call is 0 Task Service call issued Service call processing I IPL 0 s lt system IPL 0 lt system IPL j lt 0 Figure 3 23 Interrupt control in a Service Call that can be Issued from only a Task 32 e For service calls that can be issued from only non task context or from both task context and non task context When the I
154. eter ServiceCall INTNo E ES R6RA RO slp tsk 249 22 ercd wup tsk 249 26 tskid ercd iwup tsk 250 28 tskid ercd can_wup 250 30 tskid wupcnt ican_wup 250 30 tskid wupcnt tslp_tsk 249 24 tmout ercd sus_tsk 249 36 tskid ercd isus_tsk 250 38 tskid ercd rsm_tsk 249 40 tskid ercd irsm_tsk 250 42 tskid ercd frsm_tsk 249 40 tskid ercd ifrsm_tsk 250 42 tskid ercd dly_tsk 249 44 tmout ercd rel wai 249 32 tskid ercd irel wai 250 34 tskid ercd Synchronization amp Communication Function Parameter ReturnParameter Pa 0 oe RO R3R1 R2 ROR4 Al RO R3R1 wai_sem 249 50 semid ercd pol_sem 250 52 semid ercd ipol_sem 250 52 semid ercd sig_sem 249 46 semid ercd isig_sem 250 48 semid ercd twai_sem 249 54 semid tmout ercd ref_sem 250 56 semid pk_rsem ercd iref_sem 250 56 semid pk_rsem ercd wai_flg 249 64 wfmode waiptn flgid ercd flgptn twai_flg 249 92 wfmode waiptn flgid tmout ercd fgptn pol_flg 250 66 wfmode waiptn flgid ercd flgptn ipol_flg 250 66 wfmode waiptn flgid ercd flgptn set_flg 249 58 setptn flgid ercd iset_flg 250 60 setptn flgid ercd ref_flg 250 70 flgid pk_rflg ercd iref_flg 250 70 flgid pk_rflg ercd clr_flg 250 62 clrptn flgid ercd iclr flg 250 62 clrptn flgid ercd snd dtq 249 72 data dtqid ercd psnd_dtq 249 74 data dtqid ercd ipsnd_dtq 250 76 data dtqid ercd fsnd_dtq 249 80 data dtqid ercd ifsnd_dtq 250 82 data dtqid erc
155. function name Frequency The frequency is indicated by a character string that consist of numerals and period and ends with MHz The numerical values are significant up to six decimal places Also note that the frequency can be entered using de cimal numbers only Frequency entry examples are presented below e 16MHz e 8 1234MHz It is also well to remember that the frequency must not begin with period Time The time is indicated by a character string that consists of numerals and period and ends with ms The time values are effective up to three decimal places when the character string is terminated with ms Also note that the 228 time can be entered using decimal numbers only e 10ms e 10 5ms It is also well to remember that the time must not begin with period 8 1 2 Configuration File Definition Items The following definitions are to be formulated in the configuration file e System definition System clock definition Respective maximum number of items Task definition Eventflag definition Semaphore definition Mailbox definition e Data queue definition Short data queue definition Fixed size Memory Pool definition Variable size Memory Pool definition e Cyclic handler definition e Alarm handler definition Interrupt vector definition System Definition Procedure lt lt Format gt gt System Definition
156. g Function Service Call eese 108 Table 5 9 Specifications of the Data Queue Function esee eene 118 Table 5 10 List of Dataqueue Function Service Call esee een 118 Table 5 11 Specifications of the Mailbox Function essere 127 Table 5 12 List of Mailbox Function Service Call esses eene 127 Table 5 13 Specifications of the Fixed size memory pool Functi0N cccoconnoononnnonononanannnnnnnnnnnos 135 Table 5 14 List of Fixed size memory pool Function Service Call sees 135 Table 5 15 Specifications of the Variable size memory Pool Functi0N ooocconocccccononcnncnnnnnnncnnns 143 Table 5 16 List of Variable size memory pool Function Service Call sess 143 Table 5 17 Specifications of the Time Management Function ccconoocccnononnnonononnncnononononanannnnnnnns 150 Table 5 18 List of Time Management Function Service Call sees 150 Table 5 19 Specifications of the Cyclic Handler Function essen 156 Table 5 20 List of Cyclic Handler Function Service Call sese 156 Table 5 21 Specifications of the Alarm Handler Function eese 162 Table 5 22 List of Alarm Handler Function Service Call esee 162 Table 5 23 List of System Status Management Function Service C
157. g service call becoming satisfied the task is released from WAITING state and placed into READY or RUNNING state Task awaking conditions are evaluated sequentially beginning with the top of the waiting queue If TA_WMUL is specified as an eventflag attribute multiple tasks kept waiting for the eventflag can be released from WAITING state at the same time by one set_flg or iset_flg service call issued Furthermore if TA_CLR is specified for the attribute of the target event flag all bit patterns of the eventflag are cleared with which processing of the service call is terminated If all bits specified in setptn are 0 no operation will be performed for the target eventflag in which case no errors are as sumed however If this service call is to be issued from task context use set_flg if issued from non task context use iset_flg 109 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task void set flg ID flg FLGPTN Oxff000000 lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 PUSH L Al set_flg ID_FLG3 0 000000H 110 cir fig Clear eventflag iclr fig Clear eventflag handler only C Language API ER ercd clr flg ID flgid FLGPTN clrptn ER ercd iclr flg ID flgid FLGPTN clrptn Parameters ID flgid ID number
158. h tasks wait for acquisition of the fixed size memory pool If TA TFIFO is selected tasks are enqueued in order of FIFO If TA_TPRI is selected tasks are enqueued in order of priority beginning with the one that has the highest priority Variable size memory pool definition This definition is necessary to use Variable size memory pool function lt lt Format gt gt Message buffer Definition message buffer ID No name ID Name mbf_section Section name mbf size i buffer size max msgsz Maximum message size wait queue Message buffer transmit wait queue selection The ID number must be in the range from 1 to 255 The ID number can be omitted If omitted ID numbers are automati cally assigned in order of magnitude beginning with the smallest lt lt Content gt gt 6 ID name Definition format Symbol Definition range None Default value None Define the name by which the memory pool is specified in a program 7 The maximum memory block size to be allocated Definition format Numeric value Definition range 1 to 65520 Default value None Specify within an application program the maximum memory block size to be allocated 242 8 Section name Definition format Symbol Definition range None Default value MR HEAP Define the name of the section in which the memory pool is located
159. he MR100 User s Manual consists of nine chapters and thee appendix e 2 General Information Outlines the objective of MR100 development and the function and position of the MR100 e 3 Introduction to Kernel Explains about the ideas involved in MR100 operations and defines some relevant terms e 4Kernel Outlines the applications program development procedure for the MR100 e 5 Service call reffernce Details MR100 service call API e 6 Applications Development Procedure Overview Details the applications program development procedure for the MR100 7 Detailed Applications Presents useful information and precautions concerning applications program development with MR100 e 8 Using Configurator Describes the method for writing a configuration file and the method for using the configurator in detail e 9 Sample Program Description Describes the MR100 sample applications program which is included in the product in the form of a source file e 10 Stack Size Calculation Method Describes the calculation method of the task stack size and the system stack size e 11 Note Presents useful information and precautions concerning applications program development with MR100 e 12 Appendix Data type and assembly language interface 2 General Information 2 1 Objective of MR100 Development In line with recent rapid technological advances in microcomputers the functions of microcomputer based products have become complicated In addition
160. he configurator s startup format is erroneous cfg100 Error Can t write open lt XXXX gt The XXXX file cannot be created Check the directory attribute and the remaining disk capacity available cfg100 Error Can t open lt XXXX gt The XXXX file cannot be accessed Check the attributes of the XXXX file and whether it actually exists cfg100 Error Can t open version file The MRI100 version file version cannot be found in the directory indicated by the environment variable LIB30 cfg100 Error Can t open default configuration file The default configuration file cannot be accessed default cfg is needed in the current directory or directory LIB 100 specifying cfg100 Error Can t open configuration file lt xxxx cfg gt The configuration file cannot be accessed Check that the file name has been properly designated cfg100 Error illegal XXXX gt xx near line xxx xxxx cfg The value or ID number in definition item XXXX is incorrect Check the valid range of definition cfg100 Error Unknown XXXX xx near line xx xxxx cfg The symbol definition in definition item XXXX is incorrect Check the valid range of definition cfg100 Error XXXX s ID number is too large gt xxx xxxx cfg A value is set to the ID number in XXXX definition that exceeds the total number of objects defined The ID number must be smaller than the total number of objects cfg100 Error Task x s priority is too large xxx
161. hnical in accuracies or typographical errors Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage liability or other loss rising from these inaccuracies or errors Please also pay attention to information published by Renesas Technology Corporation and Renesas Solutions Corporation by various means including the Renesas home page http www renesas com e When using any or all of the information contained in these materials including product data diagrams charts programs and algo rithms please be sure to evaluate all information as a total system before making a final decision on the applicability of the informa tion and products Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage liability or other loss resulting from the information contained herein O Renesas Technology semiconductors are not designed or manufactured for use in a device or system that is used under circum stances in which human life is potentially at stake Please contact Renesas Technology Corporation Renesas Solutions Corporation or an authorized Renesas Technology product distributor when considering the use of a product contained herein for any specific pur poses such as apparatus or systems for transportation vehicular medical aerospace nuclear or undersea repeater use e The prior written approval of Renesas Technology Corporation and Renesas Solutions Cor
162. i service call issued from another task or a handler The error code returned in this case is E RLWAI The following shows how wfmode is specified and the meaning of each mode wfmdoe wait mode Meaning TWF ANDW Wait until all bits specified by waiptn are set wait for the bits AND ed TWF ORW Wait until one of the bits specified by waiptn is set wait for the bits OR ed If this service call is to be issued from task context use wai flg twai flg pol flg if issued from non task context use ipol flg 114 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task UINT flgptn if wai flg ID flg2 FLGPTN 0x00000ff0 TWF ANDW amp flgptn E OK error Wait Released n if pol flg ID flg2 FLGPTN 0x00000ff0 TWF ORW amp flgptn E OK printf Not set EventFlag n if twai flg ID flg2 FLGPTN 0x00000ff0 TWF ANDW amp flgptn 5 E OK error Wait ReleasedWn lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 PUSH L Al wai flg ID_FLG1 00000003H TWF_ANDW PUSH W R2 PUSH L Al pol flg ID_FLG2 00000008H TWF_ORW PUSH W R2 PUSH L Al PUSHM R6R4 wai_flg ID_FLG3 00000003H TWF_ANDW 20 115 ref fig Reference eventflag status iref flg Reference eventflag status handle
163. id task T RSEM rsem ER ercd ercd ref sem ID seml amp rsem lt lt Example statement in assembly language gt gt _ refsem blkb 6 include mr100 inc GLB task task PUSH W R2 PUSH L A1 ref sem ID_SEM1 refsem 107 5 4 Synchronization amp Communication Function Eventflag Specifications of the eventflag function of MR100 are listed in Table 5 7 Table 5 7 Specifications of the Eventflag Function No Item Content 1 EventOflag ID 1 255 2 Number of bits comprising eventflag 32 bits 3 Eventflag attribute TA_TFIFO Waiting tasks enqueued in order of FIFO TA_TPRI Waiting tasks enqueued in order of priority TA WSGL Multiple tasks cannot be kept waiting TA WMUL Multiple tasks can be kept waiting TA CLR Bit pattern cleared when waiting task is released Table 5 8 List of Eventflag Function Service Call No Service Call Function System State T N E D U 1 set_flg S B Sets eventflag O O O O 2 iset_flg SIB O O O O 3 clr flg S B Clears eventflag O O O O 4 iclr flg O O O O 5 wai_flg SI B Waits for eventflag O O O 6 pol_flg S B Waits for eventflag polling O O O O 7 ipol flg S O O O O 8 twai_flg S Waits for eventflag with timeout O O O 9 ref flg References eventflag status O O O O 10 iref flg O O O O Notes e S Standard profile service calls B Basic p
164. in the following cases When the rel mpf or irel mpf service call is issued before the tmout time elapses with task awaking conditions thereby satisfied The error code returned in this case is E OK When the first time tick occurred after tmout elapsed while task awaking conditions remain un satisfied The error code returned in this case is E TMOUT When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI When the target memory pool being waited for is initialized by the vrst mpf service call issued from another task The error code returned in this case is EV RST If this service call is to be issued from task context use get mpf pget mpf tget mpf if issued from non task context use ipget mpf 137 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h VP p blk void task if get mpf ID mpf amp p blk E OK error Not enough memory n F pget mpf ID mpf amp p blk E OK error Not enough memory n fier if tget mpf ID mpf amp p blk 10 E OK error Not enough memory n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 get mpf ID_MPF1 PUSH W R2 pget_mpf ID_ MPF1 PUSH
165. ing so that it looks as if a number of microcomputers exist See Figure 3 6 Actual Register Key input Remote control Task Task o o ier Register Register Figure 3 6 Task Switching The example presented in Figure 3 7 indicates how the individual task registers are managed In reality it is necessary to provide not only a register but also a stack area for each task 5 Itis figure where all the stack areas of the task were arranged in the same section 11 Memory map Register m 7 Remote control Task Key input Task Stack RO LED illumination Ld Task PC Y a Real time OS SFR Figure 3 7 Task Register Area 12 Figure 3 8 shows the register and stack area of one task in detail In the MR100 the register of each task is stored in a stack area as shown in Figure 3 8 This figure shows the state prevailing after register storage Key input task Key input Task Register stored SFR Figure 3 8 Actual Register and Stack Area Management 13 3 2 Service Call How does the programmer use the kernel functions in a program First it is necessary to call up kernel function from the program in some way or other Calling a kernel function is referred to as a service call Task activation and other processing operations can be initiated by such a service call See Figure 3 9 Key input Kernel Remote
166. inition cyclic hand ID No 1 Js name ID name interval counter Activation cycle start TA STA attribute 7 phsatr TA PHS attribute phs_counter Activation phase entry_address Start address exitf Extended information The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each cyclic handler ID number 1 2 3 4 ID name Definition format Symbol Definition range None Default value None Define the name by which the memory pool is specified in a program Activation cycle Definition format Numeric value Definition range 1 to Ox7FFFFFFF Default value None Define the activation cycle at which time the cyclic handler is activated periodically The activation cycle here must be defined in the same unit of time as the system clock s unit time that is defined in system clock definition item If you want the cyclic handler to be activated at 1 second intervals for example the activation cycle here must be set to 1000 TA STA attribute Definition format Symbol Definition range ON or OFF Default value OFF Specify the TA STA attribute of the cyclic handler If ON is selected the TA STA attribute is added if OFF is selec
167. ions generated by C compiler NC100 Modify the section allocation and start address settings in this file to suit your system The following shows how to modify the section file e g If you want to change the rom FAR section start address from FFE00000H to FFF00000H section rom FAR romdata org OFFE00000H rom FAR top l section rom FAR romdata org OFFF00000H rom FAR top 224 7 4 1 Section used by the MR100 The sample section file for the C language is asm sec inc The sample section file for the assembly language is asm sec inc Edit these files if section reallocation is required The following explains each section that is used by the MR100 MR RAM section This section is where the RAM data MR100 s system management data is stored that is referenced in absolute addressing stack section This section is provided for each task s user stack and system stack e MR HEAP section This section stores the variable size memorypool e MR KERNEL section This section is where the MR100 kernel program is stored MR CIF section This section stores the MR100 C language interface library MR ROM section This section stores data such as task start addresses that area referenced by the MR100 kernel e program section This section stores user programs This section is not used by the MR100 kernel at all Therefore you can use this section as desired e NTERRUPT VECTOR section e FIX INTERRUPT VECT
168. ironment cccccccecessessececeeeececeesesssaecececeeeesssececesecseeesseeeseeseeseseneas 255 8 2 3 Configurator Start Procedure eese entere enne there stet ente tenen a sterne tins 256 8 2 44 Precautions on Executing Configurator cccccccccccccscsesessscecececesceesesssseeeeccscsesesssaseesecesesesentaaeess 256 8 2 5 Configurator Error Indications and Remedies essen eren enne 257 Error m ssapeS teo codes paite RS iae ae I a aaa aia 257 Warning Messe catesscdccuccsesecucetdeceucabenedecetddccddetesedeeed Ecce FERRE cet Ee EEEE EE E rE ee eae Pe aed ea 259 9 Sample Program Description iude dietis Fiera A dee kh ghi Era debo Tee gg eaa AE AREE Hee e DPA Fe Ye Cod ig 260 9 1 Overview of Sample Program ccccccccccescessssscccesecsesessnsececececsesessnseescececesesensseaeeesecsessseaseassececsenes 260 9 2 Program Source Lis iii cette ete tha testes ete era e a e i eroe caldera idad 261 9 3 Configuration Wile ce asc A E An A aie tn eT 262 10 Stack Size Calculation Method 0 cccccssscccccccesssssnsccceecccesssssnsceecccceesssseeeeececceesssnnaeeeeseceesssaseeeees 264 10 1 Stack Size Calculation Method essen eene enne nete nr nest ener nett nnne seen eene n ense 264 10 1 1 User Stack Calculation Method an aa reaa AAE eet n enne en TEARI ETEA TEETE 266 10 1 2 System Stack Calculation Method ccccccccccccccccssssssceeecececeesenseceeeeececeseeessseeeeee
169. is service call is reexecuted If the task indicated by tskid is in an inactive DORMANT state error code E OBJ is returned as the service call s return value To use these service calls from task contexts be sure to use chg pri to use them from non task contexts be sure to use ichg pri Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task chg pri ID task2 2 Example statement in assembly language INCLUDE mr100 inc GLB task task PUSH W R2 PUSH W R3 chg pri HID TASK3 H1 76 get pri Reference task priority iget pri Reference task priority handler only C Language API ER ercd get pri ID tskid PRI p tskpri ER ercd iget pri ID tskid PRI p tskpri Parameters ID tskid ID number of the target task PRI p tskpri Pointer to the area to which task priority is returned Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr100 inc get pri TSKID iget pri TSKID Parameters TSKID ID number of the target task Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Acquired task priority Error code E_OBJ Object status invalid task indicated by tskid is an inactive state Functional description This service call returns
170. is specified as YYYY XXXX is specified as Y Y Y Y 259 9 Sample Program Description 9 1 Overview of Sample Program As an example application of MR100 the following shows a program that outputs a string to the standard output device from one task and another alternately Table 9 1 Functions in the Sample Program Function Type ID No Priority Description Name main Task 1 1 Starts task1 and task2 task1 Task 2 2 Outputs task1 running task2 Task 3 3 Outputs task2 running cyhlQ Handler 1 Wakes up task1 The content of processing is described below e The main task starts task1 task2 and cyh1 and then terminates itself e task1 operates in order of the following 1 Gets a semaphore 2 Goes to a wakeup wait state 3 Outputs taskl running 4 Frees the semaphore e task2 operates in order of the following 1 Gets a semaphore 2 Outputs task2 running 3 Frees the semaphore cyhl starts every 100 ms to wake up task1 260 9 2 Program Source Listing T S EE K KK RK RK ke KR RR RR RK RR RR ck ck Sk Sk Sk ke KR RK KR RR RR KK RRR eek ke RK RK e k k 27k MR100 smaple program 3 4 COPYRIGHT C 2003 2005 RENESAS TECHNOLOGY CORPORATION 5 AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED 6 7 8 Id demo c v 1 2 2005 06 15 05 29 02 inui Exp 9 HR K k k KR k k RK RRR KR KR RR k k kk Sk KR RR RRR k k kk k RR KK RR RR e e ke ke ke ke ke
171. issued from non task context use iref flg 116 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RFLG rflg ER ercd ercd ref flg ID FLG1 amp rflg lt lt Example statement in assembly language gt gt _ refflg blkb 6 include mr100 inc GLB task task PUSH W R2 PUSH L Al ref flg SID FLG1 4 refflg 117 5 5 Synchronization amp Communication Function Data Queue Specifications of the data queue function of MR100 are listed in Table 5 9 Table 5 9 Specifications of the Data Queue Function No Item Content 1 Data queue ID 1 255 2 Capacity data bytes in data queue area 0 8191 3 Data size 32 bits 4 Data queue attribute TA_TFIFO Waiting tasks enqueued in order of FIFO TA_TPRI Waiting tasks enqueued in order of priority Table 5 10 List of Dataqueue Function Service Call No Service Call Function System State T N E D U 1 snd dtq S Sends to data queue O O O 2 psnd dtq S Sends to data queue polling OJO O O 3 ipsnd dtq S O ojojo 4 tsnd_dtq S Sends to data queue with timeout 0 0 O 5 fsnd_dtq S Forced sends to data queue O 00 0 6 ifsnd dtq S O olojo 7 rcev_dtq S Receives from data queue OJO O 8 prev_dtq S Receives fro
172. it state to RUNNING or READY state This service call does not check the content of blk so that if the address stored in blk is incorrect the service call may not operate correctly If this service call is to be issued from task context use rel mpf if issued from non task context use irel_mpf 139 Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task VP p blf if get mpf ID mpfi amp p blf E OK error Not enough memory Nn Ei rel mpf ID mpf1 p b1f lt lt Example statement in assembly language gt gt include mr100 inc GLB task _g blk blkb 4 task PUSH W R2 get mpf ID_MPF1 MOV L R3R1 g blk PUSH W R2 rel mpf ID_MPF1 g blk 140 ref mpf Reference fixed size memory pool status iref mpf Reference fixed size memory pool status handler only C Language API ER ercd ref mpf ID mpfid T RMPF pk rmpf ER ercd iref mpf ID mpfid T RMPF pk rmpf Parameters ID mpfid Task ID waiting for memory block to be acquired T RMPF pk rmpf Pointer to the packet to which fixed size memory pool status is returned Return Parameters ER ercd Terminated normally E OK T RMPF pk rmpf Pointer to the packet to which fixed size memory pool status is returned Contents of pk rmpf typedef struct t rmpf ID wtskid 0 2 Task ID waiting for memory bl
173. ity 3 taskB taskC Move the end of the queue Figure 4 24 Ready Queue Management by rot rdq Service Call e Reference task ID in the RUNNING state get tid iget tid References the ID number of the task in the RUNNING state If issued from the handler TSK_NONE 0 is ob tained instead of the ID number e Lock the CPU loc cpu iloc cpu Places the system into a CPU locked state Unlock the CPU unl cpu iunl cpu Frees the system from a CPU locked state e Disable dispatching dis dsp Places the system into a dispatching disabled state Enable dispatching ena_dsp Frees the system from a dispatching disabled state e Reference context sns_ctx Gets the context status of the system Reference CPU state sns_loc Gets the CPU lock status of the system Reference dispatching state sns_dsp Gets the dispatching disable status of the system e Reference dispatching pending state sns_dpn Gets the dispatching pending status of the system 58 4 1 15 Interrupt Management Function The interrupt management function provides a function to process requested external interrupts in real time The interrupt management service calls provided by the MR100 kernel include the following e Returns from interrupt handler ret int The ret int service call activates the scheduler to switch over tasks as necessary when returning from the interrupt handler When using the C language this function is a
174. k Therefore when writing applications with the MR100 it is necessary to furnish the stack area for each task e System Stack This stack is used within the MR100 during service call processing When a service call is issued from a task the MR100 switches the stack from the user stack to the system stack See Figure 3 25 The system stack use the interrupt stack ISP Task MR100 service call processing User Stack Save Registers Stack switching Service call processing System Stack Stack switching Restore Registers User Stack Figure 3 25 System Stack and User Stack Switchover from user stack to system stack occurs when an interrupt of vector numbers 0 to 127 is generated Consequently all stacks used by the interrupt handler are the system stack 34 4 Kernel 4 1 1 Module Structure The MR100 kernel consists of the modules shown in Figure 4 1 Each of these modules is composed of functions that exer cise individual module features The MR100 kernel is supplied in the form of a library and only necessary features are linked at the time of system genera tion More specifically only the functions used are chosen from those which comprise these modules and linked by means of the Linkage Editor However the scheduler module part of the task management module and part of the time manage ment module are linked at all times because they are essential feature functions The applications program is a progra
175. kid is not DOMANT state 69 Functional description This service call starts the task indicated by tskid In other words it places the specified task from DORMANT state into READY state or RUNNING state This service call does not enqueue task activation requests Therefore if a task activa tion request is issued while the target task is not DORMANT state the error code E OBJ is returned to the service call is suing task This service call is effective only when the specified task is in DORMANT state The task start code stacd is 32 bits long This task start code is passed as parameter to the activated task If a task is restarted that was once terminated by ter tsk or ext tsk the task performs the following as it starts up 1 Initializes the current priority of the task 2 Clears the number of queued wakeup requests 3 Clears the number of nested forcible wait requests If this service call is to be issued from task context use sta_tsk if issued from non task context use ista_tsk Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task ER ercd VP INT stacd 0 ercd sta tsk ID task2 stacd void task2 VP INT msg if msg 0 i lt lt Example statement in assembly language gt gt INCLUDE mr100 inc GLB task task PUSHM R3R1 PUSH W R2 sta tsk ID_TASK4 100 70 ext t
176. l ized by the user side If you do not use a system clock define NOTIMER System clock interrupt priority level Definition format Numeric value Definition range 1 to Kernel mask level in system definition Default value 4 Define the priority level of the system clock timer interrupt The value set here must be smaller than the kernel interrupt mask level Interrupts whose priority levels are below the interrupt level defined here are not accepted during system clock interrupt handler processing 231 Definition respective maximum numbers of items Here define respective maximum numbers of items to be used in two or more applications lt lt Format gt gt Max Definition maxdef ine max task the maximum number of tasks defined max flag the maximum number of eventflags defined max_dtq the maximum number of data queues defined max mbx the maximum number of mailboxes defined max sem the maximum number of semaphores defined max mpf the maximum number of fixed size memory pools defined max mpl the maximum number of variable size memory pools defined max cyh the maximum number of cyclic handlers defined max_alh the maximum number of alarm handlers defined the maximum number of short data queues defined max vdtq lt lt Contents gt gt 1 The maxim
177. l with E OK If task awaking conditions are not met and the invoked service call is wai flg or twai_flg the task is enqueued in an eventflag waiting queue In that case if the attribute of the specified eventflag is TA TFIFO the task is enqueued in order of FIFO if TA TPRI the task is enqueued in order of priority For the pol flg and ipol flg service calls the task returns immediately and responds to the call with the error code E TMOUT For the twai_flg service call specify a wait time for tmout in ms units The values specified for tmout must be with in OX7FFFFFFF time tick value If any value exceeding this limit is specified the service call may not operate correctly If TMO POL O is specified for tmout it means specifying O as a timeout value in which case the service call operates the same way as pol flg Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as wai flg The task placed into a wait state by execution of the wai flg or twai flg service call is released from WAITING state in the following cases When task awaking conditions are met before the tmout time elapses The error code returned in this case is E_OK When the first time tick occurred after tmout elapsed while task awaking conditions remain unsatisfied The error code returned in this case is E_TMOUT When the task is forcibly released from WAITING state by the rel_wai or irel_wa
178. lm O e Q Q Notes e S Standard profile service calls B Basic profile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 162 sta alm Start alarm handler operation ista alm Start alarm handler operation handler only C Language API ER ercd sta alm ID almid RELTIM almtim ER ercd ista alm ID almid RELTIM almtim Parameters ID almid ID number of the alarm handler to be operated RELTIM almum Alarm handler startup time relative time Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc sta alm ALMID ALMTIM ista alm ALMID ALMTIM Parameters ALMID ID number of the alarm handler to be operated ALMTIM Alarm handler startup time relative time Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the alarm handler to be operated R6R4 Alarm handler startup time relative time Error code None Functional description 1 This service call sets the activation time of the alarm handler indicated by almid as a relative time of day after the l
179. low Always be sure to clear the B flag before issuing ret int service call Example interrupt fset B fclr B ret int Internally in the MR100 kernel register banks are not switched over 2 Regarding the method for specifying a high speed interrupt To ensure the effective use of a high speed interrupt be sure that the registers in register bank 1 are used in the high speed interrupt Also be aware that the high speed interrupts used cannot be a kernel interrupt handler 249 8 1 3 Configuration File Example The following is the configuration file example MM EE Ld 2 3 kernel cfg building file for MR100 Ver 1 00 4 5 Generated by M3T MR100 GUI Configurator at 2007 02 28 19 01 20 6 7 HM MM AAA AAA AAA AAA AAA AAA AAA AAA AAA AAA AAA AAT TTT MM P PP MM Ig MMIMIM 8 9 system definition 10 system 11 stack size 256 12 sysTm_IPL 4 13 message pri 64 14 timeout NO 15 task_pause NO 16 tick nume 10 17 tick deno sb 18 y 19 20 max definition 21 maxdefine 22 max_task 3 23 max flag 24 24 max sem 3 25 max dtq 3 26 max mbx 4 27 max mpf 3 28 max mpl 3 29 max cyh 4 30 max alh 2 31 32 33 system clock definition 34 clock 35 timer_clock 20 000000MHz 36 timer AO 37 IPL 3 38 39 40 task 41 entry address task1 42 name ID_task1 43 stack size 256 44 priority She 45 initial start OF
180. lt Example statement in assembly language gt gt task INCLUDE mri00 inc GLB task ext tsk 72 ter tsk Terminate task C Language API ER ercd ter tsk ID tskid Parameters ID tskid ID number of the forcibly terminated task Return Parameters ER ercd Terminated normally E OK or error code Assembly language APT include mr100 inc ter tsk TSKID Parameters TSKID ID number of the forcibly terminated task Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target task Error code E OBJ Object status invalid task indicated by tskid is an inactive state E ILUSE Service call improperly used task indicated by tskid is the issuing task itself Functional description This service call terminates the task indicated by tskid If the activation request count of the target task is equal to or greater than 1 the activation request count is decremented by 1 and processing similar to that of act tsk or iact_tsk is performed In that case the task is placed from DORMANT state into READY state The task has its extended information passed to it as parameter when the task starts up If a task specifies its own task ID or TSK SELF an E ILUSE error is returned If the specified task was placed into WAITING state and has been enqueued in some waiting queue the task is dequeued from it by execution of
181. ltiplex interrupt Handler 19 3 3 Object The object operated by the service call of a semaphore a task etc is called an object An object is identified by the ID number 3 3 1 The specification method of the object in a service call Each task is identified by the ID number internally in MR100 For example the system says Start the task having the task ID number 1 However if a task number is directly written in a program the resultant program would be very low in readability If for instance the following is entered in a program the programmer is constantly required to know what the No 2 task is act tsk 2 Further if this program is viewed by another person he she does not understand at a glance what the No 2 task is To avoid such inconvenience the MR100 provides means of specifying the task by name function or symbol name The program named configurator cfg100 which is supplied with the MR100 then automatically converts the task name to the task ID number This task identification system is schematized in Figure 3 14 sta tsk Task name Starting the task having the designated Name ID number ID number Configurator Program Real time OS Figure 3 14 Task Identification act tsk ID task This example specifies that a task corresponding to ID task be invoked It should also be noted that task name to ID number conversion is effected at the time of program generation Therefore the processi
182. ly E OK Assembly language APT include mr100 inc vrst mbx MBXID Parameters MBXID Mailbox ID to be cleared Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Mailbox ID to be cleared Error code None Functional description This service call clears the messages stored in the mailbox indicated by mbxid This service call can be issued only from task context It cannot be issued from non task context 201 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task1 void vrst mbx ID mbx1 lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 vrst mbx HID MBX1 202 vrst mpf Clear fixed size memory pool area C Language APT ER ercd vrst_mpf ID mpfid Parameters ID mpfid Fixed size memory pool ID to be cleared Return Parameters ER ercd Terminated normally E OK Assembly language APT include mr100 inc vrst_mpf MPFID O Parameters MPFID Fixed size memory pool ID to be cleared O Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Fixed size memory pool ID to be cleared Error code None Functional description This service call initializes the fixe
183. m WAITING state and the error code EV RST is returned e Clear Mailbox Area vrst mbx Initializes the mailbox Clear Fixed size Memory Pool Area vrst mpf Initializes the fixed size memory pool If there are any tasks in WAITING state they are freed from the WAIT ING state and the error code EV RST is returned e Clear Variable size Memory Pool Area vrst mpl Initializes the variable length memory pool Clear Short Data Queue Area vrst vdtq Initializes the short data queue If there are any tasks waiting for transmission they are freed from WAITING state and the error code EV RST is returned 61 5 Service call reffernce 5 1 Task Management Function Specifications of the task management function of MR100 are listed in Table 5 1 below The task description languages in item No 4 are those specified in the GUI configurator They are not output to a configuration file nor are the MR100 ker nel concerned with them The task stack permits a section name to be specified for each task individually Table 5 1 Specifications of the Task Management Function No Item Content 1 Task ID 1 255 Task priority 1 255 3 Maximum number of activation request count 255 4 Task attribute TA_HLNG Tasks written in high level language TA ASM Tasks written in assem bly language TA ACT Startup attribute 5 Task stack Section specifiable Table 5 2 List of Task Manageme
184. m created by the user It consists of tasks interrupt handler alarm handler and cyclic handler User Module Application Program fA Task Time Mara gement IO Task dependent Memorypool System stae MR100 kernel synchronization Eventfla g Management Manage ment Syste m configuration Data queue short Interrupt Management Data queue Management Alarm Cyclic handler Scheduler Hardware R32C 100 Microcomputer Figure 4 1 MR100 Structure 18 For details See 4 1 11 35 4 1 2 Module Overview The MR100 kernel modules are outlined below e Scheduler Forms a task processing queue based on task priority and controls operation so that the high priority task at the beginning in that queue task with small priority value is executed Task Management Module Exercises the management of various task states such as the RUNNING READY WAITING and SUSPENDED state Task Synchronization Module Accomplishes inter task synchronization by changing the task status from a different task e Interrupt Management Module Makes a return from the interrupt handler e Time Management Module Sets up the system timer used by the MR100 kernel and starts the user created alarm handler and cyclic han dler e System Status Management Module Gets the system status of MR100 e System Configuration Management Module Reports the MR100 kernel version number or other information e Synchronization and Communication Module This is
185. m data queue polling O 00 0 9 iprcv_dtq O O JO O 10 trev_dtq S Receives from data queue with timeout O O O 11 ref_dtq References data queue status O 0 00 12 iref dtq OJO O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state U Can be called from CPU unlocked state D Can be called from dispatch disabled state L Can be called from CPU locked state 118 snd dtq Send to data queue psnd dtq Send to data queue polling ipsnd dtq Send to data queue polling handler only tsnd dtq Send to data queue with timeout fsnd dtq Forced send to data queue ifsnd dtq Forced send to data queue handler only C Language API ER ercd snd dtq ID dtqid VP INT data ER ercd psnd dtq ID dtqid VP INT data ER ercd ipsnd dtq ID dtqid VP INT data ER ercd tsnd dtq ID dtqid VP INT data TMO tmout ER ercd fsnd dtq ID dtqid VP INT data ER ercd ifsnd dtq ID dtqgqid VP INT data Parameters ID dtqid ID number of the data queue to which transmitted TMO tmout Timeout value tsnd dtq VP INT data Data to be transmitted Return Parameters ER ercd Terminated normally E OK or error code Assembly language API include mr100 inc s
186. m directory 2 For the symbol indicating the interrupt handler start address make the external declara tion Global declaration 3 Make sure that the registers used in a handler are saved at the entry and are restored after use 4 Return to the task by ret int service call INCLUDE mr100 inc 1 GLB inth s a e 2 inth Registers used are saved to a stack 3 iwup tsk ID_task1 process Registers used are restored 3 ret int 4 4 Figure 7 8 Example of kernel OS depend interrupt handler 7 2 3 Writing Non kernel Interrupt Handler 1 For the symbol indicating the interrupt handler start address make the external declaration public declaration 2 Make sure that the registers used in a handler are saved at the entry and are restored after use Be sure to end the handler by REIT instruction No service calls can be issued from a non kernel interrupt handler NOTE If this restriction is not observed the software may malfunction 5 If you want multiple interrupts to be enabled in a non kernel interrupt handler always make sure that the non kernel interrupt handler is assigned a priority level higher than other non kernel interrupt handlers GLB inthand 1 inthand Registers used are saved to a stack 2 interrupt process Registers used are restored 25 REIT aan 3 Figure 7 9 Example of Non kernel Interrupt Han
187. m number of cyclic handler defined 9 The maximum number of alarm handler defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of alarm handlers defined 10 The maximum number of short data queues defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of short data queues defined 233 Task definition lt lt Format gt gt Tasks Definition task ID No f name ID name entry address Start task of address stack size User stack size of task priority Initial priority of task context Registers used stack section Section name in which the stack is located initial start TA ACT attribute initial startup state exinf Extended information The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each task ID number 1 2 Task ID name Definition format Symbol Definition range None Default value None Define the ID name of a task Note that the function name defined here is output to the kernel id h file as shown below define Task ID Name task ID Start address of task
188. maphore Specifications of the semaphore function of MR100 are listed in Table 5 5 Table 5 5 Specifications of the Semaphore Function No Item Content 1 Semaphore ID 1 255 2 Maximum number of resources 1 65535 TA_FIFO Tasks enqueued in order of FIFO 3 Semaphore attribute E TA TPRI Tasks enqueued in order of priority Table 5 6 List of Semaphore Function Service Call No Service Call Function System State T N E Dj U 1 sig sem S B Releases semaphore resource O O O O 2 isig sem S B O 0 O O 3 wai sem S B Acquires semaphore resource O O O 4 pol_sem S B Acquires semaphore resource polling O OJO O 5 ipol sem 01 0 00 6 twai sem S Acquires semaphore resource with timeout O O O 7 ref_sem References semaphore status O O O 0O 8 iref sem O 0 O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 100 sig sem Release semaphore resource isig sem Release semaphore resource handler only C Language API ER ercd sig sem ID semid ER ercd isig sem
189. microcomputer used Configurator can t create an Initialize routine interrupt control register interrupt causes etc for this defined interrupt You need to create that lt lt Content gt gt 4 Kernel OS dependent interrupt handler Definition format Symbol Definition range YES or NO Define whether the handler is a kernel OS dependent interrupt handler If it is a kernel OS dependent interrupt handler specify YES if it is a non kernel OS independent interrupt handler specify No If this item is defined as YES the declaration statement shown below is output to the kernel id h file pragma INTHANDLER V4 function name If this item is defined as NO the declaration statement shown below is output to the kernel_id h file pragma INTERRUPT V4 function name 5 Start address Definition format Symbol or function name Definition range None Default value SYS DMY INH Define the entry address of the interrupt handler When written in the C language add at the end or at the be ginning of the function name you have defined 246 6 Switch passed to PRAGMA extended function Definition format Symbol Definition range E F BorR Default value None Specify the switch to be passed to pragma INTHANDLER or pragma INTERRUPT If E is specified a E switch is selected in which case multiple interrupts are enabled If F is specified a F switch is selected in which
190. msgheader char body 12 PRI MSG void task void PRI MSG msg msg msgpri E snd mbx ID msg T MSG amp msg lt lt Example statement in assembly language gt gt include mr100 inc GLB task g userMsg blkb 6 Header blkb 12 Body task PUSH W R2 PUSH L A1 snd mbx ID_MBX1 g userMsg 129 rcv mbx Receive from mailbox prcv mbx Receive from mailbox polling iprcv mbx Receive from mailbox polling handler only ircev mbx Receive from mailbox with timeout C Language API ER ercd rcv mbx ID mbxid T MSG ppk msg ER ercd prcv mbx ID mbxid T MSG ppk msg ER ercd iprcv mbx ID mbxid T MSG ppk msg ER ercd trcv mbx ID mbxid T MSG ppk msg TMO tmout Parameters ID mbxid ID number of the mailbox from which to receive TMO tmout Timeout value for trev_mbx T MSG ppk msg Pointer to the start of the area in which received message is stored Return Parameters ER ercd Terminated normally E OK or error code T MSG ppk msg Pointer to the start of the area in which received message is stored Assembly language APT include mr100 inc rcv mbx MBXID prcv mbx MBXID iprcv mbx MBXID trcv mbx MBXID TMO Parameters MBXID ID number of the mailbox from which to receive TMO Timeout value for trcv mbx Register contents after service call is issued rcv mbx prcv mbx iprcv mbx Register name Content after service call is issued RO Error code
191. n Engineering Department 1 PUE Renesas Solutions Corp O 2007 Renesas Technology Corp and Renesas Solutions Corp M3T MR100 4 User s Manual S 24 N SAS RenesasTechnology Corp 2 6 2 Ote machi Chiyoda ku Tokyo 100 0004 Japan
192. n the task is released from WAITING state by a task wakeup service call it still remains in SUSPENDED state and its execution cannot be resumed until rsm tsk is issued The service call tslp_tsk may be used to place the issuing task into sleeping state for a given length of time by specifying tmout in a parameter to it The parameter tmout is expressed in ms units For example if this service call is written as tslp tsk 10 then the issuing task is placed from RUNNING state into WAITING state for a period of 10 ms If specified as tmout ZTMO FEVR 1 the task will be kept waiting perpetually with the service call operating the same way as slp tsk The values specified for tmout must be within 0x 7FFFFFFF time tick value If any value exceeding this limit is specified operation of the service call cannot be guaranteed This service call can only be issued from task context and cannot be issued from non task context 86 Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if slp tsk E OK error Forced wakeup n if tslp tsk 10 E TMOUT error time out n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task slp tsk PUSHM R6R4 tslp tsk TMO_FEVR PUSHM R6R4 tslp tsk 100 87 wup tsk Wakeup task iwup tsk Wakeup task
193. n with 0 Table 8 1 Numerical Value Entry Examples Oxf12 0Xf12 0a12h Hexadecimal 0a12H 12h 12H Decimal 32 017 Octal 170 170 Binary 101110b 101010B 5 The System distinguishes between the upper and lower case letters except for the numbers A F and a f 227 It is also possible to enter operators in numerical values Table 8 2 Operators lists the operators available Table 8 2 Operators Operator Priority Direction of computation High From left to right Unary minus From right to left 9o From left to right Binary minus Low From loft to right 13 Numerical value examples are presented below e 123 e 123 0x23 e 23 4 3 2 e 100B 08H Symbol The symbols are indicated by a character string that consists of numerals upper and lower case alphabetical let ters underscore and and begins with a non numeric character Example symbols are presented below e TASKI e IDLE3 Function Name The function names are indicated by a character string that consists of numerals upper and lower case alpha betical letters dollar and underscore begins with a non numeric character and ends with The following shows an example of a function name written in the C language e main e func When written in the assembly language the start label of a module is assumed to be a
194. nclude lt itron h gt include lt kernel h gt include kernel id h void task1i if rsm tsk ID main E OK printf Can t resume main Mn if frsm tsk ID task2 E OK printf Can t forced resume task2 n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 rsm tsk HID TASK2 PUSH W R2 frsm tsk HID TASK1 97 dly tsk Delay task C Language API ER ercd dly tsk RELTIM dlytim Parameters RELTIM dlytim Delay time Return Parameters ER ercd Terminated normally E OK or error code Assembly language APT include mr100 inc dly tsk RELTIM Parameters RELTIM Delay time Register contents after service call is issued Register name Content after service call is issued RO Error code R6R4 Delay time Error code E RLWAI Forced release from waiting Functional description 1 This service call temporarily stops execution of the issuing task itself for a duration of time specified by dlytim to place the task from RUNNING state into WAITING state In this case the task is released from the WAITING state at the first time tick after the time specified by dlytim has elapsed Therefore if specified dlytim 0 the task is placed into WAITING state briefly and then released from the WAITING state at the first time tick The task placed into WAITING state by invocation of this service call is relea
195. ncluded wait state Semaphore timeout included wait state Message timeout included wait state Data transmission timeout included wait state Data reception timeout included wait state Fixed size memory block timeout included acquisition wait state Short data transmission timeout included wait state Short data reception timeout included wait state 999999999 44 e Delay task dly tsk Keeps a task waiting for a finite length of time Figure 4 9 shows an example in which execution of a task is kept waiting for 10 ms by the dly tsk service call The timeout value should be specified in ms units and not in time tick units dly tsk 10 Figure 4 9 dly tsk service call 42 4 1 5 Synchronization and Communication Function Semaphore The semaphore is a function executed to coordinate the use of devices and other resources to be shared by several tasks in cases where the tasks simultaneously require the use of them When for instance four tasks simultaneously try to acquire a total of only three communication lines as shown in Figure 4 10 communication line to task connections can be made without incurring contention Communication Line Communication Line Communication Line Semaphore x Figure 4 10 Exclusive Control by Semaphore The semaphore has an internal semaphore counter In accordance with this counter the semaphore is acquired or released to prevent competition for use of
196. nd dtq DTOID DTODATA isnd dtq DTQID DTQDATA psnd dtq DTOID DTQDATA ipsnd dtq DTQID DTQDATA tsnd dtq DTQID DTODATA TMO fsnd dtq DTOID DTODATA ifsnd dtq DTOID DTQDATA Parameters DTQID ID number of the data queue to which transmitted DTQDATA Data to be transmitted TMO Timeout value tsnd_dtq Register contents after service call is issued snd dtq psnd dtq ipsnd dtq fsnd dtq ifsnd dtq Register name RO R3 R2 tsnd dtq Register name RO R3 R2 R6 RI RI R4 Error code Content after service call is issued Data to be transmitted ID number of the data queue to which transmitted Error code Content after service call is issued Data to be transmitted ID number of the data queue to which transmitted Timeout value 119 Error code E RLWAI Forced release from waiting E TMOUT Polling failure or timeout or timed out E ILUSE Service call improperly used fsnd_dtq or ifsnd dtq is issued for a data queue whose dtgcnt 0 EV RST Released from WAITING state by clearing of the data queue area Functional description This service call sends the 4 byte data indicated by data to the data queue indicated by dtqid If any task is kept waiting for reception in the target data queue the data is not stored in the data queue and instead sent to the task at the top of the recep tion waiting queue with which the task is released from the reception wait state On the other hand
197. need to be performed immediately should be given higher priorities The MR100 permits giving the same priority to several tasks To provide proper control over the READY task execution order the kernel generates a task execution queue called ready queue The ready queue structure is shown in Figure 3 17 The ready queue is provided and controlled for each priority level The first task in the ready queue having the highest priority is placed in the RUNNING state Priority Mr TCB gt TCB TCB TCB TCB Figure 3 17 Ready Queue Execution Queue 13 The TCB task control block is described in the next chapter The task in the RUNNING state remains in the ready queue 25 3 4 3 Task Priority and Waiting Queue In The standard profiles in uITRON 4 0 Specification support two waiting methods for each object In one method tasks are placed in a waiting queue in order of priority TA TPRI attribute in another tasks are placed in a waiting queue in order of FIFO TA TFIFO Figure 3 18 and Figure 3 19 depict the manner in which tasks are placed in a waiting queue in order of taskD taskC taskA and taskB ID No taskA FA taskB taskC ENS taskD Priority 1 Priority 5 Priority 6 Priority 9 HRE Figure 3 18 Waiting queue of the TA_TPRI attribute ID No taskD taskC taskA taskB Priority 9 Priority 6 Priorit
198. ng overflow Functional description This service call aborts execution of the task indicated by tskid and places it into SUSPENDED state Tasks are resumed from this SUSPENDED state by the rsm tsk irsm tsk frsm_tsk or ifrsm tsk service call If the task indicated by tskid is in DORMANT state it returns the error code E OBJ as a return value for the service call The maximum number of suspension requests by this service call that can be nested is 1 If this service call is issued to a task which is already in SUSPENDED state the error code E QOVR is returned This service call forbids specifying the issuing task itself for tskid If this service call is to be issued from task context use sus tsk if issued from non task context use isus_tsk 94 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task if sus tsk ID main E OK printf Can t suspend task main n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 sus tsk HID TASK2 95 rsm tsk Resume suspended task irsm tsk Resume suspended task handler only frsm tsk Forcibly resume suspended task ifrsm tsk Forcibly resume suspended task handler only C Language API 1 ER ercd rsm tsk ID tskid ER ercd irsm tsk ID tskid ER ercd frsm tsk ID tskid ER er
199. ng speed does not decrease due to this conversion feature 20 3 4 Task This section describes how tasks are managed by MR100 3 4 1 Task Status The real time OS monitors the task status to determine whether or not to execute the tasks Figure 3 15 shows the relationship between key input task execution control and task status When there is a key input the key input task must be executed That is the key input task is placed in the execution RUNNING state While the system waits for key input task execution is not needed In that situation the key input task in the WAITING state Key input Task Key input Waiting for Key input processing key input processing RUNNIG state WAITING state RUNNING state Figure 3 15 Task Status The MR100 controls the following six different states including the RUNNING and WAITING states 1 2 5 6 RUNNING state READY state WAITING state SUSPENDED state WAITING SUSPENDED state DORMANT state Every task is in one of the above six different states Figure 3 16 shows task status transition 21 MPU execlusive right acquisition READY state RUNNING state MPU execlusive right relinquishment WAITING state Entering the WAITING state WAITING state SUSPENDED state clear SUSPEND request Forced request from other task from other task vos e from other task WAITING SUSPENDED state WAITING state clear SUSP
200. nguage APT include mr100 inc sns loc Parameters None Register contents after service call is issued Register name Content after service call is issued RO TRUE CPU locked state FALSE CPUCPU unlocked state Error code None Functional description 1 This service call returns TRUE when the system is in a CPU locked state or returns FALSE when the system is in a CPU unlocked state This service call can also be invoked from a CPU locked state Example program statement lt lt Example statement in C language include lt itron h gt include lt kernel h gt include kernel id h void task BOOL stat stat sns loc lt lt Example statement in assembly language gt gt include mr100 inc GLB task task sns loc 179 sns dsp Reference dispatching state C Language API BOOL state sns dsp Parameters None Return Parameters BOOL state TRUE Dispatching disabled state FALSE Dispatching enabled state Assembly language APT include mr100 inc sns dsp Parameters None Register contents after service call is issued Register name Content after service call is issued RO TRUE Dispatching disabled state FALSE Dispatching enabled state Error code None Functional description This service call returns TRUE when the system is in a dispatching disabled state or returns FALSE when the system is in a dispatching enabled state
201. nguage Variable Treatment Table 7 1 C Language Variable Treatment Variable storage class Treatment Global Variable Variable shared by all tasks Non function static variable Variable shared by the tasks in the same file Auto Variable Register Variable Variable for specific task Static variable in function 7 1 2 Writing a Kernel OS Dependent Interrupt Handler When describing the kernel interrupt handler in C language observe the following precautions The configurator generates the file kernel_id h that is used to convert the ID number of a task into the string to be specified This means that the define declaration necessary to convert the string specified in the task definition item name into the ID number of the task is made in kernel_id h The same applies to the cyclic and alarm handlers The task starts from its start function with the initial priority in a wakeup counter cleared state 212 Describe the kernel interrupt handler as a function 2 Be sure to use the void type to declare the interrupt handler start function return value and argument 3 At the beginning of file be sure to include itron h kernel h which is in the system di rectory as well as kernel id h which is in the current directory Do not use the ret int service call in the interrupt handler The static declared functions can not be registered as an interrupt handler include lt itron h gt
202. ning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 187 vsnd dtq Send to Short data queue vpsnd dtq Send to Short data queue polling vipsnd dtq Send to Short data queue polling handler only vtsnd dtq Send to Short data queue with timeout vfsnd dtq Forced send to Short data queue vifsnd dtq Forced send to Short data queue handler only C Language API ER ercd vsnd dtq ID vdtqid H data ER ercd vpsnd dtq ID vdtqid H data ER ercd vipsnd dtq ID vdtqid H data ER ercd vtsnd dtq ID vdtqid H data TMO tmout ER ercd vfsnd dtq ID vdtqid H data ER ercd vifsnd dtq ID vdtqid H data Parameters ID vdtqid ID number of the Short data queue to which transmitted TMO tmout Timeout value tsnd_dtq H data Data to be transmitted Return Parameters ER ercd Terminated normally E_OK or error code Assembly language APT include mr100 inc vsnd dtq VDTOID DTQDATA visnd dtq VDTOID DTODATA vpsnd dtq VDTOID DTQDATA vipsnd dtq VDTOID DTQDATA vtsnd dtq VDTOID DTQDATA TMO vfsnd dtq VDTOID DTQDATA vifsnd dtq VDTOID DTQDATA Parameters VDTQID ID number of the Short data queue to which transmitted DTQDATA Data to be transmitted T
203. nl cpu Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task unl cpu lt lt Example statement in assembly language gt gt include mr100 inc GLB task task unl cpu 174 dis dsp Disable dispatching C Language API ER ercd dis dsp Parameters None Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc dis_dsp O Parameters None O Register contents after service call is issued Register name Content after service call is issued RO Error code Error code None Functional description This service call places the system into a dispatching disabled state The features of a dispatching disabled state are outlined below 1 Since task scheduling is not performed anymore no tasks other than the issuing task itself will be placed into RUNNING state 2 Interrupts are accepted 3 No service calls can be invoked that will place tasks into WAITING state If one of the following operations is performed during a dispatching disabled state the system status returns to a task exe cution state a Invocation of the ena_dsp service call b Invocation of the ext_tsk service call Transitions between dispatching disabled and dispatching enabled states occur only when the dis_dsp ena_dsp or ext_tsk service
204. nnnnonononnnonononononnanononononnononnnnononononnonannnnos 216 7 2 A Writing Cyclic Handler Alarm Handler cccccccccccccccesssssecesecececceesenseceeeeecsesenssseaeeeeeeseeseees 216 7 3 Modifying MR100 Startup Program eese nennen ene rennen enn eth n nnne seen nennen nnns sen 218 7 3 1 C Language Startup Program crtO0mr a30 eese nnns 219 TA Memory Allocation ia A AA BB 224 7 4 1 Section used by the MR10O ooooooococnnccccononoononanononocononanononononoonnnnanonononcnnononnn nono nnncnnonnnnnnnnanoncnnoos 225 8 Using ConBreu rator i AAA AAA A a 227 8 1 Configuration File Creation Procedure ccccccsccccccecesssssessececececeesenssaecececsesenesssseeesecsesentaeaeeeeeceneas 227 8 1 1 Configuration File Data Entry Format ccccccccccccccecessessceceeececeessnseceeeeeecsesenenssaeeeeeesesensaaeas 227 Operator mart te tr one teni ete cate dad RN REO on tet 228 Direction Of COMPUTATION a e nannte od e RIO Na citet Bt I 228 8 1 2 Configuration File Definition Items esee enne ne nnnee en en enter erst ener nennen 229 I System Definition Procedure oae sss tessa tsi ae e ted i uec RM Da E AC Te Le FL Dedi 229 System Clock Definition Proce dite ess een a qut o pu RUP uhi eraut eMe apes AC Romanian 231 Definition respective maximum numbers of items ccccccecsesssssseescssesesecseescsecseesesecsessesecsecsesscsessesstsceecsesseeaes 232 rd ales
205. nt Function Service Call No Service Call Function System State T N E D U L 1 act_tsk S Activates task O O O O 2 iact_tsk S O O O O 3 can_act S Cancels task activation request O O O O 4 ican_act O O O O 5 sta_tsk B Starts task and specifies start code O O O O 6 ista_tsk O O O O 7 ext_tsk SI B Exits current task O O O O O 8 ter_tsk SI B Forcibly terminates a task O O O O 9 chg pri S B Changes task priority O O O O 10 ichg_pri O O O O 11 get_pri S Refers to task priority O O O O 12 iget_pri O O O O 13 ref tsk Refers to task state O O O O 14 iref tsk O O O O 15 ref_tst Refers to task state simple ver O O O O 16 iref tst sion O O O O 63 Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 64 act tsk Activate task lact tsk Activate task handler only C Language API ER ercd act tsk ID tskid ER ercd iact tsk ID tskid Parameters ID tskid ID number of the task to be started Return parameters ER ercd Terminated normally E OK
206. o the packet to which cyclic handler status is returned Return Parameters ER ercd Terminated normally E OK T RCYC pk rcyc Pointer to the packet to which cyclic handler status is returned Contents of pk rcyc typedef struct t_reyc STAT cycstat 0 2 Operating status of cyclic handler RELTIM lefttim 2 4 Left time before cyclic handler starts up T RCYC Assembly language APT include mr100 inc ref_cyc ID PK_RCYC iref cyc ID PK RCYC Parameters CYCNO ID number of the target cyclic handler PK RCYC Pointer to the packet to which cyclic handler status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target cyclic handler Al Pointer to the packet to which cyclic handler status is returned Error code None Functional description This service call returns various statuses of the cyclic handler indicated by cycid cycstat The status of the target cyclic handler is returned TCYC STA Cyclic handler is an operational state TCYC STP Cyclic handler is a non operational state lefttim The remaining time before the target cyclic handler will start next is returned This time is expressed in ms units If the target cyclic handler is non operational state the returned value is indeterminate If this service call is to be issued from task context use ref cyc if issued from non task context use i
207. ock to be acquired UINT fblkent 2 4 Number of free memory blocks T RMPF Assembly language APT include mr100 inc ref_mpf MPFID PK RMPF iref mpf MPFID PK RMPF Parameters MPFID Task ID waiting for memory block to be acquired PK RMPF Pointer to the packet to which fixed size memory pool status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Task ID waiting for memory block to be acquired Al Pointer to the packet to which fixed size memory pool status is returned Error code None Functional description This service call returns various statuses of the message buffer indicated by mpfid wtskid Returned to wtskid is the ID number of the task at the top of a memory block waiting queue the first queued task If no tasks are kept waiting TSK NONE is returned fblkcnt The number of free memory blocks in the specified memory pool is returned If this service call is to be issued from task context use rel mpf if issued from non task context use irel_mpf 141 Example program statement 1 Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RMPF rmpf ER ercd ercd ref mpf ID MPF1 amp rmpf lt lt Example statement in assembly language gt gt include mr100 inc GLB task _ refmpf blkb 6 task
208. of data Definition format Numeric Value Definition range 0 to Ox3FFF Default value 0 Specify the number of data that can be transmitted What should be specified here is the number of data and not a data size 239 3 Selecting a data queue waiting queue Definition format Symbol Definition range TA TFIFO or TA TRPI Default value TA TFIFO Select a method in which tasks wait for short data queue transmission If TA TFIFO is selected tasks are en queued in order of FIFO If TA TPRI is selected tasks are enqueued in order of priority beginning with the one that has the highest priority Mailbox definition This definition must always be set when the mailbox function is to be used lt lt Format gt gt Mailbox Definition mailbox ID No name ID name wait_queue Select mailbox waiting queue message queue Select message queue max pri Maximum message priority The ID number must be in the range 1 to 255 The ID number can be omitted If omitted ID numbers are automatically assigned in order of numbers beginning with the smallest lt lt Content gt gt For each mailbox ID number define the items described below 1 ID name Definition format Symbol Definition range None Default value None Define the name by which the mailbox is specified in a program 2 Select mailbox waiting
209. of the eventflag to be cleared FLGPTN clrptn Bit pattern to be cleared Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc clr flg FLGID CLRPTN iclr flg FLGID CLRPTN Parameters FLGID ID number of the eventflag to be cleared CLRPTN Bit pattern to be cleared Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the eventflag to be cleared Al Bit pattern to be cleared Error code None Functional description Of the 32 bit eventflag indicated by flgid this service call clears the bits whose corresponding values in clrptn are 0 In other words the eventflag bit pattern indicated by flgid is updated by AND ing it with clrptn If all bits specified in clrptn are 1 no operation will be performed for the target eventflag in which case no errors are assumed however If this service call is to be issued from task context use clr_flg if issued from non task context use iclr flg When iclr flg is issued from interruption generated during set flg or iset flg service call execution the indivisibility of a service call is not guaranteed That is if there are two or more tasks which are waiting by the same bit pattern in the waiting queue some tasks are released and some tasks are not released by the timing of interruption generating 111 Example program statement 1 l
210. ol lowing relation Necessary size of the system stack 2Bi y 9o The maximum system stack size among the service calls to be used 9 When sta tsk ext tsk and dly tsk are used for example according to the Table 10 1 Stack Sizes Used by Ser vice Calls Issued from Tasks in bytes each of system stack size is the following Service Call name System Stack Size sta tsk 4 bytes ext tsk 4 bytes slp tsk 4 bytes dly tsk 8 bytes Therefore the maximum system stack size among the service calls to be used is the 8 bytes of dly tsk e pi The stack size to be used by the interrupt handler 57 The details will be described later ey Stack size used by the system clock interrupt handler This is detailed later 5 After switchover from user stack to system stack Refer from Table 10 1 Stack Sizes Used by Service Calls Issued from Tasks in bytes to Table 10 3 Stack Sizes Used by Service Calls Issued from Tasks and Handlers in bytes for the system stack size used for each individual service call Kernel interrupt handler not including the system clock interrupt handler here and non kernel interrupt handler 268 a The maximum system stack size among the service calls to be used gt Pv The system stack size to be used by the interrupt handler Interrupt Interrupt The necessary system stack Figure 10 4 System Stack Calculation Method 269 Stack size pi used by interrupt
211. olling cre erred rrt rtr rti iere ivo aei Ua ev rate p ebd iy 7122 iprcv dtq Receive from data queue polling handler only see 122 trcv dtq Receive from data queue with timeout ooncnionnnnnninonininnnncnncnancnncnna no nonn cana cinc rnn anna ener 122 ref dtq Reference data queue status eseessesssseserecsessssreccecssssoseecerecsssssseserecssssssesereesessssesseeeesess 125 iref_dtq Reference data queue status handler only seems 125 5 6 Synchronization amp Communication Function Mailbox esee 127 snd mbx Sendsto mailbox oe tc flet Pe eser er ee t eme et e aeree qure dese P ee Ree en 128 isnd mbx Send to mailbox handler only ocononinnnncnnnnnnnnnincncnnan coronan anna meer nre 128 rcv_mbx Receive from MallboxX ccocoooccnononoccnononnnonnnnnnnnnnnononnnnnnnonnnnnnnnonnnnnnnnnnnnnnnn nn E a er nenne rennes 180 prev_mbx Receive from mailbox polling seseeeeeeeeenee emeret nnn enes 130 iprcv mbx Receive from mailbox polling handler only 130 trev mbx Receive from mailbox with timeout essere enne 130 ref mbx Reference mailbox status ooooonnnooocccnononononononnnonnnnnnnnnnnnnnnnnnnnnonnnnnnnnnnnnnnnn nn sn en nenne enne nnne nnns 133 iref mbx Reference mailbox status handler only esee eren 133 5 7 Memory Pool Management Function Fixed size Memory Pool eee
212. on ooonooouoconcnccnnonnnonnnnonononnononnnnonononnonnononnnnnnnnnnrononnnnonononnnronanannns 165 istp_alm Stop alarm handler operation handler only sss 165 V ref alm Reference alarm handler status i cccccccccccssssseccececececececececececececececececscecsesessssssscsssssseseees 166 iref alm Reference alarm handler status handler only 166 5 12 System Status Management Function ccccccccccccesesssssececeeececeeesessesecececsesenssssseeesecsesessessaseeeees 168 rot rdq Rotate task precedence ccccccccccccccsesssscscecececsessssececccecsesessseaeeeeceseeenssseseeeeeesesesssseaeeeeeess 169 irot rdq Rotate task precedence handler only sese trennen 169 get tid Reference task ID in the RUNNING statO ooonocococnncnncononononnnonccnnnnanannnnnnonconononnononononconannnnos sql iget tid Reference task ID in the RUNNING state handler only see 171 IOE o1 Aa Lockthe OP O ENAA AET A A TE TE N TETZA iloc_cpu Lock the CPU Gandleronly costs Guerre fao eem cep ee cea did 172 unl epu Unlock the CBUL iina euet rerte lila Teneo sec robo st repe desto ese sente eea aaan aer posi 174 iunl_cpu Unlock the CPU handler only sese 174 dis dsp Disable dispatching diia 175 ena dsp Enables dispatchuimg s ucro bes teer recette iet eese titan dia eT sns ctx Reference context is 178 sns loc Reference CPU S
213. ononnanonononnnnconononnn nono noncononannn nn nono 207 6 2 1 Applications Program CodiN8 cccccnnonnoononnnonnnnnnnannnonononnononnanonnnnnncononnnnnnnnnnnncononnnnnnononnnnonannnnns 207 6 2 2 Configuration File Preparation ooccconononononnnonnnnnonanonononononnonnnononononnononnn nono re a ai aaas 208 6 2 3 Configurator Execution esce te eter tele Pese Fe rue Free eu gta 209 6 2 4 System generation ob gees Ms cats ad ae Dep di ii CO ga Ee 209 6 2 b Wr ng ROM csse ctr et cat ee eta ih tr OEE e eR E RR 210 Detailed Applications EE 211 7 1 Program Coding Procedure in C Language esee nennen eterne nenne tenir esset 211 7 1 1 Task Description Procedure ccccscscccsecsseessssecececcececeesesseaecesecsceenssssseeececesesenensaseeeeeeseneneaaeas 211 7 1 2 Writing a Kernel OS Dependent Interrupt Handler sees 212 7 1 3 Writing Non kernel Interrupt Handler cocnnnoncononcnnnnnnnononanonononononnnnononononnononnanononononnonannnnos 213 7 1 4 Writing Cyclic Handler Alarm Handler cccccccccccccccesssssecesececesceesenssceeeceesesenssssaeeeseeseeeees 218 7 2 Program Coding Procedure in Assembly Language esses eren nnne enne 215 7 2 1 Writing Tasks A A eI ER EARS 215 7 2 2 Writing Kernel Interrupt Handler sees eene rennen ennt nononcnnonanns 216 7 2 8 Writing Non kernel Interrupt Handler ococnnnonccnoncn
214. ooocooococnncncnoooononannnnonnononnnnnnononocnononnonononanaconononos 39 4 1 5 Synchronization and Communication Function Semaphore sese 43 4 1 0 Synchronization and Communication Function Eventflag sse 45 4 1 7 Synchronization and Communication Function Data Queue see 47 4 1 8 Synchronization and Communication Function Mailbox seen 48 4 1 9 Memory pool Management Function Fixed size Memory pool c cccccccssessesceseescssceseesenees 50 4 1 10 Variable size Memory Pool Management Function ccccccccceceseesssseceeeeeceseeesesssseeeeeeeceenens 51 4 1 11 Time Management Function ccccccccssseseseseseseseseseeeeeeseeeeeeeseseeeeeeeeeeeeeeeeeseeeseseeeeeseseeeeeeeeees 54 43 12 Cyclic Handler Function ic A A RAE 56 4 1 13 Alarm Handler FunctioN oooooccnnnocnncnonocnnonononnnnnnnnnnnnonononnncnnnonnncnnnonnnnnnnn SANAA SSTA EAA SENA seen nnns nnns 57 4 1 14 System Status Management Functi0N occccnnononononnnononnnnnanononononononononnnnonononnononnnononancnconannnnns 58 4 1 15 Interrupt Management Function ccccceseseseseseseseseseseseseseseeseseeeeeeeeeeeseeeseeeseeeseseseeeeeeeeees 59 4 1 16 System Configuration Management Function sees eene nnne eterna 60 4 1 17 Extended Function Short Data Queue cccccccscscccsesessccssesesscssesscsscsscsessecsessecsecses
215. ooonnnncnnnnnnnonononannnnnonannnnonanoncnnonanos 1l Tigure 3 6 Task Witt aie elec erosion lee eH DESDE NES Figure 3 7 Task Register Area ccccccccccccccssssssecscececssssssnsccscececssssnsnaeeascesecsesessuseescececssssnaeessecesseees 12 Figure 3 8 Actual Register and Stack Area Management ccocoooccnononoconononnncnnnnonnnnnnnononnnnnnnncnnnnnnoss 18 Bigure 3 9 Service Calli keer cess cack oiu eie ee eb SH ot Ua os ed ette e 14 Figure 3 10 Service Call Processing Flowchart oooooocnnococonononoccnononocononnnononononnnnnnnonno co nononnnnnnnnnnss 15 Figure 3 11 Processing Procedure for a Service Call a Handler that caused an interrupt during Task Execution 17 Figure 3 12 Processing Procedure for a Service Call from a Handler that caused an interrupt during Service Call Processing cat A Bae 18 Figure 3 13 Processing Procedure for a service call from a Multiplex interrupt Handler 19 Figure 3 14 Task Tdentification iieri e haa Vaaa KASSI CCo SAA IA S ca e fig Crea ea dns 20 Figure LO Task Status oe eese eiecit a ee ED iier 21 Figure 3 16 MR100 Task Status Transition eese enne n nennen enne nennen en 225 Figure 3 17 Ready Queue Execution Queue ccccccscssssscssssssesecscsessesecsesecsesaesececsecsesesecsacseeeesesaeas 95 Figure 3 18 Waiting queue of the TA TPRI attribute ocoooconinonoconononoccnnnononnnnnnnnnnnnonnnononcnnnnnnnnnnnoss 26 Figure 3 19 Waiting queue
216. or code returned in this case is E RLWAI If this service call is to be issued from task context use rcv dtq trcv dtq prcv dtq if issued from non task context use iprcv dtq 123 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task VP INT data if rcv dtq ID dtq amp data E RLWAI error forced wakeup n if prcv dtq ID dtq amp data E TMOUT error Timeout n if trcv dtq ID _dtq amp data 10 E TMOUT error Timeout An lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 PUSHM R6R4 trcv dtq ID DTOl1 H4TMO POL PUSH W R2 prcv dtq ID_DTQ2 PUSH W R2 rev_dtq ID_DTQ2 124 ref dtq Reference data queue status iref dtq Reference data queue status handler only C Language API ER ercd ref dtq ID dtqid T RDTQ pk rdtq ER ercd iref dtq ID dtqid T RDTQ pk rdtq Parameters ID dtqid ID number of the target data queue T_RDTQ pk rdtq Pointer to the packet to which data queue status is returned Return Parameters ER ercd Terminated normally E OK T RDTQ pk rdtq Pointer to the packet to which data queue status is returned Contents of pk rdtq typedef struct t rdtq ID stskid 0 2 Transmission waiting task ID ID wtskid 2 2 Reception waiting task ID UI
217. or error code Assembly language API include mr100 inc act tsk TSKID iact tsk TSKID Parameters TSKID ID number of the task to be started Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Task ID Error Code E QOVR Queuing overflow 65 Functional description This service call starts the task indicated by tskid The started task goes from DORMANT state to READY state or RUN NING state The following lists the processing performed on startup 1 Initializes the current priority of the task 2 Clears the number of queued wakeup requests 3 Clears the number of suspension requests Specifying tskid TSK_SELF 0 specifies the issuing task itself The task has passed to it as parameter the extended infor mation of it that was specified when the task was created If TSK_SELF is specified for tskid in non task context operation of this service call cannot be guaranteed If the target task is not in DORMANT state a task activation request by this service call is enqueued In other words the activation request count is incremented by 1 The maximum value of the task activation request is 255 If this limit is ex ceeded the error code E QOVR is returned If TSK_SELF is specified for tskid the issuing task itself is made the target task If this service call is to be issued from task context use act_tsk if issued from non task context use
218. otated In this case the task under execution may not always be linked to the ready queue Such as when isus tsk is is sued to the executed task during dispatch delay 17 Precautions e No service call e g slp tsk wai sem can be issued that may place the own task in a wait state while in a state where dispatch is disabled by dis dsp orloc cpu e ena dsp and dis dsp cannot be issued while in a state where interrupts and dispatch are disabled by loc cpu Disabled dispatch is re enabled by issuing ena dsp once after issuing dis dsp several times The above status transition can be summarized in Table 3 3 276 11 4 Regarding Initially Activated Task MR100 allows you to specify a task that starts from a READY state at system startup This specification is made by setting the configuration file Refer to 8 1 2 for details on how to set 277 12 Appendix 12 1Data Type typedef signed char B Signed 8 bit integer typedef signed short H Signed 16 bit integer typedef signed long W Signed 32 bit integer typedef unsigned char UB Unsigned 8 bit integer typedef unsigned short UH Unsigned 16 bit integer typedef unsigned long UW Unsigned 32 bit integer typedef char VB 8 bit value with unknown data type typedef short VH 16 bit value with unknown data type typedef long VW 32 bit value with unknown data type typedef void VP Pointer to unknown da
219. poration is necessary to reprint or repro duce in whole or in part these materials l these products or technologies are subject to the Japanese export control restrictions they must be exported under a license from the Japanese government and cannot be imported into a country other than the approved destination Any diversion or reexport con trary to the export control laws and regulations of Japan and or the country of destination is prohibited Please contact Renesas Technology Corporation or Renesas Solutions Corporation for further details on these materials or the prod ucts contained therein For inquiries about the contents of this document or product fill in the text file the installer generates in the following directory and email to your local distributor SUPPORT Product name S UPPORT TXT Renesas Tools Homepage http www renesas com en tools Preface The M3T MR100 4 abbreviated as MR100 is a real time operating system for the R32C 100 series microcomputers The MR100 conforms to the pITRON Specification This manual describes the procedures and precautions to observe when you use the MR100 for programming purposes For the detailed information on individual service call procedures refer to the MR100 Reference Manual Requirements for MR100 Use When creating programs based on the MR100 it is necessary to purchase the following product of Renesas C compiler package for R32C 100 series microcomputers a
220. priority of task tskpri has the current priority of the specified task returned to it If the task is in DOMANT state tskpri is indeterminate tskbpri base priority of task tskbpri has the base priority of the specified task returned to it If the task is in DOMANT state tskbpri is indeterminate tskwait cause of wait If the target task is in a wait state one of the following causes of wait is returned The values of the re spective causes of wait are listed below If the task status is other than a wait state TTS WAI or TTS WAS tskwait is indeterminate e TTW SLP 0x0001 Kept waiting by slp tsk or tslp tsk TTW DLY 0x0002 Kept waiting by dly tsk TTW SEM 0x0004 Kept waiting by wai sem or twai sem TTW FLG 0x0008 Kept waiting by wai flg or twai flg TTW SDTQ 0x0010 Kept waiting by snd dtq or tsnd dtq TTW RDTQ 0x0020 Kept waiting by rcv dtq or trcv dtq TTW MBkX 0x0040 Kept waiting by rcv mbx or trcv mbx TTW MPF 0x2000 Kept waiting by get mpf or tget mpf TTW VSDTQ 0x4000 Kept waiting by vsnd_dtq or vtsnd dtq e TTW VRDTQ 0x8000 Kept waiting by vrev_dtq or vtrcv dtq wobjid waiting object ID If the target task is in a wait state TTS_WAI or TTS WAS the ID of the waiting target object is re turned Otherwise wobjid is indeterminate 4 lefttmo left time before timeout If the target task has been placed in WAITING state TTS_WAI or TTS WAS by other than dly tsk the left time before it times out is ret
221. psnd dtq vipsnd dtq The data is transmitted to the short data queue If the short data queue is full of data the task returns error code without going to a data transmission wait state Forced Send to Short Data Queue vfsnd dtq vifsnd dtq The data is transmitted to the short data queue If the short data queue is full of data the data at the top of the short data queue or the oldest data is removed and the transmitted data is stored at the tail of the short data queue Receive from Short Data Queue vrcv dtq vtrcv dtq The data is retrieved from the short data queue If the short data queue has no data in it the task is kept waiting until data is transmitted to the short data queue Receive from Short Data Queue vprcv dtq viprcv dtq The data is received from the short data queue If the short data queue has no data in it the task returns error code without going to a data reception wait state Reference Short Data Queue Status vref dtq viref dtq Checks to see if there are any tasks waiting for data to be entered in the target short data queue and refers to the number of the data in the short data queue 60 4 1 18 Extended Function Reset Function The reset function is a function outside the scope of uITRON 4 0 Specification It initializes the mailbox data queue and memory pool etc Clear Data Queue Area vrst dtq Initializes the data queue If there are any tasks waiting for transmission they are freed fro
222. queue Definition format Symbol Definition range TA TFIFO or TA TPRI Default value TA TFIFO Select a method in which tasks wait for the mailbox If TA TFIFO is selected tasks are enqueued in order of FIFO If TA TPRI is selected tasks are enqueued in order of priority beginning with the one that has the highest priority 3 Select message queue Definition format Symbol Definition range TA MFIFO or TA MRPI Default value TA MFIFO Select a method by which a message queue of the mailbox is selected If TA MFIFO is selected messages are enqueued in order of FIFO If TA MPRI is selected messages are enqueued in order of priority beginning with the one that has the highest priority 240 4 Maximum message priority Definition format Numeric Value Definition range 1 to maximum value of message priority that was specified in definition of maximum number of items Default value 1 Specify the maximum priority of message in the mailbox Fixed size memory pool definition This definition must always be set when the fixed size memory pool function is to be used lt lt Format gt gt Fixed Memory pool Definition memorypool ID No 1 name ID name section Section Name num_block Number of blocks in memory pool siz block Block size of Memory pool wait_queue Select memory pool waiting queue
223. quire fixed size memory block Aquire fixed size memory block polling Aquire fixed size memory block polling handler only Aquire fixed size memory block with timeout ID mpfid VP p blk ID mpfid VP p blk ipget mpf ID mpfid VP p blk ID mpfid VP p blk TMO tmout ID number of the target fixed size memory pool to be acquired Pointer to the start address of the acquired memory block Timeout value tget mpf Return Parameters ER ercd Terminated normally E OK or error code VP p blk Pointer to the start address of the acquired memory block Assembly language APT include mr100 inc get mpf MPFID pget mpf MPFID ipget mpf MPFID tget mpf MPFID TMO Parameters MPFID ID number of the target fixed size memory pool to be acquired TMO Timeout value tget mpf 136 Register contents after service call is issued get mpf pget mpf ipget mpf Register name Content after service call is issued RO Error code R3RI Start address of the acquired memory block R2 ID number of the target fixed size memory pool to be acquired tget mpf Register name Content after service call is issued RO Error code R3RI Start address of the acquired memory block R2 ID number of the target fixed size memory pool to be acquired R6R4 Timeout value Error code E_RLWAI Forced release from waiting E_TMOUT Polling failure or timeout or timed out EV_RST Released from WAITING state by clearing of the memory pool
224. r blkb 16 task PUSHM Al ref ver refver 186 5 15 Extended Function Short Data Queue Specifications of the Short data queue function of MR100 are listed in Table 5 26 This function is outside the scope of HITRON 4 0 Specification Table 5 26 Specifications of the Short Data Queue Function No Item Content 1 Data queue ID 1 255 2 Capacity data bytes in data queue area 0 16383 3 Data size 16 bits 4 Data queue attribute TA_TFIFO Waiting tasks enqueued in order of FIFO TA_TPRI Waiting tasks enqueued in order of priority Table 5 27 List of Long Dataqueue Function Service Call No Service Call Function System State T IN E D U 1 vsnd dtq Sends to short data queue O O O 2 vpsnd_dtq Sends to short data queue polling OO O JO 3 vipsnd dtq O O JO jO 4 vtsnd_dtq Sends to short data queue with timeout O O O 5 vfsnd_dtq Forced sends to short data queue O O JO jO 6 vifsnd_dtq O O JO jO 7 vrcv dtq Receives from short data queue O O O 8 vprcv dtq Receives from short data queue polling O O JO jO 9 viprev_dtq O O JO jO 10 vtrcv dtq Receives from short data queue with timeout O O O 11 vref dtq References short data queue status O O JO jO 12 viref dtq OO O JO Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following mea
225. r of FIFO For the vprev_dtq and viprcv dtq service calls the task returns immediately and responds to the call with the error code E TMOUT For the vtrcv dtq service call specify a wait time for tmout in ms units The values specified for tmout must be within Ox7FFFFFFF If any value exceeding this limit is specified the service call may not operate correctly If TMO_POL 0 is specified for tmout it means specifying O as a timeout value in which case the service call operates the same way as vprcv dtq Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as vrcv_dtq The task placed into a wait state by execution of the vrev_dtq or vtrcv_dtq service call is released from the wait state in the following cases When the vrcv dtq vtrcv dtq vprcv dtq or viprcv dtq service call is issued before the tmout time elapses with task awaking conditions thereby satisfied The error code returned in this case is E OK When the first time tick occurred after tmout elapsed while task awaking conditions remain un satisfied The error code returned in this case is E TMOUT When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI If this service call is to be issued from task context use vrev_dtq vtrev_dtq vprev_dtq if issued from non task
226. r only C Language API ER ercd ref flg ID flgid T RFLG pk rflg ER ercd iref flg ID flgid T RFLG pk rflg Parameters ID flgid ID number of the target eventflag T RFLG pk rflg Pointer to the packet to which eventflag status is returned Return Parameters ER ercd Terminated normally E OK T RFLG pk rflg Pointer to the packet to which eventflag status is returned Contents of pk rflg typedef struct t rflg ID wtskid 0 2 Reception waiting task ID FLGPTN flgptn 2 4 Current eventflag bit pattern T RFLG Assembly language API include mr100 inc ref_flg FLGID PK RFLG iref flg FLGID PK RFLG Parameters FLGID ID number of the target eventflag PK RFLG Pointer to the packet to which eventflag status is returned Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the target eventflag Al Pointer to the packet to which eventflag status is returned Error code None Functional description This service call returns various statuses of the eventflag indicated by flgid wtskid Returned to wtskid is the ID number of the task at the top of a waiting queue the next task to be dequeued If no tasks are kept waiting TS amp NONE is returned flgptn Returned to flgptn is the current eventflag bit pattern If this service call is to be issued from task context use ref flg if
227. ration Management Function Table 5 25 List of System Configuration Management Function Service Call No Service Call Function System State E D U 1 ref ver S References version information O O O 2 iref_ver O O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 184 ref ver Reference version information iref ver Reference version information handler only C Language API ER ercd ref ver T RVER pk rver ER ercd iref ver T RVER pk rver Parameters T RVER pk rver Pointer to the packet to which version information is returned Contents of pk rver typedef struct t rver maker 0 2 Kernel manufacturer code UH prid 2 2 Kernel identification number UH spver 4 2 ITRON specification version number UH prver 6 2 Kernel version number UH prno 4 8 2 Kernel product management information T_RVER Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc ref ver PK VER iref ver PK VER Parameters PK VER Pointer to the packet to which version inform
228. rcv mbx tsnd dtq trcv dtq vtsnd dtq vtrcv dtq and tget mpf service call the task is queued to one of the following waiting queues depending on the request Event flag waiting queue Semaphore waiting queue Mailbox message reception waiting queue Data queue data transmission waiting queue Data queue data reception waiting queue Short data queue data transmission waiting queue Short data queue data reception waiting queue Fixed size memory pool acquisition waiting queue 4 SUSPENDED state When the sus tsk service call is issued from a task in the RUNNING state or the isus_tsk service call is issued from a handler the READY task designated by the service call or the currently executed task enters the SUS PENDED state If a task in the WAITING state is placed in this situation it goes into the WAIT ING SUSPENDED state The SUSPENDED state is the condition in which a READY task or currently executed task is excluded from scheduling to halt processing due to I O or other error occurrence That is when the suspend request is made to a READY task that task is excluded from the execution queue Note that no queue is formed for the suspend request Therefore the suspend request can only be made to the 1 Depends on the dly tsk slp_tsk tslp tsk wai flg twai flg wai sem twai sem rcv mbx trcv mbx snd dtq tsnd dtq rcv dtq trev_dtq vtsnd dtq vsnd dtq vtrcv dtq tget mpf get mpf and vrev_dtq service call 11 If the task
229. re eer eS ICH 70 BZERO MR RAM top MR RAM 71 72 j222222z2z2z2z2z2zl2ll2ll2ll2ll2ll2ll2ll2ll2l2l2l2l22l22l22l2222222222l2222l22l22l22 2 73 NEAR area initialize 74 FAR area initialize 219 BZERO bss SB8 top bss SB8 BZERO bss SB16 top bss SB16 BZERO bss NEAR top bss NEAR BZERO bss FAR top bss FAR BZERO bss EXT top bss EXT BZERO bss MON1 top bss MON1 BZERO bss MON2 top bss MON2 BZERO bss MON3 top bss MON3 BZERO bss MONA top bss MONA BCOPY data SB8 INIT top data SB8 top BCOPY data SB16 INIT top data SB16 top BCOPY data NEAR INIT top data NEAR top BCOPY data FAR INIT top data FAR top BCOPY data EXT INIT top data EXT top BCOPY data MON1 INIT top data MON1 top BCOPY data MON2 INIT top data MON2 top BCOPY data MON3 INIT top data MON3 top BCOPY data MONA INIT top data MONA top data SB16 data NEAR data FAR data EXT data MON1 data MON2 data MON3 data MON4 INI IPL P LDC 4 amp INT VECTOR INTB NC RR CHER ERR SP CERTO ee feet TUE A System timer interrupt setting qoi czu hcsnticucuaLnscsmocstesescn5ceudens el IF USE TIMER MOV B dstmr mod val stmr mod reg regoffset f MOV W dstmr cnt stmr ctr reg regoffset i MOV B stmr_int_IPL stmr_int_reg OR B stmr_bit 1 stmr_start regoffset ENDIF X n R System timer initialize ME A A a aaa IF USE SYSTEM TIME MOV W D Sys TIME L Sys time 4 MOV W D Sys TIME M Sys time 2 MOV W 4 D S
230. ref_cyc 160 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RCYC rcyc ER ercd ercd ref cyc ID CYC1 amp rcyc lt lt Example statement in assembly language gt gt include mr100 inc GLB task refcyc blkb 6 task PUSH W R2 PUSH L A1 ref cyc ID_CYC1 _refcyc 161 5 11 Time Management Function Alarm Handler Specifications of the alarm handler function of MR100 are listed in Table 5 21 The alarm handler description languages in item No 4 are those specified in the GUI configurator They are not output to a configuration file nor are the MR100 ker nel concerned with them Table 5 21 Specifications of the Alarm Handler Function No Item Content 1 Alarm handler ID 1 255 2 Activation time O 7fffffff ms 3 Extended information 16 bits 4 Alarm handler attribute TA HLNG Handlers written in high level language TA ASM Handlers written in assembly language Table 5 22 List of Alarm Handler Function Service Call No Service Call Function System State T N E D U 1 sta_alm Starts alarm handler operation Q Q Q 2 ista_alm Oe Oe Es Lo 3 stp_alm Stops alarm handler operation Q Q 4 istp alm CD s Ds EC 5 ref alm References alarm handler status O O O O 6 iref_a
231. returns FALSE when the system is in a dispatching enabled state I Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task BOOL stat stat sns dpn lt lt Example statement in assembly language gt gt include mr100 inc GLB task task sns dpn 181 5 13Interrupt Management Function Table 5 24 List of Interrupt Management Function Service Call No Service Call Function System State E D U 1 ret int Returns from an interrupt handler O O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning 4 4 4 T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 182 ret int Returns from an interrupt handler when written in assembly language C Language API This service call cannot be written in C language Assembly language APT include mr100 inc ret_int O Parameters None Error code Not return to the interrupt handler that issued this service call Functional description This service call performs the processing necessary to
232. rofile service calls Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 108 set flg Set eventflag iset_flg Set eventflag handler only C Language APT ER ercd set flg ID flgid FLGPTN setptn ER ercd iset flg ID flgid FLGPTN setptn Parameters ID flgid ID number of the eventflag to be set FLGPTN setptn Bit pattern to be set Return Parameters ER ercd Terminated normally E OK Assembly language API include mr100 inc set flg FLGID SETPTN iset flg FLGID SETPTN Parameters FLGID ID number of the eventflag to be set SETPTN Bit pattern to be set Register contents after service call is issued Register name Content after service call is issued RO Error code R2 Eventflag ID number Al Bit pattern to be set Error code None Functional description Of the 32 bit eventflag indicated by flgid this service call sets the bits indicated by setptn In other words the value of the eventflag indicated by flgid is OR d with setptn If the alteration of the eventflag value results in task awaking conditions for a task that has been kept waiting for the eventflag by the wai_flg or twai_fl
233. rogram statement lt lt Example statement in C language gt gt Hinclude lt itron h gt include lt kernel h gt include kernel id h void task ena _dsp lt lt Example statement in assembly language gt gt include mr100 inc GLB task task ena dsp 177 sns ctx Reference context C Language API BOOL state sns ctx Parameters None Return Parameters BOOL state TRUE Non task context FALSE Task context Assembly language APT include mr100 inc sns ctx Parameters None Register contents after service call is issued Register name Content after service call is issued RO TRUE Non Task context FALSE Task context Error code None Functional description 1 This service call returns TRUE when it is invoked from non task context or returns FALSE when invoked from task con text This service call can also be invoked from a CPU locked state Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel_id h void task BOOL stat stat sns_ctx lt lt Example statement in assembly language gt gt include mr100 inc GLB task task sns ctx 178 sns loc Reference CPU state C Language API BOOL state sns loc Parameters None Return Parameters BOOL state TRUE CPU locked state FALSE CPU unlocked state Assembly la
234. s after service call is issued Register name Content after service call is issued RO Error code R2 Data queue ID to be cleared Error code None Functional description 1 This service call clears the data stored in the data queue indicated by dtqid If the data queue area has no more areas to be added and tasks are enqueued in a data transmission waiting queue all of the tasks enqueued in the data transmission wait ing queue are released from WAITING state Furthermore the error code EV RST is returned to the tasks that have been released from WAITING state Even when the number of data queues defined is 0 all of the tasks enqueued in a data transmission waiting queue are re leased from WAITING state This service call can be issued only from task context It cannot be issued from non task context 197 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task1 void vrst dtq ID dtql lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 vrst dtq ID_DTQ1 198 vrst vdtq Clear Short data queue area C Language API ER ercd vrst vdtq ID vdtgid Parameters ID vdtqid Short data queue ID to be cleared Return Parameters ER ercd Terminated normally E OK Assembly language APT include mr100 inc vrst vdtq VDTOID
235. s is indicated by blk The start address of the memory block to be released that is specified here should always be that of the memory block acquired by pget mpl This service call does not check the content of blk so that if the address stored in blk is incorrect the service call may not operate correctly 146 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task VP p blk if get mpl ID mpli 200 amp p blk E OK error Not enough memory An rel mpl ID mpl p blk lt lt Example statement in assembly language gt gt include mr100 inc GLB task g blk blkb 4 task PUSH W R2 pget mpl ID_MPL1 200 MOV L R3R1 _g_blk PUSH W R2 rel mpl ID_MPL1 g blk 147 ref mpl Reference variable size memory pool status iref mpl Reference variable size memory pool status handler only C Language API ER ercd ref mpl ID mplid T RMPL pk rmpl ER ercd iref mpl ID mplid T RMPL pk rmpl Parameters ID mplid ID number of the target variable size memory pool T RMPL pk rmpl Pointer to the packet to which variable size memory pool status is returned Return Parameters ER ercd Terminated normally E OK T RMPL pk rmpl Pointer to the packet to which variable size memory pool status is returned Contents of pk rmpl typedef struct t_rmpl ID wtskid
236. s_dsp 250 156 ercd sns_dpn 250 158 ercd 285 Memorypool Management Functions Parameter ReturnParam Service INT eren Call Mo Code R1 R2 R3 R6R4 A1 RO R3R1 A0 get mpf 249 108 mpfid ercd p blk pget mpf 250 106 mpfid ercd p blk ipget mpf 250 106 mpfid ercd p blk tget mpf 249 110 mpfid tmout ercd p blk rel mpf 249 112 blk mpfid blk ercd irel_mpf 250 114 blk mpfid blk ercd ref_mpf 250 116 mpfid pk_rmpf ercd iref_mpf 250 116 mpfid pk_rmpf ercd pget_mpl 249 118 mplid ercd p_blk rel_mpl 249 120 blk mplid blk ercd ref_mpl 250 122 mplid pk rmpl ercd iref_mpl 250 122 mplid pk_rmpl ercd Time Management Functions Parameter ReturnParameter ServiceCall INTNo od ES R6RA m RO 0 set_tim 250 124 p_systim ercd iset_tim 250 124 p_systim ercd get_tim 250 126 p_systim ercd iget_tim 250 126 p_systim ercd sta_cyc 250 128 cycid ercd ista_cyc 250 128 cycid ercd stp_cyc 250 130 cycid ercd istp_cyc 250 130 cycid ercd ref_cyc 250 132 cycid pk rcyc ercd iref cyc 250 132 cycid pk rcyc ercd sta alm 250 134 almid almtim ercd ista alm 250 134 almid almtim ercd stp alm 250 136 almid ercd istp alm 250 136 almid ercd ref alm 250 138 almid pk ralm ercd iref alm 250 138 almid pk ralm ercd 286 System Config
237. sed from the WAITING state in the following cases Note that when released from WAITING state the task that issued the service call is removed from the timeout waiting queue and linked to a ready queue When the first time tick occurred after dlytim elapsed The error code returned in this case is E OK When the rel wai or irel wai service call is issued before dlytim elapses The error code returned in this case is E RLWAI Note that even when the wup tsk or iwup tsk service call is issued during the delay time the task is not released from WAITING state The delay time dlytim is expressed in ms units Therefore if specified as dly tsk 50 the issuing task is placed from RUNNING state into a delayed wait state for a period of 50 ms The values specified for dlytim must be within 0x 7FFFFFFF time tick value If any value exceeding this limit is speci fied the service call may not operate correctly This service call can be issued only from task context It cannot be issued from non task context 98 li Example program statement 1 lt lt Example statement in C language gt gt Hinclude lt itron h gt include lt kernel h gt include kernel id h void task if dly tsk E OK error Forced wakeup n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSHM R6R4 dly_tsk 500 99 5 3 Synchronization amp Communication Function Se
238. seeecseseenees 60 4 1 18 Extended Function Reset Function aan eripere Cris ca 61 Service call reffernce s il a d IER Pea iere ERR dida 63 5 1 Task Management Function e ener ntc 63 act tesk Activate task io eae AE cd re e ER ER o ehe ee ERE vere ere den 65 jact tsk Activate task handler only ou Lecce IUE A DRAN anio 65 can act Cancel task activation Tequest ococonooocoonnnnncnnonnnnononononcnnononnnnnnnnoncnnnononnn nono rne seen enter nnne seen 67 ican_act Cancel task activation request handler only sese 67 sta tsk Activate task with a start code cccoonococcnonocononononnnonnnonnnononnnnnncnnnnnnncnonnnnnn enne enne enne nnne 69 ista tsk Activate task with a start code handler Only oonononcnnnnnnncnonnnninnnnnnncanononananonncnanancnn carac 69 ext tsk Terminate invoking task mascine criais aE eier iri ieoi taea eiers eths tertek Terminate task a AE a AE A E E a E 87 chg pri Change task Priority anres enren nee n nnne en en ee enn enses nennen net nn nnne s ener tete a 75 cha pri Change task priority handler only iii tuned Ri esit plat oculta ple PDPASTMROR 75 get pri Reference task priority oooooooonononcncnononononnnononnononnnnonononnononnano nnn nnne en en nete anno eese seen tenen sese eren nns DT iget pri Reference task priority handler only ainia isch stretto i oci er Ferr rai Er rta d LE yef tsk Reference task status coa etant dia eti Da E een
239. sem ID sem E QOVR error Overflow n lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 Sig sem ID_ SEM2 102 wai sem Acquire semaphore resource pol sem Acquire semaphore resource polling ipol sem Acquire semaphore resource polling handler only iwai sem Acquire semaphore resource with timeout C Language API ER ercd wai_sem ID semid ER ercd pol_sem ID semid ER ercd ipol_sem ID semid ER ercd twai_sem ID semid TMO tmout Parameters ID semid Semaphore ID number to be acquired TMO tmout Timeout value for twai sem Return Parameters ER ercd Terminated normally E OK or error code Assembly language APT include mr100 inc wai sem S pol sem S ipol sem twai sem EMID EMID SEMID SEMID TMO Parameters SEMID TMO Semaphore ID number to be acquired Timeout value twai_sem Register contents after service call is issued wai sem pol sem ipol sem Register name Content after service call is issued RO Error code R2 Semaphore ID number to be acquired twai_sem Register Content after service call is issued name RO Error code R2 Semaphore ID number to be acquired R6R4 Timeout value Error code E RLWAI Forced release from waiting E TMOUT Polling failure or timeout 103 Functional description This service call acquires one semaphore resource from the semaphore in
240. service calls directly without using a ser vice call invocation macro your program may not be guaranteed of compatibility with future versions of MR100 The table below lists the assembly language interface parameters The values set forth in uITRON specifica tions are not used for the function code Task Management Function Parameter ReturnParameter ServiceCall INTNo LEUTE Ri B3 BE Ai Ed R2 ista tsk 250 8 stacd tskid stacd ercd sta tsk 249 6 stacd tskid stacd ercd act tsk 249 0 tskid ercd iact tsk 250 2 tskid ercd ter tsk 249 10 tskid ercd can_act 250 4 tskid actcnt ican act 250 4 tskid actcnt chg pri 250 12 tskid tskpri ercd ichg_pri 250 14 tskid tskpri ercd rel_wai 249 32 tskid ercd irel_wai 250 34 tskid ercd ref_tst 250 20 tskid pk_rtst ercd iref_tst 250 20 tskid pk_rtst ercd ref_tsk 250 18 tskid pk_rtsk ercd iref_tsk 250 18 tskid pk_rtsk ercd ext_tsk 137 106 get_pri 250 16 tskid ercd tskpri iget_pri 250 16 tskid ercd tskpri 282 Task Dependent Synchronization Function Parameter ReturnParam
241. sk Terminate invoking task C Language APT ER ercd ext_tsk Parameters None Return Parameters Not return from this service call Assembly language APT include mr100 inc ext_tsk O Parameters None O Register contents after service call is issued Not return from this service call Error code Not return from this service call Functional description This service call terminates the invoking task In other words it places the issuing task from RUNNING state into DOR MANT state However if the activation request count for the issuing task is 1 or more the activation request count is decremented by 1 and processing similar to that of act_tsk or iact_tsk is performed In that case the task is placed from DORMANT state into READY state The task has its extended information passed to it as parameter when the task starts up This service call is designed to be issued automatically at return from a task In the invocation of this service call the resources the issuing task had acquired previously e g semaphore are not re leased This service call can only be used in task context This service call can be used even in a CPU locked state but cannot be used in non task context 71 Example program statement 1 lt lt Example statement in C language include lt itron h gt include lt kernel h gt include kernel id h void task void ext _tsk lt
242. sk X stack size must set XX or more near line xxx xxxx cfg You must set more than XX bytes in task x stack size cfg100 Error R2RO must be contained in task x context near line xxxx xxxx cfg You must select R2RO register in task x context cfg100 Error Can t specify B or F switch when os intzYES xxxx cfg B and F switch cannot be specified to a kernel interrupt handler cfg100 Error Can t specify B and E switch at a time when os intzNO xxxx cfg B and E switch cannot be specified to the non kernel interrupt handler at a time cfg100 Error interrupt vector eld os int must be YES xxxx cfg When a kernel interrupt mask level is 7 an interrupt handler must be kernel interrupt handler cfg100 Error system IPL should be 7 xxxx cfg When Eipl is specified as the command option of configurator the value of sysrem IPL of a system definition must be 7 cfg100 Error Timer counter value is overflow xxxx cfg Overflow occurred in the operation of a timer count A timer cannot be initialized with the time tick cycle and peripheral clock which were specified Please initialize the timer and sets clock timer to OTHER 258 Warning messages The following message are a warning A warning can be ignored providing that its content is understood cfg100 Warning system is not defined xxxx cfg cfg100 Warning system XXXX is not defined xxxx cfg System definition or system definition item XXXX
243. sks can be enqueued in the eventflag waiting queue If TA WMUL is selected the TA WMUDL attribute is added permitting multiple tasks to be enqueued If TA WSGL is selected the TA WSGL attribute is added prohibiting multiple tasks from being enqueued 5 Clear attribute Definition format Symbol Definition range YES or NO Default value NO Specify whether the TA CLR attribute should be added as an eventflag attribute If YES is selected the TA CLR attribute is added If NO is selected the TA CLR attribute is not added Semaphore definition This definition is necessary to use Semaphore function lt lt Format gt gt Semaphore Definition semaphore ID No name ID name wait queue Selecting a semaphore waiting queue initial count Initial value of semaphore counter max_count Maximum value of the semaphore counter The ID number must be in the range of 1 to 255 The ID number can be omitted If omitted numbers are automatically assigned sequentially beginning with the smallest lt lt Content gt gt Define the following for each semaphore ID number 1 ID Name Definition format Symbol Definition range None Default value None Define the name with which a semaphore is specified in a program 237 2 Selecting a semaphore waiting queue Definition format Symbol Definition range TA TFIFO or T
244. ssembly language Select all registers when the task is written in the C language When selecting a register here be sure to select all registers that store service call parameters used in each task MR 100 kernel does not change the registers of bank If this definition is omitted it is assumed that all registers are selected 6 Section name in which the stack is located Definition format Symbol Definition range None Default value stack Define the section name in which the stack is located The section defined here must always have an area allo cated for it in the section file asm sec inc or c sec inc If no section names are defined the stack is located in the stack section 7 TA ACT attribute initial startup state Definition format Symbol Definition range ON or OFF Default value OFF Define the initial startup state of a task If this attribute is specified ON the task goes to a READY state at the initial system startup time The task startup code of the initial startup task is the extended information 235 8 Extended information Definition format Numeric value Definition range 0 to OXFFFFFFFF Default value 0 Define the extended information of a task This information is passed to the task as argument when it is restarted by a queued startup request for example Eventflag definition This definition is necessary to use Eventflag function lt
245. startup requests are accumulated but startup code cannot be specified Activate Task sta tsk ista tsk Activates the task changing its status from DORMANT to either READY or RUNNING In this service call un like in act tsk iact tsk startup requests are not accumulated but startup code can be specified Terminate Invoking Task ext tsk When the issuing task is terminated its state changes to DORMANT state The task is therefore not executed until it is restarted If startup requests are accumulated task startup processing is performed again In that case the is suing task behaves as if it were reset If written in C language this service call is automatically invoked at return from the task regardless of whether it is explicitly written when terminated Terminate Task ter tsk Other tasks in other than DORMANT state are forcibly terminated and placed into DORMANT state If startup requests are accumulated task startup processing is performed again In that case the task behaves as if it was re set See Figure 4 2 Startup request count gt 0 TaskB ter tsk B Terminated Task B reset Figure 4 2 Task Resetting Change Task Priority chg_pri ichg_pri If the priority of a task is changed while the task is in READY or RUNNING state the ready queue also is up dated See Figure 4 3 Furthermore if the target task is placed in a waiting queue of objects with TA_TPRI attribute the waiting queue also is updat
246. such as i placement of substitutive auxiliary circuits ii use of nonflammable material or iii prevention against any malfunction or mishap Notes regarding these materials These materials are intended as a reference to assist our customers in the selection of the Renesas Technology product best suited to the customer s application they do not convey any license under any intellectual property rights or any other rights belonging to Renesas Technology Corporation Renesas Solutions Corporation or a third party Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage or infringement of any third party s rights originating in the use of any product data diagrams charts programs algorithms or circuit application exam ples contained in these materials All information contained in these materials including product data diagrams charts programs and algorithms represents information on products at the time of publication of these materials and are subject to change by Renesas Technology Corporation and Rene sas Solutions Corporation without notice due to product improvements or other reasons It is therefore recommended that customers contact Renesas Technology Corporation Renesas Solutions Corporation or an authorized Renesas Technology product distributor for the latest product information before purchasing a product listed herein The information described here may contain tec
247. sued from non task context Example program statement lt lt Example statement in C language include lt itron h gt include lt kernel h gt include kernel id h void task1 void vrst mpl ID mpl1l lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 vrst mpl ID MPL1 204 6 Applications Development Procedure Overview 6 1 Overview Application programs for MR100 should generally be developed following the procedure described below 1 Generating a project When using HEW create a new project using MR100 on HEW 2 Coding the application program Write the application program in code form using C or assembly language If necessary correct the sample star tup program crtOmr a30 and section definition file c sec inc or asm sec inc 3 Creating a configuration file Create a configuration file which has defined in it the task entry address stack size etc by using an editor The GUI configurator available for MR100 may be used to create a configuration file 4 Executing the configurator From the configuration file create system data definition files sys rom inc sys ram inc include files mr100 inc kernel id h 5 System generation Execute the make command or execute build on HEW to generate a system 6 Writing to ROM Using the ROM programming format file created write the finished program file into the ROM Or load it into the deb
248. t ers you can obviate all the above disadvantages while retaining the above mentioned advantages Figure 3 3 shows an example system that will be obtained if the real time OS is incorporated in the system indicated in Figure 3 2 Key input Remote control Task Task real time OS Volume control Monitor Task Task LED illumination Task Mechanical control Task Figure 3 3 Example System Configuration with Real time OS Audio Equipment In other words the real time OS is the software that makes a one microcomputer system look like operating a number of microcomputers In the real time OS the individual programs which correspond to a number of microcomputers used in a conventional sys tem are called tasks 3 1 2 Operating Principles of Kernel A kernel is the core program of real time OS The kernel is the software that makes a one microcomputer system look like operating a number of microcomputers You should be wondering how the kernel makes a one microcomputer system function like a number of microcomputers As shown in Figure 3 4 the kernel runs a number of tasks according to the time division system That is it changes the task to execute at fixed time intervals so that a number of tasks appear to be executed simultaneously Key input Task Remote control Task LED illumination Task Volume control Task Monitor Task Mechanical control Task
249. t lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task void clr flg ID flg FLGPTN Oxf0f0f0f0 lt lt Example statement in assembly language gt gt include mr100 inc GLB task task PUSH W R2 PUSH L Al clr flg HID_FLG1 HOfOfOfOfOH 112 wai flg Wait for eventflag pol flg Wait for eventflag polling ipol flg Wait for eventflag polling handler only twai flg Wait for eventflag with timeout C Language API ER ercd wai_flg ID flgid FLGPTN waiptn MODE wfmode FLGPIN p_flgptn ER ercd pol flg ID flgid FLGPTN waiptn MODE wfmode FLGPIN p flgptn ER ercd ipol flg ID flgid FLGPTN waiptn MODE wfmode FLGPIN p flgptn ER ercd twai flg ID flgid FLGPTN waiptn MODE wfmode FLGPIN p flgptn TMO tmout Parameters ID flgid ID number of the eventflag waited for FLGPTN waiptn Wait bit pattern MODE wfmode Wait mode FLGPTN p flgptn Pointer to the area to which bit pattern is returned when released from wait TMO tmout Timeout value for twai flg Return Parameters ER ercd Terminated normally E OK or error code FLGPTN p flgptn Pointer to the area to which bit pattern is returned when released from wait Assembly language APT include mr100 inc wai flg FLGID WAIPTN WFMODE pol fl1g FLGID WAIPTN WFMODE ipol flg FLGID WAIPTN WFMODE twai flg FLGID
250. t means specifying O as a timeout value in which case the service call operates the same way as prcv mbx Furthermore if specified as tmoutZTMO FEVR 1 it means specifying an infinite wait in which case the service call operates the same way as rcv mbx The task placed into WAITING state by execution of the rcv mbx or trcv_mbx service call is released from WAITING state in the following cases When the rcv mbx trcv mbx prcv mbx or iprcv mbx service call is issued before the tmout time elapses with task awaking conditions thereby satisfied The error code returned in this case is E OK When the first time tick occurred after tmout elapsed while task awaking conditions remain un satisfied The error code returned in this case is E TMOUT When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI If this service call is to be issued from task context use rcv mbx trcv mbx prcv mbx if issued from non task context use iprcv mbx 131 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h typedef struct fifo message T MSG head char body 12 FIFO MSG void task FIFO MSG msg if rcv mbx T MSG amp msg ID mbx E RLWAI error forced wakeup n if prcv mbx T MSG
251. ta type typedef void FP 0 Pointer to a function typedef W INT Signed 32 bit integer typedef UW UINT Unsigned 32 bit integer typedef H ID Object ID number typedef H PRI Priority typedef W TMO Timeout typedef H ER Error code Signed integer typedef UH ATR Object attribute Unsigned integer typedef UH STAT Task status typedef UH MODE Service call operation mode typedef UW SIZE Memory area size typedef UW RELTIM Relative time typedef W VP INT Pointer to an unknown data type or a signed in teger for the processor typedef struct systim System time UH utime Upper16bit of the system time UW ltimer Lower32bit of the system time SYS TIM typedef W ER UINT Error code or unsigned integer 279 12 2Common Constants and Packet Format of Structure Common formats TRUE 1 FALSE 0 True False Formats related to task management TSK_SELF 0 TPRI RUN 0 typedef struct t_rtsk STAT tskstat PRI tskpri PRI tskbpri STAT tskwait ID wid TMO tskatr UINT actent UINT wupcnt UINT suscnt T_RTSK typedef struct t_rtst STAT tskstat STAT tskwait T_RTST Formats related to semaphore typedef struct t_rsem ID wtskid INT semcnt T RSEM Formats related to eventflag wfmod TWF ANDW H 0000 TWF ORW H 0002 typedef struct t rflg ID wtskid UI
252. task dependent synchronization function are listed in below Table 5 3 Specifications of the Task Dependent Synchronization Function No Item Content 1 Maximum value of task wakeup request count 255 2 Maximum number of nested forcible task wait requests count 1 Table 5 4 List of Task Dependent Synchronization Service Call No Service Call Function System State T N E D U 1 slp_tsk S B Puts task to sleep O O O 2 tslp tsk S Puts task to sleep with timeout O O O 3 wup_tsk SI B O O O O 4 iwup tsk SI B O O O O 5 can_wup B O O O O 6 ican_wup 01 0 O O 7 rel wai S B Releases task from waiting O O O O 8 irel_wai S B O O O O 9 sus_tsk S B Suspends task O O O O 10 1sus_tsk O O O O 11 rsm_tsk SI B Wakes up task O O O O 12 irsm tsk O O O O 13 frsm_tsk S Cancels wakeup request O O O O 14 ifrsm_tsk O O O O 15 dly_tsk SI B Delays task O O O Notes e S Standard profile service calls B Basic profile service calls e Each sign within System State is a following meaning T Can be called from task context N Can be called from non task context E Can be called from dispatch enabled state D Can be called from dispatch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 84 slp tsk Put task to sleep tslp tsk Put task to
253. task switching does not occur unlike in the case of a service call from a task However task switching occurs when a return from a handler is made The processing procedures for service calls from handlers are roughly classified into the following three types 1 Aservice call from a handler that caused an interrupt during task execution 2 Aservice call from a handler that caused an interrupt during service call processing 3 A service call from a handler that caused an interrupt multiplex interrupt during handler exe cution 7 The service call can t be issued from non kernel handler Therefore The handler described here does not include the non kernel interrupt handler 16 Service Calls from a Handler That Caused an Interrupt during Task Execution Scheduling task switching is initiated by the ret int service call See Figure 3 11 TaskA Interrupt handler OS Interrupt Save Registers Service call processing iset flg Restore Registers ret int Task selection SP User Scheduler TaskB Restore Registers fil Figure 3 11 Processing Procedure for a Service Call a Handler that caused an interrupt during Task Execution 8 The ret int service call is issued automatically when kernel interrupt handler is written in C language when pragma INTHANDLER speci fied 17 Service Calls from a Handler That Caused an Interrupt during Service Call Processing Scheduling task switching
254. tasks so that all steps from development to debugging can be conducted inde pendently for each task Further the introduction of the real time OS makes it easy to start debugging some already finished tasks even if the entire program is not completed yet Since engineers can be allocated to individual tasks work assignment is easy 3 Software independence is enhanced to provide ease of program debugging As the use of the real time OS makes it possible to divide programs into small independent modules called tasks OS Operating System ME ds the greater part of program debugging can be initiated simply by observing the small modules Timer control is made easier To perform processing at 10 ms intervals the microcomputer timer function was formerly used to periodically in itiate an interrupt However as the number of usable microcomputer timers was limited timer insufficiency was compensated for by for instance using one timer for a number of different processing operations When the real time OS is introduced however it is possible to create programs for performing processing at fixed time intervals making use of the real time OS time management function without paying special attention to the microcomputer timer function At the same time programming can also be done in such a manner as to let the programmer take that numerous timers are provided for the microcomputer Software maintainability is enhanced When the real tim
255. tasks to be executed is delayed until the dispatch disabled state is cleared When dispatch is being delayed Task under execution is in a RUN state and is linked to the ready queue Task to be executed after the dispatch disabled state is cleared is in a READY state and is linked to the highest priority ready queue among the queued tasks 15 isus tsk irsm tsk during dispatch delay In cases when isus tsk is issued from an interrupt handler that has been invoked in a dispatch disabled state to the task under execution a task to which dis dsp was issued to place it in a SUSPEND state During delay dis patching The task under execution is handled inside the OS as having had its delay dispatching cleared For this reason in isus tsk that has been issued to the task under execution the task is removed from the ready queue and placed in a SUSPEND state Error code E OK is returned Then when irsm tsk is issued to the task under execution the task is linked to the ready queue and error code E OK is re turned However tasks are not switched over until delay dispatching is cleared The task to be executed after disabled dispatching is re enabled is linked to the ready queue 16 rot rdq irot rdq during dispatch delay When rot rdq TPRI RUN 0 is issued during dispatch delay the ready queue of the own task s priority is ro tated Also when irot_rdq TPRI RUN 0 is issued the ready queue of the executed task s priority is r
256. tate by specifying a timeout value A timeout can be specified in a service call that places the issuing task into WAITING state This service call includes tslp tsk twai flg twai sem tsnd dtq trcv dtq trcv mbx tget mpf vtsnd dtq and vtrcv_dtq If the wait cancel condition is not met before the specified timeout time elapses the error code E TMOUT is returned and the task is freed from the waiting state If the wait cancel condition is met the error code E OK is returned The timeout time should be specified in ms units tslp_tsk 50 E_TMOUT READY state WAITING state A 50 Timeout value tslp_tsk 50 E OK RUNNING state WAITING state iwup tsk Figure 4 20 Timeout Processing MR100 guarantees that as stipulated in uITRON specification timeout processing is not performed until a time equal to or greater than the specified timeout value elapses More specifically timeout processing is performed with the following timing 1 Tf the timeout value is 0 for only dly_tsk The task times out at the first time tick after the service call is issued 2 Ifthe timeout value is a multiple of time tick interval The timer times out at the timeout value time tick interval first time tick For example if the time tick interval is 10 ms and the specified timeout value is 40 ms then the timer times out at the fifth oc currence of the time tick Similarly if the time tick interval is 5 ms and the specified timeout val
257. tate cc a cai 179 sns_dsp Reference dispatching state cccccccccccseceeeesssececcceceesensessececececeesessseeeeeesesenessesssaeeeeeeseees 180 sns dpn Reference dispatching pending state nennen ennt en nen 181 5 13 Interrupt Management Functi0N ocococonononononononononononononononononononnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnanannnnnnss 182 ret_int Returns from an interrupt handler when written in assembly language 183 5 14 System Configuration Management Functi0N ccccnnnonoooconnnonnnnnananonononnonononnnn nono nononnononnnnonanonconon 184 ref ver Reference version information ccccccsccccesssscecseseceeceesececsesseeeceessesecsesseeecceeseeeeseaeeecneaas 185 iref ver Reference version information handler only seen 185 5 15 Extended Function Short Data QUO ui Ei 187 vend_dtq Send to Short data queue esses enne eet nnne ee eh enter nennen entente nn nooo 188 vpsnd_dtq Send to Short data queue polling seen nen 188 vipsnd dtq Send to Short data queue polling handler only sese 188 vtsnd dtq Send to Short data queue with timeout oonconnnnnnicinonnnncnnnnonanininncnnnnnn cono nononn canon nannacns 188 vfsnd dtq Forced send to Short data Queue cccccssccccccccssssssssscecccecesesesssseceeceecsesessaeeeecesessesensaaeas 188 vifsnd_dtq Forced send to Short data queue handler only
258. tch disabled state U Can be called from CPU unlocked state L Can be called from CPU locked state 127 snd mbx Send to mailbox isnd mbx Send to mailbox handler only C Language API ER ercd snd mbx ID mbxid T MSG pk msg ER ercd isnd mbx ID mbxid T MSG pk msg Parameters ID mbxid ID number of the mailbox to which transmitted T MSG pk msg Message to be transmitted Return Parameters ER ercd Terminated normally E OK Assembly language APT include mr100 inc snd_mbx MBXID PK MBX isnd mbx MBXID PK MBX Parameters MBXID ID number of the mailbox to which transmitted PK MBX Message to be transmitted address Register contents after service call is issued Register name Content after service call is issued RO Error code R2 ID number of the mailbox to which transmitted Al Message to be transmitted address Structure of the message packet lt lt Mailbox message header gt gt typedef struct t msg VP msghead 0 4 Kernel managed area T_MSG lt lt Mailbox message header with priority included gt gt typedef struct t msg T MSG msgque 0 4 Message header PRI msgpri 2 2 Message priority T_MSG Error code None Functional description This service call sends the message indicated by pk_msg to the mailbox indicated by mbxid T_MSG should be specified with a 32 bit address If there is any task waiting to receive a message in the target mail
259. te U Can be called from CPU unlocked state L Can be called from CPU locked state 143 pget mpl Aquire variable size memory block polling C Language APT ER ercd pget mpl ID mplid UINT blksz VP p blk Parameters ID mplid ID number of the target Variable size Memory pool to be acquired UINT blksz Memory size to be acquired in bytes VP p_blk Pointer to the start address of the acquired variable memory Return Parameters ER ercd Terminated normally E_OK or error code VP p_blk Pointer to the start address of the acquired variable memory Assembly language APT include mr100 inc pget mpl MPLID BLKSZ Parameters MPLID ID number of the target Variable size Memory pool to be acquired BLKSZ Memory size to be acquired in bytes Register contents after service call is issued Register name Content after service call is issued RO Error code R3RI Memory size to be acquired R2 ID number of the target Variable size Memory pool to be acquired Error code E TMOUT No memory block 144 Functional description This service call acquires a memory block from the variable size memory pool indicated by mplid and stores the start address of the acquired memory block in the variable p blk The content of the acquired memory block is in determinate If the specified variable size memory pool has no memory blocks in it the task returns immediately and responds to the call with the
260. ted the TA STA attribute is not added TA PHS attribute Definition format Symbol Definition range ON or OFF Default value OFF Specify the TA PHS attribute of the cyclic handler If ON is selected the TA PHS attribute is added if OFF is selected the TA PHS attribute is not added 244 5 Activation phase Definition format Numeric value Definition range 0 to OX7FFFFFFF Default value None Define the activation phase of the cyclic handler The time representing this startup phase must be defined in ms units 6 Start Address Definition format Symbol or Function Name Definition range None Default value None Define the start address of the cyclic handler Note that the function name defined here will have the declaration statement shown below output to the ker nel id h file pragma CYCHANDLER V4 function name 7 Extended information Definition format Numeric value Definition range 0 to OXFFFFFFFF Default value 0 Define the extended information of the cyclic handler This information is passed as argument to the cyclic han dler when it starts Alarm handler definition This definition is necessary to use Alarm handler function lt lt Format gt gt Alarm Handlar Definition alarm hand ID No 1 name ID name entry address Start address exitf Extended information y
261. th task awaking conditions thereby satisfied The error code returned in this case is E OK When the first time tick occurred after tmout elapsed while task awaking conditions remain un satisfied The error code returned in this case is E TMOUT When the task is forcibly released from WAITING state by the rel wai or irel wai service call is sued from another task or a handler The error code returned in this case is E RLWAI When the target data queue being waited for is initialized by the vrst dtq service call issued from another task The error code returned in this case is EV RST For fsnd_dtq and ifsnd dtq the data at the top of the data queue or the oldest data is removed and the transmitted data is stored at the tail of the data queue If the data queue area is not filled with data fsnd dtq and ifsnd dtq operate the same way as snd dtq If dtqcnt 0 there is no task in the wait queue and fsnd dtq or ifsnd dtq service call is issued error code E ILUSE will be returned If this service call is to be issued from task context use snd_dtq tsnd_dtq psnd_dtq fsnd_dtq if issued from non task con text use ipsnd dtq ifsnd dtq 120 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h VP INT data 10 void task void if snd dtq ID dtq data 0 E RLWAI error Forced released n if psnd dtq ID dtg data
262. the priority of the task indicated by tskid to the area indicated by p tskpri If TSK_SELF is speci fied the priority of the issuing task itself is acquired If TSK SELF is specified for tskid in non task context operation of the service call cannot be guaranteed If the task indicated by tskid is in DORMANT state it returns the error code E OBJ as a return value for the service call If this service call is to be issued from task context use get pri if issued from non task context use iget pri Tf Example program statement lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task PRI p tskpri ER ercd ercd get pri ID task2 amp p tskpri lt lt Example statement in assembly language gt gt INCLUDE mr100 inc GLB task task get pri ID_TASK2 78 ref tsk Reference task status iref tsk Reference task status handler only C Language API ER ercd ref tsk ID tskid T RTSK pk rtsk ER ercd iref tsk ID tskid T RTSK pk rtsk Parameters ID tskid ID number of the target task T RTSK pk rtsk Pointer to the packet to which task status is returned Return Parameters ER ercd Terminated normally E OK Contents of pk rtsk typedef struct t rtsk STAT tskstat 0 2 Task status PRI tskpri 2 2 Current priority of task PRI tskbpri 4 2 Base priority of task STAT tskwait 6 2 Cause of wait ID wo
263. the same resource See Figure 4 11 Acquired Returned after use Figure 4 11 Semaphore Counter The MR100 kernel offers the following semaphore synchronization service calls Release Semaphore Resource sig sem isig sem Releases one resource to the semaphore This service call wakes up a task that is waiting for the semaphores ser vice or increments the semaphore counter by 1 if no task is waiting for the semaphores service e Acquire Semaphore Resource wai sem twai sem Waits for the semaphores service If the semaphore counter value is 0 zero the semaphore cannot be acquired Therefore the WAITING state prevails Acquire Semaphore Resource pol sem ipol sem Acquires the semaphore resource If there is no semaphore resource to acquire an error code is returned and the WAITING state does not prevail 43 Reference Semaphore Status ref sem iref sem Refers the status of the target semaphore Checks the count value and existence of the wait task for the target se maphore Figure 4 12 shows example task execution control provided by the wai sem and sig sem service calls wai sem sig sem Task QA wai sem Task e wai sem GN qo c wai sem Task WAIT state 1 E Semaphore 3 2 1 0 H 0 Counter Figure 4 12 Task Execution Control by Semaphore 44 4 1 6 Synchronization and Communication Function Eventflag The eventfl
264. tick denomina tor and numerator that are set here The interval is the time tick numerator divided by time tick denominator ms That is the time tick numerator ms 6 Maximum message priority value Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum value of message priority 230 System Clock Definition Procedure lt lt Format gt gt System Clock Definition clock timer clock MPU clock timer Timers used for system clock IPL System clock interrupt priority level lt lt Content gt gt 1 2 3 MPU clock Definition format Frequency in MHz Definition range None Default value 15MHz Define the MPU operating clock frequency of the microcomputer in MHz units Timers used for system clock Definition format Symbol Definition range AO A1 A2 A3 A4 A5 A6 A7 BO B1 B2 B3 B4 B5 OTHER NOTIMER Default value NOTIMER The frequency of the circumference functional clock supplied to a system timer is defined per MHz With this product f1 or f8 is chosen as count sauce and a value is set as a timer Ai register and a timer Bi register There fore overflow may occur depending on the value of timer clock and the value of tick nume of a system defini tion In this case OTHER must be set as the timer used for a system clock and a system timer must be initia
265. tion be properly maintained among the team members 3 To enhance software production efficiency so as to increase the volume of possible software development per engineer One way to achieve this target would be to educate engineers to raise their level of skill Another way would be to make use of a structured descriptive assembler C compiler or the like with a view toward facilitating program ming It is also possible to enhance debugging efficiency by promoting modular software development However the conventional methods are not adequate for the purpose of solving the problems Under these circumstances it is necessary to introduce a new system named real time OS To answer the above mentioned demand Renesas has developed a real time operating system tradenamed MR100 for use with the R32C 100 series of 32 bit microcomputers When the MR100 is introduced the following advantages are offered 1 Software recycling is facilitated When the real time OS is introduced timing signals are furnished via the real time OS so that programs depend ent on timing can be reused Further as programs are divided into modules called tasks structured programming will be spontaneously provided That is recyclable programs are automatically prepared 2 Ease of team programming is provided When the real time OS is put to use programs are divided into functional modules called tasks Therefore engi neers can be allocated to individual
266. tion file are omitted This file is placed in the directory indicated by environment variable LIB30 or the current directory If this file exists in both directories the file in the current directory is prioritized over the other include template file mr100 inc sys ram inc This file serves as the template file of include file mr100 inc and sys ram inc It resides in the directory in dicated by environment variable LIB 100 e MR100 version file version This file contains description of MR100 s version It resides in the directory indicated by environment variable LIB100 The configurator reads in this file and outputs MR100 s version information to the startup message Service call definition file kernel sysint h This file contains description of MR100 service call definition It resides in the directory indicated by environ ment variable LIB100 The configurator reads in this file and outputs to thecurrent directory When the configurator is executed the files listed below are output Do not define user data in the files output by the configurator Starting up the configurator after entering data definitions may result in the user defined data being lost e System data definition file sys rom inc sys ram inc This file contains definition of system settings Include file mr100 inc This is an include file for the assembly language Service call definition file kernel sysint h This file contains
267. tion to accumulate data The accumulated data is retrieved in order of FIFO However the number of data that can be accumulated in the data queue is limited If data is transmitted to the data queue that is full of data the service call issuing task goes to a data transmission wait state There are following data queue service calls that are provided by the MR100 kernel Send to Data Queue snd dtq tsnd dtq The data is transmitted to the data queue If the data queue is full of data the task goes to a data transmission wait state Send to Data Queue psnd dtq ipsnd dtq The data is transmitted to the data queue If the data queue is full of data the task returns error code without going to a data transmission wait state Forced Send to Data Queue fsnd dtq ifsnd dtq The data is transmitted to the data queue If the data queue is full of data the data at the top of the data queue or the oldest data is removed and the transmitted data is stored at the tail of the data queue Receive from Data Queue rcv dtq trcv_dtq The data is retrieved from the data queue If the data queue has no data in it the task is kept waiting until data is transmitted to the data queue Receive from Data Queue prcv dtq iprcv dtq The data is received from the data queue If the data queue has no data in it the task returns error code without going to a data reception wait state Reference Data Queue Status ref dtq iref dtq Checks to see if there are
268. tor is provided to simplify development proce dures A configurator is furnished so that various items including a ROM write form file can be created by giving simple definitions Therefore there is no particular need to care what libraries must be linked In addition a GUI version of the configurator is available It helps the user to create a configuration file without the need to learn how to write it 3 Introduction to Kernel 3 1 Concept of Real time OS This section explains the basic concept of real time OS 3 1 1 Why Real time OS is Necessary In line with the recent advances in semiconductor technologies the single chip microcomputer ROM capacity has in creased ROM capacity of 32K bytes As such large ROM capacity microcomputers are introduced their program development is not easily carried out by con ventional methods Figure 3 1 shows the relationship between the program size and required development time program development difficulty This figure is nothing more than a schematic diagram However it indicates that the development period increases expo nentially with an increase in program size For example the development of four 8K byte programs is easier than the development of one 32K byte program Development Period 4 8 16 32 Kbyte Program Size Figure 3 1 Relationship between Program Size and Development Period Under these circumstances it is necessary to adopt a method by which large size
269. tween the task content and non task context are shown in Table 3 1 Task Context and Non task Context Table 3 1 Task Context and Non task Context Task context Non task context Invocable service call Those that can be invoked from Those that can be invoked from task context non task context Task scheduling Occurs when the queue state has It does not occur changed to other than dispatch dis abled and CPU locked states Stack User stack System stack The processes executed in non task context include the following 1 Interrupt Handler A program that starts upon hardware interruption is called the interrupt handler The MR100 is not concerned in interrupt handler activation Therefore the interrupt handler entry address is to be directly written into the interrupt vector table There are two interrupt handlers Non kernel interrupts OS independent interrupts and kernel interrupts OS dependent interrupts For details about each type of interrupt refer to Section 3 6 The system clock interrupt handler isig tim is one of these interrupt handlers 2 Cyclic Handler The cyclic handler is a program that is started cyclically every preset time The set cyclic handler may be started or stopped by the sta cyc ista cyc or stp cyc istp cyc service call The cyclic handler startup time of day is unaffected by a change in the time of day by set tim iset tim 3 Alarm Handler The alarm handler is a h
270. uage 7 1 1 Task Description Procedure 1 Describe the task as a function To register the task for the MR100 enter its function name in the configuration file When for instance the function name task is to be registered as the task ID number 3 proceed as follows task 3 name ID task entry address task stack size 100 priority 3 13 2 Atthe beginning of file be sure to include itron h kernel h which is in system directory as well as kernel id h which is in the current directory That is be sure to enter the fol lowing two lines at the beginning of file include lt itron h gt include lt kernel h gt include kernel id h 3 No return value is provided for the task start function Therefore declare the task start function as a void function A function that is declared to be static cannot be registered as a task It isn t necessary to describe ext tsk at the exit of task start function If you exit the task from the subroutine in task start function please describe ext tsk in the subroutine 6 Itis also possible to describe the task startup function using the infinite loop include lt itron h gt include kernel h include kernel id h void task void process Figure 7 1 Example Infinite Loop Task Described in C Language The task is ended by ext tsk automatically if pramga TASK is declared in the MR100 Similarly it is ended by ext tsk when returned
271. ue is 15 ms then the timer times out at the fourth occurrence of the time tick get tim service call Set tim service call 8 SUSPENDED state is not included Strictly in a dly tsk service call the timeout value is not correct delay time is correct Strictly in a dly tsk service call a timeout is not carried out but the waiting for delay is canceled and the service call carries out the nor mal end 54 3 If the timeout value is not a multiple of time tick interval The timer times out at the timeout value time tick interval second time tick For example if the time tick interval is 10 ms and the specified timeout value is 35 ms then the timer times out at the fifth oc currence of the time tick Set System Time set tim Reference System Time get tim The system time indicates an elapsed time from when the system was reset by using 48 bit data The time is ex pressed in ms units 55 4 1 12 Cyclic Handler Function The cyclic handler is a time event handler that is started every startup cycle after a specified startup phase has elapsed The cyclic handler may be started with or without saving the startup phase In the former case the cyclic handler is started relative to the point in time at which it was generated In the latter case the cyclic handler is started relative to the point in time at which it started operating Figure 4 21 and Figure 4 22 show typical operations of the cyclic handler If th
272. ugger to debug Figure 6 1 shows a detailed flow of system generation i It is abbreviation of High performance Embedded Workshop The make command comes the UNIX standard and UNIX compatible 205 Configuration file C standard MR100 include file header file kernel h Configurator cfg100 Include file kernel id h Application Include file System data definition file include file mr100 inc Sys ram inc sys rom inc Application Assembler source Application Startup program C source start a30 crtOmr a30 Jamp table file y A mrtable a30 Relocatable Assembler as100 Create Jamp table utility mr100tbl Systemcall file mrc C compiler nc100 MR100 4 Library C standard Library Application object y Linkage Editor 1n100 Absolute module y Load module converter Imc100 ROM write format Figure 6 1 MR100 System Generation Detail Flowchart 206 6 2 Development Procedure Example This chapter outlines the development procedures on the basis of a typical MR100 application example 6 2 1 Applications Program Coding Figure 6 2 shows a program that simulates laser beam printer operations Let us assume that the file describing the laser beam printer simulation program is named Ibp c This program consists of the following three tasks and one interrupt han dler Main
273. um number of tasks defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of tasks defined 2 The maximum number of eventflags defined Definition format Numeric value Definition range 1 to 255 Default value None 3 The maximum number of data queues defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of data queues defined 4 The maximum number of mailboxes defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of mailboxes defined 232 5 The maximum number of semaphores defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of semaphores defined 6 The maximum number of fixed size memory pools defined Definition format Numeric value Definition range 1 to 255 Default value None 7 The maximum number of variable length memory blocks defined Definition format Numeric value Definition range 1 to 255 Default value None Define the maximum number of variable length memory blocks defined 8 The maximum number of cyclic activation handlers defined Definition format Numeric value Definition range 1 to 255 Default value None The maximu
274. umbers 63 through 48 and be sure to use some other numbers Table 11 1 Interrupt Number Assignment Interrupt No Service calls Used 249 Service calls that can be issued from only task context 250 Service calls that can be issued from only non task context Service calls that can be issued from both task context and non task context 251 ret int service call 252 dis dsp service call 253 loc cpu iloc cpu service call 254 ext tsk service call 255 Reserved for future extension 11 2The Use of registers of bank The registers of bank is 0 when a task starts on MR100 MR100 does not change the registers of bank in processing kernel You must pay attention to the followings Don t change the regisers of bank in processing a task e If an interrupt handler with regisers of bank 1 have multiple interrupts of an interrupt handler with regis ers of bank 1 the program can not execute normally 275 11 3Regarding Delay Dispatching MR100 has four service calls related to delay dispatching e dis dsp e ena_dsp e loc cpu e unl cpu The following describes task handling when dispatch is temporarily delayed by using these service calls 14 When the execution task in delay dispatching should be preempted While dispatch is disabled even under conditions where the task under execution should be preempted no time is dispatched to new tasks that are in an executable state Dispatching to the
275. under execution is placed into a forcible wait state by the isus tsk service call from the handler the task goes from an execut ing state directly to a forcible wait state Please note that in only this case exceptionally it is possible that a task will go from an executing state directly to a forcible wait state 23 tasks in the RUNNING READY or WAITING state If the suspend request is made to a task in the SUS PENDED state an error code is returned 5 WAITING SUSPENDED If a suspend request is issued to a task currently in a WAITING state the task goes to a WAITING SUSPENDED state If a suspend request is issued to a task that has been placed into a WAITING state for a wait request by the slp_tsk wai flg wai sem rcv mbx snd dtq rcv dtq vsnd dtq vrcv_dtq get mpf tslp tsk twai flg twai sem trcv mbx tsnd dtq trcv dtq vtsnd dtq vtrcv dtq or tget mpf service call the task goes to a WAIT ING SUSPENDED state When the wait condition for a task in the WAITING SUSPENDED state is cleared that task goes into the SUS PENDED state It is conceivable that the wait condition may be cleared when any of the following conditions occurs The task wakes up upon wup tsk or iwup tsk service call issuance The task placed in the WAITING state by the dly tsk or tslp tsk service call wakes up after the specified time elapse The request of the task placed in the WAITING state by the wai flg wai sem rcv mbx snd dtq rc
276. uration Management Functions Parameter ReturnParameter ServiceCall INTNo FuncCode AO Al RO ref_ver 250 160 pk_rver ercd iref_ver 250 160 pk_rver ercd Extenden Function Reset Function Parameter ReturnParameter ServiceCall INTNo ates R2 RO vrst vdtq 249 192 vdtqid ercd vrst dtq 249 184 dtqid ercd vrst mbx 250 186 mbxid ercd vrst mpf 249 188 mpfid ercd vrst mpl 250 190 mplid ercd vrst mbf 249 218 mbfid ercd Extenden Function Short Data Queue Function Parameter ReturnParameter ServiceCall INTNo mm E i ED R6BA i RO RI vsnd_dtq 249 162 data vdtqid E ercd vpsnd dtq 249 164 data vdtqid ercd vipsnd_dtq 250 166 data vdtgid E ercd vfsnd dtq 249 170 data vdtgid E ercd vifsnd dtq 250 172 data vdtqid B ercd vtsnd dtq 249 228 data vdtqid tmout ercd vrev_dtq 249 174 vdtqid z ercd data vprcv dtq 249 176 vdtqid y ercd data viprev_dtq 250 178 vdtqid E ercd data vtrev_dtq 249 180 vdtqid tmout ercd data vref dtq 250 182 vdtqid pk_rdtq ercd viref_dtq 250 182 vdtqid pk_rdtq ercd 287 288 Real time OS for R32C 100 Series M3T MR100 4 User s Manual Publication Date September 16 2007 Rev 1 00 Sales Strategic Planning Div Published by Renesas Technology Corp Applicatio
277. urned If the task is kept waiting perpetually TMO FEVR is re turned Otherwise lefttmo is indeterminate actcnt task activation request The number of currently queued task activation request is returned wupcnt wakeup request count The number of currently queued wakeup requests is returned If the task is in DORMANT state wupcnt is indeterminate suscnt suspension request count The number of currently nested suspension requests is returned If the task is in DORMANT state suscnt is indeterminate If this service call is to be issued from task context use ref tsk if issued from non task context use iref tsk 3 TTW_VSDTQ and TTW_VRDTQ are the causes of wait outside the scope of ITRON 4 0 Specification 80 Example program statement 1 lt lt Example statement in C language gt gt include lt itron h gt include lt kernel h gt include kernel id h void task T RTSK rtsk ER ercd ercd ref tsk ID main amp rtsk lt lt Example statement in assembly language gt gt refdata blkb 26 include mr100 inc GLB task task PUSH W R2 PUSH L Al ref _ tsk HTSK SELF refdata 81 ref tst Reference task status simplified version iref tst Reference task status simplified version handler only C Language API ER ercd ref tst ID tskid T RTST pk rtst ER ercd iref tst ID tskid T RTST pk rtst Parameters ID tskid ID number of the target task T
278. utomatically called at completion of the handler function In this case therefore there is no need to invoke this service call Figure 4 25 shows an interrupt processing flow Processing a series of operations from task selection to register restoration is called a scheduler TaskA NN Interrupt Save Registers Handler Processing pragma INTHANDLER Declare C language Task Selection Figure 4 25 Interrupt process flow TaskB 31 n the case that the interruput handler is specified by pragma INTHANDLER 59 4 1 16 System Configuration Management Function This function inspects the version information of MR100 4 1 17 References Version Information ref ver iref ver The ref ver service call permits the user to get the version information of MR100 This version information can be obtained in the standardized format of uITRON specification Extended Function Short Data Queue The short data queue is a function outside the scope of uITRON 4 0 Specification The data queue function handles data as consisting of 32 bits whereas the short data queue handles data as consisting of 16 bits Both behave the same way except only that the data sizes they handle are different Send to Short Data Queue vsnd dtq vtsnd dtq The data is transmitted to the short data queue If the short data queue is full of data the task goes to a data trans mission wait state Send to Short Data Queue v
279. v dtq vsnd dtq vrcv dtq get mpf tslp tsk twai flg twai sem trcv mbx tsnd dtq trcv dtq vtsnd dtq vtrcv dtq or tget mpf service call is fulfilled The WAITING state is forcibly cleared by the rel wai or irel wai service call When the SUSPENDED state clear request by rsm tsk or irsm tsk is made to a task in the WAIT ING SUSPENDED state that task goes into the WAITING state Since a task in the SUSPENDED state cannot request to be placed in the WAITING state status change from SUSPENDED to WAITING SUSPENDED does not possibly occur 6 DORMANT This state refers to the condition in which a task is registered in the MR100 system but not activated This task state prevails when either of the following two conditions occurs The task is waiting to be activated The task is normally terminated by ext tsk service call or forcibly terminated by ter tsk service call 1 f a forcible wait request is issued to a task currently in a wait state the task goes to a WAITING SUSPENDED state 24 3 4 2 Task Priority and Ready Queue In the kernel several tasks may simultaneously request to be executed In such a case it is necessary to determine which task the system should execute first To properly handle this kind of situation the system organizes the tasks into proper execution priority and starts execution with a task having the highest priority To complete task execution quickly tasks related to processing operations that
280. y 1 Priority 5 BgE Figure 3 19 Waiting queue of the TA TFIFO attribute 26 3 4 4 Task Control Block TCB The task control block TCB refers to the data block that the real time OS uses for individual task status priority and oth er control purposes The MR100 manages the following task information as the task control block Task connection pointer Task connection pointer used for ready queue formation or other purposes Task status Task priority Task register information and other data storage stack area pointer current SP value Wake up counter Task wake up request storage area Flag wait mode This is a wait mode during eventflag wait Flag wait pattern This area stores the flag wait pattern when using the eventflag wait service call wai_flg twai_flg No flag wait pattern area is allocated when the eventflag is not used Startup request counter This is the area in which task startup requests are accumulated The task control block is schematized in Figure 3 20 TCB TCB TCB Priority SP Wake up counter Flag wait mode Activation counter This area is allocated only when Flag wait pattern the timeout function is used Figure 3 20 Task control block 15 Called the task context 2T 3 5 System States 3 5 1 Task Context and Non task Context The system runs in either context state task context or non task context The differences be
281. ys TIME H Sys time ENDIF MOV L 0 HEAP TMR A A E IA loce ecc I6 User Initial Routine if there are noH Initialize standard I O GLB init JSR A init TERE A A E Initalization of System Data Area A A MES AI A AR eee ante SNe Ls GLB _ init heap JSR W init sys JSR W init tsk JSR W init heap IF NUM FLG GLB _ init flg JSR W init flg ENDIF IF NUM SEM GLB init sem 220 set timer mode set interval count set timer IPL system timer start 155 JSR W init sem 156 ENDIF 157 158 IF NUM DTQ 159 GLB init dtq 160 JSR W init dtq 161 ENDIF 162 163 SLE NUM VDTQ P Al 164 GLB _ init vdtq 165 JSR W init vdtq 166 ENDIF 167 168 IF _ NUM MBX 169 GLB init mbx 170 JSR W init mbx 171 ENDIF 172 173 LE ALARM HANDLER 174 GLB init alh 175 JSR W init alh 176 ENDIF 177 178 IF CYCLIC HANDLER 179 GLB init cyh 180 JSR W init cyh 181 ENDIF 182 183 IF NUM MPF P Al 184 Fixed Memory Pool 185 GLB _ init mpf 186 JSR W init mpf 187 ENDIF 188 189 LE NUM MPL P Al 190 Variable Memory Pool 191 GLB init mpl 192 JSR W init mpl 193 ENDIF 194 195 196 For PD100 197 _ LAST INITIAL 198 199 END INIT 200 20T ARIAS A SO SS A SRA 202 Start initial active task 203 phe Soe O ee A Pee AO eS aS T em ep aes 204 START TASK 205 206 GLB rdyq search 207 JMP W rdyq search 208 20955 ecco cose

Download Pdf Manuals

image

Related Search

Related Contents

ATL User Manual - first version  Operating Instructions perma PRO C 250 / 500    system menu - Instructions Manuals  

Copyright © All rights reserved.
Failed to retrieve file