Appendix A.  Macros and Global Variables

This appendix contains descriptions of macros and global variables available in Dynamic C. This is not an exhaustive list.

A.1    Macros Defined by the Compiler

The macros in the following table are defined internally. Default values are given where applicable, as well as directions for changing values.

Table 20-1.  Macros Defined by the Compiler

Macro Name

Definition and Default

_BIOSBAUD_

This is the debug baud rate. The baud rate can be changed in the Communications tab of Project Options.

_BOARD_TYPE_

This is read from the System ID block or defaulted to 0x100 (the BL1810 JackRabbit board) if no System ID block is present. This can be used for conditional compilation based on board type. Board types are listed in boardtypes.lib.

_CPU_ID_

This macro identifies the CPU type, including its revision; e.g.,

 #if _CPU_ID_ >= R4000_R0

identifies a Rabbit 4000 microprocessor.

Look in \Lib\..\BIOSLIB\sysiodefs.lib for the constants and mask macros that are defined for use with _CPU_ID_.

CC_VER

Gives the Dynamic C version in hex, i.e., if Dynamic C version 10.40 is being used, the value of CC_VER will be 0x0A40.

DC_CRC_PTR

Reserved.

__DATE__

The compiler substitutes this macro with the date that the file was compiled (either the BIOS or the .c file). The character string literal is of the form Mmm dd yyyy. The text used for the months is as follows: "Jan," "Feb," "Mar," "Apr," "May," "Jun," "Jul," "Aug," "Sep," "Oct," "Nov," "Dec." There is a space as the first character of dd if the value is less than 10.

DEBUG_RST

Go to the Compiler tab of Project Options and click on the “Advanced” button at the bottom of the dialog box. Check “Include RST 28 instructions” to set DEBUG_RST to 1. Debug code will be included even if #nodebug precedes the main function in the program.

__FILE__

The compiler substitutes this macro with the current source code file name as a character string literal.

__LINE__

The compiler substitutes this macro with the current source code line number as a decimal constant.

NO_BIOS

Boolean value. Tells the compiler whether or not to include the BIOS when compiling to a .bin file. This is an advanced compiler option accessible by clicking the “Advanced” button on the Compiler tab in Project Options.

_TARGETLESS_COMPILE_

Boolean value. It defaults to 0. Set it by selecting “Compile defined target configuration to .bin file” under “Default Compile Mode,” in the Compiler tab of Project Options.

__TIME__

The compiler substitutes this macro with the time that the file (BIOS or .c) was compiled. The character string literal is of the form hh:mm:ss.

A.2    Macros Defined in the BIOS or Configuration Libraries

This is not a comprehensive list of configuration macros, but rather, a short list of those found to be com­monly used by Dynamic C programmers. Most default conditions can be overridden by defining the macro in the “Defines” tab of the “Project Options” dialog.

All the configuration macros listed here were defined in RabbitBIOS.c prior to Dynamic C 9.30. Since then many of them have been moved to configuration libraries while RabbitBIOS.c has become a wrapper file that permits a choice of which BIOS to compile. See Section 19.1 for more information on the reorganization of the BIOS that occured with Dynamic C 9.30.

CLOCK_DOUBLED 

Determines whether or not to use the clock doubler. The default condition is to use the clock doubler, defined in \BIOSLIB\sysconfig.lib. Override the default condition by defining CLOCK_DOUBLED to “0” in an application or in the project.

ROOT_SIZE_4K

Defines the beginning logical address for the data segment. Defaults are defined in the BIOS: 0x3 if sepa­rate I&D space enabled, 0x6 otherwise. Users can override the defaults in the Defines tab of Project Options dialog.

WATCHCODESIZE

Specifies the number of root RAM bytes for watch code. Defaults are defined in the BIOS: 0x200 bytes if watch expressions are enabled, zero bytes otherwise. The defaults cannot be overridden by an application.

USE_TIMERA_PRESCALE

Uncomment this macro in \BIOSLIB\sysconfig.c to run the peripheral clock at the same frequency as the CPU clock instead of the standard “CPU clock/2.”

A.3    Global Variables

These variables may be read by any Dynamic C application program.

dc_timestamp

This internally-defined long is the number of seconds that have passed since 00:00:00 January 1, 1980, Greenwich Mean Time (GMT) adjusted by the current time zone and daylight savings of the PC on which the program was compiled. The recorded time indicates when the program finished compiling. The follow­ing program will use dc_timestamp to help calculate the date and time.

printf("The date and time: %lx\n", dc_timestamp);

main(){
   struct tm t;
   printf("dc_timestamp = %lx\n", dc_timestamp);
   mktm(&t, dc_timestamp);

   printf("%2d/%02d/%4d %02d:%02d:%02d\n",
      t.tm_mon,t.tm_mday,t.tm_year + 1900, t.tm_hour,t.tm_min,
            t.tm_sec);
}

OPMODE

This is a char. It can have the following values:

SEC_TIMER

This unsigned long variable is initialized to the value of the real-time clock (RTC). If the RTC is set cor­rectly, this is the number of seconds that have elapsed since the reference date of January 1, 1980. The periodic interrupt updates SEC_TIMER every second. This variable is initialized by the Virtual Driver when a program starts.

MS_TIMER

This unsigned long variable is initialized to zero. The periodic interrupt updates MS_TIMER every milli­second. This variable is initialized by the Virtual Driver when a program starts.

TICK_TIMER

This unsigned long variable is initialized to zero. The periodic interrupt updates TICK_TIMER 1024 times per second. This variable is initialized by the Virtual Driver when a program starts.

A.4    Exception Types

These macros are defined in errors.lib:

#define ERR_BADPOINTER
#define ERR_BADARRAYINDEX
#define ERR_DOMAIN
#define ERR_RANGE
#define ERR_FLOATOVERFLOW
#define ERR_LONGDIVBYZERO
#define ERR_LONGZEROMODULUS
#define ERR_BADPARAMETER
#define ERR_INTDIVBYZERO
#define ERR_UNEXPECTEDINTRPT
#define ERR_CORRUPTEDCODATA
#define ERR_VIRTWDOGTIMEOUT
#define ERR_BADXALLOC
#define ERR_BADSTACKALLOC
#define ERR_BADSTACKDEALLOC
#define ERR_BADXALLOCINIT
#define ERR_NOVIRTWDOGAVAIL
#define ERR_INVALIDMACADDR
#define ERR_INVALIDCOFUNC

228
229
234
235
236
237
238
239
240
241
243
244
245
246
247
249
250
251
252

A.5    Rabbit Registers

Macros are defined for all of the Rabbit registers that are accessible for application programming. A list of these register macros can be found in the user’s manuals for the Rabbit microprocessor, as well as in the Rabbit Registers file accessible from the Dynamic C Help menu.

A.5.1   Shadow Registers

Shadow registers exist for many of the I/O registers. They are character variables defined in the BIOS. The naming convention for shadow registers is to append the word Shadow to the name of the register. For example, the global control status register, GCSR, has a corresponding shadow register named GCSRShadow.

The purpose of the shadow registers is to allow the program to reference the last value programmed to the actual register. This is needed because a number of the registers are write only.