Home

THE 78000 GUIDE

image

Contents

1. 1 67 interrupt DESCRIPTION The interrupt keyword declares a function that is called upon a processor interrupt The function must be void and have no arguments If a vector is specified the address of an interrupt handler that calls the function is inserted in that vector The vector address is the offset of the vector from the start of the interrupt vector block 0x0000 The vector address must be in the range of 0x0000 to 0x003F Predefined vector definitions for popular members of the 78000 family are supplied see Installed files page 1 8 Constants for the various interrupt sources are defined in the 78000 specific include files io780xx h files If no vector is specified the user must provide an appropriate entry in the vector table preferably placed in the cstartup module for the interrupt function The run time interrupt handler takes care of saving and restoring processor registers and returning via the RETI instruction except for vector 3E 3F that returns with RETB Also register bank switching for interrupt handlers is supported See using keyword later in this chapter The compiler disallows calls to interrupt functions from the program itself It does allow interrupt function addresses to be passed to function pointers which do not have the interrupt attribute This is useful for installing interrupt handlers in conjunction with operating systems If a vector is specified with a value in the range of 0x004
2. Local or formal name never referenced was Non printable character xhh found in literal or character constant Old style K amp R type of function declarator Floating of range point constant out Illegal division float operation A formal parameter or local variable object is unused in the function definition It is considered as bad programming practice to use non printable characters in string literals or character constants Use Oxhhh to get the same result An old style K amp R function declarator was found This warning is issued only if the gA option is in use A floating point value is too large or too small to be represented by the floating point system of the target During constant arithmetic a zero by zero not allowed divide was found 2 182 pragma directive pragma directive summary pragma directives bitfields default bitfields reversed codeseg function banked function default function interrupt function monitor function non banked language default language extended memory constseg memory dataseg memory default memory near memory no_init memory saddr memory shortad warnings default warnings off warnings on in identifiers A command line option a command line option b command line option C command line option c command line option d command line option D command line option
3. executable code with optimisation with debug information A SD78K 0 Debugger Target Application Documented in Supplied with User supplied J this guide X SD78K 0 item Documented in the IAR Documented in the _ Assembler guide NEC SD78K 0 guide The text editor may be any standard ASCH editor such as WordStar BRIEF PMATE or EMACS The C compiler accepts C source files and produces code module files normally in the IAR proprietary Universal Binary Relocatable Object Format UBROF INTRODUCTION These code modules pass to the linker XLINK where they may be combined with modules created with the Assembler and library modules either supplied as standard or created previously by the user using the library manager XLIB XLINK and XLIB are supplied and documented as part of the IAR Assembler package The output of XLINK is either debuggable code for use in the C SPY Debugger or an alternative one or final executable code for use in the target application This executable code is in any one of many standard formats for use in emulators EPROM or ROM GETTING STARTED INSTALLATION This chapter shows you how to install all files from the installation disks supplied describes the installed files themselves and lists the file extensions used by the system Your should have at least 3 MB of disk space available to install the ICC7800
4. 2 128 strstr strstr string h Searches for a substring DECLARATION char strstr const char sl const char s2 PARAMETERS sl A pointer to the subject string s2 A pointer to the object string RETURN VALUE Result Value Successful A pointer to the first occurrence in the string pointed to by s1 of the sequence of characters excluding the terminating null character in the string pointed to by s2 Unsuccessful Null if the string was not found s1 if s2 is pointing to a string with zero length DESCRIPTION Searches one string for an occurrence of a second string 2 129 strtod strtod stdlib h Converts a string to double DECLARATION double strtod const char nptr char endptr PARAMETERS nptr A pointer to a string endptr A pointer to a pointer to a string RETURN VALUE Result Value Successful The double result of converting the ASCII representation of an floating point constant in the string pointed to by nptr leaving endptr pointing to the first character after the constant Unsuccessful Zero leaving endptr indicating the first non space character DESCRIPTION Converts the ASCII representation of a number into a double stripping any leading white space 2 130 strtol strtol stdlib h Converts a string to a long integer DECLARATION long int strtol const char nptr char endptr int base PARAMETERS nptr A pointer to a string endptr
5. Spans characters in a string Searches for a substring No functions various definitions including size_t NULL ptrdiff_t of fsetof etc INTEGRAL TYPES limits h No functions various limits and sizes of integral types FLOATING POINT TYPES float h No functions various limits and sizes of floating point types ERRORS errno h No functions various error return values ASSERT assert h assert 2 44 void assert int expression Checks an expression C LIBRARY FUNCTIONS REFERENCE This section gives an alphabetical list of the C library functions with a full description of their operation and the options available for each one The format of each function description is as follows Name memchr string h Header file Searches for a character in Description DECLARATION Declaration void memchr const void c size_t n PARAMETERS Parameters A pointer to an An int representina a A value of type size_t specifvina the size of each RETURN VALUE Return Result Value value Successfu A pointer to the first occurrence c inthe n characters pointed to bv s Unsuccessfu Null DESCRIPTION Full Searches for the first occurrence of a character in apointed to description memory of a aiven Both the sinale character and the characters in the obiect are unsianed 2 45 C LIBRRAY FUNCTION REFERENCE NAME The function name The function name is followed by the f
6. _args may be used only inside function definitions For an example of the use of _args see the file stdarg h CHARACTER The character has been added to the set of valid characters in identifiers for compatibility with DEC VMS C USE OF SIZEOF AT COMPILE TIME The ANSI specified restriction that the sizeof operator cannot be used in i i f and e1if expressions has been eliminated 2 35 GENERAL C LANGUAGE EXTENSIONS 2 36 GENERAL C LIBRARY DEFINITIONS INTRODUCTION The ICC C Compiler package provides most of the important C library definitions that apply to PROM based embedded systems These are of three types Standard C library definitions for use in user programs These are documented in this chapter CSTARTUP the single program module containing the start up code Intrinsic functions used only by the compiler to perform low level operations which cannot be performed by in line code Intrinsic functions have names beginning with to distinguish them from other functions Since they are not to be used in application programs they are not documented LIBRARY OBJECT FILES For each combination of configuration and mode there is a single library object file containing all the library definitions The linker includes only those routines that are required directly or indirectly by the user s program Most of the library definitions can be used without modification that is directly
7. memory constseg Directs constants to the named segment by default SYNTAX fpragma memory constseg seg_name DESCRIPTION This directive directs constants to the named segment by default It is an alternative to the memory attribute keywords The default may be overridden by the memory attributes The segment must not be one of the compiler s reserved segment names as listed in Assembly language interface page 1 93 1 85 memory near memory dataseg Directs variables to the named segment by default SYNTAX pragma memory dataseg seg_name DESCRIPTION This directive directs variables to the named segment by default The default may be overridden by the memory attributes No initial values may be supplied in the variable definitions Up to 10 different alternate data segments can be defined in any given module You can switch to any previously defined data segment name at any point in the program Alternate segments will not be initialised by cstartup EXAMPLES filel c extern void function void fpragma memory dataseg MYSEG int variable in segment MYSEG tpragma memory default void main void function file2 c fpragma memory dataseg MYSEG extern int variable in segment MYSEG fpragma memory default 1 86 memory dataseg void function variable 1 Leaving out the pragma in file2 c will cause the linker to give the warning Type
8. Sets random number sequence DECLARATION void srand unsigned int seed PARAMETERS seed An unsigned int value identifying the particular random number sequence RETURN VALUE None DESCRIPTION Selects a repeatable sequence of pseudo random numbers The function rand is used to get successive random numbers from the sequence If rand is called before any calls to srand have been made the sequence generated is that which is generated after srand 1 2 114 sscanf sscanf stdio h Reads formatted data from a string DECLARATION int sscanf const char s const char format PARAMETERS S A pointer to the string containing the data format A pointer to a format string Optional pointers to the variables that are to receive values RETURN VALUE Result Value Successful The number of successful conversions Unsuccessful 1 if the input was exhausted DESCRIPTION Operates exactly as scanf except the input is taken from the string s See scanf for details The function sscanf does not use getchar and so can be used even when getchar is not available for the target configuration Since a complete formatter demands a lot of space there are several different formatters to choose For more information see the chapter Configuration in the target specific section 2 115 strcat strcat string h Concatenates strings DECLARATION char strcat char sl const char s2 PAR
9. The Compiler will force variables of storage class auto to storgage class static The C compiler will create a segment named TEMP which holds the automatic variables TEMP can be located anywhere in memory When option d is active the compiled code is no longer reentrant 1 117 rr Suppress variable in register optimization SYNTAX rr DESCRIPTION The r option with modifier r informs the compiler to store back variables kept in registers to their memory location between statements The compiler will still keep the value in register s if possible This option modifier combination is necessary for debugging reason and it is not documented in the compiler sign on message This option must be specified together with the Y option of the linker when you use the SD78KO0 debugger from NEC 1 118 No 78000 SPECIFIC DIAGNOSTICS In addition to the error and warning messages described in Diagnostics page 2 155 the 78000 C Compiler has the following error message Error message 105 142 143 144 145 Language feature not implemented Bit fields SIGNED UNSIGNED LONG interrupt functions can only be void and have no arguments Too large negative or overlapping interrupt value in name Bad context for storage modifier storage class or function Bad context for function call modifier Suggestion Self explaining sub message See section Interrupt Functi
10. 149 Bad context for storage modifier storage class or function Bad context for function call modifier Unknown pragma identifier Extension keyword name is already defined by user expected Attempt to take address of sfr or bit variable Suggestion The no_init keyword can only be used to declare variables with static storage class That is no_init cannot be used in typedef statements or applied to auto variables of functions An active pragma memory no_init can cause such errors when function declarations are found The keywords interrupt banked non_banked or monitor can be applied only to function declarations An unknown pragma identifier was found This error will terminate object code generation only if the g enable type check compiler option is in use Upon executing fpragma language extended the compiler found that the named identifier has the same name as an extension keyword This error is only issued when compiler is executing in ANSI mode An sfr declared identifier must be followed by value The amp operator may not be applied to variables declared as bit or as sfr 2 175 DIAGNOSTICS No Error message 150 151 Illegal sfr or bit range for address Too many functions defined in a single module expected Illegal context for extended specifier Suggestion The address expression is not a valid bit or sfr address The
11. DESCRIPTION By default the compiler places variables in main volatile RAM and initializes them on start up The no_init type modifier causes the compiler to place the variable in non volatile RAM and not to initialize it on start up no_init variables are assumed to reside in bank 0 no_init variable declarations may not include initializers If non volatile variables are used it is essential for the program to be linked to refer to the non volatile RAM area For details see Non volatile RAM page 1 50 EXAMPLES no_init int settings 50 array of non volatile settings no_init int i 1 initializer included invalid 1 72 saddr saddr Storage modifier SYNTAX storage class saddr declarator DESCRIPTION By default the default storage class for any kind of variable except bit variables is near The saddr storage modifier may be used to override this Variables declared as saddr will be located in short address memory from OxFE20 to OxFELF EXAMPLES saddr int var 10 int var in saddr area initialised saddr char buffer 10 array in saddr area shortad Storage modifier SYNTAX storage class shortad declarator DESCRIPTION By default the default storage class for any kind of variable except bit variables is near The shortad storage modifier may be used to override this 1 73 shortad Variables declared as shortad will be located in short a
12. On processor reset execution passes to a run time system routine called cstartup which normally performs the following Initializes the stack pointer Initializes C file level and static variables Calls the user program function main cstartup is also responsible for receiving and retaining control if the user program exits whether through exit or abort The user may wish to modify cstartup for example to initialize special hardware before entry to main or to remove unwanted initialization of variables The overall procedure for modifying cstartup is as follows Make the required modifications to the assembler source of cstartup supplied by default in the file c iar icc78000 cstartup s26 and save it under the same name Copy one of the provided include files to devmodel inc The include files select the correct processor and the memory model you want Small memory model defmsv0 inc Banked memory model defmbvO inc By default the include files are in the directory c iar inc 1 55 CONFIGURATION Assemble the modified cstartup This will create a replacement object module file named cstartup r26 Add the new cstartup module to the appropriate run time library module replacing the original For example to add the new cstartup module to the simplest small memory model library use the command xlib def cpu 78000 rep mod cstartup cl7801s exit The library module c17801s will
13. which by default the linker places at a variable address Use R to place the code in a specific segment with a unique name chosen by the user This then allows the user to specify to the linker a fixed address for this particular segment S Optimizes for speed SYNTAX s 0 9 2 25 S DESCRIPTION The argument sets the level of optimization Value Level 0 No optimization 1 3 Fully debuggable 4 6 Some constructs not debuggable 7 9 Full optimization S Sets silent operation of compiler SYNTAX 25 DESCRIPTION By default the compiler issues introductory messages and a final statistics report Use S to inhibit these messages Note that error and warning messages are shown Sets the tab spacing SYNTAX tn 2 26 H DESCRIPTION By default the listing is formatted with a tab spacing of 8 characters Use t to set the spacing of the tab characters to between 2 and 9 characters default 8 T Lists active lines only SYNTAX T DESCRIPTION By default inactive source lines such as those in false i f structures are listed Use T to list active lines only U Undefines a symbol SYNTAX Usymb DESCRIPTION Usymb is equivalent to dtundef symb 2 27 W By default the compiler has the following pre defined symbols Symbol Value __IAR_SYSTEMS_ICC 1 __STDC__ 1 VER Compiler version number TID_ Target IDENT A EBLE lt Current
14. 1 60 1 117 1 118 1 97 1 96 1 44 1 26 1 17 1 73 2 105 1 97 1 101 1 101 1 102 1 102 1 103 1 103 1 104 1 104 1 105 1 105 1 106 1 106 1 107 1 107 1 108 1 108 INDEX RCODE 1 109 SHORTAD 1 109 TEMP 1 110 UDATAO 1 110 UDATAI1 1 111 WCSTR 1 111 WRKSEG 1 112 ZVECT 1 112 setjmp library function 2 109 setjmp h header file 2 41 sfr extended keyword 1 74 sfrp extended keyword 1 75 shared variable objects 2 153 shell for interfacing to assembler 1 93 shortad extended keyword 1 73 SHORTAD segment 1 109 signed keyword 2 150 sin library function 2 110 sinh library function 2 111 sizeof operator 2 35 small memory model 1 46 source files 1 9 1 12 1 18 path 1 19 sprintf library function 1 53 2 112 sqrt library function 2 113 srand library function 2 114 sscanf library function 1 54 2 115 stack size 1 51 stdarg h header file 2 41 stddef h header file 2 44 stdio h header file 2 41 stdlib h header file 2 41 strcat library function 2 116 strchr library function 2 117 strcmp library function 2 118 IX INDEX strcoll library function 2 119 running a program 1 26 strcpy library function 2 120 selecting a library file 1 24 strcespn library function 2 121 using pragma directive 1 28 string h header file 2 43 using additional memory 1 38 strlen library function 2 122 strncat library function 2 123 U strncmp library function 2 124 strncpy libra
15. 2 16 G Error buffer 500 a Constant index out of range arrindex c 5 WarninglL28 Constant index outside array bounds G Opens the standard input as source SYNTAX G DESCRIPTION By default the source is read from the source file of the specified name Use G to read the source directly from the standard input stream normally the keyboard The source filename is set to stdin c H Sets the object module name SYNTAX Hname DESCRIPTION By default the internal name of the object module is the source leafname If several modules have the same source leafname the identical object module names causes a duplicate modules error from the linker i This can arise for example when the source files are generated by a compiler pre processor Use H to specify an alternative object module name to overcome this problem 1 Lists included files SYNTAX i DESCRIPTION Use the i option to list include files By default they are not listed J Adds an include file search prefix SYNTAX Iprefix DESCRIPTION The compiler performs the following search sequence for each include file enclosed in angle brackets in a directive such as include lt file gt The filename prefixed by the argument of each successive I option if any K The filename prefixed by each successive path in the C_INCLUDE environment variable if any The filename alo
16. DECLARATION int isalpha int c PARAMETERS An int representing a character RETURN VALUE An int which is non zero if c is letter else zero DESCRIPTION Tests whether a character is a letter 2 72 iscntrl iscntrl ctype h Control code equality DECLARATION int iscntrl int c PARAMETERS c An int representing a character RETURN VALUE An int which is non zero if c is a control code else zero DESCRIPTION Tests whether a character is a control character 2 73 isdigit isdigit ctype h Digit equality DECLARATION int isdigit int c PARAMETERS An int representing a character RETURN VALUE An int which is non zero if c is a digit else zero DESCRIPTION Tests whether a character is a decimal digit 2 74 isgraph isgraph ctype h Printable non space character equality DECLARATION int isgraph int c PARAMETERS c An int representing a character RETURN VALUE An int which is non zero if c is a printable character other than space else zero DESCRIPTION Tests whether a character is a printable character other than space 2 75 islower islower ctype h Lower case equality DECLARATION int islower int c PARAMETERS An int representing a character RETURN VALUE An int which is non zero if c is lower case else zero DESCRIPTION Tests whether a character is a lower case letter 2 76 i
17. INDEX 1 28 1 79 1 62 1 79 1 79 1 81 1 81 1 82 1 82 1 83 1 84 1 84 1 85 1 85 1 86 1 87 1 87 1 88 1 89 1 90 1 91 1 91 1 92 2 35 2 6 2 5 2 7 2 8 2 7 1 114 2 8 d command line option 1 117 e command line option 2 10 F command line option 2 11 f command line option 2 10 G command line option 2 17 g command line option 2 11 H command line option 2 17 I command line option 2 18 i command line option 2 18 K command line option 2 19 L command line option 2 20 command line option 2 20 m command line option 1 115 mB 1 113 mb 1 113 mS 1 113 ms 1 113 O command line option 2 21 o command line option 2 21 P command line option 2 22 p command line option 2 22 q command line option 2 23 R command line option 2 25 r command line option 2 23 rr command line option 1 114 1 118 S command line option 2 26 s command line option 2 25 T command line option 2 27 t command line option 2 26 U command line option 2 27 INDEX v command line option 1 116 v0 1 113 vl 1 113 v2 1 113 v3 1 113 v4 1 113 v5 1 113 v6 1 113 V7 1 113 v8 1 113 W command line option 1 114 1 117 w command line option 2 28 X command line option 2 29 x command line option 2 29 y command line option 2 30 z command line option 2 31 __VER__ macro 2 33 _formatted_read library function 1 54 2 141 _formatted_write
18. Name Function c iar exe a 78000 exe 78000 Assembler see the IAR 78000 Assembler guide c iar exe xlib exe IAR Library Manager see the IAR 78000 Assembler guide c iar exe xlink exe IAR Linker see the IAR 78000 Assembler guide c iar exe pminfo exe IAR Protected Mode Analyser see the IAR 78000 Assembler guide c iar exe icc78000 exe 78000 C Compiler see 78000 Specific Command line options page 1 103 If you have installed the C SPY Debugger this sub directory will also contain c iar exe cs78000 exe the 78000 C SPY Debugger see the Using C SPY guide ETC FILES This sub directory contains the following miscellaneous files Name Function c iar etc emulator doc Documentation on supported emulators c iar etc xlink doc Additional information on the linker XLINK 1 11 GETTING STARTED Name c iar etc newclib doc c iar etc heap c c iar etc intwri c c iar etc sprintf c c iar etc printf c c iar etc frmwri c c iar etc frmrd c c iar etc sieve c Function Information on additional C library functions The source of the heap size control object module See Configuration page 1 43 The source of the minimal printf implementation as an example See C library functions reference page 2 45 The source of the standard sprintf as an example of va_arg use See C library functions reference page 2 45 The source of the standard printf as an example of va_arg u
19. When the error directive is found the compiler issues an error message and terminates 2 154 DIAGNOSTICS The diagnostic error and warning messages produced fall into six categories Command line error messages Compilation error messages Compilation warning messages Compilation fatal error messages o Compilation memory overflow message Compilation internal error messages In addition to these general error and warning messages any target specific error and warning messages are documented in the chapter Diagnostics COMMAND LINE ERROR MESSAGES Command line errors occur when the compiler finds a fault in the parameters given on the command line In this case the compiler issues a self explanatory message COMPILATION ERROR MESSAGES Compilation error messages are produced when the compiler has found a construct which clearly violates the C language rules such that code cannot be produced The ICC C Compiler is more strict on compatibility issues than many other C compilers In particular pointers and integers are considered as incompatible when not explicitly casted Compilation error messages are described in Compilation error messages in this chapter 2 155 DIAGNOSTICS COMPILATION WARNING MESSAGES Compilation warning messages are produced when the compiler finds a programming error or omission which is of concern but not so severe as to prevent the completion of compil
20. option e makes the extended keywords available and hence reserves them so that they cannot be used as variable names As pragma keywords These provide pragma directives which control how the compiler allocates memory whether the compiler allows extended keywords and whether the compiler outputs warning messages Asintrinsic functions These provide direct access to very low level processor details EXTENDED KEYWORDS SUMMARY The extended keywords provide the following facilities ADDRESSING CONTROL By default the address range in which the compiler places a variable or function is determined by the memory model chosen The program may achieve additional efficiency for special cases by overriding the default by using one of the storage modifiers near saddr shortad or function modifiers non banked banked 1 61 LANGUAGE EXTENSIONS I O ACCESS The program may access the 78000 I O system using the following data types sfr sfrp BIT VARIABLES The program may take advantage of the 78000 bit addressing modes by using the following data type bit NON VOLATILE RAM Variables may be placed in non volatile RAM by using the following data type modifier no_init INTERRUPT ROUTINES Interrupt routines may be written in C using the following keywords interrupt using monitor PRAGMA DIRECTIVE SUMMARY pragma directives provide control of extension features while remaining within the standar
21. 1 82 function interrupt EXAMPLES pragma function interrupt void process_int an interrupt function function monitor Makes function definitions monitor SYNTAX pragma function monitor DESCRIPTION This directive makes subsequent function definitions of monitor type It is an alternative to the function attribute monitor EXAMPLES fpragma function monitor void f2 Will make f2 a monitor function 1 83 function non_banked function non banked Makes function definitions non_banked SYNTAX pragma function non_banked DESCRIPTION This directive makes subsequent function definitions non_banked It is an alternative to the function attribute non_banked EXAMPLES fpragma function non_banked extern void f1 Identical to extern non banked void f1 language default Restores availability of extended keywords to default SYNTAX pragma language default DESCRIPTION This directive returns extended keyword availability to the default set by the e compiler option See 1 anguage extended 1 84 language extended language extended Makes extended keywords available SYNTAX fpragma language extended DESCRIPTION This directive makes the extended keywords available regardless of the state of the e compiler option It is an alternative to the e compiler option See Extended keyword reference page 1 65 for details
22. ADISO ADM EnableAD 1 now loop forever taking input when ready while 1 if ad_ready bufferLbuffindex read_data if buffindex buffsize process full buffer buf findex 0 simple processing discard data do_foreground_process The first line in the program is fpragma language extended enable use of extended keywords By default extended keywords are not available so you must include this directive before attempting to use any The pragma directive is described in the section pragma directive summary page 1 62 The second line is include lt io78P014 h gt include sfr definitions for IO registers The file i078P014 h includes definitions for all I O registers for the 78P014 microprocessor Inside this file all sfr registers are defined using the sfr extended keyword so if you use this or an alternative header file you will never need to use the sfr keyword directly 1 30 TUTORIAL The full list of C source header files for processor I O is given in Inc files page 1 13 The third line is bit AD_Ready IFOH 3 define bit variable This defines a bit variable AD_Ready to be bit number 3 of the location IFOH IFOH is one of the Interrupt request flag registers defined in the included header file Bit variables are described in Extended keyword reference page 1 65 COMPILING AND LINKING THE A D PROGRAM Compile and
23. For detailed information on choosing stack size see Stack size page 1 51 SELECTING A LIBRARY FILE Library selection involves two choices Memory model small or banked Processor type 7800X or 780XX See Memory model page 1 44 Processor type page 1 116 for more details on each of these choices Our tutorial program contains only a small amount of code and therefore requires only the small memory model The processor to compile for is the 78P014 The appropriate library file for this combination is c17801s See LIB files page 1 15 for details of the other library filenames 1 24 TUTORIAL CREATING A PROGRAM The first program is a simple program using just standard C facilities It repeatedly calls a function that increments a variable The loop program demonstrates how to compile link and run a program Using a text editor enter the source of the loop program int call_count 0 BRK KKKK KK KK KK KKK KK KKK KKK KK KK KK KK KK Start of code KKK KKK KKK KKK KKK KKK KK KKK KKK KKK KK KKK void do_foreground_process void just increment a variable call_count void main void eae 1 do_foreground_process Y Save the source as the file prog c 1 25 TUTORIAL COMPILING THE PROGRAM To compile the program enter the command icc78000 prog v2 ms The ms option selects the small memory model the v2 option selects the 78P014 If you are
24. Identifier signal storage class extern prototyped non_banked function returning xxx non_banked code pointer to prototyped non_banked function returning xxx void and having following parameter s storage class auto xxx int and having following parameter s storage class auto xxx int storage class auto xxx non_banked code pointer to non_banked function returning xxx void Initializes strings as variables SYNTAX ay 2 30 Z DESCRIPTION By default C string literals are assumed to be read only Use y to generate strings as initialized variables However arrays initialized with strings ie char c string are always treated as ordinary initialized variables Z Optimizes for size SYNTAX z 0 9 DESCRIPTION The argument sets the level of optimization Value Level 0 No optimization 1 3 Fully debuggable 4 6 Some constructs not debuggable 7 9 Full optimization See the file GLOBAL DOC for additional information 2 31 2 32 GENERAL C LANGUAGE EXTENSIONS INTRODUCTION The IAR C Compiler supports a number of extensions to the C language The majority are specific to the target processor and are therefore documented in the chapter Language extensions The remainder are common to all targets and hence are documented here COMPILER VERSION The macro __VER__ returns an integer constant containing the compiler version number in decimal format For exam
25. Sine Hyperbolic sine Square root Tangent Hyperbolic tangent GENERAL C LIBRARY DEFINITIONS NON LOCAL JUMPS setjmp h longjmp setjmp void longjmp jmp_buf env int val int setjmp jmp_buf env Long jump Sets jump VARIABLE ARGUMENTS stdarg h va_arg va_end va_list va_start type va_arg va_list ap mode void va_end va_list ap char va_list 1 void va_start va_list ap parmN INPUT OUTPUT stdio h getchar gets printf putchar puts scanf sprintf sscanf int getchar void char gets char s int printf const char format 4 int putchar int value int puts const char s int scanf const char format int sprintf char s const char format const char format int sscanf const char s Next argument in function call Ends reading function call arguments Argument list type Starts reading function call arguments Gets character Gets string Writes formatted data Puts character Puts string Reads formatted data Writes formatted data to a string Reads formatted data from a string 2 41 GENERAL C LIBRARY DEFINITIONS GENERAL UTILITIES stdlib h void abort void abort abs atof atoi atol calloc div exit free labs ldiv malloc rand realloc srand strtod strtol 2 42 int abs int j double atof const char nptr int atoi c
26. TB_STORE_AX_SP_L10 72 73 TB_LOAD_AXBC_SP_L10 74 75 TB_STORE_AXBC_SP_L10 76 77 TB_FUNC_ENTER_L10 78 79 TB_FUNC_DEALL_L10 7A TB TB_FUNC_LEAVE_L10 7C 7D TB_WRKSEG_PUSH_L10 TE TF TB_WRKSEG_POP_L10 BANKED MEMORY MODEL In the banked memory model selected by the mb or mB compiler switch the code area can be transparently on the C level extended with up to 256 blocks of memory while it is identical to the standard memory model in terms of variable allocation and initialisation Code block size can be up to 64K but the requirement to always have an accessible root block for practicular reasons usually limit blocks to 4 32K Function addresses are 3 bytes wide and mapped like the following Byte 2 Byte1 0 Bank number Offset logical address Vv Vv To mapping circuit To address data bus 1 48 CONFIGURATION Example A sample system uses a 16K root PROM and eight 16K PROM banks to create a system with up to 144K of code An I O port is used for the purpose of mapping the actual bank to execute Other ports may be used as shown in the file 107 s26 which contains the actual switching routines user configurable for other mapping hardware schemes In the sample system the root PROM was allocated to address 0000 0x7FFF which is most practical since 78000 programs fetch data at location 0x0000 after reset The root memory contains all vital intrinsic library routines i e support code like floating point arith
27. Valid but ambiguous initializers Constant array indexing out of range This includes many of the conditions which on other C Compilers can be detected only by using a separate lint utility The g option does not increase the size of the final code but does increase the compilation and unless the 0 modifier is used link times and object module size The A modifier enables warnings of the old style K amp R functions The 0 modifier inhibits the inclusion of type information in the object module and hence inhibits type checking by the linker Hence g0 does not increase the object module size or link time Note that objects in modules compiled without type information that is compiled without g A or with gO A are considered as totally typeless by the linker This means that there will never be any warning of a type mismatch from a declaration from a module compiled without type information even if the module with a corresponding declaration has been compiled with type information EXAMPLES The following examples illustrate each of these types of error Calls to undeclared functions Program void my_fun void int main void my_func mis spelt my_fun gives undeclared function warning return 0 2 12 Error my_func mis spelt my_fun gives undeclared function warning undecfn c 5 Warning 23 Undeclared function my_func assumed extern int Undeclared K amp R forma
28. a definition of variable of enum type with type undefined or a reference to undefined struct or union type ina function prototype or as a sizeof argument There was a case without any active switch statement interrupt function may not An interrupt function call was No Error message 64 Unknown size of variable object name 65 Too many errors encountered gt 100 66 Function name redefined 67 Tag name undefined 68 case outside switch 69 be referred or called 70 Duplicated case label nn 71 default outside switch 72 Multiple default within switch included in the program Interrupt functions can be called by the run time system only The same constant value was used more than once as a case label There was a default without any active switch statement More than one default in one switch statement 2 164 DIAGNOSTICS No Error message 73 Missing while in do while statement 74 Label name redefined 75 continue statement 76 break outside switch or iteration statement 77 Undefined label name 78 Pointer to a field not allowed struct int f 6 Invalid 79 Argument of binary operator missing 80 Statement expected Suggestion Probable cause is missing around multiple statements A label was defined more than once in the same function outside iteration There was a continue outside any active while do while or for state
29. as follows Length_modifier Use h before d i u x X or o specifiers to denote a short int or unsigned short int value before d i u x X or o specifiers to denote a long integer or unsigned long value L before e E f g or G specifiers to denote a long double value Conversion The result of each value of conversion is as follows Conversion Result d Signed decimal value j Signed decimal value 0 Unsigned octal value u Unsigned decimal value x Unsigned hexadecimal value using lower case 0 9 a f X Unsigned hexadecimal value using upper case 0 9 A F e Double value in the style d ddde dd E Double value in the style d dddE dd f Double value in the style ddd ddd g Double value in the style of f or e whichever is the more appropriate 2 98 printf Conversion Result G Double value in the style of F or E whichever is the more appropriate C Single character constant S String constant p Pointer value address n No output but store the number of characters written so far in the integer pointed to by the next argument character Note that promotion rules convert all char and short int arguments to int while floats are converted to double printf calls the library function putchar which must be adapted for the target hardware configuration The source of printf is provided in the file printf c The source of a reduced version that uses le
30. case letter 2 80 isxdigit isxdigit ctype h Hex digit equality DECLARATION int isxdigit int c PARAMETERS c An int representing a character RETURN VALUE An int which is non zero if c is a digit in upper or lower case else zero DESCRIPTION Test whether the character is a hexadecimal digit in upper or lower case that is one of 0 9 a f or A F 2 81 labs labs stdlib h Long absolute DECLARATION long int labs long int j PARAMETERS j A long int value RETURN VALUE The long int absolute value of j DESCRIPTION Computes the absolute value of the long integer j 2 82 Idexp Idexp math h Multiply by power of two DECLARATION double Idexp double argl int arg2 PARAMETERS argl The double multiplier value arg2 The int power value RETURN VALUE The double value of arg1 multiplied by two raised to the power of arg2 DESCRIPTION Computes the value of the floating point number multiplied by 2 raised to a power 2 83 Idiv Idiv stdlib h Long division DECLARATION ldiv_t ldiv long int numer long int denom PARAMETERS numer The long int numerator denom The long int denominator RETURN VALUE A struct of type 1div_t holding the quotient and remainder of the division DESCRIPTION Divides the numerator numer by the denominator denom The type Idiv_t is defined in stdlib h If the division is inexact the quotient is
31. conflict for external entry variable The generated executable file will not work as expected memory default Restores direction of objects to the default area SYNTAX pragma memory default DESCRIPTION This directive restores memory allocation of objects to the default area as specified by the memory model in use memory near Direct variables to the default segment by default SYNTAX pragma memory near DESCRIPTION This directive directs variables to the default data segment The default may be overridden by the memory attributes 1 87 memory near The default segment must be linked to coincide with the physical address of the 78000 RAM area see Configuration page 1 43 for details EXAMPLES fpragma memory no_init char buffer 1000 in uninitialized memory E pragma memory near int ijs default memory type Note that a non default memory pragma will generate error messages if function declarators are encountered Local variables and parameters cannot reside in any other segment than their default segment the stack memory no_init Direct variables to the NO_INIT segment by default SYNTAX fpragma memory no_init DESCRIPTION This directive directs variables to the no_init segment so that they will not be initialized and will reside in non volatile RAM It is an alternative to the memory attribute no_init The default may be overridden by the memory attributes The
32. constant 2 152 K amp R AND ANSI C LANGUAGE DEFINITIONS STRUCTURE AND UNION ASSIGNMENTS In K amp R C functions and the assignment operator may have arguments that are pointers to struct or union objects but not struct or union objects themselves ANSI C allows functions and the assignment operator to have arguments that are struct or union objects or pointers to them Functions may also return structures or unions struct s a b struct s declared earlier struct s f struct s parm declare function accepting and returning struct s a f b Le Call Ate 7 To further increase the usability of structures ANSI allows auto structures to be initialized SHARED VARIABLE OBJECTS Various C compilers differ in their handling of variable objects shared among modules The IAR C Compiler uses the scheme called Strict REF DEF recommended in the ANSI supplementary document Rationale For C It requires that all modules except one use the keyword extern before the variable declaration For example Module 1 Module 2 Module 3 int i extern int i extern int i int j 4 extern int j extern int j 2 153 K amp R AND ANSI C LANGUAGE DEFINITIONS elif ANSI C s new e1if directive allows more compact nested else if structures elif expression is equivalent to felse if expression endif error The error directive is provided for use in conjunction with conditional compilation
33. directory The assembler source may be assembled by the appropriate Micro Series assembler If the 1 or L option is also used the C source lines will be included in the assembly source file as comments The a and A options may not be used together b Makes object a library module SYNTAX b DESCRIPTION By default the object module is a program object module Use the b option to make a library object module instead C Specifies the interpretation of char SYNTAX C DESCRIPTION The ANSI standard specifies that the interpretation of char as unsigned char or signed char is implementation dependent By default the IAR C Compiler treats char as equivalent to unsigned char Use c to treat char as equivalent to signed char for compatibility with other compilers Note that the C Library is compiled without c so if c is used the type checking enabled by the g or r option may cause unexpected type mismatch warnings from the linker C C Enables nested comments SYNTAX C DESCRIPTION By default the compiler issues warnings on finding nested comments Use C to inhibit these warnings and allow comments to be nested to any level This is particularly useful for commenting out program sections that themselves contain comments D Defines a symbol SYNTAX Dsymb Dsymb xx DESCRIPTION The Dsymb option defines a symbol with the value 1 as if the line define sy
34. from the library object files supplied For many of these the source is optionally available The remainder are I O oriented routines such as putchar and getchar that you may need to customize for your target application For these the source is supplied as part of the standard installation The library object files are supplied having been compiled with the global type check option on gA 2 37 GENERAL C LIBRARY DEFINITIONS HEADER FILES The user program gains access to library definitions through header files which it incorporates using the include directive To avoid wasting time at compilation the definitions are divided into a number of different header files each covering a particular functional area letting the user include just those that are required It is essential to include the appropriate header file before making any reference to its definitions Failure to do this can cause the call to fail during execution or generate error or warning messages at compile time or link time LIBRARY DEFINITIONS SUMMARY This section lists the header files and summarizes the functions included in each Header files may additionally contain target specific definitions these are documented in the chapter Language extensions All library functions are concurrently reusable reentrant where stated CHARACTER HANDLING ctype h isalnum int isalnum int c Letter or digit equality isalpha int isalpha
35. int c Letter equality iscntrl int iscntril int c Control code equality isdigit int isdigit int c Digit equality isgraph int isgraph int c Printable non space character equality islower int islower int c Lower case equality isprint int isprint int c Printable character equality ispunct int ispunct int c Punctuation character equality isspace int isspace int c White space character equality 2 38 GENERAL C LIBRARY DEFINITIONS isupper int isupper int c isxdigit int isxdigit int c tolower int tolower int c toupper int toupper int c LOW LEVEL ROUTINES icclbutl h _formatted_read int _formatted_read const char line format va_list ap Kk const char _formatted_write in t_formatted_write const char format void outputf char SD _medium in char line format va_list ap Kk _medium in _write _smal in char format char S char format char ESDS void va_list ap void t _formatted_read const const char t_formatted_write const void outputf void void va_list ap t_formatted_write const void outputf void void p va_list ap MATHEMATICS math h acos asin atan double acos double arg double asin double arg double atan double arg Upper case equality Hex digit equality Converts to lower case Converts to upper case Reads formatted data Formats and writes data Reads formatted d
36. link the program as before icc78000 prog v2 ms xlink prog f 1nk780 r If you are going to debug the program you have to add the debugger specific command line options Debugging using C SPY icc78000 prog v2 ms r xlink prog f Ink780 r Debugging using SD78K 0 icc78000 prog v2 ms rr xlink prog f 1nk780 r Y ubr2xcof aout d26 4 RUNNING THE PROGRAM To run the program using C SPY or SD78K 0 please follow the instructions given in the User s Manual for the corresponding debugger 1 31 TUTORIAL ADDING AN INTERRUPT HANDLER We shall now extend the A D program by adding an interrupt handler The IAR C Compiler lets you write interrupt handlers directly in C using the interrupt keyword The interrupt we will handle is the A D conversion software interrupt The following is a complete listing of the interrupt program The lines that have been added to the A D program are marked with a vertical bar so as before just add these marked lines to the source of the serial program in your prog c file fpragma language extended enable use of extended keywords Finclude lt io078p014 h gt include sfr definitions for IO registers d Finclude lt in78000 h gt include for intrinsic functions bit AD_Ready IFOH 3 define bit variable mode register bits define ADISO 0x01 conversion channel 0 tdefine EnableAD 0x80 start A D conversion define buffsi
37. now have the modified cstartup instead of the original Note that XLINK allows you to test the modified cstartup before installing it the library by using the C option See the LAR 78000 Assembler guide for details 1 56 DATA REPRESENTATION DATA TYPES The 78000 C Compiler supports all ANSI C basic elements Variables are stored with the least significant part located at low memory address Byte variables are always tightly packed in memory and in structures Word variables instead are not packed because the NECs 78000 structure requires an even address alignment for any 16 bit data access Data type bit sfr sfrp char by default char using c option signed char unsigned char short int unsigned short unsigned int long unsigned long pointer Bytes 1 bit Oo He Be Be Be pw LY Range Notes 0 or 1 see Extended Keywords 0 to 255see Extended Keywords 0 to 65535 see Extended Keywords 0 to 255 equivalent to unsigned char 128 to 127 equivalent to signed char 128 to 127 0 to 255 32768 to 32767 0 to 65535 2147483648 to 2147483647 0 to 4294967295 0 to 65535 1 57 DATA REPRESENTATION Data type Bytes Range Notes float 4 1 18E 38 to 3 39E 38 double long double 4 1 18E 38 to 3 39E 38 by default same as float ENUM TYPE The enum keyword creates each object with the shortest integer type char int or 10ng required to contain its value BIT FIE
38. of an unexpected exit from a loop or switch Note that a switch without default is always considered by the compiler to be exitable regardless of any case constructs 2 179 DIAGNOSTICS No Warning message 23 24 25 26 27 28 Undeclared function name assumed extern int Static memory option converts local auto or register to static Inconsistent use of K amp R Suggestion A reference to an undeclared function causes a default declaration to be used The function is assumed to be of K amp R type have extern storage class and return int A command line option for static memory allocation caused auto and register declarations to be treated as static A K amp R function was called with a function varying number of varying number of parameters parameters Inconsistent use of K amp R function changing type of parameter For example myfunc 34 myfunc 34 6 Size of extern object name is unknown Constant index outside array bounds Hexadecimal escape sequence larger than char A K amp R function was called with changing types of parameters int argument float argument extern arrays should be declared with size There was a constant index outside the declared array bounds The escape sequence is truncated to fit into char 2 180 DIAGNOSTICS No Warning message Suggestion 30 Attribute ignored
39. on the command line itself To make long command lines more manageable and to avoid the MS DOS command line length limit f may be used to specify a command file from which the compiler reads command line items as if they had been entered at the position of the f option In the command file the items are formatted exactly as if they were on the command line itself except that multiple lines may be used since the newline character acts just as a space or tab character If no extension is included in the filename xc1 is assumed 2 10 F F Generates a formfeed after each listed function SYNTAX F DESCRIPTION Use F to include a formfeed after each function in the listing Enables global type check SYNTAX g A CO DESCRIPTION There is a class of conditions in the source that indicate possible programming faults but which by default the compiler and linker ignore The g option causes the compiler to issue warning messages for these conditions and also to include type information in the object file so that the linker will warn of them The conditions are Calls to undeclared functions Undeclared K amp R formal parameters Missing return values in non void functions Unreferenced local or formal parameters Unreferenced goto labels Unreachable code 2 11 1 ge Unmatching or varying parameters to K amp R functions Fundef on unknown symbols
40. option put C string literals into RAM in General command line options page 2 5 DATAO Uninitialized short address statics TYPE Read write DESCRIPTION Compiler only Holds static variables which are not to be zeroed on start up These will have been allocated by the compiler declared shortad or created shortad by use of the memory pragma or created manually from assembly language source 1 105 DATAI1 DATAI1 Uninitialized statics TYPE Read write DESCRIPTION Compiler only Holds static variables which are not to be zeroed on start up ECSTR Writeable string literals TYPE Read write DESCRIPTION Assembly accessible Holds writeable copies of C string literals when the compiler s y option is active See the description of the y option put C string literals into RAM in General command line options page 2 5 1 106 IDATAO IDATAO Initialized short address statics TYPE Read write DESCRIPTION Compiler only Holds static shortad variables which have been declared with explicit initial values Their initial values are copied over from the corresponding segment by CSTARTUP during initialization IDATAI Initialized statics TYPE Read write DESCRIPTION Compiler only Holds static variables which have been declared with explicit initial values Their initial values are copied over from the corresponding segment by CSTARTUP during initia
41. support the environment and usage for a given application Each feature of the environment or usage is handled by one or more configurable elements of the compiler packages as follows Feature Configurable element Memory model Compiler option linker option Memory location Linker command file Non volatile RAM Linker command file Stack size Linker command file cstartup module putchar and getchar functions Run time library module printf scanf facilities Linker command file Heap size Heap library module Initialization of hardware and memory cstartup module The following sections describe each of the above features in turn Note that many of the configuration procedures involve editing IAR files and you may want to make copies of the originals before beginning 1 43 CONFIGURATION RUN TIME LIBRARY The library file controls many of the configurable features of the system Two major features require alternative run time libraries for every combination Facilities Small memory model Banked memory model 7800X processors c17800s r26 c17800b r26 780XX processors c17801s r26 c17801b r26 By default the library files are in the directory c iar 1ib LINKER COMMAND FILE Two linker command files for the different memory models are available Small memory model c iar icc78000 1nk780 xcl Banked memory model c iar icc78000 1nk780b xcl To create a linker command file for a particular project the user fir
42. than can be represented in an unsigned integer A member of struct or union was redeclared There was a declaration of struct or union containing no members 2 161 DIAGNOSTICS No 43 44 45 46 47 48 49 50 51 52 53 54 Error message Suggestion Object cannot be initialized There was an attempted expected expected expected C expected expected expected expected expected Too many local variables and formal parameters max is 1024 Declarator too complex max is 128 and or Invalid storage class initialization of typedef declarator or struct or union member A statement or declaration needs a terminating semicolon There was a bad array declaration or array expression There was a missing colon after default case label or in operator The probable cause is a misformed for if or while statement The probable cause is a misformed for if or while statement or expression There was an invalid declaration There was an invalid declaration or initializer There was an invalid declaration or initializer Fatal The compiler limit was exceeded The declarator contained too many or An invalid storage class for the object was specified 2 162 DIAGNOSTICS No Error message 55 56 57 58 59 60 61 62 63 Suggestion Too deep block nesting ma
43. to float h d i orn short int as opposed to int O U OF X unsigned short int as opposed to unsigned int L e E g G or f long double operand as opposed to float 2 106 scanf Conversion The meaning of each conversion is as follows Conversion Meaning d Optionally signed decimal integer value j Optionally signed integer value in standard C notation that is is decimal octal 0n or hexadecimal 0xn 0Xn o Optionally signed octal integer u Unsigned decimal integer xX Optionally signed hexadecimal integer X Optionally signed hexadecimal integer equivalent to x f Floating point constant eEgG Floating point constant equivalent to f S Character string c One or field_width characters n No read but store number of characters read so far in the integer pointed to by the next argument p Pointer value address E Any number of characters matching any of the characters before the terminating For example abc means a b or c Any number of characters matching or any of the characters before the further terminating For example abc means a b orc Ps Any number of characters not matching any of the characters before the terminating For example abc means not a b or c 2 107 scanf Conversion Meaning Any number of characters not matching or any of the characters before the further terminating For example abc means not a b
44. xc1 in your project directory Before you edit the linker command file you need the following items of information about the target system and program requirements The locations of ROM and RAM For this tutorial use the following locations which are appropriate to a typical target system ROM 0x0000 to Ox7 FFF RAM OxFBOO to OxFEIF Short address RAM OxFE20 to OxFEDF If you are using C SPY you could actually specify any reasonable ROM and RAM addresses and C SPY will automatically simulate them If you are using SD78K 0 you have to take into consideration the ROM and RAM areas permitted in the real target device 1 23 TUTORIAL Whether the code will all fit in the ROM available which allows use of the most efficient small memory model The tutorial program is small and therefore it will all fit within the ROM specified above The amount of RAM required for the stack The tutorial program has few dynamic variables and no deep nesting of function calls therefore a 128 0x80 byte stack is sufficient Now edit your file c tutorial 1nk780 xcl using a text editor following the instructions given in the file to enter these items of information Note that these decisions are not permanent they can be altered later on in the project if the original choice proves to be incorrect or less than optimal For detailed information on configuring to suit the target memory see Memory location page 1 50
45. 0 C Compiler package INSTALLATION UNDER MS DOS Ensure your system has MS DOS 2 11 or higher Insert the installation disk into the floppy disk drive and type A INSTALL e The startup screen is displayed This is AR matea fustallatiom utility Ie oeler to ibstall AE Software please alues the followlag quest bom Eater to coutimie Esc of C to abort 1 5 GETTING STARTED Press 4 You will then be prompted to enter the path for installing the IAR subdirectories and files Now select poth to the root directory for IAE software It must specify driee letter followed by amd must start from drive root directory CA By default the files are installed in C IAR Edit the path or press to use the default The installation program then decompresses the contents of the installation disks prompting you for each additional disk 1 6 GETTING STARTED When decompression is complete you will see a display of the default paths for each sub directory into which the files will be installed You may edit any of the paths to suit your requirements You will not normally need to do this and this guide assumes you have chosen the defaults Press 4 to proceed If you already have some IAR files on the same paths for example because you are upgrading an existing installation you will be asked for confirmation before installation proceeds The final stage of inst
46. 0 to 0x007E the address of the function is inserted in the vector table for CALLT function calls Functions declared as CALLT accept parameters and may return values as any other function When the compiler option mS or mB is in use there might be a limitation on free resources in the call table area See Callt Library Function Calls page 1 47 In banked memory model it is highliy recommended to keep interrupt handlers in a separate file which should be compiled with the option RRCODE separated form other user functions This option will give the code segement generated the name RCODE which guarantees that interrupt handlers will not be located in banks but in root memory See Banked Memory Model page 1 48 1 68 interrupt EXAMPLES handler for external interrupt 0 interrupt 0x24 void ext_0 RQ S64 handler for timer AO interrupt interrupt void timer_A0 if P0 3 start_engine CALLT function call interrupt 0x40 int callt_function int param if param 0 return TRUE monitor Make function atomic SYNTAX storage class monitor function declarator DESCRIPTION The monitor keyword causes interrupts to be disabled during execution of the function This allows atomic operations to be performed such as operations on semaphores that control access to resources by multiple processes A function declared with monitor is equivalent to a normal funct
47. 45 c iar inc stdarg h c iar inc limits h c iar inc stdio h c iar inc stddef h c iar inc stdlib h c iar inc setjmp h c iar inc ctype h c iar inc assert h c iar inc errno h 1 13 GETTING STARTED Name c iar inc in78000 h c iar inc icclbutl h c iar inc iccext h c iar inc io 7800x h c iar inc io 801x h c iar inc io 8P014 h c iar inc io0 7802x h c iar inc i0 78p024 h c iar inc io0 804x h c iar inc i07 78p044 h Function The source header for intrinsic functions see Intrinsic functions page 1 63 The source header for use by printf c see ETC files page 1 11 The source header for internal library definitions not for use by user The C source header for I O addresses of the 7800X processor see Language extensions page 1 61 The C source header for I O addresses of the 7801X processor see Language extensions page 1 61 The C source header for I O addresses of the 78P014 processor see Language extensions page 1 61 The C source header for I O addresses of the 7802X processor see Language extensions page 1 61 The C source header for I O addresses of the 78P024 processor see Language extensions page 1 61 The C source header for I O addresses of the 7804X processor see Language extensions page 1 61 The C source header for I O addresses of the 78P044 processor see Language extensions page 1 61 1 14 GETTING STARTE
48. A pointer to a pointer to a string base An int value specifying the base RETURN VALUE Result Value Successful The long int result of converting the ASCII representation of an integer constant in the string pointed to by nptr leaving endptr pointing to the first character after the constant Unsuccessful Zero leaving endptr indicating the first non space character DESCRIPTION Converts the ASCII representation of a number into a long int using the specified base and stripping any leading white space If the base is zero the sequence expected is an ordinary integer Otherwise the expected sequence consists of digits and letters representing an integer with the radix specified by base must be between 2 and 36 The letters a z and A Z are ascribed the values 10 to 35 If the base is 16 the 0x portion of a hex integer is allowed as the initial sequence 2 131 strtoul strtoul stdlib h Converts a string to an unsigned long integer DECLARATION unsigned long int strtoul const char nptr char endptr base int PARAMETERS nptr A pointer to a string endptr A pointer to a pointer to a string base An int value specifying the base RETURN VALUE Result Value Successful The unsigned long int result of converting the ASCII representation of an integer constant in the string pointed to by nptr leaving endptr pointing to the first character after the constant Unsuccessful Zero leaving endptr ind
49. AMETERS sl A pointer to the first string s2 A pointer to the second string RETURN VALUE sl DESCRIPTION Appends a copy of the second string to the end of the first string The initial character of the second string overwrites the terminating null character of the first string 2 116 strchr strchr string h Searches for a character in a string DECLARATION char strchr const char s int c PARAMETERS An int representation of a character S A pointer to a string RETURN VALUE If successful a pointer to the first occurrence of c converted to a char in the string pointed to by s If unsuccessful due to c not being found null DESCRIPTION Finds the first occurrence of a character converted to a char ina string The terminating null character is considered to be part of the string 2 117 strcmp strcmp string h Compares two strings DECLARATION int strcemp const char sl const char s2 PARAMETERS sl A pointer to the first string s2 A pointer to the second string RETURN VALUE The int result of comparing the two strings Return value Meaning gt 0 sl lt s2 0 sl s2 lt 0 sl lt s2 DESCRIPTION Compares the two strings 2 118 streoll strcoll string h Compares strings DECLARATION int strcoll const char sl const char s2 PARAMETERS sl A pointer to the first string s2 A pointer to the second string RETURN VALUE The int res
50. An array type suitable for holding information needed by va_arg and va_end 2 139 va_start va_Start stdarg h Starts reading function call arguments DECLARATION void va_start va_list ap parmN PARAMETERS ap A pointer of type va_list to the variable argument list parmN The identifier of the rightmost parameter in the variable parameter list in the function definition RETURN VALUE See below DESCRIPTION A macro that initializes ap for use by va_arg and va_end 2 140 _formatted_read _formatted_read icclbutl h Reads formatted data DECLARATION int _formatted_read const char line const char kformat va_list ap PARAMETERS line A pointer to a pointer to the data to scan format A pointer to a pointer to a standard scanf format specification string ap A pointer of type va_list to the variable argument list RETURN VALUE The number of successful conversions DESCRIPTION Reads formatted data This function is the basic formatter of scanf _formatted_read is concurrently reusable reentrant Note that the use of _formatted_read requires the special ANSI defined macros in the file stdarg h described above In particular There must be a variable ap of type va_list There must be a call to va_start before calling _formatted_read There must be a call to va_end before leaving the current context The argument to va_start must be the formal parameter immediately to the
51. D Name c iar inc io 805x c iar inc io 7806x c iar inc defmsv0 7 c iar inc defmbv0 7 Function The C source header for I O addresses of the 7805X processor see Language extensions page 1 61 The C source header for I O addresses of the 7806X processor see Language extensions page 1 61 The assembler source header for small memory model and 7800X processors see the IAR 78000 Assembler guide The assembler source header for banked memory model and 780XX processors see the IAR 78000 Assembler guide LIB FILES This sub directory contains all library modules as follows Name Cc c C FILE TYPES iar lib cl7800s iar lib cl780l1s iar lib cl7800b iar lib cl7801b r26 r26 r26 r26 Function Library object modules for each combination of memory model S B and processors 7800X 7800X see Configuration page 1 43 The IAR C Compiler uses the following default file extensions to identify different types of file 1 15 GETTING STARTED Extension Type of file doc eXe s sh S26 inc XCI r26 a26 ASCII documentation MS DOS program C program source C header source Asm program source Asm include source Linker command files Object module Target program Target program with debug information Output from Text editor Text editor Text editor Text editor Text editor ICC78000 A78000 XLINK XLINK Input to Text
52. IAR C COMPILER FOR THE 78000 GUIDE DISCLAIMER The information in this document is subject to change without notice While the information contained herein is assumed to be accurate IAR Systems assumes no responsibility for any errors or omissions COPYRIGHT NOTICE No part of this document may be reproduced without the prior written consent of IAR Systems The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license Copyright 1994 IAR Systems AB Copyright 1994 NEC Electronics Europe GmbH TRADEMARKS C SPY ICC and Micro Series are trademarks of IAR Systems AB MS DOS is a trademark of Microsoft Corp UNIX is a trademark of Bell Laboratories MS DOS 16 Mbyte is a trademark of Rational Systems Inc Second edition July 1994 Part no ICC78000 2 IAR Systems AB Islandsgatan 2 P O Box 23051 S 750 23 UPPSALA SWEDEN ii ABOUT THIS GUIDE This guide describes how to install and use the IAR C Compiler for the NEC UPD78000 family of microprocessors This guide is divided into two parts the first part AR 78000 C Compiler describes those aspects of the C compiler that are specific to the 78000 The second part IAR C Compiler General Features describes features common to all IAR C Compilers IAR 78000 C COMPILER This part consists of the following chapters The Introduction describes the main features of the IAR C Com
53. ION Computes the sine of a number 2 110 sinh sinh math h Hyperbolic sine DECLARATION double sinh double arg PARAMETERS arg A double value in radians RETURN VALUE The double hyperbolic sine of arg DESCRIPTION Computes the hyperbolic sine of arg radians 2 111 sprintf sprintf stdio h Writes formatted data to a string DECLARATION int sprintf char s const char format PARAMETERS S A pointer to the string that is to receive the formatted data format A pointer to the format string The optional values that are to be printed under the control of format RETURN VALUE Result Value Successful The number of characters written Unsuccessful A negative value if an error occurred DESCRIPTION Operates exactly as printf except the output is directed to a string See printf for details sprintf does not use the function putchar and therefore can be used even if putchar is not available for the target configuration Since a complete formatter demands a lot of space there are several different formatters to choose For more information see the chapter Configuration in the target specific section 2 112 sqrt sqrt math h Square root DECLARATION double sqrt double arg PARAMETERS arg A double value RETURN VALUE The double square root of arg DESCRIPTION Computes the square root of a number 2 113 srand srand stdlib h
54. KO enter the command ubr2xcof sample d26 1 41 TUTORIAL The resulting output file is sample 1nk This module can be loaded into SD78KO You may follow the tutorial described in the SD78KO primer chapter 6 1 2 on page 6 3 ff The second tutorial is based on C program 78k0main c To compile the program 78k0main c enter the command icc 8000 78kOmain c v2 r The v2 option selects the uPD78P014 microcontroller as target device an the r option adds debug information to the output file To link the program enter the command xlink 78kOmain o 78kOmain f 1nk780 r The o option selects the debug output file name the f option selects the xlink command file 1nk780 and the r option adds debug information to the output file To convert the program to the debug format for SD78KO enter the command ubr2xcof 78k0main d26 The resulting output file is 78kOmain 1nk This module can be loaded into SD78KO You may follow the tutorial described in the SD78KO primer chapter 8 1 2 on page 8 4 ff 1 42 CONFIGURATION This chapter describes how to configure the C compiler for different requirements INTRODUCTION Across the range of applications of the 78000 microprocessor there is considerable variation of the hardware environment such as the amount of ROM and RAM and of the user program s requirements eg the amount of stack RAM This chapter describes how to configure the IAR C Compiler package to
55. LDS Bit fields in unions and structures can be specified to be based on any of the integral types signed unsigned char short or int This is an extension to ANSI C standard In expressions a bit field will have the same properties ie signed or unsigned and char short or int as the base type During declaration bit field variables are packed in elements of the specified type starting at the LSB position When a bit field declarator does not fit within the current element or if the size of the specified base type differs from the previous bit field base type a new element is allocated The example below shows the declaration of a number of bit fields in a structure names s struct char a l Put a in the LSB of a char element char b 5 b can be packed together with a char c 4 No room for c allocate a new element int d 3 Diffenetly sized type Allocate int element 1 58 DATA REPRESENTATION FLOATING POINT Floating point values are represented by 4 byte numbers in standard IEEE format In either case floating point values below the smallest limit will be regarded as zero and overflow gives undefined results 4 BYTE FLOATING POINT FORMAT The memory layout of 4 byte floating point numbers is 31 30 23 22 0 a The value of the number is 1 S 9 Exponent 127 1 Mantissa Zero is represented by 4 bytes of zeros The precision of the float operators and is app
56. Linkage of user code with assembly routines Long identifiers up to 255 characters Maximum compatibility with other IAR C Compilers 1 1 INTRODUCTION PERFORMANCE o Very fast compilation Memory based design avoiding temporary files or overlays Single executable C compiler program file Extensive type checking at compile time Extensive module interface type checking at link time LINT like checking of program source CODE GENERATION Selectable optimization levels for code speed and size Comprehensive output options including relocatable binary ASM ASM C XREF etc Easy to understand error and warning messages Compatibility with C SPY high level debugger simulator and emulator driver Support for over 20 emulator formats TARGET SUPPORT Small and banked memory models Flexible variable allocation including SFR SFRP and BIT types Interrupt functions requiring no assembly language A pragma directive to maintain portability while using 78000 extensions INTRODUCTION DEVELOPMENT SYSTEM STRUCTURE The following diagram shows how the IAR C Compiler is used as part of a complete Micro Series development system Text editor 78000 Series C 78000 Series Compiler Assembler C Source Assembler Source Object XLIB Librarian module Linker command file XLINK Linker
57. Modifiable lvalue required Suggestion An unexpected delimiter was encountered An unexpected delimiter was encountered An unexpected delimiter was encountered The evaluated expression yielded a result of the wrong type The evaluated expression yielded a result of the wrong type The evaluated expression yielded a result of the wrong type The evaluated expression yielded a result of the wrong type The evaluated expression yielded a result of the wrong type The expression result was not a memory address The expression result was not a variable object or was a const Prototyped function argument A prototyped function was called number mismatch with a number of arguments different from the number declared 2 171 DIAGNOSTICS No Error message Suggestion 124 Unknown struct or union An attempt was made to reference member name a nonexistent member of a struct or union 125 Attempt to take address of The amp operator may not be used on field bit fields 126 Attempt to take address of The amp operator may not be used on register variable objects with register storage class 127 Incompatible pointers There must be full compatibility of objects that pointers point to In particular if pointers point directly or indirectly to prototyped functions the code performs a compatibility test on return values and also on the number of parameters and their types This mea
58. On entry SP points to the return address to the calling function LOCAL STORAGE ALLOCATION If the routine needs local storage it may allocate it in one or more of the following ways On the stack In static workspace provided of course that the routine is not required to be simultaneously re usable re entrant INTERRUPT FUNCTIONS The calling convention cannot be used for interrupt functions since the interrupt may occur during the calling of a foreground function Hence the requirements for interrupt function routine are different from those of a normal function routine as follows The routine must preserve all registers The 78000 automatically saves PSW and PC on the stack The routine must exit using RETI This automatically restores PSW and PC from the stack The routine must treat all registers and all flags as undefined 1 98 ASSEMBLY LANGUAGE INTERFACE DEFINING INTERRUPT VECTORS As an alternative to defining a C interrupt function in assembly language as described above the user is free to assemble an interrupt routine and install it directly in the interrupt vector The interrupt vectors are located in the INTVEC segment which the supplied linker command files define as the area from address 0x0000 to 0x003F The interrupt vector 0x001E thus has offset 0x1E within this segment as used in the following example RSEG INTVEC ORG Ox1E Move to vector 0x001E WORD my_int Define int
59. RS c The int representation of a character RETURN VALUE The int representation of the upper case character corresponding to c DESCRIPTION Converts a character into upper case 2 136 va_arg va_arg stdarg h Next argument in function call DECLARATION type va_arg va_list ap mode PARAMETERS ap A value of type va_list mode A type name such that the type of a pointer to an object that has the specified type can be obtained simply by postfixing a to type RETURN VALUE See below DESCRIPTION A macro that expands to an expression with the type and value of the next argument in the function call After initialization by va_start this is the argument after that specified by parmN va_arg advances ap to deliver successive arguments in order For an example of the use of va_arg and associated macros see the files printf cand intwri c 2 137 va_end va end stdarg h Ends reading function call arguments DECLARATION void va_end va_list ap PARAMETERS ap A pointer of type va_list to the variable argument list RETURN VALUE See below DESCRIPTION A macro that facilitates normal return from the function whose variable argument list was referenced by the expansion va_start that initialized va_list ap 2 138 va_list va_list stdarg h Argument list type DECLARATION char va_list 1 PARAMETERS None RETURN VALUE See below DESCRIPTION
60. SOURCE FILE The compiler is capable of generating an assembly source file for assembly using the appropriate IAR Assembler The name is the source file leafname plus the extension s26 for assembly sources Assembly source file generation is controlled by the a and A options OBJECT FILE The compiler sends the generated code to the object file whose name is by default the source file leafname plus the extension r26 for object modules If any errors occurs during compilation the object file is deleted Warnings do not cause the object file to be deleted LIST FILE The compiler can generate a compilation listing normally to a file with the same leafname as the source but with the extension 1st 1 19 USING THE C COMPILER COMMAND FILE The compiler can accept options and source filename from a command file as well as from the command line itself Command files have the extension xc1 by default 1 20 TUTORIAL This chapter provides a tutorial for users new to the IAR C Compiler package It demonstrates A typical development cycle How to organize the files for a project How to compile and link a simple program How to use the following 78000 specific features pragma directives provided header files sfr variables bit variables and interrupt functions It assumes you are familiar with the C language in general You must have already installed the AR C Compiler for MS DOS
61. Since const or volatile are attributes of objects they are ignored when given with a structure union or enumeration tag definition that has no objects declared at the same time Also functions are considered as being unable to return const or volatile For example const struct s Ws no object declared const ignored warning const int myfunc void function returning const int warning const int fp void pointer to function returning const int warning int const fp void const pointer to function returning int OK no warning 31 Incompatible parameters of Pointers possibly indirect to K amp R functions functions or K amp R function declarators have incompatible parameter types The pointer was used in one of following contexts pointer pointer expression ptr ptr pointer relational_op pointer pointer equality_op pointer pointer pointer formal parameter vs actual parameter 2 181 DIAGNOSTICS No Warning messages 32 33 34 35 36 37 Incompatible numbers of parameters of K amp R functions Suggestion Pointers possibly indirect to functions or K amp R function declarators have a different number of parameters The pointer is directly used in one of following contexts pointer pointer expression ptr ptr pointer relational_op pointer pointer equality_op pointer pointer pointer formal parameter vs actual parameter
62. TERS arg A double value RETURN VALUE A double with the value of the largest integer less than or equal to arg DESCRIPTION Computes the largest integral value less than or equal to arg 2 65 fmod fmod math h Floating point remainder DECLARATION double fmod double argl double arg2 PARAMETERS argl The double numerator arg2 The double denominator RETURN VALUE The double remainder of the division argl arg2 DESCRIPTION Computes the remainder of arg1 arg2 ie the value argl i arg2 for some integer i such that if arg2 is non zero the result has the same sign as argl and magnitude less than the magnitude of arg2 2 66 free free stdlib h Frees memory DECLARATION void free void ptr PARAMETERS ptr A pointer to a memory block previously allocated by malloc calloc or real loc RETURN VALUE None DESCRIPTION Frees the memory used by the object pointed to by ptr ptr must earlier have been assigned a value from malloc calloc or realloc 2 67 frexp frexp math h Splits a floating point number into two parts DECLARATION double frexp double argl int arg2 PARAMETERS argl Floating point number to be split arg2 Pointer to an integer to contain the exponent of arg1 RETURN VALUE The double mantissa of arg1 in the range 0 5 to 1 0 DESCRIPTION Splits the floating point number arg1 into an exponent stored in arg2 and a mantissa whi
63. X Displays C declarations USER OPTIONS Dsymb Defines a symbol Dsymb xx Defines a symbol Usymb Undefines a symbol 2 3 GENERAL COMMAND LINE OPTIONS SUMMARY GENERAL COMMAND LINE OPTIONS This chapter lists the C compiler command line options Generates assembler source SYNTAX a file DESCRIPTION Use a to generate assembler source on file sxx By default the compiler does not generate an assembler source The a option generates an assembler source to the named file The filename consists of a leafname optionally preceded by a pathname and optionally followed by an extension If no extension is given the target specific assembler source extension is used The assembler source may be assembled by the appropriate IAR Assembler If the 1 or L option is also used the C source lines will be included in the assembly source file as comments The a and A options may not be used together A A Generates assembler source SYNTAX Aprefix DESCRIPTION Use A to generate assembler source on prefix source Sxx By default the compiler does not generate an assembler source The A option generates an assembler source to a file with the same name as the source leafname but with the target specific assembly source extension The A option may be followed by a prefix which the compiler adds to the filename This allows the user to redirect the assembly source to a different
64. _engine 1 77 using 1 78 PRAGMA DIRECTIVE REFERENCE This chapter describes the pragma directives in alphabetical order bitfields default Restores default order of storage of bitfields SYNTAX pragma bitfields default DESCRIPTION This directive causes the compiler to allocate bitfields in its normal order See bitfields reversed bitfields reversed Reverses order of storage of bitfields SYNTAX pragma bitfields reversed DESCRIPTION This directive causes the compiler to allocate bitfields starting at the most significant bit of the field instead of at the least significant bit The ANSI standard allows the storage order to be implementation dependent so you may run into portability problems which this keyword can be used to avoid 1 79 bitfields reserved EXAMPLES The default layout of struct short a 3 a is 3 bits short 5 this reserves a hole of 5 bits short b 4 b is 4 bits bits bits is 16 bits in memory is 15 1211 87 32 0 pragma bitfields reversed struct short a 3 a is 3 bits short 5 this reserves a hole of 5 bits short b 4 b is 4 bits bits bits is 16 bits has the following layout 15 1312 87 43 0 codeseg codeseg Directs program code to the named segment by default SYNTAX pragma codeseg seg_name DESCRIPTION This directive directs program code to the named
65. a number in ASCII form RETURN VALUE The double number found in the string DESCRIPTION Converts the string pointed to by nptr to a double precision floating point number skipping white space and terminating upon reaching any unrecognized character EXAMPLES 3K gives 3 00 0006 gives 0 0006 le 4 gives 0 0001 2 54 atoi atol stdlib h Converts ASCII to int DECLARATION int atoi const char nptr PARAMETERS nptr A pointer to a string containing a number in ASCII form RETURN VALUE The int number found in the string DESCRIPTION Converts the ASCII string pointed to by nptr to an integer skipping white space and terminating upon reaching any unrecognized character EXAMPLES 3K gives 3 6 gives 6 149 gives 149 2 55 atol atol stdlib h Converts ASCII to long int DECLARATION long atol const char nptr PARAMETERS nptr A pointer to a string containing a number in ASCII form RETURN VALUE The long number found in the string DESCRIPTION Converts the number found in the ASCII string pointed to by nptr toa long integer value skipping white space and terminating upon reaching any unrecognized character EXAMPLES 3K gives 3 6 gives 6 149 gives 149 2 56 calloc calloc stdlib h Allocates memory for an array of objects DECLARATION void calloc size_t nelem size_t elsize PARAMETERS nelem The number of objects elsiz
66. ack size depends heavily on the details of these operations If the given stack size is too small the stack will normally be allowed to overwrite variable storage resulting in likely program failure If the given stack size is too large RAM will be wasted ESTIMATING THE REQUIRED STACK SIZE The stack is used for the following Storing local variables and parameters Storing temporary results in expressions Storing temporary values in run time library routines Saving the return address of function calls Saving the processor state during interrupts The total required stack size is the worst case total of the required sizes for each of the above The only facilities which helps the user to make an estimate of the total required stack size is provided by the NEC IE 78000 R Incircuit Emulator This Incircuit Emulator allows to specify any range of the 780XX internal RAM area as stack memory and it checks during program execution whether the stack pointer is still inside this range or not A stack guard error message will occur if the stack pointer exceeds the defined stack area The default stack size is set to 128 bytes 1 51 CONFIGURATION INPUT AND OUTPUT PUTCHAR AND GETCHAR The functions putchar and getchar are the fundamental functions through which C performs all character based I O For any character based I O to be available the user must provide definitions for these two functions using w
67. acters with a string DECLARATION char strncat char sl const char s2 size_t n PARAMETERS sl A pointer to the destination string s2 A pointer to the source string n The number of characters of the source string to use RETURN VALUE sl DESCRIPTION Appends not more than n initial characters from the source string to the end of the destination string 2 123 strncmp strncmp string h Compares a specified number of characters with a string DECLARATION int strncmp const char sl const char s2 size_t n PARAMETERS sl A pointer to the first string s2 A pointer to the second string n The number of characters of the source string to compare RETURN VALUE The int result of the comparison of not more than n initial characters of the two strings Return value Meaning gt 0 sl lt s2 0 sl s2 lt 0 sl lt s2 DESCRIPTION Compares not more than n initial characters of the two strings 2 124 strncpy strncpy string h Copies a specified number of characters from a string DECLARATION char strncpy char sl const char s2 size_t n PARAMETERS sl A pointer to the destination object s2 A pointer to the source string n The number of characters of the source string to copy RETURN VALUE sl DESCRIPTION Copies not more than n initial characters from the source string into the destination object 2 125 strpbrk strpbrk string h Finds any o
68. alid ANSI declaration int f i invalid ANSI declaration 87 Redeclared formal parameter A formal parameter in a K amp R name function definition was declared more than once 88 Contradictory function void appears in a function declaration parameter type list together with other type of specifiers 89 without previous cannot be the only parameter parameter s description specified For example TAG BC eet s Invalid TAG EO ints we 2S Valid 90 Formal parameter identifier An identifier of a parameter was missing missing in the header of a prototyped function definition For example int f int p char float ff Invalid second parameter has no name a function body 2 167 DIAGNOSTICS Suggestion A prototyped function was declared with a different number of parameters than the first declaration first declaration valid fewer parameters invalid more parameters invalid A prototyped declaration of a function appeared after it was defined or referenced as a K amp R function A bit field was initialized with a width nn bits out of rangeconstant too large to fit in the field No Error message 91 Redeclared number of formal parameters For example int f int char Kx int f int int f int char float 92 Prototype appeared after reference 93 Initializer to field of 94 Fields of width 0 must not be named 95 Second operand fo
69. allation is to manually modify your autoexec bat file Since the modifications are version dependent they are documented in the text file autoexec iar on the directory path you chose by default C iar autoexec iar Open your autoexec bat file and the autoexec iar file in a text editor follow the instructions in autoexec iar file and save the modified autoexec bat file 1 7 GETTING STARTED INSTALLATION UNDER WINDOWS The IAR C Compiler may be used in an MS DOS window under Windows Using an MS DOS window follow the instructions given in Installation under MS DOS page 1 5 INSTALLATION UNDER UNIX Follow the separate printed installation documentation supplied with the delivery media READ ME FILES Your installation includes a number of ASCII format text files containing recent additional information Using the default pathnames they are C iar etc newclib doc Documentation of additional C library functions C iar icc78000 icc78000 doc General information about the C compiler C iar icc78000 global doc General information about the global optimiser There are further files associated with the assembler linker library manager and any tools that have been installed separately such as C SPY These are listed in their own guides Before proceeding it is recommended that you read all of these files INSTALLED FILES The IAR C Compiler and associated tools use sub directories and file extensions to ma
70. as discussed in the previous chapter If you are using a HLL debugger like C SPY Simulator or SD78K 0 you may follow this tutorial by running the program on your PC resp emulator following the instructions given in the documentation supplied with the corresponding debugger 1 21 TUTORIAL TYPICAL DEVELOPMENT CYCLE Development will normally follow the cycle illustrated below Set up a project directory Set up the linker command file Create C source program Compile with chosen memory model Link with linker command file JO Transfer to debugger simulator or emulator Hi Error Edit C source program OK Put code into PROM The following tutorial follows this cycle except for the debug session 1 22 TUTORIAL CREATING A PROJECT DIRECTORY The user files for a particular project are best kept in one directory separate from other projects and the IAR system files Create a project directory by entering the command mkdir c tutorial Select the project directory by entering the command cd c tutorial During this tutorial you will remain in this directory so that the files you create will reside here CONFIGURING TO SUIT THE TARGET PROGRAM Each project needs a linker command file containing details of the target system s memory map To create this first copy the linker command file template supplied copy c iar icc78000 1nk780 xcl This creates a copy called 1nk780
71. assembler comments L creates a listing and z0 supresses optimisation The result is the listing file she11 s26 containing the declarations function call function return and variable accesses The following sections describe the interface in detail CALLING CONVENTION There are two different function parameter passing schemes for the 78000 compiler These are Prototyped function parameter passing Non prototyped function parameter passing Generally the first parameter is always passed in register s For a Prototyped function up to four parameters can be passed in register s depending on parameter sizes in bytes Parameters not in register s will be pushed on the stack with first parameter not in register s at the top of stack The exception from the above is that as soon as a parameter of type struct or union is found that parameter and all following parameters will be put on the stack Parameters passed in register s will use the following register allocation 1 st parameter 2 nd parameter 3 rd parameter 4 th parameter 4 bytes AX BC 2 3 bytes AX C a 2 bytes AX 2bytes BC i 1 94 ASSEMBLY LANGUAGE INTERFACE I st parameter 2 nd parameter 3 rd parameter 4 th parameter 2 bytes AX 1 byte B 1 byte C 1 byte X 2 bytes BC 5 1 byte X lbytes A 2 bytes BC 1 byte X 1 bytes A 1 bytes B 1 bytes C Immediatly after an entry into a function the s
72. ata _read excluding floating point numbers Writes formatted data excluding floating point numbers Small formatted data _write write routine Arc cosine Arc sine Arc tangent 2 39 GENERAL C LIBRARY DEFINITIONS atan2 ceil cos cosh exp fabs floor fmod frexp ldexp log 10g10 modf pow sin sinh sqrt tan tanh 2 40 do do do do do do do do do do do in do in do do do do do do do do do do do uble atan2 double argl uble arg2 uble ceil double arg uble cos double arg uble cosh double arg uble exp double arg uble fabs double arg uble floor double arg uble fmod double argl uble arg2 uble frexp double argl t arg2 uble Idexp double argl t arg2 uble log double arg uble logl0 double arg uble modf double value uble iptr uble pow double argl uble arg2 uble sin double arg uble sinh double arg uble sqrt double arg uble tan double x uble tanh double arg Arc tangent with quadrant Smallest integer greater than or equal to arg Cosine Hyperbolic cosine Exponential Double precision floating point absolute Largest integer less than or equal Floating point remainder Splits a floating point number into two parts Multiply by power of two Natural logarithm Base 10 logarithm Fractional and integer parts Raises to the power
73. ation Compilation warning messages are described in Compilation warning messages in this chapter COMPILATION FATAL ERROR MESSAGES Compilation fatal error messages are produced when the compiler has found a condition that not only prevents code generation but which makes further processing of the source not meaningful After the message has been issued compilation terminates Compilation fatal error messages are described in Compilation error messages in this chapter and marked as fatal COMPILATION MEMORY OVERFLOW MESSAGE When the compiler runs out of memory it issues the special message ee COMPILER OUT OF MEMORY Dynamic memory used nnnnnn bytes If this error occurs the cure is either to add system memory or to split source files into smaller modules Also note that the q x A P and r not rn switches cause the compiler to use more memory Also see the chapter Getting Started for more information COMPILATION INTERNAL ERROR MESSAGES A compiler internal error message indicates that there has been a serious and unexpected failure due to a fault in the compiler itself for example the failure of an internal consistency check After issuing a self explanatory message the compiler terminates 2 156 DIAGNOSTICS Internal errors should normally not occur and should be reported to the IAR Systems technical support group Your report should include all possible information about the problem and pr
74. ch is returned as the value of the function The values are as follows mantissa 2 xponent value 2 68 getchar getchar stdio h Gets character DECLARATION int getchar void PARAMETERS None RETURN VALUE An int with the ASCII value of the next character from the standard input stream DESCRIPTION Gets the next character from the standard input stream The user must customize this function for the particular target hardware configuration The function is supplied in source format in the file getchar c 2 69 gets gets stdio h Gets string DECLARATION char gets char s PARAMETERS S A pointer to the string that is to receive the input RETURN VALUE Result Value Successful A pointer equal to s Unsuccessful Null DESCRIPTION Gets the next string from standard input and places it in the string pointed to The string is terminated by end of line or end of file The end of line character is replaced by zero This function calls getchar which must be adapted for the particular target hardware configuration 2 70 isalnum isalnum ctype h Letter or digit equality DECLARATION int isalnum int c PARAMETERS c An int representing a character RETURN VALUE An int which is non zero if c is a letter or digit else zero DESCRIPTION Tests whether a character is a letter or digit 2 71 isalpha isalpha ctype h Letter equality
75. ction return Becomes pl pl p2i itadd_this Merged p2 A non void function definition with lt expression gt expected should exit with a defined return Invalid storage class for function assumed to be extern Redeclared parameter s storage class value in all places Invalid storage class for function ignored Valid classes are extern static or typedef Storage class of a function formal parameter was changed from register to auto or vice versa in a subsequent declaration definition DIAGNOSTICS No 19 20 21 22 Warning message Suggestion Storage class extern An identifier declared as static ignored name was first was later explicitly or implicitly declared as static declared as extern The extern declaration is ignored Unreachable statement s One or more statements were preceded by an unconditional jump or return such that the statement or statements would never be executed For example break i 2 Never executed Unreachable statement s at One or more labeled statements unreferenced label name were preceded by an unconditional jump or return but the label was never referenced so the statement or statements would never be executed For example break here i 2 Never executed Non void function explicit A non void function generated an return lt expression gt implicit return expected This could be the result
76. d sl const void s2 size_t n PARAMETERS sl A pointer to the destination object s2 A pointer to the source object n The number of characters to be copied RETURN VALUE sl DESCRIPTION Copies a specified number of characters from a source object to a destination object If the objects overlap the result is undefined so memmove should be used instead 2 91 memmove memmove string h Moves memory DECLARATION void memmove void sl const void s2 size_t n PARAMETERS sl A pointer to the destination object s2 A pointer to the source object n The number of characters to be copied RETURN VALUE sl DESCRIPTION Copies a specified number of characters from a source object to a destination object Copying takes place as if the source characters are first copied into a temporary array that does not overlap either object and then the characters from the temporary array are copied into the destination object 2 92 memset memset string h Sets memory DECLARATION void memset void s int c size_t n PARAMETERS S A pointer to the destination object c An int representing a character n The size of the object RETURN VALUE S DESCRIPTION Copies a character converted to an unsigned char into each of the first specified number of characters of the destination object 2 93 modf modf math h Fractional and integer parts DECLARATION doubl
77. d keyword summary 1 61 extended keywords banked 1 65 bit 1 66 interrupt 1 67 monitor 1 69 near 1 70 no_init 1 72 non_banked 1 71 saddr 1 73 sfr 1 74 sfrp 1 75 shortad 1 73 using 1 76 extensions 1 15 1 61 F fabs library function 2 64 file types 1 15 files assembler 1 10 C include 1 10 C SPY 1 10 executable 1 9 1 11 include 1 13 library 1 10 1 15 miscellaneous 1 9 1 11 source 1 9 1 12 files installed 1 8 float h header file 2 44 IV floating point format 1 59 floor library function 2 65 fmod library function 2 66 free library function 2 67 frexp library function 2 68 Function parameter passing 1 94 Function return value 1 96 function banked pragma directive 1 81 function default pragma directive 1 82 function interrupt pragma directive 1 82 function monitor pragma directive 1 83 function non banked pragma directive 1 84 G getchar library function 1 52 2 69 gets library function 2 70 H header files 2 38 ctype h 2 38 errno h 2 44 float h 2 44 icclbutl h 2 39 limits h 2 44 math h 2 39 setjmp h 2 41 stdarg h 2 41 stddef h 2 44 stdio h 2 41 INDEX stdlib h 2 41 string h 2 43 heap size 1 55 hexadecimal string constants 2 152 I icc78000 command 1 17 icc78000 directory 1 12 icclbutl h header file 2 39 IDATAO segment 1 107 IDATAI segment 1 107 inc directory 1 13 include directive 1 18 include files 1 13 1 18 initialization 1 55 input an
78. d language syntax Note that pragma directives are available regardless of the e option The following categories of pragma functions are available BITFIELD ORIENTATION tpragma bitfields reversed pragma bitfields default 1 62 LANGUAGE EXTENSIONS EXTENSION CONTROL fpragma language extended fpragma language default FUNCTION ATTRIBUTE fpragma function interrupt pragma function monitor fpragma function non_banked fpragma function banked fpragma function default CODESEGMENT USAGE d fpragma codeseg SEG_NAME MEMORY USAGE dfpragma memory constseg SEG_NAME d pragma memory dataseg SEG_NAME d pragma memory near fpragma memory saddr i fpragma memory shortad d fpragma memory no_init fpragma memory default WARNING MESSAGE CONTROL fpragma warnings on Turn on warnings fpragma warnings off Turn off warnings fpragma warnings default INTRINSIC FUNCTIONS Intrinsic functions allow very low level control of the 78000 microprocessor To use them in a C application include the header file in78000 h Most intrinsic functions compile a single 78000 instruction as follows 1 63 LANGUAGE EXTENSIONS Name Instruction Function void _EI void EI Enable interrupts void _DI void DI Disable interrupts void _HALT void HALT NOP Set HALT mode void _STOP void STOP NOP Set STOP mode void _NOP void NOP No operation void _OPC char constant as Inser
79. d output 1 52 installation 1 5 installed files 1 8 MS DOS 1 5 UNIX 1 8 Windows 1 8 interrupt extended keyword 1 67 interrupt functions 1 98 interrupt handling 1 32 interrupt vectors 1 99 interrupts 1 49 1 50 intrinsic functions 1 63 disable_interrupt 1 63 enable_interrupt 1 63 introduction 1 1 INTVEC segment 1 108 isalnum library function 2 71 isalpha library function 2 72 iscntrl library function 2 73 isdigit library function 2 74 V INDEX isgraph library function 2 75 islower library function 2 76 isprint library function 2 77 ispunct library function 2 78 isspace library function 2 79 isupper library function 2 80 isxdigit library function 2 81 K Kernighan amp Richie definition 2 149 key features 1 1 keywords const 2 149 entry 2 149 enum 1 58 2 151 signed 2 150 struct 2 153 union 2 153 void 2 150 volatile 2 150 L 107 s26 1 49 labs library function 2 82 language extensions 1 61 2 33 language default pragma directive 1 84 language extended pragma directive 1 85 Idexp library function 2 83 Idiv library function 2 84 lib directory 1 15 library definitions summary 2 38 library files 1 10 1 15 library functions _formatted_read 2 141 _formatted_write 2 142 _medium_read 1 54 2 144 _medium_write 1 53 2 145 _small_write 1 53 2 147 abort 2 47 abs 2 48 acos 2 49 asin 2 50 assert 2 51 atan 2 52 atan2 2 53 atof 2 54 atoi 2 55 atol 2 56 ca
80. ddress memory from 0xFE20 to OxFE1F Variables of type shortad cannot be initialised at compile time and may only be declared on file level shortad int var jnt var in saddr area not initialised shortad int buffer 10 array in saddr area sfr Declare object of one byte I O data type SYNTAX sfr identifier constant expression DESCRIPTION sfr denotes an 78000 SFR register which Is equivalent to unsigned char Can only be directly addressable Resides at a fixed location in the range 0xFFOO to OxFFFF The value of an sfr variable is the contents of the SFR register at the address constant expression All operators that apply to integral types except the unary amp address operator may be applied to sfr variables In expressions sfr variables may also be appended by a period followed by a bit selector Predefined sfr declarations for popular members of the 78000 family are supplied see Installed files page 1 8 1 74 sfr EXAMPLES sfr PO 0x80 Defines PO void func PO 4 Set entire variable PO 00000100 ey P0 2 1 Only affects one bit PO XXXXX1XX if PO amp 4 printf ON Read entire PO and mask bit 2 if P0 2 printf ON Same but does bit access only sfrp Declare object of two byte I O data type SYNTAX sfrp identifier constant expression DESCRIPTION sfrp denotes an 78000 SFR register which Is equivalent t
81. definition An identifier was missing from a declarator goto statement or pre processor line Pre processor arguments must be separated from the directive with tab or space characters The formal parameter of a symbol in a define statement was repeated Fatal A if ifdef or ifndef was missing was followed by an unknown identifier A pre processor line was not empty after the argument part was read Fatal The pre processor limit was exceeded Fatal The pre processor limit was exceeded Fatal The pre processor limit was exceeded 2 159 DIAGNOSTICS No Error message 25 Macro name called with too many parameters 26 Actual macro parameter too long max is 512 27 Macro name called with too few parameters 28 Missing endif 29 Type specifier expected 30 Identifier unexpected 31 Identifier name 32 Invalid declaration syntax 33 Unbalanced or in declarator Suggestion Fatal A parameterized define macro was called with more arguments than declared A single macro argument may not exceed the length of a source line A parameterized define macro was called with fewer arguments than declared Fatal The end of file was encountered during skipping of text after a false condition A type description was missing This could happen in struct union prototyped function definitions declarations or in K amp R function formal parameter declara
82. der of multiple options is important The options are arranged into the following functional groups FILE CONTROL a file Generates assembler source Aprefix Generates assembler source f file Reads command line options from a file G Opens the standard input as source Iprefix Adds an include file search prefix GENERAL COMMAND LINE OPTIONS SUMMARY 1 file Lprefix o file Oprefix i pn q tn T xX D CF CT C2 CODE CONTROL b e Hname P r 012 i n Rname s 0 9 z 0 9 y LISTING CONTROL Generates a listing Generates a listing Specifies object filename Specifies object filename Generates a formfeed after each listed function Lists included files Formats listing into pages Puts mnemonics in the listing Sets the tab spacing Lists active lines only Generates a cross reference list Makes object a library module Enables target dependent extensions Sets the object module name Generates PROMable code Generates debug information Sets the code segment name Optimizes for speed Optimizes for size Initializes strings as variables LANGUAGE SPECIFICATION C C 2 2 Specifies the interpretation of char Enables nested comments GENERAL COMMAND LINE OPTIONS SUMMARY gLA O0 Enables global type check K Enables C comments MESSAGE CONTROL S Sets silent operation of compiler wW Disables warnings
83. due to illegal use of one of the extended keywords 1 120 78000 SPECIFIC DIAGNOSTICS No Error message Suggestion 154 78000 specific Self explaining sub message Not a BIT accessible SFR Interrupt function cannot be declared BANKED or MONITOR Interrupt function bad USING bank number CALLT function cannot be declared USING CALLT function cannot be declared BANED or MONITOR CALLT function without vector not legal CALLT illegal function interrupt vector Tllegal argument to _DI Illegal argument to _EI Illegal argument for _HALT Illegal argument for _STOP Tllegal argument for _NOP Argument must exist for _OPC Too many arguments for _OPC Argument not char constant for _OPC 1 121 78000 SPECIFIC DIAGNOSTICS 78000 SPECIFIC XLINK ERRORS In addition to the error and warning messages described in Diagnostics page 2 145 the XLINK has the following error message No 16 17 70 71 72 Error message Function name in module file is called from two function trees with roots namel and name2 Segment name is too large or placed at wrong address Module module file has different memory model than previously linked modules Segment name is defined incorrectly in a bank definition segment has wrong type other segment types Segment name must be defined in a Z defini
84. e A value of type size_t specifying the size of each object RETURN VALUE Result Value Successful A pointer to the start lowest address of the memory block Unsuccessful Zero if there is no memory block of the required size or greater available DESCRIPTION Allocates a memory block for an array of objects of the given size To ensure portability the size is not given in absolute units of memory such as bytes but in terms of a size or sizes returned by the sizeof function The availability of memory depends on the default heap size 2 57 ceil ceil math h Smallest integer greater than or equal to arg DECLARATION double ceil double arg PARAMETERS arg A double value RETURN VALUE A double having the smallest integral value greater than or equal to arg DESCRIPTION Computes the smallest integral value greater than or equal to arg 2 58 cos Cos math h Cosine DECLARATION double cos double arg PARAMETERS arg A double value in radians RETURN VALUE The double cosine of arg DESCRIPTION Computes the cosine of arg radians 2 59 cosh cosh math h Hyperbolic cosine DECLARATION double cosh double arg PARAMETERS arg A double value in radians RETURN VALUE The double hyperbolic cosine of arg DESCRIPTION Computes the hyperbolic cosine of arg radians 2 60 div stdlib h Divide DECLARATION div_t div int numer int de
85. e double arc sine of arg in the range pi 2 pi 2 DESCRIPTION Computes the principal value in radians of the arc sine of arg 2 50 assert assert assert h Checks an expression DECLARATION void assert int expression PARAMETERS expression An expression to be checked RETURN VALUE None DESCRIPTION This is a macro that checks an expression If it is false it prints a message to stderr and calls abort The message has the following format File name line num Assertion failure expression To ignore assert calls put a define NDEBUG statement before the Hinclude lt assert h gt statement 2 51 atan atan math h Arc tangent DECLARATION double atan double arg PARAMETERS arg A double value RETURN VALUE The double arc tangent of arg in the range pi 2 pi 2 DESCRIPTION Computes the arc tangent of arg 2 52 atan2 atan2 math h Arc tangent with quadrant DECLARATION double atan2 double argl double arg2 PARAMETERS argl A double value arg2 A double value RETURN VALUE The double arc tangent of argl arg2 in the range pi pi DESCRIPTION Computes the arc tangent of argl arg2 using the signs of both arguments to determine the quadrant of the return value 2 53 atof atof stdlib h Converts ASCII to double DECLARATION double atof const char nptr PARAMETERS nptr A pointer to a string containing
86. e files The c iar inc sub directory holds C include files such as the header files for the standard C library The C compiler searches for include files in the directories given in the C_INCLUDE environment variable see Files page 1 18 and the installation procedure includes the inc sub directory in the definition of this variable in the autoexec file see Installation under MS DOS page 1 5 This allows the user to refer to an inc header file simply by its basename For details of the contents see INC files page 1 13 Library files The c iar 1lib sub directory holds library modules The linker searches for library files in the directories given in the XLINK_DFLTDIR environment variable see the LAR 78000 Assembler guide and the installation procedure includes the 1ib sub directory in the definition of this variable in the autoexec file see Installation under MS DOS page 1 5 This allows the user to refer to a LIB library module simply by its basename For details of the contents see LIB files page 1 15 Assembler files The c iar a78000 sub directory holds assembler specific files see the ITAR 78000 Assembler guide C SPY files If you have installed the C SPY Debugger supplied separately there will also be ac iar cs78000 sub directory holding the C SPY specific files see the Using C SPY guide 1 10 GETTING STARTED EXE FILES This sub directory contains the following MS DOS executable program files
87. e is very large and provides facilities not required in many applications To reduce the memory consumption the following two alternative smaller versions are also provided in the IAR C standard library _medium_write As for __formatted_write except that floating point numbers are not supported Any attempt to use a f g G 4e and E specifier will produce the error FLOATS wrong formatter installed _medium_write is considerably smaller than __formatted_write _small_write As for __medium_write except that it supports only the d 0 c s and x specifiers for int objects and does not support field width and precision arguments The size of __smal1l_write is 10 15 of the size of _formatted_write The default version is_small_write SELECTING THE WRITE FORMATTER VERSION The selection of a write formatter is made in the linker control file The default selection smal1l_write is made by the line e_small_write _formatted_write To select the full ANSI version remove this line To select _medium_wr i te replace this line with e_medium_write _formatted_write 1 53 CONFIGURATION REDUCED PRINTF For many applications sprintf is not required and even printf with _small_formatter provides more facilities than are justified by the memory consumed Alternatively a custom output routine may be required to support particular formatting needs and or non standard output devices For such app
88. e modf double value double iptr PARAMETERS value A double value iptr A pointer to the double that is to receive the integral part of value RETURN VALUE The fractional part of value DESCRIPTION Computes the fractional and integer parts of value The sign of both parts is the same as the sign of value 2 94 pow pow math h Raises to the power DECLARATION double pow double argl double arg2 PARAMETERS argl The double number arg2 The double power RETURN VALUE argl raised to the power of arg2 DESCRIPTION Computes a number raised to a power 2 95 printf printf stdio h Writes formatted data DECLARATION int printf const char format PARAMETERS format A pointer to the format string The optional values that are to be printed under the control of format RETURN VALUE Result Value Successful The number of characters written Unsuccessful A negative value if an error occurred DESCRIPTION Writes formatted data to the standard output stream returning the number of characters written or a negative value if an error occurred Since a complete formatter demands a lot of space there are several different formatters to choose For more information see the chapter Configuration in the target specific section format is a string consisting of a sequence of characters to be printed and conversion specifications Each conversion specification causes the next
89. e used to declare function return values function parameters and generic pointers For example void f a function without return value type_spec f void a function with no parameters void p a generic pointer which can be cast to any other pointer and is assignment compatible with any pointer type 2 150 K amp R AND ANSI C LANGUAGE DEFINITIONS ENUM KEYWORD ANSI C adds enum a keyword that conveniently defines successive named integer constants with successive values For example enum zero one two step 6 seven eight DATA TYPES In ANSI C the complete set of basic data types is unsigned signed char unsigned signed int unsigned signed short unsigned signed long float double long double Pointer FUNCTION DEFINITION PARAMETERS In K amp R C function parameters are declared by conventional declaration statements before the body of the function In ANSI C each parameter in the parameter list is preceded by its type identifiers For example K amp R ANSI long int g s long int g char s char s The arguments of ANSI type functions are always type checked The IAR C Compiler checks the arguments of K amp R type functions only if the g option is used 2 151 K amp R AND ANSI C LANGUAGE DEFINITIONS FUNCTION DECLARATIONS In K amp R C function declarations do not include parameters In ANSI C they do For example T
90. editor MS DOS command ICC78000 command ICC78000 include A78000 command A78000 include XLINK XLINK XLIB EPROM C SPY etc C SPY etc The default extension may be overridden by simply including an explicit extension when the filename is specified 1 16 USING THE C COMPILER RUNNING THE C COMPILER The ICC C Compiler is run by a command of the following form icc78000 options sourcefile options These items must be separated by one or more space or tab characters PARAMETERS options A list of options separated by one or more space or tab characters sourcefile The name of the source file If no options or sourcefile is given the command displays information about the compiler including a summary of the options and the target specific file extensions used OPERATION UNDER MS DOS The command is entered as described above Filenames are not case sensitive OPERATION UNDER UNIX Filenames are case sensitive so for example program c is not equivalent to PROGRAM C Note that the default extension for C source files is lower case c 1 17 USING THE C COMPILER FILES The compilation process involves the following types of file SOURCE FILE Each invocation of the compiler processes the single source file named on the command line Its name is of the form path leafname ext For example the filename project program c has the path project the leafname program and the ex
91. eferably also a diskette with the program that generated the internal error COMPILATION ERROR MESSAGES No Error message 0 Invalid syntax 1 Too deep include nesting max is 10 2 Failed to open include file name 3 Invalid include filename 4 Unexpected end of file encountered Suggestion The compiler could not decode the statement or declaration Fatal The compiler limit for nesting of include files was exceeded One possible cause is an inadvertently recursive include file Fatal The compiler could not open an include file Possible causes are that the file does not exist in the specified directories possibly due to a faulty I prefix or C_INCLUDE path or is disabled for reading Fatal The include filename was invalid Note that the include filename must be written lt file gt or file Fatal The end of file was encountered within a declaration function definition or during macro expansion The probable cause is bad or nesting 2 157 DIAGNOSTICS No Error message Suggestion 5 Too long source line max The source line length exceeds the is 512 chars truncated compiler limit 6 Hexadecimal constant without The prefix 0x or 0X of digits hexadecimal constant was found without following hexadecimal digits 7 Character constant larger A character constant contained than long too many characters to fit in the space of a long integer 8 Invalid cha
92. eference A cross reference to another part of this user guide or to another guide In this guide K amp R is used as an abbreviation for The C Programming Language by Kernighan and Richie ABOUT THIS GUIDE vi CONTENTS IAR 78000 C COMPILER Introduction Key features Development system structure Getting started Installation Installed files Using the C compiler Running the C compiler Files Tutorial Typical development cycle Creating a program Extending the program Adding an interrupt handler Using additional memory Compiling and linking the C SPY tutorial Compiling and linking the SD78K 0 tutorial Configuration Introduction Run time library Linker command file Memory model Stack size Input and output Heap size Initialization Data representation 1 1 1 1 1 3 1 5 1 8 1 17 1 17 1 18 1 21 1 22 1 25 1 28 1 32 1 38 1 40 1 41 1 43 1 43 1 44 1 44 1 44 1 51 1 52 1 55 1 55 1 57 vii CONTENTS Language extensions Extended keywords summary pragma directive summary Intrinsic functions Extended keyword reference pragma directive reference Assembly language interface Creating a shell Calling convention Function Return Value Registers Segments Calling assembly routines from C Segment reference 78000 Specific Command line options summary 78000 Specific command line options 78000 Specific Diagnostics IAR C COMPILER GENERAL FEATURES General command
93. emory model options the compiler uses the small memory model and CALL instruction for the internal library calls To specify the memory model to the linker you select an appropriate library file Small Banked Command filename 1nk780 xcl 1nk780b xcl For example to link the module myprog previously compiled for the small memory model for the banked memory model you should use the command xlink myprog f Ink780b The f option specifies a command filename see the IAR 78000 Assembler guide for details 1 46 CONFIGURATION CALLT LIBRARY FUNCTION CALLS When compiler options mS or mB is active the run time system reserves the call table vector area for internal use Those entries not used by the run time system is free to be used by the application Compiler use of the call table vector area Vector Function 40 41 Reserved for CSPY 42 43 TB_C_LSH_L10 44 45 TB_UC_DIV_L10 46 47 TB_SC_DIV_L10 48 49 TB_SC_CMP_L10 4A 4B TB_MULU_L10 4C 4D TB_I_LSH_L10 4E 4F TB_I_MUL_L10 50 51 TB_UI_DIV_L10 52 53 TB_SI_DIV_L10 54 55 TB_UI_CMP_L10 56 57 TB_SI_CMP_L10 58 59 TB_L_MUL_L10 5A 5B TB_UL_DIV_L10 5C 5D TB_SL_DIV_L10 5E 5F TB_L_ADD_L10 60 61 TB_L_SUB_L10 62 63 TB_UL_CMP_L10 64 65 TB_SL_CMP_L10 1 47 CONFIGURATION Vector Function 66 67 TB_UI_LLOAD_BITS_L10 68 69 TB_I_STORE_BITS_L10 6A 6B TB_LOAD_A_SP_L10 6C 6D TB_STORE_A_SP_L10 6E 6F TB_LOAD_AX_SP_L10 70 71
94. ently than the signed counterparts Especially this applies to type conversions comparison array indexing and some arithmetic operations such as gt gt and Use ANSI prototypes Function calls to ANSI functions are performed more efficiently than K amp R style functions see LAR C Compiler General Features Consider using the small memory model Banked applications will however not be as efficient If the banked memory model is required for your application use the function attribute non_banked if possible for local function calls Sensible use of the memory attributes see Extended keywords summary page 1 61 can enhance both speed and code size in critical applications Avoid using large stack frames Code efficiency deteriorates in functions with more than 256 bytes of local data Consider using static rather than auto storage class for large arrays and structures Use the memory attributes saddr or shortad if possible Efficient instructions are available for memory access in short address area To achieve maximum code size optimisation use the compiler switches z9 W128 mS LANGUAGE EXTENSIONS The IAR C Compiler provides a number of powerful extensions that support specific features of the 78000 family of microprocessors The 78000 extensions are provided in three ways Asextended keywords By default the compiler conforms to the ANSI specifications and 78000 extensions are not available The command line
95. errupt vector The user must place the actual interrupt routine in the RCODE segment guaranteeing that it will reside in bank 0 The following is an example of a directly installed interrupt routine RSEG RCODE my_int PUSH AX Save the AX register MOVW AX 0 Make sure AX 0 POP AX Restore AX RETI Return from interrupt 1 99 ASSEMBLY LANGUAGE INTERFACE 1 100 SEGMENT REFERENCE The IAR C Compiler places code and data in to named segments which are referred to by the linker Details of the segments is required for programming assembly language modules and is also useful when interpreting the assembly language output of the compiler This section provides an alphabetical list of the segments For each segment it shows The name of the segment A brief description of the contents Whether the segment is read write or read only Whether the segment may be accessed from the assembly language assembly accessible or from the compiler only A fuller description of the segment contents and use BITVARS Bit variables TYPE Read write DESCRIPTION Assembly accessible Holds bit variables and can also hold user written relocatable bit variables This segment is NOT initialised by CSTARTUP 1 101 CCSTR CCSTR String initializers TYPE Read only DESCRIPTION Assembly accessible Holds C string literal initializers when the y put string literal
96. fault segment the stack memory shortad Direct variables to the SHORTAD segment by default SYNTAX fpragma memory shortad DESCRIPTION This directive directs variables to the SHORTAD segment so that they will reside in short direct addressing RAM It is an alternative to the memory attribute near The default may be overridden by the memory attributes No initial values may be supplied in the variable definitions The SHORTAD segment must be linked to coincide with the physical address of short address RAM see Configuration page 1 43 for details EXAMPLES pragma memory shortad int shortad_var in short address memory Ai fpragma memory default int i j default memory type Note that a non default memory pragma will generate error messages if function declarators are encountered Local variables and parameters cannot reside in any other segment than their default segment the stack 1 90 warnings default warnings default Restores compiler warning output to default state SYNTAX pragma warnings default DESCRIPTION Return output of compiler warning messages to the default set by the w compiler option See pragma warnings on and pragma warnings off warnings off Turns off output of compiler warnings SYNTAX tpragma warnings off DESCRIPTION This directive disables output of compiler warning messages regardless of the state of the w compiler option It is an alte
97. ge feature not The compiler does not currently implemented name support the language feature used 106 Too many function parameters Fatal There were too many max is 127 parameters in function declaration definition 2 169 DIAGNOSTICS No Error message Suggestion 107 Function parameter name A formal parameter in a function already declared definition header was declared more than once For example K amp R function int myfunc i i invalid int i Prototyped function int myfunc int i int i invalid 108 Function parameter name In a K amp R function definition declared but not found in parameter declared but not header specified in the function header For example int myfunc i int i j invalid j is not specified in the function header EJ 109 unexpected An unexpected delimiter was encountered 110 unexpected An unexpected delimiter was encountered 111 unexpected An unexpected delimiter was encountered 112 unexpected An unexpected delimiter was encountered 2 170 DIAGNOSTICS No 113 114 115 116 117 118 119 120 121 122 123 Error message unexpected unexpected unexpected Integral expression required Floating point expression required Scalar expression required Pointer expression required Arithmetic expression required Lvalue required
98. going to debug the program you have to add the debugger specific command line options Debugging using C SPY icc78000 prog v2 ms r Debugging using SD78K 0 icc78000 prog v2 ms rr This creates an object module called prog r26 LINKING THE PROGRAM To link the program enter the command xlink prog f 1nk780 The f option specifies your linker command file 1nk780 If you are going to debug the program you have to add the debugger specific command line options Debugging using C SPY xlink prog f 1nk780 r The result of linking is a code file called aout d26 1 26 TUTORIAL Debugging using SD78K 0 xlink prog f 1nk780 r Y The result of linking is a code file called aout d26 This debug file in UBROF file format has to be converted into XCOFF file format using the UBROF to XCOFF conversion utility ubr2xcof aout d26 The result of linking is a code file called aout Ink RUNNING THE PROGRAM To run the program using C SPY or SD78K 0 please follow the instructions given in the User s Manual for the corresponding debugger 1 27 TUTORIAL EXTENDING THE PROGRAM We shall now extend the loop program to access the A D converter built in to the 78P014 microprocessor The resultant program accepts input from A D conversion result register and stores the data in a buffer This A D conversion program demonstrates the use of the pragma directive inclusion of supplied header files use of intri
99. hatever facilities the hardware environment provides The starting point for the user s routines are supplied by default in the files c iar icc78000 putchar candc iar icc78000 getchar c The procedure for creating a customized version of put char is as follows 1 52 Make the required additions to the source putchar c and save it back under the same name Compile the modified putchar using the appropriate memory model For example if the user program uses the small memory model compile putchar c for the small memory model with the command icc78000 putchar v2 ms z9 This will create an optimized replacement object module file named putchar r26 Add the new putchar module to the appropriate run time library module replacing the original For example to add the new putchar module to the standard medium memory model library use the command xlib def cpu 78000 rep mod putchar c17801s exit The library module c17801s will now have the modified putchar instead of the original CONFIGURATION Note that XLINK allows you to test the modified module before installing it the library by using the A option See the IAR 78000 Assembler guide The same procedure is also used for getchar Note that putchar serves as the low level part of the printf function PRINTF AND SPRINTF The printf and sprintf functions use a common formatter called _formatted_write The ANSI standard version of _formatted_writ
100. he third parameter of _formatted_write A pointer to some type of data structure that the low level output function may need If there is no need for anything more than just the character value this parameter must still be specified with void 0 as well as declared in the output function A pointer of type va_list to the variable argument list The number of characters written 2 147 _small write DESCRIPTION A small version of _formatted_write which is about a quarter of the size and uses only about 15 bytes of RAM The _smal1_write formatter supports only the following specifiers for int objects Sd 0 SC S and x It does not support field width or precision arguments and no diagnostics will be produced if unsupported specifiers or modifiers are used For further information see __formatted_write 2 148 K amp R AND ANSI C LANGUAGE DEFINITIONS There are two major standard C language definitions Kernighan amp Richie commonly abbreviated to K amp R This is the original definition by the authors of the C language and is described in their book The C Programming Language The IAR C Compiler is fully compatible with this definition ANSI The ANSI definition is a development of the original K amp R definition It adds facilities that enhance portability and parameter checking and removes a small number of redundant keywords The IAR C Compiler closely follows the ANSI app
101. icating the first non space character DESCRIPTION Converts the ASCII representation of a number into an unsigned long int using the specified base stripping any leading white space If the base is zero the sequence expected is an ordinary integer Otherwise the expected sequence consists of digits and letters representing an integer with the radix specified by base must be between 2 and 36 The letters a z and A Z are ascribed the values 10 to 35 If the base is 16 the 0x portion of a hex integer is allowed as the initial sequence 2 132 tan tan math h Tangent DECLARATION double tan double arg PARAMETERS arg A double value in radians RETURN VALUE The double tangent of arg DESCRIPTION Computes the tangent of arg radians 2 133 tanh tanh math h Hyperbolic tangent DECLARATION double tanh double arg PARAMETERS arg A double value in radians RETURN VALUE The double hyperbolic tangent of arg DESCRIPTION Computes the hyperbolic tangent of arg radians 2 134 tolower tolower ctype h Converts to lower case DECLARATION int tolower int c PARAMETERS c The int representation of a character RETURN VALUE The int representation of the lower case character corresponding to c DESCRIPTION Converts a character into lower case 2 135 toupper toupper ctype h Converts to upper case DECLARATION int toupper int c PARAMETE
102. ilename This allows the user to redirect the listing to a different directory The 1 and L options may not be used at the same time 2 20 0 0 Specifies object filename SYNTAX o file DESCRIPTION Without the 0 option the compiler stores the object code in a file whose name is The prefix specified by 0 The leafname of the source A target specific object code extension The o option sets an entire alternative filename consisting of an optional pathname obligatory leafname and optional extension It allows the object code to be directed to a different file The o and 0 options may not be used at the same time O Specifies object filename SYNTAX Oprefix DESCRIPTION By default the compiler stores the object code in a file whose name is the leafname of the source plus a target specific object code extension 2 21 P Use 0 to specify a prefix which the compiler adds to the leafname allowing the object code to redirected to an alternative directory The o and 0 options may not be used at the same time Formats listing into pages SYNTAX pn DESCRIPTION By default the listing is not divided into pages Use p followed by the number of lines per page in the range 10 to 150 to divide the listing into pages of this size Generates PROMable code SYNTAX P DESCRIPTION By default the compiler places initialized statically allocated objects in the pr
103. in bank 0 A banked call is therefore required declare my_monitor banked void my_monitor void void my_func void call the monitor my_monitor bit Declares a bit variable SYNTAX RELOCATABLE ADDRESS storage class bit identifier SYNTAX FIXED ADDRESS bit identifier constant expression bit selector SYNTAX SFR bit identifier sfr identifier bit selector DESCRIPTION The bit variable is a variable whose storage is a single bit It may have values 0 and 1 only Bit variables should not be confused with the C standard bit fields 1 66 bit A bit variable can be one of three kinds Bit variable type Description Relocatable address The variable is one bit of an ordinary relocatable variable Fixed address The variable is one bit of a location at a fixed address between FE20 and FFFF sfr The variable is one bit of an sfr variable Bit variables can be used in all places where it is allowed to use other integral types except As operand to the unary amp address operator As formal function parameters Asstruct union elements interrupt Declare interrupt function or CALLT function SYNTAX storage class interrupt function declarator storage class interrupt vector function declarator PARAMETERS function declarator A void function declarator having no arguments vector A square bracketed constant expression yielding the vector address
104. io h Puts string DECLARATION int puts const char s PARAMETERS S A pointer to the string to be put RETURN VALUE Result Value Successful A non negative value Unsuccessful 1 if an error occurred DESCRIPTION Writes a string followed by a new line character to the standard output stream 2 102 rand rand stdlib h Random number DECLARATION int rand void PARAMETERS None RETURN VALUE The next int in the random number sequence DESCRIPTION Computes the next in the current sequence of pseudo random integers converted to lie in the range 0 RAND_MAX See srand for a description of how to seed the pseudo random sequence 2 103 realloc realloc stdlib h Reallocates memory DECLARATION void realloc void ptr size_t size PARAMETERS ptr A pointer to the start of the memory block size A value of type size_t specifying the size of the object RETURN VALUE Result Value Successful A pointer to the start lowest address of the memory block Unsuccessful Null if no memory block of the required size or greater was available DESCRIPTION Changes the size of a memory block which must be allocated by malloc calloc or realloc 2 104 scanf scanf stdio h Reads formatted data DECLARATION int scanf const char format PARAMETERS format A pointer to a format string Optional pointers to the variables that are to receive val
105. ion in all other respects 1 69 monitor EXAMPLES char printer_free monitor int got_flag char flag i 1 flag Saiki flag 1 eT 0 a f void 7 got_flag amp printer_free action code printer free semaphore Ry With no danger of interruption test if available yes take no do not take act only if printer is free near Storage modifier SYNTAX storage class near declarator DESCRIPTION The near storage class is the default storage class for any kind of variables It may be used to override the default storage class after a pragma memory saddr or pragma memory shortad directive 1 70 non_banked non_banked Declares a non banked function SYNTAX storage class non_banked declarator DESCRIPTION By default in the banked memory model all functions are callable from any bank The non_banked keyword indicates that the function is always in the same bank as the caller and so can be called by the faster unbanked method EXAMPLES Function foo is local to one file and so is only called by functions within the same file It is therefore always in the same bank as the caller static non_banked void foo void void foocaller void foo call foo by faster non banked method 1 71 no_init no_ init Type modifier for non volatile variables SYNTAX storage class no_init declarator
106. ke management and operation of them as efficient as possible This chapter describes these uses and all the IAR files It refers to the following MS DOS program files 1 8 GETTING STARTED Function Filename Where it is documented 78000 C Compiler jicc78000 This guide 78000 Assembler a78000 IAR 78000 Assembler guide IAR Linker xlink IAR Linker amp Librarian guide IAR Librarian xlib ITAR Linker amp Librarian guide C SPY Simulator cs78000 Using C SPY guide The default installation procedure creates the following directories in c iar Executable files The c iar exe subdirectory holds the MS DOS executable program files These correspond to the IAR commands such as the command to run the compiler The installation procedure includes an addition to the autoexec bat PATH statement directing MS DOS to search the exe sub directory for command files This allows the user to issue an IAR command from any directory For details of the contents see Exe files page 1 11 Miscellaneous files The c iar etc sub directory holds miscellaneous files such as read me files and example sources For details of the contents see Etc files page 1 11 Source files The c iar icc78000 sub directory holds source files for configuration to the target environment and program requirements as described in Configuration page 1 43 For details of the contents see ICC78000 files page 1 12 GETTING STARTED C includ
107. l parameters Program int my_fun parameter type of parameter not declared ay return parameter 1 Error int my_fun parameter type of parameter not declared undecfp c 1 Warning 9 Undeclared function parameter parameter assumed int Missing return values in non void functions Program int my_fun void function body Error noreturn c 4 Warning 22 Non void function explicit return lt expression gt expected Unreferenced local or formal parameters Program void my_fun int parameter unreferenced formal parameter 2 13 8 int localvar unreferenced local variable exit without reference to either variable Error unrefpar c 6 Warning 33 Local or formal localvar was never referenced unrefpar c 6 Warning 33 Local or formal parameter was never referenced Unreferenced goto labels Program int main void function body exit unreferenced label return 0 Error A unreflab c 7 Warning 13 Unreferenced label exit Unreachable code Program include lt stdio h gt int main void goto exit puts This code is unreachable exits return 0 2 14 Error puts This code is unreachable unreach c 7 Warning 20 Unreachable statement s Unmatching or varying parameters to K amp R functions Program int my_fun len str i
108. left of the variable argument list 2 141 _formatted_write _formatted_write icclbutl h Formats and writes data DECLARATION int _formatted_write const char format void outputf char void void sp va_list ap PARAMETERS format outputf Sp ap RETURN VALUE A pointer to standard printf sprintf format specification string A function pointer to a routine that actually writes a single character created by _formatted_write The first parameter to this function contains the actual character value and the second a pointer whose value is always equivalent to the third parameter of _formatted_write A pointer to some type of data structure that the low level output function may need If there is no need for anything more than just the character value this parameter must still be specified with void 0 as well as declared in the output function A pointer of type va_list to the variable argument list The number of characters written 2 142 _formatted_write DESCRIPTION Formats write data This function is the basic formatter of printf and sprintf but through its universal interface can easily be adapted by the user for writing to non standard display devices Since a complete formatter demands a lot of space there are several different formatters to choose For more information see the chapter Configuration in the target specific section _formatted_write is concurrent
109. library function 1 53 2 142 _medium_read library function 1 54 2 144 _medium_write library function 1 53 2 145 _small_write library function 1 53 2 147 78000 specific command line options d 1 117 m 1 115 rr 1 118 V 1 116 W 1 117 A abort library function abs library function acos library function ANSI definition data types function declarations function definition parameters hexadecimal string constants asin library function assembler calling from C files interrupt functions assembly language interface assembly source file assert library function atan library function atan2 library function atof library function atoi library function atol library function B bank switching banked extended keyword banked pointer banked function banked memory model 2 47 2 48 2 49 2 149 2 151 2 152 2 151 2 152 2 50 1 98 1 10 1 98 1 93 1 19 2 51 2 52 2 53 2 54 2 55 2 56 1 48 1 65 1 59 1 48 1 46 IT bit extended keyword 1 66 bitfields default pragma directive 1 79 bitfields reversed pragma directive 1 79 BITVARS segment 1 101 C C include files 1 10 C SPY files 1 10 using 1 26 calloc library function 1 55 2 57 CCSTR segment 1 102 CDATAO segment 1 102 CDATAI segment 1 103 ceil library function 2 58 CODE segment 1 103 code pointers 1 59 codeseg pragma directive 1 81 command file 1 20 command line option
110. lications a highly reduced version of the entire printf function without sprintf is supplied in source form in the file intwri c This file can be modified to the user s requirements and the compiled module inserted into the library in place of the original using the procedure described for putchar above SCANF AND SSCANF In a similar way to the printf and sprintf functions scanf and sscanf use a common formatter called _formatted_read The ANSI standard version of _formatted_read is very large and provides facilities that are not required in many applications To reduce the memory consumption one alternative smaller version is also provided in the IAR C standard library _medium_read As for __formatted_read except that no floating point numbers are supported _medium_read is considerably smaller than __formatted_read The default version is_medium_read SELECTING READ FORMATTER VERSION The selection of a read formatter is made in the linker control file The default selection _medium_read is made by the line e_medium_read _formatted_read To select the full ANSI version remove this line 1 54 CONFIGURATION HEAP SIZE If the library functions malloc or cal loc are used in the program the C compiler creates a heap of memory from which their allocations are made The default heap size is 2000 bytes The procedure for changing the heap size is described in the file c iar etc heap c INITIALIZATION
111. line options summary General command line options General C language extensions General C library definitions C library functions reference K amp R and Ansi C language definitions Diagnostics Compilation error messages Compilation warning messages Index 1 61 1 61 1 62 1 63 1 65 1 79 1 93 1 93 1 94 1 96 1 97 1 97 1 98 1 101 1 113 1 115 1 119 2 1 2 5 2 33 2 37 2 45 2 149 2 155 2 157 2 176 viii INTRODUCTION The IAR Micro Series is a range of integrated development tools that support a wide choice of target microprocessors Amongst these tools are the IAR C Compilers a family of powerful and fast C compilers The IAR C Compiler for the NEC 78000 family of microprocessors offers the standard features of the C language plus many extensions designed to take advantage of the 78000 s specific facilities The compiler is supplied with the IAR Micro Series Assembler for the 78000 with which it is integrated and shares linker and library manager tools KEY FEATURES The IAR C Compiler for the 78000 offers the following key features LANGUAGE FACILITIES Conformance to the ANSI specification Standard library of functions applicable to embedded systems with source license option IEEE compatible floating point arithmetic Powerful extensions for 78000 specific features including efficient I O Generation of fully ROM compatible code without language restrictions
112. lization 1 107 INTVEC INTVEC Interrupt vectors TYPE Read only DESCRIPTION Assembly accessible Holds the interrupt vector table generated by the use of the interrupt extended keyword which can also be used for user written interrupt vector table entries NO_INIT Non volatile variables TYPE Read write DESCRIPTION Assembly accessible Holds variables to be placed in non volatile memory These will have been allocated by the compiler declared no_init or created no_init by use of the memory pragma or created manually from assembly language source 1 108 RCODE RCODE Vector handling code TYPE Read only DESCRIPTION Assembly accessible Used for start up code and interrupt handlers that must reside in non banked memory area SHORTAD Short address memory TYPE Read write DESCRIPTION Assembly accessible Holds static saddr variables which have been declared without explicit initial values They are set to zero by CSTARTUP during initialization SHORTAD can also hold user written data elements that should initially be set to zero 1 109 TEMP TEMP Autos DESCRIPTION Used for autos when compiling with the d option UDATAO Uninitialized shortad statics TYPE Read write DESCRIPTION Assembler accessible Holds static variables which were declared without initial values ANSI C specifies that such variables be set to
113. lloc 1 55 2 57 ceil 2 58 cos 2 59 cosh 2 60 div 2 61 exit 2 62 exp 2 63 fabs 2 64 floor 2 65 fmod 2 66 free 2 67 frexp 2 68 getchar 2 69 gets 2 70 isalnum 2 71 isalpha 2 72 iscntrl 2 73 VI isdigit isgraph islower isprint ispunct isspace isupper isxdigit labs Idexp Idiv log log10 longjmp malloc memchr memcmp memcpy memmove memset modf pow printf putchar puts rand realloc scanf setjmp sin sinh sprintf sqrt srand sscanf 2 74 2 75 2 76 2 77 2 78 2 79 2 80 2 81 2 82 2 83 2 84 2 85 2 86 2 87 2 89 2 90 2 91 2 92 2 93 2 94 2 95 2 96 2 101 2 102 2 103 2 104 2 105 2 109 2 110 2 111 2 112 2 113 2 114 2 115 INDEX strcat strchr strcmp strcoll strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr strtod strtol strtoul tan tanh tolower toupper va_arg va_end va_list va_start library object files limits h header file linker linker command file linking a program list file log library function log10 library function longjmp library function 2 116 2 117 2 118 2 119 2 120 2 121 2 122 2 123 2 124 2 125 2 126 2 127 2 128 2 129 2 130 2 131 2 132 2 133 2 134 2 135 2 136 2 137 2 138 2 139 2 140 2 37 2 44 1 4 1 44 1 26 1 19 2 85 2 86 2 87 VII INDEX M malloc library function 1 55 2 88 math h header file 2 39 memchr library function 2 89 memecmp lib
114. located in the root memory not in any bank Depending on the debugging environment the user may encounter some debugging restrictions when using banked functions For detailed information please refer to the corresponding hardware development tool documentation Also see sections concerning the interrupt banked and non_banked keywords respectively MEMORY LOCATION You need to specify to the linker your hardware environment s address ranges for ROM and RAM You would normally do this in your copy of the linker command file template For how to specify the memory address ranges see the contents of the linker command file template and XLINK in the IAR Assembler Linker amp Librarian for the 78000 NON VOLATILE RAM The compiler supports the declaration of variables that are to reside in non volatile RAM through the no_init type modifier and the memory pragma The compiler places such variables in the separate segment no_init which the user must assign to the address range of the non volatile RAM of the hardware environment The run time system does not initialize these variables To assign the no_init segment to the address of the non volatile RAM the user must modify the linker command file For details how to assign a segment to a given address see XLINK in the IAR 78000 Assembler guide 1 50 CONFIGURATION STACK SIZE The compiler uses a stack for a variety of user program operations and the required st
115. lue AX BC A special technique is used for struct and union return values The caller reserves an area somewhere in it s own auto space and gives the called function an address to that area as first parameter REGISTERS A function written in assembly language should save all registers used in function at function entry and restore them before return SEGMENTS As can be seen in the linker command files Ink xcl supplied with the compiler the C system uses a large number of segments The segments listed in the command files are reserved by the run time system of ICC78000 and may not be used in assembly language programs with the exceptions mentioned in this section This information is of no importance for writing C programs but can be useful for programmers mixing C and assembly language Note that the Ink xcl files supplied with the compiler package should always be used to guarantee that linking see section Linking will work as expected The segments used by the ICC78000 compiler are explained in section Segment Reference 1 97 ASSEMBLY LANGUAGE INTERFACE CALLING ASSEMBLY ROUTINES FROM C An assembler routine that is to be called from C must Conform to the calling convention described above Exit with RET Be located in the segment CODE Have a PUBLIC entry point label Be prototyped before any call to allow type checking and promotions of parameters asin extern int foo inti intj
116. ly reusable reentrant Note that the use of _formatted_write requires the special ANSI defined macros in the file stdarg h described above In particular There must be a variable ap of type va_list There must be a call to va_start before calling _formatted_write There must be a call to va_end before leaving the current context The argument to va_start must be the formal parameter immediately to the left of the variable argument list For an example of how to use __formatted_write see the file printf c 2 143 _medium_read _medium_ read icclbutl h Reads formatted data excluding floating point numbers DECLARATION int _medium_read const char line const char format va_list ap PARAMETERS line A pointer to a pointer to the data to scan format A pointer to a pointer to a standard scanf format specification string ap A pointer of type va_list to the variable argument list RETURN VALUE The number of successful conversions DESCRIPTION A reduced version of _formatted_read which is half the size but does not support floating point numbers For further information see _formatted_read 2 144 _medium_write _medium_ write icclbutl h Writes formatted data excluding floating point numbers DECLARATION int _medium_write const char format void outputf char void void sp va_list ap PARAMETERS format outputf Sp ap RETURN VALUE A poin
117. mb 1 was included at the start of the source It provides a mechanism for command line control of the user s own compilation time options such as configuration or custom debugging or trace routines For simple Boolean control variables it is a more compact mechanism than the more flexible Dsymb xx option D The Dsymb xx option defines a symbol with the specified value as if the line dtdefine symb xx was included at the start of the source To include spaces in the expression surround the whole option by double quotes For example DEXPR F g is equivalent to itdefine EXPR F g To include a double quote character itself follow it immediately by a second double quote character For example DSTRING micro proc is equivalent to define STRING micro proc There is no limit on the number of D options used on a single command line Command lines can become very long when using the D option in which case it may be useful to use a command file see f 2 9 e Enables target dependent extensions SYNTAX e DESCRIPTION Use e to enable extensions that are specific to the particular target By default these are not enabled These extensions are documented in the chapter Language extensions f Reads command line options from a file SYNTAX f file DESCRIPTION Extends the command line with file xcl By default the compiler looks for command parameters only
118. ment There was a break outside any active switch while do while or for statement There is a goto label with no label definition within the function body There is a pointer to a field member of struct or union The first or second argument of a binary operator is missing One of or was found where statement was expected 2 165 DIAGNOSTICS No Error message 81 Declaration after statement This could be due to an unwanted int i char c Invalid Suggestion A declaration was found after a statement for example Since the second is a statement it causes a declaration after a statement 82 else without preceding de Ta ie 83 enum constant s outside int or unsigned int range 84 Function name not allowed in this context 85 Empty struct union or enum 2 166 The probable cause is bad nesting An enumeration constant was created too small or too large An attempt was made to use a function name as an indirect address There is a definition of struct or union that contains no members or a definition of enum that contains no enumeration constants DIAGNOSTICS No Error message Suggestion 86 Invalid formal parameter There is a fault with the formal parameter in a function declaration Possible causes are int f valid K amp R declaration int f i invalid K amp R declaration int f int i v
119. metic rather than user callable functions needed by the C program In addition to that the root memory also contains C string literals variable initializers and optional interrupt handlers The banked memory blocks of the sample system all start at logical address 0x4000 which means that the b flag to the linker should be set like this bCODE 4000 4000 10000 The first parameter is the logical address of the initial bank I O port 0 the second parameter shows that 16K banks were used while the third parameter increment gives bank numbers 0 1 2 3 etc In the banked area there can only be C callable functions both library type like printf as well as the user written C routines IMPORTANT No single module can be larger than the bank size over sized modules result in linker error messages Itis recommended to keep module size considerably smaller than bank size in order to avoid memory fragmentation partially filled banks as the linker only packs complete modules into banks The compiler will in banked mode select the fast standard call method if a function is considered as local i e has the storage class static and is not referenced as a function pointer 1 49 CONFIGURATION The bank switching module 107 s26 must be configured to perform bank switching Follow the comments given in this file Interrupt handlers and the correctly configured 107 r26 bank switching module have to be
120. n identifier The position of an option in the command line has no significance in itself The options are arranged into the following functional groups MEMORY MODEL ms Standard Generates non banked function calls mb Banked Generates banked external function calls mS Same as ms but using call table calls for internal run time library calls mB Same as mb but using call table calls for internal run time library calls PROCESSOR OPTION v0 Processor option 7800X default v1 Processor option 7801X v2 Processor option 78P014 v3 Processor option 7804X v4 Processor option 78P044 5 Processor option 7805X v6 Processor option 7806X v7 Processor option 7802X v8 Processor option 78P024 1 113 COMMAND LINE OPTIONS SUMMARY CODE CONTROL W rs Set register area size d Force static allocation of auto variables arr Supress variable in register optimization 1 114 78000 SPECIFIC COMMAND LINE OPTIONS In addition to the general command line options described in General General command line options page 2 5 the 78000 C Compiler has the following options m Selects memory model SYNTAX m sbSB DESCRIPTION Use the m option to select the memory model as follows Option Memory model S Standard default b Banked S Standard using call table function calls for internal run time library calls B Banked using call table function calls for internal r
121. ne In addition if the filename is enclosed in double quotes as in Hinclude file the compiler first searches the filename prefixed by the source file path Use the I option followed immediately by a path specification to direct the compiler to search for include files on that path There is no limit to the number of I options on a single command line Note that the compiler simply adds the I prefix onto the start of the include filename so it is important to include the final backslash if necessary K Enables C comments SYNTAX K DESCRIPTION C style comments are introduced by and extend to the end of the line By default C style comments are not accepted Use the K option to allow them to be accepted 1 1 Generates a listing SYNTAX 1 file DESCRIPTION By default the compiler does not generate a listing Use the 1 option to generate a listing to the named file The filename consists of a leafname optionally preceded by a pathname and optionally followed by an extension If no extension is given 1st is used The 1 and L options may not be used at the same time L Generates a listing SYNTAX Lprefix DESCRIPTION By default the compiler does not generate a listing The L option generates a listing to a file with the same name as the source leafname but with the extension lst The L option may be followed by a prefix which the compiler adds to the f
122. ne of specified characters in a string DECLARATION char strpbrk const char sl const char s2 PARAMETERS sl A pointer to the subject string s2 A pointer to the object string RETURN VALUE Result Value Successful A pointer to the first occurrence in the subject string of any character from the object string Unsuccessful Null if none were found DESCRIPTION Searches one string for any occurrence of any character from a second string 2 126 strrchr strrchr string h Finds character from right of string DECLARATION char strrchr const char s int c PARAMETERS S A pointer to a string Cc An int representing a character RETURN VALUE If successful a pointer to the last occurrence of c in the string pointed to by s DESCRIPTION Searches for the last occurrence of a character converted to a char ina string The terminating null character is considered to be part of the string 2 127 strspn strspn string h Spans characters in a string DECLARATION size_t strspn const char sl const char s2 PARAMETERS sl A pointer to the subject string s2 A pointer to the object string RETURN VALUE The length of the maximum initial segment of the string pointed to by s1 that consists entirely of characters from the string pointed to by s2 DESCRIPTION Finds the maximum initial segment of a subject string that consists entirely of characters from an object string
123. no_init segment must be linked to coincide with the physical address of non volatile RAM see Configuration page 1 43 for details 1 88 memory no_init EXAMPLES fpragma memory no_init char buffer 1000 in uninitialized memory 7 pragma memory default int i j default memory type Note that a non default memory pragma will generate error messages if function declarators are encountered Local variables and parameters cannot reside in any other segment than their default segment the stack memory saddr Direct variables to the DATAO IDATAO or UDATAO segment by default SYNTAX pragma memory saddr DESCRIPTION This directive directs variables to the DATAO IDATAO or UDATAO segment depending on the compier command line option P so that they will reside in short direct addressing RAM It is an alternative to the memory attribute near The default may be overridden by the memory attributes The DATAO IDATAO or UDATAO segment must be linked to coincide with the physical address of short address RAM see Configuration page 1 43 for details EXAMPLES pragma memory saddr int saddr_var 1 in short address memory pragma memory default int i j default memory type 1 89 memory saddr Note that a non default memory pragma will generate error messages if function declarators are encountered Local variables and parameters cannot reside in any other segment than their de
124. nom PARAMETERS numer The int numerator demon The int denominator RETURN VALUE A structure of type div_t holding the quotient and remainder results of the division DESCRIPTION Divides the numerator numer by the denominator denom The type div_t is defined in stdlib h If the division is inexact the quotient is the integer of lesser magnitude that is the nearest to the algebraic quotient The results are defined such that quot denom rem numer 2 61 exit exit stdlib h Terminates the program DECLARATION void exit int status PARAMETERS status An int status value RETURN VALUE None DESCRIPTION Terminate the program normally This function does not return to the caller This function entry resides by default in CSTARTUP 2 62 exp exp math h Exponential DECLARATION double exp double arg PARAMETERS arg A double value RETURN VALUE A double with the value of the exponential function of arg DESCRIPTION Computes the exponential function of arg 2 63 fabs fabs math h Double precision floating point absolute DECLARATION double fabs double arg PARAMETERS arg A double value RETURN VALUE The double absolute value of arg DESCRIPTION Computes the absolute value of the floating point number arg 2 64 floor floor math h Largest integer less than or equal DECLARATION double floor double arg PARAME
125. ns that incompatibility can be hidden quite deeply for example char p1 8 int char p2 8 float pl and p2 are incompatible the function parameters have incompatible types The compatibility test also includes checking of array dimensions if they appear in the description of the objects pointed to for example int p1 8 int p2 9 p1 and p2 are incompatible array dimensions differ 7 128 Function argument A function argument is incompatible with its incompatible with the argument in declaration the declaration 2 172 DIAGNOSTICS No Error message 129 130 131 132 133 134 135 136 137 Incompatible operands of binary operator Incompatible operands of operator Incompatible return expression Incompatible initializer Constant value required Unmatching struct or union arguments to operator pointer pointer operation Redeclaration error Reference to member of undefined struct or union Suggestion The type of one or more operands to a binary operator was incompatible with the operator The type of one or more operands to was incompatible with The result of the expression is incompatible with the return value declaration The result of the initializer expression is incompatible with the object to be initialized The expression in a case label dFif elif bit field declarator arra
126. nsic functions and use of bit variables The following is a complete listing of the A D conversion program The lines that have been added to the loop program are marked with a vertical bar so using a text editor just add these marked lines to the source of the loop program in your prog c file pragma language extended enable use of extended keywords include lt io78p014 h gt include sfr definitions for IO registers bit AD_Ready IFOH 3 define bit variable mode register bits define ADISO 0x01 conversion channel 0 define EnableAD 0x80 start A D conversion define buffsize OxCO char bufferLbuffsizel lint buffindex 0 int call_count 0 1 28 TUTORIAL BRK KK KKK KKK KK KK KKK KKK KKK KK KK KKK KKK X Start of code KKK KK KKK KK KK KKK KKK KK KK KKK KKK KKK KKK Return 0 if no conversion result available lt gt 0 if data now in ADCR register Kf nt ad_ready void return AD_Ready Data reader poll status register until ready return data AY unsigned char read_data void while ad_ready wait for data return ADCR return A D converted data li u void do_foreground_process void just increment a variable call_count 1 29 TUTORIAL void main void Initialize A D converter ADIS
127. nt len char str str LOJ a return len char buffer 99 int main void my_fun buffer 99 my_fun 99 return 0 Error my_fun buffer 99 varyparm c 14 Warning 26 of parameter my_fun buffer 99 varyparm c 14 Warning 26 of parameter my_fun 99 varyparm c 15 Warning 25 of parameters wrong order of parameters missing parameter wrong order of parameters Inconsistent use of K amp R function changing type wrong order of parameters Inconsistent use of K amp R function changing type missing parameter Inconsistent use of K amp R function varying number 2 15 8 undef on unknown symbols Program define my_macro 99 Misspelt name gives a warning that the symbol is unknown dtundef my_macor int main void return 0 Error d fundef my_macor hundef c 4 Warning 2 Macro my_macor is already undef Valid but ambiguous initializers Program typedef struct tl int fl int f2 typel typedef struct t2 int f3 typel f4 typel f5 type2 typedef struct t3 int f6 type2 f7 int f8 type3 type3 example 99 42 1 2 37 Error type3 example 99 42 1 2 37 ambigini c 4 Warning 12 Incompletely bracketed initializer Constant array indexing out of range Program char buffer 99 int main void buffer 500 a Constant index out of range return 0
128. o unsigned int Can only be directly addressable Resides at a fixed location in the range 0xFF00 to OxFFFF The value of an sfrp variable is the contents of the SFR register at the address constant expression All operators that apply to integral types except the unary amp address operator may be applied to s frp variables Predefined sf rp declarations for popular members of the 78000 family are supplied see Installed files page 1 8 1 75 using e using Declare interrupt function using another register bank SYNTAX storage class interrupt using bank function declarator storage class interrupt vector using bank function declarator PARAMETERS function declarator A void function declarator having no arguments vector A square bracketed constant expression yielding the vector address bank A square bracketed constant expression yielding the alternate bank number DESCRIPTION The using keyword declares an interrupt function handler that switches to another register bank before starting the execution of the program code The bank parameter must be a constant expression in the range of 0 to 3 It specifies the 78000 register bank the interrupt handling function will use 1 76 using EXAMPLES interrupt 0x24 using 2 void ext_0 handler for external interrupt 0 RQ S64 interrupt void using 1 timer_AO handler for timer AO interrupt if P0 3 start
129. ogram memory segment and hence if the program is placed in PROM the program cannot write to them 2 22 q Use the P option to make it possible for a PROMed program to write to initialized statically allocated objects P causes the run time system to copy initialized statically allocated objects from PROM into RAM upon start up Note that P is not required to enable writing to non initialized statically allocated objects This is because the compiler assumes that statically allocated objects that are not initialized will be written to and hence automatically places them in RAM Puts mnemonics in the listing SYNTAX q DESCRIPTION By default the compiler does not include the generated assembly lines in the compilation listing Use q to include assembly lines in the compilation listing as an aid to debugging See also the options a and A r Generates debug information SYNTAX r 012 Li n 2 23 r DESCRIPTION By default the object modules do not contain the additional information required by C SPY or other symbolic debuggers Use r to include this additional information in the object code so a debugger can be used on the module For the option to use to suit C SPY see the Using C SPY guide The following table describes the effect of the modifiers Modifier What it means 0 1 2 Support different debugger hardware For source code debuggers this information should be specified in the app
130. ons Check vector values of declared interrupt functions The no_init keyword can only be used to declare variables with static storage class That is no_init cannot be used in typedefs or applied to auto variables of functions An active pragma memoy no_init can cause such errors when function declaration are found The keywords interrupt non_banked or monitor can only be applied to function declarations 1 119 78000 SPECIFIC DIAGNOSTICS No 146 147 148 149 150 152 153 Error message Unknown pragma identifier name Extension keyword name is already defined by the user expected take address of or i oa fal Attempt to sft sfrp variable Illegal sfrp or range for sfr bit address expected Illegal context for bit saddr shortad sfr sfrp near no_init specifier Suggestion See section pragma Commands This error will occur if a keyworc that can serve as an extension keyword is used as an ordinary identifier when the compiler is executing in ANSI mode and the directive pragma language extended is found sfr declared identifiers must be followed by value The unary amp operator may not be applied to variables declared as bit sfr or sfrp The address expression is not a valid bit sfr or sfrp addres Bad bit declaration syntax This error will be generated
131. onst char nptr long atol void call size_t elsize div_t div int denom void exit void free long int ldiv_t ldi void mal void real const char nptr oc size_t nelem int numer int status void ptr labs long int j v long int numer long int denom oc size_t size int rand void loc void ptr size_t size Terminates the program abnormally Absolute value Converts ASCII to double Converts ASCII to int Converts ASCII to long int Allocates memory for an array of objects Divide Terminates the program Frees memory Long absolute Long division Allocates memory Random number Reallocates memory void srand unsigned int seed Sets random number double strtod const char nptr char endptr long int s nptr cha int base trtol const char r endptr sequence Converts a string to double Converts a string to a long integer GENERAL C LIBRARY DEFINITIONS strtoul STRING HANDLING string h void memchr const void s memchr memcmp memcpy memmove memset strcat strchr strcmp strcoll strcpy strcspn strlen strncat unsigned long int strtoul const char nptr char xendptr base int int c size_t n int memcmp const void sl const void s2 size_t n void memcpy void sl const void s2 size_t n void memmove void sl const void s2
132. ontroller as target device and the r option adds debug information to the output file To link the program enter the command XLINK demo o demo f Ink780 rt 1 40 TUTORIAL The o option selects the debug output file name the f option selects the xlink command file 1nk780 and the rt option adds debug information and library support functions for C SPY s TERMINAL I O functionality to the output file The resulting output file demo d26 can be loaded into C SPY CS78000 v2 demo d26 Then you may follow the tutorial described in the C SPY user s manual page 30 ff COMPILING AND LINKING THE SD78K 0 TUTORIAL Two detailed SD78K 0 tutorials are described in the SD78K 0 primer page 6 1 ff resp 8 1 ff The corresponding source files are available and they must be prepared for debugging The source file names are 78k0sub asm resp 78kO0main c and you can find them on the SD78K 0 distribution disk To assemble the program 78k0sub asm enter the command a78000 78kOsub asm 78k0sub 1st 78k0sub r26 S The S option adds local symbols to the output file To link the program enter the command xlink 78k0sub o sample c 78000 Z CODE CODE 1000 r The o option selects the debug output file name the c option selects the device family option the Z option sets the startaddress for the program code segment and the r option adds debug information to the output file To convert the program to the debug format for SD78
133. orc character In all conversions except c n and all varieties of leading white space characters are skipped scanf indirectly calls getchar which must be adapted for the actual target hardware configuration EXAMPLES For example after the following program tite Ts char name 50 float x n scanf d f s amp i amp x name This input line 25 54 32E 1 Hello World will set the variables as follows n 3 1 25 x 5 432 name Hello World and this function scanf 2d f d 0123456789 amp i amp x name with this input line 56789 0123 56a72 will set the variables as follows i 56 x 789 0 name 56 0123 unassigned 2 108 setjmp setjmp setjmp h Sets jump DECLARATION int setjmp jmp_buf env PARAMETERS env An object of type jmp_buf into which set jmp is to store the environment RETURN VALUE Zero Execution of a corresponding 1ongjmp causes execution to continue as if it was a return from set jmp in which case the value of the int value given in the longjmp is returned DESCRIPTION Saves the environment in env for later use by 1ongjmp Note that set jmp must always be used in the same function or at a higher nesting level than the corresponding call to longjmp 2 109 sin sin math h Sine DECLARATION double sin double arg PARAMETERS arg A double value in radians RETURN VALUE The double sine of arg DESCRIPT
134. pecifier for field assumed int Undeclared function parameter name assumed Int Dimension of array ignored array assumed pointer found within a comment and ignored In this implementation bit fields may be specified only as int or unsigned int An undeclared identifier in the header of a K amp R function definition is by default given the type int An array with an explicit dimension was specified as a formal parameter and the compiler treated it as a pointer to object 2 177 DIAGNOSTICS No 11 12 13 14 15 16 17 18 Warning message Storage class static ignored name declared extern Incompletely bracketed initializer Unreferenced label name Type specifier missing assumed int Wrong usage of string operator or dHE ignored Suggestion An object or function was first declared as extern explicitly or by default and later declared as static The static declaration is ignored To avoid ambiguity initializers should either use only one level of brackets or be completely surrounded by brackets Label was defined but never referenced No type specifier given in declaration assumed to be int This implementation restricts usage of and JHF operators to the token field of parameterized macros In addition the operator must precede a formal parameter tdefine mac pl p1 define mac p1 p2 Non void fun
135. piler and shows how it fits in with the other IAR development tools Getting started then shows how to install the C compiler and its associated files and explains the function of these files Using the C compiler describes how to run the 78000 C Compiler and gives information about file formats it uses The Tutorial illustrates how you might use the C compiler to develop a series of typical programs and illustrates some of the compiler s most important features It also describes a typical development cycle using the C compiler Configuration then describes how to configure the C compiler for different requirements Data representation describes how the compiler represents each of the C data types 78000 language extensions describes the extended keywords pragma keywords and intrinsic functions specific to the 78000 C Compiler Extended keyword reference then gives reference information about each of the extended keywords iii ABOUT THIS GUIDE pragma directive reference gives reference information about the pragma keywords Assembly language interface describes the interface between C programs and assembly language routines 78000 specific command line options summary gives a summary of the additional command line options in the 78000 C Compiler 78000 specific command line options describes the additional command line options in the 78000 C Compiler IAR C COMPILER GENERAL FEATURES This part consi
136. ple for version 2 34E the value of __VER__ is 234 TARGET IDENTIFICATION The macro ___TID__ returns a long integer constant containing a target identifier and related information 15 14 87 43 0 support to each target processor if supported if supported 3 16 To find the value of Target_IDENT for the current compiler execute printft 1d __TID__ gt gt 8 amp 0x7F For an example of the use of __TID__ see the file stdarg h 2 33 GENERAL C LANGUAGE EXTENSIONS ARGUMENT TYPE _argt is a unary operator with the same syntax and argument as sizeof It returns a normalized value describing the type of the argument Result Type je Unsigned char Char Unsigned short Short Unsigned int Int Unsigned long Long Oo Oo N oO A W N Float Double Eg Long double Pointer address Union gt W PY Struct For an example of the use of _argt see the file stdarg h 2 34 GENERAL C LANGUAGE EXTENSIONS FUNCTION PARAMETERS DESCRIPTION _args is a reserved word that returns a char array char containing a list of descriptions of the formal parameters of the current function Offset Contents 0 Parameter 1 type in __argt format 1 Parameter 1 size in bytes 2 Parameter 2 type in _argt format 3 Parameter 2 size in bytes 2n 2 Parameter n type in __argt format 2n 1 Parameter n size in bytes 2n 0 Sizes greater than 127 are reported as 127
137. r available DESCRIPTION Allocates a memory block for an object of the specified size The availability of memory depends on the default heap size 2 88 memchr memchr string h Searches for a character in memory DECLARATION void memchr const void s int c size_t n PARAMETERS S A pointer to an object c An int representing a character n A value of type size_t specifying the size of each object RETURN VALUE Result Value Successful A pointer to the first occurrence of c in the n characters pointed to by s Unsuccessful Null DESCRIPTION Searches for the first occurrence of a character in a pointed to region of memory of a given size Both the single character and the characters in the object are treated as unsigned 2 89 memcmp memcmp string h Compares memory DECLARATION int memcmp const void sl const void s2 size_t n PARAMETERS sl A pointer to the first object s2 A pointer to the second object n A value of type size_t specifying the size of each object RETURN VALUE An integer indicating the result of comparison of the first n characters of the object pointed to by s1 with the first n characters of the object pointed to by s2 Return value Meaning gt 0 sl lt s2 0 sl s2 lt 0 sl lt s2 DESCRIPTION Compares the first n characters of two objects 2 90 memcpy memcpy string h Copies memory DECLARATION void memcpy voi
138. r division or modulo is zero 96 Unknown size of object pointed to 97 Undefined static function name 98 Primary expression expected space Zero length fields are only used to align fields to the next int boundary and cannot be accessed via an identifier An attempt was made to divide by Zero An incomplete pointer type is used within an expression where size must be known A function was declared with static storage class but never defined An expression was missing 2 168 DIAGNOSTICS No Error message Suggestion 99 Extended keyword not allowed An extended processor specific in this context keyword occurred in an illegal context eg interrupt int i 100 Undeclared identifier There was a reference to an name identifier that had not been declared 101 First argument of The dot operator was applied to operator must be of struct an argument that was not struct or union type or union 102 First argument of gt was The arrow operator gt was applied not pointer to struct or to argument that was not pointer union to a struct or union 103 Invalid argument of sizeof The sizeof operator was applied operator to a bit field function or extern array of unknown size 104 Initializer string exceeds An array of char with explicit array dimension dimension was initialized with a string exceeding array size For example char array 4 abcde invalid 105 Langua
139. racter A character not included in the C encountered xhh ignored character set was found 9 Invalid floating point A floating point constant was constant found to be too large or have invalid syntax See the ANSI standard for legal forms 10 Invalid digits in octal The compiler found a non octal constant digit in an octal constant Valid octal digits are 0 7 11 Missing delimiter in literal No closing delimiter or was or character constant found in character or literal constant 12 String too long max is 509 The limit for the length of a single or concatenated strings was exceeded 13 Argument to define too Lines terminated by resulted in a long max is 512 ifdef ine line that was too long 2 158 DIAGNOSTICS No Error message 14 15 16 17 18 19 20 21 22 23 24 Too many formal parameters for define max is 127 or expected Identifier expected Space or tab expected Macro parameter name redefined Unmatched else endif or elif No such pre processor command name Unexpected token found in pre processor line Too many nested parameterized macros max is 50 Too many active macro parameters max is 256 Too deep macro nesting max is 100 Suggestion Fatal Too many formal parameters were found in a macro definition 4 def ine directive The compiler found an invalid syntax of a function definition header or macro
140. rary function 2 90 memcpy library function 2 91 memmove library function 2 92 memory model 1 44 1 115 memory constseg pragma directive 1 85 memory dataseg pragma directive 1 86 memory default pragma directive 1 87 memory near pragma directive 1 87 memory no_init pragma directive 1 88 memory saddr pragma directive 1 89 memory shortad pragma directive 1 90 memset library function 2 93 miscellaneous files 1 9 1 11 modf library function 2 94 monitor extended keyword 1 69 N near extended keyword 1 70 no_init extended keyword 1 72 NO_INIT segment 1 108 non banked pointer 1 59 non banked function 1 50 non volatile RAM 1 50 non_banked extended keyword 1 71 O object file 1 19 P Parameter passing 1 94 pointers banked 1 59 non banked 1 59 pow library function 2 95 printf library function 1 53 2 96 processor type 1 116 putchar library function 1 52 2 101 puts library function 2 102 VII R rand library function RCODE segment read me files realloc library function recommendations register area size register optimization Registers Return value run time library running a program running the C compiler S saddr extended keyword scanf library function 1 54 Segment segments BITVARS CCSTR CDATAO CDATAI1 CODE CONST CSTACK CSTR DATAO DATAI1 ECSTR IDATAO IDATA1 INTVEC NO_INIT 1 49 2 103 1 109 1 8 2 104
141. re may not be more than 256 functions in use in a module Note that there are no limits to the number of declared functions The was missing from a bit declaration See Diagnostics COMPILATION WARNING MESSAGES No 0 Warning message Macro name redefined Macro formal parameter name is never referenced Macro name is already tundef Macro name called with empty parameter s Suggestion A symbol defined with define was redeclared with a different argument or formal list A define formal parameter never appeared in the argument string dfundef was applied to a symbol that was not a macro A parameterized macro defined in a define statement was called with a zero length argument 2 176 DIAGNOSTICS No 10 Warning message Macro name is called recursively not expanded Undefined symbol name in dif or elif assumed zero Unknown escape sequence c assumed c Suggestion A recursive macro call makes the pre processor stop further expansion of that macro It is considered as bad programming practice to assume that non macro symbols should be treated as zeros in if and e1 if expressions Use either ifdef symbol or if defined symbol A backslash found in a character constant or string literal was followed by an unknown escape character Nested comment found without The character sequence was using the C option Invalid type s
142. rn data A unsigned char read_data void while ad_ready wait for data return ADCR return A D converted data void do_foreground_process void just increment a variable call_count Example interrupt handler Take control of A D conversion completion xJ 1 37 TUTORIAL interrupt LINTBRK_vect void ad_exception void call_count 0 void main void Initialize A D converter ADIS ADISO ADM EnableAD 1 now loop forever taking input when ready while 1 if ad_ready bufferLbuffindex read_data if buffindex buffsize process full buffer buf findex 0 simple processing discard data if buffer buffindex 1 OxFF _OPC OxBF Generate BRK interrupt do_foreground_process The change is from define buffsize 0xC0 to define buffsize 0x1000 This sets a buffer size of 0x1000 bytes too large to fit in the internal RAM which is 1024 bytes 1 38 TUTORIAL COMPILING THE LARGE BUFFER PROGRAM Compile the program as before icc78000 prog v2 ms If you are going to debug the program you have to add the debugger specific command line options Debugging using C SPY icc78000 prog v2 ms r Debugging using SD78K 0 icc78000 prog v2 ms rr LINKING THE LARGE BUFFER PROGRAM If you try to link the program as before you will get the following e
143. rnative to the w compiler option 1 91 warnings on warnings on Turns on output of compiler warnings SYNTAX pragma warnings on DESCRIPTION This directive enables output of compiler warning messages regardless of the state of the w compiler option 1 92 ASSEMBLY LANGUAGE INTERFACE The IAR C Compiler allows assembly language modules to be combined with compiled C modules This is particularly used for small time critical routines that need to be written in assembly language and then called from a C main program This chapter describes the interface between a C main program and assembly language routines CREATING A SHELL The recommended method of creating an assembly language routine with the correct interface is to start with an assembly language source created by the C compiler To this shell the user can easily add the functional body of the routine The shell source needs only to declare the variables required and perform simple accesses to them for example int k int foo int i char c i j c k void f void foo 4 5 int j Access to i Access to j Access to c Access to k Call to foo i y j y wee hs z7 1 93 ASSEMBLY LANGUAGE INTERFACE This program is then compiled as follows icc78000 shell A q L z0 The A option creates an assembly language output q includes the C source lines as
144. ropriate debugger manual For debuggers that do not support C source line display the default 0 is sufficient i include file information will be added to the object file Note that this is usually of little interest unless include files contain function definitions not just declarations Also note that C statements in inc ude files are practically non debuggable with debuggers other than C SPY A side effect is that source line records will contain the global total line count which can affect source line displays in some debuggers n Suppresses the generation of C source lines in the object file which is only required by C SPY and other debuggers based on the IAR debug format For most other debuggers that do not include specific information on how to use IAR C Compilers rn should be specified Do not use r without n unless specifically required since this increases the memory requirement considerably 2 24 R Note that global optimization activated by the z or s options may invalidate source line information due to statement combinations and rearrangements performed by the compiler and that this can affect source code displays during program stepping Also note that the r option generates slightly more target code and includes type information as if g had been used R Sets the code segment name SYNTAX Rname DESCRIPTION By default the compiler places executable code in a segment named CODE
145. roved standard X3 159 1989 Both standards are described in depth in the latest edition of The C Programming Language by Kernighan amp Richie This chapter summarizes the differences between the standards and is particularly useful to programmers that are familiar with K amp R C but would like to use the new ANSI facilities ENTRY KEYWORD In ANSI C the entry keyword is removed so allowing entry to be a user defined symbol CONST KEYWORD ANSI C adds const an attribute indicating that a declared object is unmodifiable and hence may be compiled into a read only memory segment For example const int i constant int const int ip variable pointer to constant int 2 149 K amp R AND ANSI C LANGUAGE DEFINITIONS int const ip constant pointer to variable int typedef struct define the struct cmd_entry RJ char command void function void cmd_entry const cmd_entry table declare a constant object of type cmd_entry help do_help reset do_reset quit do_quit F VOLATILE KEYWORD ANSI C adds volatile an attribute indicating that the object may be modified by hardware and hence any access should not be removed by optimization SIGNED KEYWORD ANSI C adds signed an attribute indicating that an integer type is signed It is the counterpart of unsigned and can be used before any integer type specifier VOID KEYWORD ANSI C adds void a type specifier that can b
146. roximately 7 decimal digits OBJECT POINTERS Object pointers pointers to variables do not point only to one memory type rather they can point to either short direct address memory saddr or shortad pointer or external data memory area near pointer of the 78000 The size of a pointer is 2 bytes always CODE POINTERS The code pointers are Keyword Storage in bytes Restrictions non banked 2 May only point into one bank banked 3 No restrictions The non banked pointer is used to reference only functions that are in the default code bank giving efficient access The banked pointer can reference any function and is less efficient 1 59 DATA REPRESENTATION Which of these pointer types is used as the default is determined by the memory model see Memory model page 1 45 EFFICIENT CODING It is important to appreciate the limitations of the 78000 architecture in order to avoid the use of inefficient language constructs The following is a list of recommendations on how best to use the ICC78000 1 60 Use 16 bit data types whenever possible 1 ong integers have no direct support in the 78000 architecture Also note that according to the ANSI C standard all data types that are shorter than int should undergo integral promotion ie implicit type conversions when used in arithmetic expressions Use unsigned data types whenever possible The 78000 generally performs unsigned operations more effici
147. rror Error 16 Segment DATA1 is too long for segment definition This occurs because there is insufficient RAM in the linker command file s target description Before proceeding edit the linker command file following the instructions within it to cover the following additional memory RAM 0xC000 to OxDFFF Save the linker command file and link the program as before by entering xlink prog f 1nk780 r 1 39 TUTORIAL If you are going to debug the program you have to add the debugger specific command line options Debugging using C SPY xlink prog f 1nk780 r Debugging using SD78K 0 xlink prog f 1nk780 r Y This time the link will complete confirming that the larger buffer size is available to the program RUNNING THE PROGRAM To run the program using C SPY or SD78K 0 please follow the instructions given in the User s Manual for the corresponding debugger COMPILING AND LINKING THE C SPY TUTORIAL A detailed C SPY tutorial is described in the C SPY user s manual page 27 ff The corresponding debug file is available and already prepared for debugging The name is demo d26 and you can find it in the iar cs78000 subdirectory You may modify this tutorial program if you wish To do so you have to create a source file demo c which should contain the C source code you like To compile the program demo c enter the command ICC78000 demo c v2 r The v2 option selects the u PD78P014 microc
148. ry function 2 125 strpbrk library function 2 126 UDATAO segment 1 110 strrchr library function 2 127 UDATAI segment 1 111 strspn library function 2 128 union keyword 2 153 strstr library function 2 129 using extended keyword 1 76 strtod library function 2 130 strtol library function 2 131 V strtoul library function 2 132 struct keyword 2 153 va_arg library function 2 137 T va_end library function 2 138 va_list library function 2 139 va_start library function 2 140 tan library function 2 133 void keyword 2 150 tanh library function 2 134 volatile keyword 2 150 target identification 2 33 TEMP segment 1 110 text editor 1 3 W tolower library function 2 135 toupper library function 2 136 warning messages 2 176 tutorial 1 21 warnings default pragma compiling a program 1 25 directive 1 91 configuring to suit the warnings off pragma directive 1 91 target program 1 23 warnings on pragma creating a project directory 1 23 directive 1 92 interrupt handler 1 32 WCSTR segment 1 111 linking a program 1 26 WRKSEG segment 1 112 X XLINK 1 122 XLINK Linker 1 4 XLINK option b 1 49 XLINK_DFLTDIR environment variable 1 10 Z ZVECT segment 1 112 INDEX XI INDEX XII
149. s a 2 5 A 2 6 b 2 7 C 2 7 C 2 8 D 2 8 2 10 f 2 10 F 2 11 g 2 11 G 2 17 H 2 17 INDEX i 2 18 I 2 18 K 2 19 12 20 L 2 20 m 1 48 O 2 21 O 2 21 p 2 22 P 2 22 q 2 23 T 2 23 R 2 25 S 2 25 S 2 26 t 2 26 T 2 27 U 2 27 W 2 28 X 2 29 X 2 29 y 2 30 Z 2 31 78000 specific 1 115 command line options summary 1 113 2 1 compiler version 2 33 compiling a program 1 25 configuration 1 43 const keyword 2 149 CONST segment 1 104 cos library function 2 59 cosh library function 2 60 CSTACK segment 1 104 cstartup routine 1 55 CSTR segment 1 105 ctype h header file 2 38 II INDEX D data representation 1 57 data types 2 151 DATAO segment 1 105 DATAI segment 1 106 development cycle 1 22 development system structure 1 3 diagnostics 2 155 78000 specific 1 119 1 122 error messages 2 157 warning messages 2 176 directives include 1 18 pragma 1 28 1 79 directories etc 1 11 exe 1 11 icc78000 1 12 inc 1 13 lib 1 15 disable_interrupt intrinsic function 1 63 div library function 2 61 E ECSTR segment 1 106 efficient coding 1 60 enable_interrupt intrinsic function 1 63 entry keyword 2 149 enum keyword 1 58 2 151 environment variables XLINK_DFLTDIR 1 10 errno h header file 2 44 error messages 2 157 etc directory 1 11 exe directory 1 11 executable files 1 9 1 11 exit library function 2 62 exp library function 2 63 extende
150. s given in the User s Manual for the corresponding debugger USING ADDITIONAL MEMORY If the target system has external RAM in addition to the internal RAM in the 78000 device the C program can make use of this for data storage For example our current program has a small buffer which fits into the internal RAM A large buffer may not fit into the internal RAM but it can be moved to external RAM as the following program demonstrates The program lines that have changed are marked with a bar so using a text editor just change these marked lines in the source of the interrupt program in your prog c file fpragma language extended Finclude lt i078p014 h gt d Finclude lt in78000 h gt bit AD_Ready IFOH 3 mode register bits dtdefine ADISO 0x01 dtdefine EnableAD 0x80 define buffsize 0x1000 char bufferLbuffsize int buffindex 0 int call_count 0 enable use of extended keywords include sfr definitions for IO registers include for intrinsic functions define bit variable conversion channel 0 start A D conversion 1 36 TUTORIAL BRK KK KKK KKK KK KK KKK KKK KKK KK KK KKK KKK X Start of code KKK KKK KKK KKK KKK KKK KK KKK KKK KKK KK KKK Return 0 if no conversion result available lt gt 0 if data now in ADCR register 7 int ad_ready void return AD_Ready Data reader poll status register until ready retu
151. s into variable section and P generate PROMable code compiler option are active CDATAO Variable initializers TYPE Read only DESCRIPTION Compiler only Holds variable initializers for the variables located in the corresponding IDATAO segment These values are copied over from CDATAO to IDATAO by CSTARTUP during initialization 1 102 CDATAI1 CDATAI Variable initializers TYPE Read only DESCRIPTION Compiler only Holds variable initializers for the variables located in the corresponding IDATA1 segment These values are copied over from CDATA1 to IDATA1 by CSTARTUP during initialization CODE Code TYPE Read only DESCRIPTION Assembly accessible Holds user program code various library routines that can run in alternative banks and code from assembly language modules Note that any assembly language routines included in the CODE segment must meet the calling convention of the memory model in use 1 103 CONST CONST Constants TYPE Read only DESCRIPTION Assembly accessible Used for storing const and code objects Can be used in assembly language routines for declaring constant data CSTACK Stack TYPE Read write DESCRIPTION Assembly accessible Holds the internal stack 1 104 CSTR CSTR String literals TYPE Read only DESCRIPTION Assembly accessible Holds C string literals See the description of the y
152. se See C library functions reference page 2 45 The source of the _formatted_write used by printf sprintf See C library functions reference page 2 45 The source of the _formatted_read used by scanf and sscanf functions See C library functions reference page 2 45 The source of the sieve example program ICC78000 FILES This sub directory contains the following configuration starting point files Name Function c iar icc78000 icc78000 doc Additional information about the C compiler c iar icc78000 1nk780 xcl Linker command files provided c iar icc78000 1nk780b xcl for compatibility with other 1 12 GETTING STARTED Name Function c iar icc78000 putchar c The source of putchar See Configuration page 1 43 c iar icc78000 getchar c The source of getchar See Configuration page 1 43 c iar icc78000 cstartup s26 The source of CSTARTUP See Configuration page 1 43 c iar icc78000 107 s526 The source of the stack check module See Configuration page 1 43 c iar icc78000 global doc Additional information about the global optimiser c iar icc78000 iccdemo bat The command file which runs a short demonstaration of the IAR tools for 78000 INC FILES This sub directory contains the following C include files Name Function c iar inc string h Header files for standard C library c iar inc float h functions see C library functions c iar inc math h reference page 2
153. se of multiple modules allows code sizes up to 16 Mbytes In all models the stack and global variables must fit into one single 64 Kbyte In both standard and banked memory model runtime library functions can be accessed by CALLT instruction The advantage of CALLT runtime library calls is the reduction of the program code size of two bytes for every function call but you have to accept the penalty of some additional instruction cycles for execution of this instruction Details are described in the 78000 User s Manual SPECIFYING THE MEMORY MODEL The user s program may use only one model at a time that is the same model must be used by all user modules and all library modules The memory model must be specified to both the compiler and to the linker 1 45 CONFIGURATION To specify the memory module to the compiler when a user module is compiled you use one of the following command line options Option Model ms Small memory model internal library calls using CALL instruction mS Small memory model internal library calls using CALLT instruction mb Banked memory model internal library calls using CALL instruction mB Banked memory model internal library calls using CALLT instruction For example to compile myprog for the 78P014 with optimization in the small memory model and CALLT instruction for internal library calls use the command icc78000 myprog v2 mS z9 If you include none of the m
154. segment by default The segment must not be one of the compiler s reserved segment names as listed in Assembly language interface page 1 93 function banked Makes function definitions banked SYNTAX pragma function banked DESCRIPTION This directive makes subsequent function definitions banked It is an alternative to the function attribute banked EXAMPLES pragma function banked extern void f1 Identical to extern banked void f1 CAUTION Depending on the debugging environment the user may encounter some debugging restrictions when useing banked functions For detailed information pleas refer to the corresponding hardware development tool documentation 1 81 function default function default Restores function definitions to the default type SYNTAX tpragma function default DESCRIPTION Return function definitions to near or far as set by the selected memory model See function banked EXAMPLES fpragma function banked extern void f1 Identical to extern far void fl tpragma function default extern int f3 Default function type E function interrupt Makes function definitions interrupt SYNTAX fpragma function interrupt DESCRIPTION This directive makes subsequent function definitions of interrupt type It is an alternative to the function attribute interrupt Note that pragma function interrupt does not offer a vector option
155. size_t n void memset void s int c size_t n char strceat char sl const char s2 char strchr const char s int c int strcmp const char s1 const char s2 int strcoll const char sl const char s2 char strcpy char sl const char s2 size_t strcspn const char s1 const char s2 size_t strlen const char s char strncat char sl const char s2 size_t n Converts a string to an unsigned long integer Searches for a character in memory Compares memory Copies memory Moves memory Sets memory Concatenates strings Searches for a character in a string Compares two strings Compares strings Copies string Spans excluded characters in string String length Concatenates a specified number of characters with a string 2 43 GENERAL C LIBRARY DEFINITIONS strncmp strncpy strpbrk strrchr strspn strstr COMMON DEFINITIONS stddef h int strncmp const char s1 const char s2 size_t n char strncpy char s1 const char s2 size_t n char strpbrk const char xsl const char s2 char strrchr const char s int c size_t strspn const char xsl const char s2 char strstr const char sl const char s2 Compares a specified number of characters with a string Copies a specified number of characters from a string Finds any one of specified characters in a string Finds character from right of string
156. source filename LINE Current source line number __TIME__ Current time in hh mm ss format DATE Current date in Mmm dd yyyy format The U option can be used to switch off any of these symbols to resolve a conflict with any user defined symbol of the same name W Disables warnings SYNTAX W DESCRIPTION By default the compiler issues standard warning messages and any additional warning messages enabled with g Use w to inhibit all warning messages 2 28 X Generates a cross reference list SYNTAX xX D F ET 2 DESCRIPTION By default the compiler does not include global symbols in the listing The x option with no argument list adds a list of all global symbols and their meanings at the end of the compilation listing This includes all variable objects and all referenced functions define statements enum statements and typedef statements To include additional information follow x by one or more of the following Argument Information D Unreferenced def ine symbols F Unreferenced function declarations T Unreferenced enum constants and typedefs 2 Dual line spacing between symbol entries X Describes C declarations SYNTAX X 2 29 y DESCRIPTION Use X to display a readable description of all the C declarations in the file EXAMPLES For the declaration void signal int _ sig void func int the following output will be produced
157. sprint isprint ctype h Printable character equality DECLARATION int isprint int c PARAMETERS c An int representing a character RETURN VALUE An int which is non zero if c is a printable character including space else Zero DESCRIPTION Tests whether a character is a printable character including space 2 77 ispunct ispunct ctype h Punctuation character equality DECLARATION int ispunct int c PARAMETERS Cc An int representing a character RETURN VALUE An int which is non zero if c is printable character other than space digit or letter else zero DESCRIPTION Tests whether a character is a printable character other than space digit or letter 2 78 isspace isspace ctype h White space character equality DECLARATION int isspace int c PARAMETERS c An int representing a character RETURN VALUE An int which is non zero if c is a white space character else zero DESCRIPTION Tests whether a character is a white space character that is one of the following Character Symbol Space e Formfeed f New line n Carriage return r Horizontal tab t Vertical tab v 2 79 isupper isupper ctype h Upper case equality DECLARATION int isupper int c PARAMETERS An int representing a character RETURN VALUE An int which is non zero if c is upper case else zero DESCRIPTION Tests whether a character is an upper
158. ss program space and stack is provided in the file intwri c EXAMPLES After the following C statements int i 6 j 6 char p ABC long 1 100000 float f1 0 0000001 f2 750000 double d 2 2 the effect of different printf function calls is shown in the following table _ represents space 2 99 printf Statement Output Number of characters output printf c pl1 B 1 printf d 7 6 1 printf 3d i __6 3 printf 3d i 006 3 printf 10 3d i 006 10 printf 10 3d 7 006 10 printf Value 3d i Value _ 6 9 printf 10 d i j 000006 10 printf String s p String ABC 12 printf Value 41X 1 Value 186A0 11 printf f f1 0 000000 8 printf f f2 750000 000000 13 printf e f1 1 000000e 07 12 printf 16e d ___2 200000e 00 16 printf 4e d 2 2000e 00 10 printf g f1 le 07 5 printf 4g f2 750000 6 printf g d 2 2 3 2 100 putchar putchar stdio h Puts character DECLARATION int putchar int value PARAMETERS value The int representing the character to be put RETURN VALUE Result Value Successful value Unsuccessful The EOF macro DESCRIPTION Writes a character to standard output The user must customize this function for the particular target hardware configuration The function is supplied in source format in the file putchar c This function is called by printf 2 101 puts puts std
159. st copies the supplied template c iar icc78000 1nk780 xcl or c iar icc78000 1nk780b xc1 The user then modifies this file as described within the file to specify the details of the target system s memory map MEMORY MODEL The 78000 microprocessor supports a call table mechanism which allows to reduce the code size when function calls are issued A function call using the call table results in a one byte instruction while the standard function call requires three bytes The IAR C Compiler makes use of this by supporting two memory models for each calling mechanism These offer a choice of function 1 44 CONFIGURATION call mechanism which affects execution speed and code size versus maximum size of program code Standard call mechanism Small memory model Banked memory model Variable area lt 64 Kbytes lt 64 Kbytes External RAM Yes Yes Code size 64 Kbytes gt 1Mbyte The function call mechanism for internal library calls may be selected by the compiler option ms mS and mb mB CHOOSING A MEMORY MODEL In the small memory model default data and default code are both in the 64K address range meaning that there is less than 64 Kbytes for code global data and local data In the banked memory model code accesses is slower due to the use of the bankswitcher but code may be placed in any available bank allowing code size to exceed 64 Kbytes Though any one module s code cannot exceed 64 Kbytes the u
160. sts of the following chapters General command line options summary gives a summary of the C compiler command line options General command line options then provides reference information about each command line option General C language extensions describes the C language extensions provided for all target processors C library functions summary gives an introduction to the C library functions and summarizes them according to header file C library functions reference then gives reference information about each library function K amp R and ANSI C language definitions describes the differences between the K amp R description of the C language and the ANSI standard Finally Diagnostics lists the compiler warning and error messages iv ABOUT THIS GUIDE ASSUMPTIONS This guide assumes that you already have a working knowledge of the following The NEC 78000 processor The 78000 processor assembler language MS DOS or UNIX depending on your host system It does not attempt to describe the C language itself For a description of the C language The C Programming Language by Kernighan and Richie is recommended of which the latest edition also covers ANSI C CONVENTIONS This user guide uses the following typographical conventions Style Used for computer Text that you type in or that appears on the screen parameter What you should type as part of a command option An optional part of a command r
161. successive argument following the format string to be evaluated converted and written 2 96 printf The form of a conversion specification is as follows flags Lfield_width L precision length_modifier conversion Items inside are optional Flags The flags are as follows Flag Effect Left adjusted field Signed values will always begin with plus or minus sign space Values will always begin with minus or space if Alternate form specifier effect octal First digit will always be a zero Gg Decimal point printed and trailing zeros kept Eef Decimal point printed X Non zero values prefixed with 0X xX Non zero values prefixed with 0X 0 Zero padding to field width for d i 0 u x X e E f g and G specifiers Field width The field_width is the number of characters to be printed in the field The field will be padded with space if needed A negative value indicates a left adjusted field A field width of stands for the value of the next successive argument which should be an integer Precision The precision is the number of digits to print for integers d i 0 u x and X the number of decimals printed for floating point values e E and f and the number of significant digits for g and G conversions A field width of 2 97 printf stands for the value of the next successive argument which should be an integer Length modifier The effect of each 1ength_modi fier is
162. t one byte constant at the current address The _HALT and _STOP intrinsics do not only insert the requested instruction HALT resp STOP but a NOP instruction as well This additional NOP instruction is necessary due to some device internal structures Intrinsics should be used with greatest caution since they potentially affect the rest of the C code For details concerning the effects of the intrinsic functions see the 78000 User s Manual 1 64 EXTENDED KEYWORD REFERENCE This chapter describes the extended keywords in alphabetical order The following parameters are used Parameter What it means storage class Denotes an optional keyword extern or static declarator Denotes a standard C variable or function declarator banked Declares a banked function SYNTAX storage class banked declarator DESCRIPTION In the small memory model the default position for functions is within the single data bank The banked keyword indicates that the function is in a different bank and so must be called by the slower banked method CAUTION Depending on the debugging environment the user may encounter some debugging restrictions when useing banked functions For detailed information pleas refer to the corresponding hardware development tool documentation 1 65 banked EXAMPLES The function my_func is compiled using the medium memory model It calls an assembly routine my_monitor which is located
163. tack contains the following low memory Return address SP 1 st parameter not in register SP 2 2 nd parameter not in register SP 4 3 rd parameter not in register SP 6 4 th parameter not in register SP 8 high memory n th parameter not in register The return address in the banked memory model or for a function will also contain the banking return address and the bank number of the invoking function These are the last objects put on stack immediatly after an entry into a function 1 95 ASSEMBLY LANGUAGE INTERFACE low memory Bank return address Bank number Return address l st parameter not in register 2 nd parameter not in register 3 rd parameter not in register high memory n th parameter not in register SP SP 2 SP 4 SP 6 SP 8 SP 10 A function is always responsible for deallocating all own variables from stack before returning to the caller Deallocation of a functions parameters stored on stack is done by called function if prototyped function by calling function if non prototyped function FUNCTION RETURN VALUE Function return values are passed in register s except for structs and unions The following register allocation is used Size Register 1 bit return value A O 1 byte return value A 2 byte return value AX 1 96 ASSEMBLY LANGUAGE INTERFACE Size Register 3 byte return value AX B 4 byte return va
164. tension c If you give no extension in the name the compiler assumes c INCLUDE FILE Additional source files may be invoked from the main source file through the include directive The name of the include file may be given in one of two ways Standard search sequence To use the standard search sequence enclose the filename in angled brackets lt file gt For example Hinclude lt incfile h gt The standard search sequence is as follows The include filename with successive prefixes set with the I option if any The include filename with successive prefixes set in the environment variable named C_INCLUDE if present Multiple prefixes may be specified by separating them with semicolon for example set C_INCLUDE usr proj headers 1 18 USING THE C COMPILER The include filename by itself Note that the compiler simply adds each prefix from I or C_INCLUDE to the front of the include filename without interpretation Hence it is necessary to include any final backslash in the prefix Source file path To search for the file prefixed by the source file path first enclose the filename in double quotes file For example include incfile h For example with a source file named project prog c the compiler would first look for the file project incfile h If this file is not found the compiler continues with the standard search sequence as if angle brackets had been used ASSEMBLY
165. ter to standard printf sprintf format specification string A function pointer to a routine that actually writes a single character created by _formatted_write The first parameter to this function contains the actual character value and the second a pointer whose value is always equivalent to the third parameter of _formatted_write A pointer to some type of data structure that the low level output function may need If there is no need for anything more than just the character value this parameter must still be specified with void 0 as well as declared in the output function A pointer of type va_list to the variable argument list The number of characters written 2 145 _medium_write DESCRIPTION A reduced version of _formatted_write which is half the size but does not support floating point numbers For further information see __formatted_write 2 146 _small write _small write icclbutl h Small formatted data write routine DECLARATION int _small_write const char format void outputf char void void sp va_list ap PARAMETERS format outputf Sp ap RETURN VALUE A pointer to standard printf sprintf format specification string A function pointer to a routine that actually writes a single character created by _formatted_write The first parameter to this function contains the actual character value and the second a pointer whose value is always equivalent to t
166. the integer of lesser magnitude that is the nearest to the algebraic quotient The results are defined such that quot denom rem numer 2 84 log log math h Natural logarithm DECLARATION double log double arg PARAMETERS arg A double value RETURN VALUE The double natural logarithm of arg DESCRIPTION Computes the natural logarithm of a number 2 85 log10 log10 math h Base 10 logarithm DECLARATION double logl0 double arg PARAMETERS arg A double number RETURN VALUE The double base 10 logarithm of arg DESCRIPTION Computes the base 10 logarithm of a number 2 86 longjmp longjmp setjmp h Long jump DECLARATION void longjmp jmp_buf env int val PARAMETERS env A struct of type jmp_buf holding the environment set by set jmp val The int value to be returned by the corresponding setjmp RETURN VALUE None DESCRIPTION Restores the environment previously saved by set jmp This causes program execution to continue as a return from the corresponding set jmp returning the value val 2 87 malloc malloc stdlib h Allocates memory DECLARATION void malloc size_t size PARAMETERS size A size_t object specifying the size of the object RETURN VALUE Result Value Successful A pointer to the start lowest byte address of the memory block Unsuccessful Zero if there is no memory block of the required size or greate
167. tion or is mixed with Suggestion Probable cause An interrupt function calls a function that is also executed by a background program May lead to execution errors This warning indiates that a segment holding BIT SADDR or SHORTAD elements is too large due to too many C variable declarations or is placed at wrong address in the linker command file Inconsistent use of memory models This error indicates that a faulty linker command file is used This error should not occur if a properly modified linker command is used 1 122 GENERAL COMMAND LINE OPTIONS SUMMARY The ICC Compiler has an extensive set of command line options that control its operation Those options common to all targets are documented in this chapter In addition there may be options specific to this particular target in which case these are documented in the chapter Target specific command line options Each option consist of a hyphen followed by an option identifier Some options are followed by an optional or obligatory argument If the argument is a file leafname it must be separated from the option identifier by one or more space or tab characters for example o objfile All other types of arguments including file prefixes must immediately follow the identifier for example Opathname The position of an option in the command line has no significance in itself However in the case of the options D and I the or
168. tions There was an invalid identifier This could be an identifier in a type name definition like sizeof int ident or two consecutive identifiers redeclared There was a redeclaration of a declarator identifier There was an undecodable declarator There was a parenthesis error in a declarator 2 160 DIAGNOSTICS No Error message 34 C statement or func def in d Finclude file add i to the r switch 35 Invalid declaration of struct union or enum type 36 Tag identifier name redeclared 37 Function name declared within struct or union 38 Invalid width of field max is nn 39 or expected 40 Array dimension outside of unsigned int bounds 41 Member name of struct or union redeclared 42 Empty struct or union Suggestion To get proper C source line stepping for include code when the C SPY debugger is used the ri option must be specified Other source code debuggers that do not use the UBROF output format may not work with code in include files A struct union or enum was followed by an invalid token s A struct union or enum tag is already defined in the current scope A function was declared as a member of struct or union The declared width of field exceeds the size of an integer nn is 16 or 32 depending on the target processor There was a missing or at the end of declarator Array dimension negative or larger
169. ues RETURN VALUE Result Value Successful The number of successful conversions Unsuccessful 1 if the input was exhausted DESCRIPTION Reads formatted data from standard input Since a complete formatter demands a lot of space there are several different formatters to choose For more information see the chapter Configuration in the target specific section format is a string consisting of a sequence of ordinary characters and conversion specifications Each ordinary character reads a matching character from the input Each conversion specification accepts input meeting the specification converts it and assigns it to the object pointed to by the next successive argument following format If the format string contains white space characters input is scanned until a non white space character is found 2 105 scanf The form of a conversion specification is as follows Lassign_suppress field_width length_modifier conversion Items inside are optional Assign suppress If a is included in this position the field is scanned but no assignment is carried out field_width The field_width is the maximum field to be scanned The default is until no match occurs length_modifier The effect of each 1ength_modi fier is as follows Length modifier Before Meaning d i orn long int as opposed to int O U OF X unsigned long int as opposed to unsigned int e E g G or f double operand as opposed
170. ult of comparing the two strings Return value Meaning gt 0 sl lt s2 0 sl s2 lt 0 sl lt s2 DESCRIPTION Compares the two strings This function operates identically to strcmp and is provided for compatibility only 2 119 strcpy strcpy string h Copies string DECLARATION char strcpy char s1 const char s2 PARAMETERS s1 A pointer to the destination object s2 A pointer to the source string RETURN VALUE sl DESCRIPTION Copies a string into an object 2 120 strcspn strcspn string h Spans excluded characters in string DECLARATION size_t strcspn const char sl const char s2 PARAMETERS sl A pointer to the subject string s2 A pointer to the object string RETURN VALUE The int length of the maximum initial segment of the string pointed to by s1 that consists entirely of characters not from the string pointed to by s2 DESCRIPTION Finds the maximum initial segment of a subject string that consists entirely of characters not from an object string 2 121 strlen strlen string h String length DECLARATION size_t strlen const char s PARAMETERS S A pointer to a string RETURN VALUE An object of type size_t indicating the length of the string DESCRIPTION Finds the number of characters in a string not including the terminating null character 2 122 strncat strncat string h Concatenates a specified number of char
171. un time library calls CAUTION Depending on the debugging environment the user may encounter some debugging restrictions when useing banked functions For detailed information pleas refer to the corresponding hardware development tool documentation 1 115 V For more information see Memory model page 1 44 Note that all modules of a program must use the same memory model and must be linked with a library file for that model V Selects the processor type SYNTAX v 0 8 DESCRIPTION Use the v option to select the processor type as follows Option Processor type 0 7800X default 1 7801X 2 78P014 3 7804X 4 78P044 5 7805X 6 7806X 7 7802X 8 78P024 1 116 W Set register area size SYNTAX WErs DESCRIPTION The Compiler set register area size option W rs enables the compiler register variable work area in short direct address memory segment WRKSEG The compiler puts auto variables in that area as much as it can The default maximum register area size if rs not given is 20 bytes while the maximum rs value possible to give is 128 bytes Even though only the actually used number of bytes will be allocated for each function it is possible that this may increase the code size instead of reduce it if the function is small since there is some overhead in managing the short address work area d Force static allocation of auto variables SYNTAX d DESCRIPTION
172. unction header filename and a brief description of the function DECLARATION The C library declaration PARAMETERS Details of each parameter in the declaration RETURN VALUE The value if any returned by the function DESCRIPTION A detailed description covering the function s most general use This includes information about what the function is useful for and a discussion of any special conditions and common pitfalls 2 46 abort abort stdlib h Terminates the program abnormally DECLARATION void abort void PARAMETERS None RETURN VALUE None DESCRIPTION Terminates the program abnormally and does not return to the caller This function calls the exit function and by default the entry for this resides in CSTARTUP 2 47 abs abs stdlib h Absolute value DECLARATION int abs int j PARAMETERS j An int value RETURN VALUE An int having the absolute value of j DESCRIPTION Computes the absolute value of j 2 48 acos acos math h Arc cosine DECLARATION double acos double arg PARAMETERS arg A double in the range 1 1 RETURN VALUE The double arc cosine of arg in the range 0 pi DESCRIPTION Computes the principal value in radians of the arc cosine of arg 2 49 asin asin math h Arc sine DECLARATION double asin double arg PARAMETERS arg A double in the range 1 1 RETURN VALUE Th
173. will use the intrinsic function _OPC later in the program The second additions is interrupt LINTBRK_vect void ad_exception void call_count 0 1 34 TUTORIAL This function is an exception handler which is called whenever an software break instruction is executed The interrupt keyword is described in Extended keyword reference page 1 65 The final addition is if bufferL buffindex 1 OxFF _OPC OXxBF Generate BRK interrupt This line inserts a 78000 assembler instruction using the intrinsic function _OPC The parameter 0xBF is the op code for a 78000 BRK instruction which generates a software break The advantage of intrinsic functions is that the compiler itself translates this function call to the corresponding machine instruction without any overhead of CALL or RET instructions The intrinsic functions require the in78000 h file to be included COMPILING AND LINKING THE PROGRAM Compile and link the program as before icc78000 prog v2 ms xlink prog f 1nk780 r If you are going to debug the program you have to add the debugger specific command line options Debugging using C SPY icc78000 prog v2 ms r xlink prog f 1nk780 r 4 Debugging using SD78K 0 icc78000 prog v2 ms rr ey xlink prog f 1nk780 r Y ubr2xcof aout d26 4 1 35 TUTORIAL RUNNING THE PROGRAM To run the program using C SPY or SD78K 0 please follow the instruction
174. x Fatal The nesting in a function is 50 Array of functions definition was too deep An attempt was made to declare an array of functions The valid form is array of pointers to functions int array 5 int array 5 J 0 Missing array dimension specifier Identifier name redefined Function returning array Invalid Valid There was a multi dimensional array declarator with a missing specified dimension Only the first dimension can be excluded in declarations of extern arrays and function formal parameters There was a redefinition of a declarator identifier Functions cannot return arrays Function definition expectedA K amp R function header was found Missing identifier in declaration Simple variable or array of a void type Function returning function without a following function definition for example int f i Invalid A declarator lacked an identifier Only pointers functions and formal parameters can be of void type A function cannot return a function as in int f Invalid 2 163 DIAGNOSTICS Suggestion The defined object has unknown size This could be an external array with no dimension given or an object of an only partially forward declared struct or union Fatal The compiler aborts after a certain number of diagnostic messages Multiple definitions of a function were encountered There was
175. y declarator or static initializer was not constant The second and third argument of the operator are different Pointers may not be added The current declaration is inconsistent with earlier declarations of the same object The only allowed reference to undefined struct or union declarators is a pointer 2 173 DIAGNOSTICS No Error message 138 139 140 141 142 143 pointer expression Too many extern symbols declared max is 32767 void pointer not allowed in this context error any message interrupt function can only be void and have no arguments Too large negative or overlapping interrupt value in name Suggestion The operator may be used on pointers only if both operators are pointers thatis pointer pointer This error means that an expression of the form non pointer pointer was found Fatal The compiler limit was exceeded A pointer expression such as an indexing expression involved a void pointer element size unknown Fatal The pre processor directive terror was found notifying that something must be defined on the command line in order to compile this module An interrupt function declaration had a non void result and or arguments neither of which are allowed Check the vector values of the declared interrupt functions 2 174 DIAGNOSTICS No Error message 144 145 146 147 148
176. ype Example K amp R extern int f ANSI named form extern int long int val ANSI unnamed form extern int long int In the K amp R case a call to the function via the declaration cannot have its parameter types checked and if there is a parameter type mismatch the call will fail In the ANSI C case the types of function arguments are checked against those of the parameters in the declaration If necessary a parameter of a function call is cast to the type of the parameter in the declaration in the same way as an argument to an assignment operator might be Parameter names are optional in the declaration ANSI also specifies that to denote a variable number of arguments an ellipsis three dots is included as a final formal parameter If external or forward references to ANSI type functions are used a function declaration should appear before the call It is unsafe to mix ANSI and K amp R type declarations since they are not compatible for promoted parameters char or float Note that in the IAR C Compiler the g option will find all compatibility problems among function calls and declarations including between modules HEXADECIMAL STRING CONSTANTS ANSI allows hexadecimal constants denoted by backslash followed by x and any number of hexadecimal digits For example tdefine Escape_C xlb x43 Escape C 0 x43 represents ASCII C which if included directly would be interpreted as part of the hexadecimal
177. ze 0xC0 char bufferLbuffsizel int buffindex 0 int call_count 0 RR KR KK KK KK KK KK KK KKK KKK KKK KK KK KKK KKK x Start of code X KKK KKK KKK KKK KKK KKK KK KK KKK KKK KKK KKK Return 0 if no conversion result available lt gt 0 if data now in ADCR register Ff 1 32 TUTORIAL int ad_ready void return AD_Ready Data reader poll status register until ready return data xJ unsigned char read_data void while ad_ready wait for data return ADCR return A D converted data void do_foreground_process void just increment a variable call_count Example interrupt handler Take control of A D conversion completion interrupt LINTBRK_vect void ad_exception void call_count 0 1 33 TUTORIAL void main void Initialize A D converter ADIS ADISO ADM EnableAD 1 now loop forever taking input when ready while 1 if ad_ready bufferLbuffindex read_data if buffindex buffsize process full buffer buf findex 0 simple processing discard data if bufferl buffindex 1 OxFF _OPC OxBF Generate BRK interrupt do_foreground_process The first addition is Finclude lt in78000 h gt include for intrinsic functions This include file is necessary to enable intrinsic functions Our example
178. zero before they are encountered by the program so they are set to zero by CSTARTUP during initialization These will have been allocated by the compiler declared shortad or created shortad by use of the memory pragma or created manually from assembly language source UDATAO can also hold user written data elements that should initially be set to zero 1 110 UDATAI1 UDATAI Uninitialized statics TYPE Read write DESCRIPTION Assembler accessible Holds static variables which were declared without initial values ANSI C specifies that such variables be set to zero before they are encountered by the program so they are set to zero by CSTARTUP during initialization UDATA1 can also hold user written data elements that should initially be set to zero WCSTR Writeable string literals TYPE Read write DESCRIPTION Holds writable copies of the C string literals when the y compiler option is active 1 111 WRKSEG WRKSEG Local register variables TYPE Read write DESCRIPTION Compiler only Holds the register optimisation memory area when W compiler option is selected ZVECT Initialization DESCRIPTION Used for initialization in CSTARTUP 1 112 78000 SPECIFIC COMMAND LINE OPTIONS SUMMARY The ICC Compiler has an extensive set of target specific command line options that control its operation Each option consist of a hyphen followed by an optio

Download Pdf Manuals

image

Related Search

Related Contents

PV Grid-Connected Inverter Shenzhen    Print Preview - C:\Users\thri\AppData\Local\PTC  MPT-II User Manual  EXPLICATION DES SYMBOLES RÉGLES DE SÉCURITÉ  Kanex GoBuddy+  User Manual ARK-3510  Panasonic MC-V7710 Vacuum Cleaner User Manual  Atlas Sound AM1100 User's Manual  Betriebsanleitung_WMS_2010  

Copyright © All rights reserved.
Failed to retrieve file