> ## 2. Introduction to Dynamic C

> Dynamic C is an integrated development system for writing embedded software. It is designed for use with Z-World controllers and other controllers based on the Rabbit microprocessor. The Rabbit 2000 and the Rabbit 3000 are high-performance 8-bit microprocessors that can handle C language applications of approximately 50,000 C+ statements or 1 megabyte.

> ### 2.1 The Nature of Dynamic C

> Dynamic C integrates the following development functions:

> - Editing
> - Compiling
> - Linking
> - Loading
> - Debugging

> into one program. In fact, compiling, linking and loading are one function. Dynamic C has an easy-to-use built-in text editor. Programs can be executed and debugged interactively at the source-code or machine-code level. Pull-down menus and keyboard shortcuts for most commands make Dynamic C easy to use.

> Dynamic C also supports assembly language programming. It is not necessary to leave C or the development system to write assembly language code. C and assembly language may be mixed together.

> Debugging under Dynamic C includes the ability to use `printf` commands, watch expressions, breakpoints and other advanced debugging features. Watch expressions can be used to compute C expressions involving the target's program variables or functions. Watch expressions can be evaluated while stopped at a breakpoint or while the target is running its program.

> Dynamic C provides extensions to the C language (such as shared and protected variables, costatements and cofunctions) that support real-world embedded system development. Dynamic C supports cooperative and preemptive multi-tasking.

> Dynamic C comes with many function libraries, all in source code. These libraries support real-time programming, machine level I/O, and provide standard string and math functions.

> #### 2.1.1 Speed

> Dynamic C compiles directly to memory. Functions and libraries are compiled and linked and downloaded on-the-fly. On a fast PC, Dynamic C might load 30,000 bytes of code in 5 seconds at a baud rate of 115,200 bps.

> ### 2.2 Dynamic C Enhancements and Differences

> Dynamic C differs from a traditional C programming system running on a PC or under UNIX. The motivation for being different is to be better help customers write the most reliable embedded control software possible. It is not possible to use standard C in an embedded environment without making adaptations. Standard C makes many assumptions that do not apply to embedded systems. For example, standard C implicitly assumes that an operating system is present and that a program starts with a clean slate, whereas embedded systems may have battery-backed memory and may retain data through power cycles. Z-World has extended the C language in a number of areas.

> #### 2.2.1 Dynamic C Enhancements

> Many enhancements have been added to Dynamic C. Some of these are listed below.

> - Function chaining, a concept unique to Dynamic C, allows special segments of code to be embedded within one or more functions. When a named function chain executes, all the segments belonging to that chain execute. Function chains allow software to perform initialization, data recovery, or other kinds of tasks on request.

> - Costatements allow concurrent parallel processes to be simulated in a single program.

> - Cofunctions allow cooperative processes to be simulated in a single program.

> - Slice statements allow preemptive processes in a single program.

> - The interrupt keyword in Dynamic C allows the programmer to write interrupt service routines in C.

> - Dynamic C supports embedded assembly code and stand-alone assembly code.

> - Dynamic C has shared and protected keywords that help protect data shared between different contexts or stored in battery-backed memory.

> - Dynamic C has a set of features that allow the programmer to make fullest use of extended memory. Dynamic C supports the 1M address space of the microprocessor. The address space is segmented by a memory management unit. Normally, Dynamic C takes care of memory management, but there are instances where the programmer will want to take control of it. Dynamic C has keywords and directives to help put code and data in the proper place. The keyword `root` selects root memory (addresses within the 64K physical address space). The keyword `xmem` selects extended memory, which means anywhere in the 1024K or 1M code space. `root` and `xmem` are semantically meaningful in function prototypes and more efficient code is generated when they are used. Their use must match between the prototype and the function definition. The directive `#memmap` allows further control. See "Memory Management" on page 95, for further details on memory.

> #### 2.2.2 Dynamic C Differences

> The main differences in Dynamic C are summarized here and discussed in detail in chapters Language and Keywords.

> - If a variable is explicitly initialized in a declaration (e.g., int x = 0;), it is stored in Flash Memory (EEPROM) and cannot be changed by an assignment statement. Starting with Dynamic C 7.x such declaration will generate a warning which can be suppressed using the const keyword: const int x = 0; To initialize static variables in Static RAM (SRAM) use #GLOBAL_INIT sections. Note that other C compilers will automatically initialize all static variables to zero that are not explicitly initialized before entering the main function. Dynamic C programs do not do this because in an embedded system you may wish to preserve the data in battery-backed RAM on reset

> - The default storage class is static, not auto. This avoids numerous bugs encountered in embedded systems due to the use of auto variables. Starting with Dynamic C 7.x, the default class can changed to auto by the compiler directive #class auto.

> - The numerous include files found in typical C programs are not used because Dynamic C has a library system that automatically provides function prototypes and similar header information to the compiler before the user's program is compiled. This is done via the #use directive. This is an important topic for users who are writing their own libraries. Those users should refer to the Modules section of the language chapter. It is important to note that the #use directive is a replacement for the #include directive, and the #include directive is not supported.

> - When declaring pointers to functions, arguments should not be used in the declaration. Arguments may be used when calling functions indirectly via pointer, but the compiler will not check the argument list in the call for correctness.

> - Bit fields and enumerated types are not supported. Separate compilation of different parts of the program is not supported or needed. There are minor differences involving extern and register keywords.

> ### 2.3 Dynamic C Differences Between Rabbit and Z180

> A major difference in the way Dynamic C interacts with a Rabbit-based board compared to a Z180 or 386EX board is that Dynamic C expects no BIOS kernel to be present on the target when it starts up. Dynamic C stores the BIOS kernel as a C source file. Dynamic C compiles and loads it to the Rabbit target when it starts. This is accomplished using the Rabbit CPU's bootstrap mode and a special programming cable provided in all Rabbit product development kits. This method has numerous advantages.

> - A socketed flash is no longer needed. BIOS updates can be made without a flash-EPROM burner since Dynamic C can communicate with a target that has a blank flash EPROM. Blank flash EPROM can be surface-mounted onto boards, reducing manufacturing costs for both Z-World and other board developers. BIOS updates can then be made available on the Web.

> - Advanced users can see and modify the BIOS kernel directly.

> - Board Developers can design Dynamic C compatible boards around the Rabbit CPU by simply following a few simple design guidelines and using a "skeleton" BIOS provided by Z-World.

> - A major new feature introduced in Dynamic C 7.x is the ability to program and debug over the Internet or local Ethernet. This requires the use of a RabbitLink board, available alone or as an option with Rabbit-based development kits.

Z-World http://www.zworld.com Voice: (530) 757-3737 FAX: (530) 757-3792 sales@zworld.com