background image

22

CHAPTER 3  Overview of the Standard I/O Library

3.2

Incorporating the Standard I/O Driver

When using the standard I/O library, you must develop your own code (I/O driver) for 
the target system. The driver inputs and outputs individual characters using the actual 
hardware.

Incorporating the standard I/O driver

Follow the specifications listed below when creating an I/O driver.

Input driver interface

Output driver interface

Programs in the standard I/O library do not issue system calls for exclusive control or 
waiting on events. If required, issue system calls from the program that calls the function 
or from the I/O driver.

Item

Description

Input

None

Output

AL:  Input character code
In case of an error, return EOF (-1).

Registration method

Store the entry address of the input driver (24-bit 
address) in the four bytes commencing from 
label “_stdin”.

Register saving

Save all except the AL and AH registers and T, 
N, Z, V, and C.

Item

Description

Input

@sp+4 (2 bytes)  Output character code

Output

AL:  Output character code
In case of an error, return EOF (-1).

Registration method

Store the entry address of the output driver (24-
bit address) in the four bytes commencing from 
label "_stdout".

Register saving

Save all except the AL and AH registers and T, 
N, Z, V, and C.

*

Содержание F2MC-16L Series

Страница 1: ...FUJITSU SEMICONDUCTOR CONTROLLER MANUAL F2MC 16L 16LX 16 16H 16F µITRON 2 01 SPECIFICATIONS COMPLIANT SOFTUNE REALOS 907 USER S GUIDE CM42 00325 3E ...

Страница 2: ... ...

Страница 3: ...FUJITSU LIMITED F2MC 16L 16LX 16 16H 16F µITRON 2 01 SPECIFICATIONS COMPLIANT SOFTUNE REALOS 907 USER S GUIDE ...

Страница 4: ... ...

Страница 5: ...refer to the manual of each product Trademarks TRON is an abbreviation of The Realtime Operating System Nucleus ITRON is an abbreviation of Industrial TRON µITRON is an abbreviation of Micro Industrial TRON SOFTUNE is a trademark of FUJITSU LIMITED REALOS REALtime Operating System is a trademark of FUJITSU LIMITED Microsoft Windows and Windows NT are registered trademarks of Microsoft Corporation ...

Страница 6: ...r 2 Developing Application Systems Describes how to develop application systems using REALOS 907 Chapter 3 Overview of the Standard I O Library Introduces the standard I O library Chapter 4 Program Reference for the Standard I O Library Lists standard I O library details in reference format Appendix Summarizes the REALOS 907 upgrade and describes how to generate and run the sample system ...

Страница 7: ...ffect to the public and could lead directly to death personal injury severe physical damage or other loss i e nuclear reaction control in nuclear facility aircraft flight control air traffic control mass transport control medical life support system missile launch control in weapon system or 2 for use requiring extremely high reliability i e submersible repeater and artificial satellite Please not...

Страница 8: ...cation system creation procedure and precautionary information on system use F2MC 16L 16LX 16 16H 16F Softune REALOS 907 Kernel Manual FR F2MC Family Softune REALOS FR 907 896 Configurator Manual This manual contains information required to create user programs This manual explains the REALOS Configurator functions and how to use them FR V FR F2MC Family Softune REALOS Analyzer Manual This manual ...

Страница 9: ...oft Windows NT Server network operating system Version 4 0 are abbreviated to Windows NT 4 0 The Microsoft Windows 2000 Professional operating system the Microsoft Windows 2000 Server operating system the Microsoft Windows 2000 Advanced Server operating system and the Microsoft Windows 2000 Datacenter Server operating system are abbreviated to Windows 2000 The Microsoft Windows XP Professional ope...

Страница 10: ...vi ...

Страница 11: ...e 15 2 9 Configuring and Running a System 17 CHAPTER 3 Overview of the Standard I O Library 19 3 1 Structure of the Standard I O Library 20 3 2 Incorporating the Standard I O Driver 22 3 3 Example of Creating a Standard I O Driver 23 3 4 How to Use the Standard I O Library 25 CHAPTER 4 Program Reference for the Standard I O Library 27 4 1 Standard I O Function Interface Putchar 28 4 2 Standard I O...

Страница 12: ...viii ...

Страница 13: ...1 CHAPTER 1 Notes on Operation This chapter explains a number of important points on using Softune REALOS 907 1 1 Notes on Programming 1 2 Notes on Hardware ...

Страница 14: ...by the kernel between 190H and 19fH in the general purpose register area delayed interrupt control register interrupt control register interrupt vector table and OS data area These areas are used by the kernel The user does not need to create a program containing the interrupt vector table and OS initial data These are generated as programs by the configurator during system configuration After a r...

Страница 15: ...eparate stacks must be provided for each task Task stack areas must be maintained at all times except when the task is in the DORMANT state Do not manipulate stack areas belonging to other tasks or use as the stack for different tasks All tasks go to the DORMANT state after the OS is initialized To set tasks to the READY state tasks must be started by calling the sta_tsk system call in the initial...

Страница 16: ... module One interrupt is required to operate the system clock Normally an interval timer is used to generate fixed period interrupts An interval timer internal to the MCU can also be used The OS uses the delayed interrupt module Do not specify a user program in the delayed interrupt vector table The performance of the OS improves if the system stack and kernel management data areas are located in ...

Страница 17: ...REALOS 907 2 1 Softune REALOS 907 Products 2 2 Directory Configuration 2 3 Preparing a Development Environment 2 4 Installing Softune REALOS 907 2 5 Programs Required for an Application System 2 6 Development Steps 2 7 Developing User Programs 2 8 Developing a User Defined Module 2 9 Configuring and Running a System ...

Страница 18: ...oducts consist of the REALOS 907 realtime OS programs included in provided media and the manual set REALOS 907 products Figure 2 1 shows the REALOS 907 products Figure 2 1 REALOS 907 Products Available on CD ROM Kernel Manual User s Guide Configurator Manual REALOS 907 Analyzer Manual ...

Страница 19: ...the function and operation of the Softune REALOS 907 configurator Refer to this manual when configuring an application system User s Guide This manual The manual describes the procedure for generating application systems and important points regarding the overall system The manual also describes the debugger macro commands used when debugging Softune REALOS 907 applications using the debugger Anal...

Страница 20: ...for configurator executable file lib 907 Storage directory for help file rtos 907 knl syslib rcf Directory that configurator uses Directory for standard I O liblary creation smpsys smpdrv scdef inc scdef h stdio lib OS definition file for assembly language OS definition file for C language Standard I O library r97ins asm 1 Kernel source file stdio Strage directory for sample system1 Strage directo...

Страница 21: ...e on the host computer Support tools required for development Table 2 3 lists the cross development tools and emulator required for developing REALOS 907 application programs Table 2 3 Support Tools Required for Development Tool Tool name Cross development tools Fujitsu C compiler fcc907s Assembler fasm907s Linkage kit Linker flnk907s Librarian flib907s Object tool f2ms f2is f2es m2bs m2es m2is m2...

Страница 22: ... EXE from root directory of the installation disks on Windows Follow the instructions displayed by the installation program and specify the directory for installing REALOS 907 The installation program installs the system under the specified directory Installing all files requires about 40MB of disk space Specify the drive containing the disk in the underlined section Note Do not use double byte co...

Страница 23: ...Tasks Tasks are the basic units of an application program Application processing is performed by the operation of multiple tasks Interrupt handler Executed on generation of an interrupt Interrupt handlers are used to receive processing requests from peripheral devices and notify these requests to tasks Timer handlers These consist of cyclic handlers which are activated at fixed intervals and alarm...

Страница 24: ...evelopment environment Configure the REALOS 907 development environment on a host computer Develop and debug programs Design and develop the task and handler programs based on the system design specifications Perform independent debugging of tasks and handlers C compiler assembler linkage kit simulator debugger Configure system Configure the independently developed task and handler programs as a R...

Страница 25: ... the structure of the target system etc Prepare the development environment Design the system Develop the programs on the host computer Perform system debugging on the target hardware Load the application system into ROM Operate the system environment Program development Program debugging Configure system Check operation Run system Debug system Load in ROM Operate Check operation NG OK OK NG ...

Страница 26: ...nization and communication will be performed between the tasks and handlers To undertake these steps you need to understand the functions provided by REALOS 907 For more information see the Softune REALOS 907 Kernel Manual Tasks Initialize handler Interrupt handlers Exception handlers CPU exception handler system call exception handler Timer handler cyclic handlers alarm handlers Develop the task ...

Страница 27: ...ed by the definition statement in the configurator Refer to Softune REALOS Configurator Manual for more information The reset entry routine performs the following processing Initialize the processor Set the operating mode Set the stack pointer SP When using an external bus set temporarily in internal RAM until the operating mode is set Initialize the peripheral devices Initializes those peripheral...

Страница 28: ...on frequency of 16MHz or more In the configurator assign the interval timer interrupt handler to the corresponding interrupt vector number Initialize user devices Initialize the devices used by the user program You can also uwse this routine to perform system initialization by using software as well as hardware Start tasks As all tasks are initially in the DORMANT state start the initial tasks fro...

Страница 29: ... configurator Execute configuration processing after defining the configuration settings This generates the kernel initialization data and vector table based on these settings Next the REALOS 907 kernel module and user program are linked and the absolute format object program is generated for the REALOS 907 application system See Softune REALOS Configurator Manual for details Running the System Do...

Страница 30: ...9 Processing Steps When REALOS 907 Starts Kernel initialization processing Reset entry routine Kernel data initialization routine Initialize handler User tasks Perform the required task Other user initialization processing Task Maximum priority Semaphore Task Task Handler Handler Eventflag Mailbox Memorypool Peripheral device Peripheral device and handler initialization Reset Start ...

Страница 31: ...es such as consoles and provides an interface for data communication and character data I O for debug information for example This chapter describes the structure of the standard I O driver how to use the driver and related information 3 1 Structure of the Standard I O Library 3 2 Incorporating the Standard I O Driver 3 3 Example of Creating a Standard I O Driver 3 4 How to Use the Standard I O Li...

Страница 32: ... functions File format of the standard I O library The standard I O library files are located in the syslib directory Table 3 1a lists the files Table 3 1a Standard I O Library Files Function Description putchar Output a single character getchar Input a single character printf Output a formatted text string File Contents stdiol lib Standard I O Library Large model stdiom lib Standard I O Library M...

Страница 33: ...1b lists the output segments for the standard I O library Table 3 1b Standard I O Library Segments Area Segment Segment Attribute Remarks Variable data area including initial values DCONST DSEG Initial value data DINIT DSEG Entity Variable data area no initial values DVAR DSEG Code area CSEG CSEG ...

Страница 34: ...n events If required issue system calls from the program that calls the function or from the I O driver Item Description Input None Output AL Input character code In case of an error return EOF 1 Registration method Store the entry address of the input driver 24 bit address in the four bytes commencing from label _stdin Register saving Save all except the AL and AH registers and T N Z V and C Item...

Страница 35: ...IGN 2 Define entry export _stdout _stdin _stdout data l chrout _stdin data l chrinp Serial data transmitter receiver_iSDTR_FMB89371 RCLR equ H 40 error reset RMODE equ B 01001111 mode 8251 compatible RMODE1 equ B 01000010 mode 8251 compatible RBOUD equ B 00000010 9600bps RCOMM equ B 00010101 receive transmit RSERR equ B 00111000 pattern of error RXRDY equ 1 status bit of receiver TXRDY equ 0 statu...

Страница 36: ...ETURN None ERROR CODE None export chrout chrout bbc i RS_CTRL TXRDY chrout Wait transmit ready mov a r0 mov i RS_DATA a Write data retp ALIGN 2 chrinp input 8bit data PARAMETER None RETURN AL h 0000 h 00FF input data h FFFF no data ERROR CODE None export chrinp chrinp bbc i RS_CTRL RXRDY chrinp_nod Wait receive ready mov a i RS_DATA Read data retp chrinp_nod movw a h ffff retp ALIGN 2 end Note The...

Страница 37: ...pushes the parameters being passed onto the stack After the function completes the calling program must restore the stack to its previous level When there is more than one argument push the arguments onto the stack in order from the right For value arguments push the 2 byte or 4 byte value onto the stack The number of bytes is determined by the type two bytes for the char and short int types and f...

Страница 38: ...with the C compiler include similar I O functions When using the I O functions provided with REALOS 907 use the librarian to exclude modules with the same name so as not to link the libraries provided with the C compiler by mistake Note The application will not run if you try to use both the I O functions provided with REALOS 907 and the I O functions provided with the C compiler As the printf mod...

Страница 39: ...e Standard I O Library This chapter provides a detailed description of three types of standard I O functions 4 1 Standard I O Function Interface Putchar 4 2 Standard I O Function Interface Getchar 4 3 Standard I O Function Interface Printf ...

Страница 40: ...d Output character code Return parameter ercd Output character code Normal completion EOF Error Description Outputs one character to the standard I O device The function returns the output character if the character is output normally If an error occurs the function returns EOF 1 Examples Assembler interface include scdef inc import _putchar mov a pushw a callp _putchar popw a C interface include ...

Страница 41: ...on Inputs one character from the standard I O device The function returns the input character if input completes normally If an error occurs the function returns EOF 1 Whether or not getchar echoes input characters and whether or not it waits for key input are determined by the operation of the input driver Examples Assembler interface include scdef inc import_getchar callp_getchar cbne a h 1a end...

Страница 42: ...ormat as follows control field l type control A control character that specifies the output format The following can be specified field A numeric value that specifies the number of characters to output in the output data The output data is not truncated if it requires more than the specified number of characters If the number starts with a zero 0 the leading spaces of the output data are filled wi...

Страница 43: ...a work area excluding the arguments and stack used by putchar Examples Assembler interface include scdef inc import_printf string data b data 02X 10 0 mov a dtb pushw a movl a string pushw ah pushw a callp _printf addsp 6 C interface include scdef h prog int c printf data d n data Control Character Type d Signed decimal u Unsigned decimal o Octal x Hexadecimal lower case letters X Hexadecimal uppe...

Страница 44: ...32 CHAPTER 4 Program Reference for the Standard I O Library ...

Страница 45: ...DIX The appendices summarize the REALOS 907 upgrade and describe how to generate and run the sample system Appendix A Program Description Appendix B Running the Sample System Appendix C Sample System Memory Map ...

Страница 46: ...ided frcfs exe DOS prompt version of the configurator Softune REALOS configurator add in REALOS provides the Softune REALOS configurator as an add in to Softune The following files are supplied SIRCF DLL configurator DLL Japanese SIRCFENU DLL configurator DLL English Kernel basic module The following are supplied in the kernel basic module r97ins asm and other files Kernel source basic version onl...

Страница 47: ...or users scdef_b h Header file for system calls For 1 bit eventflag scdef_w h Header file for system calls For 16 bit eventflag scdef_s inc Include file for system calls For F MC 16L 16LX 16 16H family scdef_f inc Include file for system calls For F MC 16F family There are definitions that describe system calls Object file for OS The following OS object file is supplied dbgfk obj Object file for O...

Страница 48: ...ed in the sample system smp1 prj Project file of sample system 1 for Workbench smp2 prj Project file of sample system 1 for Workbench These are the project files for constructing sample tasks and their system Refer to Appendix B Running the Sample system for the details ...

Страница 49: ...uired to view the operation of the sample system This appendix describes an example of the sample system that runs under Windows Configuration of the sample system Configure the sample system by making the connections and settings shown in Figure Ba below Instead of Hyperterm exe you can use any other communications software that can send and receive ASCII characters Figure Ba Sample System Enviro...

Страница 50: ...s mainly to sample 1 whose operation is more difficult to understand than sample 2 Figure Bb Sample Programs Install directory rtos bin lib 907 smpsys knl rcf smpdrv syslib smp1 smp1 wsp Storage directory for Sample1 work space file smp2 wsp Sample2 work space file Sample system1 Storage directory for smp2 Sample system2 Task a_tsk void While 1 cwai_flg FLG_1 printf s a_msg Higher priority Lower p...

Страница 51: ...used for the interval interrupt for the system clock count When a simulator is used each task is switching to the standby state in order unless simulation of the UART send enable interrupt has been set The sample program is recommended for operation with the emulator smp2 wsp The MB89371AH serial controller on the 16LX support board and MB89254H timer are used MB89371AH mb89371 asm communicates us...

Страница 52: ...y containing the sample system is accessed two project files are displayed Select smp1 wsp then click the Open button Figure Bd Open workspace dialog box Checking the configuration file To check or change the contents of the configuration file double click smp1 rcf which is registered as a project member The Set Configuration File dialog box opens The project members are listed as shown in Figure ...

Страница 53: ...41 APPENDIX B Running the Sample System Figure Be Project Member List ...

Страница 54: ...42 APPENDIX Figure Bf Set Configuration File Dialog Box ...

Страница 55: ...load module file Create a load module file absolute file Select Build from the Project menu to execute the build When the build is complete the completion message shown in Figure Bg is displayed in the output window Figure Bg Status when Build Complete ...

Страница 56: ...ng is started An example of debugging with the emulator debugger is described here Debugging with the emulator debugger requires the 16LX evaluation board a daughterboard and an ICE MB2140 series A memory map must have been specified for the emulator debugger Select Load target file from the Debug menu to load the sample program if it has not already been loaded Then select Reset of MCU from the D...

Страница 57: ... debugger to advance the program Select Watch from the View menu to open the watch window In the watch window right click to select Set from the context menu to open watch setup Set the variable to h A1 and click the OK button In the watch window right click to select Edit from the context menu to open variable editing Change the value to h 8B and click the OK button As soon as OK button is clicke...

Страница 58: ...ion breakpoints are expressed as bp1 and bp2 as illustrated in Figure Bk 1 Run the sample system to the point immediately before cwai_flg of a_tsk hereafter expressed as the point immediately before bp1 Run the sample system by clicking on the bp1 point shown in Figure Bk ...

Страница 59: ...ple system to the point immediately before bp2 again HyperTerminal will then display k 5 Repeat steps 3 and 4 above for output operation The data output by each task is set as follows a_tsk HELLO I AM A_TASK b_tsk hello i am b_task In step 5 the tasks look as if they are performing output operation alternately as shown in Figure Bl cwai_flg FLG_1 a_tsk printf s b_msg b_tsk set_flg FLG_1 a_tsk prin...

Страница 60: ...k as shown in Figure Bi depending on how the drivers have been designed This is because although the ID3 eventflag places the two tasks different in task priority in the wait state at the same time the tasks are scheduled by the FCFS First Come First Service system If a_tsk enters the wait state after b_tsk enters the wait state b_tsk restarts working first when the conditions for releasing the ta...

Страница 61: ...r based on polling is acceptable in the same program If any other processing task is executed however the serial driver based on polling cannot use remaining time efficiently If the driver processing speed is so fast that task switching takes longer for processing the driver must be based on polling To practice programming use sample 1 to write a program which uses a system call with tasks and han...

Страница 62: ... 2 HELLO I AM A_TASK hello i am b_task HELLO I AM A_TASK hello i am b_task HELLO I AM A_TASK hello i am b_task H ELLO I AM A_TASK hello i am b_task hello i am b_task HELLO I AM A_TASK hello i am b_task hello i am b_task HELLO I AM A_TASK hello i am b_task h ello i am b_task HELLO I AM A_TASK ...

Страница 63: ... must be used for a reference for the memory capacity required for REALOS 907 system operation Sample system memory map Figures Ca and Cb show the sample system memory maps Note Refer to Appendix B Kernel Code and Kernel Data in the Softune REALOS Configurator Manual for the procedure for allocating kernel data Figure Ca Sample System Memory Map ...

Страница 64: ...52 APPENDIX Figure Cb Sample System Memory Map Continued ...

Страница 65: ...53 INDEX INDEX The index follows on the next page This is listed in alphabetic order ...

Страница 66: ...nuals 7 N Notes on Hardware 4 Notes on Programming 2 P Preparingg a Development Environment 9 Printf 30 Processing steps from starting the system until the user tasks start 18 program 11 Program for starting Tasks and initializing the system clock 11 Program interface 25 Programs for handling abnormal conditions 11 Programs for handling normal processing 11 Programs Required for an Application Sys...

Страница 67: ...UCTOR CONTROLLER MANUAL SOFTUNE REALOS 907 October 2002 the third edition Published Edited FUJITSU LIMITED Electronic Devices Standardization Promoting Dept F2MC 16L 16LX 16 16H 16F USER S GUIDE µITRON 2 01 SPECIFICATIONS COMPLIANT ...

Страница 68: ... ...

Отзывы: