Dynamic C User's Manual
Total Page:16
File Type:pdf, Size:1020Kb
Integrated C Development System For Rabbit® 4000, 5000 and 6000 Microprocessors User’s Manual 019-0167_L The latest revision of this manual is available on the Digi website: www.digi.com. Dynamic C User’s Manual Part Number 019-0167 • Printed in the U.S.A. Digi International Inc. © 2014 • All rights reserved. Digi International Inc. reserves the right to make changes and improvements to its products without providing notice. Trademarks Rabbit® and Dynamic C® are registered trademarks of Digi International Inc. Windows® is a registered trademark of Microsoft Corporation TABLE OF CONTENTS Chapter 1. Installing Dynamic C 4.4.4 Dynamic C Version Differences .......28 1.1 Requirements...............................................8 4.5 Pointers to Functions, Indirect Calls...... 29 1.2 Assumptions ................................................8 4.6 Function Chaining .................................... 31 4.7 Global Initialization ................................. 32 2. Introduction to Dynamic C 4.8 Libraries ..................................................... 33 2.1 The Nature of Dynamic C .........................9 4.8.1 Libraries and File Scope .................... 34 2.1.1 Speed ...................................................9 4.8.2 LIB.DIR ............................................. 35 2.2 New Features from ANSI C....................10 4.9 Headers....................................................... 36 2.3 Dynamic C Enhancements and Differenc- 4.10 Modules ................................................... 36 es.......................................................................11 4.10.1 The Parts of a Module ..................... 36 4.10.2 Module Sample Code ...................... 38 3. Quick Tutorial 4.10.3 Important Notes ............................... 39 3.1 Run DEMO1.C..........................................13 4.11 Function Description Headers.............. 40 3.1.1 Single Stepping ..................................14 4.12 Support Files ........................................... 40 3.1.2 Watch Expression ..............................14 3.1.3 Breakpoint .........................................14 5. Multitasking with Dynamic C 3.1.4 Editing the Program ...........................15 5.1 Cooperative Multitasking........................ 41 3.2 Run DEMO2.C..........................................15 5.2 A Real-Time Problem.............................. 42 3.2.1 Watching Variables Dynamically ......15 5.2.1 Solving the Real-Time Problem 3.3 Run DEMO3.C..........................................16 with a State Machine ....................... 43 3.3.1 Cooperative Multitasking ..................16 5.3 Costatements ............................................. 43 3.4 Summary of Features ...............................17 5.3.1 Solving the Real-Time Problem with Costatements ............................ 44 4. Language 5.3.2 Costatement Syntax ........................... 44 4.1 Storage Classes .........................................19 5.3.3 Control Statements ............................ 45 5.4 Advanced Costatement Topics............... 47 4.2 Pointers.......................................................19 5.4.1 The CoData Structure ........................ 48 4.3 Far Pointers and Far Data........................20 5.4.2 CoData Fields .................................... 48 4.3.1 The far Qualifier ................................20 5.4.3 Pointer to CoData Structure .............. 49 4.3.2 Basic Declarations .............................20 5.4.4 Functions for Use With Named 4.3.3 Multi-Level Far Pointers ...................21 Costatements .................................... 49 4.3.4 Arrays and Structures ........................21 5.4.5 Firsttime Functions ............................ 50 4.3.5 Complex Declarations .......................22 5.4.6 Shared Global Variables .................... 50 4.3.6 Sample Programs ...............................22 5.5 Cofunctions ............................................... 50 4.4 The const Keyword...................................23 5.5.1 Cofunction Syntax ............................. 52 4.4.1 Simple Constants ...............................23 5.5.2 Calling Restrictions ........................... 52 4.4.2 Const and Pointers .............................23 5.5.3 CoData Structure ............................... 53 4.4.3 Const Conversions, Casting, and 5.5.4 Firsttime Functions ............................ 53 Parameter Passing ............................25 Dynamic C User’s Manual digi.com 3 5.5.5 Types of Cofunctions ........................54 7.2 Calling _GLOBAL_INIT()................... 100 5.5.6 Types of Cofunction Calls .................55 7.3 Global Timer Variables ......................... 101 5.5.7 Special Code Blocks ..........................56 7.3.1 Example: Timing Loop ................... 101 5.5.8 Solving the Real-Time Problem with Cofunctions ..............................58 7.3.2 Example: Delay Loop ..................... 102 5.6 Patterns of Cooperative Multitasking....58 7.4 Watchdog Timers ................................... 103 5.7 Timing Considerations.............................59 7.4.1 Hardware Watchdog ........................ 103 7.4.2 Virtual Watchdogs .......................... 103 5.7.1 waitfor Accuracy Limits ....................59 7.5 Preemptive Multitasking Drivers......... 103 5.8 Overview of Preemptive Multitasking ..60 5.9 µC/OS-II ....................................................60 8. The Slave Port Driver 5.9.1 Changes to µC/OS-II .........................60 8.1 Slave Port Driver Protocol .................... 104 5.9.2 Tasking Aware Interrupt Service Routines (TA-ISR) ...........................62 8.1.1 Overview ......................................... 104 5.9.3 Library Reentrancy ............................68 8.1.2 Registers on the Slave ..................... 105 5.9.4 How to Get a µC/OS-II Application 8.1.3 Polling and Interrupts ...................... 106 Running ............................................68 8.1.4 Communication Channels ............... 106 5.9.5 Compatibility with TCP/IP ................73 8.2 Functions ................................................. 107 5.9.6 Debugging Tips .................................74 8.3 Examples ................................................. 111 5.10 Summary..................................................74 8.3.1 Status Handler ................................. 111 8.3.2 Serial Port Handler .......................... 111 6. Debugging with Dynamic C 8.3.3 Byte Stream Handler ....................... 123 6.1 Debugging Features of Dynamic C........77 6.2 Debugging Tools ......................................79 9. Run-Time Errors 6.2.1 printf() ................................................79 9.1 Run-Time Error Handling..................... 131 6.2.2 ANSI Escape Sequences ....................80 9.1.1 Error Code Ranges .......................... 131 6.2.3 Software Breakpoints ........................81 9.1.2 Fatal Error Codes ............................ 132 6.2.4 Hardware Breakpoints .......................82 9.2 User-Defined Error Handler ................. 133 6.2.5 Single Stepping ..................................84 9.2.1 Replacing the Default Handler ........ 133 6.2.6 Watch Expressions ............................85 9.3 Run-Time Error Logging ...................... 134 6.2.7 Evaluate Expressions .........................86 9.3.1 Error Log Buffer ............................. 134 6.2.8 Memory Dump ..................................86 9.3.2 Initialization and Defaults ............... 135 6.2.9 MAP File ...........................................87 9.3.3 Configuration Macros ..................... 135 6.2.10 Symbolic Stack Trace ......................90 9.3.4 Error Logging Functions ................. 136 6.2.11 Assert Macro ...................................91 9.3.5 Examples of Error Log Use ............. 136 6.2.12 Miscellaneous Debugging Tools .....91 6.3 Where to Look for Debugger Features..94 10. Memory Management 6.3.1 Run and Inspect Menus .....................95 10.1 Memory Map ........................................ 137 6.3.2 Options Menu ....................................95 10.1.1 Memory Mapping Control ............ 138 6.3.3 Window Menu ...................................95 10.2 Extended Memory Functions ............. 138 6.4 Debug Strategies.......................................96 10.3 Code Placement in Memory ............... 138 6.4.1 Good Programming Practices ............96 6.4.2 Finding the Bug .................................98 10.4 Dynamic Memory Allocation............. 139 6.5 Reference to Other Debugging Informa- tion....................................................................99 11. Direct Memory Access 11.1 DMA Registers and Global Resources ... 7. The Virtual Driver 140 7.1 Default Operation ...................................100 11.2 API Functions ....................................... 140 Dynamic C User’s Manual digi.com 4 11.3 DMA Interrupts ....................................141 Extended Memory ......................... 183 11.4 DMA Transfer Information.................141 13.3.2 Example of Stand-Alone Assembly Code ............................................... 183 11.4.1 DMA Transfer Priority ..................141 13.3.3 The Stack Frame ........................... 184 11.4.2 DMA Transfer Mode .....................142 13.3.4 Embedded Assembly Example ..... 185 11.4.3 DMA Transfer Functions ..............142 13.3.5 The Disassembled Code Window . 186 11.4.4 DMA Transfer Function Flags ......142 13.3.6 Local Variable Access ..................