PSoC Designer: C Language Compiler - Northwestern University

1y ago
5 Views
2 Downloads
703.28 KB
74 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Wren Viola
Transcription

PSoC Designer:C Language CompilerUser GuideRevision 1.17 (Cypress Revision *B)Spec.# 38-12001Last Revised: December 5, 2003Cypress MicroSystems, Inc.CYPRESS MICROSYSTEMS

Cypress MicroSystems, Inc.2700 162nd St. SW, Building DLynnwood, WA 98037Phone: 800.669.0557Fax: ess.com/aboutus/sales locations.cfmsupport@cypressmicro.comCopyright 2002-2003 Cypress MicroSystems, Inc. All rights reserved.PSoC (Programmable System-on-Chip) is a trademark of Cypress MicroSystems, Inc.Copyright 1999-2000 iMAGEcraft Creations Inc. All rights reserved.All Microsoft products referenced herein are either trademarks or registered trademarks of Microsoft Corp.All Intel products referenced herein are either trademarks or registered trademarks of Intel Corporation. Copyright 1994-2002 Motorola, Inc. All Rights Reserved.The information contained herein is subject to change without notice.

Table of ContentsTable of ContentsList of Tables . vTwo-Minute Overview . 1Documentation Conventions . 2Section 1. Introduction . 31.1 What is the PSoC Designer C Compiler? .31.2 Section Overview . 41.3 Product Upgrades . 41.4 Support . 5Section 2. Accessing the Compiler . 72.1 Enabling the Compiler .72.2 Accessing the Compiler . 72.3 Menu Options .8Section 3. Compiler Files . 113.1 Startup File . 113.2 Library Descriptions . 11Section 4. Compiler Basics . 134.1 Types . 134.2 Operators . 144.3 Expressions .164.4 Statements .164.5 Pointers . 174.6 Re-entrancy .174.7 Processing Directives (#’s) . 174.7.1 Preprocessor Directives . 184.7.2 pragma Directives . 18Section 5. Functions . 215.1 Library Functions . 215.1.1 String Functions . 215.1.2 Mathematical Functions . 245.1.3 API Software Library Functions . 265.2 Interfacing C and Assembly . 26Section 6. Additional Considerations . 296.1 Accessing M8C Features . 296.2 Addressing Absolute Memory Locations . 296.3 Assembly Interface and Calling Conventions . 306.4 Bit Twiddling . 306.5 Inline Assembly . 316.6 Interrupts . 316.7 IO Registers . 32December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.17i

PSoC Designer: C Language Compiler User Guide6.8 Long Jump/Call . 326.9 Memory Areas .336.9.1 Flash Memory Areas . 336.9.2 Data Memory . 336.10 Program and Data Memory Usage . 336.10.1 Program Memory . 336.10.2 Data Memory . 346.11 Program Memory as Related to Constant Data . 346.12 Stack Architecture and Frame Layout . 356.13 Strings . 356.14 Virtual Registers . 366.15 Convention for Restoring Internal Registers . 36Section 7. Linker . 377.1 Linker Operations . 377.1.1 Customized Linker Actions . 38Section 8. Librarian . 398.1 Librarian . 398.1.1 Compiling a File into a Library Module . 398.1.2 Listing the Contents of a Library . 428.1.3 Adding or Replacing a Module . 428.1.4 Deleting a Module . 42Section 9. Command Line Compiler Overview . 439.1 Compilation Process . 439.2 Driver . 439.3 Compiler Arguments . 449.3.1 Arguments Affecting the Driver . 459.3.2 Preprocessor Arguments . 459.3.3 Compiler Arguments . 459.3.4 Linker Arguments . 45Section 10. Code Compression . 4710.1 Theory of Operation . 4710.2 Code Compressor Process . 4710.2.1 ‘C’ and Assembly Code . 4710.2.2 Where are the “Program Execution” Bytes? . 4810.2.3 What Can the PSoC Debugger Expect? . 4810.3 PSoC Designer Integration of the Code Compressor . 4810.3.1 boot.asm . 4810.3.2 Text Area Requirement for Code Compressor . 4810.4 Code Compressor and the AREA Directive . 4910.5 Build Messages . 5010.6 Up against the Wall? . 5010.7 Additional Things to Consider When Using Code Compression . 51Appendix A. Status Window Messages . 531.1 Preprocessor . 531.2 Preprocessor Command Line Errors . 551.3 C Compiler . 551.4 Assembler . 591.5 Assembler Command Line Errors . 611.6 Linker . 61iiDocument #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Table of ContentsIndex . 63December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.17iii

PSoC Designer: C Language Compiler User GuideivDocument #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

List of TablesList of TablesTable 1: Documentation Conventions . 2Table 2: Compiler Menu Options. 8Table 3: Supported Data Types. 13Table 4: Supported Operators . 15Table 5: Preprocessor Directives . 18Table 6: pragma Directives. 18Table 7: String Functions. 22Table 8: Mathematical Functions. 24Table 9: API Software Library Functions . 26Table 10: #pragma Fastcall Conventions for Argument Passing . 26Table 11: #pragma Fastcall Conventions for Return Value.27Table 12: Compiler Argument Prefixes. 44Table 13: Arguments Affecting the Driver. 45Table 14: Preprocessor Arguments. 45Table 15: Compiler Arguments. 45Table 16: Linker Arguments . 45Table A.1: Preprocessor Errors/Warnings. 53Table A.2: Preprocessor Command Line Errors/Warnings . 55Table A.3: C Compiler Errors/Warnings . 55Table A.4: Assembler Errors/Warnings . 59Table A.5: Assembler Command Line Errors/Warnings. 61Table A.6: Linker Errors/Warnings . 61December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.17v

PSoC Designer: C Language Compiler User GuideviDocument #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Two-Minute OverviewThis two-minute overview of PSoC Designer: C Language Compiler UserGuide was purposefully placed up front for you advanced engineers who areready to write source for the device but need a quick jump-start. (Now we onlyhave a minute and-a-half left.)Overview35 secondsYou have the device, PSoC Designer, and the C compiler This guide provides:enabling and accessing procedures,instructions for using the C compiler within PSoCDesigner parameters,references for the internal workings of the compiler.Basics30 secondsAfter generating your device configuration, click theApplication Editor iconin the toolbar to access thepre-configured source files.The source tree of project files appears in the left frame.The folders can be expanded to reveal the files. Doubleclick individual files to open and edit them in the mainwindow. Click File New to add .c files to your project.QuickReference25 secondsClick a hyperlink to reference key material:Accessing the CompilerCompiler FilesCompiler BasicsFunctionsProcessing Directives (#’s)LibrarianBottom Line10 secondsThe PSoC Designer C Compiler is an “extra” tool youcan use to customize the functionality you desire into thePSoC device.Time’s up December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.171

PSoC Designer: C Language Compiler User GuideDocumentation ConventionsFollowing, are easily identifiable conventions used throughout the PSoCDesigner suite of product documentation.Table 1:Documentation ConventionsConventionCourier Size 10-12UsageDisplays input and output://----------------------------// Sample Code// Burn some cycles//----------------------------void main(){char cOuter, cInner;for(cOuter 0x20; cOuter 0; cOuter--){for(cInner 0x7F; cInner 0; cInner--){}}}Courier Size 12Displays file locations:C:\Program Files\Cypress MicroSystems\PSoC Designer\tools2ItalicsDisplays file names:projectname.rom[bracketed, bold]Displays keyboard commands:[Enter] or [Ctrl] [C]File OpenDisplays menu paths:Edit CutDocument #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Section 1. IntroductionSection 1. Introduction1.1What is the PSoC Designer C Compiler?The PSoC Designer C Compiler compiles each .c source file to a PSoC deviceassembly file. The PSoC Designer Assembler then translates each assemblyfile (either those produced by the compiler or those that have been added) intoa relocatable object file, .o. After all the files have been translated into objectfiles, the builder/linker combines them together to form an executable file. This.rom file is then downloaded to the emulator where it is debugged to perfectdesign functionality.For comprehensive details on hardware, system use, and assembly languagesee:PSoC Designer: Integrated Development Environment User GuidePSoC Designer: Assembly Language User GuidePSoC Designer: ICE Connection Troubleshooting GuideCY8C25122, CY8C26233, CY8C26443, CY8C26643 Device Data Sheetfor Silicon Revision DCY8C27143, CY8C27243, CY8C27443, CY8C27543, CY8C27643 PSoCMixed-Signal Array Data SheetCY8C24123, CY8C24223, CY8C24423 PSoC Mixed-Signal Array DataSheetCY8C22113, CY8C22213 PSoC Mixed-Signal Array Data SheetIn-System Serial Programming (ISSP) CY3207ISSP User GuideTogether, these documents complete the PSoC Designer documentation suite.December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.173

PSoC Designer: C Language Compiler User GuideAdditional recommended reading includes:C Programming Language, Second Edition, Brian W. Kernighan andDennis Ritchie, Pearson Education March 1989C: A Reference Manual, Fifth Edition, Samuel P. Harbison andGuy L. Steele, Pearson Education February 20021.21.3Section OverviewSection 1. IntroductionDescribes the purpose of this guide, overviewseach section, and gives product upgrade andsupport information.Section 2. Accessing the CompilerDescribes enabling and accessing the compilerand its options.Section 3. Compiler FilesDiscusses and lists startup and C library optionswithin PSoC Designer.Section 4. Compiler BasicsLists C compiler types, operators, expressions,statements, and pointers that are compatiblewithin PSoC Designer parameters.Section 5. FunctionsLists C compiler functions that are compatiblewithin PSoC Designer parameters.Section 6. Additional ConsiderationsLists additional compiler options you can use toleverage the functionality of your code or program.Section 7. LinkerDiscusses C compiler linker options deployedwithin PSoC Designer.Section 8. LibrarianDiscusses C compiler library functions usedwithin PSoC Designer.Section 9. Command Line Compiler OverviewOverviews C compiler command line featuresthat can be used strictly within the constraints ofPSoC Designer.Section 10. Code CompressionDetails code compression features, benefitsand guidelines.Product UpgradesCypress MicroSystems provides scheduled upgrades and version enhancements for PSoC Designer free of charge. Compiler upgrades are included inyour PSoC Designer C Compiler license agreement.You can order PSoC Designer and Compiler upgrades from your distributor onCD-ROM or, better yet, download them directly from http://www.cypress.com/.4Document #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Section 1. IntroductionAlso provided at the web sites are critical updates to system documentation.To stay current with system functionality you can find documentation updatesunder PSoC More Resources at http://www.cypress.com/.Check the web site frequently for both product and documentation updates. Asthe device families and PSoC Designer evolve, you can be sure that new technology, features and enhancements will be added.1.4SupportSupport for PSoC Designer and its C Compiler is free and available online.Resources include Seminars, Discussion Forums, Application Notes, PSoCConsultants, TightLink Email/Knowledge Base, Tele-Training, and SupportTechnicians.Application Hotline: 425.787.4814December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.175

PSoC Designer: C Language Compiler User Guide6Document #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Section 2. Accessing the CompilerSection 2. Accessing the CompilerIn this section you will learn how to enable and access the compiler and itsoptions.2.1Enabling the CompilerEnabling the compiler is done within PSoC Designer. To accomplish this, execute the following steps:1. Access Tools Options Compiler tab.2. Enter your key code.You have this key code if you purchased the C Language Compiler Licensewhen you received PSoC Designer (by download, mail, or through a distributor).3. Scroll to read the License Agreement, then click a check to accept theLicense Agreement and hit OK.To view the version details for the iMAGEcraft Compiler, click Version.When finished, click the “x” in the upper-right to close.If, for some reason, you have not received a key code or are uncertain of howto proceed, contact a Cypress MicroSystems Support Technician at425.787.4814.2.2Accessing the CompilerAll features of the compiler are available and accessible in the ApplicationEditor subsystem of PSoC Designer.To access the Application Editor subsystem, click the Application Editor icon. This icon can be found in the subsystem toolbar .December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.177

PSoC Designer: C Language Compiler User GuideSuch features include adding and modifying .c project files, both of which aredescribed ahead in brief, and in the PSoC Designer: Integrated DevelopmentEnvironment User Guide in detail.Avoid use of the following characters in path and file names (they are problematic): \ / : * ? " & , ; [ ] % '.2.3Menu OptionsThe following menu options are available in PSoC Designer for writing andediting assembly language and C compiler files:Table 2:Icon8Compiler Menu ild Compile/Assemble[Ctrl] [F7]Compiles/assembles the mostprominent open, active file (.c or.asm)BuildBuild Build[F7]Builds entire project and linksapplicable filesNew FileFile New[Ctrl] [N]Adds a new file to the projectOpen FileFile Open[Ctrl] [O]Opens an existing file in theprojectIndentIndents specified textOutdentOutdents specified textCommentComments selected textUncommentUncomments selected textToggle BookmarkToggles the bookmark: Sets/removes user-defined bookmarks used to navigate sourcefilesClear BookmarkClears all user-defined bookmarksNext BookmarkGoes to next bookmarkPreviousBookmarkGoes to previous bookmarkFind TextEdit Find[Ctrl] [F]Find specified textReplace TextEdit Replace[Ctrl] [H]Replace specified textDocument #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Section 2. Accessing the CompilerTable 2:IconCompiler Menu Options, continuedOptionFind in FilesDecember 5, 2003MenuShortcutEdit Find inFilesFeatureFind specified text in specifiedfile(s)RepeatReplaceRepeats last replaceSet EditorOptionsSet options for editorUndoEdit Undo[Ctrl] [Z]Undo last actionRedoEdit Redo[Ctrl] [Y]Redo last actionDocument #: 38-12001 CY Rev. *B CMS Rev. 1.179

PSoC Designer: C Language Compiler User Guide10Document #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Section 3. Compiler FilesSection 3. Compiler FilesIn this section you will learn startup file procedures and can reference supported library files.3.1Startup FilePSoC Designer creates a startup file called boot.asm. Its primary functionswithin the parameters of PSoC Designer include initializing C variables, organizing interrupt tables, and calling main. The underscore ( main) allowsboot.asm to call a “main” in either C or assembly.Many functions within PSoC Designer are built upon specifications in thisfile. Therefore, it is highly recommended that you do not modify the startupfile. If you have a need, first consult your Cypress MicroSystems TechnicalSupport Representative.The boot.asm startup file also defines the reset vector. You do not need tomodify the startup file to use other interrupts because PSoC Designer manages interrupts and vectors.3.2Library DescriptionsThere are three primary code libraries used by PSoC Designer: libcm8c.a,libpsoc.a, and cms.a.The libcm8c.a library resides in the PSoC Designer \tools directory( \Program Files\Cypress Microsystems\PSoCDesigner\tools). This library contains many functions typically used in 'C'programming.December 5, 2003Document #: 38-12001 CY Rev. *B CMS Rev. 1.1711

PSoC Designer: C Language Compiler User GuideThe libpsoc.a library resides in the project \lib directory, and contains usermodule functions. Device Editor automatically adds the source code for yourUser Modules to the library during the generate-application process. However,other library objects can be manually added to this library.To add existing object files, copy your source file to the project \lib directory, then “officially” add it to the project in PSoC Designer. For details on adding existing files to your project, see PSoC Designer: Integrated DevelopmentEnvironment User Guide.Avoid use of the following characters in path and file names (they are problematic): \ / : * ? " & , ; [ ] % '.The cms.a library resides in the \tools directory. This library contains convenient functions that do not involve User Modules. For example, the functionsto read and write flash reside here (Flash Block Programming). 'C' prototypesfor using these functions are given in the include file (flashblock.h) stored inthe \tools \include directory.12Document #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Section 4. Compiler BasicsSection 4. Compiler BasicsIn this section you can reference PSoC Designer C Compiler basics, whichinclude types, operators, expressions, statements, and pointers.With few exceptions, PSoC Designer C Compiler implements the ANSI Clanguage. The one notable exception is that the standard requires that double floating point be at least 64 bits, but implementing full 64 bits is prohibitive on 8-bit microcontrollers. Therefore, PSoC Designer C Compiler treatsthe “double” data type the same as the “float” data type.In terms of the compiler, the ONLY non-ANSI feature is that doubles are only32-bit. ANSI "bar" proper would require that to be at least 64 bits. Otherwise,if it is in C89 or the ISO equivalent, it is supported by the compiler.4.1TypesPSoC Designer C Compiler supports the following standard data types:All types support the signed and unsigned type modifiers.Table 3:Supported Data TypesTypeBytesDescriptionchar1A single byte of memory thatdefines charactersint2Used to define integer numbersRange1unsigned 0 255signed -128 1271shortDecember 5, 20032Standard type specifying 2-byteintegersDocument #: 38-12001 CY Rev. *B CMS Rev. 1.171unsigned 0 65535signed -32768 32767unsigned 0 65535signed -32768 3276713

PSoC Designer: C Language Compiler User GuideTable 3:Supported Data Types, continuedType1BytesDescriptionRangelong4Standard type specifying thelargest integer entityunsigned0 42949672951signed 2147483648 2147483647float4Single precision floating pointnumber in IEEE format1.175e-38 3.40e 38double4Single precision floating pointnumber in IEEE format1.175e-38 3.40e 38enum1 if enum 2562 if enum 256Used to define a list of aliasesthat represent integers.0 65535Default, if not explicitly specified as signed or unsigned.The following type definitions are included in m8c.inc. Express common conventions for additional data types.typedef unsigned char BOOL;typedef unsigned char BYTE;typedef signed char CHAR;typedef unsigned int WORD;typedef signed int INT;typedef unsigned long DWORD;typedef signed long LONG;The following floating-point operations are supported in the PSoC Designer CCompiler. Floating Point Intrinsic Functions:compare ( )add ( )multiply (*)subtract (-)divide(/)casting (long to float)floats and doubles are in IEEE 754 standard 32-bit format with 8-bit exponent and 23-bit mantissa with one sign bit.4.2OperatorsFollowing is a list of the most common operators supported within the PSoCDesigner C Compiler. Operators with a higher precedence are applied first.14Document #: 38-12001 CY Rev. *B CMS Rev. 1.17December 5, 2003

Section 4. Compiler BasicsOperators of the same precedence are applied right to left. Use parentheseswhere appropriate to prevent ambiguity.Table 4:Supported OperatorsPre.Op.FunctionGroupFormDescription1 Postincrementa 1--Postdecrementa --1[]Subscripta[b]1()Function Calla(b)1.Select Membera.b1- Point at Membera- b2sizeofSizeofsizeof a2 Preincrement a2--Predecrement-- a2&Address of&a2*Indirection*a2 Plus a2-Minus-a2 Bitwise NOT2!Logical NOT2(declaration)Type Cast3*MultiplicationBinarya*ba multiplied by b3/DivisionBinarya/ba divided by b3%ModulusBinarya%bRemainder of a divided by b4 AdditionBinarya ba plus b4-SubtractionBinarya-ba minus b5 Left ShiftBinarya bValue of a shift

Check the web site frequen tly for both product and do cumentation updates. As the device families and PSoC Designer evolve, you can be sure that new tech-nology, features and enhancements will be added. 1.4 Support Support for PSoC Designer and its C Compiler is free and available online.

Related Documents:

AN77759 - Getting Started with PSoC 5 PSoC Creator Training 1.3.2 Engineers Looking for More AN54460 - PSoC 3 and PSoC 5 Interrupts AN52705 - PSoC 3 and PSoC 5 - Getting Started with DMA AN52701 - PSoC 3 - How to Enable CAN Bus Communication AN54439 - PSoC 3 and PSoC 5 External Crystal Oscillators AN

PSoC 4: PSoC 4100 PS Datasheet Document Number: 002-22097 Rev. *B Page 3 of 44 PSoC Creator PSoC Creator is a free Windows-based Integrated Design Environment (IDE). It enables concurrent hardware and firmware design of PSoC 3, PSoC 4, and PSoC 5LP based systems. Create designs usin g

PSoC 3 and PSoC 5LP GPIO basics and demonstrates techniques for their effective use in a design. It is assumed that you are familiar with PSoC Creator and the PSoC 3 and PSoC 5LP family device architecture. If you are new to PSoC, see the introductions in AN54181, Getting Started

PSoC 4: PSoC 4100S Plus Datasheet Document Number: 002-19966 Rev. *H Page 3 of 44 PSoC Creator PSoC Creator is a free Windows-based Integrated Design Environment (IDE). It enables concurrent hardware and firmware design of PSoC 3, PSoC 4, and PSoC 5LP based systems. Create designs using

PSoC Creator PSoC Creator is a free Windows-based Integrated Design Environment (IDE). It enables concurrent hardware and firmware design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 1 - with PSoC Creator, you can: 1. Drag and drop Components to build your hardware system design in the main design workspace 2.

001 96819 Owner: JFMD Introduction to PSoC 4 Customer Training Workshop with PSoC 4 M- Series 5 Rev ** Tech lead: PMAD PSoC Terms PSoC PSoC is the world's only programmable embedded system-on-chip integrating an MCU core, Programmable Analog Blocks, Programmable Digital Blocks, Programmable Interconnect and Routing1 and CapSense Programmable Analog Block

2.1 PSoC Creator PSoC Creator is a free Windows-based Integrated Development Environment (IDE). It enables concurrent hardware and firmware design of systems based on PSoC 3, PSoC 4, and PSoC 5LP. See Figure 1 - with PSoC Creator, you can: 1. Drag and drop Components to build your hardware system design in the main design workspace 2.

PSoC Designer 5.0 SP6 is provided on the PSoC Designer archives web page for any user interested in maintaining system-level projects, although creating new projects is no longer recommended. PSoC Designer 5.0 SP6 and PSoC Designer 5.4 will coexist on the same machine allowing users to conti