Home

C/C++ Compiler Package for M32R Family V.5.00 C++ Compiler

image

Contents

1. C source C source c cpp a Compile Driver cc32R C front end C pre processor Intermidiate C Template Template source instance C information a source file ti Pre processor aen Generating To File C Compiler and Library Assembler File lib Object File mo ml Pre Linker instantiation request file ii C Librarian 4 Librarian lib32R lib32R Absolute File abs Library File Lib Figure 1 1 Programming Flow by CC32R CC32R MANUAL 4 Chapter 1 Overview of CC32R 1 4 2 Object Generation Flow Figure 1 2 shows an object file generation flow and the files generated C C source c cpp SYSROF Format mo C Information Object Module files steal dw2 dws et Figure 1 2 Flow of Object Generating CC32R MANUAL 5 Chapter 1 Overview of CC32R 1 4 3 How to Link Figure1 3 shows how to link the object and library files to generate a load module file Even when linking only object files make sure the linker is started through the compile driver cc32R This is because if the user invokes the linker directly the prelinker will not be started and therefore objects will not be generated that can be linked correctly Do not write a program statement
2. CC32R generates labels for the start address of the section and the last address of the section 1 __TOP_CTOR Start address of the section __END_CTOR Last address of the section 1 7 1 3 Writing the VTBL Section The C frontend generates a virtual function table for classes that have virtual functions and locates it in the VIBL section Therefore the VIBL section in which the virtual function table will be stored needs to be written in a startup program section VTBL data align 4 jThe virtual function table will be stored here CC32R MANUAL 124 Chapter 7 Embedded Applications Programming 7 1 4 Regarding the COMMON Section When the internal static variable of an inline function or the runtime type information facility is used data is output to the COMMON section Since the linker Ink32R always generate a COMMON section be sure to specify a COMMON section with the SEC option when compiling the sources e The COMMON section is located in the RAM e If any section with the same name is set an error is assumed when linking e The COMMON section should not be confused with the COMMON attribute CC32R MANUAL 125 Chapter 7 Embedded Applications Programming ee Embedded Application Programming Procedure When programming an embedded application the start up program and lower level libraries must be developed as well as the user program which performs the desired functions To link
3. CC32R MANUAL 332 Chapter 10 The cc32R s Behavior e ANSI C 7 9 3 Files lt Whether the file position indicator of an append mode stream is initially positioned at the beginning or end of the file gt The file position indicator is initially located at the end of file lt Whether a write on a text stream causes the associated file to be truncated beyond that point gt Truncating the associated file is not caused lt The characteristics of file buffering gt Three methods are available for buffering full buffering line buffering and no buffering You can set change them by use of the setbuf function or the setvbuf function lt Whether a zero length file actually exists gt It is depends on user defined low level functions lt The rules for composing valid file names gt They depend on user defined low level functions lt Whether the same file can be open multiple times gt It is depends on the user defined open function a low level function e ANSI C 7 9 4 1 The remove function lt The effect of the remove function on an open file gt It is depends on the user defined remove function a low level function e ANSI C 7 9 4 2 The rename function lt The effect if a file with the new name exists prior to a call to the rename function gt It is depends on the user defined rename function a low level function CC32R MANUAL 333 Chapter 10 The cc32R s Behavior e ANSI C 7 9
4. Figure 3 5 Setup examples of R12 and__ REL_BASE start ms CC32R MANUAL 34 Chapter 3 Invoking the Compiler 3 2 3 Debugging Limitations when Optimize Options Are Specified The compiler is always specified the function for debugging Therefore the compiler allows for source level debugging during optimization However unnecessary lines or variables may be deleted or the sequence of evaluation may be changed as a result of optimization Therefore it is only when the conditions shown below are met that the values of variables can be verified by the debugger This limitation does not apply when optimization is not specified e Ata breakpoint at the entry of a function any variable from 1 to 4 shown below can be checked Breakpoint at the entry of a function is the first statement in which it is possible to set a breakpoint within the function 1 A global variable 2 A static declared global variable used inside that function 3 A static declared local variable used inside that function 4 A function parameter e Ata breakpoint at the exit of a function any variable from 1 to 3 shown below can be checked Breakpoint at the exit of a function is the last statement in which it is possible to set a breakpoint within the function 1 A global variable 2 Astatic declared global variable 3 A static declared local variable used inside that function e At the other breakpoints any variable from 1
5. Figure A 5 Examples of pragma ADDRESS Coding Not Checked by Compiler Appendix A 21 Appendix A Extended Functions Reference pragma ADDRESS Examples pragma ADDRESS is written directly into the C C source code as follows Pa Example coding pragma ADDRESS varl 0x10000 pragma ADDRESS var2 0x20000 char varl static char var2 void func void varl var2 Output from example coding assembler code _varl EQU 0x10000 SECTION P CODE ALIGN 4 EXPORT Sfunc Sfunc LD24 R1 0x20000 LD24 RO 0x10000 LDB R1 R1 STB R1 RO JMP R14 EXPORT _varl END Figure A 6 Example Use of pragma ADDRESS declaration In this example code vari is mapped to address 0x10000 and var2 is mapped to address 0x20000 By so doing code is generated such that 1 byte is read from address 0x20000 and written to address 0x10000 by the expression var1 var2 in func Also because var1 is an externally defined variable EQU defines the corresponding symbol vari and EXPORT makes it possible for other objects to reference it Appendix A 22 Appendix A Extended Functions Reference pragma SECTION Function Syntax Description Declares that a variable is mapped to the specified absolute address pragma SECTION default section nameAmodified section name pragma SECTION changes the default section name created by the compiler to a user defined
6. Ink32R linker and lib32R librarian process files as command files even when the filename does not start with Note however that lines starting with in such command files are not processed as comments II NOTE Do NOT use filenames starting with other than for command files as com mand lines will not be processed correctly operation cannot be assured CC32R MANUAL 17 Chapter 3 Invoking the Compiler 3 1 5 Input File Conditions Conditions of the input files which can be processed on the compiler are listed in Table 3 3 If a file does not meet these conditions you should not input the file Table 3 3 Input File Conditions Where Conditions Valid input files C source file s or M32R assembly source file s Object module file s Load module file s Library s Valid name length Identifiers function name variable name and etc Up to 240 characters Note The different names as if the initial parts which consists of characters from the 1st to the 240th are matched and the other characters from the 241st are unmatched are recognized as the same identifiers Maximum number of names Section names Up to 65535 file Symbol names Up to 65535 file Module names Up to 65535 file Note The number may be limited by the capacity of the development environment system memory 3 1 6 Input File Names The C C compiler identifies the type of input file by i
7. Maximum value of LONG64 LONG64_MIN Minimum value of LONG64 ULONG64_MAX Maximum value of ULONG64 3 Prototype declaration Prototype for a 64 bit integer arithmetic function is declared A Function structure Comprised mainly of the C language operators that are put into functions 1 Arithmetic operation functions Performs a 64 bit integer arithmetic operation with the result returned by 64 bit integer type Four rules of arithmetic addition subtraction multiplication and division remainder and monadic negative CC32R MANUAL 359 Chapter 13 A set of 64 bit integer arithmetic functions 2 Bitwise operation functions Performs a 64 bit integer bitwise operation with the result returned by 64 bit integer type Bitwise shifts left shift right logical shift right arithmetic shift Bitwise logical operations OR AND exclusive OR and inversion 3 Comparison and determination functions Compares a 64 bit integer or determines if it is 0 with the result returned by int type Comparison Determination of whether or not 0 4 Type conversion functions Converts type from 64 bit integer to C language integer or floating point type or vice versa Signed 64 bit integer lt gt unsigned 64 bit integer Signed 64 bit integer lt gt float or double Unsigned 64 bit integer lt gt float or double Signed 64 bit integer lt gt long or unsigned long Unsigned 64 bi
8. Output data is rounded CC32R MANUAL 204 Chapter 9 C Standard Library Conversion Specifiers for fprintf 2 3 Conversion Conversion Method Type of the Notes on Precision Specifier Argument e Converts double type data intoa double The precision shows the character sequence of decimal number of digit of notation in the format d ddde fractional part ddd The exponent is output at For a converted character least two digits one figure is output before a decimal point and the number of digits equal to E Converts double type data into a double the precision is output after character sequence of decimal the decimal point notation in the format d dddE If the precision is omitted 6 ddd The exponent is output at is assumed If the precision least two digits is 0 a decimal point and decimal place are not output Output data is rounded g or G Outputs the value double type double The precision shows the stored int the argument in either maximum number of the f conversion format or in the e effective digits of converted or E conversion format data depending on a value stored in the argument and the precision which specifies the number of effective digits If the exponent of converted data is smaller than 4 or more than the precision this function converts to the e or E conversion format After the conversion a 0 at the end of the decimal places is removed If there is no c
9. e Optimization at assembly language Eliminates unnecessary codes at assembly language level converts to most suitable codes and schedules instructions e Local optimization Analyzes C C language structure locally transfers or copies constants and deletes unnecessary codes and common sub expressions e Global optimization Analyzes C C language structure globally analyzes live variables replaces codes and optimizes control flow The following lists the optimization items performed e Optimize control flow e Delete expressions in common parts e Propagate constants and copy e Analyze valid variables e Delete dead code e Optimize register assignment The combination of different optimization levels further improves efficiency of code generation although each optimization can be used independently Most optimizations combined at different levels increase program execution speed and reduce code size However some optimizations offer only one advantage or offer better functional performance at the sacrifice of some other advantage When using these optimization functions the user should specify which optimization advantage should come first CC32R MANUAL 10 Chapter 2 Overview of cc32R e Selectable output file The result of compiling can be output in the form of an assembly language source file an object module file or a load module file linked object module The assembly language source file is useful
10. inline A type specifier A function A means one or more white space characters Example 1 Function declaration inline int func1 void Example 2 Function definition inline static int func2 int a a 2 return a Compile Option 1 O lt level gt lt level gt 0 to 7 Where the optimization exceeding Level 4 is effective the inline expansion is made effective In the event of Levels 0 to 3 without optimization no inline expansion is valid NOTE When Ospace and Otime are designated O7 becomes effective in the default even if O lt level gt is not specified therefore the inline expansion becomes valid 2 noinline The inline keyword is made invalid The inline keyword if specified is ignored even when it is described This is not a error Explanation 1 The inline keyword designates the specified function as the inline function a function of applicatable to inline expansion Also designate the inline keyword when the function is defined Even when it is specified for function declaration it does not recognize this function as inline function in the absence of inline keyword when the function is defined 2 The inline keyword even if specified is ignored where noinline option is designated at the time of compiling This is not a error Appendix A 29 Appendix A Extended Functions Reference 3 Since inline expansion
11. 3 Object registration line Code format Format 1 Object name Format 2 Object name source file name function name Format 3 Format 4 SectionName Functions One or more object registration lines can be included following the base register definition line The object registration lines specify the names of the objects for 16 bit register relative indirect addressing using the base register specified in the preceding line a Format 1 e Global variables and static variables within the file b Format 2 e Variables within the specified function in the specified file c Format 3 e All static objects not written in other object definition lines in the Access Control File wildcard specification e Format 3 can only be used once in the Access Control File d Format 4 Applies to all static objects belonging to the specified section that Appendix A 8 Appendix A Extended Functions Reference are not written in other object definition lines except Format 3 of the access control file i e section specified wildcard specification The specified section name is either 1 altered section name by pragma SECTION or 2 designated section name The base register is applied to the static objects that are allocated to these sections Even if the designated section specifies a P or C section name the specification is ignored Specification of format 4 for th
12. Chapter 7 Embedded Applications Programming IMPORT _100_builtin_memcopy SECTION P CODE ALIGN 4 EXPORT sumXY SsumXY LDI RO 0 mvtachi r0 mvtaclo r0 BRA L5 L4 LDH RO R4 LDH R1 R5 macwlo r0 rl L2 ADDI R4 2 ADDI R5 L5 MV R1 R6 ADD3 R6 R1 1 BGTZ R1 L4 LS MV RO R7 mvfachi r3 st r3 r0 mvfaclo r3 st r3 r0 Lie JMP R14 END Figure 7 8 Example of Compiled asm Functions CC32R MANUAL 146 Chapter 8 Standard Header Files Chapter 8 Standard Header Files ESI Overview of the Header Files A standard header file is a file in which prototype declaration macro definition and data type declaration necessary to for use of the C standard libraries are written Available standard header files include 15 types Table 8 1 When using a C standard library function the header file containing definition and declaration required to execute the library function must be included for each process Table 8 1 shows the standard header files and associated library functions type name CC32R MANUAL 147 Chapter 8 Standard Header Files Table 8 1 Standard Header Files Header File Description Associated Library Function assert h Macro definition that outputs program diagnostic Program diagnostic information function ctype h Macro definition of the character handling function Character handling and character check
13. L amp amp wbuff i L BH kanjiout wbuff i Appendix A 40 Appendix A Extended Functions Reference The wide character string is a wchar_t type array Taking out each a character removing one of the particular characters those are or No in this program of it and outputting it to the function 7 Taking out each a character from another string and outputting it for i 0 i lt sizeof wstr i kanjiout wstr i It is similar to above 6 taking out each a character ouputting it to the function This is a simple case that letter check is nonexistent A 6 4 Restriction items A 6 4 1 Message display When the compiler output the Japanese Kanji string in the compile message it may be octal number instead of original character Example A warning message to M32RKOUT a case of sjis warning 0212 0277 unportable character constant 0212 0277 is 2 octal notation of Kan 0x8a and Oxbf in sjis The display result is different each in host environments A 6 4 2 Attention on multi byte character string processing Because the boundary between the characters is unstable if you need process a mult byte character string as conventional char type argument please carry out several operations show below only in that this boundary is known clearly Otherwise a character will be broken or searching will finish incorrectly A character string is divided in a
14. Preface Meaning A text file written source code in the C C language or the assembly language Object module file An object file which is translated from the C C or assembly code into the object code of machine instructions for M32R It is an output file from the C compiler or the assembler Load module file A linked object module which is an executable file for an M32R system It is an output file from Ink32R or Imc32R Link map A list have information on sections and global symbols in an object module or a load module It is generated by map32R Library file A C library file for an M32R system It is an output file from lib32R C standard library The CC32R supplied ANSI C conforming library User library A library file made by a user using the librarian Return value A function value returned as an operation result from a called function to a calling function Local variable This variable is only effective in a function Rx Any general register of M32R CRx Any control register of M32R EWS An engineering work station OS An operating system Default A value or values or the process provided automatically if there is none specified by the user Space character A blank which is entered by the space key or the tab key CC32R MANUAL xii Chapter 1 Overview of CC32R Chapter 1 Overview of CC32R ERE Feature
15. The name of the compiled assembly language source file The file name is the name of the C language file with the extension replaced with ms file mo file ml The name of the assembled object module file The filename is derived from the source filename by changing its extension to mo To compile the C language with the mklib option specified select file ml Otherwise file mo am out The linked load module file file elf A load module file in ELF DWARF format generated simultaneously with the load module file To debug the sources written in C language download the load modules that bear this name CC32R MANUAL 19 Chapter 3 Invoking the Compiler 3 1 8 Output During Execution When two or more input files are specified the compiler outputs the following status information during execution e Upon start of compiling The name of file being compiled is output when the input file is a source file e Upon start of linking The message Linking is displayed The C C compiler will end by doing nothing if no input file name is specified No starting or ending messages will appear 3 1 9 Procedure for Up to Linking Programs The following describes a standard procedure for up to linking C programs by using command line specification as an example denotes the prompt 1 Compiling the C source files Example cc32R c Otime filel cpp cc32R c Ot
16. non 0 c is hexadecimal digit 0 cis anything other than hexadecimal digit Returns any value other than 0 if c is a hexadecimal digit and returns 0 if c is not a hexadecimal digit e Hexadecimal digits 0123456789ABCDEFabcdef If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 236 Chapter 9 C Standard Library l a b S General utility function Obtains the absolute value of a long type integer Syntax include lt stdlib h gt long labs long 7 Ti integer calculating an absolute value Return Value Absolute value of calculation result Description The labs function calculates an absolute value of a long type integer If the calculation result cannot be expressed as a long type the operation is not guaranteed l d ex p Mathematics function Performs multiplication of a floating point number and 2 to the nth power Syntax include lt math h gt double Idexp double x int f X floating point number Lt index integer Return Value Result of x2 Description The Idexp function calculates a value of x 2 and return the result If the calculation result overflows this function sets a value of ERANGE in errno and returns HUGE_VAL HUGE_VAL if negative as a return value CC32R MANUAL 237 Chapter 9 C Standard Library 7 General utility fun
17. referenced label not declared in current function scope A label to be referenced cannot be found in a function register must appear within a function A declaration of a register variable is present outside a function return type incompatible with function s defined return type The return value of a function is different from the one declared return with expression in function with void return type An attempt has been made to return a value from a function brought under a void declaration same argument name used in macro xxx An identical argument is used in a macro second or third operand of conditional operator has invalid type An improper type has been defined in a ternary operation size of return type from function must be known The return size of a function is unknown sizeof object is of unknown length An object whose length is indefinite has been specified in the sizeof operator xxx storage class incompatible with subsequent file scope declaration The storage class declaration is inconsistent with the next file scope declaration xxx storage class is nonvalid for formal argument The storage class declaration is incorrect CC32R MANUAL 384 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 13 15 Message Description struct or union must not contain member of function type You cannot include an entity of function type either in a structure or
18. the operation is not guaranteed If the number of arguments is larger than the number of conversion specifications all of the excessive arguments are ignored lt Details of Conversion Specifiers gt The function of each conversion specifier and how to specify are e Flag A flag specifies processing for the data to be output such as marking with a symbol Types and meaning of the available flags are described as follows CC32R MANUAL 200 Chapter 9 C Standard Library Flag Meaning ust Left justified If the number of characters of converted data is smaller than the specified field width this function outputs the data as left justification in the filed If this flag is not specified this function will output the data as right justification 4 With a sign Upon converting into data followed by a sign this function adds the sign or to the beginning of the converted data space Without a sign Upon converting into data followed by a sign a space is added to the beginning of converted data if no sign is added to the beginning of the data This flag is ignored if it is specified together with Processing This function processes the converted data according to the conversion specifier as follows Conversion Processing Specifier ed pies oa This flag is ignored o 0 is added to the beginning of converted data if the data is not 0 x X Ox or OX if X c
19. x field_width size_specifier conversion_specifier Example 2d f Two conversion specifications The the field width 2 and the conversion specifier d The and the conversion specifier f Every item shall be described continuously not separated by a space If there is no corresponding argument for a conversion specification such as there is no variable argument list there are insufficient arguments the operation is not guaranteed If the number of arguments is larger than the number of conversion specifications all of the excessive arguments are ignored lt Details of Conversion Specifiers gt The function of each conversion specifier and how to specify are e asterisk Prefixing prior to a conversion specifier allows reading the corresponding token from the input but suppresses assignment e Field width A field width specifies the number of characters in decimal number CC32R MANUAL 214 Chapter 9 C Standard Library format which can be input Size specifier for the corresponding argument With the size specifiers h 1 or L at the preceding a conversion specifier type of the corresponding argument can be specified when the conversion specifier is d i o u x X e E f g Gorn Size Following conversion Type of the corresponding specifier specifier argument is h d i o u x orX short int or unsigned short int n pointer to short int 1 ell d i o u x orX long int or
20. 6 1 1 General Register RO R15 Usage The M32R is provided with 16 32 bit general registers RO R15 see Figure 6 1 The C C compiler uses R14 as the link register R15 as the stack pointer SP and RO R13 as working register to temporarily store intermediate results of function operation and the variables Registers R11 R13 can also be used as the base register when declared to do so in the program in this case R11 to R13 as specified in the base register always store the base addressR11 to R13 as specified in the base register always store the base address CC32R MANUAL 99 Chapter 6 C C Calling Conventions General Registers Work Registers RO The return value of a function is stored ARegisters here for C language Function Arguments R11 to R13 as specified in the base register always store the base address The Base Register Link raso Stack Pointer Figure 6 1 General Registers Used The applications and associated operations of the general registers used by the C C compiler are described below e Work registers RO R13 Store intermediate results of function operation and variables The RO stores the values returned by function e Registers for function arguement R4 R7 The registers R4 R7 are used to store function argument C language e Registers for the Base Registerf R11 R13 The registers R11 R13 are used to the Base Register See Appen
21. A 5 3 2 Not normalized a At compiling Where the m32re5 option is effective a warning is issued when the floating point constant is not normalized then it is reduced to 0 0 b During execution Where the floating point constant is not normalized during FPU instruction operation there may arise non packaging exceptions For FPU instruction non normalized constant handling refer to the M32R ECU 5 software manual A 5 3 3 Round off mode The CC32R is designed on the premise that the round off mode is rounding to the nearest in float operation it is therefore necessary to allow the M32R ECU 5 rounding mode to match this mode as well A 5 3 4 fminst Option The FMADD instruction differs in round off handling from the FMUL and FADD combined for computing This is also the same with the FMSUB and FMUL amp FSUB combinations It should therefore be noted that there may arise a difference in results between the cases where the fminst option was designated and not designated For the FPU instruction rounding mode refer to the M32R ECU 5 Software Manual Appendix A 35 Appendix A Extended Functions Reference A6 About Japanese Kanji character processing A 6 1 A 6 1 1 A 6 1 1 The Japanese character can be described to the character constant of a program The Japanese character can be processed as the multi byte character and wide character JIS EUC JP Shift JIS Unicode UTF 8 are able t
22. Chapter 8 Standard Header Files 8 2 14 string h Performs the prototype declaration of the character string handle function and memory handle function Table 8 23 shows the functions declared by string h Table 8 23 Functions Declared by string h Function Description Reentrant memchr Locates in a memory area the position where O a character first appears memcmp Compares the contents of two memory areas O memcpy Copies the contents of a memory area to the destination O memory area memmove Moves the contents from a memory area to O the destination memory area memset Copies a character into the first n characters in memory O area strcat Links a string to the end of a string O strchr Locates in a string the position where a character first O appears strcmp Compares two strings O strcoll Compares the two strings based on the current locale O strcpy Copies the contents including null characters of the O source string to the target memory area strespn Computes the length of initial segment of a string which O consists of unspecified characters strerror Returns the error message O Depends on _strerror function strlen Measures the size of string O strncat Links the specified number of characters to the string O strnecmp Compares specified number of characters of two strings O strncpy Copies the specified number of characters from the O st
23. X floating point number Return Value Calculated value of argument Successful Description The cosh function calculates the hyperbolic cosine of x When the calculation result of the function cannot be expressed as a double type value this function sets a value of ERANGE in errno If the calculation result overflows this function returns HUGE_VAL as a return value ct i me Date and time function Converts the calendar time a time_t value into the equivalent text string Syntax include lt time h gt char ctime const time_t timer timer calendar time Return Value Pointer to a converted character string Description The ctime function converts the calendar time specified by timer into the following format Thu May 12 16 00 00 1995 n 0 CC32R MANUAL 188 Chapter 9 C Standard Library d ifft i me Date and time function Computes the difference between the two specified times Syntax include lt time h gt double difftime time_t timel time_t time timel time 1 time2 time 2 Return Value The value of time2 subtracted from time by the second Description The difftime function calculates the value of time2 subtracted from time1 d iv General utility function Divides an int type integer and obtains the quotient and remainder Syntax include lt stdlib h gt div_t div int number int denom number dividend denom divisor Return Value
24. _rel_core getenv getenv malloc get_core _rel_core realloc rel_core _get_core system system time h asctime write _get_core rel_core lseek clock clock ctime write _get_core getenv _rel_core lseek localtime getenv strftime write _get_core getenv _rel_core lseek time time IIll Note IIll Before starting C C program initial setting of the low level libraries is re quired To do so write the initial setting program in the startup program CC32R MANUAL 342 Chapter 11 Low level Library 11 1 2 Input Output with the Low level Library Files of standard input and output functions of C standard library level are controlled with file type data Files of low level library are controlled with file numbers A file number is an integer corresponding to the file number of the actual file and starts with 0 File numbers 0 1 and 2 should be assigned to a standard input standard output and standard error output respectively Typically 0 is input from console 1 and 2 are output to console For file numbers 0 to 2 prepare low level libraries which are compatible with execution environment for file number When 0 to 2 are already assigned make sure that the open function will not return values 0 1 and 2 Low level library s open function assigns the file number to the given file path name the name to identify the file in the file system The
25. signed U unsigned ULONG64 subul64 ULONG64 n1 ULONG64 n2 U subtraction nl n2 ULONG64 mulul64 ULONG64 nl ULONG64 n2 U multiplication nl n2 ULONG64 divul64 ULONG64 nl ULONG64 n2 U division nl n2 ULONG64 modul64 ULONG64 n1 ULONG64 n2 U remainder ni 3 n2 ULONG64 negul64 ULONG64 n1 U monadic negative n1 Table 13 1 64 bit integer arithmetic functions 2 Bitwise operation functions function name Prototype declaration of C language Perform S signed U unsigned Operation Bitwise shifts left shift right logical shift right arithmetic shift LONG64 shitl64 LONG64 nl unsigned int nbit S left shift nl lt lt nbit LONG64 shrtl64 LONG64 nl unsigned int nbit S right arithmetic shift nl gt gt nbit ULONG64 shltul64 ULONG64 n1 unsigned int nbit U left shift nl lt lt nbit ULONG64 shrtul 4 ULONG64 nl unsigned int nbit U right arithmetic shift nl gt gt nbit Bitwise logical operations OR AND exclusive OR and inversion LONG64 orl64 LONG64 nl LONG64 n2 S OR nl n2 LONG64 andl64 LONG64 nl LONG64 n2 S AND nl amp n2 LONG64 xorl64 LONG64 nl LONG64 n2 S exclusive OR nil n2 LONG64 notl64 LONG64 n1 S inversion nl ULONG64 orul64 ULONG64 ni ULONG64 n2 U OR nl n2 ULONG64 andul64 ULONG64 n1 ULONG64 n2 U AND nl amp n2Z ULONG64 xorul64 ULONG64 nl ULONG64 n2 U exclusive OR
26. xxx unable to optimize skipped phase Optimization of the input file xxx is impossible The optimization steps have been passed by xxx undefined name in if constant expression regarded as 0 An undefined name xxx is present in the constant expression given after if It is regarded as 0 CC32R MANUAL 370 Chapter 14 Messages from the C Compiler Table 14 4 Warning Messages 4 4 Message Description unknown commandline option ignored This command option is unsupported The option is ignored unknown directiv directive ignored This directive is unsupported The directive is ignored unknown size static global array used You cannot specify this size for a static global array xxx unknown suffix passed to linker The extension of the input file xxx cannot be determined neither c ms nor mo It is regarded as an object file and its name is left unchanged and passed to the linker unportable character constant The value of a character constant is troublesome in portability unrecognized pragma directive ignored This is not a pragma directive supported The directive is ignored x is hex escape sequenc A character that represents a hexadecimal number has not been specified after x x is the prefix of hexadecimal number code CC32R MANUAL 371 Chapter 14 Messages from the C Compiler 14 2 3 Command Line Error Messages Table 14 5 Command Line
27. 0 contents of s1 contents of s2 Negative value contents of s1 lt contents of s2 Description The strncmp function compares the contents of string specified by s1 with the contents of the string specified by s2 up to the nth characters specified by the parameter n and sets the result as the return value CC32R MANUAL 280 Chapter 9 C Standard Library strncpy String handling function Copies the specified number of characters from the string to memory Syntax Return Value Description include lt string h gt char strncpy char si const char s2 size_t 7 sl pointer to space to which copy is made S2 pointer to string to be copied n the number of characters to be copied Pointer to the memory area to which the characters are to be copied The strncpy function copies the specified number of characters within the string s2 to the specified memory area s1 If the size of the string specified by s2 is smaller than the number of characters specified by n null characters are added until the s2 specified character size matches the n specified character size If the number of s2 specified characters is larger than that of the n specified character size the last character of the string copied to s1 is other than a null character CC32R MANUAL 281 Chapter 9 C Standard Library strpbrk String handling function Locates the position where one of the specified chara
28. An identifier must begin with either a letter Table 4 1 or an underscore _ The other part can contain letters digits Table 4 1 and underscores The first 240 characters are significant for an identifier Table 4 1 Letters and Digits Called Character s Letters ABCDEFGHtIJdJKLMNOPQRS TU V W Y Z abcdefghigjgklmnopgqrstu Vwx yz Digits 0123456789 Alphanumerics Both letters and digits A region of program text in which identifiers can be used called scope is shown below Table 4 2 CC32R MANUAL 44 Chapter 4 C Programming Language Specification Table 4 2 Scopes of Identifiers Identifier e A variable declared outside a function e A function prototype declaration e A function definition Scope Each of the identifiers has file scope which begins at its declaration or definition and terminates at the end of the file A parameter in a function definition The identifier has block scope which begins at the and ends atthe A parameter in a function The identifier has function prototype scope prototype declaration It is visible only in the function prototype declaration in which it appears A label The identifier has function scope which begins at its declaration or definition and terminates at the end of the function A variable declared inside a block The identifier has block scope If the identifier is the same as
29. C language only delete delete pointer destroy de allocate C language only deletel delete pointer destroy array C language only type expr cast type conversion object pointer to member member selection C language only gt pointer gt pointer to member member selection C language only j expr expr binary multiply CC32R MANUAL 53 Chapter 4 C Programming Language Specification Table 4 0 Operators 3 4 Operator Usage and Note Description expr expr divide Yo expr expr modulo expr expr add expr expr subtract lt lt expr lt lt expr shift left gt gt expr gt gt expr shift light lt expr lt expr less than lt expr lt expr less than or equal gt expr gt expr greater than gt expr gt expr greater than or equal expr expr equal I expr expr not equal amp expr amp expr bitwise AND is expr expr bitwise XOR expr expr bitwise OR amp amp expr amp amp expr logical AND expr expr logical OR 2 expr expr expr ternary operator lvalue expr assignment operator lvalue expr binary multiply and assignment operator lvalue expr divide and assignment operator Ivalue expr modulo and assignment operator lvalue expr add and assignment operator lvalue expr subtract and assignment operator lt lt lva
30. Chapter 3 Invoking the Compiler 14 Si Howto Invoke the Compile yscectaiten fs cctevs yuatst ase vaee tad devedeeeasytenstcteeedecnsdadgeeeee Maviadesd 14 SA Invoking Procedure 2 sibicciwcascici cieces reanna E eaaa ai 14 3 1 2 Setting Environment Variables s icisssssiiseiitreisisrresisrssnatasioisidncssdesnidsspienain senais ias 14 3 1 3 Command Line Syntax and RUIeS 2000 eceecceeeeseeeeeeeeeeeeaeeeseeseaeeeeeeseaeeteaeeeaeenaaes 15 SkA Command TG sos cu cesacc deca e e cease theca a ee a Tipi 16 315 np t File Conditions rsrs ea Ean AN ea a iA 18 Ike Input FileName Seinens n a it aera 18 Slee OUPUt FIS NAMING eaga a e a aeaa 19 318 Q tp t During Execution isisisi a 20 3 1 9 Procedure for Up to Linking Programs cs cccessseeeseceeeseeeteseeeeeseneeeeseeeeeseeeees 20 CC32R MANUAL iii 3 2 3 3 3 4 Chapter 4 C C Programming Language Specification 4 1 4 2 4 3 4 4 4 5 4 6 Contents SAO Creating a CiDtary issan teed asidte eee A ee iis 21 Command OPUN Stessen eaae aa ana nea E ak 22 3 2 1 Command OPtonS sissien hese peach evteetece de sath aE N ESERE A E EN e 22 3 2 2 Notes about rel16 option to be taken when programming seesseeseessessesesreseeee 33 3 2 3 Debugging Limitations when Optimize Options Are Specified cece 35 32 4 SWitCh DY OSet OPHION disisit ea o aE S E eSa 36 Command Line Example sisis messiin horsia enih idaan a ehe ais hedad 38 TE ONO NI O ia N
31. L3 and Ld respectively e Where the ROM size becomes larger than in linear searching the linear search is used without employing the address table and offset table but explanation is given here on the premise that the branch table is always used Compile with conventional compatibility witout switch by offset C Source case 1 case 2 default case 4 offset CC32R MANUAL 36 Chapter 3 Invoking the Compiler Explanation The address table generated with conventional compatibility indicates the array with which the branch addresses are stored Each element of the array is 32 bits 4 bytes The switch statement is branched to the addresses shown by Table Expression 1 after checking to see if the expression value is 1 to 4 If switch_by_offset is provided at compiling the address table becomes the offset table The offset table also shows the array but each element becomes offset distance from L1 in place of the branch address and each element of the array is as small as 16 bits 2 bytes The compiler generates a code branched to the address with the origin L1 added to the offset value shown in Table Expression 1 for the switch statement CC32R MANUAL 37 Chapter 3 Invoking the Compiler EEJ Command Line Example An invocation example of the C C compiler is shown here is a prompt lt RET gt shows an inputting return key e amp cc32R c v test0O ms testl
32. LDBL_MAX Indicates the max positive value which can be expressed in a long double type floating point number FLT_MIN Indicates the min positive value which can be expressed in a float type floating point number CC32R MANUAL 150 Chapter 8 Standard Header Files Table 8 4 Macros Defined by float h 2 3 Macro Name Description DBL_MIN Indicates the min positive value which can be expressed in a double type floating point number LDBL_MIN Indicates the min positive value which can be expressed in a long double type floating point number FLT_MAX_EXP Indicates the max value of the power of the base which can be expressed in a float type floating point number DBL_MAX_EXP Indicates the max value of the power of the base which can be expressed in a double type floating point number LDBL_MAX_EXP Indicates the max value of the power of the base which can be expressed in a long double type floating point number FLT_MIN_EXP Indicates the min value of the power of the base which can be expressed in a float type floating point number DBL_MIN_EXP Indicates the min value of the power of the base which can be expressed in a double type floating point number LDBL_MIN_EXP Indicates the min value of the power of the base which can be expressed in a long double type floating point number FLT_MAX_10_EXP Indicates the max value of the power of 10 which can be expressed in a floa
33. Table 1 1 lists the input output file names that are handled by CC32R file represents any file name File file c Table 1 1 File names for CC32R Type C source file file cpp C source file file mi Preprocessor output file i e a C source file after expansion by the preprocessor file ms Assembly source file file mo Object module file For C used exclusively to create load modules file ml Object module file For C used exclusively to create libraries file lib libray file file abs Load module file am out the default file name file mot Load module file Motorola S format file ic fileti file et file ii file dw2 file dw3 A group of files that contain the information necessary to realize each function of the C language Needed to create load module files file abs or am out CC32R MANUAL 8 Chapter 2 Overview of cc32R Chapter 2 Overview of cc32R EAN About the C C Compiler cc32R 2 1 1 cc32R Functions The cc32R is the C C complier contained in the CC32R cross tool kit and has the following functions e Generates an assembly source file by compiling each C C source file specified by the S option e Generates an object module file from each C C or assembly source file as default or specified by the c option e Generates a load module file from C C and or assembly source file
34. as it is at the time when the function A invokes the function B regardless of whether the function B references arguments of a variable number If you pass the ap s address as an argument or if you pass an aggregate if ap is an aggregate as an argument ap of the function A at the time when returned from the function B continues from the value at the time when the function B terminates va_start va_arg and va_end have been realize from macros If you invoke these by nullifying a macro call so as to access a function a warning is issued during compilation and an error CC32R MANUAL 317 Chapter 10 The cc32R s Behavior occurs during linking due to the absence of external symbols e ANSI C 7 8 1 1 The va_start macro If the second argument parmN of the va_start macro has been declared as a register class variable function type or array type or if the declaration doesn t agree with the type as it becomes after the default actual argument promotions the type resulting from applying implicit type conversion to an argument the operation is not guaranteed e ANSI C 7 8 1 2 The va_arg macro If the argument to be handled is not actually present in calling va_arg the operation is not guaranteed If the argument to be handled is not of the type specified in calling va_arg the operation is not guaranteed e ANSI C 7 8 1 3 The va_end macro Invoking va_end before invoking va_start doesn t cause an error and th
35. include lt stdlib h gt int wectomb char s wchar_t wchar Sj multibyte character storage buffer wchar wide character e If s is NULL 0 Current multibyte character set does not depend on the status non 0 Current multibyte character set depends on the status e If s isnot NULL number of bytes The number of bytes of converted multibyte characters 0 wchar is 0 1 A multibyte character correspond to wehar dose not exist he maximum value of multibyte characte is 3 byte And even euc sjis utf8 in addition to C are supported as the locale The wctomb function converts the wide character specified by wchar into the corresponding multibyte character and stores the result into the buffer specified by s When s is NULL the function checks if the multibyte character set depends on the status at that time CC32R MANUAL 305 Chapter 10 The cc32R s Behavior Chapter 10 The cc32R s Behavior This chapter describes the C C compiler cc32R s behavior corresponding to undefined behavior implementation defined behavior and locale specific behavior in ANSI C Each description is preceded by its corresponding section number in the ANSI C American National Standard for Programming Languages C ANSI ISO 9899 1990 The ANSI C says as follows e Undefined behavior Behavior upon use of a nonportable or erroneous program construct of erroneous d
36. maximum value of the domain HUGE_VAL INT_MAX or the like e ANSI C 7 10 3 Memory management functions the free function realloc function If you reference an area deallocated either by the free function or the realloc function the operation is not guaranteed CC32R MANUAL 320 Chapter 10 The cc32R s Behavior If you pass a value as given below to the first argument the pointer toward an area to be deallocated of the free function or the realloc function the operation is not guaranteed A value that is not a return value the pointer toward an area whose allocation has been completed of the calloc function malloc function or the realloc function A pointer toward an area that was formerly deallocated either by the free function or by the realloc function e ANSI C 7 10 4 3 The exit Function If a program executes a call to the exit function twice or more runs the atexit function so as to catalog the exit function for example the operation is not guaranteed e ANSI C 7 10 6 Integer arithmetic functions If the result of running one of the arithmetic functions of integer type abs div lab Idiv cannot be expressed then the value cannot be guaranteed e ANSI C 7 10 7 Multibyte character function shift state The shift state of the multi byte exists However all functions implement processing in supposing that it is in absolutely the inital shift state when these functions were called e ANSI C 7
37. or if the memory area has been already freed by the free and realloc functions the operation is not guaranteed CC32R MANUAL 210 Chapter 9 C Standard Library f reo pe n Input output function Closes a currently opened stream and reopens a new file with the new file name Syntax include lt stdio h gt FILE xfreopen const char fname const char mode FILE fp fname file name mode file access mode LD pointer to File structure Return Value Pointer for opened stream Successful NULL pointer Error Description The freopen function closes the stream pointed to by fp opened currently and opens a new file fname for the stream by reusing the FILE structure specified by the same fp Select any file access mode from the access modes used in the fopen function and set it as the mode CC32R MANUAL 211 Chapter 9 C Standard Library frexp Mathematics function Divides a floating point number into products of value 0 5 1 0 and 2 to the nth power Syntax Return Value Description include lt math h gt double frexp double x int e X floating point number ej pointer to area in which exponent integer is Value of coefficient m The frexp function calculates a power n of 2 which meets the condition x m 2 and the coefficient m where the absolute value of the coefficient m is smaller than 1 0 and larger than 0 5 A
38. part can be omitted If the mantissa consists of only digit_sequence the number is either a floating point constant or a different constant and the exponent part is required if it is a floating point constant e Expression when the mantissa is fractional_constant fractional_constant Exponent Suffix CC32R MANUAL 47 Chapter 4 C Programming Language Specification e Expression when the mantissa is numerical character string digit_sequence Exponent Suffix Note The content in can be omitted The examples in Table 4 5 show floating point constant expressions Table 4 5 Expression of Floating Point Constant Example Description 1 0 When the mantissa is a floating point constant including a decimal point the exponent part can be omitted 10E3 When the mantissa is a numerical character string not including a decimal point the exponent part cannot be omitted L OF1L If an L or lis suffixed to the end of the data it becomes a long double type data L OE1 If F or f is suffixed to the end of the data it becomes float type data L OE1 If For f or Lor lis not used the data becomes double type data 1E1 The number can start with a decimal point 4 1 3 2 Integer Constant The integer constant is used to express integer It starts with a number and does not include exponent and fractional parts The following three radix numeration systems can be used CC32R MANUAL
39. 0000 0000 0000 0000 0000 0000 0001 1111 1111 1111 1111 1111 1111 1111 1111 unsigned long 0000 0000 0000 0000 0000 0000 0000 0001 1111 1111 1111 1111 1111 1111 1111 1111 4294967295 CC32R MANUAL 77 Chapter 5 Internal Data Representation EEJ Floating Types Table 5 3 shows internal representation of floating type data Table 5 3 Internal Representation of Floating Types Type Size Alignment Signed Minimum Value Maximum Value float 4bytes 4bytes Yes 1 17549435e 38F 3 40282347e 38F double 8bytes 4bytes Yes 2 2250738585072014e 308 1 7976931348623157e 308 long double 8bytes 4bytes Yes 2 2250738585072014e 308 1 7976931348623157e 308 A floating point number is expressed in IEEE standard format Floating type is expressed in IEEE single precision format 32 bits double and long double types in IEEE double precision format 64 bits Figure 5 1 shows these internal representations float 1 8 9 31 Sign eJ double long double 0 1 11 12 63 p Exponent Manisa Sign Sign Indicates the sign of floating point number When 0 indicates positive When 1 indicates negative Exponent Indicates the characteristic of the floating point number as a power of 2 Mantissa Indicates the effective value of the floating point number binary Figure 5 1 Internal Representation of Floating Types CC32R MANUAL 78 Chapter 5 Internal Data Representation Table 5 4 shows exam
40. 0123456789 If a value of c is not included in a range expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 226 isalpha Chapter 9 C Standard Library Character handling function Judges whether a letter or not Syntax Return Value Description Caution include lt ctype h gt int isalpha int c CG character to be judged non 0 is alphabetic A Z a z 0 is non alphabetic A Z a z Returns any value other than 0 if c is alphabetic and returns 0 if c is not alphabetic The alphabetic shall be defined as follows e Upper case letters ABCDEFGHIJKLMNOPORSTUVWXYZ e Lower case letters abcdefghijklmnopqrstuvwxyz If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 227 Chapter 9 C Standard Library iscntrl Character handling function Judges whether a control character or not Syntax Return Value Description Caution include lt ctype h gt int Twsentedk int yey CF character to be judged non 0 cis control character 0 cis anything other than control character Returns any value other than 0 if c is a control character and returns 0 if c is not a control character A control character is any character other
41. 1 This function sets a value of EDOM in errno if x is less than 1 or more than 1 CC32R MANUAL 178 Chapter 9 C Standard Library assert Program diagnostic function Adds a diagnostic function to a program Syntax Return Value Description include lt assert h gt include lt stdio h gt void assert int expression expression an expression to be diagnosed None The assert function is defined as a macro and it outputs a diagnosis message to a standard error file when expression is false 0 And then the assert function starts the abort function This function does nothing when expression is true The assert function is usually used to detect a logical error of the program and a conditional expression is specified so that expression can be true only when a program runs correctly If the description of assert is deleted from the program after the program has been debugged define a macro called NDEBUG in the define statement before fetching lt assert h gt define NDEBUG If the undef statement is used for a macro called assert the effect of the assert function is not guaranteed any more CC32R MANUAL 179 Chapter 9 C Standard Library ata n Mathematics function Obtains the arc tangent of a floating point number Syntax include lt math h gt double atan double x Xi Return Value Calculated value of argument Description The atan function calculates
42. 11 2 Copying functions 7 11 3 Concatenation functions The operation of these functions is not guaranteed in such instances as given below If the size of the copy destination is less than the copy source in running the memcpy memmove strcpy or strncpy function If the area for storing the result of concatenating character strings is insufficient in running either the strcat function or the strncat function e ANSI C 7 12 3 5 The strftime function If a character that is not a conversion specifier is present in the time conversion format format of the strftime function then the character is output without being changed CC32R MANUAL 321 Chapter 10 The cc32R s Behavior A subtraction involved in two pointers that don t point toward the same array doesn t result in an error provided that all the types of operands pointers are compatible But if you make the types compatible by casting the operation result is not guaranteed A mismatch between the number of arguments and that of parameters If the number of actual arguments does not agree with that of formal parameter in calling a function at a position where the function s prototype is invisible the values of unmatched dummy arguments are not guaranteed Concatenating wide string literals With wide string literals specified concatenated strings turn invalid Accessing an object by use of an Ivalue If you assign to an object a value on an lvalue having
43. 5 9604648328104304e 8F Indicates the min floating point number x 1 0 x 41 0 of the float type DBL_POS_EPS 1 1102230246251567e 16 Indicates the min floating point number x 1 0 x 41 0 of the double type LDBL_POS_EPS 1 1102230246251567e 16 Indicates the min floating point number x 1 0 x 41 0 of the long double type FLT_NEG_EPS 5 9604642999033786e 8F Indicates the min floating point number x 1 0 x 41 0 of the float type DBL_NEG_EPS _ 1 1102230246251565e 16 Indicates the min floating point number x 1 0 x 41 0 of the double type LDBL_NEG_EPS 1 1102230246251565e 16 Indicates the min floating point number x 1 0 x 41 0 of the long double type FLT_POS_EPS_EXP 23 Indicates the min No of the power of the binary base which can be expressed floating point number x 1 0 x 41 0 of the float type DBL_POS_EPS_EXP 52 Indicates the min No of the power of the binary base which can be expressed floating point number x 1 0 x 41 0 of the double type LDBL_POS_EPS_EXP 52 Indicates the min No of the power of the binary base which can be expressed floating point number x 1 0 x 41 0 of the long double type CC32R MANUAL 153 Chapter 8 Standard Header Files Classification definition name value Explanation Macro FLT_NEG_EPS_EXP 24 Indicates the min No of the power of the binary base which can be expressed floating point number
44. 6 1 The fprintf function lt The output for p conversion in the fprintf function gt The output for p in the printf like functions turns equal to X e ANSI C 7 9 6 2 The fscanf function lt The input for p conversion in the fscanf function gt The input for p in the scanf like functions turns equal to X lt The interpretation of a character that is neither the first nor the last character in the scanlist for conversion in the fscanf function gt The conversion in the scanf like functions allows to indicate an inclusive range of characters by using hyphen as follows assuming that the character set is ASCII S Character set a f a f i e a b c d e and f 0 9 a f 0 9 and a f a through a only z a Nothing af a and f at the top do not indicate a range af a f and at the end do not indicate a range a f z a f and z e ANSI C 7 9 9 1 The fgetpos function 7 9 9 4 The ftell function lt The value to which the macro errno is set by the fgetpos or ftell function on failure gt errno is setto EFSEEK if the result of the fgetpos or ftell function is unsuccessful i e an error was returned from the environment Note 5 The printf like functions fprintf pointf sprintf vfprintf vprintf and vsprintf Note 6 The scanf like functi
45. 9 Call the main function Note however that depending on the content of a user program there are some other processes that need to be added or those that need to be deleted from the above Each process is detailed beginning with the next page and an example startup program is shown in Section 7 3 10 CC32R MANUAL 130 Chapter 7 Embedded Applications Programming 7 3 3 Getting the Stack Area Get the stack area necessary for the application to run First declare the stack section area in the assembly program by using pseudo directive SECTION and then reserve the stack area by using pseudo directive RES Every time the C C program calls a function stack frame is created on the stack see 6 2 The stack frame is saved until the called function returns process to the calling program Therefore if functions are called successively without returning to their caller such as the function A function B gt function C all stack frames for these functions will be saved when the functions C is called Determine the stack size necessary for the application to run by taking into considerations these function calling behavior and stack size necessary for these functions Since the size cannot be exactly determine estimate approximate size by referring to Chapter 5 Internal Data Representation and Chapter 6 C C Calling Conventions Most practical way is to actually monitor the stack while running the program for de
46. Always left to right e ANSI C 7 1 1 Definitions of terms lt The decimal point character gt The decimal point is 0x2E in the all locales e ANSI C 7 3 Character handling lt ctype h gt lt The implementation defined aspects of character testing and case mapping functions gt Same as e ANSI C 7 3 1 Character testing functions in 10 2 Implementation defined Behavior 10 2 14 Library Functions The behavior of macros declared and functions defined in ctype h in the all locales are the same as in C locale e ANSI C 7 11 4 4 The strncmp function lt The collation sequence of the execution character set gt In the all locales the collation sequence of the character set under the strncmp function is the same as that of ASCII CC32R MANUAL 337 Chapter 10 The cc32R s Behavior e ANSI C 7 12 3 5 The strftime function lt The formats for time and date gt The strftime function allows to represent time and date in the all enviroments locales as follows e Date mm1 dd yy mm1 is the month dd is the day and yy is low order 2 digits of the year in Christian Era Time hh mm2 ss hh is hours mm2 is minutes and ss is seconds CC32R MANUAL 338 Chapter 11 Low level Library Chapter 11 Low level Library 114 The Low level Library Programming 11 1 1 The Low level Library for the C Standard Library Part of actions of the library functions such as s
47. Appendix A Extended Functions Reference e Medium model The medium model is a memory model in which the code and the data of the application respectively are assumed to be stored within the address space of given address A to A OxOOFFFFFF colored part in Figure A 3 and the address space of 0x00000000 to OxFFFFFFFF colored part in Figure A 3 To compile the source in this memory model specify the option shown below when compiling medium The C standard libraries that correspond to this memory model are m32RcRM lib for functions passed via register CODE DATA 0x00000000 0x00000000 on A OxOOFFFFFF UXFFFEFFFFFF OxFFFFFFFF Figure A 3 Address Space in Medium Model e Large model The large model is a memory model in which both code and data of the application are assumed to be stored within the address space of 0x00000000 to OxOOFFFFFF colored part in Figure A 4 To compile the source in this memory model specify the option shown below when compiling large The C standard libraries that correspond to this memory model are m32RcRL lib for functions passed via register Appendix A 17 Appendix A Extended Functions Reference COD 0x00000000 OxFFFFFFFF E DATA Ox00000000 OxFFFFFFFF Figure A 4 Address Space in Medium Model Appendix A 18 Appendix A Extended Functions Reference A3 pragma Extended Functions A 3 1 List of pragma E
48. C 4 3 2 1 dynamic_cast dynamic_cast is a cast operator that permits a value to be safely down cast by determining its type during execution When a pointer is converted if down castable a down cast pointer is returned if not down castable null is returned Syntax dynamic_cast lt type gt expression CC32R MANUAL 66 4 3 2 2 static_cast Chapter 4 C Programming Language Specification static_cast is used for casts that require bit conversions such as a float to int con version up casts and down casts that do not involve testing types Use this cast operator when other casts do not suit the purpose Syntax static_cast lt type gt expression 4 3 2 3 reinterpret_cast 4 3 2 4 const_cast reinterpret_cast is used in cases where the compiler is only instructed to inter pret types and none of data are converted when executed Since only interpre tation is instructed bits are simply copied without being altered Syntax reinterpret_cast lt type gt expression const_cast is used to remove const This operator is used when arguments to functions whose values obviously will not be altered are not specified as const Syntax const_cast lt type gt expression 4 3 3 Implicit Conversions Even though no an explicit conversion is specified a conversion may be done by the C C compiler This is termed implicit conversion and includes the following e Conversion of enumerations A constant declar
49. Compiler Table 14 6 Error Messages 15 15 Message Description undefined static function A function brought under a static declaration cannot be found xxx undefining not userdefined macro You have attempted to eliminate a macro which is not defined unexpected string as initializer An unexpected character string has appeared union used as type is incomplete or undefined The name of a shared set is either incomplete or undefined xxx unknown preprocessor directive A preprocessing directive is indefinite unnamed parameter An argument name is missing unterminated character constant The end of a character constant cannot be found unterminated comment The end of a comment cannot be found unterminated xxx conditional The endif directive for the xxx directive is missing unterminated macro call The end of a macro call cannot be found unterminated string The end of a character string cannot be found file inclusion is too deep up to XXX nesting level The nesting count of included file exceeded the limit number The limit value is displayed to xxx operand of cast to pointer must not be a floating A floating type cannot be converted to a pointer type directly by a cast operand of cast to floating must not be a pointer A pointer type cannot be converted to a floating type directly by a cast member array size too large The size of member described to the struct was big CC32R
50. E f g G orn Types of the size specifiers and their meanings are shown below Size Following conversion Type of the corresponding specifier specifier argument is h d i o u x orX short int or unsigned short int n pointer to short int 1 ell d i o u x orX long int or unsigned long int n pointer to long int L e E f 9g orG long double A size specifier is ignored if the following conversion specifier is other than d i o u x X e E f g Gorn e Conversion specifier A conversion specifier specifies how the corresponding argument is converted If the argument to be converted is a structure or array type or any pointer for those types the operation is not guaranteed except upon converting character array by s conversion and upon converting pointer by p conversion The conversion specifiers and conversion methods are shown below Tables If specifying any character not mentioned here as the conversion specifier the operation is not guaranteed Notice in the tables Types in the Type of the Argument columns are shown assuming that a size specifier h 1 or L is not specified in the conversion specification The argument and the precision mean an argument in the variable argument list and the precision in the conversion specification respectively correspond to the conversion specifier CC32R MANUAL 203 Chapter 9 C Standard Library Conversion Specifi
51. E Terminationt nction NNANSI essasi neea ee aa Aea 8 E Special floating point values judgement function NON ANSI cceeeeeeseeeseeesteeeseeeneeees 8 Appendix C Restrictions on Usage H How to get files that is not included the debug informatio eccecceeceeeeeeeeeeeeeeeeeeeeaees 1 E Cautions on using the base register function with standard library for C uo eeeeeseeeeee 2 HM Avoiding the integral zero division problem of M32R ECU series ccccceeeeereeeees 2 E On indirect calling a function that has variable argument c cscceeseeeeeeeteeeeeeteeeeeees 4 HM Data definition within the Code Section c ccecceeceecceeceeseeeeeeseeeeeeaeeeeecaeseeeteeteseteeenaeeaees 4 E Use of preprocessor variables inside a macro body ecceesscecsseeseeesseeeseeesseeesseesseeeseeess 4 E About compiling the functions of 500 or More lines ccecceeceeceeeeeeeeeeeeeeeeeseseeeeeeeeeaees 5 E Precautions about changing C C Calling Convention ce ceceecceeceeseteeteeteeeeeeeeees 5 E Precautions to be observed when debugging C for the library cccceeeeereereeeees 5 CC32R MANUAL x Contents Appendix D Precautions on a compiling D 1 Regarding Link D 2 Regarding Library Creation D 3 Regarding Directory Movement D 4 Regarding Object Filename Change D 5 Precautions Regarding Special Files for C D 6 Regarding External Symbol Names D 7 Important
52. Error Messages Message Description XXX XXX XXX XXX XXX can t execute The subordinate process xxx cannot be started up Check the setting of the environment variable M32RLIB or files in the default directory and set the environment so that the subordinate process can be started up invalid multicharacter option The option xxx does not recognize invalid parameter The parameter specified after the option xxx is improper Example In R old new neither of P D C and B has been specified for old or nothing has been specified for new invalid unicharacter option The option xxx is not available missing parameter A necessary argument is not specified after the option xxx there is no option An option is not specified CC32R MANUAL 372 Chapter 14 Messages from the C Compiler 14 2 4 Error Messages Table 14 6 Error Messages 1 15 Message Description xxx after else xxx is present after else aggregate union type object must have constant expression initializer list You must initialize an aggregate and a shared set by use of a constant expression argument name not specified in function header No argument is specified for a function header xxx argument starts with a digit The first argument of the preprocessing directive xxx starts with a numeric character it must be an identifier arguments given to macro xxx Arguments are required on the
53. If the calculation result overflows the function returns HUGE_VAL HUGE_VAL if negative CC32R MANUAL 268 Chapter 9 C Standard Library sprintf Input output function Converts the data by following the format and outputs the data to an area Syntax Return Value Description include lt stdio h gt int sprintf char s const char control E S pointer to the memory area to which data is output control pointer to format string st variable argument list output data Number of output characters Note No return value when an error is shown The sprintf function converts and edits the output data specified by the variable argument list according to the format control and then outputs the result to the memory area denoted by s For more information on the format control refer to the description of the fprintf function CC32R MANUAL 269 Chapter 9 C Standard Library sq rt Mathematics function Obtains the positive square root of a floating point number Syntax include lt math h gt double sqrt double x X floating point number Return Value Positive square root of x Description The sqrt function obtains the positive square root of x If x is a negative the value of EDOM is set into errno S ra n d General utility function Sets the initial values of the pseudo random integers which the rand function generates Syntax include lt
54. MANUAL 387 Chapter 14 Messages from the C Compiler 14 2 5 Fatal Error Messages Table 14 7 Fatal Error Messages Message Description no memory available No memory available out of memory No memory available From the optimizer prior errors have corrupted symbol scoping The scope has been broken by a previous error CC32R MANUAL 388 Appendix A Extended Functions Reference Appendix A Extended Functions Reference CC32R has additional extended functions to facilitate its incorporation in systems using the M32R family Appendix A describes how to use the extended functions other than those related to language specifications Table A 1 Extended Functions Extended function Description of function Base register function 1 This function enables the code size to be minimized by speci fying which of the several dedicated base registers for 16 bit register relative indirect addressing each variable is relative to 16 bit register relative indirect addressing 2 The following are required in order to use this function 1 Access Control File and 2 Compile option access access_control_file Memory Models 1 When compiling the program this function hypothesizes multiple storage patterns in the application s memory space so that the optimum object can be generated depending on the size and location of the code P and C sections and data D and B sections in the address space 2 This com
55. _ e A class that is having virtual functions The compiler creates a virtual function table and allocates a pointer to the virtual function table The virtual function table is a data array their structure was explained at Pointers to function and virtual function members of the section 5 8 pointers The 2nd and next arguments are written pointers to virtual functions Coding class A char data1 public virtual char getData1 obj Internal Representation obj data1 Pointer to the virtual base class generated by the compiler Virtual function table generated by the compiler 0 A getData1 CC32R MANUAL 96 Chapter 5 Internal Data Representation e A class that is having virtual base class base class and virtual functions Coding class A short data1 virtual char getDatal1 1 class B virtual public A char data2 char gerData2 char getDatal y class C virtuar protected A int data3 1 class D virtual public A public B public C piblic int data4 char getDatal1 obj Internal Representation obj data2 I Pointer to the virtual function table generated by the compiler Pointer to the virtual base class generated by the compiler obj data3 Pointer to the virtual base class generated by the compiler obj data4 obj data1 Pointer to the virtual function table ge
56. a floating point number Xx modf Divides a floating point number into integer and Xx fractional parts pow Obtains a floating point number to nth power Xx sin Obtains the sine of the radians of a floating point Xx number sinh Obtains hyperbolic sine of a floating point number x sqrt Obtains the positive square root of a floating point x number tan Obtains the tangent of the radians of a floating point x number tanh Obtains hyperbolic tangent of a floating point number x CC32R MANUAL 157 Chapter 8 Standard Header Files Table 8 9 Macro Defined by math h Macro Name Description HUGE_VAL Indicates the value that the function returns when its operation results in an overflow CC32R MANUAL 158 Chapter 8 Standard Header Files 8 2 8 setjmp h Performs the prototype declaration of a branch function and necessary data type declaration The declared functions and data types are shown in Table 8 10 and Table 8 11 Table 8 10 Functions Declared by setjmp h Function Description Reentrant longjmp Recovers the execution environment saved by setjmp O and transfers control to the program location of a setjmp call setjmp Saves the current environment to a memory area O Table 8 11 Data Types Declared by setjmp h Data Type Description jmp_buf Indicates the type name corresponding to the memory location where information that enables movement of the control between functions 8 2 9 signal h Perfo
57. a read error occurs The fgetc function inputs one character from the stream specified by the file pointer fp and returns the character When EOF end of file is encountered the EOF indicator for the stream is set and this function returns EOF When a read error occurs during the operation the error indicator for the stream is set and this function returns EOF The EOF indicator can be referred by the feof function and the error indicator can be referred by the ferror function CC32R MANUAL 194 Chapter 9 C Standard Library fg et pos Input output function Locates the current position on a stream Syntax include lt stdio h gt int fgetpos FILE stream fpos_t pos stream pointer to FILE structure pos current position on the stream Return Value 0 Successful non 0 Error An error is returned to errno Description The fgetpos function returns the current value of the file position indicator of the stream specified by stream to the memory area specified by pos CC32R MANUAL 195 Chapter 9 C Standard Library fgets Input output function Gets a string from an input stream Syntax Return Value Description include lt stdio h gt char fgets char s int n FILE fp S pointer to data storage location n the number of characters to be stored LP pointer to FILE structure s Successful NULL End of file is encount
58. allocation infomation size etc CC32R MANUAL 242 Chapter 9 C Standard Library m b l e n General utility function Obtains the number of bytes composed of multibyte characters Syntax include lt stdlib h gt int mblen const char s size_t n S pointer to the multibyte character nD number of the inspection bytes Return Value e Ifs is NULL non 0 Multibyte character set depends on the status 0 Multibyte character set does not depend on the status e If s isnot NULL number of bytes s is a multibyte character The number of bytes of it is returned 0 The pointer s indicates a null character 1 sis not a multibyte character Description The mblen function returns the number of bytes which consists of multibyte characters specified by s If the mbtowc function is not affected by the shift status mblen is the same value as the following example Example mbtowc wchar_t 0 s n mony Caution The maximum value of multibyte characte is 3 byte And even euc sjis utf8 in addition to C are supported as the locale CC32R MANUAL 243 Chapter 9 C Standard Library mbstowcs General utility function Converts a multibyte character string into a wide character string Syntax include lt stdlib h gt size_t mbstowcs wchar_t pwes const char s size_t 7 PWCS storage buffer of wide character string S pointer to multibyte
59. are not evacuated or returned Even if any of R11 to R13 are specified as base registers they are similarly by default not evacuated or returned The following is extracted from 6 3 Basic Procedures for Function Call and Return in the User s Manual 4 Save registers The contents of registers R4 R13 to be used by the called function are saved on the stack The size of the saving area is ithe number of registers to be saved x 4 bytesi When the link register R14 is used then the link register is saved The following registers can be specified for register names General registers RO R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 Control registers PSW or CRO BPC or CR6 Accumulator ACCO or AO ACC1 or A1 ACC When a register name is specified it is added to the default setting and the compiler generates the code for evacuating and returning that register To have other than the default registers evacuated and returned register names must be specified To specify two or more registers specify their names delimited by spaces Note that there is no differentiation between uppercase and lowercase letters when specifying the names Notes 1 ACC1 or A1 is a reserved register name for the M32Rx core instruction set and this specification is ignored 2 If ACC is specified the operation is the same as when only ACCO or AO is specified The pragma INTERRUPT declaration is valid whether the actual function i
60. asm again as the identifier write the following pragma keyword asm off Write the asm function in the format shown in Figure 7 6 pragma keyword asm on asm assembly_code argument1 argument2 assembly_code The assembly code to be embedded argumenti Expression to be set to register RO argument2 Expression to be set to register R1 Figure 7 6 Format of asm function Write the assembly language code to be embedded into the assembly_code field by following the assembler writing specification An escape sequence as well as a string literal see 4 1 4 can be written Since the beginning of an assembly_code is recognized as a label the first mnemonic must be preceded by one or more space characters CC32R MANUAL 141 Chapter 7 Embedded Applications Programming Example asm ldi RO h 10 T one or more spaces With the asm function up to 2 arguments expressions can be specified in addition to assembly code Each argument is evaluated before executing the assembly code of the asm function A value stored in argument is set to register RO and that stored in argument2 to register R1 A valid argument value is an integer only Bear in mind that integral promotion described in 4 3 2 Implicit Conversions will be applied to signed and unsigned char and short types Arguments having other types may not guarantee proper C C compiler operation Example int i j asm add RO RI i
61. b pragma SECTION B B2 int c pragma SECTION P Pl void func void Variable a is mapped to section B because it occurs before the pragma SECTION declaration Variable b is mapped to section B1 Variable c is mapped to section B2 Function func is mapped to section P1 Figure A 7 Example Use of pragma SECTION Declaration Appendix A 25 Appendix A Extended Functions Reference pragma INTERRUPT pragma INTF Function Declares an interrupt processing function written in C C Syntax pragmaINTERUPT interrupt processing function nameA register namedAregister namea pragma INTF interrupt processing function nameA register namedregister named Description pragma INTERRUPT declares a specified function as an interrupt processing func tion The compiler generates the code for evacuating and returning the register to be used to the stack at the entry and exit points of the function declared as the interrupt pro cessing function It uses the RTE instruction to execute a return at the exit of the function lf no register name is specified default setting the compiler generates the code for evacuating and returning registers RO to R7 and register R14 if there is a function call within the interrupt processing function Because due to the function call rules see 6 3 Basic Procedures for Function Call and Return in the User s Manual registers R8 to R13 are reserved they
62. b c Executing this function call stores the arguments R4 a R5 b R6 e Type conversions If the type of an argument has been declared by the function prototype declaration the argument is converted to that type Otherwise the rules given below are applied e char unsigned char short or unsigned short is promoted to int float is promoted to double e Otherwise unconverted e Store into the register Arguments which have done type conversion as above are stored into the registers follows depending on their types e Ifthe type after conversion is one of char unsigned char short and unsigned short type the argument first is converted to type int and then is pushed onto the stack float type arguments are converted to double types and pushed to the stack if their type has not been declared in a prototype declaration To use register passing with float type arguments be sure to declare their type in a prototype declaration CC32R MANUAL 106 Chapter 6 C C Calling Conventions 6 4 2 The Cases where Stack passing is Valid Part of or all arguments are passed through the stack in the following cases e If there are five or more arguments stack passing is applied to the fifth and subsequent arguments e If the first 4 arguments include either floating type structure type or union type the arguments up to the argument preceding the argument of sucha type are passed by registers T
63. base address 3 Objects to which the base register function is applied variables and structures See A 1 7 The access Control File for details Appendix A 1 Appendix A Extended Functions Reference ESI Base Register Function A 1 1 What is the Base Register Function The base register function enables the code size to be minimized by specifying which of the several dedicated base registers for 16 bit register relative indirect addressing each variable is relative to 16 bit register relative indirect addressing The code generated by CC32R consists of the following 1 Code using 16 bit register relative indirect addressing is generated for accessing objects allocated to the D section area for data with initial values and B section area for data without initial values 2 Code using 16 bit register relative indirect addressing is generated for the read write access of objects at fixed addresses To use this function the following are required e Access Control File e When compiling the compile option access access_control_file Note that the Access Control File can be generated using the map32R map generator 1 The Access Control File contains the following information 1 Base address for 16 bit register relative indirect addressing 2 Register storing the base address 3 Objects to which the base register function is applied variables and structures See A 1 7 The access Control File for de
64. be specified as linker option are limited to one of those listed below If any other option is specified the compiler may not operate normally e Werrsec Specifies that an error be assumed if a nonexistent section is specified in the SEC option of the compiler e Wreloc Shows details of a relocation size overflow error e Wlimit gt message_max Sets the number of messages to be displayed by the linker Ink32R Wnolimit Shows all messages of the linker e Wmangle Shows a mangle name after demangle notation in a message For details about the options available for Ink32R refer to the sections in the Assembler Part of the CC32R Useris Manual in which the linker is described Example specification To pass Wreloc and Wnolimit to the linker cc32R QI Wreloc Ql Wnolimit o test abs SEC P 1000 C D B file Creates a load module file in the form of relocatable one If this option is not specified the module file is generated as an absolute file This option becomes effective at during linking This option cannot be used with MEM or SEC R old new The C C compiler changes the name of the section it is creating The C C compiler classifies the C program into the following 4 sections according to its function default Section name Description Program Constant value Global variable having initial value wana Global variable having no initial value When changing these section names us
65. c is a printable character including space and returns 0 if c is not a printable character or a space Printable character including space is visible on a display and corresponds to the ASCII codes from 0x20 to Ox7E If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 232 Chapter 9 C Standard Library ispunct Character handling function Judges whether a special character or not Syntax Return Value Description Caution include lt ctype h gt int ispunct int c G character to be judged non 0 cis special character 0 cis anything other than special character Returns any value other than 0 if c is a special character and returns 0 if c is not a special character A special character is any printable character excluding space capital letter small letter and decimal digit If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 233 Chapter 9 C Standard Library isspace Character handling function Judges whether a white space or not Syntax Return Value Description Caution include lt ctype h gt int isspace int c G character to be judged non 0 cis a white space 0 cis anything other than a white sp
66. c test2 cpp lt RET gt The c option generates the object module files for test0 ms test1 c and test2 c file ms is an assembly language source file file c is a C language source file and file cpp is a C language source file The name of each object module file is the name of the source file with the extension changed to mo test0 mo test1 mo test2 mo With g debug information is included in each object module generated by the compiler The v option allows verification on the screen at the start of each phase of the C C compiler CC32R MANUAL 38 Chapter 3 Invoking the Compiler EZI The other notes e Stack frame capacity limit limit to size of auto variable The maximum stack frame that can be assigned per function is 32 764 bytes An error results if you attempt to secure more stack frame and no code is generated Data over 32 764 bytes should be secured as static or global data Code example that an error arises void foo void char x 32765 Over 32 764 byts x 0 0 e Use of the run time library for assigning or returning struct In your program if assignment of a structure or a function which returns a structure as a return value is written an error may arises at link time The linker error message error external symbol not defined _100_builtin_memcopy is displayed to show that the _100_builtin_memcopy function does not exist This occurs because the assignment and setti
67. call in the macro body the preprocessor variable may not be correctly expanded when the macro call is effected Code Example macro INST_MACRO MOV 0 RO endm macro LABEL MACRO label INST_MACRO label putting a preprocessor variable from the first column endm section P code align 2 LABEL MACRO L1 this expansion will be failed LABEL MACRO L2 this expansion will be failed end Solution Inside a macro body write a preprocessor variable from the second column or the subseque nt Appendix C 4 Appendix C Restrictions on Usage E About compiling the functions of 500 or more lines When you compile a program that has the big functions of 500 or more lines by CC32R a er ror Out of memory will occur In this case divide this function so that its lines decrease E Precautions about changing C C Calling Convention CC32R V 3 00 Release 1 or newer always generates code for function parameters by regist ers Accordingly objects of CC32R V 3 00 Release 1 or newer and V 2 10 Release 1 can t be linked without measuring Correspond in the following methods 1 C C language program that passes the function argument by using stack It means objects and libraries that was compiled by the CC32R V 2 10 Release 1 without RBPP option How to adapt Compile them with CC32R V 3 00 Release 1 or newer 2 Program of the assembly language that is handing over the function argument by
68. char c inline char func void char s abcde c s 2 Set s 2 before rewriting to c s 2 Rewrite the character string literal here return s Return the present pointer char c1 c2 c3 c4 void foo void char s s func cl c2 s 2 s func c3 c c4 s 2 Function foo execution results In the case of non inline expansion of func Operation for the same abcde C1 c C2 c3 c cA In the case of inline expansion of func Operation for different abcde C1 e C2 c3 c4 Appendix A 32 Appendix A Extended Functions Reference A5 M32R ECU 5 M32R FPU core Compatible Function The new 32180 and 32182 Group abbreviated as M32R ECU 5 MCU s extension instructions and FPU instructions support This function is compatible with the M32R ECU 5 a A code can be generated using M32R ECU 5 added instruction C C Compiler b The program using M32R ECU 5 added instruction can be assembled Assembler c The floating point constant can be handled Assembler A 5 1 Option designation m32re5 A code is generated using the M32R ECU 5 extension instruction Also the non normalized numeral in the floating point constant is reduced to 0 0 fminst A code is generated using FMADD Floating point multiply and add operation instruction and FMSUB Floating point multiply an
69. character or is a space Printable character excluding space is visible on a display and corresponds to the ASCII codes from 0x21 to Ox7E If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 230 Chapter 9 C Standard Library islower Character handling function Judges whether a lower case letter or not Syntax Return Value Description Caution include lt ctype h gt int islower int c G character to be judged non 0 cis lower case letter 0 cis anything other than lower case letter Returns any value other than 0 if c is a lower case letter and returns 0 if c is not a lower case letter A lower case letter shall be defined as follows e Lower case letters abcdefghijklmnopqrstuvwxyz If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 231 isprint Chapter 9 C Standard Library Character handling function Judges whether a printable character including space Syntax Return Value Description Caution include lt ctype h gt int isprint int c g character to be judged non 0 cis a printable character including space 0 cis not a printable character which is not space Returns any value other than 0 if
70. character string n number of wide characters to be converted Return Value Number of converted characters Successful However a null character at the end shall not be included in number of characters 1 Casts 1 as size_t and returns it when any character other than multibyte character is detected during conversion Description The mbstowcs function converts the number of characters pointed to by n among the multibyte character string specified by s into the corresponding character string of wide characters and returns the result to the buffer pwes mow Caution The maximum value of multibyte characte is 3 byte And even euc sjis utf8 in addition to C are supported as the locale CC32R MANUAL 244 Chapter 9 C Standard Library mbtowc General utility function Converts a multibyte character into a wide character Syntax Return Value Description Caution include lt stdlib h gt int mbtowc wchar_t pwc const char s size_t n PWC storage buffer of wide character Sj pointer to multibyte character n number of inspection bytes Number of bytes Both pwc and s are not NULL The number of bytes of the converted multibyte characters 0 s indicates a null character 1 s does not correctly indicate a multibyte character Note If multibyte character encoding has state dependent encoding a non zero is returned Otherwise a zero
71. codes volatile int i volatile int j j i j i CC32R MANUAL 63 Chapter 4 C Programming Language Specification 4 2 6 Storage Class Specifiers C C compiler supported types can be prefixed the following 5 storage class specifiers in C language a storage type specifier If a variable that appears inside a function body is not specified a storage class auto is assumed e auto e extern e static e register Declares that an object under consideration is of automatic storage class You can make this declaration only on an object within a function and the object turns effective within a block only the part between and When the block finishes the storage area is released Example auto int a 1 a is visible only inside the block in which this declaration appears The object or function declared extern is the external storage class The extern declaration is to make an object or function with global declaration visible in the current source file Example extern int val The declaration to use in the source file in which this declaration appears the variable val declared in another source file The object or function declared static is the static storage class It is visible only in the source file in which its static declaration appears Example static void f int The prototype declaration to use only in the source file in which this declaration appears the functi
72. current position on a stream x fgets Gets a string from an input stream x fopen Opens a file xX fprintf Outputs data to a stream according to the format x fputc Outputs a character to a stream x fputs Outputs a string to a stream xX fread Transfers data from a stream to a memory area x freopen Closes a currently opened stream and reopens a new x file with the new file name fscanf Gets data from a stream and converts the data by x following the format fseek Moves the current read write position within a stream x fsetpos Changes the current position on a stream x ftell Locates the current read write position in a stream x fwrite Transfers data from a memory area to a stream x getc Gets one character from a stream x getchar Gets a character from the standard input stdio x gets Gets a string from the standard input stdio x perror Outputs the error message corresponding to the error x code to the standard error file stderr printf Converts data by following the format and outputs it to x the standard output file stdout CC32R MANUAL 162 Chapter 8 Standard Header Files Table 8 17 Functions Declared by stdio h 2 2 Function Description Reentrant putc Outputs a character to a stream Xx putchar Outputs a character to the standard output file stdout x puts Outputs a string to the standard output file stdout x remove Delet
73. default directories are selected automatically Table 3 1 Environment Variables Environment Variable Default M32RKIN EWS version euc MS Windows PC version sjis NR32RKOUT EWS version euc MS Windows PC version sjis CC32R MANUAL 14 Chapter 3 Invoking the Compiler 3 1 3 Command Line Syntax and Rules The command line syntax and rules for the command cc32R which invokes the C C compiler are as follows For details on the command options and input output files see 3 1 4 to 3 2 cc32R access access_control_file c C cs CS constr D name def e entrypoint ecpp E exception noexception float_only fminst g I path L air i iib lang cpp c M MAP map_filename MEM addrl addr2 mklib mklib cla noinline o0 output_filename Opriority O levelZ m32re5 P r R old new rtti on off S strict_standard SEC name addr name addr switch_by_offset U name v V w warn_suppressed_nested_comment rel16 XX symbol_num small memlarge medium large stack zdiv ef_endian big little Iinput_filenames lt RET gt where e Without Indispensable eJn Optional e Prefixed by A command option see 3 2 e lt RET gt Enter the return key Figure 3 1 cc32R Command Line Syntax e Write into the command line
74. function CC32R MANUAL 255 Chapter 9 C Standard Library q S O rt General utility function Performs sorting Syntax include lt stdlib h gt void qsort const void base size_t nmemb size_t size int compar const void const void base pointer to the sort target table nmemb the number of members to be sorted size size bytes of the member to be sorted compar pointer to the function to be compared Return Value None Description The qsort function sorts the table denoted by base The order of the sorted data depends on the compar function The specification of this function is the same as that for the bsearch function CC32R MANUAL 256 Chapter 9 C Standard Library ra i se Signal handling function Send a signal to the executing program Syntax include lt signal h gt int raise int sig Sig signal to be generated Return Value 0 Successful non 0 Error Description The raise function sends the signal indicated by sig to the program Caution To call the raise function in actual the user written raise function is required see Section 11 1 and Table 11 2 ra n d General utility function Generates a pseudo random integer which resides between 0 and RAND_MAX Syntax include lt stdlib h gt int rand void Return Value Generated pseudo random integer Description The rand function generates a pseudo random integer i
75. function main is not initia lized __HEAPSIZE__ Heap Size Heap Size for malloc etc H 4000 __USTACKSIZE __ User Stack User Stack SPU pointed Size H 1000 PointerStack Size __ISTACKSIZE _ Interrupt Stack Interrupt Stack SPI pointed Size H 1000 PointerStack Size CC32R MANUAL 140 Chapter 7 Embedded Applications Programming a In line Assembling 7 5 1 Overview of In line Assembling Embedded application also requires low level processes such as controlling of hardware and operating system OS as well as high speed efficient functional processes To meet these various processing requirements the C C compiler supports the In line assembly function which allows to write an assembly language command in the C C language source program To insert an assembly description into the C C source program use the special function asm The asm function allows embedding an assembly language code into the C C source program Illl Note IIll The C C compiler optimization feature is powerful when used for removing unnecessary codes replacing commands and substituting commands When using the in line assembling feature take into consideration effects of C C compiler optimization feature 7 5 2 How to Write the asm Function To use the asm function use the following definition pragma keyword asm on This does not specify the asm as a normal identifier but as a reserved word To use the
76. h The tmpnam function returns NULL upon exceeding TMP_MAX times At least the space whose size is equal to L_tmpnam defined in stdio h must be secured in the buffer CC32R MANUAL 294 Chapter 9 C Standard Library to l ower Character handling function Converts an upper case letter into lower case Syntax include lt ctype h gt int tolower int c CG character to be converted Return Value Converted character When the character c specified as the parameter meets the condition Character c as it is When the character c specified as the parameter cannot meet the condition Description The tolower function converts the character corresponding to the parameter c into lower case if it is an upper case character and returns the lower case character Otherwise returns the character without converting it CC32R MANUAL 295 Chapter 9 C Standard Library Character handling function toupper Converts a lower case letter into upper case Syntax include lt ctype h gt int toupper int cyz G character to be converted Return Value Converted character When the character c specified as the parameter meets the condition Character c as it is When the character c specified as the parameter cannot meet the condition Description The toupper function converts the character corresponding to the parameter c into upper case if it is a lower case character and returns the
77. handling lt ctype h gt The argument to be passed to a character handling function is neither unsigned char nor EOF the operation is not guaranteed e ANSI C 7 6 Nonlocal jumps lt setjmp h gt setjmp if the macro definition is nullified doesn t result in an error e ANSI C 7 6 1 1 The setimp macro Using the setjmp macro in the ways given below is recommended If you use it in ways other than these no error results but if you use it in an complex expression there can be a chance that part of the current execution environment an interim result of expression evaluation for example is lost Controlling an operand in selection statement iteration statement and in comparing an integer constant expression implicit process by use of the unary operator or the like e Controlling an operand in a selection statement or an iteration statement e Expression statement casting to void e ANSI C 7 6 2 1 The longjmp function If you change an object of an automatic storage class that is not qualified as volatile during a period from executing setjmp to calling longjmp the value of the object is not guaranteed If the longjmp function starts up from a nested signal routine it returns to the setjmp function but the subsequent operation depends on the specifications of a signal function a low level function you prepare CC32R MANUAL 316 Chapter 10 The cc32R s Behavior e ANSI C 7 7 1 1 The signal funct
78. having the same meaning In ANSI C the definition of signed or unsigned integer type includes the character types see Table 4 12 so both int and signed int are given in the above list Illl Note III Type int is regarded as signed int unless signed or unsigned is specified Type long int is regarded as signed long unless signed or unsigned is specified Type short int is regarded as signed short unless signed or unsigned is specified Type enum is a signed int type Type wchar_t is an unsigned short type CC32R MANUAL 58 4 2 2 Types Chapter 4 C Programming Language Specification Types are classified into several groups according to their properties or standpoints For example the integer types including the character types the floating types and the pointer type are generically called scalar types Such groups are shown in Table 4 12 and in Figure 4 5 and other representations of types are shown in Table 4 13 This manual uses these terms to give explanations in some instances Table 4 12 Types Called Types Character types char unsigned char Signed integer types char int short long Unsigned integer types unsigned char unsigned int unsigned short unsigned long Floating types float double long double Basic types signed integer types unsigned integer types floating types integer types signed integer types unsigned integer types enumerated types enum Ari
79. in line assembly function see Section 7 4 Appendix A 19 Appendix A Extended Functions Reference pragma ADDRESS Function Declares that a variable is mapped to the specified absolute address Syntax pragma ADDRESS variable nameAabsolute address Description pragma ADDRESS declares that a variable is mapped to a specified absolute ad dress The compiler generates the code to define the variable name specified in this declara tion as the value of the symbol in the assembler pseudocommand EQU Therefore the area for the variable is not secured The absolute address is output as a character string in a EQU pseudocommand ex pression Therefore the coding rules for the assembler EQU pseudocommand apply Note that only the following numerical format constants can be specified for the abso lute address Also the expression can only be described as a constant expression Octal A constant starting with 0 and consisting of 0 to 7 numerals Decimal Aconstant starting with other than 0 and consisting of 0 to 9 numerals Hexadecima A constant starting with Ox or 0X and consisting of numerals 0 to 9 and A a to F f Variable names of the following storage classes and data types can be specified for the variable name Storage classes Externally definition variables global variable Externally referenced variables extern variable Static definition variables static variables excluding static variables defined
80. include lt stdarg h gt type va_arg va_list ap type ap pointer to variable parameter list the same as ap initialized by va_start type type of return value Value of the argument By using macros va_start va_arg and va_end the arguments of the function having variable parameters can be referenced Specify the va_list type ap initialized by the va_start macro as the first parameter The second parameter type is a the type name of parameter to be referenced Each call of the va_arg function updates the value of ap so that the values of successive arguments are returned as the return value one by one When the type is a type whose size changes by type conversion the parameter is not correctly referenced The operation is not guaranteed if such a type is specified CC32R MANUAL 298 Chapter 9 C Standard Library Va e n d M ac ro Variable arguments access function Ends the reference to variable arguments Syntax Return Value Description include lt stdarg h gt void va_end va_list ap ap pointer to variable parameter list the same as ap initialized by va_start None By using macros va_start va_arg and va_end the arguments of the function having variable parameters can be referenced The va_end macro terminates the reference to variable arguments ap must be equal to the ap initialized by the va_start macro If the va_end macro is not called before the retur
81. length if the value cannot be represented gt In converting an integer into a signed integer less in size than the original the lower order bits of the original integer are converted into a signed integer without being changed The most significant bit of the singed integer after conversion is used for the sign bit In converting an unsigned integer into a signed integer of the same size the lower order bits are converted into a signed integer without being changed e ANSI C 6 3 Expressions lt The results of bitwise operations on signed integers gt The bit operation of a signed integer is dealt with as that of unsigned integer e ANSI C 6 3 5 Multiplicative operators lt The sign of the remainder on integer division gt The sign of the remainder is the same as that of the dividend CC32R MANUAL 326 Chapter 10 The cc32R s Behavior e ANSI C 6 3 7 Bitwise shift operators lt The result of a right shift of a negative valued signed integral type gt A right shift of negative valued signed integer is an arithmetic right shift 10 2 6 Floating Point e ANSI C 6 1 2 5 Types lt The representations and sets of values of the various types of floating point numbers gt Refer to 5 3 Floating Types for internal representations and sets of values of floating types e ANSI C 6 2 1 3 Floating and integral lt The direction of truncation when an integral number is converted to a floating point number
82. library but defined as entry functions in ANSI For specifications for these functions refer to Chapter 9 C Standard Library Table 11 2 Functions defined as low level functions in cc32R Header Function Description signal h raise Send a signal to the executing program signal Sets up a signal handler that responds to the signal stdio h remove Deletes a file rename Renames a file stdlib h getenv Gets the content of an environmental variable system Passes a command string to the host environment time h clock Gets the elapsed processor time time Reads the current calendar time Table 11 3 shows C standard library functions which need low level library listed in Table 11 1 and Table 11 2 Table 11 3 C Standard Library vs Low level Library 1 3 Header C Standard Library Required Low level Function s Function assert h assert _get_core _rel_core write lseek raise locale h localeconv _get_core _rel_core setlocale _get_core _rel_core signal h raise raise signal signal stdio h perror write _get_core _rel_core lseek _strerror fclose write getuniqnum _rel_core close remove lseek fflush write lseek fopen open close lseek freopen write getuniqnum _rel_core close open remove lseek remove remove rename rename tmpfile getuniqnum open close lseek tmpnam getuniqnum fgetpos Iseek CC32R MANUAL 340 Chapter 11 Low level Library T
83. macro definition and macro definition using a the same name as a keyword the corresponding standard header files must have been included before the first reference If you include them after referencing they don t operate correctly Redefining a reserved external name The process at the time of defining an external name other than program reserved ones an external name within a header for example depends on the linker e ANSI C 7 1 4 Errors lt errno h gt errno has been realized from macros and external variables You can access errno even when you nullify the macro definition e ANSI C 7 1 6 Common definition lt stddef h gt Specifying a bit field member of a structure for the second parameter of the offsetof macro results in an error e ANSI C 7 1 7 Use of library functions If the number of actual arguments of a library function is invalid the operation of program is not guaranteed If a library function that accepts variable arguments is not declared by means of including headers there can be a chance CC32R MANUAL 315 Chapter 10 The cc32R s Behavior that the function being handled doesn t operate correctly e ANSI C 7 2 Diagnostics lt assert h gt assert has been realized from macros If you call assert by nullifying a macro call so as to access a function a warning is issued during compilation and an error occurs during linking due to the absence of external symbols e ANSI C 7 3 Character
84. name and an identifier a name numbers strings in a source cord 14 2 1 Information Messages Table 14 3 Information Messages Message Description constant out of range due to unportable conversion A constant will be out of the range of the type in other implementations less complete than prior compatible declaration this declaration ignored This declaration contains less declaration elements than in the previous compatible declaration This declaration is ignored more complete than prior compatible declaration prior declaration ignored This declaration contains more declaration elements than in the previous compatible declaration The prior declaration is ignored prior identical declaration ignored There is an identical declaration before this This declaration is ignored some garbage after xxx argument There is an improper character after xxx unnecessarily punctuated parameter list in define The parameter list in a function like macro definition is incomplete under define xxx with no argument Argument s is are missing from xxx CC32R MANUAL 367 Chapter 14 Messages from the C Compiler 14 2 2 Warning Messages Table 14 4 Warning Messages 1 4 Message Description argument type inconsistent with imputed declaration The type of an argument is inconsistent with the declaration array subscript imply one element initialized by 0 A subscript of a
85. of the allocated area return void p j Return the start address of the allocated area CC32R MANUAL 345 Chapter 11 Low level Library _re l c oO re Low level function Syntax Summary Return Value Description void _rel_core void ptr ptr pointer to the memory space to be freed Frees a memory area None This function frees a memory area being managed by the _get_core function is deallocated ptr is the pointer to the memory area to be released _ st re r ro r Low level function Syntax Summary Return Value Description char _strerror int error_number error_number user defined error number Gets the error message corresponding to an error number Pointer to an error message character string The _strerror function returns the pointer to the error message corresponding to the error number error_number CC32R MANUAL 346 Chapter 11 Low level Library close Low level function Syntax Summary Return Value Description int close int file_no file_no file number of the file to be closed Closes a file 0 Successful 1 Failed The close function closes the file denoted to by the file number file_no which is gotten by the open function This function clears the file control information storage area set by the open function so that the area can be used again When file buffering is used within low level libra
86. of the load module converter refer to CC32R User s Manual 3 The Others Chapter Load Module Converter 6 Embed onto the target system Using a ROM programmer write the S format load module program into the ROM Install the ROM on the target system CC32R MANUAL 129 Chapter 7 Embedded Applications Programming 7 3 Programming the Start up Program 7 3 1 Composition of the Startup Program The startup file consists of three files start ms in assembly language cpp_main cpp in C language and call_main c in C language Startup settings can be updated by rewriting start ms Although part of startup settings are made in cpp_main cpp updating can normally be achieved by only rewriting start ms 7 3 2 Tasks in the Start up Program To run an embedded application on a target system start up program is required that is executed before and after a user program starting with the main function is called The start up program carries out initialization and termination the steps 1 through 5 given below startup ms 1 Gets the stack area 2 3 4 5 Initializes the processor modes Initializes the stack pointer Initializes the data sections www wo Call the_cpp_ main function cpp_main cpp 6 Call a global constructor call _ctor of runtime library 7 Call the _call_main function 8 Call a global destructor call _dtor function of runtime library call_main c
87. open function must set the following information so that the file can be input and output by using this file number e Device type of file console printer disk file etc Give unique name to files of special devices such as console and printer and identify these files with the open function e Information on buffer location and size This information is necessary when buffering files e Byte offset from the start of a file to the next reading or writing location The byte offset is necessary to read write disk file By using the information set by the open function read write the file read write function set read write location lseek function The close function reads contents of file buffer and writes the contents into the file allowing the data area set by the open function to be used again CC32R MANUAL 343 Chapter 11 Low level Library 11 2 The Low level Functions Specifications exit This section describes specifications of functions for low level library in alphabetical order The specifications include Syntax interface to call the function Summary general description Return Value value meaning and Description operation precaution example etc Low level function Syntax Summary Return Value Description void _exit int ex_num ex_num exit status code of program Exits a program None The _exit function terminates the program run and returns the exit sta
88. period If the decimal integers are omitted it is assumed that 0 has been specified As the result of the accuracy specification if there is any discrepancy between the field width and the specification the field width specification is disabled The type of conversion specifier and the meaning of the precision specification are stated below Conversion specifier Precision specification d i o u x X Shows the minimum number of digits of converted data e E f Shows the number of digits of fractional part of converted data g G Shows the maximum number of effective digits of converted data s Show the maximum characters to be printed e The specification for field width or precision An asterisk can be used to specify the field width or precision When is specified the value of the variable argument corresponding to the conversion specification is used as a value to specify the field width or precision If the value of the variable argument is negative the field width is assumed that the flag has been specified for a positive field width The precision is assumed that the precision has been omitted CC32R MANUAL 202 Chapter 9 C Standard Library e Size specifier for the corresponding argument With the size specifiers h 1 or L at the preceding a conversion specifier size of the corresponding argument can be specified when the conversion specifier is d i o u x X e
89. position is set by the third parameter base as shown below a base is 0 At the position beginning of the file plus offset bytes b base is 1 At the position current position plus offset bytes c base is 2 At the position file size plus offset bytes When the file is interactive device for example console printer or the like if the new offset value is negative or setting of a or b exceeds the file size error occurs When the correct file position is set this function returns the new read write position represented by the offset from the beginning of the file Otherwise it returns 1 CC32R MANUAL 349 Chapter 11 Low level Library open Low level function Syntax Summary Return Value Description int open const char name int mode int flag name string denoting the file path name mode specification of mode upon opening the file flag specification of process upon opening the file always 0666 Opens a file File Number of the open file Successful 1 Failed The open function prepares process to handle the file which corresponds to the path name of the file specified by name This function must determine the type of file console printer disk or file for later reading writing The type of file will be referenced every time read write process is taken by using the file number returned from the open function The second parameter mode specifies the process w
90. power value n is stored in the memory area specified by the argument e and the coefficient m is returned as a return value If x is 0 0 both m and n are 0 0 CC32R MANUAL 212 Chapter 9 C Standard Library fscanf Input output function Gets data from a stream and converts the data by following the format Syntax Return Value Description include lt stdio h gt int fscanf FILE fp const char control Lp pointer to File structure control pointer to format string a variable argument list receivers The number of arguments converted Successful Substitution suppression and substituted by n conversion and is not included in this number EOF Input data has been completed before the first conversion excluding has been succeeded Otherwise an error occurred The fscanf function reads input data from the I O stream pointed to by the file pointer fp converts and edits the input according to the format control and then stores the result into the memory area s specified by the variable argument list An input item text in a file when the fscanf function is separated into tokens by on or more white spaces space horizontal tab t newline n Those white spaces are ignored For example the input ABCD abcd is translated into the 2 tokens ABCD and abcd The 2 tokens are converted and then stores into the corresponding ar
91. return value in the type defined function has no return statement The return statement is missing from a function illegal character in input file ignored illegal character A invalid character is present in the input file The invalid character is ignored xxx is referenced before set The name xxx was referenced without being assigned to length of character constant is greater than 512 constant truncated The length of a character constant has exceeded 512 characters The constant has been truncated length of identifier name is 240 characters name truncated The length of an identifier is up to 240 characters The name has been truncated length of identifier name is 31 characters name truncated The length of an identifier is up to 31 characters The name has been truncated length of string literal is greater than 512 string truncated The length of a character string literal has exceeded 512 characters The character string has been truncated xxx may be referenced before set There is a chance that the name xxx may have been referenced without being assigned missing terminal for string assumed at end of line The termination of a character string is missing The end of line has been assumed to be termination mixed normal and wide characters in the same string concatenated string omitted Regular characters and wide characters are mixed in a single charac
92. section name This declaration is valid until another pragma SECTION declaration for the same section is encountered or the end of the file Specify one of the following section names created by the compiler in default section name Section Section Location Description Name Attribute Attribute P CODE ALIGN 4 Program code area C DATA ALIGN 4 Constant data area D DATA ALIGN 4 Data area with initializers B DATA ALIGN 4 Data area without initializers Specify a new user defined section name in modified section name The rules of de scription for section names depend on the rules of description for the assembler names see 3 5 The rules of description for names in the User s Manual lt Assem bler gt The section attributes section attribute and location attribute of the modified section name are the same as the attributes of default section name The following is extracted from section 3 5 The rules of description for names in the User s Manual lt Assembler gt Rules for names are given below MCharacters you can use for the leading character One of alphabetic letters dollar sign and underscore _ You cannot use a digit for the leading character MCharacters you can use for the second and subsequent characters One of alphanumeric characters dollar sign and underscore _ MiThe number of characters you can use in a name Module name 206 characters Symbol name 243 characters
93. see samples in 7 3 9 e userl c user2 c User program including the main function When executing the command line of this example the load module am out reflecting the following specifications is generated e Mmg2RG lib C standard library m32Rc lib is linked e startup Entry point is the start address of the start up program when the start address is defined by the symbol start up in the start up program The application is then executed from the start up program CC32R MANUAL 128 Chapter 7 Embedded Applications Programming SEC D 1000 B SP1 SPU P 8000 C D The linking order of sections is D B gt SPI gt SPU gt P gt C ROM_D SPI and SPU sections are sections prepared for stack by the user in the assembly program ROM_D section is the data area to initialize D section The sections are arranged as follows D Only area is located starting at address 100016 P Located starting at address 800016 B SPI SPU C ROM_D Located following the preceding section e start ms cpp_main cpp call_main c userl c Veer2 After each of these files is compiled and or assembled they are linked 5 Convert to S format file Convert the load module into S format to write it into the ROM Use the load module converter Imc32R Example lmc32R d 4 o file a mout The load module am out is converted into S format and divided into four files file m40 file m41 file m42 and file m43 For operation
94. shorter signed integer The highest bit means a sign Signed unsigned Signed integer has The low bits in the original value will be integer shorter size copied to the shorter signed integer The highest bit means a sign Unsigned integer has shorter size The positive remainder on The original value 1 the maximum value for the new type CC32R MANUAL 68 Chapter 4 C Programming Language Specification e Floating and integral Results of conversions from a floating type to an integral type vice versa and from a floating type to another floating type are as shown in Table 4 16 Table 4 16 Floating and Integral Conversions Original New The Value after Conversion Integral type Floating type It is unchanged if the value can be represented with the new type It is rounded to the nearest value which can be represented with the new type if the value cannot be represented exactly Floating type Integral type The fractional part is discarded Floating type Shorter floating type It is unchanged if the value can be represented with the new type It is rounded to the nearest value which can be represented with the new type if the value cannot be represented exactly float double or long double Unchanged double long double Unchanged Usual arithmetic conversions In performing a binary operation the types of the operands are converted implicitly in order to yield a common type as sho
95. specify any storage class other than register for an argument parameter cannot have initializer in function header You cannot initialize an argument at a function s header segment parameter in this definition incompatible with prior use An argument defined is inconsistent with the previous declaration parameter incompatible with previous declaration An argument is inconsistent with the previous declaration parameter missing declaration is not allowed The number of arguments is insufficient different from what is declared parameter name only is not allowed on function declaration Giving an argument name alone in declaring a function is not permitted parameter name starts with a digit in define The first argument of define starts with a digit it must be an identifier parameter redeclared in current declaration An argument has been redefined pragma keyword has unrecognized keyword option An improper specification is present in pragma CC32R MANUAL 383 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 12 15 Message Description prior errors have corrupted symbol type The type of a symbol has been broken by a previous error proscribed type specifier combination in declaration A declaration is present in which a given combination of types is forbidden redefined statement label in function scope A label has been redefined in a function
96. stderr Converts data by following the format and outputs it to the standard output file stdout Outputs a character to a stream Outputs a character to the standard output file stdout Outputs a string to the standard output file stdout Deletes a file Renames a file Moves the current read write position on a stream to the beginning of the file Gets data from the standard input file stdin and converts the data by following the format Defines a buffer for an I O stream Defines and sets a buffer for an I O stream Converts the data by following the format and outputs the data to an area Gets data from a memory area and converts the data by following the format Creates a temporary file Creates a named temporary file Returns a character a stream Outputs a variable argument list to a stream by following the format Appendix B 4 Appendix B The C Standard Library Function List vprintf vsprintf General utility function abort abs atexit atof atoi atol bsearch calloc div exit free getenv labs ldiv malloc mblen mbstowcs mbtowc Outputs a variable argument list to the standard output stdout by following the format Outputs a variable arguments list to a memory area by following the format Puts the running program to forced stop Obtains the absolute value of an int type integer Catalogs the function to be called upon successful termination of t
97. strtol makes a judgment on the radix from the first character that nptr points to see 4 1 3 2 Integer Constants When the value of base is between 2 and 36 the value of base becomes the radix for conversion Characters a through z and A through Z among a string to be brought to conversion are made to correspond to 10 through 35 and a character equal to or greater than the value of base is recognized as a character that strtol cannot interpret 0 after a sign and 0x 0X at the time when base is 16 are ignored If conversion fails strtol returns 0 as a return value and nptr is set in endptr only when endptr does not hold NULL If the value after conversion overflows i e it cannot be expressed by long strtol function returns LONG_MAX LONG_MIN if negative as a return value and ERANGE is set in errno CC32R MANUAL 287 Chapter 9 C Standard Library strtoul General utility function Converts a string into an unsigned long type integer Syntax Return Value Description include lt stdlib h gt unsigned long int strtoul const char nptr char endptr int base DOET pointer to string to be converted endptr end point of reading base radix Numeric value after conversion Successful 0 Failed The strtoul function reads a string pointed to by ntpr and converts it into a value unsigned long type having a radix specified by base The strtoul function reads a s
98. system function is required see Section 11 1 and Table 11 2 CC32R MANUAL 290 Chapter 9 C Standard Library ta n Mathematics function Obtains the tangent of the radians of a floating point number Syntax include lt math h gt double tan double x X floating point number in radians Return Value Calculated parameter the tangent of x Description The tan function calculates the tangent of x If the result of the function cannot be expressed as a double type value the ERANGE value is set into errno If the operation results in an overflow HUGE_VAL HUGE_VAL in the case of negative value is returned ta n h Mathematics function Obtains hyperbolic tangent of a floating point number Syntax include lt math h gt double tanh double x X floating point number Return Value Calculated parameter Description The tanh function calculates the hyperbolic tangent of x If the calculation result overflows the function returns HUGE_VAL HUGE_VAL if negative value CC32R MANUAL 291 time Chapter 9 C Standard Library Date and time function Reads the current calendar time Syntax Return Value Description Caution include lt time h gt time_t time time_t timer timer calendar time Current calendar time The timer is not NULL 1 Current calendar time was not obtained casting 1 to time_t type upon returning The time func
99. that cannot exactly represent the original value gt Numbers are rounded to the nearest value within representable range of the floating type that is the result of conversion e ANSI C 6 2 1 4 Floating types lt The direction of truncation or rounding when floating point number is converted to a narrower floating point number gt Numbers are rounded to the nearest value within representable range of the floating type that is the result of conversion 10 2 7 Arrays and Pointers e ANSI C 6 3 3 4 The sizeof operator 7 1 1 Definitions of terms lt The type of integer required to hold the maximum size of an array that is the type of the sizeof operator size_t gt The type of the sizeof operator size_t is defined as unsigned long e ANSI C 6 3 4 Cast operators lt The result of casting a pointer to an integer or vice versa gt In converting a pointer to an integer or vice versa all the bits are used with the notation unchanged so a correct conversion results CC32R MANUAL 327 Chapter 10 The cc32R s Behavior e ANSI C 6 3 6 Additive operators 7 1 1 Definitions of terms lt The type of integer require to hold the difference between two pointers to elements of the same array ptrdiff_t gt The type of integer that holds the difference between two pointers ptrdiff_t is defined as int 10 2 8 Registers e ANSI C 6 5 1 Storage class specifiers lt The extent to which objects can actually be placed in r
100. that is set in the environment variable M32RINC However when the header files specified in include lt file h gt format are searched the search in 1 above is skipped 1 lib Specifies a library named lib The library is searched in the following order 1 The directory specified in L option 2 The directory set for the environment variable M32RLIB lang cpp c Specifies the source program language When lang c is specified the source is compiled as a C program When lang cpp is specified the source is compiled as a C program If this option is omitted the source program extension is checked to determine the language If the extension is c the source is compiled as a C program If the extension is cpp cc or cp the source is compiled as a C program Example cc32r test c Compiled as a C program cc32r test cpp Compiled as a C program cc32r lang cpp test c test c is compiled as a C program if lang C is specified the ecpp option is ignored L dir Specifies the library search directory Starts only the C preprocessor to identify the dependency of makefile and outputs the result to the standard output MAP map_filename Outputs the map_filename map file This option becomes effective at linking CC32R MANUAL 24 Chapter 3 Invoking the Compiler Table 3 6 Command Options for the C Compiler 4 11 Option Description MEM addr1 addr2 Thi
101. that no further input will come from the file L_tmpnam Indicates that the size of the location is enough to store the string of the name of the temporary file generated by the tmpnam function SEEK_CUR Indicates that the current read write position of the file is moved from the current of file to the offset SEEK _ END Indicates that the current read write position of the file is moved from the end of the file to the offset SEEK SET Indicates that the current read write position of the file is moved from the beginning of the file to the offset TMP_MAX Indicates the maximum number of file names generated by the tmpnam function FOPEN_MAX Indicates the maximum number of files including stdio stdout and stderr that the fopen function can open at the same time FILENAME_MAX Indicates the maximum size of the name of the file that can be opened stderr The file pointer which indicates the standard error stdin The file pointer which indicates the standard input file stdout The file pointer which indicates the standard output file Table 8 19 Data Type Declared by stdio h Data Type Description FILE Indicates the type of structure that stores the pointer of the buffer necessary for the stream input and output processes and error indicator and end indicator and other control information fpos_t Used by fsetpos and fgetpos functions to indicate file position CC32R MANUAL 164 Chapter 8 Standard Header Fil
102. the application arrange specification and entry point specification suitable for embedding and allocation of address for burning into ROM are required The load module file must be converted into an S format file for burning it into ROM These activities are included in a development of an embedded application and must follow steps 1 to 6 as shown in Figure 7 3 Tasks in the start up program Gets the stack area Initializes the processor modes Initializes the stack pointer Initializes the data sections Calls the main function 1 2 3 1 3 User Program Start up Low level User written main etc Program library programs C Standard Library 4 Generate a load module Using cc32R as32R Load Module and Ink32R 5 4 Convert to S format Using Imc32R S format Load Module 6 Embed onto the target 4 system by burning into the ROM ROM 4 wae Figure 7 3 Embedded Application Programming 1 Write user program Write the main function and other routines which perform the required processes To write in C C follow the C C specification refer to Chapter 4 C C Language Elements To write in assembly follow the M32R assembly specification refer to CC32R User s Manual 2 Assembler Some processes can be performed by writing assembly instructions in the C source program in line assembling function CC32R MANUAL 126 Chapter 7 Embe
103. the arc tangent of x This function returns a value in a range from 0 to 7 ata n 2 Mathematics function Divides a floating point number by a floating point number and obtains the arc tangent of the result Syntax include lt math h gt double atan2 double y double x Y Xi Return Value Calculated value of argument Description The atan2 function calculates the arc tangent of y x This function returns a value in a range from 7 to x The result of the atan2 function indicates an angle made by the x axis of a memory area through a point x y and origin 0 0 When both arguments x and y of the atan2 function is 0 this function sets a value EDOM in errno CC32R MANUAL 180 Chapter 9 C Standard Library atex i tT General utility function Catalogs the function to be called upon successful termination of the program Syntax include lt stdlib h gt int atexit void func void func pointer to registered function Return Value 0 Registered Other than 0 Not registered Description The atexit function registers a function called when a program has completed correctly or when the exit function has been called A maximum of 32 functions can be registered When the program has completed the functions are executed in the reverse order of registration atof General utility function Converts the character string representing a number into a double type floating point numb
104. this function returns EOF When a read error occurs during the operation the error indicator for the stream is set and this function returns EOF The EOF indicator can be referred by the feof function and the error indicator can be referred by the ferror function CC32R MANUAL 224 gmtime Chapter 9 C Standard Library Date and time function Converts calendar time to Coordinated Universal Time UTC Syntax Return Value Description include lt time h gt struct tm gmtime const time_t timer timer time Converted result pointer to tm structure Successful NULL timer could not be converted into UTC The gmtime function converts the calendar time shown by timer into Coordinated Universal Time UTC and converts it toa struct tm broken down time CC32R MANUAL 225 isalnum Chapter 9 C Standard Library Character handling function Judges whether a letter or decimal digit Syntax Return Value Description Caution include lt ctype h gt int isalnum int c CG character to be judged non 0 cis alphanumeric A Z a z 0 9 0 cis anything other than alphanumeric Returns any value other than 0 if c is alphanumeric and returns 0 if c is not alphanumeric Alphanumeric shall be defined as follows e Upper case letters ABCDEFGHIJKLMNOPQRSTUVWXYZ e Lower case letters abcdefghijklmnopgqrstuvwxyz e Decimal digits
105. to 2 shown below can be checked 1 A global variable which is type struct union or array 2 A local variable which is type struct union or array used inside that function CC32R MANUAL 35 Chapter 3 Invoking the Compiler 3 2 4 switch_by_offset Option When the compiler generates a code using the table jump command for the switch statement an offset table excellent in ROM efficiency is created PRECAUTIONS The offset table generated when this option is designated can be handled only up to the range of 32K bytes with the initial case of switch statement as origin Accordingly if such a large switch statement as exceeds 32K bytes is described the code may be unable to be generated normally There arises overflow in linking with linker Ink32R At this time remove the switch_by_offset option for re compiling effect Format Example cc32R switch_by_offset filename c Additional designation to cc32R command line option is required at compiling Effect Where the switch statement is generated by the table jump command with the conventional CC32R the ROM size can be reduced Actually generated code The following is the branch table of switch statement generated by CC32R with conventional compatibility and switch_by_offset e For explanation only the branch table address table amp jump table is described e The top label of statements a b c d shall be L1 L2
106. to invoke the linker alone even in Makefile dw2 SYSROF Format C Information 4 Object Module files ides et b sal ii Linking cc32R User Library Environment lt _ User Library my Lah ti C Information ewe files lil et ii SYSROF Format abs ELF DWARF Format Load Module Module Load Module Convert Imc32R ae as Debugging PD32R PD32RSIM Figure 1 3 Flow of Linking CC32R MANUAL 6 Chapter 1 Overview of CC32R 1 4 4 Library File Generation Flow Figure 1 4 shows how to link the object and library files to generate a load module file To create a library file the prelinker needs to be invoked Therefore even when creating a library file make sure the librarian is started through the compile driver cc32R by using the mklib option C C source c cpp oa Compile cc32R A AN SYSROF Format ml C Information p Object Module files OWS et ii Compile cc32R xxx ml Object Module for Template Figure 1 4 Flow of Linking CC32R MANUAL 7 Chapter 1 Overview of CC32R 1 5 Input and Output File Names for CC32R CC32R identifies the type of an input file by its file name extension And CC32R will determine the file name or the extension for an output file
107. types viod bool wchar_t char signed char unsigned char char signed char int signed int u hort signed short signed short int ong signed long signed long int unsigned char unsigned int ar nsigned short unsigned short int unsigned long unsigned long int float double long double struct union enum wchar_t CC32R MANUAL 57 Chapter 4 C Programming Language Specification Types of C language e Basic types Character types char signed char unsigned char Signed integer types char signed char int signed int short signed short signed short int long signed long signed long int Unsigned integer types unsigned char unsigned int unsigned short unsigned short int unsigned long unsigned long int Floating types float double long double e The others Array types Structure types struct Union types union Enumeration types enum Void types void Pointer types Function types Wide character types wcehar_t signed and unsigned are type specifiers that indicate whether an entity is either signed or unsigned As for an array pointer or function assigned no type specifier you specify that either an object or a function is of the type you declare in a fixed format in ANSI C As for a type specifier that is alternatively represented by alias such as signed int the C C compiler translates the alternative representation as
108. unsigned long int n pointer to long int L e E f 9g orG long double A size specifier is ignored if the following conversion specifier is other than d i o u x X e E f g Gorn Conversion specifier A conversion specifier specifies how the corresponding argument is converted The fscanf function unless the conversion specifier is c n or skips the white spaces in the input before conversion The skipped characters are not included in the field width When a space is read during conversion if it is any character unauthorized for conversion processing is terminated without reading the character When the specified field width is completed during conversion processing is terminated The conversion specifiers and conversion methods are shown below Tables If specifying any character not mentioned here as the conversion specifier the operation is not guaranteed Notice in the tables Types in the Type of the Argument columns are shown assuming that a size specifier h 1 or L is not specified in the conversion specification The argument means an argument in the variable argument list which corresponds to the conversion specifier CC32R MANUAL 215 Chapter 9 C Standard Library Conversion Specifier d Conversion Specifiers for fscanf 1 2 Conversion Method Converts a character sequence which represents a decimal number into integer data Type of the Argume
109. upper case character Otherwise returns the character without converting it CC32R MANUAL 296 Chapter 9 C Standard Library ungetc Input output function Returns a character a stream Syntax Return Value Description include lt stdio h gt int ungetc int c FILE fp CF character of pushback fp pointer to FILE structure Pushed back character c Successful Normal EOF Failed The ungetc function returns the character c to the I O stream specified by the file pointer fp The pushed back character will become the next input data if the fflush fseek or rewind function is not called If the ungetc function is called twice or more without first one of the three functions being called the operation is not guaranteed Upon execution of the ungetc function the position indicator for the file is moved backward by one step If the indicator is already at the beginning of the file the indicator is not guaranteed When an error occurs during the operation the error indicator for the stream is set or the EOF indicator is set and this function returns EOF The EOF indicator can be referred by the ferror function The error indicator can be referred by the ferror function CC32R MANUAL 297 Chapter 9 C Standard Library Va_a rg M ac ro Variable arguments access function Gets variable arguments in turn Syntax Return Value Description Caution
110. 00 or older or is not corresponding to the Japanese character displays the Japanese character may not be displayed correctly A 6 4 6 preprocessor output P E option The compiler that the P or E option is designated outputs always the Japanese letter with euc A 6 4 7 Restriction item of Unicode Pay attention to the next point in the case of programming to use utf8 Unicode 1 Character that is able to use it Only the character in the 6 1 1 can be used even if environment variable is designated to utf8 The program including the character other than Japanese that is defined with JIS X 0201 0208 is not able to process normally 2 Character that differs by the implement The number that is assigning the Unicode correspondence to the same character by impl ement of host environment an editor and target environment even if it is called may di ffer Because of this if utf8 is designated to environment variable M32RKIN M32RKOUT ple ase use and pay attention to the handling of Unicode Appendix A 42 Appendix A Extended Functions Reference 3 Handling of a resemblance character The character that was inputed will be transforming to euc at first in the compiler inside The several of the character that form resembled on Unicode are normalized to same cha racter on euc Therefore even if both M32RKIN and M32RKOUT are utf8 several charact ers of source and output may not be equal A 6 5 The supplement of Japane
111. 00_C_action_atexit function calls all of termination functions registered by using the atexit function and then clears the counter which counts registered functions Call this function always after terminating the main function in the start up program See 7 2 7 3 1 0o Cg et ex i t cod e Termination function non ANSI Gets the exit status from exit Syntax Return Value Description int_100_C_get_exit_code void The exit status the termination code returned from the exit function The _100_C_get_exit_code function gets the exit status code from the exit function Call this function always in the start up program to check the exit status for the function which has been terminated with the exit function See 7 3 9 Start up Program Example CC32R MANUAL 175 Chapter 9 C Standard Library a b O rt General utility function Puts the running program to forced stop Syntax include lt stdlib h gt void abort void Return Value None Description The abort function terminates execution of the program and generates a signal SIGABRT Abort function does not flush any buffer close any file nor delete any temporary file a b S General utility function Obtains the absolute value of an int type integer Syntax include lt stdlib h gt int abs int 7 E an integer to be computed Return Value An absolute value of the result Description The abs function ca
112. 140 Start Up Program Example isis sicciecsssiecsiessdissoeseteedensdcndeieheclendacteccnescetasiensttensinces 134 About start up tle Starts m HEW rrisin ara nei tas eke a iia 140 IMIS ASSSMIDNING cmne a E E 141 7 5 1 Overview of In line Assembling eee eeceeeeeeeneeeeeeeeneeeeaeeeeeeteaeeteaeeeaeesaaeetaeeteaten 141 7 5 2 Howto Write the Asm FUMCUOM siccae adanida aneia 141 7 5 3 Limitations lt OF asm FUNCION secies anniari daea aaae 142 POA asm Function EXAM Pls ceeace sidai aasa iai 145 Chapter 8 Standard Header Files 8 1 8 2 Overview of the Header Pile casccicssszeescctevests celeconys tateusaneessepeaads Coledteestaceeseains heleee 147 Contents of the Header PileSiiansicesns cette ctesuetiian a ial nndee 149 821 ASSONU ossur aa iaa aia A aioe pasaia eisai 149 BIZ CVP Nianie aee a a Ra 149 8 2 3 ENNO akesi a a EET 150 BIZ AOA eee AE NE A ASES OE EES 150 825 MNE Meyen e aee a nie E E 155 8 26 l GAlE iseyen aiena e a aaa ae ae aripii 156 827 Maheran i a E ees 157 828 SOUMMP Miei ee ee a E E ea Ee E eea EE E o EAS aeda 159 8 2 9 SIGMA aaneen a n E a E R E N EE ERE 159 8210 Std eeso aia a apia enna 160 B211 Sto hieiererre e O a a 161 147 CC32R MANUAL vi Contents O22 VSIA EPEN E E E TE ANTT 162 8 2 13 Sth Mrara eena O N EE de 165 Sil VA GUNG Misrni ea riaa iiaiai 167 8 215 WME Miren A E Ee 168 Chapter 9 C Standard Library 9 1 9 2 9 3 Overview of the C Standard Library c
113. 4 Messages from the C Compiler Table 14 6 Error Messages 7 15 Message Description invalid file name in xxx A file name specified in the preprocessing directive xxx is incorrect xxx invalid file name in include A file name specified in the preprocessing directive include is incorrect invalid initializers Initialization has been performed in an incorrect manner invalid line number in line The way of specifying a line number in line is improper xxx invalid macro name A macro name is incorrect invalid macro name A macro name is incorrect invalid parameter name in define A parameter name in define is improper invalid token in if constant expression An improper token is present in a constant expression under if XXX is not within a conditional The position of the preprocessing directive xxx is improper is required after defined macroname The right parenthesis for enclosing an identifier after defined is missing the identifier is not enclosed left operand of assignment operator must be modifiable lvalue The lvalue of an assignment expression must be modifiable less parameters than definition There is a shortage of the number of parameters in a function prototype declaration line number shall not specify zero nor a number greater than 32767 A line number must be between 1 and 32767 CC32R MANUAL 379 Chapter 14 Messages f
114. 48 Chapter 4 C Programming Language Specification Table 4 6 Expression of Integer Constant Radix Consists of Base and Integer Constant Decimal number Starts with a number other than 0 followed by numbers Numbers 0123456789 Hexadecimal number A hexadecimal number starting with Ox or OX Hexadecimal numbers 0123456789 abcdeforABCDEF Octal number An octal number starting with 0 Octal numbers 01234567 When the character u or U is suffixed to an integer constant the constant is treated as an unsigned constant If neither character is suffixed the constant is treated as a signed constant When the character or L is suffixed to an integer constant the constant is treated as a long type constant If neither character is suffixed the constant is treated as an int type constant Table 4 7 Integer Type Constant Data Type Following constant Process by C C compiler data type u or U suffixed Unsigned constant No u or U suffix Signed constant lor L suffixed long type constant No lor L suffix int type constant Table 4 8 shows examples of integer type constant expression Table 4 8 Description of Integer Type Constant Example Description 123 Signed int type decimal number 123 123u Unsigned int type decimal number 123 1231 Signed long type decimal number 123 123ul Unsigned long type decimal number 123 0123 Signed octal number 123 0x123 Signed hex number 123 CC32R MANUAL 49 Chapter 4
115. 6 4 3 Function Names after Compiling Function names in the object module are named by preceding the names of functions in the C C program with a dollar mark However in the case of functions that return floating point types double or long double structure types or union types and in the case of functions that have variable arguments the following rules apply e Functions which return either floating point number structure or union The function name is preceded by an underscore _ e Functions having variable parameters Assume that the number of arguments passed via register is n When n 0 The name is a function name used by the C C program with a preceding underscore _ Example int foo char is given the name _ foo When n 4 The name is a function name used by the C C program with a preceding dollar mark Example int foo int int int int TAC pace 3 is given the name foo When n 1 2 or3 The name is a function name used by the C C program with a preceding dollar mark and the number of arguments passed by register passing Example int foo int int is given the name 1 foo 6 4 4 How to Refer set Arguments To refer to an arguments within the called function refer to the stack frame if the argument is passed through the stack or refer to the register into which the argument is set when the argument is passed through the register Note that some arguments ar
116. 7e 308 ong double 4 2 4 Data Format for Floating Point Constants Floating type data is assumed to be in the IEEE 754 format IEEE 754 is the internal representation of real numbers in the form specified by Institute of Electrical and Electronics Engineers IEEE For internal representation of floating type data see Chapter 5 Internal Data Representation CC32R MANUAL 62 Chapter 4 C Programming Language Specification 4 2 5 Type Qualifiers Type qualifiers const and volatile can be added to any data type supported by the C C compiler The type qualifiers are const volatile The type qualifier indicating that the value of the object cannot be changed The value of an object once declared by a data type such as const cannot be replaced Example const char c 1 a b const char ptr a Variable c is fixed at 1 and cannot be replaced b The content specified by the pointer ptr is fixed and cannot be changed The ptr itself can be changed The type qualifier implying that the object can be changed Once volatile is specified the C C compiler will not optimize the object and directly outputs writing and reading processes to the object code For example specifying volatile to an area or a memory map I O area suggests that the contents in that area may be changed In the following example the C C compiler does not perform optimization and outputs objects to the object
117. 8 wchar_t kanji2 0x6f 22 0x5b57 0x0032 0x0000 Example 2 wide character Next some program is shown description of the same meaning as wchar_t kanji3 L 2 sjis wchar_t kanji3 Ox8abf euc wchar_t kanji3 Oxb4c1 utf8 wchar_t kanji3 0x6f22 char kanji4 L 3 It becomes an overflow Appendix A 43 Appendix A Extended Functions Reference A 6 5 2 Standard library 1 Designate the locale locale h It is possible designated a character code name that shows it in Table 9 in addition to loc ale conventional C a locale name as it is 2 A wide character transformation function mbtowc mbstowcs mblen wctomb wcstombs LC_CTYPE processes on the basis of each character code in the case of euc sjis and also utf8 locale 3 Function of printf scanf series A format designated character string considers as the multi byte character string of a cha racter code that was designated to LC_CTYPE 4 Other standard functions The locale will be regarded that it is the same action as C locale always 5 About shifting condition A standard library function is not remembering shifting condition It supposes that shifting condition is already initialized when it is called Appendix A 44 Appendix B The C Standard Library Function List Appendix B The C Standard Library Function List This appendix lists the C standard library functions and their summ
118. A 39 TOO sr sas stehenaae shan pce tiss on nesodswiagniadoel an meted dena aes daa aan 42 AAA ROY WONSvxcsitsaccecesttone ceasetstctaaceecstabtesssiuadhaesest phatetcascensteceeheadaehibtecceeunncdgmecntaneteantenehs 43 A12 Identifiers G lanQuagevonly siiseie ce cies tesesieastecyinente a e maser 44 AMS COMSTAMS 3 eciscz E E E T AE E A A A 46 4 1 3 1 Floating PONT CONSTANT esssisac seeds eeeucenessernars seazeneeseerbetysieseeesneavescesusns ceaneancrrerscaeds 47 4 1 3 2 MEGS COMSLAING sans cecitasshasansleatcannsstasnetanidensnateubancsaasnate aA eO TAERA 48 4 1 3 3 Enumeration Constant oninia E E ada 50 4 1 3 4 Character GOMStAINT casass sisscueseapcssinccestascasseanesanh EE EEN 50 4 1 3 5 TAMIA GS OMS ANE saanane A EA 50 AMA String literal Sesiapa ea eadein eai oiai 51 ANS OMSRALONS wu edscacesdeceeti aes ese reed elec vcncuieng deus doses E te aaa eE 51 AAG Punct ator Sennan N ea EE EE e aE a 55 A COMMENT iaa EE e AEA AEE AEE AES 56 Daa Wy OS Seene NA 57 4 2 1 Types and Type Specifiers 0 2 ceeceesceceseeeseeeeeeesseeeeaeeeeeseaeeeeeseaeeeeeeteaeetsaeeeaeenaas 57 422 TYPES cnsesreann a ei edoi edaean teu useti cd tsengescananctevtebs cemtereeeeeeeeiecs 59 4 2 3 Data Size and Range of Basic Types eceeeeseseeeeceeeeseceeeaeeseeeeeaeesaeetaeesseeteaes 62 4 2 4 Data Format for Floating Point Constants 0 ecceeeeeeeceeeeeneeeeeeeeaeeeeeeteeeseeeenaes 62 425 Typ Qualilers xcs ccsisces sc ccnces sszceseecsers ccgesscge
119. ANUAL 308 Chapter 10 The cc32R s Behavior e ANSI C 6 1 4 String literals Mixing wide character string literals and character literals With regular string literal specified if a wide character string literal token appears the prefix character L is ignored and concatenated as a character string literal With wide character literal specified character strings cannot be concatenated e ANSI C 6 1 7 Header names The characters or if appear in a header name are recognized as characters making up a file name not processed as special characters e ANSI C 6 2 1 Arithmetic operations If the result of an arithmetic conversion cannot be expressed within a given space deficiency in accuracy an approximate value is used In the case of conversion into an integer however digits to the right of the decimal points and the bit pattern of higher order digits that couldn t be accommodated is discarded e ANSI C 6 2 2 1 Lvalues and function designators In other cases than initializing an array by use of an initialization expression using an incomplete type on the lvalue results in an error e ANSI C 6 2 2 2 void Either accessing an object by use of a value of void type or adapting an implicit conversion to a void expression except conversion into void results in an error e ANSI C 6 3 Expressions Side effects A side effect that occurs between sequence points of an expression is indeterminate Do not write co
120. C Programming Language Specification 4 1 3 3 Enumeration Constant The enumeration constant is a member of type enum and has type int Example enum rgb red green blue The red green and blue are enumeration constant 4 1 3 4 Character Constant The character constant represents the character or escape sequence and is enclosed by single quotation marks To include a quotation mark itself in a character constant prefix the mark to The following escape sequences can be used ye a b yE n r t v Figure 4 2 Escape Sequence Character Constant To express a hexadecimal number prefix x to express an octal number Valid hex and octal number consists of up to 3 figures Table 4 9 describes how to write character constant Table 4 9 Example of Character Constant Expression Example Description mr 2 Escape sequence Represents single quote TATU Escape sequence Represents line feed TAg Octal number Represents character code 00 hex x7 Hexadecimal number Represents character code 07 hex xFF Hexadecimal number Represents character code FF hex 4 1 3 5 Truth Constant The truth constant is a constant with two statuses true and fales CC32R MANUAL 50 Chapter 4 C Programming Language Specification 4 1 4 String Literals 4 1 5 Operators Enclose a string literal with double quotations The escape sequences shown in Figure 4 3 can be us
121. Data Representation Example 1 Coding Internal Representation Description e Example 2 Coding Internal Representation Description struct bl unsigned int a 5 unsigned int b 6 unsigned int c 7 0 45 1011 1718 31 The member of structure b1 is stored at the leftmost and subsequent 4 byte location size of unsigned int struct b2 short a 5 short b 5 short c 8 y 0 45 910 150 78 15 The c of the structure b2 would overflow from the third location 6 bits and is allocated a new location CC32R MANUAL 91 Chapter 5 Internal Data Representation Example 3 Coding Internal Representation Description e Example 4 Coding Internal Representation Description struct b3 short a 5 short b 5 short 0 unsigned short c 5 0 45 910 150 45 15 The 0 bit bit field short 0 of structure b3 is placed before c which is then allocated a new location struct b4 short short int d a b Ink CE9 9 short e E short The area allocated for 5 7 9 9 6 8 4 byte alignment In the structure b4 different bit field type specifiers are used The largest type specifier is int and the entire alignment is 4 byte 32 bit long The type specifier for each field specifies the bytes of the location at which the bit field is to be placed Because c is int type the alignment is 4 bytes The 9 bits can follow b If c is short type
122. Data area without initializers for uninitialized global variables For C source files the following three sections are generated in addition to the above e CTOR section An area used to store the addresses of constructors and destructors that are called for global class objects e VTBL section An area used to store the data necessary to call a virtual function when any virtual function is found in a class declaration e COMMON section An area used to store RTTI information and the internal static variables of inline functions CC32R MANUAL 120 Chapter 7 Embedded Applications Programming Program 1 Object Module A Program 2 Program 3 Object Module B Object Module C a Figure 7 1 C C Compiler Defines a Program to Sections A section is a unit program processed by linker Each section has the section name section attribute and location attribute as shown in Table 7 1 Table 7 1 Sections Output from C C Compiler Section Section Location Description Name Attribute Attribute P CODE ALIGN 4 Program code area C DATA ALIGN 4 Constant data area for const declared variables D DATA ALIGN 4 Data area with initializers for global variables having initial values excluding const declared variables B DATA ALIGN 4 Data area without initializers for uninitialized global variables CTOR DATA ALIGN 4 An area used to store the addresses of co
123. E f F gorG Converts a character sequence showing a floating point number into the floating type data Input format is a floating point number which can be expressed by the strtod function pinter to float CC32R MANUAL 216 Chapter 9 C Standard Library Conversion Specifier p Conversion Specifiers for fscanf 2 2 Conversion Method Converts a character sequence in the format to be converted by the p conversion in the fprintf function into pointer type data Type of the Argument pointer to void No data is input and the number of characters which have been input is set pointer to int Specifies a set of characters between and called scan set e g abcd a z abcd The scan set defines characters to be read If a scan set begins with non the initial character sequence preceding the first appearance one unspecified in the scan set is read If a scan set begins with the initial character sequence preceding the first appearance one specified in the scan set is read Appends the null character to the read character sequence automatically The area pointed to the corresponding argument should be enough to store it including the null character pointer to char A is read No conversion or assignment occurs None CC32R MANUAL 217 Chapter 9 C Standard Library Input output function fseek Moves the current r
124. INT_MAX Indicates the max value that an unsigned int type variable can have LONG_MAX Indicates the max value that a long type variable can have LONG_MIN Indicates the min value that a long type variable can have ULONG_MAX Indicates the max value that an unsigned long type variable can have CC32R MANUAL 155 8 2 6 locale h Chapter 8 Standard Header Files Performs prototype declaration and macro definition of a function locale handle function which processes localization of the program Table 8 6 and Table 8 7 list the functions declared and macros declared by locale h Table 8 6 Functions Declared by locale h Function Description Reentrant localeconv Initialize struct lconv x setlocale Sets and searches for locale information x Table 8 7 Macros Defined by locale h Macro Name Description LC_ALL Sets and searches all locale information LC_COLLATE Sets and searches information that affects the strcoll function and strxfrm function LC_CTYPE Sets and searches information that affects functions handling character and multi bytes except for the isdigit and isxdigit functions LC_MONETARY Sets and searches information that affects currency information returned from the localeconv function LC_NUMERIC Sets and searches information that affects information other than decimal point used by the input and output functions and the character handling functions and currency information returned from
125. Information on Compiling a C Program with the C Compiler D7 1 Function prototype declarations D7 2 Linkage of const objects D7 3 Assignment of void CC32R MANUAL xi Audience References Preface Preface M3T CC32R abbreviated as CC32R is a cross tool kit which supports software development for the Renesas M32R family of 32 bit RISC architecture microcomputers It provides many functions suitable for development of embedded systems for the M32R family The CC32R manual set provides information for programming by use of CC32R targeting an M32R system The CC32R manual set assumes that the readers are developers programming for the M32R system using the C C or assembly language Accordingly it also assumes that the readers are familiar with programming languages C or assembly and their development environment a host machine and its operating system etc and have basic knowledge of the target M32R systems A manual related to development for the M32R family is e M32R Family User s Manual e M32R Family Software Manual Refer to the WWW site of the Renesas Microcomputers The URL is http www renesas com For details about the ANSI C ISO C language refer to e ANSI ISO 9899 1990 American National Standard for Programming Languages C American National Standards Institute Inc e ISO IEC 14882 2003 Programming Languages C This document was made in the light of the coments of next UR
126. L Wide character wchar_t e s Multi byte character string char LF Wide character string wchar_t Parentheses inside show a regular value style name Attention The character in the character constant style must not be multi byte character Namely Kan is not possible description It will become warning A 6 2 1 Multi byte character This is the one that expressed 1 character of Japanese Kanji with 1 or more plural byte And this is expressed with a character string the array type of char Even if it is a simple only 1 character it becomes the form of a character string as Length of the multi byte character is not stable Therefore if you needs to searching inse rtion and elimination for a multi byte character in a multi byte string continuation of the multi byte characters it is necessary to confirm continually boundaries between neighb or characters during the processing On the other side there is the advantage that conventional functions the standard functi on of printf and strcpy etc that handle the byte string can be used without changing it A 6 2 2 Wide character This expresses one character of Japanese Kanji The wide character can be declared with the wchar_t type This type is defined with std def h standard header The wide character string the array of the wide characters has so many data volume in comparison with the multi byte string On the othe
127. L e Japan Women s University http momijwu ac jp ccenter cpp cpp2 htm CC32R MANUAL x Conventions Preface The CC32R manual set uses the following conventions e Symbols Symbol Meaning Italics Represents a generic description that should be replaced with a specific a b Represents alternative items a b represents either a or b Encloses optional elements that can be included or omitted Indicates to repeat the preceding item zero or more times Represents omission of a or more lines lt RET gt Represents to enter the return key e Terms 1 2 Term Meaning M32R A Renesas 32 bit RISC architecture microcomputer M32Rx M32R system A system using the M32R CC32R The cross tool kit for an M32R system C C compiler cc32R The C C compiler in CC32R Assembler as32R The assembler in CC32R Linker Ink32R The linker in CC32R Librarian lib32R The librarian in CC32R Map generator map32R The map generator in CC32R Load module converter Imc32R The load module converter in CC32R Release notes The document related to the release of the CC32R in a CC32R package Please read it at first C program A program written in the C language C program A program written in the C language Assembly program A program written in the assembly language CC32R MANUAL xi e Terms 2 2 Term Source file
128. LIGN 4 LD24 R1 _a LDB R1 R1 LD24 RO _b STB R1 RO JMP R14 Figure 6 8 Referencing C C Program Data e Inthe assembly program To reference char type variables a and b written in C C from the assembly program specify labels _a and _b by the pseudo instruction IMPORT or GLOBAL The CC32R prefixes an underscore _ to the external reference and the definition symbol of C C upon outputting them to the object module The variables in the C C program in Figure 6 8 for example correspond to the labels _a and _b in the assembly program CC32R MANUAL 112 Chapter 6 C C Calling Conventions 6 6 3 Calling Assembly Routines from a C C Program To call an assembly function from a C C program write programs by following examples described in Figure 6 9 Calling program C program extern int func int int void foo fune 1 2 Calling program C C program extern C extern int func int int void foo fune 1 2 Called program assembly program EXPORT Sfunc SECTION P CODE ALIGN 4 func MV R0 R5 Copying the 2nd argument to RO ADD RO R4 Writing the total of lst and 2nd arguments to RO JMP R14 END Figure 6 9 Calling Assembly Program Function CC32R MANUAL 113 Chapter 6 C C Calling Conventions e The C program that is calling the assembly progr
129. Library Chapter 9 C Standard Library This Chapter describes the C standard libraries contained in CC32R 9 1 Overview of the C Standard Library 9 1 1 The Library Files Contained in CC32R CC32R provides two versions of the library which should be used properly according to the argument passing method for library functions m32RcR lib m32RcRM lib m32RcRL lib for register passing e m32RcR lib m32RcRM lib m32RcRL lib Specify either libraries with the l option as you invoke the C compiler or linker III Note IIll Do not mix use m32Rc lib mM32RcM lib m382RcL lib for stack passing and m32RcR lib mM82RcRM lib m382RcRL lib for register passing in an application CC32R MANUAL 169 Chapter 9 C Standard Library 9 1 2 Library Function Groups C standard libraries are in conformity to ANSI specifications ANSI ISO 9899 1990 The functions are classified into 11 groups as shown in Table 9 1 Each library can be made available for use in a unit process only when the corresponding standard header file is included Table 9 1 C Standard Library Function Groups Group Summary Corresponding Header file Program diagnostic function Program diagnostic information output assert h Character handling function Character handling and checking ctype h Mathematics function Arithmetic operations e g trigonometric functions math h Non local jump function Transfer of c
130. NUAL 40 Chapter 3 Invoking the Compiler Notes about MS Windows PC version 1 Floating point numbers For the floating point value 0 0 the code for 0 0 are output 2 Path delimiter 3 The path delimiter symbol is the backslash However to specify the path for included files specified in the source file you can use either or In this case is only recognized when input and is internally replaced by Therefore the path delimiter output into warning error messages listing files and debugging information is always Upper lower case in a file name A file name is upper lower case insensitive For example file c FILE C and FiLe C are all process ed as the same file name However upper lower case in the generated file is effective for the long file names Specifying Path You do not use the relative path name with a drive letter CC32R MANUAL 41 Chapter 4 C Programming Language Specification Chapter 4 C C Programming Language Specification This chapter describes basic specifications of the ANSI C ISO C programming language processed by the compiler e g the elements of the C C programming language and the structure of a C C language source program ESI Token A token is the minimal lexical element of the C C language text for manipulation and analysis by the compiler The compiler manipulates and analyzes the following elements as tokens in confor
131. Quotient and the remainder in calculation result Description The div function calculates the quotient and the remainder for the result of dividing number by denom The return value is div_tstructure and the quotient and the remainder are put in quotand rem respectively of the member CC32R MANUAL 189 exit Chapter 9 C Standard Library General utility function Terminates the program Syntax Return Value Description include lt stdlib h gt void exit int status status exit status code None The exit function terminates a program by executing the following 1 Flashes all the buffers of an opened stream 2 Closes all the opened files 1 2 3 Deletes all the files generated by tmpfile 4 Executes all the functions registered by atexit functions in reverse order 5 5 Returns control to the environment saved by a setjmp function Control no returns to the caller To check status in the environment to which the process returns you can use the _get_exit_code function CC32R MANUAL 190 Chapter 9 C Standard Library ex p Mathematics function Obtains the exponential function of a floating point number Syntax include lt math h gt double exp double x x floating point number Return Value Value of exponential function e Successful Description The exp function calculates the exponential function e of x and returns the resu
132. RcR lib m32RcRM lib m32RcRL lib Because of this If you have been using CC32R V 4 10 Release 1 and use the zero divis ion measurement libraries please use general standard libraries instead of them The case of using non standard libraries In use the customer made libraries or the re build libraries from the standard library sources set of attachment to CC32R please re build or re compile with zdiv option Explanation of the zdiv option When it uses in compiling with cc32R Compiling with zdiv option it generates assembly source with inserting NOP instru ctions each after the all of created DIV instructions Also it inserts NOP instructions as same in asm functions too However if you use zdiv option with S or CS in same time compiler generates asse mbly source with removing comment and coverting alphabetic letters to upper In the case of inputting assembly sources to cc32R it performs same from assembling by as32R When it uses in assembling with as32R If assemble code includes DIV instructions with zdiv option it inserts NOP instructi ons each after the all of this DIV instructions However it except case of that NOP ins truction already exists after the DIV instruction It means there is not following object between the DIV instruction and the NOP instr uction In other words the compiler inserts NOP instruction after the DIV instruction if there is following object between the DIV instruction and the NOP instru
133. Renesas Electronics does not warrant that such information is error free Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein Renesas Electronics products are classified according to the following three quality grades Standard High Quality and Specific The recommended applications for each Renesas Electronics product depends on the product s quality grade as indicated below You must check the quality grade of each Renesas Electronics product before using it in a particular application You may not use any Renesas Electronics product for any application categorized as Specific without the prior written consent of Renesas Electronics Further you may not use any Renesas Electronics product for any application for which it is not intended without the prior written consent of Renesas Electronics Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for an application categorized as Specific or for which the product is not intended where you have failed to obtain the prior written consent of Renesas Electronics The quality grade of each Renesas Electronics product is Standard unless otherwise expressly specified in a Renesas Electronics data sheets or data books etc Standard Computers office
134. SAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKKKKKK KKK KKK KK KKK This Start up program start ms is sample program CC32R MANUAL 137 Chapter 7 Embedded Applications Programming e Startup program cpp_main cpp In this sample program a program part that executes the basic processes 6 to 8 is written as a C language program if defined __M32R_ COPYRIGHT C 1993 2003 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION include lt setjm h gt extern C externjmp_buf_900_init_env void_ctor void void_dtor void int_call_main void int_100_C_get_exit_code void void_100_C_action_atexit void void__call_terminate void void_exit int extern void _900_exit_stdio_func_ptr void extern void _900_exit_mem_func_ptr void extern C void _cpp_main void int exit_code ifdef __ EXCEPTIONS try endif __EXCEPTIONS _ctor call global constructor if setjmp _900_init_env exit_code _call_main else exit_code _100_C_get_exit_code if setjmp _900_init_env _100_C_action_atexit _dtor call global destructor CC32R MANUAL 138 Chapter 7 Embedded Applications Programming ifdef _ EXCEPTIONS Gateh Cs A if setj
135. SO C a bit field declared with signed int is sign extended whereas whether a bit field declared with int is zero extended or sign extended is indeterminate Thus there can be a chance for a bit field declared with int though holding a signed data item to be zero extended depending on a com piler used struct bl signed int a 4 int b 4 x x a 1 The value stored in x a becomes 1 x b 1 The value stored in x b is indeterminate It correctly becomes 1 by sign extension but becomes 15 by zero extension e signed int In ANSI C ISO C a bit field declared with signed int is sign extended Thus specifying 1 for the field width allows the value to range between 1 and 0 not between 0 and 1 singed int c 1 c can take on a range between 1 and 0 CC32R MANUAL 89 Chapter 5 Internal Data Representation 5 9 2 Packing and Alignment The type specifiers that can be specified in the bit field are limited in size to 1 byte 8 bits char 2 bytes 16 bits short or 4 bytes 32 bits int long or bool Allocation of a bit field to a memory location is shown in examples below Size of the alignment boundary at location Memory space to accommodate all members are reserved in units of size 1 2 and 4 bytes denoted by the type specifiers For example memory space is divided in 4 byte locations in the case where the structure is composed of int type bit fields Bit fiel
136. Section name 243 characters Preprocessing name 32 characters Macro name 32 characters MDistinction between uppercase and lowercase letters Distinction is made for names the user can define No distinction is made for names the user cannot define You define a name according to the preceding rules Be careful about the following in that instance You cannot use a name identical to a reserved word for an entity other than a module name MNames the user defines such as symbol names section names cannot be duplicated a 5595 5 5 amp 55 50 R Appendix A 23 Appendix A Extended Functions Reference pragma SECTION Description The default compiler section name can be restored by specifying the default section name in modified section name To change the section name declare the pragma SECTION before the function defi nitions or data definitions The D section must be initialized to the initial values at startup If you change the name of the D section be sure to initialize the modified section to the initial values at startup The B section must normally be cleared to zeros at startup If you have changed the name of the B section be sure to clear the modified section to zeros at startup Rules lf you change the name of the P section section names in functions defined after this declaration take the modified section name lf you change the names of the C D or B secti
137. To our customers Old Company Name in Catalogs and Other Documents On April 1 2010 NEC Electronics Corporation merged with Renesas Technology Corporation and Renesas Electronics Corporation took over all the business of both companies Therefore although the old company name remains in this document it is a valid Renesas Electronics document We appreciate your understanding Renesas Electronics website http www renesas com April 1 2010 Renesas Electronics Corporation Issued by Renesas Electronics Corporation http www renesas com Send any inquiries to http www renesas com inquiry CENESAS 8 10 11 12 Notice All information included in this document is current as of the date this document is issued Such information however is subject to change without any prior notice Before purchasing or using any Renesas Electronics products listed herein please confirm the latest product information with a Renesas Electronics sales office Also please pay regular and careful attention to additional and different information to be disclosed by Renesas Electronics such as that disclosed through our website Renesas Electronics does not assume any liability for infringement of patents copyrights or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document No license express implied or otherwise is grant
138. _D section P code align 4 i Initialize PSW control register r CC32R MANUAL 134 Chapter 7 Embedded Applications Programming STARTUP LOOP1 SKIP1 LOOP2 SKIP2 LOOP3 LDI RO 128 MVTC RO PSW i Setting the user and i r SETH RO HIG OR3 RO RO MVTC RO SPU SETH RO HIG OR3 RO RO MVTC RO SPI r f f Clear the B section to SETH RO HIG OR3 RO RO SETH Rl HIG OR3 Rl Ri LDI R2 0 CMP RO R1 BNC SKIP1 STB R2 RO ADDI RO 1 BRA LOOP 1 r f r Clear the COMMON secti SETH RO HIG OR3 RO RO SETH Rl HIG OR3 R1 R1 LDI R2 0 CMP RO R1 BNC SKIP2 STB R2 RO ADDI RO 1 BRA LOOP2 t Transfer the data in t area to the RAM area r SETH R1 HIG OR3 R1 R1 SETH R2 HIG OR3 R2 R2 SETH R3 HIG OR3 R3 R3 CMP R1 R3 BNC SKIP3 LDB RO R1 STB RO R2 ADDI Rl 1 ADDI R2 1 BRA LOOP3 nterrupt stack H USTACK_BOTTOM LOW USTACK_BOTTOM H ISTACK_BOTTOM LOW ISTACK_BOTTOM zero H __TOP_B LOW __TOP_B H __END_B LOW __END_B on to zero H __TOP_COMMON LOW __TOP_COMMON H __END_COMMON LOW __ END_COMMON he ROM_D section in ROM H __TOP_ROM_D LOW __TOP_ROM_D H __TOP_D LOW __TOP_D H __END_ROM_D LOW __END_ROM_D CC32R MANUAL 135 Chapter 7 Embedded Applications Programming SKIP3 i Jump to the C standard ini
139. a library filename with the o option To add object modules to an existing library file be sure to specify mklib a If while mklib c is specified the library file specified by the o option already exists the specified library file is temporarily deleted and then newly created If while mklib a is specified the library file specified by the o option does not exist the specified library file is newly created same way as when mklib c C E P S M and CS cannot be used at the same time Example 1 cc32R mklib c o xx lib aaa ml bbb cpp ccc c The library file xxx lib is generated from the object module files derived by compiling aaa ml and bbb cpp and ccc c 2 cc32R mklib a o xxx lib ddd ml eee cpp fff c The object module files derived by compiling ddd ml and eee cpp and fff c are added to the library file xxx lib To create a library file use the object module files extension ml generated with the mklib option or use this option mklib This option is used to create the object module files extension ml that comprise a library file extension lib Always be sure to specify c lowercase along with this option The applicable files are those that bear the extensions cpp c and ms C E P S M and CS cannot be used at the same time Example 1 cc32R mklib c xxx cpp yyy c Object module files xxx ml and yyy ml are created 2 cc32R mklib o combine ml c d ms To create a library f
140. a cages aE E aS EER A 327 1028 REJIS Siana N a E E open SEE 328 10 2 9 Structures Unions Enumerations and Bit fields 2 0 0 0 eee etree 328 10 2 10 Qualifiers ciccone eeter erra inden ieee ce 329 HOLS TMD SCIARALONS argani reepa dactaadbtacse sagcetgaasveeapcbtucassabiastdansadsestuanteds 329 MO2 1 2 State mE Senne E E N a a A eh aces 329 10 213 Preprocessing Directive ssnsdin ar eae a a Diaa 329 10 2 14 Library FUNCIONS sosisini orsina caveachabetteveceovndsactensdtcaeddeecde 330 L Cal SpeCiiC BEMAVION sic cccsrh occensntt nccamestecte nea nist aa aaie 337 Chapter 11 Low level Library 11 1 The Low level Library Program in iri sstcice ace seceseutered ca aadiviteadicotansine Eis 339 11 1 1 The Low level Library for the C Standard Library 00 0 ccceeceeseeeeeeeeeeeeeeeeeteeeeeees 339 11 1 2 Input Output with the Low level Library cecceeceesseesseeeeeeeeeeeteaeeeeeeteaeeseeeeatens 343 The Low level Functions Specifications c cccecccececceeeeeeeeeeeeeeeeeeesetaeeeeeeeees 344 169 306 339 CC32R MANUAL vii Contents Chapter 12 Single precision Mathematical Function Library 354 12 1 COMPOSINON Of FUMCHOMS saisisit ieina aaae eaa N 354 122 Using MELDA tascetesseseccts peace n a 356 1221 Header Filesi iaar E aE ias A enas 356 12 2 2 Link with the Single precision Mathematic Function Library s seseesseeeeeeeeeeeeeeea 357 Ieo PoC UNON ssccucehoctae Sacdids Seborhoaasetbehisaee phahinas de
141. a lower case letter into upper case O CC32R MANUAL 149 Chapter 8 Standard Header Files 8 2 3 errno h Upon occurrence of an error defines the external variable errno that holds the error number and the macro that indicates the error number Table 8 3 shows the macros defined by errno h Table 8 3 Macros Defined by errno h Macro Name Description EDOM If the value of input parameter is outside the range defined by a function EDOM indicates the value to be set to errno ERANGE If the calculation of a function results in a value which cannot be expressed in double type or if it results in an overflow or underflow ERANGE indicates the value to be set to errno 8 2 4 float h Defines the limits concerning internal representation of a floating point number Table 8 4 describes the macros defined by float h Table 8 4 Macros Defined by float h 1 3 Macro Name Description FLT_RADIX Indicates the radix of an exponent FLT_ ROUNDS Indicates the round mode in addition operation The macro definitions are as shown below e Round to the nearest value 1 e Round toward 0 2 e Round toward vo 13 e Round down to 0 0 e Not specified 1 Round and round off are process system definitions FLT_MAX Indicates the max positive value which can be expressed in a float type floating point number DBL_MAX Indicates the max positive value which can be expressed in a double type floating point number
142. a union struct used as type is incomplete or undefined A structure is either incomplete or undefined struct union improperly defined possibly as a result of previous error s Either a structure or a shared set is improper There is a chance that an error may have occurred previously subscript must be positive non zero integral value An array size must be an constant of integer sequence greater than 0 syntax error A syntax error syntax error at or near symbol xxx A syntax error is present near the symbol xxx syntax error in if constant expression A syntax error is present in the description of a constant expression under if tag conflicts with prior struct union appearance A tag is inconsistent with that of struct union previously described tag conflicts with prior struct union enum appearance A tag is inconsistent with that of struct union enum previously described tag redeclared in current declaration A tag re declared is present xxx tag use inconsistant with previous definition The use of the tag xxx is inconsistent with the one in the previous definition xxx tentative definition static object shall not have incomplete type at declaration The type declaration of the static object is incomplete VRE too many arguments to macro n arguments The number of arguments of the macro xxx is too many n arguments are present CC32R MANUAL 385 Chapter 14 Messages from th
143. able 11 3 C Standard Library vs Low level Library 2 3 Header C Standard Library Required Low level Function s Function stdio h fseek lseek write Cont fsetpos Iseek write ftell Iseek rewind lseek write fgetc read _get_core _rel_core fgets read _get_core _rel_core fputc write _get_core lseek _rel_core fputs write _get_core lseek _rel_core getc read _get_core _rel_core getchar read _get_core _rel_core gets read _get_core _rel_core putc write _get_core _rel_core lseek putchar write _get_core _rel_core lseek puts write _get_core _rel_core lseek ungetc _get_core rel_core fread read _get_core _rel_core fwrite write _get_core _rel_core lseek fprintf write _get_core _rel_core lseek fscanf read _get_core _rel_core printf write _get_core _rel_core lseek scanf read _get_core _rel_core sprintf write _get_core _rel_core lseek sscanf read _get_core _rel_core setbuf _rel_core setvbuf _rel_core vfprintf write _get_core _rel_core lseek vprintf write _get_core _rel_core lseek vsprintf write _get_core _rel_core lseek CC32R MANUAL 341 Chapter 11 Low level Library Table 11 3 C Standard Library vs Low level Library 3 3 Header C Standard Library Required Low level Function s Function stdlib h abort raise calloc get_core _rel_core free
144. ace Returns any value other than 0 if c is a white space and returns 0 if c is not a white space A white space shall be as the following characters e White spaces white space form feed f line feed n carriage return r horizontal tab t and vertical tab v If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 234 Chapter 9 C Standard Library isupper Character handling function Judges whether an upper case letter or not Syntax Return Value Description Caution include lt ctype h gt int isupper int c CF character to be judged non 0 cis an upper case letter 0 cis anything other than an upper case letter Returns any value other than 0 if c is an upper case letter and returns 0 if c is not an upper case letter An upper case letter shall be defined as follows e Upper case letters ABCDEFGHIJKLMNOPORSTUVWXYZ If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 235 Chapter 9 C Standard Library isxdigit Character handling function Judges whether a hexadecimal digit or not Syntax Return Value Description Caution include lt ctype h gt int isxdigit int e y3 CF character to be judged
145. aches the character code which is best for outputting character constant and string letteral to the compiler The name that shows it to character code name of Table A 3 is designated The upper and lower have the same meaning in this environment variable If this environment variable is undefined sjis in PC version or euc in EWS version is selected in the default c Character code the standard library at the time of implementation locale LC_CTYPE category The name that shows it to the character code name of Table A 3 is designated The upper character or lower character are distinguished in this locale name The character code is set to LC_CTYPE even in the case that the character code name is designated to the LC_ALL category The initial value of the LC_ALL category is C This designation is effective to the multi byte processing functions printf series functions and scanf series functions Please pay attention because it is ineffective to string h and ctype h function group As for the details refer to A 6 4 3 Appendix A 37 Appendix A Extended Functions Reference A 6 2 Description method of the Japanese character The Japanese character can be described to the character constant and character string letter al directly Also there are 2 kinds of a wide character or a string and multi byte character about whether L is attached or not 2 Multi byte character char
146. ack passing iS Valid ec cc eeceeeeeeteeeeeeeeeeeteaeeeeeeteaeeteeenaeetee 107 6 4 2 1 PSIG OMG TS stac Ko sisanne AAEE 107 6 4 3 Function Names after Compiling ecceeeceeeeeeeeeeeeeeeseeeeeaeeeeeeeeeeseeeeeeeseneeeeeeea 109 6 4 4 How to Refer set ArQuimentss cc ceccccccecssseecteccesssdecciceaceees sbtseaterecnstnveasiee eetueseusenece 109 Seting Return Vall Eassa aa AE 110 Interface with Assembly Program cc ccccseceeeneeeeeeeeeeeaeeeseaeeeeeaaeeseeeeeseaaaeennees 111 6 6 1 Referencing Assembly Data from a C C Program cecceeeceeeeeeeeeeteteneteneetens 111 6 6 2 Referencing a C C Program from Assembly Data cccecceeceeeseeeeeeeeeeneetens 112 6 6 3 Calling Assembly Routines from a C C Program cceecceeecceeseeeeeeeeneeeeeeenreeees 113 6 6 4 Calling C C Routines from an Assembly Program cccceecceeeeeeeeeeeeeeteneeeneetens 115 Interfacing C and Gr Programs isitniti ninian apai hdan 116 6 7 1 extern C and External Symbol Names sisissssirssrmeisrrrrornnisa 116 6 7 2 To Reference C Program Data from a Program eceeseeeceeeeeeteeeeeeeeneeeens 117 6 7 3 Reference C Program Data from a C Program eeeceeseeeeteeeeeeeeeetenteseeeeeeeeee 117 6 7 4 Call C Program Functions from a C Program cccccceeeeeeeeeeeeeeeeeeneeeeeeeneeeeas 118 75 99 CC32R MANUAL v Contents 6 7 5 Call C Program Functions from a C Program esceeeceeeeeeeeeeeeeeeeneee
147. al even if it inclu des Japanese characters 2 Description of Japanese with the wide character string wchar_t wstr L 374 L is attached to the top of character string letteral in the case of a wide character string Even both the Japanese character and conventional characters can be described in wide string 3 Copy and connect of a multi byte character string strepy buff str1 strceat buff str2 As for the multi byte character string the processing such as the copy and connection are possible like the conventional character string 4 Setting of a character code setlocale LC_CTYPE sjis Setting up the locale name the character code name of Table A 3 by the setlocale functio n for converting from multi byte character string to wide character string in the next part 5 At this time the same character code as M32RKOUT needs to be designated to LC_CTYPE If the M32RKOUT is undefined please designate sjis for PC version or euc for EWS version to the setlocale function 5 Transformation to a wide character string size_wch mbstowcs wbuff buff WBUFSIZE Transforming from the multi byte character string that made it in the above 3 to the wi de character string for the byte unit processing in next 6 6 Taking out each a character and outputting it except particular character for i 0 i lt size_wch i if wbuff i
148. am Declare functions that need to be referenced from an assembly program using the extern C keyword e As passing arguments A symbol name of the assembly program is the corresponding function name but preceded by the dollar mark e Calling program C C program Arguments are set to the registers e Called program assembly program In the figure 6 9 RO has 1st argument and R1 has 2nd argument and RO will have return code at the end of this function CC32R MANUAL 114 Chapter 6 C C Calling Conventions 6 6 4 Calling C C Routines from an Assembly Program To call a C C program function from an assembly program write an assembly program by following the example described in Figure 6 10 Calling program assembly program register passing GLOBAL Sfunc SECTION P CODE ALIGN 4 LDI R5 2 iV LDI R4 1 iX BL func END Called program C program int func int x int y Called program C program extern C int func int x int y Figure 6 10 Calling C C Program Function e When calling a C program Define the called function using extern C e As passing arguments A symbol name of the assembly program is the corresponding function name but preceded by the dollar mark The calling program assembly program sets arguments to the registers R4 R7 In the example shown in Figure 6 10 arguments are two
149. amily V 5 00 C C Compiler User s Manual 2tENESAS Renesas Electronics Corporation 1753 Shimonumabe Nakahara ku Kawasaki shi Kanagawa 211 8668 Japan REJ10J0930 0100
150. an incompatible type the operation is not guaranteed CC32R MANUAL 322 Chapter 10 The cc32R s Behavior A Implementation defined Behavior Here follows how the operation dealt with as implementation defined behavior in ANSI C goes on in the C C compiler cc32R such as how messages are notified the number of significant characters for an identifier or the format of integer or floating point number etc The number and the heading subsequent to e ANSI C are the section number and the section heading of the corresponding ANSI C ANSI ISO 9899 1900 Each issue as implementation defined behavior is shown in a pair of angular brackets lt gt and the corresponding behavior of cc32R is detailed subsequent to lt gt 10 2 1 Translation e ANSI C 5 1 1 3 Diagnostics lt How a diagnostic is identified gt The diagnosis messages include information messages warning messages error messages and fatal error messages For details of output formats of messages see Chapter 12 Messages from the C C Compiler 10 2 2 Environment e ANSI C 5 1 2 2 1 Program startup lt The semantics of the arguments to main gt The arguments passed to the main function depend on the specifications of the startup program you prepare e ANSI C 5 1 2 3 Program execution lt What constitutes an interactive device gt The operation of input output devices depends on the specifications of the read function and t
151. an identifier outside the current block in the current block the external identifier is invalid The external identifier becomes visible after the current block terminates CC32R MANUAL 45 Illl Note III Chapter 4 C Programming Language Specification There are four kinds of name spaces of identifiers see Table 4 3 Name Space Table 4 3 Name Spaces of Identifiers C language only Function Name Variable Name Identifier in the Name Space An identifier which is not any of the identifiers a label name a tag name and a member name Label Name An identifier which is followed by a colon and is in goto statement Tag Name An identifier disambiguated by following any of the keywords struct union or enum Member Name An identifier disambiguated by the type of the expression used to access the member via a period or the operator gt Identifiers having different name space can have the same name because the C compiler differentiates between them as described above The identifiers in the same space cannot have the same name For example the name of a label can be the same as that of a function On the contrary a structure tag and union tag cannot have the same name A key word cannot be used as an identifier see 4 1 1 4 1 3 Constants A constant represents a constant numerical value It has a type determined by its form and value as follows Float
152. and Renesas Solutions Corporation assume no responsibility for any damage liability or other loss resulting from the information contained herein Renesas Technology semiconductors are not designed or manufactured for use in a device or system that is used under circumstances in which human life is potentially at stake Please contact Renesas Technology Corporation Renesas Solutions Corporation or an authorized Renesas Technology product distributor when considering the use of a product contained herein for any specific purposes such as apparatus or systems for transportation vehicular medical aerospace nuclear or undersea repeater use The prior written approval of Renesas Technology Corporation and Renesas Solutions Corporation is necessary to reprint or reproduce in whole or in part these materials f these products or technologies are subject to the Japanese export control restrictions they must be exported under a license from the Japanese government and cannot be imported into a country other than the approved destination Any diversion or reexport contrary to the export control laws and regulations of Japan and or the country of destination is prohibited Please contact Renesas Technology Corporation or Renesas Solutions Corporation for further details on these materials or the products contained therein For inquiries about the contents of this document or product fill in the text file the installer generates in the following dire
153. and stores the result into the memory area denoted by the variable argument list For further information on the format control refer to the fscanf function description CC32R MANUAL 271 Chapter 9 C Standard Library strcat String handling function Links a string to the end of a string Syntax Return Value Description include lt string h gt char strceat char si const char s2 sl pointer to string S2 pointer to string to be appended to si The pointer s1 after linking The strcat function links the string s2 to the end of the string s1 The last NULL character of string s1 is replaced with the first character of s2 string A NULL character is always added to the end of the linked s2 string The strncat function can specify the number of characters to be linked to by using the parameter n CC32R MANUAL 272 Chapter 9 C Standard Library st rc h r String handling function Locates in a string the position where a character first appears Syntax include lt string h gt char strchr const char s int c S pointer to string used to search Cj character to be searched Return Value Pointer to the first searched character Character is found NULL Character is not found Description The strchr function returns the pointer to where the character c first appears in the string s st rc m p String handling function Compares two s
154. any existing file is opened in the writing mode the beginning of the file is overwritten and the former record is erased If any file is opened in the appending mode writing is performed from the end of the file If any file is opened in the updating mode I O processing is available for the file However input processing cannot be continued without executing the fflush fseek or rewind function after output processing Moreover the output processing cannot be continued without executing these functions after the input processing CC32R MANUAL 198 Chapter 9 C Standard Library fprintf input output function Outputs data to a stream according to the format Syntax Return Value Description include lt stdio h gt int fprintf FILE fp const char control fo pointer to FILE structure control pointer to format string S variable argument list output data The number of output characters Successful Negative value Error The fprintf function converts and edits the output data specified by the variable argument list according to the format control and then outputs them to the I O stream specified by the pointer fp Details of the format are Ditto for formats handled in the printf sprintf vfprintf vprintf and vsprintf functions lt Contents of the Format gt A format is character string pointed to by control which can contain two kinds of charact
155. aracters to the string Compares specified number of characters of two strings Copies the specified number of characters from the string to memory Locates the position where one of the specified characters first appears in a string Locates the position where a character last appears in a string Computes the length of initial segment of a string which consists of specified characters Finds the first occurrence point of a string within another Separates a string into tokens Converts the string based on the current locale Initialize struct lconv Sets and searches locale information Converts data and time a struct tm into the equivalent text string Gets the elapsed processor time Converts the calendar time a time_t value into the equivalent text string Computes the difference between the two specified times Converts calendar time to Coordinated Universal Time UTC Converts current calendar time to the local time Converts date and time a struct tm to the calendar time Converts date and time a struct tm to the format specified Reads the current calendar time Appendix B 7 Appendix B The C Standard Library Function List Signal handling function raise Send a signal to the executing program signal Sets up a signal handler that responds to the signal Termination function non ANSI _100_C_action_atexit Performs user registered terminations 100_C_get_exit_code Gets the exit status f
156. aran e 41 A 6 4 4 Cotrespondence Of the ASSSMDICH efesien oA ARa 42 A 6 4 5 Gorrespondence of the WelatiOM tOOIS sareren sansaara 42 A 6 4 6 Preprocessor ouput P E OPON sraa wichdaeaca Aedasatbantonays cevends 42 A 6 4 7 FROSHRICTIONEONUON UNCOJ E sasiore 42 A 6 5 The supplement of Japanese processing ccceseceecseeceeseeceeeseeeeeeeeeenseneeeesoees 43 A 6 5 1 Inside expression of the Japanese character cssccsccccssessseseseesseessensecessees 43 A 6 5 2 S GH VINO ANY gt ascot dept eg se aaa R ade 44 Appendix B The C Standard Library Function List E Program diagnostic fUNCtHOMN srainsett ia iene 1 E Character handling fUNCtiON cecceeceecesceeceeceececeeeeaececeeaeceeecaeeseesaeeeaesaeeeaesarseseeeeesaeeaees 1 E Mathematics UNCION s2 seccccerersbss tec s2stestedee sszzeattucurins lect oceadtalteaarsaseneehinaseeessbeassaeetanstagesscadie 2 E Non locall jump fUNCtiOn isien anenee rare eea ren aaae EA rE Eare OaE EEr 3 E Variable arguments access function cc ccecceeceeceeeeeeceeeeeeeeeeeeeaeceeeeaeseeesaeeesetaeeeaeeaeenaees 3 E Input Output FUNCTION siessen sson esnie eie ineeie ri araia arisi 3 E General Utility UnC Osseo E anera e EEIE 5 W Sining handing TUM CHO tas sxisetsccaaceecases sacse n Eaa aae 6 E Localization f nNCtUON eieae err ea ed a aAa cick eres Ee E Date and time TUNCtiON siesiiesstesceteieaceheddinaaten inten Aiden dannii 7 E Signalhandling UnetiO Mesedea e aa cc EE EE eA EE iS 8
157. are registered trademarks of Adobe Systems Incorporated Netscape and Netscape Navigator are registered trademarks of Netscape Communications Corporation in the U S and other countries All other brand and product names are trademarks registered trademarks or service marks of their respective holders Keep safety first in your circuit designs Renesas Technology Corporation and Renesas Solutions Corporation put the maximum effort into making semiconductor products better and more reliable but there is always the possibility that trouble may occur with them Trouble with semiconductors may lead to personal injury fire or property damage Remember to give due consideration to safety when making your circuit designs with appropriate measures such as i placement of substitutive auxiliary circuits ii use of nonflammable material or iii prevention against any malfunction or mishap Notes regarding these materials These materials are intended as a reference to assist our customers in the selection of the Renesas Technology product best suited to the customer s application they do not convey any license under any intellectual property rights or any other rights belonging to Renesas Technology Corporation Renesas Solutions Corporation or a third party Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage or infringement of any third party s rights originating in the use of any produ
158. aries by function group Program diagnostic function assert Adds a diagnostic function to a program Character handling function isalnum Judges whether a letter or decimal number isalpha Judges whether a letter or not iscntrl Judges whether a control character or not isdigit Judges whether a decimal number or not isgraph Judges whether a printable character other than a space islower Judges whether a lower case letter or not isprint Judges whether a printable character including a space ispunct Judges whether a special character or not isspace Judges whether a space or not isupper Judges whether an upper case letter or not isxdigit Judges whether a hexadecimal number or not tolower Converts an upper case letter into lower case toupper Converts a lower case letter into upper case Appendix B 1 Appendix B The C Standard Library Function List Mathematics function acos asin atan atan2 ceil cos cosh exp fabs floor fmod frexp ldexp log log10 modf pow sin sinh sqrt tan tanh Obtains the arc cosine of a floating point number Obtains the arc sine of a floating point number Obtains the arc tangent of a floating point number Divides a floating point number by a floating point number and obtains the arc tangent of the result Computes the integer ceiling of a floating point number Obtains the cosine of radians of a floating point number Obtains hyperbolic cosine of a float
159. as blanks 2 Successive blanks at the beginning of a line are ignored This also applies to blanks before a semicolon e Duplicate specifications The following cannot be duplicated Identical base register names Identical variable names Wildcard specifications Appendix A 10 Appendix A Extended Functions Reference A 1 8 Example of Using Base Register Function This section describes how to use the base register function A 1 8 1 Example Use of Base Register Function As shown in the figure below there are three 64KB data areas Explain the basic procedure 1 to 5 below for allocating a base register to each of these data areas e In the example base registers R13 R12 and R11 are allocated respectively to data areas 1 2 and 3 e Additionally data area 1 accommodates global variables var1 var2 and var3 data area 2 accommodates global variables var4 and var5 and data area 3 accommodates global variable var6 00F70000 re variables varl var2 var3 OOF7FFFF 00F80000 data area 2 variables var4 var5 OOF8FFFF 00FC0000 data area 3 variables var6 OOFCFFFF Appendix A 11 1 Appendix A Extended Functions Reference Determining the base address The base address is a fixed address set in the base register Because of the M32R register relative indirect specifications the base registers can cover the following range Base address 0x8000 to base address 0
160. ase of strtol ULONG64 strtoul64 const char s U String gt Integer 64 bit version char endptr int base of strtoul Method for using the functions and example usage To use the functions create a program as described below 1 Include long64 h 2 Define the variable in which to store a value with either LONG64 or ULONG64 3 From Table 8 select the function corresponding to the relevant type for the necessary operation and call it in your program 4 Hold the return value in a variable of type LONG64 or ULONG64 The set of 64 bit integer arithmetic functions are included in the C standard library e g m32RcR lib that is included with your software Link the C stand ard library in the same way as when using the conventional C standard library functions The following shows a function as a programming example that performs a b c 10 gt gt 33 with signed 64 bits and returns the result after being converted to long type include lt long64 h gt LONG64 a b G long func void LONG64 sl s2 s3 long k sl long_to_164 10L sl LONG64 10L s2 subl64 c s1 s2 c sl s3 mull164 b s2 s3 b s2 a shrtl64 s3 33 a s3 gt gt 33 k 164_to_long a k long a return k CC32R MANUAL 363 Chapter 13 A set of 64 bit integer arithmetic functions 13 4 Notes 13 4 1 Precautions regarding the sign In the 64 bi
161. ata or of indeterminately valued objects for which this International Standard imposes no requirements e Implementation defined behavior Behavior for a correct program construct and correct data that depends on the characteristics of the implementation and that each implementation shall document e Locale specific behavior Behavior that depends on local conventions of nationality culture and language that each implementation shall document CC32R MANUAL 306 Chapter 10 The cc32R s Behavior 10 1 Undefined Behavior The operation dealt with as undefined behavior in ANSI C is not guaranteed in the C C compiler In most cases the result may be ignoring the issuance of a diagnostic message or occurrence of run time error Thus it is recommend ed to write a program that is free from undefined behavior Here follow operations corresponding to undefined behavior that may be probable not guaranteed in the C C compiler cc32R The number and the heading subsequent to e ANSI C are the section number and the section heading of the corresponding ANSI C ANSI ISO 9899 1990 e ANSI C 5 1 1 2 Translation Phases End of source file If no new line character is present at the end of source file a new line character is automatically added the last line of a file need not to end with a new line character If the source file ends with a new line character preceded by a backslash the backslash and t
162. ated ifdef conditional Filename Line number Message type Message lt command line gt error macro name missing after D option Message type Message a c line 9 warning main function has no return statement File name Line number Message type Message CC32R MANUAL 365 Chapter 14 Messages from the C Compiler 14 1 2 Message Types Messages are classified into three types depending on their severity as shown in Table 14 1 Table 14 1 Message Type Message Type When an Error Occurs Information Outputs an information message and continues processing Warning Outputs a warning message and continues processing Command line error Outputs an error message which corresponds to the command line and stops processing Error Outputs an error message and stops processing Fatal error Outputs an error message and stops processing For details of messages see 14 2 Message Lists 14 1 3 Exit Status Upon completion of the execution the C compiler returns the exit status value showing the execution result as shown in Table 14 2 Table 14 2 Exit Status Exit Status Result 0 Complete successfully or warning occurs 1 Error occurs CC32R MANUAL 366 Chapter 14 Messages from the C Compiler KA Message Lists Tables 14 2 to 14 7 show messages of the C compiler alphabetically xxx in the messages means arbitrary input information an input file
163. ax Return Value Description Caution include lt signal h gt void signal int sig void func int int SLO signal number func The handler to be executed upon detecting the signal The latest func value Successful SIG_ERR Error returns corresponding value to errno The signal function calls the process handler denoted by func when the signal specified by sig is detected func specifies the following two special macros in addition to the user defined ones e SIG_DFL Executes the default signal process e SIG_IGN Ignores signals To call the signal function in actual the user written signal function is required see Section 11 1 and Table 11 2 CC32R MANUAL 267 Chapter 9 C Standard Library Ss i n Mathematics function Obtains the sine of the radians of a floating point number Syntax include lt math h gt double sin double x X floating point number in radians Return Value Calculated argument value Description The sin function calculates sine of x Si n h Mathematics function Obtains hyperbolic sine of a floating point number Syntax include lt math h gt double sinh double x X floating point number Return Value Calculated argument value Description The sinh function calculates the hyperbolic sine of x If the calculation result cannot be expressed in double type value the function sets the ERANGE value in the errno
164. ber of file being compiled __FILE__ The name of the file being compiled __STDC__ 1 when ANSI compatible __DATE__ Current compiling date __TIME__ Current compiling time __M32R__ The target microprocessor is M32R __cplusplus Compiles a program written in C language with a C compiler c_plusplus Same as the reserved macro _cplusplus __embedded_cplusplus Compiles as Embedded C Only when the option ecpp is specified _EXCEPTIONS Defined when the option exception is specified CC32R MANUAL 71 Chapter 4 C Programming Language Specification The operators shown in Figure 4 7 can be used in a constant expression amp sizeof gt Figure 4 7 Operators that can be used in a constant expression CC32R MANUAL 72 Chapter 4 C Programming Language Specification 4 5 System Reserved Names The names in Figure 4 6 are reserved during development environment of the M32R and can be used in a C program Syntax _Number_Name Number 3 digit decimal number Name Character string consisting of alphanumerics and underscore s see 4 1 2 An underscore Example 900_main _900_INITLIB Figure 4 8 System reserved names Reserved names are classified into the three groups Of these names the names numbered 000 099 and 901 999 can be used in most programs The 3 groups are e System names reserved for operating systems 000 099 System names reserved for variable
165. bjects covered by A 1 2 2 Accessing Constant Addresses are within the duplicated areas the first base register with a base address defined is used to cover that area Appendix A 6 Appendix A Extended Functions Reference A 1 7 The Access Control File The Access Control File contains the following information which is required in order to use the base register function 1 Base address for 16 bit register relative indirect addressing 2 Register storing the base address 3 Objects to which the base register function is applied variables and structures This file is specified in the compiler option access access_control_file Note that the Access Control File can also be generated using the map32R map generator A 1 7 1 Contents of the Access Control File The Access Control File contains the following 1 Base address This item specifies the base address for the base register function register relative indirect addressing When using fixed address access read write of the area around the base address base address 0x8000 to base address 0x7FFF the code will be generated for register relative indirect addressing 2 Base register This item specifies the register storing the base address Any of R11 R12 and R13 can be allocated Registers assigned as base registers are not used within functions for other purposes such as temporary work areas 3 Target objects This item specifies the objects that ar
166. ble for the library that comes standard with the compiler Library name Command line specification m32RcR lib libg32R m32cR lib small Otime zdiv m32RcRM lib libg32R m32cRM lib medium Otim zdiv m32RcRL lib libg32R m32cRL lib large Otime zdiv CC32R MANUAL 173 Chapter 9 C Standard Library EE Library Function Descriptions Thisectiorlescribefhainctiondh tandardlbrarialphabetical ordedlowmefeeactiunctiomescriptionshowmFigur8 2 Return Value Description Caution J Not Function name Group Summary Syntax Shows a call type of function include lt header_file gt is a standard header file to use this function Be sure to include it Shows a return value of function A comment preceded by which is stated immediately after a return value explains the return value return conditions etc Explains the specifications of the function Shows something to be considered if any Figure 9 2 C Standard Library Function Reference Format Note The parenthesized non ANSI here means a function that is included in the C standard library and it however is not defined in ANSI C see Sections 7 3 6 7 3 7 and 7 3 8 CC32R MANUAL 174 Chapter 9 C Standard Library 1 00 C act i O n atex i t Termination function non ANSI Performs user registered terminations Syntax Return Value Description void_100_C_action_atexit void None The _1
167. bugging and evaluating purposes reserving enough stack area at initial stage or measuring stack area space with the debugger etc Provide the stack area needed for interrupts in the similar way 7 3 4 Initializing the Processor Modes Specify the stacks and interrupt levels for the target microprocessor register PSW setting For information on settings PSW configuration refer to the microprocessor manual 7 3 5 Initializing the Stack Pointer Set the highest address of the reserved stack area as the stack pointer 7 3 6 Initializing the Data Sections Embedded application requires the initial setting of the data area sections D and B Perform the following steps during application linking and running of the start up program e Tasks during linking of the embedded application e Allocate area of sections D and B on the RAM area no data output e Allocate initial value data of section D ROM_D on the ROM area CC32R MANUAL 131 Chapter 7 Embedded Applications Programming Illl Note IIll 100046 Initial data is not placed fF here RAM Only area S for data sections are RAM Area Allocated Initial data for the D ROM Area section is placed here ROM Figure 7 4 Allocation of Sections for data Allocation of the section area and data sampling during linking can be specified by the SEC or MEM option For the generated load module the labels indicating the start and end addresses respec
168. by following the format shown in Figure 3 1 Each of the items i e the command name an option an input file name must be separated from adjacent items by at least one space character By entering the return key at the end of a command line the C C compiler starts execution e Between an option and its parameter s one or more spaces may be inserted input_filenames represents the specification of one or more input file names Between input file names one or more spaces are needed for separation The number of files is not limited CC32R MANUAL 15 Chapter 3 Invoking the Compiler e The type of each input file is determined based on its extension as listed in Table 3 2 Table 3 2 Input File Name and Type Extension Type C C source file cpp C source file ms Assembly source file mo Object module file For C used exclusively to create load modules ml Object module file For C used exclusively to create libraries Others Object module file 3 1 4 Command file When invoking CC32R one or more command options listed in a command file a text file can be specified by one parameter cc32R file name lt RET gt where e file_name File name of Command file eh Optional e lt RET gt Enter the return key Figure 3 2 cc32R Command file Syntax e Asa parameter specify only a command file name prefixed by If anything other than one command_f
169. by timeptr as follows e Ignores tm_wday of the tm type structure and the original value upon reading of tm_yday e Contents of the tm structure of timeptr are updated according to the calendar time CC32R MANUAL 250 Chapter 9 C Standard Library m O d f Mathematics function Divides a floating point number into integer and fractional parts Syntax include lt math h gt double modf double x double Zz X floating point number FAS pointer to memory area which stores integral part Return Value Fractional part of x Description The modf function divides the value of x into fractional part and integral part and returns the fractional part It stores the integral part in the memory area specified by i pe rror Input output function Outputs the error message corresponding to the error code to the standard error file stderr Syntax include lt stdio h gt void perror const char s S pointer to error message Return Value None Description The perror function outputs the error message indicated by s and the corresponding errno to a standard error file stderr CC32R MANUAL 251 Chapter 9 C Standard Library p OW Mathematics function Obtains a floating point number to nth power Syntax include lt math h gt double pow double x double y xX Vj floating point number Return Value Value of x Successful HUGE_VAL Calculation
170. c32R as32R and Ink32R Strip32R is able to process both files of object module before the link and load module after the link cc32R c o samplel mo samplel c strip32R samplel mo as32R sample2 ms strip32R sample2 mo Ink32R o sample abs sample1 mo sample2 mo strip32R sample abs To process two or more files at a time For example after all the compiling and the assembling completed the strip32R can process all the files of them cc32R c sample1 c sample2 c sample3 c cc32R c sample4 c as32R c sample5 ms strip32R samplel mo sample2 mo sample3 mo sample4 mo sample5 mo Even the wild card can be designated strip32R mo Appendix C 1 Appendix C Restrictions on Usage E Cautions on using the base register function with standard library for C The supplement of attention on using the base register function Combinations of the object file as follows are not recommended For more details refer to the A 1 6 Base Register Function Limitations of the M3T CC32R User s Manual lt C Compiler gt 1 The combination of object files that was created in using base register function and in not using this function 2 The combination of object files that was created by using different access control files Attention to use the base register function and C standard library in same time Attached C standard library was created when the base register function is ineffec
171. ccccccsceeseneeeeeeeeeeeseeeeeteeeeeaaeeeeeeeeeeaeeeeaes 169 9 1 1 The Library Files Contained in CC32R ecceeeeeeseeeeeeeeeseeeeaeesneeteaeeeeaeeeaeeteas 169 912 Library FUNCION GlOUDS mesrine iaden ranere dtaa a ES E NENE 170 9 1 3 Consideration for using the Library ceeeeeeceeseeeeteneeeeeeeeaeeteaeeeaeeeeaeeeaeeeeaeeee 171 9 1 4 Library Error M SSaG6 iini scenascctcesstcaesicee case Ea rr E SAN NENS 171 Rebuild to Method of Standard DRA sssini oriniai nat ii andaka 172 9 2 1 Library Building ProCeQuie cszccccccccs evisee cateccties cevescancvuseneted teases vasthensasteededs cevtsaces 172 LI Drary FUMCHOMIDESCMDUOMS icc shidscace tetdieccetaisactectaidsnceeheaiwadediaaineeanicamttanids 174 Chapter 10 The cc32R s Behavior 10 1 10 2 10 3 Undeined IBGMNAVION siseeaxevetnn tected aispee state tea din dd a a aas 307 Implementation defined Behavior cccccceeccceeeeesecceeeeseeeeceeeeeneeeeeeesneeneeeeeenenees 323 WOE TWAS QUO Measann es evsveteaiysi ey ise ae athe d aceeetavecieentel 323 10 22 EMVIROMMOG Misi sscecnds ccsastetesiednccsdenceeesecesssiedesdedetahi edsansth cckeseendecacas sipeendacetasesi interes 323 10 2 3 Identifiers arneses en EE OE TE EESE 324 1024 Characters acs senses desceasecacncaascnaaceiaas boned pedeciec da eop ideri ten ERA ararsan i aieiai 324 1025 JNeEJerS ocorren ina a a a eee 326 102 6 Floating POIt resia na E a vhs a aS UNE aaa 327 10 2 7 Arrays and POmnters sorena a
172. cess of the called function Postcalling process Figure 6 3 Function Call and Return in C C 1 Setting arguments C C compilers generally use register passing to pass arguments when a function is called Note that type conversion and alignment rules apply to how the content of arguments is stored see 6 4 parameter register 1 1 Register passing The first four arguments are stored sequentially in registers R4 to R7 If the function takes fewer than four arguments the number of registers equivalent to the number of arguments is used For example only R4 and R5 are used in the case of two arguments Also if there are five or more arguments stack passing is applied to the fifth and subsequent arguments 1 2 Stack passing The following applies if the conditions in 6 4 2 The Cases where Stack passing is Valid are satisfied The arguments are pushed onto the stack and the argument area is set up The arguments are stacked in sequence from the last argument The first argument is set at the lowest address in the argument area as shown in Figure 6 4 CC32R MANUAL 103 Chapter 6 C C Calling Conventions TLower Address gt 1st Argument SP gt n th Argument n th Argument Higher SP JAdaress Figure 6 4 Argument Setting When a called function returns the structure or union type return value after the first argument is pushed the top address of t
173. ch section These features are useful when developing embedded application or writing the application program into ROM For further information refer to the CC32R User s Manual 3 The Others Chapter Linker Illl Note Options SEC and MEN cannot be specified simultaneously The MEM option does not support control of CTOR VTBL and COMMON sections Note Linking method varies with section attribute and linking order varies with the command options CC32R MANUAL 122 Chapter 7 Embedded Applications Programming In practice the linking order and start address of each section are determined by the conditions described in this section For function of options and use of options refer to Chapter 3 Invoking the Compiler e Section linking order When the linking order is specified the sections are linked in the order of priority levels Sections having no linking priority are linked following the lowest level section 1 When specified by the SEC or MEM When specified by the SEC option Sections are linked in the order SEC option is written When specified by the MEM option LOC in the case of linker e RAM area D B e ROM area P gt C gt D 2 Without order setting default Sections are linked in the order of the files specified written in the command line If a specified file contains two or more sections the are linked in the order they appear written e Start address Specified a
174. ch time a function is called The Figure 6 2 shows a typical stack frame areas 0 to 2 in the order from higher to lower address The argument area of area 0 is pushed to the stack only under the conditions described in 6 4 2 The Cases where Stack passing is Valid SP R15 gt TLower Register Save Address Area Local Variable Area Argument Area Higher JaAddress Figure 6 2 Typical Stack Frame 1 Argument area Case of the Stack passing arguments to be passed to the function called are set in this area Arguments are arranged so that the first argument is at the lowest address 2 Local variable area The area into which the local variable declared by the called function is to set 3 Register save area Used to save the current contents of the general register which will be used by the function called CC32R MANUAL 102 Chapter 6 C C Calling Conventions 6 3 Call and Return Procedures Calling and returning of a function by C C program are performed in the order given in Figure 6 3 Calling Program Caller Called Function Callee 1 Set arguments 2 Call Funct 3 Allocate local variable area all Function 4 Save registers execution of the function 8 Free argument area 5 Restore registers 6 Free local variable area 7 Return to the caller 1 2 Precalling process 4 Input process of the called function 5 7 Output pro
175. character it is the value of the rightmost characters in a string literal The wide character constatnt is processed in accordance with the M32RKOUT enviroment variable lt The current locale used to convert multibyte characters into corresponding wide characters codes for a wide character constant gt The euc sjis and utf8 locales are supported e ANSI C 6 2 1 1 Characters and integers lt Whether a plain char has the same range of values as signed char or unsigned char gt char behaves like signed char on the code CC32R generated Yet the CC32R processes char with regarding as different model from signed char when a interpreting CC32R MANUAL 325 Chapter 10 The cc32R s Behavior 10 2 5 Integers e ANSI C 6 1 2 5 Types lt The representations and sets of values of the various types of integers gt For internal representation and the limit values of various integer data see 5 2 Integral Types The C C compiler interprets int as equivalent to signed int short to signed short and long to signed long Yet the C C compiler interprets assuming that char and signed char differ when the grammar interpretation But the generated binary code executes as equivalent to char and signed char e ANSI C 6 2 1 2 Signed and unsigned integers lt The result of converting an integer to a shorter signed integer or the result of converting an unsigned integer to a signed integer of equal
176. cifying O7 as Olevel Skipping both this option and Olevel cannot start optimization Specifying only 0 is equal to specifying Opriority to Ot ime and Olevel to 07 lt Examples gt Otime Priority on speed optimization at 07 level Ospace 04 Priority on size optimization at 04 level Ospace 0O Priority on size optimization at 07 level O Priority on speed optimization at 07 level When using this option simultaneously with the debug option g the function of debugging receives an influence For more details refer to Section 3 2 3 CC32R MANUAL 27 Chapter 3 Invoking the Compiler Option Olevel Table 3 6 Command Options for the C Compiler 7 11 Description Specifies optimization level Do not separate the symbols O from the word level by a space character Set Olevel to one of the following values No optimization Optimization of assembly language Local optimization Global optimization BP MO FO Note that combination of values 1 2 and 4 achieves optimization at these levels Specifying this option without specifying Opriority is equal to specifying Ot ime as Opriority Skipping both this option and Opriority cannot start optimization Specifying only 0 is equal to specifying Opriority to Otime and Olevel to 07 lt Examples gt 01 Optimization at level 1 giving pri
177. clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen fprintf fputc fputs fread freopen fscanf fseek Clears an error condition in a stream Closes a file Checks if the end of a stream is reached Checks if a stream is in an error condition Outputs the contents of a stream to a file Gets a character from a stream Locates the current position on a stream Gets a string from an input stream Opens a file Outputs data to a stream according to the format Outputs a character to a stream Outputs a string to a stream Transfers data from a stream to a memory area Closes a currently opened stream and reopens a new file with the new file name Gets data from a stream and converts the data by following the format Moves the current read write position within a stream Appendix B 3 Appendix B The C Standard Library Function List fsetpos ftell fwrite getc getchar gets perror printf putc putchar puts remove rename rewind scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam ungetc vfprintf Changes the current position on a stream Locates the current read write position in a stream Transfers data from a memory area to a stream Gets one line from a stream Gets a character from the standard input file stdio Gets a string from the standard input file stdio Outputs the error message corresponding to the error code to the standard error file
178. column for the I option I path in Table 3 6 in 3 2 Startup Options of the C C Compiler lt The support of quoted names for includable source files gt In the include preprocess instruction you can specify a file name to include by means of enclosing it in a pair of quotation marks lt The mapping of source file character sequences gt The values of ASCII characters are respectively assigned to the characters in the source file e ANSI C 6 8 6 Pragma directive lt The behavior on each recognized pragma directive gt Unrecognized pragma directives are ignored e ANSI C 6 8 8 Predefined macro names lt The definitions for DATE __ and __TIME__ when respectively the date and time of translation are not available gt DATE__and _TIME_ are always available 10 2 14 Library Functions e ANSI C 7 1 6 Common definitions lt stddef h gt lt The null pointer constant to which the macro NULL expands gt NULL the null pointer is defined as void 0 CC32R MANUAL 330 Chapter 10 The cc32R s Behavior e ANSI C 7 2 Diagnostics lt assert h gt lt The diagnostic printed by and the termination behavior of the assert function gt The diagnostic message from assert is Assertion failed expression file file_name line line_number e ANSI C 7 3 1 Character testing functions lt The set of characters tested for by the isalnum isalpha iscntrl islower isprint and isupper functions g
179. cription errno Every time an error occurs while processing the errno library function the error code set for that library is set to the errno macro To check the error that occurred during processing of a library function set the errno to 0 before calling the library function and then check the code set into errno after the process NULL Indicates the value when the pointer is pointing to nothing Table 8 16 Data Types Declared by stddef h Data Type Description ptrdiff_t Indicates the type resulting from subtraction of two pointers size_t Indicates the type resulting from operation of the sizeof operator wchar_t Indicates the type of the wide character L CC32R MANUAL 161 Chapter 8 Standard Header Files 8 2 12 stdio h Performs the prototype declaration of the input and output functions and the definition of macro definition and data type declaration required for input and output functions The declared functions defined macros and data types are shown in Table 8 17 Table 8 18 and Table 8 19 respectively Table 8 17 Functions Declared by stdio h 1 2 Function Description Reentrant clearerr Clears an error condition in a stream x fclose Closes a file x feof Checks if the end of a stream is reached x ferror Checks if a stream is in an error condition x fflush Outputs the contents of a stream to a file x fgetc Gets a character from a stream x fgetpos Locates the
180. ct data diagrams charts programs algorithms or circuit application examples contained in these materials All information contained in these materials including product data diagrams charts programs and algorithms represents information on products at the time of publication of these materials and are subject to change by Renesas Technology Corporation and Renesas Solutions Corporation without notice due to product improvements or other reasons It is therefore recommended that customers contact Renesas Technology Corporation Renesas Solutions Corporation or an authorized Renesas Technology product distributor for the latest product information before purchasing a product listed herein The information described here may contain technical inaccuracies or typographical errors Renesas Technology Corporation and Renesas Solutions Corporation assume no responsibility for any damage liability or other loss rising from these inaccuracies or errors Please also pay attention to information published by Renesas Technology Corporation and Renesas Solutions Corporation by various means including the Renesas home page http www renesas com When using any or all of the information contained in these materials including product data diagrams charts programs and algorithms please be sure to evaluate all information as a total system before making a final decision on the applicability of the information and products Renesas Technology Corporation
181. cters first appears in a string Syntax Return Value Description include lt string h gt char strpbrk const char siZ const char s2 isi pointer to string in which the character is searched S2 pointer to string which consists of characters to be found Pointer to the character found The character is found NULL The character is not found The strpbrk function locates in the string s1 the position where one of characters in the string s2 first appears and returns the pointer to that position CC32R MANUAL 282 Chapter 9 C Standard Library strrchr String handling function Locates the position where a character last appears in a string Syntax Return Value Description include lt string h gt char strrchr const char ts int c Sj pointer to string in which the character is searched Ci the character to be searched for Pointer to the character found The character is found NULL The character is not found The strrchr function searches for the character c in the character string s and locates the location where the c last appears and returns the pointers of the position The null character indicating the end of the string s is included in the characters to be searched CC32R MANUAL 283 Chapter 9 C Standard Library st rs p n String handling function Computes the length of initial segment of a string which consists of specif
182. ction 1 Labels 2 Generic M32R instructions except NOP instruction 3 as32R pseudo instructions influencing the code areas as follows ALIGN DATA DATAB END FDATA FDATAB FRES RES SDATA SDATAB SECTION Appendix C 3 Appendix C Restrictions on Usage On indirect calling a function that has variable arguments The program will not run correctly if a function having a variable argument is called indirec tly by using a pointer variable to a function without prototype declaration Code Example include lt stdio h gt int funcptr printf int main void funcptr calling printf with Sd n 1 Solution Include a prototype declaration for the pointer variable to the function Rewrite the above code as follows include lt stdio h gt int funcptr const char printf int main void funcptr calling printf with Sd n 1 E Data definition within the code section The assembler outputs a warning warning caution there are some data in code section so as to alert you to data items or space areas present in the code section It is recommended to put data items in the data section You can suppress this warning by use of the option warn_suppress_code_data E Use of preprocessor variables inside a macro body If as in the following example a preprocessor variable appears starting in the first column of the line immediately after a macro
183. ction Idiv y Divides a long type integer and obtains the quotient and remainder Syntax include lt stdlib h gt ldiv_t ldiv long number long denom number dividend denom divisor Return Value Quotient and remainder of the calculation result Description The Idiv function calculates the quotient and the remainder as the result of dividing number by denom The return value is the Idiv_t structure and the quotient and the remainder are put in the quot and rem of the member respectively loca l econv Localization function Initialize struct lconv Syntax include lt locale h gt struct lconv localeconv void Return Value Pointer to initialized 1conv structure Description The localeconv function initializes the 1conv structure Caution As the locale only the C environment is supported In order to use the localeconv function user written _get_core or _rel_core function called by this function internally needs to be created CC32R MANUAL 238 Chapter 9 C Standard Library l oca l tT i me Date and time function Converts current calendar time to the local time Syntax include lt time h gt struct tm localtime const time_t timer timer time Return Value Converted result Pointer to the tm structure Description The localtime function converts a calendar time shown by timer to the local time and converts it into the tm type Caution As the locale
184. ctory and email to your local distributor SUPPORT Product name SUPPORT TXT Renesas Tools Homepage http www renesas com en tools Contents Contents Preface x PAUGIENICG aietecazish siisespivecneieaxeceeaean tans bpeaiarentreeeraptaccaeteatanialaeevietneeetcuvanens aseentaconnaga eens x FRORSIOINGCES zosnenis a aoaaa a N x CONVENIOS waina e r re ree eT xi Chapter 1 Overview of CC32R 1 del Peatlites OM GCI2 Reseno aai aceon E n E N aa ES 1 L2 Components O COB2 Rasanin E lad ee RNE 1 1 2 Components Of COS2R ass scceteciresster sets Aiasieeednetiiae eke eevee desiree 1 1 3 Overview of the Components Of CC32R ecccecesceeceteeeeeeeeeeneeeeesaeeeeeeeetsaeeeninees 2 4 Components of CCs2 Ranen enn Hoe ees 4 WAS Programming LOW cistiti sated euaueechaseegsnadeedeaye dad inde ieusetess bices sets etsuceni 4 1 4 2 Object Generation FlOW apeissonar nea ia par i E aN E EEE Ea Ea 5 143 HOWIK staen aea E S eSa 6 1 4 4 Library File Generation FlOW siseccsaccsstzcedhetaaceadsassat ssiaevaacasailesstangcacsdaaeusessdteasusaaicnte eee 7 1 5 Input and Output File Names for CC32R eccceeesceeeeeeeeeeeeeeeeeeeeeeeaeeeeneeeesaeeenenees 8 Chapter 2 Overview of cc32R 9 2 1 About the C C Compiler CC32R ceeeccceceeeceeeceeceteeeeeeeeeeeeeeeeaaeeeeeeeeeeeaaesteneees 9 Zell CCS FUNCIONS enian aA eE EI EAN AE OREA ra eii 9 Ql GC32R Features ea e S a N NE 9 22 Compatibility Witham old VerSiON snis iiun ei ai aE EEEE ANTES 13
185. d is packed into the memory space denoted by the type specifier A series of bit fields are packed into a unit memory space 1 2 or 4 bytes as long as they can go See Example 1 For example an int type structure consisting of 3 members of field width 4 12 bits is completely packed into a 4 byte location 32 bits Arrangement is from upper to lower bits A series of fields are placed in the order of declarations starting with the left side upper bit to the right lower bit of the memory location whose size is specified by the type specifier No field can exist across an alignment boundary No bit field is separated by an alignment boundary If not all bits of a field is accommodated in a location the field is shifted to the next location leaving unused bits in the preceding location This means that the data string is discontinued See Example 2 0 bit field is placed on the next location If the size of the next field is 0 bit the field is placed at the next location See Example 3 Different alignments for different type bit fields If a structure or union is composed of bit fields members of different types every time a field is placed the size of the type specifier of that bit field is recognized as the alignment of the memory location The size of the alignment of the structure and union is equal to the size of the type which has the largest size See Example 4 CC32R MANUAL 90 Chapter 5 Internal
186. d substract operation instruction This option is disregarded where no m32re5 option is valid Where this option is not specified the FMADD and FMSUB instructions are not used Where this option is used also refer to A 5 3 4 float_only The double type is regarded forcedly as the float type If this option is used together with the m32re5 option all floating point operations can be made applicable to the FPU instruction In utilizing this function be sure to refer to the contents given in A 5 3 1 lt CAUTIONS float only Option as well A 5 2 Utilize FPU Instruction Effectively The m32re5 option generates the FPU instruction for float type operation To exhibit M32R ECU 5 capacity to the maximum in floating point operation make arrangements so that as many floating point operations as possible are of a float type by using the following method Even if the m32re5 option is effective the run time routine is used as usual for the double type operation 1 Change the double type declaration to the float type one However even in the float type ensure that there is no problem in computing accuracy and effective range of floating point value 2 Specify the precision in the floating point constant Carry out precision designation f indicating the float type with the real arithmetic Appendix A 33 Appendix A Extended Functions Reference constant suffixed by f as shown below 1 234f The
187. dded Applications Programming 2 Write the start up program Write a start up program for the target system The start up program performs initialization to allow the application to run on the target system and generally performs the following processes Gets the stack area Initializes the processor mode Initializes the stack pointer Initializes data area sections Call the _cpp_main function Calla global constructor call _ctor of runtime library Call the _call_main function Calla global destructor call _dtor function of runtime library Co OND PF WN BR Call the main function For writing the start up program refer to 7 3 Tasks in the Start up Program 3 Write the low level library If the application performs the following tasks by using C standard libraries low level libraries should be prepared e Standard input and outputs e Memory management e Signal handling e Time management For information on the low level function s which is required by each C standard library function and on the specifications of the low level functions refer to Chapter 11 Low Level Library Programming by following these specifications use the librarian to make these programs libraries 4 Generate a load module Using the cc32R command prepare load module based on generated user program and start up program When linking files are referenced in the order specified by the command line and th
188. ddresses have priority Unspecified sections are assigned relative address according to the linking format Default alignment is 4 bytes any value can be specified by using the assembler pseudo directive SECTION The start address of a load module is 0 if not specified 1 When specified by the SEC or MEM When specified by the SEC option The address is specified for each section The start address of section having unspecified address is auto matically specified according to the linking order When specified by the MEM option LOC in the case of linker e Dsection The address specified for RAM area e P section The address specified for ROM area e B C D section The address immediately following the end address lower address of the preceding linked section CC32R MANUAL 123 Chapter 7 Embedded Applications Programming 2 When not specified default e Each section The address immediately following the end address lower address of the preceding linked section e Entire load module Address 0 7 1 2 Writing the CTOR Section The C frontend locates the function pointer to a global constructor in the CTOR section Therefore the CTOR section in which the function pointer to a global constructor will be stored needs to be written in a startup program Add the program statement shown below to the startup file section CTOR data align 4 The function pointers to global constructors will be stored here
189. de that might lead to a different operation result due to a side effect For example there can be chances in which p 5 of code xp p 5 is evaluated before or after p so that what is assigned p 5 turns indeterminate In this instance code a program in either way given below according to the purpose of process CC32R MANUAL 309 Chapter 10 The cc32R s Behavior p pts t p or ptl pt5 ptt Invalid operation domain error An invalid operation division by 0 for example results in an error A domain error an overflow an underflow or the like if results from an operation results in a warning A warning is given only when either domain error is detected during compilation In either case the operation based on the arithmetic operation is not guaranteed e ANSI C 6 3 2 2 Function calls If the argument to a function is a void expression Specifying a void expression other than null argument for an actual argument results in an error If a null argument void expression is specified and if one or more formal arguments are defined for the function called the value passed to the function is indeterminate Type incompatibility between argument and parameter If the function is defined in a position where the function is not visible in calling a function with no function prototype declaration and if the type of actual argument is not consistent with that of the formal argument after promotion a
190. dix A e Link register R14 The R14 stores the return address during function call It may also be used as work register or register variable register by the C C compiler CC32R MANUAL 100 Chapter 6 C C Calling Conventions e Stack pointer R15 The R15 is a stack pointer SP which stores the lowest address of the stack area The SP manages the stack 6 1 2 Register Consideration Table 6 1 shows whether the contents of register is retained or not when a function is called by the C C program Yes means that the register is saved and restored automatically by a called function and No shows that you must save and store the register when you call a function Table 6 1 Is State of the Register Assured Register s Consideration RO R3 No R4 R7 No For Function Argument R8 R10 Yes R11 R13 Yes For the Base Register R14 Link register No R15 SP Yes PSW CRO Yes CBR CR1 Yes Accumulator Yes Note 1 PSW CR0O Processor post status register An M32R control register in which conditional bit of stack mode interrupt Note 2 enable and operation result and saved value of them are set CBR CR1 Conditional bit register An M32R read only control register which stores the results of the preceding operation carry borrow overflow etc CC32R MANUAL 101 Chapter 6 C C Calling Conventions 6 2 Stack Frame Configuration The stack frame is an area allocated on the stack ea
191. e C Compiler Table 14 6 Error Messages 14 15 Message Description too many characters in a character constant The number of characters in a character constant is too many too many initializers The number of initializers is too many too many parameters for asm The number of arguments of the asm function is too many type cannot be inherited from a typedef This type cannot be taken over by typedef type incompatible with subsequent definition Type is not compatible with the later definition xxx type incompatible with subsequent definition The type is inconsistent with the next definition type of argument does not match with prototype The type of argument does not agree with that given in the function prototype declaration type of asm parameter must be integral The argument of the asm function must be integer type xxx type of initialized entity can not be function type The type of initialized components cannot be put into the function type type of struct member is an array of unknown length An array whose size is indefinite is declared on a structure s member type used for this symbol is incomplete or undefined This type of symbol is either incomplete or undefined unable to evaluate case label out of range The expression cannot be evaluated by case unbalanced endif Meaningless endif has been specified CC32R MANUAL 386 Chapter 14 Messages from the C
192. e a chance that the shift is correctly performed provided that the result can be expressed by the size that the type can afford e ANSI C 6 3 8 Relational operators macro replacement Even if a pointer to be compared by a relational operator lt lt gt gt points neither to the same aggregate nor union no error occurs but the operation is not assured e ANSI C 6 3 16 1 Simple assignment simple assignment If you assign an object to objects in an overlapping manner data in the overlapped part are not guaranteed e ANSI C 6 5 Declarations If an object declared without linkage is incomplete even after the declaration ends if the objects has an initial value or even after the initial declaration ends an error occurs e ANSI C 6 5 1 Storage Class Specifiers If a function is declared by use of a storage class specifier other than extern in a block scope the operation is not guaranteed e ANSI C 6 5 2 1 Structure and union specifiers Unnamed members If you define either a structure or a union made up of unnamed members only the operation is not guaranteed Type of bit field in structure Types valid for the declaration of a structure s bit field include char short int and long either signed or unsigned If you declare any type other than these the operation is not guaranteed CC32R MANUAL 312 Chapter 10 The cc32R s Behavior e ANSI C 6 5 3 Type qualifiers If you attempt to change an ob
193. e assembly feature is not output Functions defined under the in line assembly feature are not output Functions called under the in line assembly feature are not output No stack utilization display file is generated for the assembler function the source file written assembly language If the stack utilization display file for the assembler function is necessary make a text file separately For descriptions as to the stack utilization display file see the file stack size caluculation utility guide For information on functions and usage of the stack size caluculation utility stk32R see description in the file stack size caluculation utility guide zdiv For avoiding the integral zero division problem of M32R ECU series to generate assembly source with inserting NOP instructions each after the all of created DIV instructions Also it inserts NOP instructions as same in asm functions too In the case of inputting assembly sources to cc32R it performs same from assembling by as32R Invoking the tool with the option you can output messages which are output to the standard error by default to the standard output elf_endian big little Specifies whether the debug information in object files be handled as big endian or as little endian By default elf_endian big big endian is assumed CC32R MANUAL 32 Chapter 3 Invoking the Compiler 3 2 2 Notes about rel16 option to be taken w
194. e of scalar type controlling expression of switch statement must have integral type An expression within a switch statement must be of integer type xxx D option must be followed by an identifier Specify an identifier for the D option defined is followed by invalid macro name The macro name after defined is improper it must be an identifier xxx defined is followed by invalid macro name The macro name after defined is improper it must be an identifier dereference a pointer to void You cannot perform an indirect reference to a pointer toward void directive has unexpected non whitespace preceding newline An improper character is present in the line declaration division by zero A division by zero is contained division by zero in if constant expression An attempt has been made to perform division by 0 in an expression under if double quoted strings not allowed in if constant expression You cannot specify a character string enclosed in a pair of quotation marks in an expression under if CC32R MANUAL 375 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 4 15 Message Description duplicate case label in switch statement case is duplicated in a switch statement duplicate definition of enumeration constant A definition is duplicated in an enum constant empty constant expression in if An expression is missing from if en
195. e passed through stack even if register passing is specified e g structure type In sucha case refer to the stack frame CC32R MANUAL 109 Chapter 6 C C Calling Conventions 6 5 Setting Return Value The return value from the function is first converted into a value of the type suitable for return e Integer pointer The called side set the return value to RO The calling side refers to RO e Floating point number Structure union Same as for the structure and union types The calling side set the address of the return value setting area as the first argument see Figure 6 5 and Figure 6 6 The called side set the return value by using this address The calling side refers to the return value setting area SP R15 gt TL Register Save Address Area Local Variable Area 4 bytes Return Size of Higher Value Area Return LAdaress Value Argument Area Figure 6 6 Struct or Union Type Return Value Setting CC32R MANUAL 110 Chapter 6 C C Calling Conventions 6 6 Interface with Assembly Program When developing an application by linking more than two programs modules a program may refer to data of a different program or may call a function from another program This section describes how a C C program can refer to an assembly program and how the assembly program can refer to the C C program To call C C program function from a different C C program s
196. e program operates properly If a function having a variable argument list initialized by the va_start macro returns before the va_end macro is invoked no error occurs but the operation of program is not guaranteed e ANSI C 7 9 5 2 The fflush function fflush for an input stream is ignored no error returns e ANSI C 7 9 5 3 The fopen function If neither the fflush function nor file positioning function is invoked during a period from an input request to an output request for one stream the input output operation is not guaranteed Note 2 File positioning functions are fgetpos fseek fsetpos ftell and rewind CC32R MANUAL 318 Chapter 10 The cc32R s Behavior e ANSI C 7 9 6 Formatted input output functions printf like functions scanf like functions Though the type of function specifications doesn t agree with the corresponding number in the argument list or the number of actual arguments are less than the number of conversion specifications no error occurs but the operation is not guaranteed If the number of arguments is greater than specified by the conversion specifier the excess arguments are ignored The input output result for invalid conversion specifications in the printf like functions or the scanf like functions is indeterminate In most cases no error message is output If input output is different from what is expected check that the code for conversion spec
197. e same section name can be written only once in an access control file Examples varl lt Format 1 var2 samplw c func 4 Format 2 Format 3 D1 lt Format 4 A 1 7 3 Hints on describing the Access Conirol File e To specify static variables in a function Specifying variable name file name function name as the variable name makes static variables within that function the subject of the base register Example var2 sample c func This specifies variable var2 in function func in source file sample c This does not apply to var2 not belonging to the specified function e To specify all variables together You can specify the wildcard for the variable name to include all variables not otherwise specified that are allocated to the data area sections D and B Example The following example shows the lines from the Access Control File that assigns base register R13 to global variable varl and base register R12 to all other variables in the data area D and B sections Example R13 0x00F78000 varl R12 0x00F88000 e Comments 1 Lines starting with the semicolon are processed as comments 2 If a blank is encountered after the name of a variable the rest of that line is processed as a comment Note however that the bar cannot be included in comments Appendix A 9 Appendix A Extended Functions Reference e Blanks 1 Tabs are processed
198. e sections are linked in that order When writing the input files into the command line be sure to specify the start up program in the beginning Also specify options for linking as follows CC32R MANUAL 127 Chapter 7 Embedded Applications Programming e land L Specify linking of low level library and C standard library 2 Specifies the start up address of the start up program as the entry point e SEC or MEM Specifies the order and address of the section allocation With an embedded application in general allocate the D and B sections onto the RAM area D section initialization data and the P and C sections onto the ROM area To allocate the data used to initialize the D section onto the ROM area use linker s Initial value data sampling function the section is named ROM_D If the execution of a cc32R command results in a compile error correct the source file When all error causes are removed the linker automatically starts and the load module is generated according to linking specified by the command option s The following example shows the commands specified in the cc32R command line is a prompt Example cc32R 1 m32RcR 1lib e startup SEC D 1000 B SPI SPU P 8000 C D start ms cpp_main cpp call_main c userl c user2 c This example assumes the following input files start ms cpp_main cpp call_main c A start up program initial setting process corresponding to the target system
199. e startup program or in a user program be sure to specify an address that is ona 4 byte boundary See the sample startup program in the 7 3 Programming the Start up Program If you specify an address that is not on a 4 byte boundary an address exception AE may occur when the program is run e Calling the floating point operation function If you compile a program written in C language that performs a floating point operation there can be instances in which a code is internally generated that calls the floating point operation function _100_F The floating point operation function is included in the library files m32RcR lib etc With the code for calling the floating point operation function generated an error results if you don t specify the library files in performing linker For this reason specify the library files in performing linker even for a program that doesn t use the C s standard library functions e The problem that a module name that starts with a numeric turns to ASM32R_MPRO Don t generate an object file whose name starts with a numeric If you generate an object file whose name starts with a numeric the module name becomes ASM32R_ MPRO and module names duplicate when generating a library as a result library files cannot be generated Also the module name within a map file generated by use of map32R becomes ASM32R_MPRO Example 1 cc32R o 1234 mo file c 2 as32R o 1234 mo file ms CC32R MA
200. e this option to enter the original section name P C D or B to old and the new section name to new rtti on off Specifies to enable disable the runtime type information in C If rttizon is specified dynamic_cast and typeid are enabled If rtti off is specified dynamic_cast and typeid are disabled If this option is omitted rtti off is assumed by default S upper case Only compiles the sources to generate an assembly language source file extension ms No object files are generated CC32R MANUAL 29 Chapter 3 Invoking the Compiler Table 3 6 Command Options for the C Compiler 9 11 Option strict_standard Description Outputs a warning when extended functions are used for the standard C specification If this option is specified exception and rttizon become effective SEC name SEC name addr SEC name addr name add Specifies the linking order of sections and the start address Enter the section name into name and the address of the location for the section into addr Next to the specify the start address in hexadecimal Affix 0 zero to the first letter of the hexadecimal if the hex number starts with an alphabetic character If the start address is not specified a section is immediately followed by the next section If the symbol is affixed to the beginning of the section name the memory reserve information for that section is output with
201. e to be targeted by the base register function 16 bit register relative indirect addressing The addresses to which objects variables structures arrays etc are mapped are not decided at the time of compiling so each object must be registered in the Access Control File including pragma ADDRESS For details of the map32R map generator see Part 3 Map Generator map32R in the M3T CC32R User s Manual lt Assembler gt Appendix A 7 Appendix A Extended Functions Reference A 1 7 2 The Access Control File Syntax The Access Control File is written with each item on a new line 1 Comment line Code format Format 1 Comment Format 2 Blank line Functions The comment line is ignored Example This is comment 1 lt Comment in format 1 Comment in format 2 blank line jThis is comment 2 lt lt Comment in format 1 2 Base register definition line Code format base register name base address Functions Defines the base address and the registers allocated as base registers a Base registers e The same register cannot be specified two or more times as a base register b Base address e Omissible If omitted accessing fixed addresses is not available Specify the hexadecimal value in 8 or fewer digits preceded by Ox e Base address Oxffffffff is reserved and cannot be specified Example R13 OxF78000 R12
202. ead write position within a stream Syntax include lt stdio h gt int fseek FILE fp long offset int type Lp pointer to File structure offset offset from the location specified by type type offset type Return Value 0 Successful non 0 Error Description The fseek function moves a read write position of the stream specified by the file pointer fp from a place specified by the offset type type to a position of offset byte Types of offset are shown as follows type Meaning offset SEEK SET Beginning of file 0 a positive value SEEK CUR Current read write position A negative value 0 a positive value SEEK END _ End of file 0 a negative value For a text file type must be SEEK_SET and offset must be 0 or any value returned by the ftell function for the file The ungetc function is disabled by calling the fseek function CC32R MANUAL 218 Chapter 9 C Standard Library fset p O S input output function Changes the current position on a stream Syntax include lt stdio h gt int fsetpos FILE stream const fpos_t pos stream pointer to File structure POs a position on the stream to be modified Return Value 0 Successful non 0 Error Returns an error number to errno Description The fsetpos function moves the position on the stream specified by stream to a place designated by memory location specified by pos pos specifies a value
203. eas specified by arguments in the variable argument list In this example 2 arguments are required Details of the format are shown below Ditto for formats handled in the scanf and sscanf functions lt Contents of the Format gt A format is character string pointed to by control which can contain two kinds of character sequences such as plain characters and conversion specification The number of and the appearance order of conversion specifications correspond to them of arguments in the variable argument list which are pointers to the areas in which the separated input items store CC32R MANUAL 213 Chapter 9 C Standard Library e Plain characters Characters in a sequence beginning with non i e other than a conversion specification but White spaces They can be input if there are the characters matched up to them in the input item text in a file when the fscanf function If there are characters unmatched up to them the unmatched characters are remained in the input stream e Conversion specification A character sequence beginning with It specifies how to convert the input data It consists of and following specifiers shown below They are optional a4 e Field width e Size specifier for the corresponding argument e Conversion specifier lt Conversion Specification Syntax gt A conversion specification can be specified by the following format a specifier in is optional
204. ecified at the same time noexception Disables the exception handling facility The C exception handling facility try catch throw is disabled The C C compiler by default assumes that the noexception option is specified float_only he double type is regarded forcedly as the float type If this option is used together with the m32re5 option all floating point operations can be made applicable to the FPU instruction For more details refer to Chapter A 5 fminst A code is generated using FMADD Floating point multiply and add operation instruction and FMSUB Floating point multiply and substract operation instruction This option is disregarded where no m32re5 option is valid Where this option is not specified the FMADD and FMSUB instructions are not used For more details refer to Chapter A 5 CC32R MANUAL 23 Chapter 3 Invoking the Compiler Table 3 6 Command Options for the C Compiler 3 11 Option 8 Description Outputs the information debug information as necessary for debugging to the object module file or the load module file This option had been always designated This option is always enabled I path Adds a path to the directory under which a header file is to be searched The header file search is performed in the order shown 1 Within the directory under which source file is stored 2 Within the directory specified by this option 3 Directory
205. ective e ANSI C 6 8 3 2 The operator character string formation If string formation based on the operator for preprocess doesn t result in a valid string constant the operation is not guaranteed There can be a chance that an error occurs during expansion e ANSI C 6 8 3 3 The operator token coupling If coupling tokens with the operator for preprocess doesn t turn to a valid preprocess token the operation is not guaranteed For example func 1 if expanded turns to func1 but if funcl is a meaningless token then there can be a chance that an warning is issued during compilation or that an error occurs during linking CC32R MANUAL 314 Chapter 10 The cc32R s Behavior e ANSI C 6 8 4 Line control If the syntax of the preprocessing directive for line after expansion is incorrect an error occurs In this instance the line information is not updated e ANSI C 6 8 8 Predefined macro names LINE__ __FILE _ __ DATE _ __TIME__ and__STDC are macros already defined Defining them or canceling their definition by use of either define or undef causes an error e ANSI C 7 Library If you attempt to copy an object to objects in an overlapping manner by use of a library function other than memmove data in the overlapped part are not guaranteed e ANSI C 7 1 2 Standard headers Including standard headers inside an external definition As for function declaration object declaration type definition
206. ed Functions Reference LA Memory Models A 2 1 About Memory Models This compiler has four memory models available helping to develop your application programs efficiently Memory models refer to several assumed patters for applications to be stored in address space provided to ensure that optimum objects will be generated according to the size and position of address space in which code sections P C and data sections D B are stored when compiling This helps to generate the most suitable object for the size of each application developed The four memory models available for this compiler are shown below Memory model name Address space usable C standard library for code and data Small model Code 0x00000000 to OxOOFFFFFF m32RcRlib Data 0x00000000 to 0x0OFFFFFF Small model Code 0x00000000 to OxO0OFFFFFF m32RcRM lib with memlarge attached Data 0x00000000 to 0xFFFFFFFF Entire 32 bit memory space Medium model Code Given address A to A Ox00FFFFFF m32RcRM lib Data 0x00000000 to OxFFFFFFFF Entire 32 bit memory space Large model Code 0x00000000 to OxFFFFFFFF m32RcRL lib Data Entire 32 bit memory space 0x00000000 to OxFFFFFFFF Entire 32 bit memory space When using C standard libraries be sure to use the library file that corresponds to each memory model A 2 2 Detailes of Memory Models Each memory model is detailed below e Small model The small model is a memory m
207. ed as enum is assumed as int e Conversion of type bool Type bool and type int are converted to each other depending on the situation type bool type int true gt 1 true gt 0 excluding fales lt gt 0 CC32R MANUAL 67 Chapter 4 C Programming Language Specification e Conversion of characters and integers If an int can be represented all values of the original type the value is converted to an int Otherwise it is converted to an un signed int This implicit conversions termed integral promo tion e Conversion of signed unsigned integers Results of conversions from a signed integral type to an unsigned integral type or vice versa are as shown in Table 4 15 Original Positive signed integer Table 4 15 Signed unsigned integers Conversions New Type after conversion Unsigned integer has equal or greater size Value after Conversion Unchanged Negative signed integer Unsigned integer has The original value equal size the maximum value for unsigned type 1 Unsigned integer has First the original value is promoted greater size to the signed integer corresponding to the unsigned integer Then the value is converted to unsigned by the result in promotion the maximum value for the unsigned integer type 1 Unsigned integer Signed integer has The low bits in the original value will be equal size copied to the
208. ed hereby under any patents copyrights or other intellectual property rights of Renesas Electronics or others You should not alter modify copy or otherwise misappropriate any Renesas Electronics product whether in whole or in part Descriptions of circuits software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples You are fully responsible for the incorporation of these circuits software and information in the design of your equipment Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits software or information When exporting the products or technology described in this document you should comply with the applicable export control laws and regulations and follow the procedures required by such laws and regulations You should not use Renesas Electronics products or the technology described in this document for any purpose relating to military applications or use by the military including but not limited to the development of weapons of mass destruction Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture use or sale is prohibited under any applicable domestic or foreign laws or regulations Renesas Electronics has used reasonable care in preparing the information included in this document but
209. ed in a string literal vu An a b f n r t v Figure 4 3 Escape Sequence String Literal To express a hexadecimal number use the prefix x to express an octal number use An operator performs an operation Figure 4 4 shows the operators that are available Operators in C C language amp i sizeof 5 lt lt gt gt lt gt lt gt amp E amp I vA lt lt gt gt Operators in C language only a gt typeid dybamic_cast static_cast reinterpret_cast const_cast new delete delete throw and and_eq biand bitor compl not not_eq or or_eq xor xor_eq Figure 4 4 Operators and J and and are used as a pair an expression may be sandwiched between them Table 4 10 describes the operators and their functions CC32R MANUAL 51 Chapter 4 C Programming Language Specification Table 4 0 Operators 1 4 Operator Usage and Note Description class_name member scope resolution C language only namespace_name member scope resolution C language only mame global C language only protected_member global C language only pointer expr array reference expr expr_list constructor expr expr_list function call object member structure union reference gt pointer gt member structure union pointe
210. ed to generate the definitions of template functions or those of inline functions that cannot be put into in line only one instance for all objects The prelinker is incorporated into the C C compiler cc32R It is executed internally in cc32R as necessary exzample a cpp b cpp template lt class T gt template lt class T gt void func T a Tb a void func T a Tb a void afunc void void bfunc void int a int a func a func a In cases where the above a cpp and b cpp have the same template function defined with a call to the template function made in each it is possible to generate the definition of the func template function only one instance in all objects e Assembler as32R The as32R generates an object module by assembling an assembly source file In an assembly source file you can write the pseudo instructions and the macro instructions Also the assembler outputs an assemble list with the l option CC32R MANUAL 2 Chapter 1 Overview of CC32R e Linker Ink32R The Ink32R generates a load module file by linking an object module the relocatable load module files and library files It is selectable that either a generated load module is relocatable format or absolute format A relocatable load module can be reloaded onto the linker When linking do not start the linker Ink32R directly Always be sure to use the compile driver cc32R to link Example cc32R mo To
211. ee 6 3 Call and Return Procedure For data reference see 6 4 Parameter Passing To reference C C program data from an assembly program or to call a C C program function from an assembly program it is necessary to write a program by following the C C calling rule 6 6 1 Referencing Assembly Data from a C C Program To reference assembly data from a C C program write programs by following the example described in Figure 6 7 C C program Assembly program extern int i j EXPORT _i j SECTION D DATA ALIGN 4 void func _i DATA W 1 _j DATA W 1 i 4 END Figure 6 7 Referencing Assembly Program Data e Inanassembly program Declare the C C program data to be referenced in a pseudo instruction EXPORT or GLOBAL to enable external reference In the example in Figure 6 7 declare labels _i and _j in EXPORT e Inan C C program Specify the assembly program data to be referenced by using an external declaration When declaring use a corresponding assembly program label name but remove the underscore _ from the name CC32R MANUAL 111 Chapter 6 C C Calling Conventions 6 6 2 Referencing a C C Program from Assembly Data To reference C C data from an assembly program write an assembly program by following the example in Figure 6 8 C C program Assembly program GLOBAL _a char a b GLOBAL _b SECTION P CODE A
212. eeeeneeeeas 119 120 Chapter 7 Embedded Applications Programming 7 1 7 2 7 3 7 4 7 5 Compiler Generated Sections siccciesvninitiienidia estes lncieeicaielies 120 TAA Regarding the Section Configuration wc cc sccssc ccc case cdevceetntesivechedicccssisyabevetevies 120 Gill NWritimosthe CTOR SEGUON orpoen aeaa pe i nnn Anana E ae a e Et 124 FAS Writing the VTBL SOC ssri sisan andas a N E E E RE 124 7 1 4 Regarding the COMMON Section 200 0 cece eeceesceeeeeeneeteeeeeseeseaeeeaeeseaeeseeseaeeeaeees 125 Embedded Application Programming Procedure ssesssseesssrrssseerreesssnrnnseennneennna 126 Programming the Start Up Prograf soisissa s 130 7 3 1 Composition of the Startup Program 0 eecceeceeseeseeeeseeteeeeeeeteaeeeeeseaeeteeenaeetae 130 73 2 Tasksiin the Start up Program iivisc ste iee nre i 130 Toar Getting testak Ale durcie ai e 131 79 4 Initializing the Processor Modes svtecsesei eeicevekttectietes prertsctddietid ei ieeseeienieete 1311 Foro IMnitializing thie Stack POMC iinne ena n aE aa i are Eiern E 131 7 0 Anitializing the Data Section Sirisiri inasnan a aae kia T81 7 3 7 Calllthe Gpp Maim FUMCUOM wis cc2ieccetscteascnaiccisanacseendsceesaccadezeaienassseatea snnesstassacp ena 133 7 3 8 Processing the Cpp Main FUNCHON s c c ciseeccieeetcceeceted scene ntteeteceeeeeeate eatin ca 133 7 3 9 Processing the Call Main Function c cccccsccecssseceeseeeeeneeeeseeeesseeeessaeeeesaees 133 7 3
213. egisters by use of the register storage class specifier gt The register storage class specifier is ignored 10 2 9 Structures Unions Enumerations and Bit fields e ANSI C 6 3 2 3 Structure and union members lt A member of a union object is accessed using a member of a different type gt The bit pattern stored in the member of union is accessed and the value is interpreted according to the type of the member accessed e ANSI C 6 5 2 1 Structure and union specifiers lt The padding and alignment of members of structures This should present no problem unless binary data written by one implementation are read by another gt Details of padding and alignment of bit field see 5 9 Bit Fields lt Whether a plain int bit field is treated as a signed int bit field or as an unsigned int bit field gt A normal bit field of int type is dealt with as a bit field of signed int type lt The order of allocation of bit fields within a unit gt Bit fields are allocated from high order to low order in storage lt Whether a bit field can straddle a storage unit boundary gt A bit field is not allocated across an alignment boundary CC32R MANUAL 328 Chapter 10 The cc32R s Behavior e ANSI C 6 5 2 2 Enumeration specifiers lt The integer type chosen to represent the values of an enumeration type gt An enumeration type is treated as a int 10 2 10 Qualifiers e ANSI C 6 5 3 Type qualifiers lt What constitut
214. embers are open to the outside and can be accessed from any external function Internal Representation of Class Type 5 10 1 1 Alignment Number The alignment number of class type is always 4 when virtual functions are involved or otherwise the maximum value among the alignment numbers of data members CC32R MANUAL 94 Chapter 5 Internal Data Representation 5 10 1 2 Class Type Data Allocation e Classes that are having no base class or virtual functions These data members are allocated according to the allocation rules of structure data Coding class A char data1 int data2 public AQ char getData1 return data1 y Internal Representation obj data1 obj data2 e A class that is derived from a base class of 1 byte alignment and the start member of the derived class is 1 byte data These data members are allocated without unused areas Coding class A char data1 I class B public A char data2 short data3 obj Internal Representation obj datal obj data2 obj data3 CC32R MANUAL 95 Chapter 5 Internal Data Representation e A class that is having a virtual base class A pointer to the virtual base class is allocated Coding class A short data1 y class B virtual protected A char data2 obj Internal Representation obj data2 Pointer to the virtual base class generated by the compiler obj data1 i
215. entation of the time of a day in 24 hour system integer 00 through 23 Yol Representation of the time of a day in 12 hour system integer 01 through 12 oj The number of days starting at the first day of the year integer 001 through 366 Yom Representation of the month integer 01 through 12 M Representation of the minute integer 00 through 59 Yop AM or PM of the locale used when representing in 12 hour system S Representation of the second integer 00 through 59 U The number of the week starting at the first week of the year integer 00 through 53 with Sunday defined as the first day of week Yow The nth day of the week with Sunday defined as the Oth day integer 0 through 6 YoW The number of weeks starting at the first week of the year integer 00 through 53 with Monday defined as the first day of week ox Representation of the date appropriate in the locale YoX Representation of the time of a day appropriate in the locale y Representation of nth year of a century integer 00 through 99 Y Representation of a year of the Christian era integer L Time zone or abbreviation of the zone null character if the time zone cannot be specified Yo o Representation of itself CC32R MANUAL 277 Chapter 9 C Standard Library st r l e n String handling function Measures the size of string Syntax include lt string h gt size_t strlen const char s S pointer to string whose le
216. epresentation Alignment struct sl char a char b 2 char c x1 re 4bytes Since alignment of each member is 1 byte total alignment is also 1 byte The size of a structure is 4 bytes struct s2 char lt a B3 short c char d x2 a 8 bytes sS x2 b x2 C x2 d Since a member has 4 byte alignment pointer type the alignment of the structure is 4 bytes CC32R MANUAL 82 Chapter 5 Internal Data Representation Example 3 Coding Internal Representation Alignment Example 4 Coding Internal Representation Alignment struct s3 char a int b x3 A 8 bytes x3 a x3 b SN 3 bytes Since a member has 4 byte alignment int type the alignment of the structure is 4 bytes Since 3 byte gap is used for alignment of member b the total size is 8 bytes struct s4 short a char b 3 x4 Since a member has 2 byte alignment short type the alignment of the structure is 2 bytes Since the location of the last member ends at odd byte a 1 byte of memory space is added and the size becomes 6 bytes CC32R MANUAL 83 Chapter 5 Internal Data Representation 5 6 Unions The data of members of union are assigned the same address The alignment of union type data is the maximum value of the alignment of the data type of that member The alignment of entire union is either 4 2 or 1 byte s depending on the largest alignment among the me
217. equipment communications equipment test and measurement equipment audio and visual equipment home electronic appliances machine tools personal electronic equipment and industrial robots High Quality Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems safety equipment and medical equipment not specifically designed for life support Specific Aircraft aerospace equipment submersible repeaters nuclear reactor control systems medical equipment or systems for life support e g artificial life support devices or systems surgical implantations or healthcare intervention e g excision etc and any other applications or purposes that pose a direct threat to human life You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics especially with respect to the maximum rating operating supply voltage range movement power voltage range heat radiation characteristics installation and other product characteristics Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges Although Renesas Electronics endeavors to improve the quality and reliability of its products semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under ce
218. er Syntax include lt stdlib h gt double atof const char nptr npotr pointer to string to be converted Return Value Converted value Successful Description The atof function converts a character string nptr expressing a number into a double type value and returns a converted value If a conversion result overflows or underflows this function sets a value of ERANGE in errno and returns HUGE_VAL HUGE_VAL if negative or 0 as a return value CC32R MANUAL 181 Chapter 9 C Standard Library ato i General utility function Converts the character string representing a decimal number into a int type integer Syntax include lt stdlib h gt int atoi const char nptr npotr pointer to string to be converted Return Value Converted value Successful Description The atoi function converts a character string nptr expressing a number into an int type value and returns a converted value If a conversion result overflows this function sets a value of ERANGE in errno and returns INT_ MAX INT_MIN if negative or 0 as a return value ato l General utility function Converts the character string representing a decimal number into a long type integer Syntax include lt stdlib h gt long atol const char nptr npotr pointer to string to be converted Return Value Converted value Successful Description The atol function converts a character string nptr expressing a number into an l
219. er sequences such as plain characters and conversion specification The number of and the appearance order of conversion specifications correspond to them of arguments in the variable argument list Plain characters Characters in a sequence beginning with non i e other than a conversion specification They are output directly Example fprintf fp data 02d a The underlined are plain characters Conversion specification A character sequence beginning with It specifies how to convert the corresponding argument in the variable argument list It consists of and following specifiers shown below They are optional CC32R MANUAL 199 Chapter 9 C Standard Library e Flags e Field width e Precision e Size specifier for the corresponding argument e Conversion specifier Example fprintf fp data 02d a The underlined is a conversion specification It converts a lt Conversion Specification Syntax gt A conversion specification can be specified by the following format a specifier enclosed in is optional flags field_width precision size_specifier conversion_specifier Example 02d The the flag 0 the field width 2 and the conversion specifier d Every item shall be described continuously not separated by a space If there is no corresponding argument for a conversion specification such as there is no variable argument list arguments are not enough
220. ered or a read error occurs Note The content of the storage specified by s does not vary when an input file is ended but it depends on the user defined read function when an error occurs The fgets function inputs a string from the stream specified by the file pointer fp and stores it in the memory area specified by the pointer s This function inputs n 1 characters any characters up to the new line character or to the end of the file and it adds a null character to the end of the string The input new line character is included in the string and is stored When EOF end of file is encountered the EOF indicator for the stream is set and this function returns EOF When a read error occurs during the operation the error indicator for the stream is set and this function returns EOF The EOF indicator can be referred by the feof function and the error indicator can be referred by the ferror function CC32R MANUAL 196 Chapter 9 C Standard Library f O O r Mathematics function Cuts off the fraction of a floating point number Syntax include lt math h gt double floor double x X floating point number Return Value Calculation result Description The floor function returns the maximum integer equal to or less than the value x as a double type value f m O d Mathematics function Computes the floating point remainder Syntax include lt math h gt double fmod double x double y X V
221. erefore be included in for example the start up program In the example shown below we have extracted the relevant portion of a start up program in which the three base registers R11 to R13 are used Note that in this example all three registers R11 to R13 are assigned as base registers but that it is not necessary to set up all of R11 to R13 when they are not used Note When the base address is specified in the Access Control File you must specify the same value for the base symbol as at that address 1 Definition of base symbol export can also be global EXPORT __REL_BASE11 EXPORT __REL_BASE12 EXPORT __REL_BASE13 ee BASE11 EQU 0x10000000 a BASE12 EQU 0x20000000 BASE13 EQU 0x30000000 2 Initialization of base registers SETH R11 HIGH __REL_BASE11 OR3 R11 R11 LOW __REL_BASE11 SETH R12 HIGH __REL_BASE12 OR3 R12 R12 LOW __REL_BASE12 SETH R13 HIGH __REL_BASE13 OR3 R13 R13 LOW __REL_BASE13 A 1 6 Base Register Function Limitations 1 When the offset is 32768 or greater With extremely large structures or arrays the base register function cannot be used to access members or elements mapped to offsets greater than 32768 bytes from the base 2 Duplication of base addresses If there are duplicate ranges covered by the base registers and o
222. ers for fprintf 1 3 Conversion Conversion Method Type of the Notes on Precision Specifier Argument dori Converts int type data into a int The precision shows how character sequence of signed many characters are output decimal notation at least The conversion specifier d ifthe numberof conv rted behaves the same as i characte sinaller than o Converts unsigned int type data unsigned the value of precision 0 is into a character sequence of int added to the beginning of unsigned octal notation the character string j If the precision is omitted 1 u Converts unsigned int type data unsigned assumed into a character sequence of int unsigned decimal notation Even if any data of value 0 is output with a precision of x Converts unsigned int type data unsigned 0and converting it nothing into a character sequence of int is output unsigned hexadecimal notation The hexadecimal letters abcdef are used X Converts unsigned int type data unsigned into a character sequence of int unsigned hexadecimal notation The hexadecimal letters ABCDEF are used f Converts double type data intoa double The precision shows the character sequence of decimal number of digit of notation in the format ddd ddd fractional part If there is are any decimal place s a figure is output before a decimal point If the precision is omitted 6 is assumed If the precision is 0 a fractional part is not output
223. es 8 2 13 stdlib h Performs the prototype declaration of general utility functions memory management end process definition of macros and declaration of data types necessary for general utility functions These functions macros and data types are shown in Tables 8 20 8 21 and 8 22 Table 8 20 Functions Declared by stdlib h 1 2 Function Description Reentrant abort Puts the running program to forced stop x abs Obtains the absolute value of an int type integer O atexit Catalogs the function to be called upon successful x termination of the program atof Converts the character string representing a number Xx into a double type floating point number atoi Converts the character string representing a decimal x number into a int type integer atol Converts the character string representing a decimal x number into a long type integer bsearch Performs binary search O Depends on comparison function calloc Allocates a memory space and initializes the allocated x memory space to 0 div Divides an int type integer and obtains the quotient O and remainder exit Terminates the program Xx free Releases the specified memory area x getenv Gets the content of an environmental variable Depends on user description labs Obtains the absolute value of a long type integer O ldiv Divides a long type integer and obtains the quotient O and remainder malloc Allocates memory area x mble
224. es a file Depends on user description rename Renames a file Depends on user description rewind Moves the current read write position on a stream to x the beginning of the file scanf Gets data from the standard input file stdin and x converts the data by following the format setbuf Defines a buffer for an I O stream Xx setvbuf Defines and sets a buffer for an I O stream x sprintf Converts the data by following the format and outputs x the data to an area sscanf Gets data from a memory area and converts the data x by following the format tmpfile Creates a temporary file Xx tmpnam Creates a not existing temporary file name x ungetc Returns a character a stream x vfprintf Outputs a variable argument list to a stream by Xx following the format vprintf Outputs a variable argument list to the standard output x stdout by following the format vsprintf Outputs a variable arguments list to a memory area x by following the format CC32R MANUAL 163 Chapter 8 Standard Header Files Table 8 18 Macros Defined by stdio h Macro Name Description _IOFBF Indicates that all input and output processes use the buffer area _IOLBF Indicates that input and output processes use the buffer area in units of one line _IONBF Indicates that input and output processes do not use the buffer area BUFSIZ Indicates the size of the buffer required for input and output processes EOF End of file i e indicates
225. es an access to an object that has volatile qualified type gt Each reference to a volatile object name will constitute one access to the object volatile qualified objects are not optimized 10 2 11 Declarators e ANSI C 6 5 4 Declarators lt The maximum number of declarators that may modify an arithmetic structure or union type gt No limit is placed on the maximum number of declarators 10 2 12 Statements e ANSI C 6 6 4 2 The switch statement lt The maximum number of case values in a switch statement gt The maximum value of case in a switch statement depends on the available memory capacity 10 2 13 Preprocessing Directive e ANSI C 6 8 1 Conditional inclusion lt Whether the value of a single character character constant in a constant expression that controls conditional inclusion matched the value of the same character constant in the execution character set Whether such a character constant CC32R MANUAL 329 Chapter 10 The cc32R s Behavior may have a negative value gt The value of a single character constant in the constant expression that controls conditional inclusion agrees with the value of the same character constant in the execution character set Such character constant can be assigned a negative value e ANSI C 6 8 2 Source file inclusion lt The method for locating includable source files gt The sequence of retrieving header files specified by include is given in the Function
226. es ineniets 75 Integral TY PeS ssscsansdcscesaieeisseparcicern ick eaide aden enna Aaa edieeay 76 Floating WV DSS acacia voice aries otis cdeledateettin EA 78 PANT AY EE AIAI veces dais OA A AO A 80 E R E A E 81 MIO INS EEE E P T AIEA EAEI T TEA EA A EAA E A alee 84 Enumera on WY POS nenen aa a anes 86 POME acwenrere pene tet nnana re ree 87 Bite e E E EIA E I P OA A O T T E I aia aie 88 O94 Data Typer BIFE sisson aa aaaea 88 59 2 Packingand ANgMMEN sssri eee a ae e a a i 90 Internal Representation of Class Type csscceceeeeceeeeeeeeeeeeeeaeesteneeeteeeeeeneeeees 94 5 10 1 Internal Representation of Class Type cccecceesceseeeeeeeeeeneeeeeeeeeeseeeeeeeseateneeeeaes 94 SANOI Alignment N MDOT it sicurtieciesiasineisccuesecs ceiseenes ear eersceencnmnaecer AEE 94 SAO 12 Class Type Data AllOCAatiOn irie a T 95 Chapter 6 C C Calling Conventions 6 1 6 2 6 3 6 4 6 5 6 6 6 7 Register Usage iii sarc tenrtin tata tis tandoori 99 6 1 1 General Register RO R15 Usage 0 ee cece eeeeeseeeeeeeeneeteaeeeseeteseeseeeeaeeseaeenaeetaaee 99 i2 Register Consideration cams tutor deat ee e EEE EE EREET 101 Stack Fiame Configuratio Tasirin aranan aniani i A aiae 102 Galland Retin Procedures 2i sciezisaecetcacctuackeeevacgciaitesis a hdneeeaitlenndtgeand eats 103 Parameter PASSING minneu eai a Eaa ESTO TAE EEEa 106 6 4 1 Rules Par meter PASsinG seis sve cccsesseveesstsces sede eseisto 106 6 4 2 The Cases where St
227. fread void ptr size_t size size_t n FILE fp ptr pointer to data storage area SIZE the number of bytes of one member Dy the number of members to be read Lp pointer to File structure Return Value The number of read members Successful the same value as usually A value smaller than n The file is ended or an error occurs It can be judged by the ferror and feof function Description The fread function reads up to n members which have size byte data from the stream pointed to by fp to the memory area specified by ptr If size or n is O this function returns 0 as a return value and the contents of the memory area specified by ptr does not change If an error in encountered or if the members are not read completely the value of the file position indicator is not guaranteed CC32R MANUAL 209 Chapter 9 C Standard Library free General utility function Releases the specified memory area Syntax Return Value Description include lt stdlib h gt void free void ptr ptr top address of memory area to be free None The free function frees the memory area specified by ptr so that the memory area can be allocated again for use This function does nothing if ptr is NULL If the memory area to be free by the free function or the memory area specified by ptr of the realloc function is not any of memory area allocated by the calloc malloc and realloc functions
228. fter executing implicit type conversion the value of the actual argument is not guaranteed For example if an actual argument that has been declared as short implicitly converted into int if no function prototype is given is passed to a function that has a formal argument of unsigned int an error occurs but no error occurs if the said actual argument is passed to a function that has a formal argument of int Type incompatibility between function prototype and function definition In calling a function when the function prototype declaration is visible if the function is not defined for the type compatible with the declaration an error results CC32R MANUAL 310 Chapter 10 The cc32R s Behavior Prototype declaration of variable arguments If a function that accepts a variable arguments list is called ina position where the function prototype that ends with is not visible there can be a chance that part of variable number of actual arguments is not correctly passed e ANSI C 6 3 3 2 Address and indirection operators Unary operators amp If you perform a reference as given below by use of an address arithmetic operator amp or an indirect reference operator the operation is not guaranteed e Referencing an invalid array e Referencing a null pointer e Referencing an object having automatic storage duration whose scope has expired e ANSI C 6 3 4 Cast operators If you cast a pointer toward a functio
229. function Allocates a memory space and initializes the allocated memory space to 0 Syntax Return Value Description include lt stdlib h gt void calloc size_t nelem size_t elsize nelem the number of elements elsize bytes of an element Top element address in Successful allocated memory area NULL Error No memory area has been allocated Any of the arguments is 0 The calloc function allocates nelem objects of the memory area in elsize bytes This function initializes all of the allocated area to 0 12 bytes more area have been secured as memory area allocated by each the calloc functions This memory area of 12 bytes is stored a allocation infomation size etc CC32R MANUAL 184 Chapter 9 C Standard Library ce i l Mathematics function Computes the integer ceiling of a floating point number Syntax include lt math h gt double ceil double x Xx floating point number Return Value The calculation result Description The ceil function returns a minimum integer equal to or greater than value x as double type value CC32R MANUAL 185 Chapter 9 C Standard Library C l earerr Input output function Clears an error condition in a stream Syntax include lt stdio h gt void clearerr FILE fp fo pointer to FILE structure Return Value None Description The clearerr function clears the error and EOF end of file indica
230. function function errno h Macro definition related to the error number All functions as necessary float h Macro definition of the limit value related to internal Mathematics function etc representation of a floating point number only when float h macro is used limits h Macro definition of the limit value related to All functions as necessary the compiler internal process locale h Declaration of the locale localization handle function Localization function math h Declaration of the double and float type mathematical Mathematics function unction and macro definition mathf h Declaration of the float type mathematical function Mathematics function and macro definition setjmp h Declaration of the branch function data type declaration Non local jump function signal h Signal interrupt declaration of the number of processes Signal handling function stdarg h Macro declaration of variable arguments functions Variable arguments access Data type declaration function stddef h Definition common to standard headers data type All functions as necessary declaration stdio h Declaration of the input and output functions data type Input output function declaration macro definition stdlib h Declaration of the C program standard process function General utility function e g memory management data type declaration macro definition string h Declaration of the string handle function and memory String handling function handle function ti
231. haracter at any of the decimal places the decimal point is also removed c Considers int type data as int The precision is disabled unsigned char and converts it into a character corresponding to the data CC32R MANUAL 205 Chapter 9 C Standard Library Conversion Specifiers for fprintf 3 3 Conversion Conversion Method Type of the Notes on Precision Specifier Argument s Outputs a character sequence pointerto The precision shows the specified by data of the pointer to char number of characters to be char type up to the null character output If the precision is which shows the end of the omitted the character character string or the output the string specified by the data number of characters specified by up to the null character is the precision The null character output The null character is not output is not output p Regards data as pointer type and pointerto The precision is disabled converts it into a printable void character string depending on the compiler n Considers the data is regarded as pointerto The precision is disabled pointer type to int type and sets int the number of characters of data output to the memory area specified by the data Outputs None The precision is disabled Note Specifying the n or specifier cannot convert the corresponding argument CC32R MANUAL 206 fputc Chapter 9 C Standard Library Input outp
232. he area where the return value is set is pushed The return value setting area general ly in the stack area is reserved by the calling side before starting the function call Figure 6 5 shows the argument area for the function having structure or union type return value TLower Address Top Address of Return Value Area 1st Argument 2nd Argument Return Size of 3 Pa Value Area Return Value er gumeni JHigher Address 4 bytes Argument Area Figure 6 5 Argument Area for the Function which Returns Structure or Union 2 Call function This function is called by BL or JL instruction The address return address of the instruction following the function call instruction is set in the link register R14 3 Allocate local variable area On the stack a local variable area is allocated which the called function will use The size of the reserved area is subtracted from the SP value The size of the reserved area is always a multiple of 4 CC32R MANUAL 104 Chapter 6 C C Calling Conventions 4 Save registers 5 Restore registers The contents of registers R8 R13 to be used by the called function are saved on the stack The size of the saving area is the number of registers to be saved 4 bytes When the link register R14 is used then the link register is saved The register s saved at the entry of a called function see 4 Save registers above is restored 6 Free
233. he new line character are deleted If the source file ends at a midpoint of a preprocessing token or of a comment an error occurs Note 1 Preprocessing token see the ANSI C 6 1 A minimal lexical element of text within a source file in C and includes the following header names identifiers preprocess ing numbers character constants string literals operators punctuators and single non white space character that do not match the above e ANSI C 5 2 1 Character Sets Characters other than those belonging to the character set If characters that do not belong to the variable character set ap pear in a source file excluding preprocess tokens not to be con verted into tokens character constants string literals header names and comments a warning is given and the characters are ignored e ANSI C 5 2 1 2 Multi byte Characters If multi byte characters are used anywhere other than comments character constant and string literal the operation is not guaran teed There can be instances in which the end of comment is not detected if what immediately precedes the end of comment is in shift state CC32R MANUAL 307 Chapter 10 The cc32R s Behavior e ANSI C 6 1 Lexical elements Pair of quotation marks Either a or that does not form a pair if appears in a source results in an error e ANSI C 6 1 2 1 Scopes of identifiers Using the same identifier twice or more as a label within a funct
234. he program Converts the character string representing a number into a double type floating point number Converts the character string representing a decimal number into a int type integer Converts the character string representing a decimal number into a long type integer Performs binary search Allocates a memory space and initializes the allocated memory space to 0 Divides an int type integer and obtains the quotient and remainder Terminates the program Releases the specified memory area Gets the content of an environmental variable Obtains the absolute value of a long type integer Divides a long type integer and obtains the quotient and remainder Allocates memory area Obtains the number of bytes composed of multibyte characters Converts a multibyte character string into a wide character string Converts a multi byte character into a wide character Appendix B 5 Appendix B The C Standard Library Function List qsort rand realloc srand strtod strtol strtoul system westombs wctomb String handling function memchr memcemp memcpy memmove memset strcat strchr strcmp strcoll strcpy strcspn Performs sorting Generates a pseudo random integer which resides between 0 and RAND_MAX Changes the memory area size to the specified size Sets the initial value of the pseudo random integer which the rand function generates Converts a string represe
235. he remaining arguments are passed by the stack e Ifthe return value is either floating types structure type or union type all the arguments are passed by the stack u n e If the function has a variable parameter is specified at the end of the parameter list as with the printf function the variable argument and the preceding argument are passed by the stack 6 4 2 1 Pushing onto the stack Arguments which have done type conversion as above are pushed onto the stacks e Ifthe type after conversion is one of char unsigned char short and unsigned short type the argument first is converted to type int and then is pushed onto the stack If an argument has another scalar type it pushed on without being converted An argument which has converted to type float will not be converted to type double when pushed on the stack e Ifan argument has type struct or union with 4 byte boundary alignment is directly stacked Otherwise i e it is not a 4 byte boundary first the area with 4 byte boundary which can be represented the argument is allocated on the stack and then the argument is set to the lowest address a multiple of 4 and subsequent of that area The examples 1 to 5 shown below describe various stack passing procedures figures are images of the argument are on the stack e Example 1 int Argument Area D 8 bytes f 1 0f 2 4 bytes The first argument is type float without the function
236. he write function low level functions you prepare CC32R MANUAL 323 Chapter 10 The cc32R s Behavior 10 2 3 Identifiers e ANSI C 6 1 2 Identifiers lt The number of significant initial character beyond 31 in an identifier without external linkage gt As for an identifier without external linkage the first 240 charac ters are significant The 241st character and subsequent ones are ignored lt The number of significant initial character beyond 6 in an identifier with external linkage gt As for an identifier the first 240 characters are significant The 241st character and subsequent ones are ignored Identifiers are case sensitive lt Whether case distinctions are significant in an identifier with external linkage gt You can describe only an integer constant expression in the case statement 10 2 4 Characters e ANSI C 5 2 1 Character sets lt The members of the source and execution character sets except as explicitly specified in this International Standard gt Both the source character set and execution character set comply with JIS X 0201 0208 character set The Latin character part of JIS X 0201 will be regarded as ASCII The EUC Expanded Unix Code Shift JIS and UCS 2 UTF 8 encoded are supported as the actual character encoding e ANSI C 5 2 1 2 Multibyte characters lt The shift states used for the encoding of multibyte characters gt The shift state character strings that i
237. hen programming When the option rel16 is specified the compiler outputs load store instructions by register relative indirect addressing for access to the symbols of D and B sections located in RAM Access to symbols are performed in register relative indirect addressing mode via the fixed register R12 Example Differences in codes output with and without rel16 option When rel16 option is not used When rel16 option is specified LD24 R1 _symbol LDUB R1 R1 LDUB R1 _symbol __REL_BASE R12 When the option rel16 pay attention to the precautions below during programming e Be sure to set the R12 register and define the __REL_BASE symbol When using this option you need to set the R12 register and define the __REL_BASE symbol at the beginning of the program Generally these may be set in the startup program start ms Refer to Section 7 3 Programming Start up Program The values set for the R12 register and __REL_BASE symbol must be the start addresses of the D and B sections plus 32 Kbytes For example if linked in order of D and B sections with the total area of 64 Kbytes and the start address of D section h 20000 then you set the value h 28000 See Figures 3 1 and 3 2 e Make sure the total size of data in D and B sections is within 64 Kbytes When using this option make sure the total size of data in D and B sections is within 64 Kbytes and that the data are located at contiguous addresses If the
238. hich must be taken upon opening the file Each bit of the data has the following function Otte 23 24 25 26 27 28 29 30 3i mode ow 9 a c la b Bit Description a 31st bit When 0 indicates that the file is read only When 1 indicates that the file is write only b 31st bit Indicates that the file is read and write when both this bit and the 31st bit are 0 Note that this bit is not set to 1 when the 31th bit is 1 c 30th bit When 1 the read write point of the next file can be set at the end of the file and when 0 at the beginning of the file cont CC32R MANUAL 350 Chapter 11 Low level Library Bit Description d 27th bit When 1 indicates that a new file can be opened if the file indicated by path name is not found e 26th bit When1 and if the file indicated by the path name is found indicates that the contents of the file are discarded and file size is set to 0 f 25th bit When 1 indicates that a file is opened on binary mode When 0 indicates that a file is opened on text mode g 23rd bit When 0 the file is opened in text mode If the bit is 1 the file is opened in binary mode If the file process specified by mode is not compatible with the nature of the real file an error is occurred When the file is successfully open this function returns the number integer 0 or larger of the file which will be u
239. his printf is executed jelse printf false in actual the relation yields false and this printf is executed This is because following implicit conversions are executed 1 According to usual arithmetic conversions the 1 type int is converted to type unsigned int 2 According to signed unsigned integers conversions when 1 the 1 is converted to Oxffffffff calculated from the original value the maximum number for unsigned type 1 shown in Table 4 15 that is 1 Oxffffffff which is the maximum value for int 1 CC32R MANUAL 70 Chapter 4 C Programming Language Specification 4 4 Preprocessing Directives A preprocessing directive starts with and processed by the C compiler in the C preprocessor phase Preprocessing directives include the commands shown in Table 4 18 Table 4 18 Preprocessing Directives Preprocessing Directive Description include Insert file define Defines macro undef Undefines macro if Executes conditional compile else Executes conditional compile endif Ends conditional compile elif Executes conditional compile ifdef Executes conditional compile ifndef Executes conditional compile line Specifies line error Issues an error message and pauses process The macros shown in Table 4 19 are predefined reserved Table 4 19 Predefined Macros Predefined Macro Description __LINE__ The line num
240. ication The comment is a text which though written in a program is not processed by the compiler It begins with and ends with To write one line of comment a symbol may be used A comment can be written in a space beginning with the delimiter to the end of the line A comment that begins with and ends with cannot be nested To write a comment in Japanese use the character codes specified by the envi ronment variable M32RKIN If the environment variable M32RKIN is un defined comments in Japanese are construed as written in EUC format extend ed UNIX code for EWS version CC32R or shift JIS format for PC version CC32R Example void foo void char x 3 3 Comment can be written x 0 0 Comments can be written in this manner CC32R MANUAL 56 Chapter 4 C Programming Language Specification 4 2 Data Types 4 2 1 Types and Type Specifiers The type data type determines the meaning of a value stored in an object or a return value from a function The types supported by the C C compiler and their type specifiers identifiers in C C for declaration are Types of C C language Basic types Void types Bool types Wide character types Character types Signed integer types Unsigned integer types Floating types Class types The others Array types Structure types Union types Enumeration types Pointer types Function types Wide character
241. ics products or if you have any other inquiries Note 1 Renesas Electronics as used in this document means Renesas Electronics Corporation and also includes its majority owned subsidiaries Note 2 Renesas Electronics product s means any product developed or manufactured by or for Renesas Electronics tENESAS C 7 D me on lt D D C C Compiler Package for M32R Family V 5 00 C C Compiler User s Manual Renesas Microcomputer Development Environment System Renesas Electronics Rev 1 00 2005 07 www renesas com Active X Microsoft MS DOS Visual Basic Visual C Windows and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and other countries HP UX is a registered trademark of Hewlett Packard Company Sun Java and all Java based trademarks and logos are trademarks or registered trademarks of Sun Microsystems Inc in the U S or other countries and are used under license UNIX is a registered trademark of The Open Group in the United States and other countries IBM and AT are registered trademarks of International Business Machines Corporation HP9000 is a product name of Hewlett Packard Company SPARC and SPARCstation are registered trademarks of SPARC International Inc Intel and Pentium are registered trademarks of Intel Corporation i386 i486 and MMX are trademarks of Intel Corporation Adobe and Acrobat
242. ied characters Syntax include lt string h gt size_t strspn const char si const char s2 sl pointer to string to be checked S2 pointer to string used to check si Return Value The length of the searched string Description The strspn function searches the string s1 starting from the beginning for a series of characters which match the characters of the string s2 and returns the number of continuous characters that precede the first match series of characters of s2 st rst r String handling function Finds the first occurrence point of a string within another Syntax include lt string h gt char strstr const char si const char s2 isd pointer to string to be searched S2 pointer to string to be searched for Return Value Pointer to the character found The character is found in the string s1 NULL The character is not found or s2 is null Description The strstr function locates in the character string s1 the position where the character string s2 first appears and returns the pointer to that position If s2 is null the return value is also null CC32R MANUAL 284 Chapter 9 C Standard Library strtod General utility function Converts a string into a double type floating point number Syntax Return Value Description include lt stdlib h gt double strtod const char nptr char endptr npotr pointer to string to be converted end
243. ifiable lvalue The lvalue of the operator and operator may be modifiable operand of must have arithmetic type or pointer to object type The operand of the operator and operator must have arithmetic or pointer type CC32R MANUAL 381 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 10 15 Message Description operand of must have integral type The operand of the operator must be integer operand of must have scalar type The operand of the operator and operator must have scalar type operand of must have scalar type The operand of the operator must have scalar type operand of sizeof must not be bitfield You may not specify a bit field for the operand of the sizeof operator operand of sizeof must not be function type You may not specify an function type for the operand of the sizeof operator operand of sizeof must not be incomplete type You may not specify an incomplete type for the operand of the sizeof operator operand of unary amp must be lvalue or function designator The operand of the amp address operator must be either an lvalue or a function specifier operand of unary must be pointer type The operand of the indirect reference operator must be pointer type operand of unary must have arithmetic type The operand of the unary operator and una
244. ifications is in correct format printf like functions scanf like functions conversion In dealing with conversion specifications for the printf like functions or the scanf like functions in most cases in which characters other than numeric characters are contained between and the characters between and are subjected to input output For example abcdef is converted into abcdefg e ANSI C 7 9 6 1 The fprintf function Qualifier In dealing with conversion specifications of the printf like functions if the qualifier the size specifying character h or 1 is specified previous to h or preceding the conversion specifier other than the one involved 0 x X e E f g G then the qualifier is ignored Flag In dealing with conversion specifications of the printf like functions if the flag is specified previous to a conversion specifier other than the one involved o x X e E f g G then the flag is ignored In dealing with conversion specifications of the printf like functions if the flag 0 is specified previous to a conversion specifier other than involved d i o u x X e E f g G then the flag is ignored Note 3 The printf like functions fprintf printf sprintf vfprintf vprintf and vsprintf Note 4 The scanf like functions fscanf scanf and sscanf CC32R MANUAL 319 Chapter 10 The cc32R s Behavior Conversion result Though an aggregate a uni
245. ignment Signed Minimum Value Maximum Value char lbyte 1byte Yes 2 128 2 1 127 unsigned char byte 1byte No 0 2 1 255 short 2bytes 2bytes Yes 2 32768 2 1 32767 unsigned short 2bytes 2bytes No 0 2 1 65535 int 4bytes 4bytes Yes 2 2147483648 2 1 2147483647 unsigned int 4bytes 4bytes No 0 2 1 4294967295 long 4bytes bytes Yes 2 2147483648 2 1 2147483647 unsigned long 4bytes 4bytes No 0 2 1 4294967295 bool lbyte 1bytes Yes reference Abytes 4bytes No 0 2 1 4294967295 The MSB of a non unsigned data indicates the sign 0 positive data or 0 1 negative data Negative data is expressed as two s complement An unsigned type data has no sign and its value is positive or 0 Examples of the internal representation are shown in Table 5 2 Note MSB most significant bit CC32R MANUAL 76 Chapter 5 Internal Data Representation Table 5 2 Examples of Internal Representation of Integers Type Internal Representation Value char 0000 0001 1 1111 1111 1 unsigned char 0000 0001 1 1111 1111 255 short 0000 0000 0000 0001 1 1111 1111 1111 1111 1 unsigned short 0000 0000 0000 0001 1 1111 1111 1111 1111 2 1 65535 int 0000 0000 0000 0000 0000 0000 0000 0001 1111 1111 1111 1111 1111 1111 1111 1111 1 1 unsigned int 0000 0000 0000 0000 0000 0000 0000 0001 1111 1111 1111 1111 1111 1111 1111 1111 1 2 1 4294967295 long 0000
246. ile use the object module files extension ml generated with the mklib option ml mo When the mklib option is specified this option causes the object module filename extension ml to be changed to mo when processed Chapter 3 Invoking the Compiler Table 3 6 Command Options for the C Compiler 6 11 Option noinline Description invalidates the inline storage class specification specified for functions by the inline expansion facility keyword iinline i When this option is specified the inline storage class specification for functions is ignored For details about the inline expansion facility refer to Section A 4 o output_filename Assumes output_filename for the output filename If this option is omitted and the output file is a load module file then the file is output under a filename am out The output_filename specified here is effective for the P S c CS and cs options too Opriority The option priority is used to specify a higher priority between code size and speed during optimization Use the time priority or space priority by referring to the definition below Do not separate symbols O from the word priority Otime Optimization with the speed has priority over code size Ospace Optimization with the size reduction has priority over speed Otime and Ospace cannot be specified simultaneously Specifying this option without specifying Olevel is equal to spe
247. ilename except for the option is specified it will not assumed as a command file even if its beginning character is Example 1 sample cmd processed as a command file gt cc32R sample cmd gt cc32R sample cmd gt cc32R sample cmd Example 2 sample cmd is not assumed as a command file gt cc32R v sample cmd there is a parameter which is not command file specification except for gt cc32R sample cmd v ditto gt cc32R sample cmd sample cmd there are two or more command file specifications CC32R MANUAL 16 Chapter 3 Invoking the Compiler e Rules for the command file are O Each parameter options input output filenames etc takes the same format as parameters specified on the command line O Delimit parameters with one or more spaces or a new line character return key O Lines starting with are seen as comments and are skipped O You cannot call a command file from within a command file Figure 3 3 shows results when commands are executed from a command file and from the command line in ordinary format gt cc32R sample cmd f Ib include C This is a comment line o a work sample mo a work sample c sample cmd Same results are obtained gt cc32R I b include C o a work sample mo a work sample c Figure 3 3 When executing commands from a command file and from the command line III NOTE
248. ime file2 cpp cc32R c Otime file3 cpp Compile the C source files xxx cpp to create object modules In the above example the C source files are compiled to generate three object module files filel mo file2 mo and file3 mo and a special file for C 2 Assembling the startup file Example cc32R c start ms The startup file in assembly language is assembled to create an object module file In the startup file make various settings needed for program operation such as CPU settings section initialization and main function calls For details refer to Chapter 7 Creating Embedded Applications CC32R MANUAL 20 Chapter 3 Invoking the Compiler 3 Linking Example cc32R start mo filel mo file2 mo file3 mo o loadmodule abs SEC P 400 C D CTOR VTBL D 804000 B COMMON 1 m32RcR lib Link the object module files created in 1 and 2 above to generate a load module file in the above example loadmodule abs At that time you can specify a library file 1 option or the order and addresses in and at which sections are located SEC option Note that SEC P 400 C D CTOR VTBL D 804000 B COMMON in the above example is the specification for seven sections P C D B CTOR VTBL and COMMON created by compiling and linking C in cc32R to determine the order in which they are located and the addresses at which they are located More specifically it means that the sections P C D ini
249. ined _strerror function a low level function CC32R MANUAL 335 Chapter 10 The cc32R s Behavior e ANSI C 7 12 1 Components of time lt The local time zone and Daylight Saving Time gt The environment variable TZ is used to set the local time the calender time in each locale As the local time JST default EST5EDT CST6CDT MST7MDT PST8PDT and UTC are supported As daylight saving time ESTS5EDT CST6CDT and MST7MDT are supported e ANSI C 7 12 2 1 The clock function lt The era for the clock function gt It is depends on the user defined clock function a low level function CC32R MANUAL 336 Chapter 10 The cc32R s Behavior 10 3 Locale specific Behavior Here follows how the operation dealt with as locale specific behavior in ANSI C goes on in the C C compiler cc32R The number and the heading subsequent to e ANSI C are the section number and the section heading of the corresponding ANSI C ANSI ISO 9899 1900 Each issue as locale specific behavior is shown in a pair of angular brackets lt gt and the corresponding behavior of cc32R is detailed subsequent to lt gt e ANSI C 5 2 1 Character sets lt The content of the execution character set in addition to the required members gt The character code set of JIS X 0201 except for the Latin characters and JIS X 0208 were extended e ANSI C 5 2 2 Character display semantics lt The direction of printing gt
250. ing DXA Important Information on Compiling a C Program with the C Compiler D7 1 Function prototype declarations Before using a function a prototype declaration is necessary At this time the types of parameters should also be declared extern void func extern void func int void g gt void g D7 2 Linkage of const objects Whereas in C programs const objects are linked externally in C programs they are linked internally In addition const objects require initial values const cvaluel Error const cvaluel o gt Give intial value const cvalue2 1 Internal extern const cvalue2 1 D7 3 Assignment of void In C programs if explicit casting is not used assignment of pointers to other objects excluding pointers to functions and to members is not possible void func void ptrv int ptri void func void pyrv int ptri gt ptri ptri Error ptri int ptrv 0K Appendix D 3 C C Compiler Package for M32R Family V 5 00 C C Compiler User s Manual Publication Date Sep 15 2005 Rev 1 00 l Sales Strategic Planning Div Published by Renesas Technology Corp Edited by Microcomputer Tool Development Department Renesas Solutions Corp 2005 Renesas Technology Corp and Renesas Solutions Corp All rights reserved Printed in Japan C C Compiler Package for M32R F
251. ing of Yes Yes Yes JIS X 0201 0208 utf8 UTF 8 The UTF 8 encoded Yes Yes No Unicode UCS 2 that was transformed from JIS X 0201 0208 UTF 16 The UTF 16 encoded No No Yes Unicode UCS 2 that transformed from JIS X 0201 0208 Pay attention to several points on the using of the Unicode utf8 application As for the details refer to A 6 4 7 Appendix A 36 Appendix A Extended Functions Reference A 6 1 3 Method of selecting character codes Designate the name of the character code column of Table 9 to each for the environment var iable for compiler and the setlocale function LC_CTYPE category for standard library to select the character code code that wants to use it Furthermore please pay attention to the difference the environment variable does not distinguish between the upper and lower of character code name but setlocale function distinguishes them a Character code at the time of input C C Compiler Environment variable M32RKIN The character code that describes the C C source file is designated The name that shows it to character code name of Table A 3 is designated The upper and lower have the same meaning in this environment variable If this environment variable is undefined sjis in PC version or euc in EWS version is selected in the default b Character code at the time of output C C Compiler Environment variable M32RKOUT This environment variable te
252. ing point constants Integer constants Enumeration constants Character constants Truth constants See 4 1 3 1 See 4 1 3 2 See 4 1 3 3 See 4 1 3 4 See 4 1 3 5 C language only CC32R MANUAL 46 Chapter 4 C Programming Language Specification 4 1 3 1 Floating Point Constant A floating point constant describes a floating point number It consists of a mantissa a fractional constant or a digit sequence an exponent part and a suffix as shown follows Example 1 23 E10 c Suffix Exponent Mantissa Table 4 4 Floating Point Constant Representation Part Format Description Mantissa fractional_constant A numeric character string containing a floating point constant and a decimal point It can be one of the following types integer fraction Example 3 12 integer Example 123 fraction Example 12 digit_sequence Decimal point is not included Example 123 Exponent e exponent or E exponent A description to express a constant as the base 10 exponent Sign can be omitted The exponent is decimal number Suffix L 1 Indicates a long double type constant F f Indicates a float type constant Without A double type constant Note encloses optional text divides choices Select one If the mantissa is a fractional_constant a digit sequence containing a floating point it is clear that the number is a floating point constant and the exponent
253. ing point number Obtains the exponential function of a floating point number Obtains the absolute value of a floating point number Cuts off the fraction of a floating point number Multiplies fractions of two floating point numbers and obtains the remainder Divides a floating point number into products of value 0 5 1 0 and 2 to the nth power Performs multiplication of a floating point number and 2 to the nth power Obtains natural logarithm of a floating point number Obtains the base 10 logarithm of a floating point number Divides a floating point number into integer and decimal Obtains a floating point number to nth power Obtains the sine of the radians of a floating point number Obtains hyperbolic sine of a floating point number Obtains the positive square root of a floating point number Obtains the tangent of the radians of a floating point number Obtains hyperbolic tangent of a floating point number Appendix B 2 Appendix B The C Standard Library Function List Non local jump function longjmp setimp Recovers the execution environment saved by setjmp and transfers control to the program location of a setjmp call Saves the current environment to a memory area Variable arguments access function va_arg Macro Gets variable arguments in turn va_end Macro Ends the reference to variable arguments va_start Macro Initializes to reference variable arguments Input output function
254. ing the operation the error indicator for the stream is set and this function returns EOF The error indicator can be referred by the ferror function CC32R MANUAL 253 putchar Chapter 9 C Standard Library Input output function Outputs a character to the standard output file stdout Syntax Return Value Description include lt stdio h gt int putchar int c Cj character to be output The character written Successful EOF A write error occurs The putchar function it may be implemented as a macro is the same as putc c stdout When a write error occurs during the operation the error indicator for the stream is set and this function returns EOF The error indicator can be referred by the ferror function CC32R MANUAL 254 puts Chapter 9 C Standard Library Input output function Outputs a string to the standard output file stdout Syntax Return Value Description include lt stdio h gt int puts char s Sj pointer to string to be output 0 Successful EOF A write error occurs The puts function outputs the string indicated by s to the standard output stdout The null character at end of the string is replaced with the new line character upon output When a write error occurs during the operation the error indicator for the stream is set and this function returns EOF The error indicator can be referred by the ferror
255. invokes the linker directly the prelinker will not be started and therefore objects will not be generated that can be linked correctly Do not write a program statement to invoke the linker alone even in Makefile D 2 Regarding Library Creation To create a library file the prelinker also needs to be invoked Therefore make sure the librarian is started through the compile driver cc32R by using the mklib option Do not write a program statement to invoke the librarian alone even in Makefile PEI Regarding Directory Movement If object files etc are moved to another directory after being compiled they cannot be correctly linked This is because the path information on object files etc when they were compiled is retained for processing by the prelinker D4 Regarding Object Filename Change If the extension of a relocatable object file is changed the prelinker may not operate correctly The prelinker refers to the name of a relocatable object file not including its extension as it searches for external information files Therefore if the name of a relocatable object file is changed using the o option etc object files cannot be correctly linked Appendix D 1 Appendix D Precautions on a compiling D 5 Precautions Regarding Special Files for C To compile or link C or create a library the compiler handles files that have the following extensions in order to realize various features of C language f
256. ion The signal function is not packaged in the C standard library The process relating to a signal depends on the specifications of a signal function a low level function you prepare Thus the instances given below also depends on a signal function a low level function you prepare e An instance in which a signal occurs as a result of calling the abort function or the raise function e An instance in which the signal handler calls a standard library function other than the signal function e An instance in which the signal handler references any static object of type other than volatile sig_atomic_t e An instance in which the value of errno is referenced after a signal occurs except the result of calling the abort function or the raise function and the corresponding signal handler calls the signal function that returns the value SIG_ERR e ANSI C 7 8 1 Variable arguments list access macros When a certain function let this be A invokes a function let this be B by using as an actual argument ap pointer to variable argument list updated by a va_arg macro if the function B calls a va_arg macro by using ap the following results e The function B the function invoked by the function A can carry out reference from variable arguments that ap indicates at the time when the function B is invoked The function A the function that invoked the function B can carry out reference from variable arguments indicated by ap
257. ion on a stream to the beginning of the file Syntax include lt stdio h gt void rewind FILE fp fp pointer to FILE structure Return Value None Description The rewind function moves the current read write position of the I O stream denoted by the file pointer fp to the beginning of the file The rewind function disables the ungetc function CC32R MANUAL 261 Chapter 9 C Standard Library scanf Input output function Gets data from the standard input file stdin and converts the data by following the format Syntax Return Value Description include lt stdio h gt int scanf const char control control pointer to format string sf variable argument list receivers The number of arguments converted Successful the number excludes and substituted arguments for n conversion and arguments inhibited by EOF The end of the input data is reached before the completion of the first conversion except for or an error occurs The scanf function gets data from the standard input file stdin exchanges and edits it according to the format specified by control and stores the results into the memory area specified by the variable argument list For further information on format control see the fscanf function description CC32R MANUAL 262 Chapter 9 C Standard Library setbuf Input output function Defines a buffer fo
258. ion results in an error Using an identifier that is not present in the current scope results in an error e ANSI C 6 1 2 Identifiers Characters subsequent to the significant characters if different in an identifier that identifies the same entity result in a warning e ANSI C 6 1 2 2 Linkages of identifiers If you declare the same identifier that stands for a function both for internal identifier and external identifier it is regarded as an external identifier If the identifier is put to static declaration in function definition it is regarded as an internal identifier If you define an identifier standing for anything else than functions for both internal identifier and external identifier it is regarded as an internal identifier e ANSI C 6 1 2 4 Storage durations of objects If a storage area reserved for an object that has automatic storage duration becomes no longer guaranteed and if you use the pointer value that references the object no error occurs during compilation but its operation is not guaranteed e ANSI C 6 1 2 6 Compatible type and composite type If there are two declarations for the same object or for a function and if their types are not compatible an error results e ANSI C 6 1 3 4 Character constants A non supported escape sequence if appears either in a character constant or in a string literal results in a warning and the backslash is ignored example c is interpreted as c CC32R M
259. iption Caution include lt stdlib h gt char getenv const char name name environment variable name Pointer to the character string Variable specified by name has been found specified by variable NULL Variable specified by name has not been found The getenv function searches for the variable specified by name in an environment list To call the getenv function in actual the user written getenv function is required see Section 11 1 and Table 11 2 CC32R MANUAL 223 Chapter 9 C Standard Library gets Input output function Gets a string from the standard input stdio Syntax Return Value Description include lt stdio h gt char gets char s string input from standard input Sj pointer to data storage area s Successful NULL End of file is encountered or a read error occurs Note The content of the storage specified by s does not vary when an input file is ended but it depends on the user defined read function when an error occurs The gets function inputs the data of one line from the standard input file stdin and stores it in the memory area specified by s Data of one line shall be a string from the start of the input to a new line character or the end of file The new line character in the input character is discarded and null character is appended When EOF end of file is encountered the EOF indicator for the stream is set and
260. irst calling separates the first group of the s1 string by using the character in the string s2 and the second group upon the second calling etc When the second and subsequent calls specify NULL as the first parameter The contents of s2 may be different from call to call A null character is added to end of each token CC32R MANUAL 286 Chapter 9 C Standard Library strtol General utility function Converts a string into a long type integer Syntax Return Value Description include lt stdlib h gt long strtol const char nptr char endptr int base nNptr pointer to string to be converted endptr end point of reading base radix of conversion 0 2 36 Numeric value after conversion Successful 0 Failed The strtol function reads a string pointed to by ntpr and converts it into a value long type having a radix specified by base The strtol function reads a string to be brought to conversion sequentially from the first character and stops reading when it detects either a null character or a character that it cannot interpret as a number that assumes a value having the radix base and sets in endptr the pointer pointing to the character handled at the time only when endptr does not hold NULL Space characters preceding the string to be brought to conversion the first segment where a non space character does not appear are ignored and not converted If base is 0
261. is carried out as one optimizing it should be carried out only when O4 level optimizing is effective 4 Even in the event of forward reference of inline function inline development is carried out 5 Even when the nested inline function is called the inline function calls another inline function inline expansion is carried out except for the inline function corresponding to the Precautions 2 Where inline development is suppressed described later Sample Use Source file cat sample c inline int func int a intb a 2 return b int answer void foo int a answer func a Command line cc32R S O7 sample c Code to be generated cat sample ms IMPORT _100_builtin_memcopy EXPORT _answer SECTION P CODE ALIGN 4 EXPORT func func MV __ RO R4 SLLI RO 1 JMP R14 EXPORT foo foo MV __ RO R4 Inline expansion SLLI RO 1 Equal to answer a 2 LD24 R1 _answer ST RO R1 JMP R14 SECTION B DATA ALIGN 4 ALIGN 4 _answer RES B 4 END Appendix A 30 Appendix A Extended Functions Reference Precautions 1 Static declared inline function Where static declared inline function calling was all inline expanded or it was not originally called from any place the compiler deletes its function body by judging it as unnecessary 2 Where inline expansion is suppressed For the following inline function call no inline ex
262. is returned The mbtowc function processes multibyte characters specified by s as follows e When both pwc and s are not NULL It converts multibyte characters of n bytes from the point specified by s into wide characters and stores them into the buffer pws e When pwc is NULL and s is not NULL It operates like the mblen function e When s is NULL or both pwc and s are NULL It checks whether a multibyte character set depends on the status The maximum value of multibyte characte is 3 byte And even euc sjis utf8 in addition to C are supported as the locale CC32R MANUAL 245 Chapter 9 C Standard Library memchr String handling function Locates in a memory area the position where a character first appears Syntax Return Value Description include lt string h gt void memchr const void s int c size_t 7 Sj pointer to memory area to be searched Cj character to be searched nj number of characters to be searched Pointer to character position As the result of search the character has been found NULL As the result of search the character has not been found The memchr function returns the pointer as a return value to the position of the same character as the character c which appears for the first time in n characters from the beginning of the specified memory area CC32R MANUAL 246 Chapter 9 C Standard Library memcom p St
263. ity strcpy buff strl strceat buff str2 4 Setting up the character code for preparation to use the mbstowcs function setlocale LC_CTYPE sjis In the case of Shift JIS 5 Transformation to the wide character string size_wch mbstowcs wbuff buff WBUFSIZE 6 Sending each 1 character to output function while taking out each 1 letter from wide character string that transformed Yet 2 and No will be omitted for i 0 i lt size_wch i if wbouff i L amp amp wbhuff i L a kanjiout wbuff i 7 Sending 1 character to output function while taking out each 1 letter from another wide character string for i 0 i lt sizeof wstr i kanjiout wstr i return 0 A 8 Programming that used a Japanese processing function Appendix A 39 Appendix A Extended Functions Reference This program processes the character string including Japanese that was written in the str1 str2 wstr and sends each 1 character to output function Although the kanjiout function of this example does not work yet this program can be appl ied to the usage such as the likes that carries out the output to the indicator It explains about each part of the program below 1 Description of Japanese with a multi byte character string char str2 FF AFE String can be described similarly as conventional character string letter
264. ize const char format const struct tm timeptr isis buffer for storing converted string maxsize maximum number of conversion characters format format string timeptr pointer to tm structure Return Value Number of characters written Number of characters written into s is smaller than or equal to maxsize 0 Number of characters written into s is larger than the maxsize contents is unknown Description As the locale only the C environment is supported The strftime function converts the broken down time of the tm structure specified by timeptr according to the format specified by format and stores the conversion result into s The maximum number of characters to be stored into s is the number specified by maxsize The following lists the conversion specifiers that can be used in format Any conversion specifier not included in the table makes operation result unknown 1 2 Conversion Description Specifier a Abbreviation for the day of the week in the locale A The name of the day of the week in the locale b Abbreviation for the month in the locale B The name of month in the locale oC Representation of the date and time appropriate in the locale d Representation of the date of a month integer 01 through 31 CC32R MANUAL 276 Chapter 9 C Standard Library 2 2 Conversion Description Specifier H Repres
265. j The variable i is preset to RO and the variable j preset to R1 If no argument is specified the contents of RO and R1 are unknown 7 5 3 Limitations of asm Function When writing the asm function take the following limits into consideration e Limited register usage The asm function can normally recognize four registers RO R3 When using the other registers and the accumulator in the asm function the user program must assure that the contents of the register are recovered after the function releases the register To do so save the contents of the register before the asm function uses it and then return the contents to the register upon releasing of the register by the function Example Saving and recovering of register R4 within asm function asm ST R4 sp n Save R4 M a ENNEN n Any process using R4 LD R4 spt n Restore R4 e Limits during compiling optimization specified During optimization the compiler deletes unnecessary codes and replaces and substitutes instructions When compiling and specifying optimization of the source file using the asm function take into consideration the effects of optimization by the C C compiler CC32R MANUAL 142 Chapter 7 Embedded Applications Programming Error check considerations The C C compiler does not check the contents of the assembly code used in the asm function If the asm function contains invalid assembly code the error is detec
266. j floating point number Return Value The remainder of x y Description The fmod function calculates the remainder of x y and returns the result as a double type The return value assumed as f has the same sign as the dividend x the absolute value of f is smaller than the absolute value of the divisor y and the following expression is satisfied x y i f where i is some integer If the quotient of x y cannot be expressed e g when y 0 any result is not guaranteed CC32R MANUAL 197 Chapter 9 C Standard Library fopen Opens a file Input output function Syntax Return Value Description include lt stdio h gt FILE fopen const char fname const char mode fname file name mode file access mode Pointer to opened stream Successful NULL Error The fopen function opens a file specified by fname Set any of the following file access modes to the argument mode Access Mode Meaning re Opens a file for reading w Opens a file for writing an Opens a file for appending Tepr Opens a file for reading and updating w Opens a file for writing and updating rate Opens a file for appending and updating A file is opened in a text mode The file can be opened in a binary mode by adding b after the access mode designation Example r b If any file to be opened is not found in the writing mode or reading mode a new file is created If
267. ject declared as const by a value other than const on the left hand side that is if you attempt to process an area declared as const by a cast or the like as if it is not const the operation is not guaranteed there can be instances in which no error occurs If you attempt to change an object declared as volatile by a value other than volatile on the left hand side that is if you attempt to process an area declared as volatile by a cast or the like as if it is not volatile the operation is not guaranteed there can be instances in which no error occurs e ANSI C 6 5 7 Initialization If you use an object that has a non initialized automatic storage duration before assigning a value to it there can be instances in which a warning such as an error is not issued It value is indeterminate There can a chance that a warning such as an error is not issued in the instances given below but the operation is not guaranteed e An instance in which an object of either aggregate type or union type having a static storage duration has an initial value that are not enclosed in a pair of braces e An instance in which an object of either aggregate type or union type having an automatic storage duration has either an initialization expression of the type of the object or an initial value that are not enclosed in a pair of braces e ANSI C 6 6 6 4 The return statement If a function s value referenced is not returned from the fu
268. jmp The setjmp function saves the current calling environment in env into the specified memory area By using this function in conjunction with the longjmp function a global jump to outside the function can be achieved This function is used to pass the error handling execution control to the previously called routine without using the normal function calling or return convention When the setjmp function is called with a complex expression a portion of current execution environment such as the temporary result of an expression evaluation may be lost To avoid this use the setjmp function only for the purpose of comparing the result of the setjmp function and a constant expression and don t call this function in a complex expression In using the setjmp function the general purpose registers are saved recovered by contrast the accumulator ACC and the control registers are not saved recovered CC32R MANUAL 264 Chapter 9 C Standard Library set l oca l e Localization function Sets and searches for locale information Syntax Return Value Description include lt locale h gt char setlocale int category const char locale category portion of locale to be set search locale locale to be set The pointer to the available string for locale Successful locale will not be returned NULL Both category and locale are invalid As the locale only the C environment is su
269. l the _call_main function 7 3 9 Processing the Call_Main Function Since the C language does not allow the main function of a user program to be called from the startup process call the main function via the _call_main function CC32R MANUAL 133 Chapter 7 Embedded Applications Programming 7 3 10 Start up Program Example The following shows an example of the start up program e Start up program start ms In this sample program the basic processes 1 to 5 are performed by the assembly program starting with the STARTUP KKK KKK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK KK KKK KKK KKEKKKK KK COPYRIGHT C 2004 RENESAS TECHNOLOGY CORPORATION AND RENESAS SOLUTIONS CORPORATION ALL RIGHTS RESERVED start ms cc32R startup and low level sample program i Contents 1 Sample startup routine i 2 Stack memory area H 3 Sample low level routine 4 Reset vector area NOTES This startup sample never set addresses for all sections expect RI Reset Vector Table section then you have to set address by SEC option by link32R M32R linker ekkxkxk xkxkxkxkxkxkkxkkkkkkkkxkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkxkxk r USTACKSIZE EQU H 1000 ISTACKSIZE EQU H 1000 export STARTUP export HALT import _cpp_main import TOP_B END_B import TOP_D END_D import __TOP_COMMON __END_COMMON import TOP_ROM_D END_ROM
270. lculates an absolute value of int type Any operation cannot be guaranteed if the result cannot be expressed in the int type CC32R MANUAL 176 Chapter 9 C Standard Library aco S Mathematics function Obtains the arc cosine of a floating point number Syntax include lt math h gt double acos double x x Return Value Calculated value of argument Description The acos function calculates the arc cosine of argument x and returns a value in a range from 0 to z Value x must be in a range between 1 and 1 This function sets a value of EDOM in errno if x is less than 1 or more than 1 as ct i me Date and time function Converts data and time a struct tm into the equivalent text string Syntax include lt time h gt char asctime const struct tm timeptr timeptr pointer to tm type structure Return Value Pointer for a converted character string Description The asctime function converts the time and date specified by timeptr into the format as follows Thu May 12 16 00 00 1995 n 0 CC32R MANUAL 177 Chapter 9 C Standard Library as i n Mathematics function Obtains the arc sine of a floating point number Syntax include lt math h gt double asin double x x Return Value Calculated value of argument Description The asin function calculates the arc sine of argument x and returns a value in a range from 1 2 to 7 2 Value x must be in a range between 1 and
271. le precision mathematic functions Function Corresponding C language formats of prototype declarations math h Those do not use Those that use functions the FPU instructions the FPU instructions float cosf float float cosf5 float Cosine cos float sinf float float sinf5 float Sine sin float tanf float float tanf5 float Tangent tan float acosf float float acosf5 float Inverse cosine acos float asinf float float asinf5 float Inverse sine asin float atanf float float atanf5 float Inverse tangent atan float atan2f float float float atan2f 5 float float Inverse tangent atan with division float coshf float float coshf5 float Hyperbolic cosine cosh float sinhf float float sinhf5 float Hyperbolic sine sinh float tanhf float float tanhf5 float Hyperbolic tangent tanh float powf float float float powf5 float float Power pow float sqrtf float float sqrtf5 float Positive square root sqrt float ceilf float float ceilf5 float Integral value with ceil fractions rounded up float expf float float expf5 float Exponential function exp float fabsf float float fabsf5 float Absolute value fabs float floorf float float floorf5 float Integral value with floor fractions rounded down float fmodf float float float fmodf5 float float Remainder fmod float frexpf float int float frexpf5 float int Resolve into 0 5 1 0 rexp values and power of 2 float ldexpf float int float ldexpf5 float int Mu
272. ler Table 3 6 Command Options for the C Compiler 10 11 Description For access to the symbols of D and B sections located in RAM this option outputs load store instructions by register relative indirect addressing Access to symbols are performed in register relative indirect addressing mode via the fixed register R12 When using this option pay attention to the precautions below 1 Set the R12 register and define the __REL_BASE symbol 2 If the total size of D and B sections exceed 64 Kbytes do not use this option 3 For const qualified variables located in C section to be referenced in another source a prototype accompanied by const must always be declared 4 Do not destroy the content of the R12 register Also refer to Section 3 2 2 for more information about this option XX symbol_num This option allocates memory for symbols that are required when compiling The required memory size is expressed by a number of symbols which is specified in symbol_num The default value of symbol_num is 40 000 Specify this option when compiling a source file such as middleware which has more than 40 000 symbols small small medium large memlarg These options specify the memory model in which to compile If none of these options is specified the source file is compiled in small model small The option small specifies that the source file be compiled for the small model both code and data s
273. ling and the handling at program startup for each signal recognized by the signal function gt They are depend on the user defined signal function a low level function lt lf the equivalent of signal sig SIG_DEL is not executed prior to the call of a signal handler the blocking of the signal that is performed gt It is depends on the user defined signal function a low level function lt Whether the default handling is reset if the SIGILL signal is received by a handler specified to the signal function gt It is depends on the user defined signal function a low level function e ANSI C 7 9 2 Streams lt Whether the last line of a text stream requires a terminating new line character gt Whether the line feed character is required depends on the specifications of the read function and the write function low level functions you prepare Functions in the C standard library used for calling them are so designed that they operate properly though the line feed code is missing from the last line lt Whether space characters that are written out to a text stream immediately before a new line character appear when read in gt Whether the null character is output depends on the specifications of the read function and the write function low level functions you prepare lt The number of null characters that may be appended to data written to a binary stream gt No null characters are appended to a binary stream
274. link only the objects written in C or assembly language the Ink32R can be started directly without causing any problem e Librarian lib32R The lib32R generates an M32R compatible library file from object modules or relocatable load modules When creating a library file do not start the librarian lib32R directly Even when creating a library file make sure the librarian is started through the compile driver cc32R by using the mklib option To create a library file with only the objects written in C or assembly language the lib32R can be started directly without causing any problem e Map generator map32R The map32R outputs a link map which consists of a map list and global symbol list from an object module an relocatable load module and an absolute load module e Load module converter Imc32R The Imc32R converts a load module generated at the linker into the S format load module ROMable This tool is necessary to write a program into ROM e Debug information discarding utility strip32R Debug information discarding utility strip32R is added The strip32R cuts and discards the debug informations from SYSROF format load module files that the linker generates and object files that the compiler or the assembler generate CC32R MANUAL 3 Chapter 1 Overview of CC32R Components of CC32R 1 4 1 Programming Flow The programming flow using CC32R is shown in Figure 1 1
275. linker To correspond to the new function a part of object format has been changed Accordingly if you have the object that was made with old CC32R V 2 10 Release 1 or older when you input them to new linker CC32R V 3 00 Release 1 or newer this linker displays a warning message like the following Ink32R filename warning old interface module revision 01 In this case please remake these objects by using the new CC32R e Problems encountered when linking objects of V 1 00 Release 3 or earlier An error relocation out of range may be encountered when linking some objects generated by CC32R V 1 00 Release 3 or earlier by the linker in V 1 00 Release 4 or later including this version In such a case regenerate the objects using the assem bler in V 1 00 Release 4 or later CC32R MANUAL 13 Chapter 3 Invoking the Compiler Chapter 3 Invoking the Compiler 31 How to Invoke the Compiler 3 1 1 Invoking Procedure To invoke the C C compiler first set the environment variables see 3 1 2 enter the cc32R command according to the command line rules and execute it see 3 1 3 3 1 2 Setting Environment Variables Set the valid directories for the environment variables M32RBIN M32RINC M32RLIB and M32RTMP This step may be skipped since these variables are normally set during installation For the setting procedure refer to CC32R Installation Guide If you do not set the directories the
276. local variable area 7 Return to the caller 8 Free argument area The local variable area reserved at the entry of a called function see 3 Allocate local variable area above is released That is the size of the area is added to the SP The return address stored in the link register is reset in the Program Counter returning process control to the calling side program Once the control is returned the size of the argument area is returned back to the SP releasing the argu ment area CC32R MANUAL 105 Chapter 6 C C Calling Conventions 6 4 Parameter Passing C C compilers generally use register passing to pass arguments when a function is called If the function takes five or more arguments or if the function s arguments include floating point types double long double structure types or union types etc stack passing is used The following describes how to set the arguments 6 4 1 Rules Parameter Passing By register passing actual arguments to a function are passed via the registers R4 to R7 The first 4 arguments are stored in R4 R7 one by one in the order declared by the functions For example if only two arguments are declared only two registers R4 and R5 are used Once the function is called by register passing the values in RO R7 are not guaranteed The arguments that can pass into the registers are those of character integer pointer and float types Example int func a
277. lt If a conversion result overflows this function sets a value of ERANGE in errno and returns HUGE_VAL as a return value fa b S Mathematics function Obtains the absolute value of a floating point number Syntax include lt math h gt double fabs double x Xx floating point number Return Value Absolute value of x Description The fabs function returns the absolute value of x CC32R MANUAL 191 Chapter 9 C Standard Library fc l O se input output function Closes a file Syntax include lt stdio h gt int fclose FILE fp fp pointer to FILE structure Return Value 0 Successful EOF Error Description The fclose function closes the I O stream specified by file pointer fp If an output file of the I O stream is opened and if any data not yet output still remains in the buffer this function outputs it to a file and closes the file If the I O buffer is assigned automatically by a system this function release it Moreover if the stream is opened by the tmpfile function this function deletes the corresponding file feof input output function Checks if the end of a stream is reached Syntax include lt stdio h gt int feof FILE fp fo pointer to FILE structure Return Value 0 When a file is not ended non 0 When a file is ended Description The feof function judges whether the I O stream specified by the file pointer fp is ended or not The fe
278. ltiply power of 2 ldexp float logf float float logf5 float Natural logarithm log float logl0f float float logl0f5 float Base ten logarithm log10 float modff float float float modff 5 float float Resolve into integral modf and fractional parts Specifications for these single precision mathematic functions have been determined based on the C standard double precision mathematic functions according to the rules described below 1 Operation The basic operations of these functions are the same as each double precision mathematic functions from which they have been CC32R MANUAL 355 Chapter 12 Single precision Mathematical Function Library derived except that internal arithmetics are performed with the type float 2 Function name The functions that do not use the FPU instructions are named after the double precision mathematic functions from which they have been derived by adding the letter f to each The functions that use the FPU instructions are named in the same way by adding the string f5 to each 3 Type of argument and return value The arguments and return values have their types changed from double to float KA Using the Library 12 2 1 Header File Before the single precision mathematic functions can be used one of the following header files must be included Choose either one that suits to your need mathf h When you use only the single preci
279. lue lt lt expr shift left and assignment operator gt gt lvalue gt gt expr shift right and assignment operator CC32R MANUAL 54 4 1 6 Punctuators Chapter 4 C Programming Language Specification Table 4 0 Operators 4 4 Operator Usage and Note Description amp Ivalue amp expr bitwise AND and assignment operator Ivalue expr bitwise OR and assignment operator lvalue expr bitwise XOR and assignment operator throw throw expr throw exception j expr expr sequencing Punctuators direct other tokens or specify a range The punctuators in Table 4 11 are available Punctuators Table 4 11 Punctuators Applications Declaration of array Declaration of function or variable Member declaration of structure or union Punctuation of initial value Declaration of pointer Punctuation of initial value Punctuation of parameter of function Declaration of bit field Punctuation of label Start of initial value End of declaration or statement Declaration of prototype of function used when the number of parameters is variable and J and and are used as a pair An expression may be sandwiched between them A punctuation character can be recognized as an operator depending on how it is written CC32R MANUAL 55 4 1 7 Comment Chapter 4 C Programming Language Specif
280. macro xxx array subscript requires combination of pointer to object type and integral type An array must be a combination of pointers and entities of integer type at most one storage class specifier per declaration Two or more storage class specifiers are present in a declaration you can specify only a single storage class specifier in a declaration auto must appear within a function You must declare an auto variable within a function badly punctuated parameter list in define An improper character is present in an argument of define bit field members must have integral types A member of bit field must be of integer type bit field size must be integral constant expression A bit field size must be specified by an integer constant bit field size must not be negative A bit field size must be specified by a positive number CC32R MANUAL 373 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 2 15 Message Description bit field size too large A size specified for a bit field is too large block scope initialization not allowed for external declaration You must not initialize an external variable within a block break statement in invalid context You cannot use break here call to non function attempted You have attempted to perform a function call to an entity that is not a function cannot const a function type object You cannot make a const declaratio
281. mance with the ANSI Standard e Keywords see 4 1 1 e Identifiers see 4 1 2 e Constants see 4 1 3 e String Literals see 4 1 4 e Operators see 4 1 5 e Punctuators see 4 1 6 e Comment see 4 1 7 CC32R MANUAL 42 Chapter 4 C Programming Language Specification 4 1 1 Keywords A keyword is used as a reserved word in the C C language In translation phases of the compiler the words in Figure 4 1 are keywords and and_eq asm auto bitand bitor bool break case catch char class comp1 const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto Le inline int long mutable namespace new not not_eq operator Ors or_eq private protected public register return reinterpret_cast short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while xOr xor_eq Figure 4 1 Keywords ITI NOTE Marked with are the C language only keywords CC32R MANUAL 43 Chapter 4 C Programming Language Specification 4 1 2 Identifiers C language only Identifiers are names listed as follows e Function name Variable name e Label name e Tag name of a structure union or enumeration e Member name of a structure union or enumeration e Macro name e Object name e Typedef name
282. mbers The size of a union is the maximum size of a member If the alignment of the union is 2 bytes or 4 bytes and the largest value is not a multiple of alignment the area of the union is set to a multiple of the alignment The size of the union is always a multiple of the alignment Examples 1 to 3 show the internal presentation of union type data e Example 1 Coding Internal Representation Alignment union ul char a char b 3 x1 3 bytes x1 a aS ee que queen ann x1 b 0 x1 b 1 x1 b 2 The alignment of each member is 1 byte and therefore the alignment of the entire union is 1 byte The size is 3 bytes CC32R MANUAL 84 Chapter 5 Internal Data Representation Example 2 Coding Internal Representation Alignment Example 3 Coding Internal Representation Alignment union u2 char a int b short c x2 ET 4 bytes x2 a Mm C ess qx l x2 b X2 C One member has 4 byte alignment and therefore the alignment of whole union is 4 bytes The size is 4 bytes union u3 short a char b 3 x3 x3 b 0 x3 b 1 x3 b 2 1 byte One member has 2 byte alignment and therefore the alignment of whole union is 2 bytes Since the size of the member having the largest location is odd byte a 1 byte of memory space is added and the size becomes 4 bytes CC32R MANUAL 85 Chapter 5 Internal Data Representation Ea Enumeratio
283. me h Declaration of the date and time handle functions Date and time function CC32R MANUAL 148 Chapter 8 Standard Header Files 8 2 Contents of the Header Files The section describes standard library functions declared or defined in standard header files To use these functions the associated header file must be included The macros defining limit values are listed The header files are listed in the alphabetical order 8 2 1 8 2 15 8 2 1 assert h Defines the program diagnostic function assert macro definition with parameter 8 2 2 ctype h Prototype declaration and macro definition of the character handling function These functions are listed in Table 8 2 Table 8 2 Functions Declared by ctype h Function Description Reentrant isalnum Judges whether a letter or decimal digit O isalpha Judges whether a letter or not O iscntrl Judges whether a control character or not O isdigit Judges whether a decimal digit or not O isgraph Judges whether a printable character other than space O islower Judges whether a lower case letter or not O isprint Judges whether a printable character including space O ispunct Judges whether a special character or not O isspace Judges whether a white space or not O isupper Judges whether an upper case letter or not O isxdigit Judges whether a hexadecimal digit or not O tolower Converts an upper case letter into lower case O toupper Converts
284. ment 9 2 1 Library Building Procedure 1 2 3 4 Prepare a command prompt which has had environment variables set Prepare any working directory Go to the directory prepared in 2 we Dawa YH Specify a library name and compile option to start libg32R as in the example shown below Example startup To create a library in the name m32RcR lib as a small model optimized for speed libg32R m32RcR lib small Otime library name code generation option If the library has been successfully created the files listed below are created in the directory 2 m32RcR lib Library m32RcR stk Stack usage indication file CC32R MANUAL 172 Chapter 9 C Standard Library Caution e If the directory in which libg32R was executed contains a file with the same name as that of the library or the stack usage indication file the existing file is overwritten e The specifiable code generation options are limited to a combination of the following options No other options can be specified access Access control file constr D lt name gt D lt name gt lt def gt exception float_only large _medium noexception noinline 0 lt priority gt Ospace Otime 0 lt level gt S00 0L seez O7 R lt old gt lt new gt rel16 rtti off rtti on small strict_standard switch_by_offset U lt name gt zdiv lt lt Reference gt gt List of libg32R command line specifications usa
285. mory Non function objects 1 Global variables 2 static global variables 3 extern global variables Objects in functions 4 static variables in functions 5 static variables in blocks A 1 3 2 Object types The following types of objects are targeted by the base register function 1 Integer types char short long signed unsigned enum 2 Floating point numbers float double 3 Structures including bit field members Appendix A 4 Appendix A Extended Functions Reference 4 Unions 5 Arrays 6 Pointers A 1 3 3 Types of type qualifier The following object type qualifiers are targeted by the base register function 1 No type qualifier 2 Volatile A 1 4 Objects Not Targeted by Base Register Function A 1 4 1 Types of types and derived types etc 1 Member names Structure type names can be specified 2 Functions 3 Constants A 1 4 2 Memory classes and storage 1 static variables in functions or in blocks that have the same name as those in objects not in functions 2 Global variables with names the same as objects in functions 3 auto 4 5 typedef register A 1 4 3 Qualifiers 1 const Appendix A 5 Appendix A Extended Functions Reference A 1 5 Setting Base Symbols and Base Registers With the base register function the compiler s output code does not 1 Definition of base symbol or 2 Initialization of base registers These operations must th
286. mp _900_init_env __call_terminate F else 4 exit_code _100_C_get_exit_code endif EXCEPTIONS if _900_exit_stdio_func_ptr _900_exit_stdio_func_ptr terminating stdio library if _900_exit_mem_func_ptr _900_exit_mem_func_ptr terminate memory library _exit exit_code endif defined __M32R__ e Startup program call _main c In this sample program a program part that executes the basic process 9 is written as a C language program extern int main extern int _call_main void int _call_main void return main CC32R MANUAL 139 Chapter 7 Embedded Applications Programming 74 About start up file start ms in HEW The Hew generates a file start ms when creating new project This file was modified from one that was using with the TM and the User s Manual Fundamentally the contents of these start ms are nearly equal However the start ms HEW generated can be controled by the assembler as32R with setting following paramter into D option If you will modify this start ms be careful in this point Table 7 3 Meaning of control symbols of start ms the HEW generated SymbolName ltem name of Means Initial HEW project Name value creating dialog _ STANDARD IO _ Use Standard I O Decides whether or not that 0 Library the start ms initializes the The stand standard library before calling ard library
287. mple acc to the compiler command line Example output code The following shows the code for varl and var4 resulting from compiling the program with sample acc specified and var1 and var4 as int type global variables e C language Expression 1 varl 5 writing var1 Expression 2 return var4 reading var4 e Output code when applying base register function Expression 1 LDI RO 5 ST _RO _var1 __REL_BASE13 R13 Expression 2 LD RO0 _var4 __REL_BASE12 R12 Appendix A 13 4 5 Appendix A Extended Functions Reference Defining the base symbols and setting the base registers Next add the code for a defining the base symbols and b setting the base registers in the startup program The base address is represented by the base symbol __REL_BASExx where xx is the base register number This symbol is required for calculating the offsets when generating the code See Example output code in step 3 Compiling In the following example the settings are for base registers R13 R12 and R11 a Definition of base symbols b Setting base registers Note e As with the Access Control File a base register setting program can also be automatically generated by map32R See Section 2 map32 Map Generator in the CC32R User s Manual lt Assembler gt for details Linking Link the component programs including the program created in step 4 Appendix A 14 Appendix A Extend
288. n Chapter 5 Internal Data Representation This chapter describes memory allocation of C C program data for various types Data Representation on Memory EAM Data Representation on Memory Representation of C C language data on memory is determined by the following items Data size Function of data Memory size occupied by data Relationship between data contents on memory bit pattern and C C language data value Defines the range of value of scalar type data and allocation of aggregate type data elements e Alignment of data adjusting boundaries If a data item is put in a location having an address of a multiple of an integer either 2 or 4 there can be instances in which you can access it quickly though this depends on the type of data This integer is termed alignment The C C compiler allocates data according to the alignment in compliance with its type A data item whose alignment is an integer n is dealt with as n byte alignment In this instance an address of a multiple of n is called either alignment boundary or n byte boundary An n byte alignment data item is not allocated across its alignment boundaries n byte boundaries CC32R MANUAL 75 Chapter 5 Internal Data Representation 5 2 Integral Types Table 5 1 lists integral types used in C language Table 5 1 Internal Representation of Integral Types Type Size Al
289. n the operation is not guaranteed CC32R MANUAL 299 Chapter 9 C Standard Library va_sta rt M ac ro Variable arguments access function Initializes to reference variable arguments Syntax Return Value Description include lt stdarg h gt void va_start va_list ap parmN ap pointer to variable parameter list parmN the rightmost identifier in parameter list None By using macros va_start va_arg and va_end the arguments of the function having variable parameters can be referenced The va_start macro initializes the ap used by the va_arg and va_end macro The parmN is the identifier indicating the rightmost parameter in the parameter list of the external function definition namely the identifier just before the variable parameter list To reference an unnamed parameter of the variable parameters first call the va_start macro CC32R MANUAL 300 Chapter 9 C Standard Library vfprintf Input output function Outputs a variable argument list to a stream by following the format Syntax Return Value Description include lt stdarg h gt include lt stdio h gt int vfprintf FILE fp const char control va_list arg fo pointer to FILE structure control pointer to format string arg pointer to variable argument list Number of characters output Successful Negative value Output error occurs The vfpri
290. n Limitations cccsscceceseceeceeeeeeseeeeeeseeeeeeseneesenseeeseeeeseseees 6 AA The Access Control Fil jiccicssociesset ccliciinit wesietictendeecinuecntdsdeesian deste endian 7 ATZI Comems of the Access Control File sz saccikassasinssesedevcdcucenstantesctaeieenateavinibesieceyaasianea 7 AA 2 The Access Control File Sy Max ssns 8 A 1 7 3 Hints on describing the Access Control File ceeeceseesseeeeseeeeceeeeaeeeeeeaeeeeeeaeeaees 9 A 1 8 Example of Using Base Register Function cecceeeseeeeeeseeeceeeseeeeeeeeeeeeeeeeeeeeenaes 11 A 1 8 1 Example Use of Base Register Function siicissssicscessascsscsivsntsaccusonsenvsiacenssbervereseeecsnes 11 Ace Memon Modol sscxciitieca ieciesonieiacinercn mesa nindeconsanbasiaeieca sina aioanuanina 15 Aces About Memory Modelsiicincnictiiitkin ee et ee LA ee 15 A 2 2 Detailes of Memory Models cccccccceeeneeeeseeeeeeneeeeeeneeeceaeeeecaeeesseaeeeseaeeeseneeeseaes 15 AS f pragma Extended FUNCIONS sssnccienedc czalududecseso taudendaeginacecse aa 19 A 3 1 List of pragma Extended Functions cccccccccceeeeeeeeeeeeeeecneeeeeesesenaeeeeeesenneeeeeeees 19 AA Inline xpanSlOMn asinna anda eee 29 A 5 M82R ECU 5 M32R FPU core Compatible Function cccscecessteeeeeeneees 33 ASI OptomdesignatioM sss eaea aparia eae oasi 33 A52 Utilize FRU Instruction Effectively inssin rnr ran siat 33 A53 Precautions in Utilizing FPU INStHUCHOM sspea
291. n Obtains the number of bytes composed of multibyte O characters mbstowcs Converts a multibyte character string into a wide O character string mbtowc Converts a multibyte character into a wide character O qsort Performs sorting O Depends on comparison function CC32R MANUAL 165 Chapter 8 Standard Header Files Table 8 20 Functions Declared by stdlib h 2 2 Function Description Reentrant rand Generates a pseudo random integer which resides Xx between 0 and RAND_MAX realloc Changes the memory area size to the specified size srand Sets the initial values of the pseudo random integers which the rand function generates strtod Converts a string into a double type floating point Xx number strtol Converts a string into a long type integer x strtoul Converts a string into an unsigned long type integer Xx system Passes a command string to the host environment Depends on user description wcstombs Converts a wide string into a multibyte string O wctomb Converts a wide character into a multibyte character O Table 8 21 Macro Defined by stdlib h Macro Name Description RAND_MAX Indicates the maximum value of a pseudo random integer generated by the rand function Table 8 22 Data Type Declared by stdlib h Data Type Description div_t Indicates the type of structure of the value div function returns ldiv_t Indicates the type of structure of the value Idiv function returns CC32R MANUAL 166
292. n Types The internal representation of an enumeration type is the same as that for an int type Table 5 5 Internal Representation of Enum Type Type Size Alignment Signed Minimum Value Maximum Value enum 4bytes 4bytes Yes 2 2147483648 2 1 2147483647 The value of the enumeration type member s name starts with 0 and subsequent integers in that order with 0 given to the member which first appears e Example enum a b c The value of the members a 0 b 1 c 2 CC32R MANUAL 86 Chapter 5 Internal Data Representation EI Pointers The value of a pointer type data represents the address of the location at which the data or function is stored The pointer type data is 4 bytes Table 5 6 Internal Representation of Pointer Type Type Size Alignment Signed Minimum Value Maximum Value Pointer 4bytes 4bytes No 0 2 1 4294967295 Pointers to a data members 4bytes 4bytes Yes 0 2 1 4294967295 Pointers to functionand 8bytes 4bytes virtual function members e Pointer The C C compiler handles pointer type data as unsigned data If pointer type data needs to be used as a signed logical address value convert its type to type int before use Pointer 4 bytes Figure 5 2 Pointer Type Data e Pointers to function and virtual function members Pointers to function and virtual function members are represented by classes in the following data structure class PMF
293. n about the Handling of Development Support Utilities For details on how to use it refer to the file in which a description is made of Absolute Listing Utility abslist sj CC32R MANUAL 11 Chapter 2 Overview of cc32R O Stack size calculation utility stk32R We provide the Stack size calculation utility stk32R The utility stk32R processes the stack amount usage files output by the compiler stack option added to find the stack size required for program operation Also available are the stack amount usage files m32Rc stk m32RcR stk etc for the functions registered in C standard libraries m32Rc lib m32Rck lib etc To enter the stack amount usage file for the program that calls library functions in stk32R specify in I option the stack amount usage files present in the library file used Note that correct values cannot be obtained for the functions pow and setlocale because these are recursive call functions The values in the files are for reference purposes only The utility stk32R is not a standard product of the compiler For details on how to handle it refer to the file written about the Handling of Development Support Utilities For details on how to use it refer to the file in which a description is made of Stack Size Calculation Utility stk txt CC32R MANUAL 12 Chapter 2 Overview of cc32R 2 2 Compatibility with an old version e About inputting old CC32R s object V 2 10 Release 1 or older to new
294. n array contains an element that has been initialized to 0 calling a non function object xxx The source code contains an attempt to call the object xxx that is not a function ch illegal escape sequenc An escape sequence is improper xxx conflicts with prior option ignored The option xxx conflicts with prior option The prior option takes effect constant out of range due to unportable conversion A constant may fall outside the range of the type when porting xxx empty macro definition regarded as empty The D option lacked the macro definition No definition is given after D xxx EOF in character constant constant truncated EOF is contained in a character constant The constant is truncated EOF or NUL in string literal string truncated Either EOF or NUL is contained in a character string literal The character string is truncated fewer arguments specified than in imputed definition There is shortage of arguments designated floating point number overflow A floating point number has overflowed floating point number underflow A floating point number has underflowed CC32R MANUAL 368 Chapter 14 Messages from the C Compiler Table 14 4 Warning Messages 2 4 Message Description function called before declared A function is called before declared function does not return value with defined return type A function has not returned a
295. n named as the same name as one of C standard library functions which conforms to the ANSI C specifications It is not recommendable 9 1 4 Library Error Message Some library function sets an error number in errno defined in the standard header file errno h when an error occurs during execution of the library function An error message is defined by the error number and such an error message can be output An example of program to check errno is shown below include lt stdio h gt include lt math h gt include lt errno h gt include lt string h gt void main void double x a 2 0 x asin a if errno EDOM printf Ss n strerror errno print error message Figure 9 1 Example of Checking errno In the example in Figure 9 1 an arc sine value of a number is calculated through the asin function When an argument a exceeds the domain 1 1 of the asin function a value EDOM is set in errno and therefore an error message is output by the printf function When an error number is passed as a real argument the strerror function returns a string pointer to the corresponding error message CC32R MANUAL 171 Chapter 9 C Standard Library 9 2 Rebuild to Method of Standard Library The source environment of the standard library is attached Using this environment the library can be created using any code generation option Explain the procedure of creating a library using this environ
296. n on an entity of function type cannot initialize a typedef variable You cannot perform initialization when making a typedef declaration cannot start or end with operator The operator must not lie at the beginning or the end of a replacement character string list cannot typedef function definition You cannot make typedef declaration on a function definition case label must be an integral constant expression You must specify an integer constant expression for case case or default label in invalid context You can use neither case nor default here cast type must be void or scalar type You must specify either void or an entity of scalar type for cast character constant must fit its storage range The value of a character constant must be within a proper range constant expression evaluated out of range The value of a constant expression has exceeded a proper range CC32R MANUAL 374 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 3 15 Message Description constant should fit its storage range The value of a constant must be within a proper range continue statement in invalid context You cannot use continue here controlling expression of if statement must have scalar type An expression within an if statement must be of scalar type controlling expression of iteration statement must have scalar type An expression within an iteration statement must b
297. n optional place A character and character string are inserted in an optional place The forwarding of a character string is discontinued halfway A character is searched from an optional place A string is compared with other string from an optional place A 6 4 3 Attention on standard function use The following functions are supposing always that LC_CTYPE is C locale Therefore pay attention in the case that the string or character including the Japanese character is processed with these functions Appendix A 41 Appendix A Extended Functions Reference 1 Character string operation function Function that belongs to string h Because this function does not know boundary between multi byte characters if a multi byte character has Japanese Kanji character the function does not act along to expectati on memchr strchr strpbrk strrchr functions The searching may not act normally strcspn strspn functions The exact character number may not be returned 2 Character operation function Function that belongs to ctype h This function can not process it normally in the case that the Japanese character is desig nated Example Do not call a function as follows isprint L j isupper L A Zenkaku A A 6 4 4 Correspondence of the assembler Japanese is unable to be described with assembly language A 6 4 5 Correspondence of the relation tools If the debugger that is for CC32R V 3
298. n the range of 0 to RAND_MAX CC32R MANUAL 257 Chapter 9 C Standard Library realloc General utility function Changes the memory area size to the specified size Syntax Return Value Description Note include lt stdlib h gt void realloc void ptr size_t size ptr pointer to the memory area to be changed SIZE size bytes of the changed memory area The start address Memory area is allocated of the allocated memory area NULL Memory space is not allocated or successfully freed size is 0 ptr is not 0 The realloc function changes the size of the memory space indicated by ptr to the bytes denoted by the size If the changed memory size is smaller than before the contents is unchanged up to the changed memory size If the space denoted by ptr of the realloc function is not allocated by the calloc malloc or realloc function or the space is already freed by the free or realloc function the operation is not guaranteed When pir is NULL the realloc function operates like the malloc function When size is 0 and ptr is not NULL the memory area is freed 12 bytes more area have been secured as memory area allocated by each the realloc functions This memory area of 12 bytes is stored a allocation infomation size etc CC32R MANUAL 258 Chapter 9 C Standard Library remove Deletes a file Input output function Syntax Return Value Descrip
299. n to a pointer toward a function of different type and if you call a function of a type incompatible with the original type the operation is not guaranteed You can cast a pointer toward a function to a pointer toward an object and you can cast a pointer toward an object to a pointer toward a function If you cast a pointer to an entity of non integer type non character type either or to an entity of non pointer type an error occurs in most cases The operation of program is not guaranteed even though no error occurs e ANSI C 6 3 6 Additive operation If you add subtract a pointer toward an array and if the pointer points toward an area outside the area for the array elements the value of the pointer is correctly derived no error occurs Referencing the content that a pointer points toward by use of the operator allows you to reference the data stored there The data is not an array element so the operation of program is not guaranteed CC32R MANUAL 311 Chapter 10 The cc32R s Behavior e ANSI C 6 3 7 Bitwise shift operators If you specify a negative number for the extent of a shift operation or a number greater than the bit width of the expression to be shifted the operation is not guaranteed An example of operation if you give a negative shift extent there can be instances in which the shift direction reverses If the shift extent is greater than the bit width of the expression to be shifted there can b
300. nction the function s value referenced is indeterminate e ANSI C 6 7 External definitions If you define two or more identical identifiers having external linkage and if they are included in one source an error occurs during compilation if they are separately included in two or more sources an error occurs during linking CC32R MANUAL 313 Chapter 10 The cc32R s Behavior e ANSI C 6 7 1 Function definitions If the parameter list in defining a function that accepts variable arguments doesn t end with and if an attempt is made to pass more arguments than the number declared in the parameter list an error occurs e ANSI C 6 7 2 External object definitions The identifier of an incomplete object having internal linkage is declared by an ambiguous definition the operation is not guaranteed there can be instances in which a warning is issued e ANSI C 6 8 1 Conditional inclusion The token defined that is generated during expanding the preprocessing directive for if or elif is dealt with as an operator e ANSI C 6 8 2 Source file inclusion If the preprocessing directive for include agrees with neither of two header files an error occurs e ANSI C 6 8 3 Macro replacement A macro call on a function sequence having no arguments results in a error A line that begins with a preprocessing directive if present in the actual argument list in a macro call is regarded as a preprocessing dir
301. ndicate the beginning and the end of a multibyte character for multibyte characters is not available CC32R MANUAL 324 Chapter 10 The cc32R s Behavior e ANSI C 5 2 4 2 1 Sizes of integral types lt limits h gt lt The number of bits in a character in the execution character set gt 8 bits e ANSI C 6 1 3 4 String literals lt The mapping of member of the source character set in character constants and string literals to members of the execution character set gt If the M32RKIN enviromen variable is not utf8 the arrange ment correspondence between the characters in the source character set and those in the execution charcter set is one to one Otherwise the characters that have same meaning and different character code may be changed to normalize with the character set of JIS X 0201 and JIS X 0208 lt The value of an integer character constant that contains a character or escape sequence not represented in the basic execution character set or the extended character set for a wide character constant gt If the M32RKIN enviroment variable is not utf8 the most right edge of 2 byte in this character will be combined by the big endian order Otherwise this character will be changed to Oxffff lt The value of an integer character constant that contains more than one character or a wide character constant that contains more than one multibyte character gt If this character constant is not wide
302. nerated by the compiler Virtual function table generated by the compiler 18 A getData1 Virtual function table generated by the compiler 0 B getData1 CC32R MANUAL 97 Chapter 5 Internal Data Representation e An empty class or an empty class that is having an empty class as its base class A 1 byte dummy area is assigned Coding class A void fun obj One byte Internal Representation Dummy area e An empty class that is having an empty class as its base class A 1 byte dummy area is assigned Coding class A void fun y class B void sub obj Internal Representation One byt Dummy area eA not empty class that is having an empty class as its base class Dummy area is not assigned Coding class A void fun y class B void sub obj Internal Representation Orne byte obj data1 CC32R MANUAL 98 Chapter 6 C C Calling Conventions Chapter 6 C C Calling Conventions This chapter describes the way C C compiler calls a C C program and how to interface with an assembly program Register Usage See 6 1 Stack Frame Configuration See 6 2 Call and Return Procedures See 6 3 Parameter Passing See 6 4 Setting Return Value See 6 5 Interface with Assembly Program See 6 6 Interface between C Program and C Program See 6 6 6 1 Register Usage
303. ng based on the current locale Syntax Return Value Description include lt string h gt size_t strxfrm char si const char s2 size_t nn sl buffer to store the converted string S2 pointer to string to be converted n number of characters converted The number of bytes of the converted string except the last null of the string Note When the return value is larger than the n the contents of s1 are unknown As the locale only the C environment is supported The strxfrm function converts n bytes of the s2 string starting at the beginning of the string according to LC_COLLATE specified by the current locale and stores the result into s1 CC32R MANUAL 289 Chapter 9 C Standard Library system General utility function Passes a command string to the host environment Syntax Return Value Description Caution include lt stdlib h gt int system const char string string command string non 0 string is NULL and command processor exists 0 string is NULL and no command processor exists Note If the command string is not NULL the return value depends on the processing system The system function passes the string specified by string to the host environment where the command processor runs When NULL is specified as string the function checks whether the command processor exists To call the system function in actual the user written
304. ng of the return value are performed by the run time library function _100_builtin_memcopy The _100_builtin_memcopy function is included in the ANSI C standard library m32RcR lib etc for stack passing parameters or m32RcR libsm32RcRM lib m32RcRL lib for register passing parameters Specify either one of these libraries when linking Code example that an error arises at link time struct s char xx 100 xy void foo void x y assignment of a structure CC32R MANUAL 39 Chapter 3 Invoking the Compiler e Notes on data access The C C compiler generates the code by selecting the optimum instruction for the size of the data type being accessed Therefore if your program attempts to access data that is not aligned via the pointer an address exception AE arises at run time This may also occur with the type of casting shown in the example below Code example in which an exception may occur long p char array 10 mapped to 4 byte boundary address void foo void p long amp array 1 address not on 4 byte boundary assigned as long p 1 access using the ST instruction but as address is not on 4 byte boundary an address exception AE occurs e Notes on setting the stack pointer For loading and storing data on the stack the C compiler outputs code for the LD ST LDH and STH instructions etc Therefore when you set a value into the stack pointer in th
305. ngth is to be measured Return Value Number of characters of the string measured Description The strlen function measures the length of the string s The null character indicating the end of the character is not counted CC32R MANUAL 278 strncat Chapter 9 C Standard Library Links the specified number of characters to the string Syntax Return Value Description include lt string h gt char strncat char si const char s2 sl pointer to string to be S2 pointer to string to be n number of characters to Pointer s1 of the linked string String handling function size_t n linked by linked to be linked to The strncat function links the string s2 to the end of the string s1 The last null character of the string s1 is replaced with the first character of s2 The last character of the linked string s2 is always followed by a null character The number of characters to be linked is specified by the parameter n CC32R MANUAL 279 Chapter 9 C Standard Library String handling function strncmp Compares specified number of characters of two strings Syntax include lt string h gt int strncemp const void si const void s2 size_t 7 Sl pointer to string to be compared S2 pointer to string used to compare nD maximum number of characters to be compared Return Value Positive value contents of s1 gt contents of s2
306. nl n2 ULONG64 notul64 ULONG64 n1 U inversion enl CC32R MANUAL 361 Chapter 13 A set of 64 bit integer arithmetic functions Table 13 1 64 bit integer arithmetic functions 3 Comparison and determination functions function name Perform Operation Prototype declaration of C language S signed Returns U unsigned Comparison int cmpl64 LONG64 nl LONG64 n2 S Comparison nl gt n2 gt positive int cmpul64 ULONG64 nl ULONG64 n2 U Comparison nl n2 gt 0 nl lt n2 gt negative Determination of whether or not 0 int evall64 LONG64 n1 S Determination nl 0 gt 0 lint evalul64 ULONG64 nl U Determination nl 0 gt not 0 Table 13 1 64 bit integer arithmetic functions 4 Type conversion functions function name Conversion Prototype declaration of C language Signed 64 bit integer lt gt unsigned 64 bit integer ULONG64 164_to_ul64 LONG64 input LONG64 gt ULONG64 LONG64 ul64_to_164 ULONG64 input ULONG64 gt LONG64 Signed 64 bit integer lt gt float or double float 164_to_float LONG64 input LONG64 gt float double 164 _to_double LONG64 input LONG64 gt double LONG64 float_to_164 float input float gt LONG64 LONG64 double_to_164 double input double gt LONG64 Unsigned 64 bit integer lt gt float or double float ul64_to_float ULONG64 i
307. nput ULONG64 gt float double u164_to_double ULONG64 input ULONG64 gt double ULONG64 float_to_ul64 float input float gt ULONG64 ULONG64 double_to_ul64 double input double gt ULONG64 Signed 64 bit integer lt gt long or unsigned long long 164_to_long LONG64 input LONG64 gt long unsigned long 164_to_ulong LONG64 input LONG64 gt unsigned long LONG64 long_to_164 long input long gt LONG64 LONG64 ulong_to_164 unsigned long input unsigned long gt LONG64 Unsigned 64 bit integer lt gt long or unsigned long long ul64_to_long ULONG64 input ULONG64 gt long unsigned long ul64_to_ulong ULONG64 input ULONG64 gt unsigned long ULONG64 long_to_ul64 long input long gt ULONG64 ULONG64 ulong_to_ul64 unsigned long input unsigned long gt ULONG64 CC32R MANUAL 362 Chapter 13 A set of 64 bit integer arithmetic functions Table 13 1 64 bit integer arithmetic functions 5 Other functions function name Perform Operation Prototype declaration of C language S signed U unsigned Immediate set LONG64 imml64 signed long shigh S Immediate set shigh lt lt 32 ulow unsigned long ulow ULONG64 immul64 unsigned long uhigh U Immediate set uhigh lt lt 32 ulow unsigned long ulow String to 64 bit integer conversion LONG64 strtol64 const char s S String gt Integer 64 bit version char endptr int b
308. nstant CC32R MANUAL 380 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 9 15 Message Description nonintegral initialization of bitfield An attempt has been made to initialize a bit field with an entity of non integer not first non whitespace character has been written in a position other than the beginning of a line not in any file _FILE_ cannot be expanded object with block scope and external or internal linkage can not be initialized You cannot initialize an object with external internal linkage only xxxa argument s to macro xxxb xxxc argument s expected There is a shortage of the number of arguments in a macro the macro xxxb requires xxxc arguments but no more than xxxa arguments have been specified only leftmost dimension of array may be incomplete The leftmost dimension of an array is incomplete only one default statement allowed per switch statement You can describe no more than one default statement in a switch statement operand of cast can not be type void The operand of a cast to void must have scalar type operand of equality operator has invalid type The type of operand of the equivalence operator is incorrect operand of has invalid type The type of operand of the operator is incorrect operand of has invalid type The type of operand of the operator is incorrect operand of must be mod
309. nstructors and destructors that are called for global class objects VTBL DATA ALIGN 4 An area used to store the data necessary to call a virtual function when any virtual function is found in a class declaration COMMON DATA ALIGN 4 An area used to store RTTI information and the internal static variables of inline functions CC32R MANUAL 121 Chapter 7 Embedded Applications Programming Note The section name and attributes can be defined as other than those in Table 7 1 by using the pseudo instruction SECTION assembler supported The use of SECTION are described in CC32R User s Manual lt Assembler gt For details on section name and attributes see CC32R User s Manual lt Assembler gt in Chapter link32R The linker assumes the sections are the same section when these sections have Note2 the same name and attributes It links these same sections and arranges them continuously in the load module as shown in Figure 7 2 Program 1 Object Module A Load Module Link _ gt P Program 2 Object Module B P c gt c c Program 3 Object Module C een Figure 7 2 Linking Sections by Sections Image when SEC D P C is specified The C C compiler permits the order in which sections are combined and the start address of each section to be specified by the startup option SEC or MEM The C C compiler observes these specifications as it determines the address of ea
310. nt pointer to int Converts a character sequence beginning with a sign or followed by u or U or 1 or L in decimal digit into integral data Considers a character sequence beginning with Ox or OX as a hexadecimal digit and converts the character sequence into integral data Considers a character sequence beginning with 0 as an octal digit and converts the character sequence into integral data pointer to int Converts a character sequence which represents an octal digit into integral data pointer to unsigned int Converts a character sequence which represents an unsigned decimal digit into integral data pointer to unsigned int x or X Converts a character sequence which represents a hexadecimal digit into integral data The x and X conversion specifiers are the same pointer to unsigned int Converts the initial part preceding the first appearance white space either a space a horizontal tab or a newline into a character string suffixing the null character The area pointed to the corresponding argument should be enough to store it including the null character pointer to char Inputs one character Then the input character is not skipped even if the character is a white space Specifying the field width allows to read specified number of characters Therefore the area pointed to the corresponding argument should be enough to store the characters pointer to char e
311. nt hdaasee see dbasendnedicans sh antebateauedooiameans 357 WS JD YMAMMIGMANGS Act2is cenczseceaues domeeecahe E D AOA AOE EEIEIE 357 123 2 Abouteror handing caesen E E 358 Chapter 13 The set of 64 bit integer arithmetic functions 359 Wel I AGeSr TG TONG OS erronea 359 ke RURMCUOM STUC sionais A ncegiuate cate venccateeenmecteene 359 13 3 Method for using the functions and example usage ceeeeeeeeeeeeteeeeeeeeeeees 363 WGA E E E heme weet 364 13 4 1 Precautions regarding the sign 0 ee eeeeseseeeeeseeeeeneeeeeeaeeeeseeeeseneeeeeeaeeeeseneesenaeees 364 Chapter 14 Messages from the C Compiler 365 14 1 Getting Execution Result of the C Compiler cccccessceeeeeeeeeeeeeeeeeeeeeetaeeeeneees 365 TAT Message Formal wisn sii eietkinecei aii oie eee eee 365 t412 MESSAGE TY POSS sensasine santos tad cansmctectest bes anaiai 366 WA AS EXITS UTS ese sti inanar aine ee asked EEr Na EENES sats dada a nir erR webceag abe etete 366 t42 MOSS age ISIS eare a ar Ta AE AEA A E EER 367 14 21 Information MESSAGES 22 2 5 cainccadeeceetincco cece ccincenstdeteuut ned seteeneue svilacdeeeccteessccenendeleee 367 14 22 Warning MESSAGES csicsas sade faugdectdaacepesiasatedge dadvedeasatecceusecten d 368 14 2 3 Command Line Error Messages ccecceeeseeeseeteceeeeeeteaeeeeeesaeenseeeeaeeeaeeteaeeeeees 372 142 4 Eror MOSSAGOS icc sev getin tei x ea stenaddcenitctetitecvegvnbeti eteeeeiiethdeeh Habart 373 142 5 Fatal Er
312. nt x int y return x y Figure 6 13 Example Calling Program Function from a C Program CC32R MANUAL 118 Chapter 6 C C Calling Conventions 6 7 5 Call C Program Functions from a C Program For the functions in a C program to be called from a C program the function should be defined or should have its prototype declared on the C program side by using extern C as in the example shown below Calling program C program extern int func int int void foo void fune 1 2 Called program C program extern C int func int x int y return x y Figure 6 14 Example Calling Program Function from a C Program CC32R MANUAL 119 Chapter 7 Embedded Applications Programming Chapter 7 Embedded Applications Programming This chapter provides information necessary to program embedded application programs embedded applications for the M32R system KAN Compiler Generated Sections 7 1 1 Regarding the Section Configuration When an object module file is generated by the C C compiler using a C C source file all codes and data contained in the program are automatically defined as one of the following sections e The P section Program code area e The C section Constant data area for const declared variables e The D section Data area with initializers for global variables having initial values e The B section
313. ntf function converts and edits the variable arguments pointed to by arg according to the format control and then outputs the result to the stream specified by fp This function is equivalent to the fprintf function but receives pointer to a variable argument list as data to be output not a variable argument list itself This function suffixes a null character to actual output character sequence however the null character is not counted as the number of output characters return value For more information on the format control refer to the description of the fprintf function The arg indicating the variable argument list must be initialized by the va_start and va_arg macros The vfprintf function does not call the va_end macro CC32R MANUAL 301 Chapter 9 C Standard Library vprintf Input output function Outputs a variable argument list to the standard output stdout by following the format Return Value Description include lt stdarg h gt include lt stdio h gt int vprintf const char control va_list arg control pointer to format string arg pointer to variable argument list Number of characters output Successful Negative value Output error occurs The vprintf function converts and edits the variable arguments pointed to by arg according to the format control and then outputs the result to the standard output stdout This function is equivalent to the printf f
314. nting a number into a double type floating point number Converts a string into a long type integer Converts a string into an unsigned long type integer Passes a command string to the host environment Converts a wide character string into a multibyte character string Converts a wide character into a multibyte character Locates in a memory area the position where a character first appears Compares the contents of two memory areas Copies the contents of a memory area to the destination memory area Moves the contents from a memory area to the destination memory area Copies a character into the first n characters in memory area Links a string to the end of a string Locates in a string the position where a character first appears Compares two strings Compares the two strings based on the current locale Copies the contents including null characters of the source string to the target memory area Computes the length of initial segment of a string which consists of unspecified characters Appendix B 6 Appendix B The C Standard Library Function List strerror strlen strncat strncmp strncpy strpbrk strrchr strspn strstr strtok strxfrm Localization function localeconv setlocale Date and time function asctime clock ctime difftime gmtime localtime mktime strftime time Returns the error message Measures the size of string Links the specified number of ch
315. o be used as the character code of the Jap anese character correspondence You can control those character codes flexibly by operation of the environment variable For example case that the C source file is written by Shift JIS and the corresponding object shall be outputted by UTF 8 character sets and character code The Japanese character The character set that is defined with JIS The Japanese Industrial Standard X 0201 and also JIS X 0208 can be used Yet the Latin character part of JIS X 0201 considers as ASCII and process JIS X 0201 Generally it is called a Hankaku Characters JIS X 0208 The Japaneze Kanji character of the 1st JIS standard the 2nd standard are included Both those characters are called Zenkaku Characters general ly In this chapter if a character is called Japanese character it includes right half of JIS X 0201 characters and all of JIS X 0208 characters kind of character code The character code name that corresponds is shown in Table A 3 In this chapter These character codes are expressed with the name that is written to the Character code name column in Table A 3 Table A 3 The chart of corresponding Japanese Kanji character codes aracter eneral utline Able to be used code name notation C source Multi byte wide character character string string euc euc JP JIS X 0201 0208 Yes Yes Yes EUC Extended Unix Code encoding sjis Shift JIS_ Shift JIS encod
316. odel in which both code and data of the application are assumed to be stored within the address space of 0x00000000 to OxOOFFFFFF colored shaded part in Figure 3 3 To compile the source in this memory model specify the option shown below when compiling small If no memory model is specified the compiler by default assumes the small model as it compiles the source The C standard libraries that correspond to this memory model are m32RcR lib for functions passed via register Appendix A 15 Appendix A Extended Functions Reference CODE DATA Ox00000000 OxO00000000 OxOOFPFFFFF OxOOFFFFFF OXFFFFFFFF OXFFFFFFFF Figure A 1 Address Space in Small Model e Small model with memlarge attached The small model with memlarge attached is a memory model in which the code and the data of the application respectively are assumed to be stored within the address space of 0x00000000 to OxOOFFFFFF colored part in Figure A 2 and the address space of 0x00000000 to OxFFFFFFFF colored part in Figure A 2 To compile the source in this memory model specify the option shown below when compiling small memlarge The C standard libraries that correspond to this memory model are m32RcRM lib for functions passed via register CODE DATA Ox00000000 Ox00000000 OxOOFFFFFE OxOOFFFFFF OxFFFFFFFF OxPFFFFFFF Figure A 2 Address Space in Smal with memlarge attached Model Appendix A 16
317. of buffer Return Value 0 New buffer has been defined non 0 Error Description The setvbuf function changes the buffer for the stream associated with the Notel input output I O file pointed to by fp from the default buffer to the storage area denoted to by buf And it redefines the buffer size to size and the buffer management method to type The following three buffer management methods are available type Description _IOFBF Full buffering Every I O process uses a buffer Data are taken out of the buffer either when the buffer is fulled or when flushed _IOLBF Line buffering Every I O process uses a buffer line by line Data are taken out of the buffer either when the buffer is fulled when flushed or when a newline character is encountered _IONBF No buffering I O processing is done in quantities of reading writing from to a stream without using the buffer Caution The setvbuf function must be used after the stream input output file is opened and before the start of the input output process Do not deallocate the buffer before closing the file Notel The default buffer is an automatically allocated buffer when either the fopen function or the freopen function opens a file Its buffer size BUFSIZ is defined in the header file stdio h CC32R MANUAL 266 Chapter 9 C Standard Library signal Signal handling function Sets up a signal handler that responds to the signal Synt
318. of function judges that the file is ended if the EOF end of file indicator is set CC32R MANUAL 192 Chapter 9 C Standard Library fe r ro r input output function Checks if a stream is in an error condition Syntax include lt stdio h gt int ferror FILE fp fp pointer to FILE structure Return Value 0 No error condition for the file non 0 An error condition for the file Description The ferror function judges whether any error is made in the I O stream specified by the file pointer fp The ferror function judges that an error is made in the file if the error indicator is set ffl u S h input output function Outputs the contents of a stream to a file Syntax include lt stdio h gt int fflush FILE fp fp pointer to FILE structure Return Value 0 Successful EOF Error Description When the stream specified by fp is opened for output the fflush function outputs the stream buffer content which has not yet been output to the file This function disables the designation of the ungetc function if such a file is opened for input CC32R MANUAL 193 Chapter 9 C Standard Library fgetc Input output function Gets a character from a stream Syntax Return Value Description include lt stdio h gt int fgetc FILE fp fo pointer to FILE structure The character read Successful EOF End of file is encountered or
319. on declared in the same source file The object declared register is the register storage class The register declaration requires the C compiler that an object that will be accessed frequently can be faster accessed register can be declared for only an object inside a function The object declared register has block scope visible only between and Such object is called register variable Example register reg The variable reg is used frequently CC32R MANUAL 64 Chapter 4 C Programming Language Specification typedef By using typedef you can define any name fora type In the ANSI standard typedef is a storage class specifier for convenience However no storage is created Example typedef char STR STR can be used as a type specifier The type of an object declared by using STR is a pointer to char ie STR str equals char str e Linkage specification extern C mutable The C C compiler encodes function names to allow for over loading Therefore when functions written in C language are called from C language an extern C declaration needs to be used to inhibit this encoding Similarly when functions written in C language are called from C language an extern C declaration should be used for the functions written in C language The functions declared by extern C for all arguments with re turn types and functions or pointer
320. on Based on the contents of the Access Control File this option determines the code for the following two types of access read write 1 Access to objects variables and structures etc assigned to the default D or B section 2 Access to objects at fixed addresses Code is generated as a command using 16 bit register relative indirect addressing mode c lower case Only compiles the sources to generate object module files file mo If this option is used along with the mklib option object module files file ml are generated C upper case The C preprocessor does not delete any comment Has no effect for C source files cs lower case Only compiles the sources to generate object module files file mo Furthermore an assembly language source file extension cs that contains C source and C source lines is generated CS upper case Only compiles the sources to generate an assembly language source file extension ms that contains C source and C source lines No object files are generated Cconstr Allocates character string constant to C section enabling allocation in the ROM area D name D name def Defines the name or constant specified by the def into the macro named name The name 1 if def is not used e entrypoint Sets the entry point of a load module at entrypoint symbol This option is effective during linking CC32R MANUAL 22 Cha
321. on or a pointer toward an aggregate or a union is specified for an item other than p and s of the printf like functions the program operates properly If the result of conversion effected by the printf function exceeds 509 characters the operation is not guaranteed e ANSI C 7 9 6 2 The fscanf function Qualifier In dealing with conversion specifications of scanf like functions if the qualifier the size specifying character h 1 L is specified previous to a conversion specifier other than the one involved as given below then the qualifier is ignored e Either h or l put previous to a conversion specifier other than d i n 0 u or x e L put previous to a conversion specifier other than e f or g Compatibility with p of printf like functions The output format of the p conversion of the printf like functions is compatible with the address format assigned to Yop of the scanf like functions Storage area for the conversion result If the area to which the resultant value of conversion effected by the scanf like functions is assigned is insufficient in capacity or of incompatible type the operation is not guaranteed e ANSI C 7 10 1 String conversion functions conversion from a string into a numerical value If the conversion result effected by one of the functions atof atoi atol that converts a string into a numerical value cannot be expressed due to a domain error the function returns the
322. ong type value and returns a converted value If a conversion result overflows this function sets a value of ERANGE in errno and returns LONG _ MAX LONG_MIN if negative or 0 as a return value CC32R MANUAL 182 bsearch Chapter 9 C Standard Library General utility function Performs binary search Syntax Return Value Description include lt stdlib h gt void bsearch const void key const void base size_t nmemb size_t size int compar const void const void key pointer to data to be surched base pointer to table to be surched nmemb the number of members to be surched size bytes of a member compar pointer to function to be compared Pointer for specified members Specified members have been searched NULL Not searched The bsearch function searches for members who meet the conditions of data specified by key through a table specified by base A function which performs comparison receives pointers p1 the 1st argument and p2 the 2nd argument for the two comparison data and returns the result according to the following specifications e p1 lt p2 this function returns a negative value e p1 p2 this function returns a value e p1 gt p2 this function returns a positive value All the members to be searched must be arranged in ascending order CC32R MANUAL 183 Chapter 9 C Standard Library calloc General utility
323. only the C environment is supported In order to use the localtime function user written getenv function called by this function internally needs to be created l O g Mathematics function Obtains natural logarithm of a floating point number Syntax include lt math h gt double log double x X floating point number Return Value Natural logarithm of x Description The log function calculates the natural logarithm of x and returns the result If a value of x is negative this function sets the value of EDOM in errno If the value of x is 0 0 this function sets the value of ERANGE in errno CC32R MANUAL 239 Chapter 9 C Standard Library Og 1 O Mathematics function Obtains the base 10 logarithm of a floating point number Syntax include lt math h gt double logl0 double x X floating point number Return Value Common logarithm of x Description The logl0 function calculates the common logarithm of x and returns the result If a value of x is negative this function sets a value of EDOM in errno If the value of x is 0 0 this function sets a value of ERANGE in errno CC32R MANUAL 240 Chapter 9 C Standard Library longjmp Non local jump function Recovers the execution environment saved by setjmp and transfers control to the program location of a setjmp call Syntax Return Value Description Note include lt setjmp h gt void longjmp jm
324. ons fscanf scanf and sscanf CC32R MANUAL 334 Chapter 10 The cc32R s Behavior e ANSI C 7 9 10 4 The perror function lt The messages generated by the perror function gt It is depends on the user defined _strerror function a low level function e ANSI C 7 10 3 Memory management functions lt The behavior of the calloc malloc or realloc function if the size requested is zero gt NULL is returned e ANSI C 7 10 4 1 The abort function lt The behavior of the abort function with regard to open and temporary files gt It is depends on the user defined abort function a low level function e ANSI C 7 10 4 3 The exit function lt The status returned by the exit function if the value of the argument is other than zero EXIT_SUCCESS or EXIT_FAILURE gt It is depends on the user defined _exit function a low level function e ANSI C 7 10 4 4 The getenv function lt The set of environment names and the method for altering the environment list used by the getenv function gt It is depends on the user defined getenv function a low level function e ANSI C 7 10 4 5 The system function lt The contents and mode of execution of the string by the system function gt It is depends on the user defined system function a low level function e ANSI C 7 11 6 2 The strerror function lt The contents of the error message strings returned by the strerror function gt It is depends on the user def
325. ons section names for variables and constant data defined after this declaration take the modified section name However this is only valid until a delimiter comma semicolon or equal sign after a variable name for which data has been defined This declaration can be made multiple times for the same default section The section attribute or location attribute cannot be specified If pragma SECTION is used together with the R compiler command line option R default section name modified section name which changes the section name created by the C compiler e The pragma SECTION declaration is not affected by the R command line option If both are used the pragma declaration takes precedence where the pragma SECTION declaration is valid e f modified section name in the pragma SECTION declaration is the same as the default section name if the default section name generated by the compiler is restored the command line option R is valid Notes You cannot split one function or one data definition into two or more section names Use the same section name pragma declaration for the same variables Do not specify a different section name in a temporary definition etc Appendix A 24 Appendix A Extended Functions Reference pragma SECTION Examples pragma SECTION is directly written into the C source code as follows Example coding int a pragma SECTION B B1 int
326. ontrol from function to function setjmp h Variable arguments access Access to arguments of variable arguments function stdarg h function Input output function Input and output operations stdio h General utility function C program standard processes stdlib h e g memory management String handling function Comparison copy etc of character string string h Localization function Setting and handling of locale localization locale h Date and time function Setting changing etc of date and time time h Signal handling function Transferring of signal interrupt signal h In addition there are initialization function and termination function that effect several settings for using functions shown above They are undefined in ANSI C Their function names begin with an underscore _ In general they should be used in the start up program see 7 3 6 to 7 3 8 CC32R MANUAL 170 Chapter 9 C Standard Library 9 1 3 Consideration for using the Library When using C standard library observe the following precautions e Include the standard header files If you use the C standard library include necessary standard header files For header files refer to Chapter 8 Standard Header Files Header file s for each function are described in Syntax in 9 2 Library Function Descriptions e Do not create any function of the same name as the C standard library function Ina user program do not create any functio
327. onversion is added to the beginning of the converted data if the data is not 0 e E 9 G A floating point is output even if the converted data has no fractional part When g or G 0 which is appended to the converted data is not removed 0 If a conversion specifier is d i o u x X e E f g or G a space at the left of value is filled with several 0s to eliminate the space If it is specified together with the flag or if a conversion specifier is d i o u x or X this flag is ignored when any precision is specified CC32R MANUAL 201 Chapter 9 C Standard Library e Field width A field width specifies the number of output characters of converted data in decimal number format or asterisk If the number of output characters of the converted data is smaller than the field width several spaces added to the beginning of the data to adapt to the field width However if the flag is specified the spaces are appended to the data If the number of output characters of converted data is larger than the field width the field width is expanded so that the conversion result can be output If the flag 0 is specified a character 0 instead of space is added to the beginning of the output data e Precision A precision specifies the precision of the converted data according to the kind of conversion specifier Upon specifying write the decimal integers and the after a
328. or Messages 2 2 tsececaactenticarissececasandebienenvasegiuhdacendstessadsaczdeacscanciashuntaneey 388 CC32R MANUAL viii Contents Appendix A Extended Functions Reference AT Base Register FUNCION scent iecncstsives settcheaetcerstntaaindsted cea grant inaire tatdentes tes arinaa 2 A 1 1 What is the Base Register Function cceeseesceeeeeeeeeeteaeeeeeeteaeesaeeeeaeeteeeeeaeeeaees 2 A 1 2 Types of Access Targeted by Base Register Function and Code Output 3 AA ACCESS to VanAlOS a ccssceicacesscaveszsesnsnesneascerssnnsenteyscvnanacosasaisi seetanesrtaanenadtsscnessecnaancessenns 3 A 1 2 2 PE es ACO STAINES aniccsadecataahs teat napster a 8 A 1 3 Objects Targeted by Base Register Function eceeceeeeeeeeeeeeeeeeeeeeneeeeeeeeeeseeesners 4 AAB1 Memory Class linkage sic isicscsasescssscesesanssccrsstnesscanscetaretacenessrteersaecasaaceraass scnsesaennancesseoee 4 BAG OBEP Soniaren ansaa 4 AN3 3 Types Of ly pe gualile beurien A udbaant wasdasdtcewsiaaliasautaaynedsbenad 5 A 1 4 Objects Not Targeted by Base Register Function ecceeceeeeeeneeeeeeeeereteeeeeeeenatens 5 AAA Types of types and derived types CtCyccsisissccssesesccnscevesnessscvase costes svncsnasuscesencertoenasbeaes 3 A 1 4 2 Memory classes and storage rriaire 5 Aala S OANE S na a E E 5 A 1 5 Setting Base Symbols and Base Registers cceeceeeeeeeteeeeeeeeteeeeseeeeneesseeeeeeeeeees 6 A 1 6 Base Register Functio
329. or the inline expanded function avoid the following operation otherwise an unexpected result may be reached Assignment and reference of variable Where the same name exists in the variable including the dummy argument inside the inline expanded function and the expansion destination calling source the debugger cannot discriminate between the both In such a case the value of these variables should not be changed and referenced Break point in source line Where the source line is inline expanded and several codes are made Appendix A 31 Appendix A Extended Functions Reference only one of these codes is effective in source line break No other source lines break are disabled 4 Inline Development Compatibility Except the item not defined yet with ANSI C ISO C the program execution results are coincident between inline expansion and non inline expansion However it should be noted that for the item not defined yet with ANSI as shown in the following example the results may change depending on inline expansion Example For the local character string literal within the function a new area is maintained at each inline expansion Consequently the results may differ depending on inline expansion and non inline expansion of function for rewriting the local character string literal Rewriting the character string literal is not recommendable which is not defined yet in ANSI C ISO C Source file
330. ority to speed 06 Optimization at levels 2 and 4 giving priority to speed O Ospace Optimization at levels 1 2 and 4 giving priority to size 0 Optimization at levels 1 2 and 4 giving priority to speed When using this option simultaneously with the debug option g the function of debugging receives an influence For more details refer to Section 3 2 3 Also where the optimization exceeding Level 4 is effective the inline expansion is made effective For more details about the inline expansion function refer to Chapter A 4 m32re5 A code is generated using the M32R ECU 5 extension instructions FPU instructions of M32R FPU core Also the non normalized numeral in the floating point constant is reduced to 0 0 For more details refer to Chapter A 5 P upper case Invokes only the C frontend or C preprocessor A file with the extension mi file mi is generated and the output result is output to this file Note that the generated mi files do not include the line number information The C C compiler selects the C frontend or C preprocessor by the source file extension as it invokes CC32R MANUAL 28 Chapter 3 Invoking the Compiler Table 3 6 Command Options for the C Compiler 8 11 Option Description Specifies the option that will be passed directly to Ink32R Ql The linker option when linking the objects written in C language Note that the options that can
331. out any data initial data elimination function of the linker The initial data which is not output because of the elimination function of can be output to another area initial data extraction function of the linker To output enter the section name without in the command line The data is output under the section name ROM_name Example SEC D 1000 B P 0c000 C D This example assigns address 100016 and subsequent addresses for the D section and places the D section initial data next to the C section The initial data is output to the load module file under the section name ROM_D This option cannot be used with MEM or r switch_by_offset Additional designation to cc32R command line option is required at compiling For more details refer to Chapter 3 2 4 U name upper case Undefines the defined preprocessor macro specified by name v lower case Displays the command used to invoke each subprocess of the C compiler as they are executed V upper case Outputs the invoking message to the standard error output The other options are ignored No processing actually takes place w lower case Disables the warning message and the information message displays warn_suppressed_nested_comment Generation of a warning for nested comments is suppressed Only when compiled in C language CC32R MANUAL 30 Option rell6 Chapter 3 Invoking the Compi
332. p_buf env int ret env variable in which executable environment is stored ret return value to setjmp None The longjmp function recovers the executable environment saved by the last call of setjmp function and transfers control to the location of program which called the setjmp function Then ret of the longjmp function returns as a return value of the setjmp function The longjmp function does not return If longjmp function is executed before setjmp function is executed at a destination or if any function which called the setjmp function has already executed a return statement the operation is not guaranteed In using the longjmp function the general purpose registers are saved recovered by contrast the accumulator ACC and the control registers are not saved recovered CC32R MANUAL 241 Chapter 9 C Standard Library malloc General utility function Allocates memory area Syntax Return Value Description Note include lt stdlib h gt void malloc size_t size SIZE number of bytes of memory area to be allocated Top element address in the allocated Successful memory area NULL Error No memory area has been allocated Any of the arguments is 0 The malloc function allocates the memory area in bytes specified by size 12 bytes more area have been secured as memory area allocated by each the malloc functions This memory area of 12 bytes is stored a
333. pansion is carried out a Variable arguments are included b The static variable is included in the function c The type of actual argument in function calling is not compatible with that of dummy argument d The calling and function definition are not described on the same compilation unit e The function calls itself Recursive call 3 Debugging information The debugging information C C source and generated code related information in the inline expanded part is generated from the contents of inline function body before inline expansion For example if the inline expanded part is step executed with the debugger such as PD32R the source line of inline function body before inline expansion is displayed However in the following cases the corresponding debugging function is to be restricted Restrictions to debugger during inline expansion The command name is associated with PD32R and PD32RSIM a Step execution The line near the function entrance or exit and the line near the place where its function was called may be inversed in sequence b Function call status display where command Among the functions in the calling path the inline expanded function is not displayed c Specified function func command For the inline function with static declaration the original function that has not been required any more is deleted In this case no command for referencing the function can be used d F
334. pecified at the same time include lt math h gt ans cos rd Compiled with float_only added ans cosf rd Becomes equivalent to this This replacement for the cos function case for example is accomplished by a macro like the one shown below Appendix A 34 Appendix A Extended Functions Reference define cos cosf Defined the same way for other double precision mathematic functions The function name that is stored in the load module when a called function name is replaced is the replaced function name and not the pre replacement function name Therefore pre replacement function names can be neither specified nor displayed in the debugger e g M3T PD32R or TM inspector You can specify or display replaced function names though c The interface specifications for the function having the double type argument and variable arguments that may possibly handle the floating point value change Consequently where the object generated by compiling it with the float_only option and the object corresponding to any one of the following are interfaced with the function having the double type argument or variable arguments the both cannot be linked e Object generated without float_only e Object generated with V 3 20 or earlier CC32R e Standard library math h printf amp scan functions etc All floating point operation functions of the standard library are of a double type
335. pies the first n bytes of content of s2 to s1 The memmove function copies correctly even if the object memory area of s1 and that of s2 overlaps with each other However original data in the overlapped area is erased The operation is not guaranteed if the copied data exceeds the buffer area of s1 as the result of copy CC32R MANUAL 248 memset Chapter 9 C Standard Library String handling function Copies a character into the first n characters in memory area Syntax Return Value Description include lt string h gt void memset void s int c size_t n Sj pointer to area in which character is set Cj character to be set nD number of characters to be set Pointer s to memory area in which character is set The memset function sets n characters of c into memory area pointed to by s CC32R MANUAL 249 Chapter 9 C Standard Library mktime Date and time function Converts date and time a struct tm to the calendar time Syntax Return Value Description include lt time h gt time_t mktime struct tm timeptr timeptr pointer to tm structure Conversion result Converted into a calendar time correctly 1 Could not be converted Casts 1 to time_t type and returns it The mktime function converts the broken down time of the tm structure shown by timeptr into calendar time The mktime function handles the tm structure specified
336. piler has four memory models 1 Small model 2 Small model with C compiler option memlarge 3 Medium model 4 Large model pragma Extended 1 This extended functions can be used to efficiently access functions the M32R family hardware specifications from the C C language Inline expansion This function is such that the contents of C language function to be called are expanded directly in place of function call Since the overhead such as the subroutine jump instruction BL can be omitted it is possible to obtain a more advantageous code in view of speed than normal function call by means of inline expansion M32R ECU 5 M32R The new 32180 and 32182 Group abbreviated as M32R FPU core Compatible ECU 5 MCU s extension instructions and FPU instructions Function support This function is compatible with the M32R ECU 5 About Japanese Kanji 1 The Japanese character can be described to the character character processing constant of a program The Japanese character can be processed as the multi byte character and wide character 2 JIS EUC JP Shift JIS Unicode UTF 8 are able to be used as the character code of the Japanese character correspondence 3 You can control those character codes flexibly by operation of the environment variable The Access Control File contains the following information 1 Base address for 16 bit register relative indirect addressing 2 Register storing the
337. ples of internal representation of floating type data Table 5 4 Examples of Internal Representation of Floating Type Data Type Internal Representation Value float 0011 1111 1000 0000 0000 0000 0000 0000 1 0 0011 1111 0100 0000 0000 0000 0000 0000 0 75 double long double 0011 1111 1111 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1 0 0011 1111 1110 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0 75 CC32R MANUAL 79 Chapter 5 Internal Data Representation EZI Arrays The elements of array type data are continuously allocated to a series of memory locations The size of array type data is the size of array element x the number of elements The alignment of the array type data is the same as that of the data type of array element The examples show the following internal presentation of array type data and their alignment e Example 1 Coding Internal Representation Alignment e Example 2 Coding Internal Representation Alignment char a 5 ma 5byts _ a 0 alt al2 al3 af4 a is 5 bytes 1 byte x 5 Since the data type of the array element is char the alignment is also char type alignment 1 int bI 12 bytes b0 bt b 2 b is 12 bytes 4 bytes x 3 Since the data type of the array element is pointer the alignment is also pointer type alignment 4 CC32R MANUAL 80 Chapter 5 Internal Data Re
338. pported The setlocale function sets the portion of the program s locale denoted by category into the locale specified by locale If locale is NULL the setlocale function searches the current locale information and the locale is not changed The following are the macros that can be specified in category category Description LC_ALL Sets or searches for all locale information LC_COLLATE Sets or searches for information that affects the strcoll and strxfrm functions LC_CTYPE Sets or searches for information that affects all character handling functions and multibyte handling functions except for the isdigit and isxdigit functions LC_MONETARY Sets or searches for information that affects the currency information which the localeconv function returns LC_NUMERIC Sets or searches for information that affects input and output functions decimal points used by character handling functions and information excluding the currency information which the localeconv function returns LC_TIME Sets or searches for information that affects the strftime function CC32R MANUAL 265 Chapter 9 C Standard Library Input output function setvbuf Defines and sets a buffer for an I O stream Syntax include lt stdio h gt int setvbuf FILE fp char buf int type size_t size fo pointer to FILE structure buf pointer to buffer type buffer management method size size
339. presentation e Example 3 Coding char c 3 2 Internal _ Bbytes __ Representation cloto fetoj fof 1310 fernen erzo etz Alignment c is 6 bytes 1 byte x 2 x 3 Since the data type of array element is char the alignment is also char type alignment 1 5 5 Structures The member data of structure type is allocated to continuous locations in the order of member declaration Particular allocation rule applies to bit field members see 5 9 Bit Fields The alignment of structure type data is determined by the data type alignment of that member i e the largest alignment The size of a structure is in general the sum of the sizes of that member Exception when allocating members of structure 1 3 bytes of gap may be inserted after the end location of the preceding member due to alignment for each member Since the alignment of a structure type is equal to the largest alignment in the member if the end location of the last member is at an address which does not match the alignment the location is assumed to end at the address which matches the alignment Therefore the size of a structure type is always a multiple of the alignment Examples of internal presentations of structure type data and their alignment are shown in Examples 1 to 4 CC32R MANUAL 81 Chapter 5 Internal Data Representation Example 1 Coding Internal Representation Alignment Example 2 Coding Internal R
340. prototype declaration It is therefore first converted to type double and then is pushed on the argument area on the stack CC32R MANUAL 107 Chapter 6 C C Calling Conventions e Example 2 int f float char Argument Area 1 0 an 4 bytes 1 49 The first argument is converted to 1 0 as type float The second argument is first converted to type char according to the function prototype declaration and then is reconverted to type int as it being pushed on the stack e Example 3 struct s Char x yrz ja Argument Area int f a The argument s requires 3 bytes size and is aligned with 1 byte boundary When the argument is pushed on the stack a single byte of unused area is added to the argument area on the stack to make its size 4 bytes e Example 4 StruUCcE sf i Argument Area Int X y3 EO 4bytes e Return 4 bytes Value Area When the function returns struct the pointer address to the return value area reserved by the calling side is set to the low address of the argument area on the stack e Example 5 int f float eee 1 0 float 4 bytes 1 0 double 8 bytes 1 0 1 0f Since the first argument is denoted as type float by the function prototype declaration the argument is converted to type float The second argument is not declared its type and is therefore converted to type double CC32R MANUAL 108 Chapter 6 C C Calling Conventions
341. pter 3 Invoking the Compiler Option ecpp Table 3 6 Command Options for the C Compiler 2 11 Description Compiles the sources based on Embedded C language specification The Embedded C language specification does not support catch const_cast dynamic_cast explicit mutable namespace reinterpret_cast static_cast template throw try typeid typename and using If these keywords are written in a program an error message is output The Embedded C language specification does not support multiple inheritance and virtual base class If multiple inheritance or virtual base class is written in a program an error message Embedded C Does Not Support Multiple or Virtual Inheritance is output This option and the exception option cannot be specified at the same time Invokes only the C frontend or C preprocessor and outputs the result to the standard output device The C C compiler selects the C frontend or C preprocessor by the source file extension as it invokes exception Enables the exception handling facility The C exception handling facility try catch throw is enabled If the exception is specified the efficiency of code generation may be reduced If this option is omitted noexception is assumed by default For the exception handling facility to be enabled between files the specification shown below should be made e rtti on This option and the ecpp option cannot be sp
342. ptr end point of reading Converted value The strtod function converts a string into a double type numeric value The input string must be an array of characters that after conversion into a numeric value of a type can be interpreted as a valid numeric value of that type The strtod function upon encountering a character which cannot be interpreted as a value stops inputting current string and sets the pointer to the first character found in the input string which cannot be interpreted as a numeric value in the area indicated by endptr If the endptr is null the function does not perform this setting If the conversion results in overflow or underflow the function sets ERANGE value to the errno and returns either HUGE_VAL HUGE_VAL in case of negative value or 0 CC32R MANUAL 285 Chapter 9 C Standard Library strtok String handling function Separates a string into tokens Syntax Return Value Description include lt string h gt char strtok char sl const char s2 sl pointer to string to be divided into tokens s2 pointer to string used to divide a string Pointer to the top character Divided into tokens of the token after division NULL Cannot be divided into tokens The strtok function uses a particular character in the string s2 as the punctuator to divide the string s1 into tokens The function is called continuously once for each token The function upon f
343. public short d Object offset value short i Index in the virtual function table when the target function is the virtual function union void f Address of a function when the target function is a non virtual function long offset Object offset value of the virtual function table when the target function is the virtual function i obj CC32R MANUAL 87 Chapter 5 Internal Data Representation EI Bit Fields A bit field is a set of bits Members in a structure or union have data in the form of bit field When declaring a bit field specify the field width number of bits The bit field data are stored into the byte 8 bit half word 16 bit or word 32 bit memory area in the order which they declared 5 9 1 Data Type for Bit Field Valid bit field data types can be signed or unsigned char short int or long types IIII Note Ill ANSI C ISO C allows only the int signed int or unsigned int for bit field data This means that a program using char or short type data may not be processed by compilers other than CC32R Before being used a bit field is expanded to data of the size of the type of which it is declared The specified bit field width is allocated with the expanded data bits low order bit first The high order bit the expanded field is set as follows depending on whether the bit field is signed or unsigned e Unsigned bit field The high order bit is set to 0 du
344. r a read error occurs The getc function inputs one character from the stream specified by the file pointer fp and returns that character When EOF end of file is encountered the EOF indicator for the stream is set and this function returns EOF When a read error occurs during the operation the error indicator for the stream is set and this function returns EOF The EOF indicator can be referred by the feof function and the error indicator can be referred by the ferror function CC32R MANUAL 221 Chapter 9 C Standard Library getchar Input output function Gets a character from the standard input stdio Syntax Return Value Description include lt stdio h gt int getchar void one character input from standard input The character read Successful EOF End of file is encountered or a read error occurs The getchar function is the same as getc stdin function When EOF end of file is encountered the EOF indicator for the stream is set and this function returns EOF When a read error occurs during the operation the error indicator for the stream is set and this function returns EOF The EOF indicator can be referred by the feof function and the error indicator can be referred by the ferror function CC32R MANUAL 222 Chapter 9 C Standard Library getenv General utility function Gets the content of an environmental variable Syntax Return Value Descr
345. r an I O stream Syntax Return Value Description include lt stdio h gt void setbuf FILE fp char buf Lp pointer to FILE structure buf pointer to buffer None The setbuf function changes the buffer for the stream associated with the input output file pointed to by fp from the default buffer denoted to by buf The buffer size is unchanged To change the buffer size use ote 1 to the storage area the setvbuf function Setting NULL in buf causes the buffer not to be used effects no buffering This is equivalent to specifying _IONBF for the third argument type buffer management method of the setvbuf function Note1 The default buffer is an automatically allocated buffer when either the fopen function or the freopen function opens a file Its buffer size BUFSIZ is defined in the header file stdio h CC32R MANUAL 263 Chapter 9 C Standard Library setjmp Non local jump function Saves the current environment to a memory area Syntax Return Value Description Note include lt setjmp h gt int setjmp jmp_buf env env the current environment 0 The setjmp function has been executed The current environment has been set to env The second argument ret of longjmp Control is returned to the setjmp function function upon execution of the longjmp If the second argument ret of the longjmp function is 0 1 is returned to set
346. r reference lvalue post increment lvalue post decrement typeid typeid type type identification C language only typeid typeid expr run time type identification C language only dynamic_cast dynamic_cast lt type gt expr dynamic cast C language only static_cast static_cast lt type gt expr static cast C language only reinterpret_cast reinterpret_cast lt type gt expr reinterpret cast C language only const_cast const_cast lt type gt expr const cast C language only sizeof sizeof expr size of object sizeof sizeof type size of type Ivalue pre increment lvalue pre decrement CC32R MANUAL 52 Chapter 4 C Programming Language Specification Table 4 0 Operators 2 4 Operator Usage and Note Description expr bitwise complement compl expr can be available on C language expr logical negate not expr can be available on C language z expr unary negate as an unary operator expr unary add as an unary operator amp amp lvalue address of as an unary operator expr pointer dereference new new type create allocate C language only new new type expr_list create allocate and initialize C language only new new expr_list type create placement C language only new new expr_list type expr_list create placement and initialize
347. r side because one element becomes one character there is the advantage that wide character string can be searched inserted and eliminated at an optional position wi thout concerning the gap between the characters Attention In CC32R the wchar_t type is equal to the signed short type However do not suppose it in your programming Appendix A 38 Appendix A Extended Functions Reference A 6 3 Programming that used a Japanese processing function This is an example of the programming that used a Japanese processing function include include include include include char char wchar_t define define char wchar_t void int main voi lt stddef h gt Wchar_t type definition lt locale h gt Due to the control of locale lt stdlib h gt Due to the mbstowcs function application lt stdio h gt lt string h gt strl CC32R str2 a gt HME 1 Description of Japanese with a multi byte character string wstr L xF Ms 2 Description of Japanese with a wide character string BUFSIZE 256 WBUFSIZE 128 buff BUFSIZE wbuff WBUFSIZE kanjiout wchar_t wc The function for outputting wide character dummy Make program as that wc is outputted to the display devices return d int size_wch i 3 Multi byte character string if there be not division etc conventional character string processing possibil
348. result overflows Description The pow function returns a value of x raised to the power y If the value of x is 0 0 and the value of y is 0 0 or less or if a value of x is negative and a value of y is not an integer this function sets EDOM in errno If the calculation result overflows this function sets ERANGE in errno p r i n tf Input output function Converts data by following the format and outputs it to the standard output file stdout Syntax include lt stdio h gt int printf const char control control pointer to format string i variable argument list output data Return Value Number of output characters Successful Negative value Error Description The printf function converts and edits variable arguments according to format control and then outputs them to a standard output file stdout For the details of format control refer to the description of the fprintf function CC32R MANUAL 252 putc Chapter 9 C Standard Library Input output function Outputs a character to a stream Syntax Return Value Description include lt stdio h gt int putc int c FILE fp CF character to be output fo pointer to FILE structure The character written Successful EOF A write error occurs The putc function it may be implemented as a macro outputs the character c into the stream specified by the file pointer fp When a write error occurs dur
349. returned by the fgetpos function ftel l input output function Locates the current read write position in a stream Syntax include lt stdio h gt long ftell FILE fp Lp pointer to File structure Return Value A file read write position Description The ftell function seeks a read write position of the stream specified by the file pointer fp and returns it as a return value CC32R MANUAL 219 Chapter 9 C Standard Library fw r i te Input output function Transfers data from a memory area to a stream Syntax include lt stdio h gt size_t fwrite const void ptr size_t size size_t n FILE p ptr pointer to data storage area size number of bytes per member n number of written members fp pointer to File structure Return Value The number of read members Successful the same value as n usually A value smaller than n When an error is made Description The fwrite function reads n members which have size byte data from the memory area pointed to by pir to the stream pointed to by fp CC32R MANUAL 220 Chapter 9 C Standard Library getc Input output function Gets one character from a stream Syntax Return Value Description include lt stdio h gt int getc FILE fp one character input from file Lp pointer to File structure The character read Successful EOF End of file is encountered o
350. riable areas overlap as a result of the specified absolute address Take care when specifying the address No check is performed to see if array or structure access addresses overflow the 32 bit address as a result of the specified absolute address Take care when specifying the absolute address that there is no overflow The specifying of the same absolute address in a pragma ADDRESS declaration for a different variable has an effect on the compiler s optimization processing and correct code may not be generated When specifying the same absolute address use the volatile qualifier as a variable Note that the following will result in faulty operation but are not checked by the com piler ra S Example of specifying addresses that overlap for variable porta and portb areas pragma ADDRESS porta 0x10010 pragma ADDRESS portb 0x10012 int porta int portb Example of specifying overflow array access address pragma ADDRESS x Oxffffffff char x 2 void func void Example of effect on compiler s optimization processing pragma ADDRESS x 0x1000 pragma ADDRESS y 0x1000 int x Yy int func void x 0 y 17 if x 0 return 0 return 1 Under the ANSI C specifications the interpretation of modification y 1 of y above does not affect the value of x and is allowed Thus the if statement x 0 can be interpreted as always true and the compiler might generate code that always returns 0
351. ring handling function Compares the contents of two memory areas Syntax include lt string h gt int memcmp const void si const void s2 size_t 7 sl pointer to compared memory area S2 pointer to comparing memory area nD number of characters of comparing memory location Return Value Positive value content of s1 gt content of s2 0 content of s1 content of s2 Negative value content of s1 lt content of s2 Description The memcmp function compares the contents of the first n bytes of the memory areas specified by s1 and s2 meme py String handling function Copies the contents of a memory area to the destination memory area Syntax include lt string h gt void memcpy void si const void s2 size_t 2 y3 sl copy destination s2 original nj number of copied bytes Return Value Pointer to the memory area at the copy destination Description The memcpy function copies n characters of the memory area s2 to the destination memory area s1 CC32R MANUAL 247 Chapter 9 C Standard Library memm ove String handling function Moves the contents from a memory area to the destination memory area Syntax Return Value Description include lt string h gt void memmove void si const void s2 size_t n sl copy destination storage buffer s2 original nj number of copied bytes s1 The memmove function co
352. ring promotion zero extension e Signed bit field The high order bit is set to the MSB of the bit field sign extension For example see char member 2 in Figure 5 3 when using a char type bit field whose width is declared as 2 bits high order 6 bits are sign extended to 8 bits and are processed as a 1 byte data The value of the byte allocated to the bit field is 1100 0000 The upper 2 bits 11 are allocated to the member IMPORTANT A bit field though having the same bit pattern may take ona different range that it expresses depending on signed or unsigned see the example below So be careful Example char a 4 a ranges between 8 and 7 1 for 1111 unsigned char b 4 b ranges between 0 and 15 15 for 1111 Note MSB most significant bit CC32R MANUAL 88 Chapter 5 Internal Data Representation E By the declaration char member 2 E lf 1 is assigned to member the area is gotten as shown below byte bit 7 0 bit 7 0 RR for member Sign L Lower 6 bits are Assigned Value unknown E When member is referenced such as char s abc member the bit field is sign extended Ls ign Extension Figure 5 3 Example of Internal Representation of Bit Field IIll Note IIll The behavior of a bit field may depend on an implementation So be careful of the following in transporting an application or the like e int In ANSI C I
353. ring to memory strpbrk Locates the position where one of the specified O characters first appears in a string strrchr Locates the position where a character last appears in O a string strspn Computes the length of initial segment of a string O which consists of specified characters strstr Finds the first occurrence point of a string within another O strtok Separates a string into tokens x strxfrm Converts the string based on the current locale O CC32R MANUAL 167 8 2 15 time h Chapter 8 Standard Header Files Performs the prototype declaration and macro definition of the date and time handle functions Table 8 24 shows the declared functions Table 8 24 Functions Declared by time h Function Description Reentrant asctime Converts data and time a struct tm into the equivalent x text string clock Gets the elapsed processor time Depends on user description ctime Converts the calendar time a time_t value into x the equivalent text string difftime Computes the difference between the two specified O times gmtime Converts calendar time to Coordinated Universal Time x UTC localtime Converts current calendar time to the local time x mktime Converts date and time a struct tm to the calendar time x strftime Converts date and time a struct tm to the format x specified time Reads the current calendar time Depends on user description CC32R MANUAL 168 Chapter 9 C Standard
354. rites data into a file Number of bytes actually written Successful Si Failed The write function writes the count byte data stored in the area pointed to by buffer into the file denoted by file_no The read write point in the file advances by the bytes written When writing is successful the number of bytes actually written is returned Otherwise 1 is returned CC32R MANUAL 353 Chapter 12 Single precision Mathematical Function Library Chapter 12 Single precision Mathematical Function Library This library is a version of the C standard mathematic function library defined in the math h header that has been turned into single precision arithmetic It helps to increase the efficiency of applications using conventional double precision mathematic function libraries by increasing the execution speed and reducing the code size Some single precision mathematic functions use the FPU instructions and others do not 121 Composition of Functions Table 12 1 lists the functions in the single precision mathematic function library Check the C language formats of prototype declarations shown in the table to find the types of return values and arguments of these single precision mathematic functions CC32R MANUAL 354 Chapter 12 Single precision Mathematical Function Library Table 12 1 Single precision Mathematic Function Library Sing
355. rms the prototype declaration and macro definition of the signal process functions The declared functions are shown in Table 8 12 Table 8 12 Functions declared by signal h Function Description raise Send a signal to the executing program signal Sets up a signal handler that responds to the signal CC32R MANUAL 159 8 2 10 stdarg h Chapter 8 Standard Header Files Performs the macro definition and data type declaration required for the variable arguments functions The defined macros and declared data types are shown in Table 8 13 and Table 8 14 Theses macros are further described in 9 2 Library Function Descriptions Table 8 13 Macros Defined by stdarg h Macro Name Description Reentrant va_arg Macro Gets variable arguments in turn O va_end Macro Ends the reference to variable arguments O va_start Macro Initializes to reference variable arguments O Data Type va_list Table 8 14 Data Types Declared by stdarg h Description Indicates the types of variable arguments used by the macros va_start va_arg and va_end for referencing variable arguments CC32R MANUAL 160 Chapter 8 Standard Header Files 8 2 11 stddef h Defines the macros which are commonly used by the standard header files and declares the common data types The defined macros and declared data types are shown in Table 8 15 and Table 8 16 Table 8 15 Macros Defined by stddef h Macro Name Des
356. rom exit Special floating point values judgement function non ANSI These are the functions that judges whether or not the value corresponds to any special floating point values float or double one of 0 0 Zero Infinity or NaN Not a Number The floating point operation program can use these functions for checking previously input value of the operation and for checking whether or not the result of the operation is special value Table B 1 Special floating point values judgement function The floating point value type Checking functions C language formats of that these functions check prototype declarations double type float type Infinity int isinf double int isinff float Zero 0 0 int iszero double int iszerof float Not a Number NaN int isnan double int isnanf float These functions return 1 if input value was corresponds to the special value of each function Otherwise these functions return 0 Before the judgement functions can be used one of the following header files must be included Choose either one that suits to your need mathf h When you use only the float type judgement functions math h When you use the float or double type judgement functions Note that because the header math h includes the functions of mathf h you do not need to include mathf h if you already have math h included Appendix B 8 Appendix B The C Standard Library Function List Example A f
357. rom the C Compiler Table 14 6 Error Messages 8 15 Message Description xxx macro body parameter list redefined The source code attempted to redefine either a macro or an argument list macro name xxx is reserved xxx is a predefined macro macro name missing after D option A macro name hasn t been specified for the D option macro name missing after U option There is no macro name after the U option member fields with bit size of zero must not be named You cannot give a name to a bit field whose size is 0 more arguments are specified than declared The number of arguments is greater than declared more parameters than definition The number of parameters in a function prototype declaration is too many The number of parameters does not agree with that in a function definition new style function can not have an old style parameter declaration An old way of declaring arguments must not be mixed with a new way newline character not allowed You cannot include a line feed character in a character constant no arguments to macro xxx No arguments are present in the macro xxx no repetition of type qualifier in declaration You cannot declare a type qualifier repeatedly xxx No such file or directory The file to be included xxx cannot be read non integral constant expression for enumeration constant An attempt has been made to define a non integral constant for an enum co
358. rs 34 A 5 3 1 CAUTION float_only Option cscscsesssesssesssssesssesssesssessesssesssstsvessesssetssstseensersesteess 34 A 5 3 2 PVC MO UMN eNO apacd esse E E R alee A E 35 A 5 3 3 Round Off MOJE sscccesscccvseesn ctrasvnssveseccvasscvascsnntnnsktcwnseessnsitatassstasecknixesisctawsnias tcuneeess 35 A 5 3 4 NSE OPUOM steaseasesatesscdiedisaceess aiiecbe na tleaseaieaaceiseude A 35 A 6 About Japanese Kanji character processing s ccceeceeccceeeeeeeeeeeeeeeeeeeeeeneeneees 36 AG character sets and Character Code sensensa e eisai 36 A 6 1 1 Tmhedapanesechalactan saridona rar i Ain E 36 A 6 1 1 KiNG ORGMArACIEH GOJE assen 36 A 6 1 3 Method of selecting character COQS a cisicccsescrscscessessccsncescascsensacsascescensasensetasssenoas 37 A 6 2 Description method of the Japanese Character cecceeeeeseeeeeneeeeneeeeeeteteeeeeeaes 38 A 6 2 1 Multi bytecharactar suonna es ceaiecs said vadea see N NN 38 A 6 2 2 Wide CHAlACICN seis ceases sevssndscaarerscecesneapecncateess cesdeenestennerd sateaseevees careers arnassersnensadecaeds 38 CC32R MANUAL ix Contents A 6 3 Programming that used a Japanese processing function eeeeeeeeeeeetteeteeeees 39 AGA ReStrictlonintemssisieeldsieendatiniih a len nil naan 41 A 6 4 1 ME eE eE DIA pari E E E E E E E A T 41 A 6 4 2 Attention on multi byte character string processing ss irsissisrisirsirisessnireississass 41 A 6 4 3 Attention On standard TUMCUOM USES sn
359. rtain use conditions Further Renesas Electronics products are not subject to radiation resistance design Please be sure to implement safety measures to guard them against the possibility of physical injury and injury or damage caused by fire in the event of the failure of a Renesas Electronics product such as safety design for hardware and software including but not limited to redundancy fire control and malfunction prevention appropriate treatment for aging degradation or any other appropriate measures Because the evaluation of microcomputer software alone is very difficult please evaluate the safety of the final products or system manufactured by you Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances including without limitation the EU RoHS Directive Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations This document may not be reproduced or duplicated in any form in whole or in part without prior written consent of Renesas Electronics Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electron
360. ry this function outputs the buffer content to the actual file This function returns 0 when the file is successfully closed if not 1 CC32R MANUAL 347 Chapter 11 Low level Library g et U n iq nN u mMm Low level function D Syntax int getuniqnum void Summary Return Value Description Obtains the unique number for each process The value specific to a unit of the program operations This value must be kept unchanged during program is running The getuniqnum function returns the number by which the environment specifies the operation unit when two or more programs are to run simultaneously The number may differ from operation unit to unit even though these units have the same execution code However it must be the same for the same operation unit codes This function returns the same value to environment where the program performs only one operation CC32R MANUAL 348 Chapter 11 Low level Library Iiseek Low level function Syntax Summary Return Value Description long lseek int file_no long offset int base file_no target file number offset offset bytes indicating the read write point base origin of offset Reposition the read write point ina file The new offset bytes from the read write position to ina file Successful 1 Failed The lseek function sets the read write position as measured in bytes in the file denoted by file_no The new
361. ry area to which the characters are copied Description The strcpy function copies the string including the terminating null character specified by s2 into the memory area specified by s1 CC32R MANUAL 274 Chapter 9 C Standard Library st rcs p n String handling function Computes the length of initial segment of a string which consists of unspecified characters Syntax include lt string h gt size_t strcspn const char si const char s2 sl pointer to string to be checked S2 pointer to string used to check the si string Return Value The length of the searched string Description The strcspn function computes the length of the maximum initial segment of the string pointed to by s1 which consists of characters not from the string pointed to by s2 And it returns the length i e the number of characters st rerror String handling function Returns the error message Syntax include lt string h gt char strerror int e e error number Return Value Pointer to the error message corresponding to the error number e Description The strerror function returns the pointer to the error message corresponding to the error number e as the return value CC32R MANUAL 275 Chapter 9 C Standard Library st rft i me Date and time function Converts date and time a struct tm to the format specified Syntax include lt time h gt size_t strftime char s size_t maxs
362. ry operator must be arithmetic type operand of unary amp must not refer to bitfield You cannot use the amp address operator for a bit field operand of unary amp must not refer to register object You cannot use the amp address operator for an object brought under a register declaration operands of multiply divide must have arithmetic type The operand of the multiplication operator and division operator must be arithmetic type operands of amp must have integral type The operand of the amp operator operator and operator must be arithmetic type CC32R MANUAL 382 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 11 15 Message Description operands of lt lt gt gt must have integral type The operator of the lt lt operator and gt gt operator must be integral type operands of S must have integral type The operand of the operator must be integral type operands of amp amp must have scalar type The operand of the amp amp operator and operator must be scalar type operands of relational operator have invalid type The type of the relational operator lt lt gt gt is improper operator should be followed by a macro argument name A macro argument name must be present after the operator parameter can not have any storage class other than register You cannot
363. s This function is the default By default cc32R performs a chain process as compiling assembling and linking Contents of each source file e g a use language are discriminated by the filename extension 2 1 2 cc32R Features e Conformance with ANSI The C C complier and the C C standard libraries conform with the ANSI Standard ANSI ISO 9899 1990 e The set of 64 bit integer arithmetic functions is supported The set of functions to perform C C language integer arithmetic in the 64 bit dynamic range has been added to the standard library As for the integer type in C C language these functions can perform the four fundamental operations in arithmetic as well as bitwise shift and compare operations in the 64 bit range e Floating point operation is supported Internal data representation of floating point data conforms with the IEEE The Institute of Electrical and Electronics Engineers 754 Standard CC32R MANUAL 9 Chapter 2 Overview of cc32R e Creating ROMable programs is supported ROMable object modules can be created This depends on the linker s functions When linking and placing sections of object modules space can be allocated for the section which contains initialized data within the RAM area and the initialized data can be placed in the ROM area e Supports optimization function Optimization function enables efficient generation of object code The following optimization levels are supported
364. s and functions offered by different operating systems OS and therefore may vary from OS to OS These names are used to interface with a particular OS e System names reserved for languages and libraries 100 900 These names are used by development support tools such as languages and libraries Do not use these names in a program because they may be used by language processing and libraries These names are used in the C standard libraries e Names reserved for user systems 901 999 These symbols can be used in the user program By providing layers in the user system symbols can be used without confliction The names in the object program that correspond to external definitions and reference symbols in a C program are the names used in the C program but have a underscore _ or dollar mark prefixed to the name For examples the system reserved names shown in Figure 4 6 are expressed as follows when used in an object file _ _900_main _900_INITLIB or _900_main _900_INITLIB CC32R MANUAL 73 Chapter 4 C Programming Language Specification 4 6 Precautions Regarding Language Specification 4 6 1 Specification of const in C Language Objects specified to be const are not always located in a ROM Objects that involve dynamic initialization cannot be located in a ROM Example 1 const int a func Example 2 const struct S int a S b CC32R MANUAL 74 Chapter 5 Internal Data Representatio
365. s defined before or after the declaration To ensure compatibility with other compilers it is able to describe pragma INTF in stead of pragma INTERRUPT Base registers R11 to R13 specified using the access option are not evacuated or returned unless specified in a pragma INTERRUPT statement Appendix A 26 Appendix A Extended Functions Reference pragma INTERRUPT Rules Examples pragma INTERRUPT is written directly into the C C source code as follows a An error is returned when compiling in the case of interrupt processing functions other than those of the void type and an interrupt processing function that has arguments are described An error is returned when compiling if a pragma INTERRUPT is declared two or more times for the same function lf other than a function name is specified that specification is ignored pragma IN TERRUPT is invalid The compiler does not generate instruction code for reenabling the interrupt within the interrupt processing function The compiler does not handle multiple interrupts no code is generated for reenabling the interrupt within the specified function Example of use pragma INTERRUPT int_func R12 extern int counter void int_func void counter In this example the pragma INTERRUPT specifies function int_func as the interrupt processing function and the compiler generates the code for evacuating and returning
366. s of C Standard Library Functions in the user s manual to confirm function specifications for the corresponding double precision mathematic functions e Conditions in which a domain error EDOM occurs e Conditions in which a range error ERNAGE occurs e Conditions in which an overflow value HUGE_VAL is returned to the calling function e Conditions in which an underflow value 0 is returned to the calling function CC32R MANUAL 358 Chapter 13 A set of 64 bit integer arithmetic functions Chapter 13 The set of 64 bit integer arithmetic functions The set of functions to perform C language integer arithmetic in the 64 bit dynamic range has been added to the standard library As for the integer type in C language these functions can perform the four fundamental operations in arithmetic as well as bitwise shift and compare operations in the 64 bit range 134 Header file long64 h For the 64 bit integer arithmetic functions to be used the header file long64 h must be included In long64 h the necessary types constants and function prototypes are declar ed 1 Type name The type structure holds a 64 bit integer All of the 64 bit integer arithmetic functions use this type as they input and output 64 bit integers Signed 64 bit integer LONG64 Unsigned 64 bit integer ULONG64 2 Constant The constant represents the maximum and minimum values of a 64 bit integer LONG64_MAX
367. s of CC32R CC32R is a cross tool kit designed to develop an application program for the M32R family Its versatile features are especially useful for development of a control system to be embedded Major features of the CC32R include the following e Generates a load module file which is executable on the M32R from a source file written in C C or assembly language e Converts a load module into S format one which can be written into ROM e Offers optimizing functions which generate efficient object codes to speed execution time 1 2 Components of CC32R 1 2 1 Components of CC32R CC32R consists of the following cross tools e Ccomplier cc32R with C standard libraries e Assembler as32R e Linker Ink32R e Librarian lib32R e Map generator map32R e Load module converter Imc32R e Debug information discarding utility strip32R CC32R MANUAL 1 Chapter 1 Overview of CC32R EEJ Overview of the Components of CC32R The following tools are contained in CC32R e C C compiler cc32R This is the C C compiler compile driver compliant with ANSI ISO 9899 1990 and ISO IEC 14882 2003 It compiles and assembles C C language source files to generate an assembly language source file It also starts the assembler or linker Once cc32R is started a series of processing necessary to generate a load module file from the source files can be executed e prelinker plink32R The prelinker is the utility us
368. s option allows writing of the C C program into the ROM by assigning the sections to the appropriate memory locations This option is a simplified version of the SEC option and is made effective when the section is composed of P D B and C and cannot be used if a user made section exists Specify the address in hexadecimal The hexadecimal number starting with an alphabetic letter must have a 0 zero preceding the letter addr1 must be assigned the start address of the RAM area locations for D B section The sections must be linked in the order of D and B The RAM memory locations specified by addr1 are reserved but they are not used to store the initial value data addr2 must be assigned the start address of the ROM area locations for initial value data of P C and D sections The sections must be linked in the order of P C and D The D section initial value data is output as the section name ROM_D The MEM option cannot be used together with the SEC or r option Each of the following options denotes the same process MEM 1000 8000 SEC D 1000 B P 8000 C D CC32R MANUAL 25 Option mklib c a Table 3 6 Command Options for the C Compiler 5 11 Description This option is used to create library files extension lib A library file extension lib is newly created mklib c and object module files extension ml are added to the library file mklib a Always be sure to explicitly specify
369. s tepsace0saescedvedeisiti csaieas Na eS a ae 63 42 6 Storage Class SpeCiiiers ciinii engaina eia aa a eae dsl Saeco 64 KC OMVENSIOIMNS ace is inicas cectds deaegecaceauien A datasel os pteebvauigeieeedonenceelane 66 434 Explicit CONVERSIONS GASE caccasccest exces cate Sersecenest A aAa a aaien 66 4 3 2 Explicit Conversions Cast operator for only C eeeecceseceeeeeeeeeeeeeeeeeeeeneeteeeeeaes 66 4 3 2 1 LY TARTS SOCAL R E E E E E E E 66 4 3 2 2 SIAC CASE ws scene ste E E E E E E E sical sgeaimesncles mentee 67 4 3 2 3 reinterpret GaSb 2 ccsi ics ccen cont E oes raat Aae 67 4 3 2 4 or gk il crs E Gian rr reer Erie terre ere renner enor tren eer a E A en rrr ta errrr meer erre 67 4 3 3 IMPlicit COMVETSIONS acis cess ccanteesesends eeatecescensdeesgeneanees tanta aden vein sve desatdecdceestadettestecnGee 67 Preprocessing DINGCIIVES cs ciezeseciveudentssnsaeecdetnidacncseeivagtcelsivaduar ts tabdagteedebetssuelshviaaag 71 System Reserved Names cccccceccceeeeeceeceeeeeeneeeeeaeeeeeaaeeeeaeeeseaaeseeaeeeeeaeeeeeees 73 Precautions Regarding Language Specification cccescecceeceeeeeneeeseteeeeneeeees 74 4 6 1 Specification of const in C Language eeceeeteeeeeeeeeeteeeeeeeeeteeeeaeeeeeeeneeteeeenaes 74 42 CC32R MANUAL iv Contents Chapter 5 Internal Data Representation 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 10 Data Representation On Memory ossessi ierahiemestebdansteetivignie
370. s to functions conform to C language rules Example Function call between C and C extern C void foo void int foo void return i When calling a C language function from C it is also pos sible to explicitly declare it by extern C mutable is a storage class specifier applicable to the data mem bers that are neither const nor static The member specified to be mutable does not become const even though it is part of a const object CC32R MANUAL 65 Chapter 4 C Programming Language Specification 4 3 Conversions 4 3 1 Explicit Conversions Cast You can temporarily convert cast the type name of an object or a function by use of the cast operator The syntax for a cast is show in Figure 4 6 A cast to an lvalue is not allowed Syntax new_type_specifier identifier where new_type_specifier Either a scalar type or void identifier An identifier declared as a scalar type Example char str abc int a int str In order to substitute the operation value of int type a for double type x it convert into a double type Figure 4 6 Syntax of Explicit Conversion Cast Although a type is converted to its compatible type the value in the object or from the function is unchanged However making conversion to an incompatible type changes the value as shown in Table 4 15 and 4 16 in 4 3 2 Implicit Conversion 4 3 2 Explicit Conversions Cast operator for only
371. se processing A 6 5 1 Inside expression of the Japanese character 1 Inside expression of the multi byte character string The multi byte character string on C C source will be transformed to the character code that is designated by M32RKOUT and be transformed to the text stream image of the content of the text file of 8bit Example Multi byte character string Next some program is shown description of the same meaning as char kanjil BF1 sjis char kanjil Ox8a 0xbf 0x8e 0x9a 0x31 0 euc char kanjil Oxb4 0xc1 0xbb 0xfa 0x31 0 utf8 char kanjil Oxe6 0xbc 0xa2 0xe5 0xad 0x92 0x31 0 2 Expression of a wide character Itis euc or sjis if the multi byte character is transformed a wide character the highest byte of wide character is 1st byte of multi byte character the lowest byte of wide char acter is 2nd byte of multi byte character In same environment if the 1byte multi byte character is transformed a wide characte r the highest bytes of wide character is zero the lowest byte of wide character is multi byte character It is utf8 if the multi byte character is transformed a wide character this value is UTF 16 Example 1 wide character string Next some program is shown description of the same meaning as wchar_t kanji2 L BF 2 sjis wchar_t kanji2 Ox8abf 0x8e9a 0x0032 0x0000 euc wchar_t kanji2 Oxb4c1 0xbbfa 0x0032 0x0000 utf
372. sed in read write lseek and close routines The file number and corresponding real file must be controlled by low level library 1 is returned if the file cannot be opened CC32R MANUAL 351 Chapter 11 Low level Library read Low level function Syntax Summary Return Value Description int read int file_no char buffer unsigned int count file_no file number of the file to be read buffer pointer to the area in which the data read is stored count number of bytes to be read Reads data from a file Number of bytes actually read Successful 1 Failed This function reads a range of data within the bytes indicated by count from the file indicated by file number file_no and stores it in the area indicated by buffer The read write position in the file is advanced forward by the number of bytes read When the function was able to read normally return the number of bytes read if it failed to read return the value 1 If there was no data to read and the end of file EOF was reached return the value 0 and not 1 CC32R MANUAL 352 Chapter 11 Low level Library write Low level function Syntax Summary Return Value Description int write int file_no const char buffer unsigned int count file_no file number of the write target file buffer pointer to the area into which data is written count bytes of data to be written W
373. sing base register function LD24 RO _var LDUB R1 _ var REL BASE12R12 LDUB R0 R0 A 1 2 2 Accessing constants a Targeted constants When casting constants to the pointers shown below A 1 3 Objects Targeted by Base Register Function to access an area specified by the pointer and when this address is in the range base address 0x8000 to base address 0x7FFF around the base address they are the target of the base register function Example 1 int 0x12345678 100 writing to address 0x12345678 Example 2 return int 0x12345678 reading from address 0x12345678 Appendix A 3 Appendix A Extended Functions Reference b Generated code When outputting code for access to a constant address the expression constant address base address is used as the relative indirect offset Example code output When the base register is R13 012340000 Hex Example 1 Writing No base register definition Using base register function SETH RO HIGH 0x12345678 OR3 RO RO LOW 0x12345678 ST R1 0x5678 R13 ST R1 RO Example 2 Reading No base register definition Using base register function SETH RO HIGH 0x12345678 OR3 RO RO LOW 0x12345678 LD RO 0x5678 R13 LD RO RO A 1 3 Objects Targeted by Base Register Function A 1 3 1 Memory class linkage Objects targeted by the base register function must be objects statically mapped to me
374. sion mathematic functions math h When you use the C standard double precision mathematic functions or the single precision mathematic functions Note that because the header math h includes the functions of mathf h you do not need to include mathf h if you already have math h included The following shows the contents written in these header files 1 Prototype declaration of functions The prototype declaration of single precision mathematic functions are written in mathf h while the prototype declaration of both double precision and single precision mathematic functions are written in math h 2 Function name replacement In mathf h if the m32re5 option to use the FPU instructions of the M32R FPU core is specified when compiling the source file calls to the single precision mathematic functions that do not use the FPU instructions are changed to calls to the equivalent functions in the single precision mathematic function library that use the FPU instructions CC32R MANUAL 356 Chapter 12 Single precision Mathematical Function Library Example 1 When m32re5 is specified at the same time include lt mathf h gt lt math h gt also acceptable ans cosf rd Compiled with m32re5 added ans cosf5 rd Becomes equivalent to this This replacement for the cosf function case for example is accomplished by a macro like the one shown below define cosf cosf5 Defined the same
375. so that the first argument is set to R4 and the second to R5 CC32R MANUAL 115 Chapter 6 C C Calling Conventions 6 7 Interfacing C and C Programs In cases where multiple programs modules are combined to develop one application it may occur that each program interact by referencing data in another program or calling functions from another program This section describes how to reference a C program from a C program and how to reference a C program from C by using an example 6 7 1 extern C and External Symbol Names The external symbol names generated from function names and static data members when compiled in C language are converted following different rules than in C language There are two methods to know the external symbol names generated by a compiler as explained below 1 When compiling specify the option to generate an assembly language file S CS or cs and check the external symbol name that is output 2 From the generated object module or load module generate map information by adding the option mangle to map32R When C functions are defined by adding extern C external symbol names are generated following the same rules as for C language functions However said function cannot be overloaded CC32R MANUAL 116 Chapter 6 C C Calling Conventions 6 7 2 To Reference C Program Data from a C Program For the data ina C program to be referenced from a C program defini
376. stack It is the program of the assembly language passing the argument of the function by using stack and that calls function of C C language or is called from it They include start up program and low level library functions How to adapt Change the assembly language program in accordance with the setting rule of the function argument of V 3 00 Release 1 Refer to the chapter of the C C calling rule of the M3T CC32R user s manual lt C C Compiler gt When function passes the argument by registers this function name is not under score _ to the top but dollar mark is added in object file You need to change the functi on name in the assembly language that you have this to the name that complied with When you links these programs above 1 and 2 without this adaptation and program made for CC32R V 3 00 Release 1 or newer the error external symbol not defined will occur E Precautions to be observed when debugging C for the library To debug the C sources for any object module in the library make sure that the library file is located in the same directory as the one in which the object module extension ml was created Appendix C 5 Appendix D Precautions on a compiling Appendix D Precautions on a compiling D4 Regarding Link Even when only linking object files make sure the linker is started through the compile driver cc32R by using the mklib option This is because if the user
377. stdlib h gt void srand unsigned int seed seed initial value for a sequence of pseudo random integers generation Return Value None Description The srand function sets the initial value seed for the sequence of pseudo random integers generated by the rand function If the srand function sets the same value as the initial value while the rand function is generating pseudo random numbers the same sequence of pseudo random integers is generated again When the rand function is called before the srand function the initial value for the sequence of pseudo random integer generation is set to 1 CC32R MANUAL 270 sscanf Chapter 9 C Standard Library Input output function Gets data from a memory area and converts the data by following the format Syntax Return Value Description include lt stdio h gt int sscanf char s const char control 33 Si pointer to the memory area to which data is to be stored control pointer to format string lt 3 variable argument list receivers The number of arguments Successful the number excludes arguments of converted and substituted sn conversion and arguments inhibited by EOF The end of input data is reached before completion of the first conversion except for or an error occurs The sscanf function gets data from the memory area denoted by s exchanges and edits the data in the format specified by control
378. suffix f denotes the float type 1 234 Since no precision is specified this real constant indicates the double type 3 Declare the argument in the float type in prototype declaration Where the floating point numerical value is used for the function return value and argument be sure to carry out prototype declaration with type declaration in the argument Example extern void funcl float void func2 floa fv funcl fv In the absence of prototype declaration of func1 function the argument is of a double type 4 Do not use variable arguments Since the float type covering the variable arguments is transformed to the double type see to it that no float type is handled in variable arguments A 5 3 Precautions in Utilizing FPU Instruction A 5 3 1 CAUTION float_only Option The float_only option is such that the FPU instruction is applicable to all floating point operations even when the source files as described If used however give the greatest possible care thereto since there arises a problem of compatibility as described below a It is not match to ANSI C ISO C standard b Function name replacement In math h if the float_only option is specified when compiling the source file calls to the double precision mathematic functions are changed to calls to the equivalent functions in the single precision mathematic function Example 1 When float_only is s
379. t Characters ASCII characters for which isalnum isalpha iscntrl islower isprint or isupper returns true are as follows Function Tested character set isalnum 0 9 A Z a z isalpha A Z a z iscntrl 0x00 0x1F 0x7F islower a z isupper A Z isprint 0x20 0x7E e ANSI C 7 5 1 Treatment of error conditions lt The value returned by the mathematics functions on domain errors gt If a definition area error occurs in a numerical value calculating function EDOM is set to errno lt Whether the mathematics functions set the integer expression errno to the value of the macro ERANGE on underflow range errors gt If an underflow occurs in a numerical value calculating function ERANGE is setin errno e ANSI C 7 5 6 4 The fmod function lt Whether a domain error occurs or zero is returned when the fmod function has a second argument of zero gt If the second argument of the fmod function is 0 a domain error occurs and EDOM is set in errno the calculation result is not guaranteed CC32R MANUAL 331 Chapter 10 The cc32R s Behavior e ANSI C 7 7 1 1 The signal function lt The set of signals for the signal function gt It is depends on the user defined signal function a low level function lt The semantics for each signal recognized by the signal function gt It is depends on the user defined signal function a low level function lt The default hand
380. t type floating point number DBL_MAX_10_EXP Indicates the max value of the power of 10 which can be expressed in a double type floating point number LDBL_MAX_10_EXP Indicates the max value of the power of 10 which can be expressed in a long double type floating point number FLT_MIN_10_EXP Indicates the min value of the power of 10 which can be expressed in a float type floating point number DBL_MIN_10_EXP Indicates the min value of the power of 10 which can be expressed in a double type floating point number LDBL_MIN_10_EXP Indicates the min value of the power of 10 which can be expressed in a long double type floating point number FLT_DIG Indicates the max No of digits of decimal precision of a float type floating point number DBL_DIG Indicates the max No of digits of decimal precision of a double type floating point number CC32R MANUAL 151 Macro Name LDBL_DIG Chapter 8 Standard Header Files Table 8 4 Macros Defined by float h 3 3 Description Indicates the max No of digits of a decimal precision of a long double type floating point number FLT_MANT_DIG Indicates the max No of digits of the mantissa of a float type floating point number when expressed to radix DBL_MANT_DIG number when expressed to radix Indicates the max No of digits of the mantissa of a double type floating point LDBL_MANT_DIG point n
381. t arithmetic functions no operations can be performed where signed and unsigned types coexist When using the arithmetic functions please make sure that all of the 64 bit integers input and output unanimously are either signed or unsigned Example When adding a signed LONG64 variable b to an unsigned ULONG64 variable a and assigning the sum to an unsigned variable c Incorrect c addl64 a b or c addul64 a b b is converted to unsigned type and all are changed to unsigned type Correct c addul64 a 164_to_u164 b CC32R MANUAL 364 Chapter 14 Messages from the C Compiler Chapter 14 Messages from the C Compiler 141 Getting Execution Result of the C Compiler You can judge the execution result yielded by the C compiler by looking into the messages and the exit status 14 1 1 Message Format Upon encountering an error condition the C compiler outputs the error message describing the error status to the standard error output in the following format e Syntax input_information message_type message Note input_information is output only when necessary e Pattern filename message_type message file name line number message_type message lt command line gt message_type message message_type message Note Underlined items are input_information no the underline is output Example smp c line 2 error untermin
382. t contains a description of one or more asm functions is compiled after specifying optimization a warning message like the one shown below may appear with the optimization partly suppressed We recommend that functions which use the inline assembly facility be defined in another module Warning message lt command line gt warning xxx c unable to optimize skipped phase CC32R MANUAL 143 Chapter 7 Embedded Applications Programming e Other limits The following descriptions should not be included in the asm function If such a description is included in the asm function the user must be responsible for the results e Branch instructions e Assembler s pseudo instructions and macro instructions e Changing contents of stack e Label definitions Reference to C C compiler generated labels CC32R MANUAL 144 7 5 4 Chapter 7 Embedded Applications Programming asm Function Example Figure 7 7 shows examples using the asm functions Multiply arrays X cnt and Y cnt and obtain the result pragma keyword asm on void sumXY short X short Y int cnt int output asm mvtachi r0 n mvtaclo r0 0 for 7 cnt gt 0 4K Y asm macwlo r0 rl X Y asm mvfachi r3 n m st r3 r0 n y mvfaclo r3 n st r3 r0 n int output Figure 7 7 Example of asm Functions Figure 7 8 shows the compiled source program shown in Figure 7 7 CC32R MANUAL 145
383. t integer lt gt long or unsigned long 5 Other functions Sets immediate data or replaces a decimal string etc with a 64 bit integer Immediate set String to 64 bit integer conversion These 64 bit integer arithmetic library functions are listed in Table 13 1 1 to 5 below For the return values and return types of these functions refer to the C langua ge prototype declaration formats shown in the table Table 13 1 64 bit integer arithmetic functions 1 Arithmetic operation functions 1 2 function name Perform Operation Prototype declaration of C language S signed U unsigned Four rules of arithmetic remainder and monadic negative LONG64 add1l64 LONG64 n1 LONG64 n2 S addition nl n2 LONG64 subl64 LONG64 nl LONG64 n2 S subtraction nl n2 LONG64 mull64 LONG64 nl LONG64 n2 S multiplication AL aie LONG64 divl64 LONG64 nl LONG64 n2 S division nl n2 LONG64 mod164 LONG64 nl LONG64 n2 S remainder nl n2 LONG64 negl64 LONG64 n1 S monadic negative al ULONG64 addul64 ULONG64 nl ULONG64 n2 U addition nl n2 CC32R MANUAL 360 Chapter 13 A set of 64 bit integer arithmetic functions Table 13 1 64 bit integer arithmetic functions 1 Arithmetic operation functions 2 2 function name Perform Operation Prototype declaration of C language S
384. tails 2 For details of the map32R map generator see Part 3 Map Generator map32R in the M3T CC32R User s Manual lt Assembler gt Appendix A 2 Appendix A Extended Functions Reference A 1 2 Types of Access Targeted by Base Register Function and Code Output A 1 2 1 Access to Variables a Targeted variables The variables specified on the object registration line of the Access Control File and matching A 2 2 Objects Targeted by Base Register Function are targeted by the base register function Objects defining addresses mapped by pragma ADDRESS are treated in the same way b Generated code When outputting the code for accessing variables the expression variable label base symbol is used for the relative indirect offset The base symbol shows the corresponding base address and the format is ___REL_BASExx where xx is the number of the register 11 to 13 However note that this symbol is not defined in the output code of the compiler referenced by IMPORT and it is therefore necessary to define the value in the startup file etc Example code output The following is an example of the code output for base R12 and global variable var access In this example var is an unsigned char type Example 1 Writing No base register definition Using base register function LD24 RO _var STB R1 _var __REL_BASE12 R12 STB R1 R0 Example 2 Reading No base register definition U
385. tandard input output memory management signal handling time manipulation etc depend on the target system In the C standard library the functions dependent on the target system are separated as low level functions low level library and input output specifications of the process functions low level functions see Table 11 1 and Table 11 2 that achieve respective actions are defined In the C standard library the actions dependent on the target system are effected by means of calling the low level functions To use actions dependent on the target system in a C C program you must prepare necessary low level functions Specifications of individual low level functions are given in 11 2 The Low level Functions Specifications Table 11 3 shows which C standard library function uses which low level function Table 11 1 Low level Functions Used by C Standard Library Low level Function Description open Opens a file close Closes a file read Reads data from a file write Writes data into a file lseek Reposition the read write point in a file _get_core Allocates a memory area _rel_core Frees a memory area getuniqnum Obtains the unique number for each process _strerror Gets the error message corresponding to an error number _exit Exits a program CC32R MANUAL 339 Chapter 11 Low level Library Table 11 2 shows the functions which are defined as low level functions in C standard
386. te calculations for some instructions that are executed immediately after 0 division For more details refer to the Technical News No M32R 06 0301 M32R ECU series Usage Notes for 0 Division Instruction The correspondence in CC32R and explain about avoiding the zero division problem by zdiv option below Appendix C 2 Appendix C Restrictions on Usage Correspondence methods The case of C C language program or assembly language program 1 Please re program so the zero division does not occur in logical following the teh nical news suggests CC32R generates the DIV instructions to the integral calculat ions both divisions and also and remainders and also of C C language please program so that the divisor do not become 0 Also in assembly language please program so that the second parameter of DIV instructions it means divisor do not become 0 2 If you can not accomplish 1 completely re compile or re assemble with zdiv opt ion insted of 1 The case of using standard libraries Even if the DIV instructions computes the zero dividion in the standard library funct ons the problem does not occur It is because the standard library is already treated about avoiding this problem Furthermore The functions of the zero division measurement libraries m32RcRZ lib m32RcRZM lib m32RcRZL lib that was prepared in CC32R V 4 10 Release 1 have be en incorporated to general standard libraries m32
387. ted by the assembler and the error message is output to the assembly source file but not to the C C source file If an assembler error message is output after starting the C C compiler first check the contents of the asm function e Limitations on parameter specification Although expressions can be written in asm function parameters we recommend that only constant expressions and identifiers but no other expressions be written If an expression like the one shown below is written the C C compiler may not operate correctly An expression that has side effect e g operators such as expressions that contain a function call Complicated expression Limitations on length of asm function Up to about 1 000 characters can be written in an asm function When writing multiple lines of assembly code we recommend that they be divided and written in multiple asm functions Limitations on labels We recommend using labels which are not the duplicates of those generated internally by the compiler label names beginning with the underscore _ Make sure any parts of label names except the underscore are not the duplicates of symbol or function names defined in C C language Limitations on instructions writable in asm function Pseudo instruction and macro instructions cannot be written in a asm function Limitations on optimization of a program in which asm functions are written When a program tha
388. ter string The concatenated string has been omitted CC32R MANUAL 369 Chapter 14 Messages from the C Compiler Table 14 4 Warning Messages 3 4 Message Description more arguments specified than in imputed definition The number of arguments designated is too many xxx multiple optimization options ignored The command line option for optimization is duplicated The option xxx is ignored nothing declared in current declaration ignored No declaration has been made in a declaration line The declaration has been ignored number of parameters not equal between use and definition The number of arguments doesn t agree with that given in the prototype declaration parameter incompatible with previous use There is no compatibility between arguments xxx requires exactly 1 identifier What is to be specified by xxx is a single identifier shift count greater than number of bits The count of shift has turned greater than the number of bits storage specifier conflicts with prior declaration this declaration ignored The storage class designation doesn t agree with that previously declared This declaration has been ignored the characters are found in a comment The characters is found inside a comment too many digits in floating point number extra digits ignored The number of digits of a floating point number is too many The excess digits have been ignored
389. than a printable character A printable character is a character to be indicated on a display and corresponds to the ASCII codes from 0x20 to 0x7E If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 228 isdigit Chapter 9 C Standard Library Character handling function Judges whether a decimal digit or not Syntax Return Value Description Caution include lt ctype h gt int isdigit int c CI character to be judged non 0 cis decimal digit 0 cis anything other than decimal digit Returns any value other than 0 if c is a decimal digit and returns 0 if c is not a decimal digit e Decimal digits 0123456789 If a value of c is not included in a range to be expressed by the unsigned char type and if it is not EOF the operation of this function is not guaranteed CC32R MANUAL 229 isgraph Chapter 9 C Standard Library Character handling function Judges whether a printable character other than space Syntax Return Value Description Caution include lt ctype h gt int isgraph int c G character to be judged non 0 cis a printable character excluding space 0 cis not a printable character excluding space Returns any value other than 0 if c is a printable character excluding space and returns 0 if c is not a printable
390. the alignment is 2 bytes There are 4 CC32R MANUAL 92 Chapter 5 Internal Data Representation bits left following b in that 2 byte location the 9 bit long c is not accommodated c is stored in the next 2 byte location If c is short type it is stored in the next 2 byte location see figure below When the data type of c is short c is allocated in the next 2 byte area 4 5 7 9 9 oe 8 l EEA e ES 2 bytes gt 2 bytes gt ja 2 bytes gt h 2 bytes 4 bytes gt lt 4 bytes CC32R MANUAL 93 Chapter 5 Internal Data Representation 5 10 Internal Representation of Class Type The class is an extended version of the structure in C language Although only data can be written in a structure as its members both data and a function that manipulates the data can be written together in a class They are referred to as member variables and member functions which together are called class members A class in C permits accesses to class members to be limited The access specifiers private and public are used to specify accesses to class members within a class definition Members written after private are handled private members Memters written after public are handled as public members Private members are not open to the outside and cannot be altered by referencing from an external function As a rule only the member functions of the same class can access private members Public m
391. the default registers RO to R7 as well as the specified register R12 Also instruction RTE is executed at the end of the function Appendix A 27 Appendix A Extended Functions Reference pragma keyword asm on pragma keyword asm off Function Declares the use of the in line assembly function asm function Syntax pragma keyword asm on pragma keyword asm off Description pragma keyword asm on off causes asm to be interpreted as an asm keyword rather than as the normal identifier This enables the in line assembly function to be used To have asm again used as an identifier specify pragma keyword asm off See 7 4 In line Assembly function for details of the in line assembly function Appendix A 28 Appendix A Extended Functions Reference A4 Inline expansion This function is such that the contents of C language function to be called are expanded directly in place of function call Since the overhead such as the subroutine jump instruction BL can be omitted it is possible to obtain a more advantageous code in view of speed than normal function call by means of inline expansion CAUTION When the size and scale of a function to be expanded are large and there are many areas to be called this expansion may adversely be affected for example the code size increases It is therefore necessary to use this inline expansion function after satisfactorily checking this effect Format
392. the localeconv function LC_TIME Sets and searches information that affects the strftime function CC32R MANUAL 156 Chapter 8 Standard Header Files 8 2 7 math h Performs prototype declaration and macro definition of arithmetic functions Table 8 8 and Table 8 9 list the functions declared and macros declared by math h Table 8 8 Functions Declared by math h Function Description Reentrant acos Obtains the arc cosine of a floating point number Xx asin Obtains the arc sine of a floating point number Xx atan Obtains the arc tangent of a floating point number x atan2 Divides a floating point number by a floating point Xx number and obtains the arc tangent of the result ceil Computes the integer ceiling of a floating point number x cos Obtains the cosine of radians of a floating point number Xx cosh Obtains the hyperbolic cosine of a floating point number Xx exp Obtains the exponential function of a floating point Xx number fabs Obtains the absolute value of a floating point number x floor Cuts off the fraction of a floating point number Xx fmod Computes the floating point remainder x frexp Divides a floating point number into products of value Xx 0 5 1 0 and 2 to the nth power Idexp Performs multiplication of a floating point number and 2 x to the nth power log Obtains natural logarithm of a floating point number x log10 Obtains the base 10 logarithm of
393. thmetic types integer types floating types Scalar types integer types floating types pointer types Aggregate types structure types struct array types Derived declarator types array types pointer types function types Derived types array types pointer types function types structure types struct union types union Bool types bool CC32R MANUAL 59 Chapter 4 C Programming Language Specification Table 4 13 Type Representations Called Description Composite types They are constructed from two types which are compatible Incomplete types They describe object but lack information needed to determine the sizes of objects e g an array type unspecified its size Object types Describe objects without function types Function types Describe functions They determine types of the return value and parameters and the number of parameters Example char funcl int int funcl is the pointer to a function which returns a pointer to char and has two int type parameters Qualified types Types with any type qualifier const or volatile Unqualified types Types without any type qualifier const or volatile Top types In a derived type the top type is outermost derivation represented by type specifiers and qualifiers In a no derived type the top type is itself Example const int i This means that i is pointer to qualified int The top type is pointer t
394. tial values CTOR and VTBL will be located at addresses beginning with 400 hex and that the sections D runtime area B and COMMON will be located at addresses beginning with 804000 hex When linking do not start the linker Ink32R directly Always be sure to use the compile driver cc32R to link Example cc32R mo To link only the objects written in C or assembly language the Ink32R can be started directly without causing any problem 3 1 10 Creating a Library To create a library using object module files employ the method for specifying the mklib option in cc32R as shown below cc32R mklib o mylib lib lib1 mo lib2 mo lib3 mo This results in creating a library named mylib lib from the object modules lib1 mo lib2 mo and lib3 mo When creating a library file do not start the librarian lib32R directly Even when creating a library file make sure the librarian is started through the compile driver icc32Ri by using the mklib option To create a library file with only the objects written in C or assembly language the lib32R can be started directly without causing any problem CC32R MANUAL 21 Chapter 3 Invoking the Compiler Er Command Options 3 2 1 Command Options The functions of the C C compiler command options are listed in Table 3 6 Table 3 6 Command Options for the C Compiler 1 11 Option access Access Control File Description Specified when using the base register functi
395. tialize routine SETH RO HIGH _cpp_main OR3 RO RO LOW S _cpp_main JL RO i End of program infinity loop i HALT BRA HALT section C data align 4 section ROM_D data align 4 section CTOR data align 4 section VIBL data align 4 F r S_exit BRA r export S_exit export _get_core export Swrite export S_rel_core export S_strerror export Sclose export Sgetunigqnum export Slseek export Sopen export Sread export Sgetenv export Sraise export Sremove section P code align 4 Terminate the program run HALT Get the heap memory routine _get_core MV R1 R4 SETH R2 HIGH HEAP_POINTER OR3 R2 R2 LOW HEAP_POINTER LD RO R2 ADD R1 RO ST R1 R2 JMP R14 i Not implemented routine i Swrite _rel_core _strerror Sclose S getunignum Slseek Sopen Sread Sgetenv Sraise Sremove LDI RO 0 JMP R14 CC32R MANUAL 136 Chapter 7 Embedded Applications Programming HEAP_POINTER HEAP_TOP USTACK BOTTOM ISTACK BOTTOM COPYRIGHT C NY ste section DATA W section RES B RES B RES B section SETH OR3 JMP end D data align 4 HEAP_TOP B data align 4 HEAPSIZE USTACKSIZE ISTACKSIZE RI code locate h 00000000 RO HIGH STARTUP RO RO LOW STARTUP RO STARTUP KKK KK KKK KKK KKK KKK KKK KKK KKK KKK KKK KK KKK KKK KKK KKK KKK KKK KKKKKKKKEKKK t 2004 RENE
396. tion Caution include lt stdio h gt int remove const char filename filename name of the file to be deleted 0 Successfully deleted non 0 Error The remove function deletes the file denoted by filename even if the denoted file is currently open Whether a currently open file is changed or deleted depends on the operating environment To call the remove function in actual the user written remove function is required see Section 11 1 and Table 11 2 CC32R MANUAL 259 Chapter 9 C Standard Library re n a m e input output function Renames a file Syntax include lt stdio h gt int rename const char old const char new old original file name new new file name Return Value 0 File name is changed non 0 Error Description The rename function changes the name of the file specified by old to the name denoted by new The rename function will change the name of the file which is denoted by old and currently open also it will change the name of the file specified by new even if the name specified already exists Caution Whether the currently open file is changed or deleted depends on the operating environment To call the rename function in actual the user written rename function is required see Section 11 1 and Table 11 2 CC32R MANUAL 260 Chapter 9 C Standard Library rewi n d input output function Moves the current read write posit
397. tion writes the current calendar time into the buffer specified by timer To call the time function in actual the user written time function is required see Section 11 1 and Table 11 2 CC32R MANUAL 292 Chapter 9 C Standard Library t m pfi l e input output function Creates a temporary file Syntax include lt stdio h gt FILE tmpfile void Return Value Pointer to the stream of the generated file The file is generated NULL The file cannot be generated Description The tmpfile function generates a temporary file The generated file is opened in the binary file update mode wb and is automatically deleted upon closing of the file or terminating the program CC32R MANUAL 293 Chapter 9 C Standard Library tmpnam Input output function Creates a not existing temporary file name Syntax Return Value Description include lt stdio h gt char tmpnam char s Si buffer to store the name of file generated by the tmpnam Generated file name The file name is generated NULL The number of the tmpnam function calls exceeds TMP_MAX The tmpnam function generates a new temporary file name and stores it into the buffer specified by s When NULL is substituted for s the result is written into the tmpnam internal buffer The buffer is overwritten every time tmpnam is called The tmpnam function can be repeatedly called up for TMP_MAX times defined in stdio
398. tions in the C program should be made by using the same types as in the C program C program C program extern struct int a int b s LI pJ extern int i j struct int a int b s void func void S a s b i j Figure 6 11 Example for referencing C program data from a C program ITI NOTE H Data of C specific type e g class cannot be used in a C program 6 7 3 Reference C Program Data from a C Program For the data in a C program to be referenced from a C program extern declarations should be made by using the same types and names as those defined in the C program C program C program int i j extern struct int a int b s struct int a int b s extern int i j void func void S a s b i j Figure 6 12 Example for referencing C program data from a C program ITI NOTE Data of C specific type e g class cannot be used in a C program CC32R MANUAL 117 Chapter 6 C C Calling Conventions 6 7 4 Call C Program Functions from a C Program For the functions in a C program to be called from a C program the function to be called should have its prototype declared by using extern C as in the example shown below Calling program C program extern G ant functint int void foo fune 1 2 Called program C program int func i
399. tive Therefore attached C standard library and the object file that used the base register function correspond to above 1 In such case the base register does not have the base address when the standard library function is executing The base register will returns the base address after these standard functions although the base register will not have the base address when as follows 1 Interrupt processing routine Because the interrupt process happens during execution of standard library functions you must think value of the base register is undefined 2 User function that is called from the particular standard library functions qsort bsea rch etc Solutions When the base register function and the C standard library are used in same time please use one of the solution methods following 1 and 2 1 Create a special standard library by using same access control file from the user progr am And replace present standard library with it 2 Re compile interrupt processing routine and user function that is called from the part cular standard library functions qsort bsearch etc by not using the base register fun ction E Avoiding the integral zero division problem of M32R ECU series In M32R ECU Series Microcomputer if zero division calculation its divisor is equal zero is executed for integral division instructions they are DIV DIVU REM and REMU abbreviat ed as DIV instructions the result will be inaccura
400. tively will be automatically generated These labels are named as shown in Table 7 2 Table 7 2 Reserved Label Names for Sections Address Label Name Example Example D section ROM_D section parpaddtess TOP TOP_D __TOP_ROM_D of section ae iia END END_D __END_ROM_D of section For further information on section allocation and section initialization refer to the M3T CC32R User s Manual lt Assembler gt Part 1 Linker Ink32R The link can be specified by the command option during start up of the C C compiler e Initialization by the start up program e For initialization purposes the data in the ROM_D section in the ROM area is transferred to the D section of the RAM area e The B section in the RAM area is cleared to zero filling with 0 data CC32R MANUAL 132 Chapter 7 Embedded Applications Programming Zero clear RAM Area Transfer this initial data block to the for the D area for the ROM Area section in RAM Figure 7 5 Initial Setting of Data Area When programming these processes use the reserved labels see Table 7 2 and the section names for referencing the start address of the sections 7 3 7 Call the_Cpp_ Main Function Call the _cpp_main function in order to initialize the C language and use a standard library 7 3 8 Processing the Cpp_ Main Function Initialize the C language and make initial settings to use a standard library and then cal
401. tored within the range of 0x00000000 to 0x00FFFFFF The option small memlarge specifies that the source file be compiled for the small model with memlarge attached full 32 bit memory space supported for only data The option medium specifies that the source file be compiled for the medium model code stored within the range of given address A to A OxOOFFFFFF and the full 32 bit memory space supported for data The option large specifies that the source file be compiled for the large model full 32 bit memory space supported for both code and data Also refer to Appendix A 2 for more information about this option CC32R MANUAL 31 Chapter 3 Invoking the Compiler Table 3 6 Command Options for the C Compiler 11 11 Option stack Description Selecting the stack option generates a stack utilization display file a text file whose input file name extension is changed to stk and generates an object file too at the same time One stack utilization display file is generated for each source file written in C language Stack sizes of individual functions are output to the file together with a list of function names called by them The stack utilization display file is used as an input file to the stack size calculation utility stk32R Selecting this option concurrently with one of the E M and P options generates no stack utilization display file The use status of the stack used under the in lin
402. tors for the stream pointed to by fp The indicators are data held per stream file Both data indicate whether an error is occurred or not and whether a file is completed or not and such data can be referred through the ferror and feof function respectively If any information on the error occurrence and file completion cannot be obtained through the return value of the functions which handle the stream this function checks the status of the file by means of these data CC32R MANUAL 186 Chapter 9 C Standard Library C l O C k Date and time function Gets the elapsed processor time Syntax include lt time h gt clock_t clock void Return Value Not supported Description The clock function depends on your system environment Therefore the clock function is not supported for the present Caution To call the clock function in actual the user written clock function is required see Section 11 1 and Table 11 2 CoO S Mathematics function Obtains the cosine of radians of a floating point number Syntax include lt math h gt double cos double x X floating point number in radians Return Value Calculated value of argument Description The cos function calculates cosine of x CC32R MANUAL 187 Chapter 9 C Standard Library C O S h Mathematics function Obtains the hyperbolic cosine of a floating point number Syntax include lt math h gt double cosh double x
403. total size of data in D and B sections exceeds 64 Kbytes do not specify this option Otherwise a relocation size overflow or another error may occur because the 16 bit displacement is exceeded See Figures 3 1 and 3 2 e Prototype declaration of const qualified variables When const qualified variables located in D section are going to be referenced in another source a prototype accompanied by const must always be declared Example When a variable declared in program b is referenced in program a Program a Program b extern int aa int aa extern const int bb const const int bb wee See ana void test void aa 0 rene bh i else foai CC32R MANUAL 33 Chapter 3 Invoking the Compiler Do not destroy the content of the R12 register Because the R12 register is used from start to end of the program as the Rsrc register for register relative indirect addressing be careful not to destroy the content of the R12 register TLower Add Address Top Address of RAM ress space n ERRIRE 4 Senate 32Kbytes Area of D and B y sections Within t 64Kbytes Values set in R12 and REL_BASE Higher Address Figure 3 4 Values to be set in R12 and__ REL_BASE ADDI _ R6 1 BGTZ R6 loop1 loop_cntl export _ REL BASE Newly added __REL_BASE EQU h 28000 Newly added LD24 R12 __REL_BASE Newly added BL _c_main END
404. tring to be brought to conversion sequentially from the first character and stops reading when it detects either a null character or a character that it cannot interpret as a number that assumes a value having the radix base and sets in endptr the pointer pointing to the character handled at the time only when endptr does not hold NULL Space characters preceding the string to be brought to conversion the first segment where a non space character does not appear are ignored and not converted If base is 0 strtoul function makes a judgment on the radix from the first character that nptr points to see 4 1 3 2 Integer Constants When the value of base is between 2 and 36 the value of base becomes the radix for conversion Characters a through z and A through Z among a string to be brought to conversion are made to correspond to 10 through 35 and a character equal to or greater than the value of base is recognized as a character that strtoul cannot interpret 0 after a sign and 0x 0X at the time when base is 16 are ignored If conversion fails strtoul function returns 0 as a return value and nptr is set in endptr only when endptr does not hold NULL If the value after conversion overflows i e it cannot be expressed by unsigned long strtol returns ULONG_MAX as a return value and ERANGE is set in errno CC32R MANUAL 288 strxfrm Chapter 9 C Standard Library String handling function Converts the stri
405. trings Syntax include lt string h gt int strcmp const void s const void s2 Sl pointer to string to be compared S2 pointer to string to be used for comparison Return Value Positive value contents of s1 gt contents of s2 0 contents of s1 contents of s2 Negative value contents of s1 lt contents of s2 Description The strcmp function compares the contents of string specified by s1 and those specified by s2 and returns the result CC32R MANUAL 273 Chapter 9 C Standard Library st rco l l String handling function Compares the two strings based on the current locale Syntax include lt string h gt int strcoll const char si const char s2 sl comparison string 1 S2 comparison string 2 Return Value Positive value contents of s1 gt contents of s2 0 contents of s1 contents of s2 Negative value contents of s1 lt contents of s2 Description As the locale only the C environment is supported The strcoll function compares s1 with s2 based on LC_COLLATE locale h definition denoted by the current locale st rc py String handling function Copies the contents including null characters of the source string to the target memory area Syntax include lt string h gt char strepy char sZ const char s2 isi pointer to space to which string is copied S2 pointer to string to be copied Return Value Pointer of the memo
406. ts extension and then starts the process required for that file such as compiling the file if it is written in C language or linking the file if it is object module Table 3 4 shows the starting process for each type of file See Figure 1 1 Programming Flow by CC32R Table 3 4 Input File and First Procedure Extension Type determined by the C C Compiler First Procedure C C language source file Compiling C cpp C language source file Compiling C CC32R MANUAL 18 Chapter 3 Invoking the Compiler ms Assembly language source file Assembling mo Object module file Linking For C used exclusively to create load modules ml Object module file Library creation For C used exclusively to only when mklib create libraries is specified Others Object module file Linking 3 1 7 Output File Naming The name of the output file is the one specified by the o option If this option is not used the C C compiler automatically gives the name to the output file as shown in Table 3 5 The o option lower case is ignored if two more input files are specified and the output is not a load module The output file is given the name according to Table 3 5 File name file mi Table 3 5 Output File Names default Description The name of the preprocessed C language source file The file name is the name of the C language file with the extension replaced as mi file ms
407. tus of the program to the environment This function signals the environment that the program is to end Write the end process of the current environment in this function definition CC32R MANUAL 344 Chapter 11 Low level Library _g et c O re Low level function Syntax Summary Return Value Description void _get_core int size size the size of data to be allocated Allocates a memory area The start address of the allocated area Successful void 0 Failed The _get_core function allocates a memory area size is the size of memory area to be allocated If size is smaller than the available space to allocate an error is occurred When allocation is successful the start address of the location is returned Otherwise void 0 Refer to examples shown below define HEAPSIZE bytes Specify the size bytes of the area managed by _get_core static unionf int dummy char heap HEAPSIZE heap_area Declare the data area for allocation This is union which has the int type member as the first menber to align in the 4 byte boundary static char brk heap_area heap Initialize by substituting the start address to be allocated void _get_core int size char p if brk size gt heap_area heap HEAPSIZE Check the area for remainder return void 0 p brk brk size 22 wee Update the end address
408. uence however the null character is not counted as the number of output characters return value For more information on the format control refer to the description of the fprintf function The arg indicating the variable argument list must be initialized by the va_start and va_arg macros The vsprintf function does not call the va_end macro CC32R MANUAL 303 Chapter 9 C Standard Library wcsto m bs General utility function Converts a wide string into a multibyte string Syntax Return Value Description include lt stdlib h gt size_t wcstombs char s const wchar_t pwcs size_t 7 S multibyte string storage buffer PWCS wide string n number of bytes to be written Number of characters converted Successful the number excludes the termination null 1 Invalid wide character is found during conversion casting 1 to size_t upon returning mony The maximum value of multibyte characte is 3 byte And even euc sjis utf8 in addition to C are supported as the locale The wcstombs function converts the number of bytes specified by n out of the wide string specified by pwes into multibyte characters and stores the result into the buffer specified by s CC32R MANUAL 304 Chapter 9 C Standard Library wctomb General utility function Converts a wide character into a multibyte character Syntax Return Value Description
409. um used as type is incomplete or undefined Either an incomplete or an undefined enum is used enumeration constant out of range The value of enum constant has exceeded a proper range EOF in comment The end of comment is not present expected parameter list missing or missing type for variable Either an argument or an initializer is not found Or the type of a variable is indefinite fewer arguments are specified than declared The number of arguments is less than declared first operand of conditional operator must have scalar type The first term of a conditional operation must be of scalar type A ternary operation must be of scalar type first operand of is not struct union type The operator period must be used for a structure or a union first operand of gt must be pointer to struct union type The operator gt must be used for a pointer of a structure or a union floating point numbers are not allowed in if constant expression You cannot specify a floating point number in an expression under if function already defined The function has already been defined CC32R MANUAL 376 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 5 15 Message Description function cannot be an array element You cannot make a function an array element function cannot return a function A function cannot return an entity of function type function cannot ret
410. umber when expressed to radix Indicates the max No of digits of the mantissa of a long double type floating FLT_EPSILON Indicates the min floating point number x 1 0 x 1 0 of the float type DBL_EPSILON Indicates the min floating point number x 1 0 x 1 0 of the double type LDBL_EPSILON Indicates the min floating point number x 1 0 x 1 0 of the long double type Classification definition name value Explanation FLT_GUARD 1 Specifies whether or not the multiplication calculation result The macro definitions are as shown below Use the guard bit 1 Not use the guard bit 0 FLT_NORMALIZE 1 Specifies whether or not the library normalize floating numeric number The macro definitions are as shown below Normalize 1 Not normalize 0 FLT_EXP_DIG 8 Indicates the max No of digits of binary precision of the power of the base which can be expressed in a float type floating point number DBL_EXP_DIG 11 Indicates the max No of digits of binary precision of the power of the base which can be expressed in a double type floating point number CC32R MANUAL 152 Chapter 8 Standard Header Files Classification definition name value Explanation LDBL_EXP_DIG 11 Indicates the max No of digits of binary precision of the power of the base which can be expressed in a long double type floating point number FLT_POS_EPS
411. unction but receives pointer to a variable argument list as data to be output not a variable argument list itself This function suffixes a null character to actual output character sequence however the null character is not counted as the number of output characters return value For more information on the format control refer to the description of the fprintf function The arg indicating the variable argument list must be initialized by the va_start and va_arg macros The vprintf function does not call the va_end macro CC32R MANUAL 302 Chapter 9 C Standard Library vsprintf Input output function Outputs a variable arguments list to a memory area by following the format Syntax Return Value Description include lt stdarg h gt include lt stdio h gt int vsprintf char s const char control va_list arg Sj pointer to space to which data is output control pointer to format string arg pointer to variable argument list Number of characters output The vsprintf function converts and edits the variable arguments pointed to by arg according to the format contro and then outputs the result to the area of memory pointed to by s This function is equivalent to the sprintf function but receives pointer to a variable argument list as data to be output not a variable argument list itself This function suffixes a null character to actual output character seq
412. unction returns 1 if input is infinity or NaN include lt mathf h gt lt math h gt also acceptable float func float fin if isinff fin return 1 0f In the case of infinity if isnanf fin return 1 0f In the case of NaN return fin 2 0f Other cases Appendix B 9 Appendix C Restrictions on Usage Appendix C Restrictions on Usage There are restrictions of the CC32R For other precautions of only this version see the Precautions on using of the next chapter E How to get files that is not included the debug information C C compiler cc32R assembler as32R and linker Ink32R have come to be generating the debugging information always Namely the object module and load module files that these tools generate always include the debugging information Such a outputting debug information is not possible to impede in those options The strip32R can process even the object module that compiler and assembler generated in addition to the load module that the linker The strip32R can process even the object module that compiler and assembler generated in addition to the load module that generated the linker In other words if each output files are processed with strip32R after cc32R as32R or Ink32R these tools act as conventional CC32R V 4 10 or before Example of using strip32R expresses a prompt Usually usage The strip32R is able to apply to each output file of the c
413. unctionality ic ti et ti dw2 dws These files are located in the same directory as xx mo and are created referenced updated or deleted as needed for C language processing by cc32R commands Since these files are very important for C functionality do not perform any of the following operations on them until a series of compile link and debug procedures all have finished 1 Updating and deleting C information files 2 Moving C information files to other than the directory that contains the corresponding xx mo files 3 Creating files with the same name as that of any C information file D 6 Regarding External Symbol Names The external symbol names generated from function names and static data members when compiled in C language are converted following different rules than in C language There are two methods to know the external symbol names generated by a compiler as explained below 1 When compiling specify the option to generate an assembly language file S CS or cs and check the external symbol name that is output 2 From the generated object module or load module generate map information by adding the option mangle to map32R When C functions are defined by adding extern C external symbol names are generated following the same rules as for C language functions However said function cannot be overloaded Appendix D 2 Appendix D Precautions on a compil
414. urn an array A function cannot return an array function missing parameter declaration No arguments have been declared on a function function return type incompatible with previous declaration The return type of the function is different from that declared earlier function return type is not declared The return type of the function has not been declared garbage after end of constant expression in if An improper character is present after a constant expression under if identifier already used as member name in this struct union The member name has already been used identifier cannot have type void You cannot define an identifier as an entity of void type identifier is not member of left hand side struct union You used a member which is not the declared member of a structure or union xxx identifier is required between and in defined You must put an identifier in of defined identifier must be defined as a typedef name You used a name which is not the typedef defined name identifier not member of left hand side struct union You used a member which is not the declared member of a structure or union identifier redeclared in current declaration An identifier declared in a duplicate manner is present CC32R MANUAL 377 Chapter 14 Messages from the C Compiler Table 14 6 Error Messages 6 15 Message Description identifier redefined in c
415. urrent declaration An identifier defined in a duplicate manner is present identifier undeclared in current declaration The specified identifier has not been declared identifier undefined An undefined identifier is present identifier with no linkage and incomplete object type There is an identifier of incomplete type without linkage illegal combination of types in initialization The combination of types in performing initialization is incorrect illegal floating point constant The description of a floating point number is incorrect illegal hexadecimal constant The description of a hexadecimal digit is incorrect illegal octal constant The description of an octal digit is incorrect implicit declaration conflicts with prior possibly implicit declaration An implicit declaration is inconsistent with a previous implicit declaration initializer must be constant expression Initialization must be in terms of a constant expression integer character constant requires one or more multibyte characters enclosed in single quotes A character constant has be so formed that one or more characters are enclosed in a pair of single quotation marks invalid character constant in if The way of specifying a character constant in if is erroneous invalid combination of types in assignment The combination of types in an assignment is incorrect CC32R MANUAL 378 Chapter 1
416. ut function Outputs a character to a stream Syntax Return Value description include lt stdio h gt int fputc int c FILE fp Cj character s to be output Lp pointer to File structure The character written Successful EOF A write error occurs The fputc function outputs the character c into the stream specified by the file pointer fp When a write error occurs during the operation the error indicator for the stream is set and this function returns EOF The error indicator can be referred by the ferror function CC32R MANUAL 207 fputs Chapter 9 C Standard Library Input output function Outputs a string to a stream Syntax Return Value Description include lt stdio h gt int fputs char s FILE fp S pointer to character s to be output fp pointer to File structure 0 Successful EOF A write error occurs The fputs function outputs the character s specified by s into the stream specified by the file pointer fp However the null character is not output When a write error occurs during the operation the error indicator for the stream is set and this function returns EOF The error indicator can be referred by the ferror function CC32R MANUAL 208 Chapter 9 C Standard Library f read Input output function Transfers data from a stream to a memory area Syntax include lt stdio h gt size_t
417. way for other single precision mathematic functions Caution The function name that is stored in the load module when a called function name is replaced is the replaced function name and not the pre replacement function name Therefore pre replacement function names can be neither specified nor displayed in the debugger e g M3T PD32R or TM inspector You can specify or display replaced function names though 12 2 2 Link with the Single precision Mathematic Function Library The single precision mathematic function library is contained in the C standard library e g m32RcR lib included with your package Link the C standard library in the same way as you would use conventional C standard libraries 123 Precautions 12 3 1 Dynamic range In single precision representation type float the magnitude of representable values is smaller than in double precision type double When you replace the double precision mathematic functions with single precision mathematic functions make sure the input or output values will not exceed the range of values representable by single precision numbers CC32R MANUAL 357 Chapter 12 Single precision Mathematical Function Library 12 3 2 About error handling The error occurring conditions listed below are handled the same way as for the C standard double precision mathematic functions Because these conditions vary with each function refer to the Section 9 3 Detail
418. when checking the C C language source program at the assembly language level e Output of C C language source line debug information The source line debug infomation in the C C language source files are added to the load module generated by the linker Use of this load module permits a program to be debugged at the C C language source line level using a debugger e Development Support Utilities O C source merge utility strip32R We provide the C source merge utility cmerge The utility cmerge merges the assembler source file with CS option added that is output by the compiler with the original C source file to generate a C ASM mixed list The utility strip32R is not a standard product of the compiler For details on how to handle it refer to the file written about the Handling of Development Support Utilities For more information of strip32R refer to the certain documents in directory UnSpt32R PC version or unsupport EWS version The license txt explains about license and the strip32R txt explains about how to use it O Absolute listing utility abslist We provide the absolute listing utility abslist The utility abslist generates an absolute list file in which the LOCATION values in the assembly list files output by the assembler as32R have been converted into the actual addresses after linking The utility abslist is not a standard product of the compiler For details on how to handle it refer to the file writte
419. within a function Data types char short int long unsigned char unsigned short unsigned int unsigned long long double float double struct union enum pointers The pragma ADDRESS declaration applies to variables defined both prior to and subsequent to this declaration Rules lf pragma ADDRESS is declared two or more times for the same variable name error is returned at compiling Variables for which an initialization expression has been described cannot be speci fied If they are specified a warning is returned at compiling and the declaration has no effect Variables local variables and static variables defined within a function defined within a function cannot be specified If they are specified a warning is returned at compiling and the declaration has no effect Structure member names union member names enum type member names or array elements cannot be specified as variable names If they are specified the declaration has no effect no warning is displayed Function arguments cannot be specified as variable names If they are specified the declaration has no effect no warning is displayed Appendix A 20 Appendix A Extended Functions Reference pragma ADDRESS Notes No check is performed to see if the specified absolute address follows the variable alignment Be sure to specify the absolute address following the alignment of data type No check is performed to see if the va
420. wn in Table 4 17 which is also the type of the operation result These are termed usual arithmetic conversions CC32R MANUAL 69 Illl Note IIl Chapter 4 C Programming Language Specification Table 4 17 Usual Arithmetic Conversions Either operand The other operand Usual arithmetic conversion long double non long double The other operand is converted to long double double non double The other operand is converted to double float non float The other operand is converted to float unsigned long non unsigned long The other operand is converted to unsigned long long unsigned int If the other operand is represented in long it is converted to long Otherwise both operands are converted to unsigned long long non long The other operand is converted to long unsigned int non unsigned int The other operand is converted to unsigned int Otherwise in this table both operands have type int Be warned that implicit conversions are yield when you write a program For example as shown in the example given below when some integer which has type unsigned int its value will be equal to or greater than 0 is compared to the data 1 which is assumed int the comparison result is that the integer is greater than the 1 in logical however a converse judgement is actually made unsigned int u if u gt 1 expected relation yields true in logical printf True if true t
421. x 1 0 x 1 0 of the float type Macro DBL_NEG_EPS_EXP 53 Indicates the min No of the power of the binary base which can be expressed floating point number x 1 0 x 1 0 of the double type Macro LDBL_NEG_EPS_EXP 53 Indicates the min No of the power of the binary base which can be expressed floating point number x 1 0 x 1 0 of the long double type CC32R MANUAL 154 Chapter 8 Standard Header Files 8 2 5 limits h Defines limits concerning numerical value of each type Table 8 5 shows the macros defined Table 8 5 Macros Defined by Limits h Macro Name Description CHAR_BIT Indicates the number of bits composing a char type CHAR_MAX Indicates the max value that a char type variable can have CHAR_MIN Indicates the min value that a char type variable can have SCHAR_MAX Indicates the max value that a signed char type variable can have SCHAR_MIN Indicates the min value that a signed char type variable can have UCHAR_MAX Indicates the max value that an unsigned char type variable can have SHRT_MAX Indicates the max value that a short int type variable can have SHRT_MIN Indicates the min value that a short int type variable can have USHRT_MAX Indicates the max value that an unsigned short int type variable can have INT_MAX Indicates the max value that an int type variable can have INT_MIN Indicates the min value that an int type variable can have U
422. x7FFF The base addresses for covering data areas 1 to 3 are as follows data area 1 0xF78000 data area 2 0xF88000 data area 3 0xFC8000 These are allocatde to R13 R12 and R11 respectively 00F70000 data area 1 R13 variables var1 F78000 var2 var3 OOF7FFFF OOF80000 data area 2 R12 variables var4 F88000 oars OOF8FFFF OOFCOO0O data area 3 variables var6 R11 gt FC8000 OOFCFFFF Appendix A 12 2 3 Appendix A Extended Functions Reference Creating the Access Control File After determining the base addresses create the Access Control File which defines the details of the base register function Assume the file name is sample acc sample acc R13 OxF78000 var var2 var3 R12 OxF88000 var4 var5 R11 OxFC8000 var6 As shown above the base register is defined using the following format base_register_name 0x base_address hex The global variables to be covered by that base register are listed on the following lines e The Access Control File can also be automatically generated from the load modules See Section 2 map32 Map Generator in the CC32R User s Manual lt Assembler gt for details e For details of how to specify static variables in a function see A 1 7 3 Hints on describing the Access Control File Compiling Compile the program specifying the Access Control File created in step 2 Add access sa
423. xtended Functions The following table lists the contents and rules pertaining to the extended functions related to pragma Table A 2 List of pragma Extended Functions Extended function Description of function pragma ADDRESS Declares that the specified variable is mapped to the specified absolute address Syntax pragma ADDRESS variable nameAabsolute address Example pragma ADDRESS val_1 0x1000 pragma SECTION Changes the default section name created by the com piler Syntax pragma SECTION default section nameAmoditied sec tion name Example pragma SECTION B USR_SEC_B pragma INTERRUPT Declares an interrupt function described in C C pragma INTF This declaration generates the code for processing of an interrupt processing function at the entry and exit points of a function Additionally a return is performed by the RTE instruction at the exit of the function Syntax oragma INTERRUPT interrupt functiond register nameAregister name J Example pragma INTERRUPT int_func R6 pragma ketword asm on Declares the use of the in line assembly function asm pragma keyword asm off function This setting is used so that asm is interpreted not as a normal identifier but as a keyword Specify pragma keyword asm off to restore asm to a normal identifier Syntax pragma keyword asm on or off Example pragma keyword asm on 1 A is space code mandatory 2 For details of the The
424. ype and is not qualified type or int type CC32R MANUAL 60 Chapter 4 C Programming Language Specification void lt Scalar Types gt lt arithmetic types gt lt integral types gt character types enumerated signed integer types type short enum unsigned integer types unsigned char unsigned int unsigned short unsigned long floating types double long double pointer types lt derived declarator types gt lt aggregate types gt structure lt derived types gt union types types union struct array types function types Figure 4 5 Types C language only Note Underlined type specifiers are basic types CC32R MANUAL 61 Chapter 4 C Programming Language Specification 4 2 3 Data Size and Range of Basic Types The size and limits maximum and minimum values that can be expressed of basic type data are as shown in Table 4 14 For further information see Chapter 5 Internal Data Representation Table 4 14 Data Type and Size Data Type Size Minimum Value Maximum Value bool 1 byte 8 bits fales true char 128 127 unsigned char 1bytets bits 0 255 short 32768 32767 unsigned short a Hy a 0 65535 int 2147483648 2147483647 unsigned int i 0 4294967295 long 2147483648 2147483647 unsigned long payne sespies 0 4294967295 float 4 byte 32 bits 1 17549435e 38F 3 40282347e 38F double l 8 byte 64 bits 2 2250738585072014e 308 1 797693134862315

Download Pdf Manuals

image

Related Search

Related Contents

Zebra ZT230  Verbatim CD-R AZO Data Vinyl  2-CHANNEL SATA II PCI EXPRESS CARD User Manual  Digital Watchdog  

Copyright © All rights reserved.
Failed to retrieve file