Part Number Hot Search : 
KP100A AM7996 STRRP MM3S0530 XT971A XT971A A4336 SEL1210R
Product Description
Full Text Search
 

To Download RX78K4 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  document no. u10603ej3v0um00 (3rd edition) date published january 1997 n printed in japan 1994 78k/iv series real-time os rx78k/iv fundamental
tron is an abbreviation of the realtime operating system nucleus. itron is an abbreviation of industrial tron. ms-dos is a trademark of microsoft corporation. ibm-pc/at is a trademark of ibm corporation. the other company names and product names appearing in this document are the trademarks of the respective companies. the information in this document is subject to change without notice. no part of this document may be copied or reproduced in any form or by any means without the prior written consent of nec corporation. nec corporation assumes no responsibility for any errors which may appear in this document. nec corporation does not assume any liability for infringement of patents, copyrights or other intellectual property rights of third parties by or arising from use of a device described herein or any other liability arising from use of such device. no license, either express, implied or otherwise, is granted under any patents, copyrights or other intellectual property rights of nec corporation or of others. m7a 96. 10
regional information some information contained in this document may vary from country to country. before using any nec product in your application, piease contact the nec office in your country to obtain a list of authorized representatives and distributors. they will verify: device availability ordering information product release schedule availability of related technical literature development environment specifications (for example, specifications for third-party tools and components, host computers, power plugs, ac supply voltages, and so forth) network requirements in addition, trademarks, registered trademarks, export restrictions, and other legal issues may also vary from country to country. nec electronics inc. (u.s.) santa clara, california tel: 800-366-9782 fax: 800-729-9288 nec electronics (germany) gmbh duesseldorf, germany tel: 0211-65 03 02 fax: 0211-65 03 490 nec electronics (uk) ltd. milton keynes, uk tel: 01908-691-133 fax: 01908-670-290 nec electronics italiana s.r.1. milano, italy tel: 02-66 75 41 fax: 02-66 75 42 99 nec electronics (germany) gmbh benelux office eindhoven, the netherlands tel: 040-2445845 fax: 040-2444580 nec electronics (france) s.a. velizy-villacoublay, france tel: 01-30-67 58 00 fax: 01-30-67 58 99 nec electronics (france) s.a. spain office madrid, spain tel: 01-504-2787 fax: 01-504-2860 nec electronics (germany) gmbh scandinavia office taeby, sweden tel: 08-63 80 820 fax: 08-63 80 388 nec electronics hong kong ltd. hong kong tel: 2886-9318 fax: 2886-9022/9044 nec electronics hong kong ltd. seoul branch seoul, korea tel: 02-528-0303 fax: 02-528-4411 nec electronics singapore pte. ltd. united square, singapore 1130 tel: 253-8311 fax: 250-3583 nec electronics taiwan ltd. taipei, taiwan tel: 02-719-2377 fax: 02-719-5951 nec do brasil s.a. sao paulo-sp, brasil tel: 011-889-1680 fax: 011-889-1689 j96. 8
introduction thank you for buying necs 78k/iv series real-time os rx78k/iv, which is embedded software for the 78k/iv series. this manual is intended to introduce to the user the general idea of 78k/iv series real-time os rx78k/iv. [readers] it is assumed that the readers of this manual have already read the users manual of the device and has experience in software programming. note that this package only contains the real-time os. to use the real-time os actually, the cc78k4 series c-compiler and ra78k4 series assembler package are necessary. [organization] this manual is organized as follows: chapter 1 general describes general descriptions and execution environment of this real-time os. chapter 2 basic functions of rx78k/iv describes the basic functions of the real-time os. chapter 3 rx78k/iv basic operations and control blocks describes the operation and control block of the real-time os. chapter 4 rx78k/iv system call list describes system calls supplied by the real-time os. chapter 5 rx78k/iv reset operation describes the operation to initialize this real-time os. appendix 1 error code list and task status list describes the return parameters of the system calls and task status. appendix 2 description in c language describes the functions supported by c compiler cc78k4. appendix 3 system call list lists the system calls supported by this real-time os. appendix 4 example of cyclic handler coding shows examples of describing cyclic handlers. appendixes 5 and 6 estimating memory capacity describes how to estimate the memory capacity used by this real-time os, taking examples. appendix 7 standby function describes the method to implement the standby function supplied by the 78k/iv by using this real-time os. appendix 8 maximum stack size used by each system call indicates the stack capacity used when issuing each system call. appendix 9 restrictions of symbol names explains the symbol names used by this real-time os.
[legend] the following symbols are used throughout this manual: : repeat [ ] : can be omitted : character string : character string ( ) : character bold : character as is _ : important point. underlined characters in application example must be input as is. d : one or more blank : : omission of program description / : delimiter \ : back slash [related documents] the following table lists the documents (users manuals) related to this manual. document name document no. 78k/iv series real-time os rx78k/iv -install u10604ej3v0um00 78k/iv series real-time os rx78k/iv -debugger u10364ej1v0um00 ra78k4 assembler package -language u10334ej1v0um00 ra78k4 assembler package -operation u11162ej1v0um00 cc78k4 c compiler -language ? cc78k4 c compiler -operation ? 78k/iv series -instruction eeu-1386
- i - contents chapter 1 general .......................................................................................................... ............. 1 1.1 multi-task os ............................................................................................................... ............................. 1 1.2 rx78k/iv .................................................................................................................... ............................... 1 1.3 outline and features of rx78k/iv ............................................................................................ .............. 2 1.4 configuration and size of rx78k/iv.......................................................................................... ............. 3 1.5 memory confuguration of rx78k/iv ............................................................................................ .......... 4 chapter 2 basic functions of rx78k/iv ............................................................................. 7 2.1 task state .................................................................................................................. ............................... 8 2.1.1 task state transition ..................................................................................................... ................... 9 2.2 task manipulation........................................................................................................... ......................... 11 2.3 synchronization and communication........................................................................................... ......... 12 2.3.1 event flag ................................................................................................................ ........................ 13 2.3.2 semaphore................................................................................................................. ..................... 14 2.3.3 mail box .................................................................................................................. ......................... 15 2.4 interrupt management ........................................................................................................ ..................... 16 2.5 memory management ........................................................................................................... ................... 18 2.6 time management............................................................................................................. ....................... 19 chapter 3 rx78k/iv basic operations and control blocks................................... 21 3.1 rx78k/iv configuration...................................................................................................... ..................... 22 3.1.1 flow of overall processing................................................................................................ ............... 22 3.1.2 configuration of ready queue and dispatching.............................................................................. .. 24 3.2 rx78k/iv control block...................................................................................................... ..................... 25 3.2.1 control block memory area ................................................................................................. ............ 25 3.2.2 control blocks............................................................................................................ ...................... 26 chapter 4 rx78k/iv system call list .................................................................................. 27 4.1 system calls related to task ................................................................................................ ................. 30 4.1.1 sta_tsk (start task) ...................................................................................................... ................... 31 4.1.2 ext_tsk (exit task)....................................................................................................... .................... 32 4.1.3 ter_tsk (terminate task) .................................................................................................. ............... 33 4.1.4 chg_pri (change task priority) ichg_pri (change task priority for interrupt) .................................................................................. .34 4.1.5 rot_rdq (rotate ready queue) irot_rdq (rotate ready queue for interrupt).................................................................................... 35 4.1.6 tsk_sts (get task status) ................................................................................................. ............... 36 4.1.7 slp_tsk (sleep task)...................................................................................................... .................. 37 4.1.8 wai_tsk (wait for wakeup task)............................................................................................ .......... 38 4.1.9 wup_tsk (wakeup task) iwup_tsk (wakeup task for interrupt) ........................................................................................... .. 39 4.1.10 can_wup (cancel wakeup task)............................................................................................. ...... 40
- ii - 4.2 synchronization and communication ........................................................................................... ......... 41 4.2.1 set_flg (set eventflag) iset_flg (set eventflag for interrupt)......................................................................................... ........ 42 4.2.2 clr_flg (clear eventflag) ................................................................................................. .................. 43 4.2.3 wai_flg (wait eventflag).................................................................................................. ................. 44 4.2.4 cwai_flg (wait and clear eventflag) ....................................................................................... ......... 45 4.2.5 pol_flg (poll eventflag).................................................................................................. ................... 46 4.2.6 cpol_flg (poll and clear eventflag) ....................................................................................... ........... 47 4.2.7 sig_sem (signal semaphore) isig_sem (signal semaphore for interrupt) ...................................................................................... 48 4.2.8 wai_sem (wait on semaphore) ............................................................................................... ........ 49 4.2.9 preq_sem (poll and request semaphore) ..................................................................................... .50 4.2.10 snd_msg (send message to mailbox) isnd_msg (send message to mailbox for interrupt) ....................................................................... 51 4.2.11 rcv_msg (receive message from mailbox) ................................................................................... .53 4.2.12 prcv_msg (poll and receive message from mailbox) .................................................................... 54 4.3 memory management........................................................................................................... .................... 55 4.3.1 pget_blk (poll and get fixed-length memory block) ...................................................................... 56 4.3.2 rel_blk (release fixed-length memory block)............................................................................... .57 4.4 interrupt processing ........................................................................................................ ........................ 58 4.4.1 ret_int (return from interrupt handler) ................................................................................... ......... 59 4.4.2 ret_wup (return and wakeup task).......................................................................................... ...... 60 4.5 version management .......................................................................................................... ..................... 62 4.5.1 get_ver (get version no.)................................................................................................. ............... 63 4.6 time management ............................................................................................................. ....................... 64 4.6.1 act_cyc (activate cyclic handler) iact_cyc (activate cyclic handler for interrupt)............................................................................... .65 chapter 5 rx78k/iv reset operation ................................................................................... 67 5.1 hardware used ............................................................................................................... .......................... 68 appendix 1 error code list and task status list...................................................... 69 appendix 2 description in c language .............................................................................. 71 appendix 3 system call list.............................................................................................. ...... 73 appendix 4 example of cyclic handler coding ............................................................ 75 appendix 5 estimating memory capacity (large model) ........................................... 77 appendix 6 estimating memory capacity (small model) ........................................... 79 appendix 7 standby function............................................................................................... ... 81 appendix 8 maximum stack size used by each system call .................................. 83 appendix 9 restrictions on symbol names ..................................................................... 85
- iii - list of figures figure no. title page 1-1 memory structure example (large model)...................................................................................... .............. 5 1-2 memory structure example (small model) ...................................................................................... .............. 5 2-1 rx78k/iv task state transition.............................................................................................. ...................... 10 2-2 example of ret_int ........................................................................................................ ............................... 16 2-3 example of ret_int ........................................................................................................ ............................... 17 2-4 memory pool configuration ................................................................................................... ........................ 18 3-1 stack state in dispatching .................................................................................................. .......................... 22 3-2 flow of overall processing.................................................................................................. .......................... 23 3-3 ready queue configuration ................................................................................................... ....................... 24 3-4 example of parameters ....................................................................................................... .......................... 25 4-1 entry address storage table ................................................................................................. ....................... 29 4-2 stack status when ret_int and ret_wup are called ............................................................................ .......... 61 5-1 reset routine branch program for system initialization (large model) ....................................................... 6 7 list of tables table no. title page 5-1 timer of each cpu........................................................................................................... ............................. 68
- iv - [memo]
1 chapter 1 general systems in the field of control equipment are required to respond immediately to changes in external and internal events. the conventional systems have tried to satisfy this requirement by using simple interrupt programs. as the application systems have increasingly become high-performance and sophisticated, however, many problems that cannot be solved only by simple interrupt programs have arisen. in other words, as systems have increasingly become complicated and as the quantity of the programs to be executed has increased, it has been difficult to manage the execution sequence ofthe programs. the real-time operating system (hereafter referred to as the real-time os) was developed to cope with this problem. the real-time os immediately respond to changes in an event and executes the optimum programs in the optimum sequence. 1.1 multi-task os the minimum unit that is executed under the management of the real-time os is called a task. multi-tasking is executing two or more tasks simultaneously on one cpu. actually, however, the cpu can only execute one program at a time. if two or more tasks are selected and executed alternately, for example, at fixed time intervals, however, it seems to the human eye as if these tasks are being executed at the same time. the tasks are executed by taking advantage of opportunities such as time intervals. an os that has a function to execute tasks in parallel by selecting a task at specific opportunities is called a multi-task os. a multi-task os is intended to improve the overall processing ability of the system processing tasks in parallel. 1.2 rx78k/iv the rx78k/iv is a real-time os for embedded control applications and has been developed to supply an efficient real-time/multi-task processing environment and to expand the application range of a targeted cpu in the control equipment field, providing complete real-time/multi-task functions. because it is assumed that the rx78k/iv is embedded in the target system, it has been designed as a compact, high execution speed os, for implementation in rom.
chapter 1 general 2 1.3 outline and features of rx78k/iv (1) conforms to m m itron ver.2.01 the system calls of the rx78k/iv conform to the m itron specifications which are the specifications for a real- time os for embedded control applications. (2) real-time/multi-task processing functions many functions are provided to realize complete real-time/multi-task processing. ? event-driven priority scheduling ? three types of synchronization/communication functions ? memory management function ? interrupt management function ? time management function (3) designed for romization because the rx78k/iv is an operating system intended for embedded control application, it is designed to be compact. system calls not used can be deleted when configuring a system. (4) convenient utilities for system configuration two utilities useful for configuring system are provided. ? configurator ? high-level language interface (5) rx78k/iv supports the following cross tools for 78k/iv series. ? ra78k4 ? cc78k4 (6) two types of memory models supported the rx78k/iv supports the memory models supported by the cc78k4 as follows: ? large model (1m-byte space) : supports location 0fh ? small model (64k-byte space) : supports location 00h
chapter 1 general 3 1.4 configuration and size of rx78k/iv the rx78k/iv consists of the following three subsystems. (1) nucleus this is the central part of the rx78k/iv. it is embedded in the target system along with the application program and actually carries out real-time/multi-task control. it also performs processing in response to system calls issued from processing tasks. the size of the nucleus differs depending on the system calls to be linked. in the case of the large model, it is about 7k bytes max.; in the case of the small model, it is about 5k bytes max. (2) c language interface library when the user program is described in c language, system calls are called in the format of c language calling functions. this format, however, differs from the input format the nucleus can understand. the c language interface library is a program that converts system calls written in c into an input format the nucleus can understand and links the processing tasks described in c with the nucleus. the c language interface library is described so that it can be used with the necs 78k/iv series c compiler cc78k4. (3) configurator this is a tool for creating tables with information on the user system necessary for the nucleus. the configurator runs on the development machine and can be used to input and correct the information on the user system necessary for the os in interactive mode.
chapter 1 general 4 1.5 memory confuguration of rx78k/iv the memory of the system using rx78k/iv consists of the following: (1) nucleus (2) reset routine for system initialization (3) system call entry address storage table (4) os management area note (5) initialization information table (6) object management control block note (7) user program [large model] (1), (2), and (3) above are stored in the internal rom or external memory space at addresses 0h through 0ffffh. because (1), (2), and (3) are relocatable objects, they can located in any area of memory in the above range. (4), (5), and (6) are information tables that are referenced by the reset routine when it initializes the system (these tables are created by the configurator). the user can locate these tables in any area. note : the area in which (4) and (6) can be located is within 64k bytes with the most significant byte fixed. the area is allocated starting from the address specified by the user. [small model] (1), (2), and (3) above are stored in the internal rom or external memory space at addresses 0h through 0ffffh. because (1), (2), and (3) are relocatable objects, they can located in any area of memory in the above range. (4), (5), and (6) are information tables that are referenced by the reset routine when it initializes the system (these tables are created by the configurator). locate (4) and (6) within an 256-byte area at addresses 0f700h through 0f7ffh in the internal ram area. for the memory map, refer to the users manual of the cpu you are using. an example of memory configuration when the rx78k/iv is embedded with the m pd784026 is shown below.
chapter 1 general 5 fig. 1-1 memory structure example (large model) ?object management block ?os management table ?nucleus ?system initialization information table ?system call entry address storage table ?user program (task & interrupt handler) fffffh fff00h ff700h 10000h 00000h sfr internal ram external memory internal rom (64kb) fig.1-2 memory structure example (small model) ?object management block ?os management table ?nucleus ?system initialization information table ?system call entry address storage table ?user program (task & interrupt handler) 0ffffh 0ff00h 0f700h 00000h sfr internal ram internal rom 0f7ffh
6 [memo]
7 chapter 2 basic functions of rx78k/iv because rx78k/iv is a multi-task os, it can process two or more tasks concurrently. 78k/iv series microcomputer has 8 register banks. with rx78k/iv, bank 0 of these register banks is used by the os. tanks can be allocated to registers for high-speed task switching. (for details, refer to 3.1 rx78k/iv configuration) there are 16 levels of task priorities (0 to 15), with the lowest number assigned the highest priority level. however, priority 0 and priority 1 are reserved for os. therefore, priorities to which user tasks can be allocated are limited to the 14 levels of 2 to 15. this chapter describes the following items of the basic functions: (1) task state (2) task manipulation (3) synchronization and communication (4) interrupt processing (5) memory management (6) time management
chapter 2 basic functions of rx78k/iv 8 2.1 task state a task can be in any of the following 4 states: (1) run state in this state, the task is given the privilege to use the cpu and is under execution. only one task in the run state can exist in the system at a given point of time. (2) ready state a task in the state is ready for execution. all the elements to place the task in the run state are ready, but the task in the ready state cannot be executed because a task having the higher priority is currently under execution. (3) wait state a task is placed in this state because it has issued a system call to request a resource. a task in this state can be an event flag waiting for an event, a semaphore waiting for a resource, a mail box waiting for a message, or waiting for time. (4) dormant state when resetting rx78k/iv, tasks other than the initial one are in a dormant state. when a task is terminated, it enters the pause state.
chapter 2 basic functions of rx78k/iv 9 2.1.1 task state transition fig. 2-1 illustrates state transition of a task. each state transition has the following meaning, and system calls that places a task in one state from another are available. (1) starting a task is started when it is placed in the ready state from the dormant state by a system call. (2) terminating a task is terminated when it is placed in the dormant state from the run state by a system call. (3) dispatch dispatching is to select a ready task to be placed in the run state. the task that will be placed in the run state has the highest priority of the tasks in the ready state. dispatching is also called scheduling, and the block that executes dispatching or scheduling is called a dispatcher or scheduler. there are 14 levels of task priorities (2 to 15), with the lowest number assigned the highest priority. others include priorities 0 and 1. however, these cannot be specified for tasks because they are reserved for os. (4) preempt when a task having a higher priority than that of the task currently executed is placed in the run state, the currently executed task is once returned to the ready state. the task placed in the ready state from the run state cannot return to the run state, unless selected by the dispatcher again. (5) wait condition if there is a necessity to wait for occurrence of an event, a task enters the wait state from the run state. a task enters the wait state because the task has requested a resource while it was waiting for an event flag to be set but the requested reception has not been found, the task has requested reception of a message but the message has not arrived, the task has requested to wait for a fixed time period, but the period has not yet elapsed, etc. (6) wait release when a task is released from the wait state, it is placed in the ready state. in this case, an event is an occurrence that cancels the factor causing the wait state by the system. (7) forced termination a task is forcibly terminated when it is placed in the dormant state from a state other than the run state by a system call.
chapter 2 basic functions of rx78k/iv 10 fig. 2-1 rx78k/iv task state transition dispatch preempt ready run wait dormant forced termination normal termination start forced termination wait release wait conditon
chapter 2 basic functions of rx78k/iv 11 2.2 task manipulation rx78k/iv allows the following manipulation of tasks: (1) starting task all the tasks created when the system is started are placed in the dormant state. a task in the dormant state cannot be dispatched until it is started. therefore, it must be placed in the ready state by issuing system call sta_tsk. (2) terminating task a task can be terminated by system call ext_tsk (normal termination) or ter_tsk (forced termination). * interrupts are enabled when a task has been started for the first time. disable interrupts for each task.
chapter 2 basic functions of rx78k/iv 12 2.3 synchronization and communication a task is executed under its own environments as an independent program. to execute two or more independent tasks in parallel and thereby to organize one system, it is necessary to control execution flow of the tasks, manage the resources shared by the tasks, and transfer information among tasks. synchronization and communication are to implement these functions. synchronization is performed in two modes: wait and mutual exclusion. the wait mode is used, when two tasks play the respective roles of work, to stop the work of one task until the other task has completed its work. in this case, the two tasks have a cooperative relationship. the mutual exclusion mode is used, when two tasks are using a common resource, to prevent one task from using the resource while the other task is using it. in this case, the two tasks are in a competitive relationship. communication between tasks is for transferring a message between tasks. a task that is to receive the message cannot proceed with processing until it has received the message. therefore, the communication function can also be used in the place of the synchronization function. as a means to implement synchronization and communication, rx78k/iv provides event flags and semaphores for synchronization, and mail boxes for communication.
chapter 2 basic functions of rx78k/iv 13 2.3.1 event flag an event flag is used to make a task wait. since an event flag is a 1-bit flag, it is not ored or anded with the other flags. a task issues system call wai_flg, cwai_flg or pol_flg, cpol_flg to wait for an occurrence of an event. if the event does not occur, the issuing task enters the wait state (when wai_flg or cwai_flg is issued). if the task does not enter the wait state, an error code is returned (when pol_flg or cpol_flg is issued). to inform the occurrence of the event, system call set_flg is issued. the event flag is cleared by system call clr_flg. an event flag can be used to place two or more tasks in the wait state. therefore, the event flag can queue tasks. in this case, the tasks are released from the wait state when set_flg is issued once. if at least one task of the tasks placed in the wait state specifies clearing the flag (cwai_flg), the event flag is cleared after that task has been released from the wait state. therefore, the tasks following that task are not released from the wait state.
chapter 2 basic functions of rx78k/iv 14 2.3.2 semaphore a semaphore is used to mutually exclude tasks. the semaphore is a measurement that can check whether currently usable resources exist, or manage the number of resources. the number of requested resources of the wait manipulation (p) and signal manipulation (v) instructions for a semaphore is fixed to 1. if a task needs a resource, it performs resource acquisition manipulation (p instruction) by issuing system call wai_sem, preq_sem. if the number of resources is 1 or more, the number of resources of the semaphore is decremented by one. if the number of resources is 0, the resource requesting task is placed in the wait state (wai_sem), or if the task is not placed in the wait state, an error code is returned (preq_sem). if the task does not need the resource any more, it executes resource return manipulation (v instruction) by issuing system call sig_sem. as a consequence, the number of resources of the semaphore is incremented by one. if there are tasks waiting for a resource at this time, the task first placed in the wait state is released. a task waits for a semaphore on a fif0 basis only.
chapter 2 basic functions of rx78k/iv 15 2.3.3 mail box a mail box transmits messages between tasks and has a queue of tasks waiting for reception of a message and a queue of messages waiting to be transmitted. a task can request reception of a message from a mail box by issuing system call rcv_msg or prcv_msg. if the message has not arrived after rcv_msg has been issued, the task enters the wait state and queued to the mail box. if the task has issued prcv_msg, it does not enter the wait state, but an error code is returned. a task can also send a message to a mail box by issuing system call snd_msg. if there is a task waiting for the message, that task is released from the wait state and the message is transmitted to that task. if there is no waiting task, the message is queued. messages and tasks are queued on a fif0 basis only.
chapter 2 basic functions of rx78k/iv 16 2.4 interrupt management interrupt management is for managing processing that is driven taking an interrupt as an event. a processing routine that is vectored by an interrupt is called an interrupt handler, which is independent of tasks. there are functions to set or exit execution from the interrupt handler. to terminate the interrupt handler and pass control to a task, system calls ret_int and ret_wup are used. to issue ret_int from an interrupt handler occupying the register bank, select the register bank of the task executed before the interrupt has occurred, and then call ret_int. because rx78k/iv does not initialize each interrupt source, each source must be initialized by the user task. fig. 2-2 and 2-3 illustrate the flow of control when a task in the wait state is waken up by an event flag in an interrupt handler. if a task in the wait state is waken up an interrupt handler, system calls ret_int and ret_wup return control to the state of a task under execution when the interrupt has occurred, if the priority of the task to be waken up is lower than the priority of the task under execution when the interrupt has occurred. if the task to be waken up has a higher priority than that of the task under execution, control is passed to the task to be waken up. fig. 2-2 illustrates flow of control if task a has a higher priority than task b. caution ? system calls cannot be issued during nmi interrupt processing. ? please note that rx78k/iv does not support multiple interrupt among the interrupt handlers which are set for interrupt priority 3 (lowest level). neither does it support them with the timer processing. <1> task b has issued system call wai_tsk and is now in the wait state. <2> task a is under execution (has the highest priority of the tasks in the ready state). <3> an interrupt occurs while task a is executed, and processing is passed to the interrupt handler. <4> system call iset_flg is issued in the interrupt handler and task b is waken up. <5> system call ret_int is issued in the interrupt handler. <6> because task a has a priority higher than that of task b, processing is returned to task a. fig. 2-2 example of ret_int task a (pr1=2) interrupt handler task b (pri=3) <2> <3> <6> <5> <4> ret_int iset_flg (wakes up task b) <1> wai_flg interrupt
chapter 2 basic functions of rx78k/iv 17 fig. 2-3 shows an example where task a has a lower priority than task b. <1> task b has issued system call wai_flg and is now in the wait state. <2> task a is under execution (has the highest priority of the tasks in the ready state). <3> an interrupt occurs while task a is executed, and processing is passed to the interrupt handler. <4> system call iset_flg is issued in the interrupt handler, and task b is waken up. <5> system call ret_int is issued in the interrupt handler. <6> because task b has a priority higher than task a, processing is passed to task b. fig. 2-3 example of ret_int task a (pri=3) interrupt handler task b (pri=2) <2> <3> <5> <4> ret_int iset_flg (wakes up task b) <1> wai_flg interrupt <6>
chapter 2 basic functions of rx78k/iv 18 2.5 memory management rx78k/iv performs dynamic memory management based on a memory block of fixed size. this means that a task acquires memory when necessary, and releases it when unnecessary. by using this feature, it is not necessary to acquire a memory area in advance for even two or more tasks, so that the memory can be efficiently used. the memory block of rx78k/iv is dynamically acquired by a system call under execution by the system, and is returned after it has been used and is no longer necessary. if one memory block cannot be acquired, state transition of a task does not take place, but only an error code is returned. the size of one memory block is fixed to a value specified on system creation. usually, an acquired memory block is used as a message area, in which case the first 2 bytes with the large model, the first 1 byte with the small model, are used as a queue link area. therefore, the area that can be used as a message area is the area excluding link area. fig. 2-4 memory pool configuration queue area queue area queue area memory block queue area memory block queue area memory block memory pool first address free block management area large model : 4 bytes small model : 2 bytes large model : 2 bytes small model : 1 byte size of 1 memory block =0 (queue area of last memory block) caution when using a memory block as a message area, please make the size of the memory block a multiple of 2. operation is not guaranteed if the size is not a multiple of 2.
chapter 2 basic functions of rx78k/iv 19 2.6 time management time management refers to delayed wake up of tasks and the running of cyclic handlers. delayed wake up tasks means performing wake up processing on a task after the elapsing of a specified amount of time, and is implemented by means of the wai_task system call. running of cyclic handlers means managing the running of handlers as interrupt processes as specified time intervals, and is implemented by means of the act_cyc(iact_cyc) system call. in rx78k/iv, one of the cpus 16-bit timer/counter units is used as the interval timer. by allocating vector table of the timer dispatch routine provided by the os to this timer (?tmdsp), this routine can be periodically run. in the timer dispatch routine, the waiting time of a task that has issued the (wai_tsk) system call, or the waiting time of a cyclic handler is counted down, and when the specified time has elapsed, the task is awakened, or the cyclic handler is run. regarding the actual state transition, a task that has issued wai_tsk goes from the wait state to the ready state, whereas a cyclic handler is called directly from the timer dispatch routine.
20 [memo]
21 chapter 3 rx78k/iv basic operations and control blocks this chapter describes the basic operations of a system running rx78k/iv and the control block configuration managed by rx78k/iv.
chapter 3 rx78k/iv basic operations and control blocks 22 3.1 rx78k/iv configuration 3.1.1 flow of overall processing rx78k/iv uses register bank 0 of the 8 register banks of the 78k/iv series microcomputers. for user tasks, multiple tasks can be allocated to register bank 1, and one task each to register bank 2 to 7. the tasks allocated to register banks 2 to 7 can realize high-speed task switching, because with them, it is unnecessary to save the registers when tasks are switched over during execution. an example method for allocating register banks is shown below. example 1: with 6 tasks register bank 1 : none register banks 2 to 7 : one task each example 2: with 6 tasks register bank 1 : 3 tasks register banks 2 to 4 : one task each register banks 5 to 7 : for interrupting example 3: with 10 tasks register bank 1 : 4 tasks register banks 2 to 7 : one task each the task area is required for each task; therefore, when performing a task, the stack area of the task is used. the interrupt handler uses the stack area of the task being performed when an interrupt occurred. the stack state in dispatching is shown below. fig. 3-1 stack state in dispatching stack area pc15-8 pswh r15 r13 r pc19-16 pc7-0 pswl r14 r2 r0 high low stack area pc15-8 pswh pc19-16 pc7-0 pswl high low when tasks are allocated to register bank 1 when tasks are allocated to register bank 2 to 7
chapter 3 rx78k/iv basic operations and control blocks 23 register bank 1 is shared by multiple tasks. therefore, dispatching or preempting make it necessary for registers to be saved or restored. this causes the overhead of these tasks to be slightly larger than the tasks allocated to register banks 2 to 7. fig. 3-2 shows the flow of the processing to be performed since the system call has been issued until control is returned to the bank. fig. 3-2 flow of overall processing task issurance of system call rx78k/iv selected task processing system call save registers, etc. (when using rb1) dispatch
chapter 3 rx78k/iv basic operations and control blocks 24 3.1.2 configuration of ready queue and dispatching when rx78k/iv passes cpu execution privilege to a task, it searches for a task having the highest priority in the ready state. at this time, rx78k/iv references a ready queue. rx78k/iv has 16 ready queues each corresponding to 16 priority levels (0 to 15). the task chained to the head of a ready queue has the highest priority of the tasks in the queue, and the task chained to the tail of the queue has the lowest priority. among these priority levels, levels 2 to 15 can be specified for a task. rx78k/iv searches the ready queues from the one having the highest priority for a task to be placed in the run state. however, if there is no executable user task at that time, it sets the cpu in the halt mode. to resume execution of a user task, therefore, an interrupt must be used. the stack area at that time becomes the user stack area. fig. 3-3 shows the configuration of the ready queue. fig. 3-3 ready queue configuration ready queue top last tcb1 queue area information particular to the task tcb2 queue area information particular to the task tcbn queue area information particular to the task
chapter 3 rx78k/iv basic operations and control blocks 25 3.2 rx78k/iv control block rx78k/iv has control blocks to manage each object. the control blocks are created by the user at time of configuration, and rx78k/iv uses these blocks for system calls or for management. therefore, the state of the control blocks can be always monitored by the user task. the types of rx78k/iv control blocks are as follows: <1> tcb (task control block) <2> evt (eventflag) <3> sem (semaphore) <4> mbox (mail box) <5> mpl (memory pool) <6> hcb (cyclic handler control block) 3.2.1 control block memory area as described above, the control blocks are created by the user at time of configuration with rx78k/iv. therefore, all parameters are passed to system calls (related to control blocks) by specifying an address by using a symbol name. fig. 3-4 shows an example of parameters. fig. 3-4 example of parameters tcb queue area takid = tskid_1 tskid_1 evt queue area flgid = evtid_1 evtid_1 xxxid = starting adderss of target object
chapter 3 rx78k/iv basic operations and control blocks 26 3.2.2 control blocks (1) task control block (tcb) this control block is used by rx78k/iv to manage tasks. one control block of this type is assigned to each task. one tcb is 10 bytes long with the large model, and 8 bytes long with the small model. (2) event flag (evt) an event flag is a block that manages events that are used to synchronize tasks or make tasks wait. one event flag is 4 bytes long with the large model, and 2 bytes long with the small model. * if two or more tasks are waiting when the event flag is set, all the wait tasks enter the ready state. however, if a task exists that has issued cwai _ flg? and has entered the wait state, the flag is cleared after that task has been released from the wait state. after that, task state transitions do not take place. (3) semaphore (sem) a semaphore is a resource management block that is used to synchronize or mutually exclude tasks. one semaphore is 4 bytes long with the large model, and 2 bytes long with the small model. (4) mail box (mbox) a mail box is a control block that manages message communication between tasks. one mail box is 4 bytes long with the large model, and 2 bytes long with the small model. (5) memory pool (mpl) the memory pool manages free memory blocks. normally, memory blocks are used as message areas. when use it as a message area, be sure to set the size of one memory block to a multiple of 2. even in cases other than messages, it is possible to secure only the portion of the memory blocks required for the relevant purpose. the size of the memory pool is the total of the free block management area and the memory blocks. the size of the free block management area is 4 bytes long with the large model, and 2 bytes long with the small model. (6) cyclic handler control block (hcb) cyclic handler control blocks are used by rx78k/iv to manage cyclic handlers. one cyclic handler is given one control block. the size of each cyclic handler control block is 10 bytes long with the large model, and 8 bytes long with the small model.
27 chapter 4 rx78k/iv system call list this chapter describes the following items of each system calls: [function]: outline of the function of the system call [remarks]: describes the function of the system call [system call id number]: number particular to system call when the assembler calls the system call [parameter]: describes the name, data size, and explanation of each parameter. [return parameter]: a list of return values that may occur as a result of issuance of the system call. the return value is returned as a function value of the system call in the case of the c language, and to register c in the case of the assembler. since no abnormal termination processing is performed for all the system calls, add abnormal termination processing by referring to the value of the return parameter. [assembler format]: describes which register is used for output parameter, and how to handle an input parameter when the system call is issued in the assembler. for the system call called from an interrupt handler, describes which register is used as an input parameter. the symbols described in the assembler format have the following addresses: [large model] bnk0_b = 0ffef3h, bnk0_vp = 0ffef8h, bnk0_up = 0ffefah, bnk0_e = 0ffefch, bnk0_d = 0ffefdh [small model] bnk0_b = 0fef3h, bnk0_vp = 0fef8h, bnk0_up = 0fefah, bnk0_e = 0fefch the system call which can be issued from an interrupt handler uses the register bank of that time. the following is described in the assembler format: [large model] example e, uup, vvp [small model] example e, up, vp
chapter 4 rx78k/iv system call list 28 [c format]: description format used when the system call is issued in the c language and the data type of the parameter ? ? interface with c language the high-level language supported in developing an application program is the c language. to issue a system call in the c language, an assembler routine is necessary for interfacing with the os. therefore, the interface routine corresponding to the system call used must be linked with each task. the format of the system call in the c language is as follows: ret = ([],...); ret : function return value (char type) : system call name : input parameter the data type of each parameter and size are as follows. char : 8-bit integer unsigned short : 16-bit integer char* : 24-bit pointer (large model) 16-bit pointer (small model) ? interface with assembler to issue a system call in the assembler, set parameters to the relevant register of register bank 0 as follows. example of sta_tsk issuance (large model) example of sta_tsk issuance (small model) the entry address of branch processing to branch to the system call is set to 40h. the branch processing module takes out the entry address of each system call from a table created by the configurator and branches. the configuration of the entry address storage table of system calls is as follows: mov bnk0_reg1, #system call id number movw bnk0_reg2, #parameter 1 (lower 16 bits) mov bnk0_reg3, #parameter 1 (higher 8 bits) callt [40h] mov bnk0_reg1, #system call id number movw bnk0_reg2, #parameter 1 callt [40h]
chapter 4 rx78k/iv system call list 29 fig. 4-1 entry address storage table sta_tsk? ext_tsk 00h? get_ver .? .? .? . entry address of target system call if system call is not selected be sure to directly call the following i _ system call issued from the interrupt handler, without going through the branching module. the values in the brackets indicate the addresses of the callt table. however, addresses corresponding to unused system calls can be used by users. ichg_pri (42h), irot_rdq (44h), iwup_tsk (46h), iset_flg (48h), isig_sem (4ah), isnd_msg (4ch) the ret_int and ret_wup system calls are branched out to system calls directly by the br command. ? differences between ? _ ? and ?i _ ? system calls system call ?i _ ? is started by an interrupt handler and is not dispatched its own. this system call is dispatched when ?ret_int? has been issued that returns execution from the interrupt handler, or ?ret_wup? that returns execution from the interrupt handler and wakes up a task. when a system call is recovered from the interrupt handler with the reti command, dispatching occurs in the next system call.
chapter 4 rx78k/iv system call list 30 4.1 system calls related to task the following system calls are related to tasks: (1) sta_tsk starts task (2) ext_tsk normally terminates task itself (3) ter_tsk forcibly terminates another task (4) chg_pri changes the tasks priority ichg_pri changes the tasks priority (5) rot_rdq rotates specified priority ready queue irot_rdq rotates specified priority ready queue (6) tsk_sts checks the tasks state (7) slp_tsk places the tasks in wait state (8) wai_tsk places the tasks in wait state for fixed time (9) wup_tsk wakes up the task iwup_tsk wakes up the task (when used in interrupt handler) (10) can_wup makes the task wake-up request invalid
chapter 4 rx78k/iv system call list 31 4.1.1 sta_tsk (start task) [function] starts a task by placing it in the ready state from the dormant state. [remarks] this system call starts the task specified by tskid. as a result, the task enters the ready state from the dormant state. this system call must not be issued to a task that is not in the dormant state. if issued, error code e_nodmt is returned. to start a task for the first time, or to restart a task that has been once terminated, processing is started from the start address of the task, and the value of the stack pointer is set to the initial value. the values of the other registers are undefined. a task to which the sta_tsk system call is to be issued enables interrupts. disable interrupts for each task. [system call id number] sta_tsk = 0 [parameter] tskid (task identifier) task id (tcb top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination e_nodmt specified task is not in dormant state [assembler format] [large model] [small model] mov bnk0_b, #0 mov bnk0_b, #0 movw bnk0_up, #tskid movw bnk0_up, #tskid mov bnk0_d, #tskid callt [40h] callt [40h] : : c register= return parameter c register= return parameter [c format] ret = sta_tsk(tskid); char *tskid;
chapter 4 rx78k/iv system call list 32 4.1.2 ext_tsk (exit task) [function] normally terminates the task itself and places the task in the dormant state from the run state. [remarks] this system call normally terminates the task that issues this system call itself. as a result, the task enters the dormant state from the run state. to restart by the sta_tsk system call the task that has entered the dormant state by issuing the ext_tsk system call, the start address and stack pointer are returned to the initial values. the wakeup request counter is cleared to 0. the task does not automatically release the resource it has acquired before the ext_tsk system call is issued. release the resources before issuing this system call. [system call id number] ext_tsk = 1 [parameter] none [return parameter] none (control is not returned to the task that has issued this system call.) [assembler format] [large/small model] mov bnk0_b, #1 callt [40h] [c format] ext_tsk ();
chapter 4 rx78k/iv system call list 33 4.1.3 ter_tsk (terminate task) [function] forcibly aborts another task. [remarks] this system call forcibly aborts the task specified by tskid. if the specified task is placed in a queue, the task is released from the queue when the ter_tsk system call has been issued. therefore, the task is released from the wait state before it is terminated. ter_tsk does not automatically release the resources that the task has acquired before. release the resources before terminating the task. this system call cannot specify the task itself that issues it. [system call id number] ter_tsk = 2 [parameter] tskid (task identifier) task id (tcb top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination e_dmt specified task is in dormant state [assembler format] [large model] [small model] mov bnk0_b, #2 mov bnk0_b, #2 movw bnk0_up, #tskid movw bnk0_up, #tskid mov bnk0_d, #tskid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = ter_tsk(tskid); char *tskid;
chapter 4 rx78k/iv system call list 34 4.1.4 chg_pri (change task priority) ichg_pri (change task priority for interrupt) [function] changes the priority of a task. [remarks] changes the priority of the current task indicated by tskid to a value indicated by tskpri. the own task is specified at tskid = 0. however, the own task cannot be specified with ichg_pri. priorities modified in the current system call are valid until remodified or performing the task is finished. the priority for a task which has been restarted is the initial priority. [system call id number] chg_pri = 3 [parameter] tskid (task identifier) task id (tcb top address) - 24 bits (large model) - 16 bits (small model) tskpri(task priority) task priority - 8 bits [return parameter] e_ok normal termination e_dmt specified task is in dormant state [assembler format] ? on issuing chg_pri [large model] [small model] mov bnk0_b, #3 mov bnk0_b, #3 mov bnk0_e, #tskpri mov bnk0_e, #tskpri movw bnk0_up, #tskid movw bnk0_up, #tskid mov bnk0_d, #tskid callt [40h] callt [40h] : : c register = return parameter c register = return parameter ? on issuing ichg_pri [large model] [small model] mov e, #tskpri mov e, #tskpri movg uup, #tskid movw up, #tskid callt [42h] callt [42h] :: c register = return parameter c register = return parameter [c format] ? on issuing chg-pri ? on issuing ichg-pri ret = chg_pri (tskid, tskpri); ret = ichg_pri (tskid, tskpri); char *tskid; char *tskid; char tskpri; char tskpri;
chapter 4 rx78k/iv system call list 35 4.1.5 rot_rdq (rotate ready queue) irot_rdq (rotate ready queue for interrupt) [function] rotates the ready queue of the specified priority. [remarks] rotates the ready queue of the priority indicated by tskpri. consequently, the task placed at the top of the ready queue is placed at the end of the queue and execution of the task of the same priority is changed. when tskpri = 0, the ready queue of the priority of the task itself is rotated. therefore, this system call can be issued to relinquish execution privileges so that the task itself is placed at the end of the ready queue. however, irot_rdq cannot specify tskpri = 0. if no task exists in the ready queue of the specified priority, nothing is executed, but this does not result in an error. [system call id number] rot_rdq = 4 [parameter] tskpri (task priority) task priority - 8 bits [return parameter] e_ok normal termination [assembler format] ? on issuing rot_rdq [large/small model] mov bnk0_v, #4 mov bnk0_e, #tskpri callt [40h] : c register = return parameter ? on issuing irot_rdq [large/small model] mov e, #tskpri callt [44h] : c register = return parameter [c format] ? on issuing rot_rdq ? on issuing irot_rdq ret = rot_rdq (tskpri); ret = irot_rdq (tskpri); char tskpri; char tskpri;
chapter 4 rx78k/iv system call list 36 4.1.6 tsk_sts (get task status) [function] gets a tasks state. [remarks] references each status of the task indicated by tskid, and sets the current priority of the target task tskpri and task state tskstat in a specified address (refer to the figure below). the own task is specified at tskid = 0. the area for p-tsksts should be allocated by the user. for the task status, refer to appendix 1 . p_tsksts? 1h? 0h? task priority? (tskpri)? task status? (tskstat)? [system call id number] tsk_sts = 5 [parameter] tskid (task identifier) task id (tcb top address) - 24 bits (large model) - 16 bits (small model) p_tsksts (pointer of task status) address of area storing task status - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #5 mov bnk0_b, #5 movw bnk0_up, #tskid movw bnk0_up, #tskid mov bnk0_d, #tskid movw bnk0_vp, #p_tsksts movw bnk0_vp, #p_tsksts callt [40h] mov bnk0_e, #p_tsksts : callt [40h] c register = return parameter : c register = return parameter [c format] ret = tsk_sts (p_tsksts,tskid); short *p_tsksts; char *tskid;
chapter 4 rx78k/iv system call list 37 4.1.7 slp_tsk (sleep task) [function] places a task in the wait state. [remarks] places the task itself in the wait state from the run state. this wait state is released issuing the system call wup_tsk (iwup_tsk) or ret_wup to the task. [system call id number] slp_tsk = 6 [parameter] none [return parameter] e_ok normal termination [assembler format] [large/small model] mov bnk0_b, #6 callt [40h] : c register = return parameter [c format] ret = slp_tsk ();
chapter 4 rx78k/iv system call list 38 4.1.8 wai_tsk (wait for wakeup task) [function] places a task in the wait state for a fixed amount of time. [remarks] places the task itself in the wait state for a fixed amount of time from the run state. this wait state can be released issuing the system call wup_tsk (iwup_tsk) or ret_wup to this task, or when the amount of time specified by tmout has elapsed. if the value of tmout is 0, immediate return is executed, and e_tmout is returned as the return parameter. if tmout is 0 and the number of wake-up request counts is 1 or more, e_ok is returned (and the wake-up request count is updated). when this system call is used, the vector address of the timer to be used must be set. for the timer to be used, refer to 5.1 hardware used . [system call id number] wai_tsk = 7 [parameter] tmout (timeout) time out specification - 16 bits [return parameter] e_ok normal termination e_tmout elapsed time [assembler format] [large/small model] mov bnk0_b, #7 movw bnk0_vp, #tmout callt [40h] : c register = return parameter [c format] ret = wai_tsk (tmout); unsigned short tmout; wait time = set interrupt time tmout value
chapter 4 rx78k/iv system call list 39 4.1.9 wup_tsk (wakeup task) iwup_tsk (wakeup task for interrupt) [function] wakes up a task and places it in the ready state from the wait state. [remarks] places a task that has been placed in the wait state by system call slp_tsk or wai_tsk in the ready state. the target task is indicated by tskid. the task itself cannot be specified. if the target task has not executed slp_tsk or wai_tsk and is not in the wait state, this wup_tsk request is queued. in this case, this wup_tsk request becomes valid when the target task later executes slp_tsk or wai_tsk. if the number of wake-up requests in the queue is about to exceed the upper limit (0ffh), an error (e_qovr) is returned. [system call id number] wup_tsk = 8 [parameter] tskid (task identifier) task id (tcb top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination e_dmt specified task is in dormant state e_qovr queue overflow [assembler format] ? on issuing wup_tsk [large model] [small model] mov bnk0_b, #8 mov bnk0_b, #8 movw bnk0_up, #tskid movw bnk0_up, #tskid mov bnk0_d, #tskid callt [40h] callt [40h] : : c register = return parameter c register = return parameter ? on issuing iwup_tsk [large model] [small model] movg uup, #tskid movw up, #tskid callt [46h] callt [46h] :: c register = return parameter c register = return parameter [c format] ? on issuing wup_tsk ? on issuing iwup_tsk ret = wup_tsk (tskid); ret = iwup_tsk (tskid); char *tskid; char *tskid;
chapter 4 rx78k/iv system call list 40 4.1.10 can_wup (cancel wakeup task) [function] cancels a task wake-up request. [remarks] stores the number of wake-up requests queued to the target task indicated by tskid to a specified pointer, and at the same time cancels all wake-up requests. the area for p_wupcnt should be allocated by the user. the own task is specified at tskid = 0. [system call id number] can_wup = 9 [parameter] tskid (task identifier) task id (tcb top address) - 24 bits (large model) - 16 bits (small model) p_wupcnt (pointer of wakeup count) pointer storing the number of wake-up - 24 bits (large model) requests queued - 16 bits (small model) [return parameter] e_ok normal termination e_dmt specified task is in dormant state [assembler format] [large model] [small model] mov bnk0_b, #9 mov bnk0_b, #9 movw bnk0_up, #tskid movw bnk0_up, #tskid mov bnk0_d, #tskid movw bnk0_vp, #p_wupcnt movw bnk0_vp, #p_wupcnt callt [40h] mov bnk0_e, #p_wupcnt : callt [40h] c register = return parameter : c register = return parameter [c format] ret = can_wup (p_wupcnt,tskid); char *p_wupcnt; char *tskid;
chapter 4 rx78k/iv system call list 41 4.2 synchronization and communication the following system calls are used for synchronization and communication: (1) set_flg sets an event flag (2) iset_flg sets an event flag (when used in interrupt handler) (3) clr_flg clears an event flag (4) wai_flg waits for an event flag (without clear) (5) cwai_flg waits for an event flag (with clear) (6) pol_flg obtains an event flag (without clear) (7) cpol_flg obtains an event flag (with clear) (8) sig_sem signal manipulation of a semaphore (v instruction) (9) isig_sem signal manipulation of a semaphore (when used in interrupt handler) (10) wai_sem wait manipulation of a semaphore (p instruction) (11) preq_sem obtains the semaphore resource (12) snd_msg sends a message (13) isnd_msg sends a message (when used in interrupt handler) (14) rcv_msg waits for message reception (15) prcv_msg receives a message
chapter 4 rx78k/iv system call list 42 4.2.1 set_flg (set eventflag) iset_flg (set eventflag for interrupt) [function] sets an event flag. [remarks] the event flag indicated by flgid is set to 1. if a task exists that has been made to wait for the event flag by wai_flg, cwai_flg, the task is released from the wait state and placed in the ready state. two or more tasks can wait for the same event flag. in this case, the tasks can be released from the wait state when set_flg is issued once. [system call id number] set_flg = 10 [parameter] flgid (eventflag identifier) event flag id (eventflag top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] ? on issuing set_flg [large model] [small model] mov bnk0_b, #10 mov bnk0_b, #10 movw bnk0_up, #flgid movw bnk0_up, #flgid mov bnk0_d, #flgid callt [40h] callt [40h] : : c register = return parameter c register = return parameter ? on issuing iset_flg [large model] [small model] movg uup, #flgid movw up, #flgid callt [48h] callt [48h] :: c register = return parameter c register = return parameter [c format] ? on issuing set_flg ? on issuing iset_flg ret = set_flg (flgid); ret = iset_flg (flgid); char *flgid; char *flgid;
chapter 4 rx78k/iv system call list 43 4.2.2 clr_flg (clear eventflag) [function] clears an event flag. [remarks] clears the event flag indicated by flgid. even if a task exists that has been made to wait for the event flag by wai_flg, cwai_flg, that task is not released from the wait state. [system call id number] clr_flg = 11 [parameter] flgid (eventflag identifier) event flag id (eventflag top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #11 mov bnk0_b, #11 movw bnk0_up, #flgid movw bnk0_up, #flgid mov bnk0_d, #flgid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = clr_flg (flgid); char *flgid;
chapter 4 rx78k/iv system call list 44 4.2.3 wai_flg (wait eventflag) [function] waits for an event flag (without clear). [remarks] waits until an event flag indicated by flgid is set to 1. the value of the event flag remains set after it has been set and the task has been released from the wait state. two or more tasks can wait for the same event flag. [system call id number] wai_flg = 12 [parameter] flgid (eventflag identifier) event flag id (eventflag top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #12 mov bnk0_b, #12 movw bnk0_up, #flgid movw bnk0_up, #flgid mov bnk0_d, #flgid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = wai_flg (flgid); char *flgid;
chapter 4 rx78k/iv system call list 45 4.2.4 cwai_flg (wait and clear eventflag) [function] waits for an event flag (with clear). [remarks] waits until an event flag indicated by flgid is set to 1. the event flag is cleared when it has been set and the task has been released from the wait state. if set_flg is issued when two or more tasks are waiting for an event flag, the tasks are sequentially woken up starting from the one placed at the top of the queue. however, the tasks following the one in the wait state by cwai_flg cannot be woken up because the event flag is cleared. [system call id number] cwai_flg = 13 [parameter] flgid (eventflag identifier) event flag id (eventflag top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #13 mov bnk0_b, #13 movw bnk0_up, #flgid movw bnk0_up, #flgid mov bnk0_d, #flgid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = cwai_flg (flgid); char *flgid;
chapter 4 rx78k/iv system call list 46 4.2.5 pol_flg (poll eventflag) [function] obtains an event flag (without clear). [remarks] checks whether the event flag indicated by flgid is set. if the flag is set, the task is terminated normally; if not, an error is returned (e_plfail). in either case, the original value of the event flag is retained. [system call id number] pol_flg = 14 [parameter] flgid (eventflag identifier) event flag id (eventflag top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination e_plfail polling failed [assembler format] [large model] [small model] mov bnk0_b, #14 mov bnk0_b, #14 movw bnk0_up, #flgid movw bnk0_up, #flgid mov bnk0_d, #flgid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = pol_flg (flgid); char *flgid;
chapter 4 rx78k/iv system call list 47 4.2.6 cpol_flg (poll and clear eventflag) [function] obtains an event flag (with clear). [remarks] checks whether the event flag indicated by flgid is set. if the flag is set, the flag is cleared and the task is terminated normally; if not, an error is returned (e_plfail) with the flag value left untouched. [system call id number] cpol_flg = 15 [parameter] flgid (eventflag identifier) event flag id (eventflag top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination - 8 bits e_plfail polling failed - 8 bits [assembler format] [large model] [small model] mov bnk0_b, #15 mov bnk0_b, #15 movw bnk0_up, #flgid movw bnk0_up, #flgid mov bnk0_d, #flgid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = cpol_flg (flgid); char *flgid;
chapter 4 rx78k/iv system call list 48 4.2.7 sig_sem (signal semaphore) isig_sem (signal semaphore for interrupt) [function] executes signal manipulation for semaphore (v instruction). [remarks] if tasks exist that wait for a semaphore indicated by semid, the task at the top of the queue is placed in the ready state. if no task is waiting for the semaphore, the count value of the semaphore is increased by one. if the count value of the semaphore is about to exceed the upper limit (0ffh), e_qovr is returned as an error code. [system call id number] sig_sem = 16 [parameter] semid (semaphore identifier) semaphore id (semaphore top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination e_qovr queue overflow [assembler format] ? on issuing sig_sem [large model] [small model] mov bnk0_b, #16 mov bnk0_b, #16 movw bnk0_up, #semid movw bnk0_up, #semid mov bnk0_d, #semid callt [40h] callt [40h] : : c register = return parameter c register = return parameter ? on issuing isig_sem [large model] [small model] movg uup, #semid movw up, #semid callt [4ah] callt [4ah] :: c register = return parameter c register = return parameter [c format] ? on issuing sig_sem ? on issuing isig_sem ret = sig_sem (semid); ret = isig_sem (semid); char *semid; char *semid;
chapter 4 rx78k/iv system call list 49 4.2.8 wai_sem (wait on semaphore) [function] executes wait manipulation for a semaphore (p instruction). [remarks] if the count value of the semaphore indicated by semid is 1 or more, the count value of the semaphore is decremented by one, and to the task that issued this system call. if the count value of the semaphore is 0, the count value of the semaphore is not changed, and the task that has issued this system call is placed in the wait state. [system call id number] wai_sem = 17 [parameter] semid (semaphore identifier) semaphore id (semaphore top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #17 mov bnk0_b, #17 movw bnk0_up, #semid movw bnk0_up, #semid mov bnk0_d, #semid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = wai_sem(semid); char *semid;
chapter 4 rx78k/iv system call list 50 4.2.9 preq_sem (poll and request semaphore) [function] obtains a semaphore resource. [remarks] if the count value of the semaphore indicated by semid is 1 or more, the count value of the semaphore is decremented by one, and the task terminates normally. if the count value of the semaphore is 0, the semaphore value is not changed and an error is returned (e_plfail). [system call id number] preq_sem = 18 [parameter] semid (semaphore identifier) semaphore id (semaphore top address) - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination e_plfail polling failed [assembler format] [large model] [small model] mov bnk0_b, #18 mov bnk0_b, #18 movw bnk0_up, #semid movw bnk0_up, #semid mov bnk0_d, #semid callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = preq_sem(semid); char *semid;
chapter 4 rx78k/iv system call list 51 4.2.10 snd_msg (send message to mailbox) isnd_msg (send message to mailbox for interrupt) [function] sends a message. [remarks] sends a message at the address pk_msg to a mail box indicated by mbxid. if a task exists that is waiting for the message, the top address of the sent message is returned, and the task is placed in the ready state. in this case, the message is not sent to the mail box. if there is no task waiting for the message, the task issuing snd_msg is not placed in the wait state. this system call only sends a message to a mail box, and execution of the task continues. in other words, message transmission is carried out asynchronously. the first 2 bytes of the transmitting message are used as the link area of the queue. therefore, be sure to store the message from the 3rd byte and onward. [system call id number] snd_msg = 19 [parameter] mbxid (mailbox identifier) mail box id (mailbox top address) - 24 bits (large model) - 16 bits (small model) pk_msg (message packet) transmission message top address - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] ? on issuing snd_msg [large model] [small model] mov bnk0_b, #19 mov bnk0_b, #19 movw bnk0_up, #mbxid movw bnk0_up, #mbxid mov bnk0_d, #mbxid movw bnk0_vp, #pk_msg movw bnk0_vp, #pk_msg callt [40h] mov bnk0_e, #pk_msg : callt [40h] c register = return parameter : c register = return parameter ? on issuing isnd_msg [large model] [small model] movg uup, #mbxid movw up, #mbxid movg vvp, #pk_msg movw vp, #pk_msg callt [4ch] callt [4ch] :: c register = return parameter c register = return parameter
chapter 4 rx78k/iv system call list 52 [c format] ? on issuing snd_msg ? on issuing isnd_msg ret = snd_msg (mbxid, pk_msg); ret = isnd_msg (mbxid, pk_msg); char *mbxid; char *mbxid; char *pk_msg; char *pk_msg;
chapter 4 rx78k/iv system call list 53 4.2.11 rcv_msg (receive message from mailbox) [function] waits for reception from a mail box. [remarks] receives a message from a mail box indicated by mbxid and sets the top address of the received message in an address specified by the parameter. if the message has not arrived at the mail box, the task that has issued this system call is placed in the wait state. the area for ppk-msg should be allocated by the user. received message becomes a top address of the message area actual data is stored. [system call id number] rcv_msg = 20 [parameter] mbxid (mailbox identifier) mail box id (mailbox top address) - 24 bits (large model) - 16 bits (small model) ppk_msg (pointer of message packet) address of area storing the top - 24 bits (large model) address of received message - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #20 mov bnk0_b, #20 movw bnk0_up, #mbxid movw bnk0_up, #mbxid mov bnk0_d, #mbxid movw ax, #ppk_msg movg vvp, #ppk_msg push ax push vvp callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = rcv_msg (ppk_msg,mbxid); char **ppk_msg; char *mbxid;
chapter 4 rx78k/iv system call list 54 4.2.12 prcv_msg (poll and receive message from mailbox) [function] receives a message. [remarks] if a message has arrived to the mail box indicated by mbxid, it receives the message and sets the top address of the received message in an address specified by the parameter. in this case, this system call terminates normally. if the message has not arrived to the mail box, this system call returns e_plfail as an error code. the area for ppk-msg should be allocated by the user. received message becomes a top address of the message area actual data is stored. [system call id number] prcv_msg = 21 [parameter] mbxid (mailbox identifier) mail box id (mailbox top address) - 24 bits (large model) - 16 bits (small model) ppk_msg (pointer of message packet) address of area storing the top - 24 bits (large model) address of received message - 16 bits (small model) [return parameter] e_ok normal termination e_plfail polling failed [assembler format] [large model] [small model] mov bnk0_b, #21 mov bnk0_b, #21 movw bnk0_up, #mbxid movw bnk0_up, #mbxid mov bnk0_d, #mbxid movw bnk0_vp, #ppk_msg movw bnk0_vp, #ppk_msg callt [40h] mov bnk0_e, #ppk_msg : callt [40h] c register = return parameter : c register = return parameter [c format] ret = prcv_msg (ppk_msg,mbxid); char **ppk_msg; char *mbxid;
chapter 4 rx78k/iv system call list 55 4.3 memory management the following system calls are related to memory: (1) pget_blk gets a fixed-length memory block (2) rel_blk releases a fixed-length memory block
chapter 4 rx78k/iv system call list 56 4.3.1 pget_blk (poll and get fixed-length memory block) [function] gets a memory block of a fixed length. [remarks] gets a memory block of a fixed length from a memory pool indicated by mplid. this memory block can be used as a message area for communication between tasks. the size of the memory block is determined on creation of the system and is fixed. when a memory block can be gotten, the top address of the memory block is set in an address specified by the parameter. if the memory block cannot be gotten, an error code e_plfail is returned. in either case, the task is not placed in the wait state. the area for p-blk should be allocated by the user. [system call id number] pget_blk = 22 [parameter] mplid (memory pool identifier) memory pool id - 24 bits (large model) (memory pool top address) - 16 bits (small model) p_blk (pointer of block start address) address of area storing the top - 24 bits (large model) address of the memory block - 16 bits (small model) [return parameter] e_ok normal termination e_plfail polling failed [assembler format] [large model] [small model] mov bnk0_b, #22 mov bnk0_b, #22 movw bnk0_up, #mplid movw bnk0_up, #mplid mov bnk0_d, #mplid movw bnk0_vp, #p_blk movw bnk0_vp, #p_blk callt [40h] mov bnk0_e, #p_blk : callt [40h] c register = return parameter : c register = return parameter [c format] ret = pget_blk (p_blk,mplid); char **p_blk; char *mplid;
chapter 4 rx78k/iv system call list 57 4.3.2 rel_blk (release fixed-length memory block) [function] releases a memory block of a fixed length. [remarks] releases the memory block indicated by blk to a memory pool specified by mplid. [system call id number] rel_blk = 23 [parameter] mplid (memory pool identifier) memory pool id - 24 bits (large model) (memory pool top address) - 16 bits (small model) blk (block start address) top address of the memory block - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #23 mov bnk0_b, #23 movw bnk0_up, #mplid movw bnk0_up, #mplid mov bnk0_d, #mplid movw bnk0_vp, #blk movw bnk0_vp, #blk callt [40h] mov bnk0_e, #blk : callt [40h] c register = return parameter : c register = return parameter [c format] ret = rel_blk (mplid,blk); char *mplid; char *blk;
chapter 4 rx78k/iv system call list 58 4.4 interrupt processing the following system calls can be used for interrupt processing: (1) ret_int terminates the interrupt handler (2) ret_wup returns from an interrupt and wakes up a task
chapter 4 rx78k/iv system call list 59 4.4.1 ret_int (return from interrupt handler) [function] returns from an interrupt handler. [remarks] this system call is issued when execution is returned from an interrupt handler. even if i _yyy? system call is issued in the interrupt handler, dispatching does not take place and is delayed until execution exits from the interrupt handler after this system call has been issued. [system call id number] none [parameter] none [return parameter] none. does not return to the interrupt handler that issued the system call. [assembler format] [large/small model] br !ret_int unlike the other system calls, this system call is caused to branch by the jump instruction. caution when this system call is issued from an interrupt handler, be sure to save the register values before the interrupt occured to the stack. save the register values to the stack in the sequence shown in fig. 4-2. if the interrupt handler occupies a register bank, select the register bank of the task executed before the interrupt has occurred, and then call this system call. [c format] ret_int (); remark because this system call is only supported in version 2.00 or above of the c complier cc78k4, it cannot be used with a c complier of a version lower than 2.00. with a c complier of a version 2.00 or above, specify #pragma d rtos_interrupt? (refer to appendix 2 ).
chapter 4 rx78k/iv system call list 60 4.4.2 ret_wup (return and wakeup task) [function] returns from an interrupt handler and wakes up a task. [remarks] returns from an interrupt handler and wakes up an interrupt processing task indicated by tskid (the task placed in the wait state by slp_tsk or wai_tsk). if the target task does not execute slp_tsk or wai_tsk, the request is queued. even if i _yyy? system call is issued in the interrupt handler, dispatching does not take place and is delayed until execution exits from the interrupt handler after this system call has been issued. [system call id number] none [parameter] tskid (task identifier) task id (tcb top address) - 24 bits (large model) - 16 bits (small model) [return parameter] none. does not return to the interrupt handler that issued the system call. [assembler format] [large/small model] movg uup, #tskid br !ret_wup unlike the other system calls, this system call is caused to branch by the jump instruction. caution when this system call is issued from an interrupt handler, be sure to save the register values before the interrupt occured to the stack. save the register values to the stack in the sequence shown in fig. 4-2. if the interrupt handler occupies a register bank, select the register bank of the task executed before the interrupt has occurred, and then call this system call. [c format] ret_wup (tskid); char *tskid; remark because this system call is only supported in version 2.00 or above of the c complier cc78k4, it cannot be used with a c complier of a version lower than 2.00. with a c complier of a version 2.00 or above, specify #pragma d rtos_interrupt? (refer to appendix 2 ).
chapter 4 rx78k/iv system call list 61 fig. 4-2 stack status when ret_int and ret_wup are called high address? +17h? +16h? +15h? +14h? +13h? +12h? +11h? +10h? +0fh? +0eh? +0dh? +0ch? +0bh? +0ah? + 9h? + 8h? + 7h? + 6h? + 5h? + 4h? + 3h? + 2h? + 1h? ? low address? ? pc19-16 pswh7-4? pswl? pc15-8? pc7-0? w? h(r15)? l(r14)? t? d(r13)? e(r12)? u? r11? r10? v? r9? r8? r7? r6? r5? r4? b(r3)? c(r2)? a(r1)? x(r0)? ? pc19-16 pswh7-4? pswl? pc15-8? pc7-0? h(r15)? l(r14)? d(r13)? e(r12)? r11? r10? r9? r8? r7? r6? r5? r4? b(r3)? c(r2)? a(r1)? x(r0)? high address? +13h? +12h? +11h? +10h? +0fh? +0eh? +0dh? +0ch? +0bh? +0ah? + 9h? + 8h? + 7h? + 6h? + 5h? + 4h? + 3h? + 2h? + 1h? ? low address? automatically ? saved by ? hardware? when large model is used? when small model is used?
chapter 4 rx78k/iv system call list 62 4.5 version management the following system call can be used for version management: (1) get_ver gets the version number of rx78k/iv
chapter 4 rx78k/iv system call list 63 4.5.1 get_ver (get version no.) [function] gets the version number of rx78k/iv. [remarks] sets the top address of the version management block in an address specified by the parameter. the version management block stores the following information. the area for pk_ver should be allocated by the user. the details of the version information is shown below. parameter size value meaning maker 2 byte 0 000d manufacturer (nec) id 2 byte 0 0 model number (large model) spver 2 byte 0 5201 tron specification version ( m itron ver. 2.01) prver 2 byte 0 0120 product version (rx78k/iv ver. 1.20) prno 2 byte *4 0 0 product management information cpu 2 byte 0 0d14 cpu information (nec 78k/iv series) var 2 byte 0 0 variation descriptor [system call id number] get_ver = 25 [parameter] pk_ver (packet of version numbers) address of area storing the pointer to version management block - 24 bits (large model) - 16 bits (small model) [return parameter] e_ok normal termination [assembler format] [large model] [small model] mov bnk0_b, #25 mov bnk0_b, #25 movw bnk0_vp, #pk_ver movw bnk0_vp, #pk_ver mov bnk0_e, #pk_ver callt [40h] callt [40h] : : c register = return parameter c register = return parameter [c format] ret = get_ver (pk_ver); char **pk_ver;
chapter 4 rx78k/iv system call list 64 4.6 time management the system calls for time management are as follows: (1) act_cyc controls activation of a cyclic handler. iact_cyc controls activation of a cyclic handler. (when used within an interrupt handler)
chapter 4 rx78k/iv system call list 65 4.6.1 act_cyc (activate cyclic handler) iact_cyc (activate cyclic handler for interrupt) [function] controls activation of a cyclic handler. [remarks] changes the activation state of the cyclic handler shown by cyhid to the state specified by the cyhact. the specific method of specifying cyhact is as follows: 000000 76543210bit fixed to 0 0 : tcy_off (not started)? 1 : tcy_on (started) 1 : tcy_ini (initializes the cycle time) cyhact = (tcy_off || tcy_on) | [tcy_ini] cyhact = tcy_off means that the cyclic handler has temporarily stopped. during this time, the handler is not started. cyhact = tcy_on sets the activation state to on, independently of the elapsing of the cycle. the specified cycles are counted even while the activation state is off; therefore, the time from execution of the act_cyc (iact_cyc) system call until the first execution of the cyclic handler is not constant. cyhact = (tcy_on | tcy_ini) not only sets the activation state to on but at the same time clears the cyclic handler counter. therefore, the initial handler startup takes place exactly after the specified number of cycles has elapsed since the actcyc (iact_cyc) system call. a cyclic handler cannot be created or destroyed dynamically. a cycle handler is registered with the configurator. [system call id number] act_cyc = 26 [parameter] cyhid (cyclic handler identifier) cyclic handler id (hcb top address) - 24 bits (large model) - 16 bits (small model) cyhact (cyclic handler activation) cyclic handler activation state - 8 bits [return parameter] e_ok normal termination
chapter 4 rx78k/iv system call list 66 [assembler format] ?i n the case of act_cyc: [large model] [small model] mov bnk0_b, #26 mov bnk0_b, #26 mov bnk0_e, #cyhact mov bnk0_e, #cyhact movw bnk0_up, #cyhid movw bnk0_up, #cyhid mov bnk0_d, #tskpri callt [40h] callt [40h] : : c register = return parameter c register = return parameter ?i n the case of iact_cyc: [large model] [small model] mov e, #cyhact mov e, #cyhact movg uup, #cyhid movw up, #cyhid callt [4eh] callt [4eh] :: c register = return parameter c register = return parameter [c format] ?i n the case of act_cyc: ?i n the case of iact_cyc: ret = act_cyc(cyhid, cyhact); ret = iact_cyc(cyhid, cyhact); char cyhid; char cyhid; char cyhact; char cyhact;
67 chapter 5 rx78k/iv reset operation a system running rx78k/iv is initialized when the system initialization reset routine stored with rx78k/iv in the internal rom or external memory of the 78k/iv series is expected. after resetting the device, the system is branched out to the address which is set in address 0000h. therefore, be sure to set the address of the users initialization routine. make sure that the user initial routine performs necessary processing such as initialization of the peripheral hardware. after this, read out the location address of the kernel from the initialization information table created by the configurator, and branch to the reset routine for system initialization. at this time, set the top address of the initialization information table to the tde register. fig. 5-1 shows an example program to branch to the reset routine for system initialization. the reset routine for system initialization initializes the reserved area and object in accordance with the initialization information table. after initialization, control is passed to the rx78k/iv dispatcher. the dispatcher selects a task from a ready queue initialized by the reset routine and places the task in the run state. the task selected at this time is called an initial task. fig. 5-1 reset routine branch program for system initialization (large model) name res_prog ; extrn sys_inf, ; initialization information table ; vcttb10 cseg at 0000h dw res_rtn ; sets vector address at reset vcttbl1 cseg at 0018h dw ?tmdsp ; sets vector address for timer processing resrtn cseg res_rtn: location 0fh (initialization of ram, initialization of peripheral hardware, etc.) movg tde, #sys_inf ; sets top address of the initialization information table to tdereg. movw ax, [tde] ; sets kernel location address to axreg. br ax ; branches to the reset routine for system initialization of rx78k/iv ; end
chapter 5 rx78k/iv reset operation 68 5.1 hardware used with rx78k/iv, hardware such as the timer/counter unit used for wai_tsk, act_cyc(iact_cyc) is used (refer to table 5-1 ). since rx78k/iv does not initialize the timer/counter unit, initialize the unit within the user initialization routine. when wai_tsk, act_cyc(iact_cyc) is not used, the following timer/counter unit is not used. table 5-1 timer of each cpu cpu timer compare register interrupt vector m pd784021, 784025 m pd784026, 78p4026 tm3 (16 bits/timer 3) cr30 intc30 to use a timer other than tm3, set the start address (??tmdsp?) of the timer dispatcher to the vector table address of the timer used (refer to fig. 5-1 ). when setting 3 for the interrupt level of the timer processing to permit multiple interrupt with the interrupt handler, this os cannot warrant proper operations. therefore, ensure either to set a value other than 3 for the interrupt level of the timer processing or inhibit multiple interrupt if interrupt level 3 is to be set.
69 appendix 1 error code list and task status list ? error code list error code value (8 bits, char type) contents e_ok 0 normal termination e_nodmt 1 specified task is not in dormant state when system call sta_tsk is issued e_dmt 2 specified task is in dormant state when system call wup_tsk(iwup_tsk), ter_tsk, or chg_pri is issued e_qovr 3 queue overflow e_tmout 4 when task is terminated after lapse of specified time when system call wai_tsk is issued e_plfail 5 polling has failed ? task status list value status 0x0 dormant status 0x1 run or ready status 0x2 wait status (timeout) 0x3 wait status (sleep) 0x4 wait status (eventflag) w/clear 0x5 wait status (eventflag) w/o clear 0x6 wait status (semaphore) 0x7 wait status (message)
70 [memo]
71 appendix 2 description in c language c compiler cc78k4 of version 2.00 or above supports tasks and interrupt handlers. examples of describing a task and an interrupt handler in the c language are shown below. ? task description format example remark no external reference declaration is necessary for the ext_tsk system call. ? interrupt handler description format example remark external reference declaration is not necessary for system calls ret_int and ret_wup. for details, refer to the users manual of the c compiler. #pragma rtos_task [task function name] #pragma rtos_interrupt [(interrupt request name)(interrupt handler name){stack selection specification] remark stack selection specification: sp = array name [ offset position] #pragma rtos_task sample extern void slp_tsk (void); /* external reference of slp_tsk */ void sample() { slp_tsk(); ext_tsk(); } #pragma rtos_interrupt intpo sample_h sp=int_stack 10 unsigned char int_stack[10]; /* allocates stack area for interrupt */ extern char iset_flg(char*); /* external reference declaration of iset_flg */ extern char flag_idl; /* external reference declaration of event flag id */ sample_h() { iset_flg(&flag_idl); ret_int(); }
72 [memo]
73 appendix 3 system call list system call function entry no. sta_tsk starts task by placing it in run state from dormant state 0 ext_tsk normally terminates task itself by placing it in dormant state from run state 1 ter_tsk forcibly terminates another task by placing it dormant state 2 chg_pri changes a tasks priority 3 ichg_pri changes a tasks priority [issues from interrupt handler] - rot_rdq rotates the ready queue of the specified priority 4 irot_rdq rotates the ready queue of the specified priority [issues from interrupt handler] - tsk_sts checks the task status 5 slp_tsk places the task in the wait state 6 wai_tsk places the task in the wait state temporarily 7 wup_tsk wakes up and places the task in the ready state from the wait state 8 iwup_tsk wakes up and places the task in the ready state from the wait state [issues from interrupt handler] - can_wup cancels a task wake-up request 9 set_flg sets an event flag 10 iset_flg sets an event flag [issues from interrupt handler] - clr_flg clears an event flag 11 wai_flg waits for an event flag to be set (w/o clear) 12 cwai_flg waits for an event flag to be set (w/clear) 13 pol_flg gets an event flag (w/o clear) 14 cpol_flg gets an event flag (w/clear) 15 sig_sem signal manipulation of a semaphore (v instruction) 16 isig_sem signal manipulation of a semaphore (v instruction) [issues from interrupt handler] - wai_sem wait manipulation of a semaphore (p instruction) 17 preq_sem obtains semaphore resources 18 snd_msg sends a message 19 isnd_msg sends a message [issues from interrupt handler] - rcv_msg waits for reception from a mail box 20 prcv_msg receives a message 21 pget_blk gets a fixed-length memory block 22 rel_blk releases a fixed-length memory block 23 ret_int returns from an interrupt handler - ret_wup returns from an interrupt handler and wakes up a task - get_ver gets the rx78k/iv version number 25 act_cyc controls activation of a cyclic handler. 26 iact_cyc controls activation of a cyclic handler. [issues from interrupt handler] -
74 [memo]
75 appendix 4 example of cyclic handler coding when creating a cyclic handler, be careful about the following points. (1) the cyclic handler can be mapped in the 1mb memory space. (large model only) (2) the cyclic handler is invoked with the br rg command from the timer dispatch routine. for this reason, it is handled in the same manner as an interrupt handler; therefore, the system calls that can be issued are only the i _ ? system calls. however, the ?i _ ? system calls targeting cyclic handlers cannot be issued from a cyclic handler. (3) after ending the cyclic handler processing, be sure to return to the timer dispatch routine ??tm_ret?. please code the cyclic handler processing as follows: (4) when switching to another register bank in the cyclic handler, return to the original register bank first before returning to the timer dispatch routine. (5) in the timer dispatch routine, the ?rg7, rg6, rg5, rp1, and rp0? registers are stored on the stack when interrupted. therefore, when using the ?rg4, rp3, and rp2? registers in the cyclic handler, please restore the value to the original one when returning to the timer dispatch routine. public [cyclic handler address] extern ?tm_ret [cyclic handler address]: [cyclic handler processing] br !?tm_ret public cyc_ptr extrn ?tm_ret cyc_ptr: push psw sel rb6 push rp2 cyclic handler processing pop rp2 pop psw br !?tm_ret ? (4) ? (5) ? (5) ? (4) ? (3)
76 [memo]
77 appendix 5 estimating memory capacity (large model) on rx78k/iv, it is possible to set an area capable of generating objects (tcb, event flag, semaphore, mail box, memory pool, and cyclic handler) in an arbitrary area. however, the area of 20 bytes starting from the start address of the user-set area is an os management area. each object management area is secured from there on. then the 12 bytes to 64 bytes ready queue area is secured. the ready queue area varies depending on the specified number of task priorities. each object can be generated in up to 255 units. calculation of the object size (data) for a system running rx78k/iv is shown below. example where number of objects to be created is: task : 20 event flag : 5 semaphore : 4 mail box : 3 cyclic handler : 2 memory pool : 2 (number of memory blocks: 5, size of 1 memory block: 16 bytes) (number of memory blocks:10, size of 1 memory block: 32 bytes) the task priority can be used up to 10 levels. the top address (?objhead) of the os management area shall be 0ff700h. ram size used os management table ready queue tcb event flag semaphore mail box cyclic handler p ppppppp 228 (bytes) = 20 4 u 10 10 u 10 4 u 5 4 u 4 4 u 3 10 u 2 ram size used memory pool pp 408 (bytes) = 4 16 u 5 4 32 u 10 total 228 408 = 636 (bytes)
appendix 5 estimating memory capacity (large model) 78 0ffeffh 0ff97ch 0ff7bch 0ff7b0h 0ff7a0h 0ff78ch 0ff714h (?objhead) 0ff700h stack area per each task memory pool mail box semaphore event flag tcb area os management table 16 bytes* 5+4 bytes 32 bytes*10+4 bytes 4 bytes*3 4 bytes*4 4 bytes*5 0ff778h cyclic handler 10 bytes*2 10 bytes*10 20 bytes ready queue 4 bytes*10 0ff954h
79 appendix 6 estimating memory capacity (small model) on rx78k/iv, it is possible to set an area capable of generating objects (tcb, event flag, semaphore, mail box, memory pool, and cyclic handler) in 256 bytes of the internal ram area 0f700h through 0f7ffh. however, the area of 14 bytes starting from 0f700h is an os management area. each object management area is secured from there on. then the 6 bytes to 32 bytes ready queue area is secured. the ready queue area varies depending on the specified number of task priorities. each object can be generated in up to 255 units. calculation of the object size (data) for a system running rx78k/iv is shown below. example where number of objects to be created is: task : 20 event flag : 5 semaphore : 4 mail box : 3 cyclic handler : 2 memory pool : 2 (number of memory blocks: 5, size of 1 memory block: 10 bytes) (number of memory blocks: 10, size of 1 memory block: 6 bytes) the task priority can be used up to 10 levels. the top address (?objhead) of the os management area shall be 0f700h. ram size used os management table ready queue tcb event flag semaphore mail box cyclic handler p ppppppp 154 (bytes) = 14 2 u 10 8 u 10 2 u 5 2 u 4 2 u 3 8 u 2 ram size used memory pool pp 94 (bytes) = 2 10 u 3 2 6 u 10 total 154 94 = 248 (bytes)
appendix 6 estimating memory capacity (small model) 80 0f7f8h 0f786h 0f780h 0f778h 0f76eh 0f70eh (?objhead) 0f700h stack area per each task memory pool mail box semaphore event flag tcb area os management table 10 bytes* 3+2 bytes 6 bytes*10+2 bytes 2 bytes*3 2 bytes*4 2 bytes*5 0f75eh cyclic handler 8 bytes*2 8 bytes*10 14 bytes ready queue 2 bytes*10 0f7e4h 0feffh
81 appendix 7 standby function the rx78k/iv places the cpu in the halt status as default assumption when there are no longer any selected tasks. in some systems, however, the stop mode or idle mode may be preferred to the halt mode. with the rx78k/iv, therefore, the standby processing is decided by the user. the supplied sample of the standby block, nuc_idle.asm, is shown below. sample nuc_idle.asm public @nuc_idl cseg base @nuc_idl: mov x, stbc and x, #0f0h shr x, 1 mov a, #0 movw bc, #hlt_tbl addw bc, ax br bc ; hlt_tbl: ei mov stbc, #00000001b ; set halt mode (fxx/2) ret ; nop nop ; ei mov stbc, #00010001b ; set halt mode (fxx/4) ret ; nop nop ; ei mov stbc, #00100001b ; set halt mode (fxx/8) ret ; nop nop ; ei mov stbc, #00110001b ; set halt mode (fxx/16) ret ; end remark the above is the file supplied as a sample. this file is a routine that can be executed by the rx78k/iv even if the internal system clock is changed in the user system.
appendix 7 standby function 82 the following sample indicates an example of changing the internal system clock if the clock is fixed in the user system. sample 1 remark the above sample is for when the internal system clock is fixed. however, do not change symbol name @nuc_idl. the default standby mode of the rx78k/iv is halt. to change the mode, refer to the following: ? to change from halt mode to stop mode change standby control register (stbc) value before change after change mov stbc, #00000001b o mov stbc, #00000010b ? to change from halt mode to idle mode change standby control register (stbc) value before change after change mov stbc, #00000001b o mov stbc, #00000011b for the standby control register (stbc), refer to the users manual of the device. public @nuc_idl cseg base @nuc_idl: ei mov stbc, #00000001b ; set halt mode (fxx/2) ret ; end
83 appendix 8 maximum stack size used by each system call the stack area of the task that has issued the system call is used as a stack area used for system call processing. therefore, the stack size of each system call must be determined taking into consideration the stack size used for the user task and the maximum stack size of the system call. the stack area which is used for the interrupt handler and the timer processing can be set to an arbitrary address. however, when an interrupt occurs, this task stack area uses 4 bytes. the maximum stack size for the processing of each system call when the program is described in assembly language is as shown in the following table.
appendix 8 maximum stack size used by each system call 84 maximum stack size used (bytes) large model small model register bank used register bank used 1 2 to 7 1 2 to 7 sta_tsk 28 8 24 8 ext_tsk 28 8 24 8 ter_tsk 28 8 24 8 chg_pri 28 8 24 8 ichg_pri 22 22 19 19 rot_rdq 28 8 24 8 irot_rdq 19 19 14 14 tsk_sts 28 8 24 8 slp_tsk 28 8 24 8 wai_tsk 28 8 24 8 wup_tsk 28 8 24 8 iwup_tsk 18 18 16 16 can_wup 28 8 24 8 set_flg 28 8 24 8 iset_flg 23 23 17 17 clr_flg 28 8 24 8 wai_flg 28 8 24 8 cwai_flg 28 8 24 8 pol_flg 28 8 24 8 cpol_flg 28 8 24 8 sig_sem 28 8 24 8 isig_sem 21 21 16 16 wai_sem 28 8 24 8 preq_sem 28 8 24 8 snd_msg 28 8 24 8 isnd_msg 23 23 20 20 rcv_msg 31 11 26 10 prcv_msg 28 8 24 8 pget_blk 28 8 24 8 rel_blk 28 8 24 8 ret_int 24 24 20 20 ret_wup 24 24 20 20 get_ver 28 8 24 8 act_cyc 28 8 24 8 iact_cyc 10 10 9 9 timer processing 24 17 20 14 remark including 4 bytes (pc, psw) used at interrupting. system call name
85 appendix 9 restrictions on symbol names rx78k/iv uses the following symbols as public symbols. therefore, make sure that the same names are not used on tasks and interrupt handlers. ?objhead brproc ?sysrt ?qin ?qin1 ?qout ?qout1 ?canc1 ?cnsav ?itdsp ?tmdsp ?tkdsp ?tm_ret x_serial bittbl ent_tbl sys_inf rdyqtp az_arg wtcbh wtcbt runtcb timnst wqlnkp retdata pribit cnftblp tranos bittbl end_intsys ?db_tkds end_itdsp ?db_itds @nuc_idl system call names
86 [memo]


▲Up To Search▲   

 
Price & Availability of RX78K4

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X