![]() |
| RabbitCore RCM3700 User's Manual |
5. Software Reference
Dynamic C is an integrated development system for writing embedded software. It runs on an IBM-compatible PC and is designed for use with Rabbit Semiconductor single-board computers and other single-board computers based on the Rabbit microprocessor. Chapter 5 describes the libraries and function calls related to the RCM3700.
5.1 More About Dynamic C
Dynamic C has been in use worldwide since 1989. It is specially designed for programming embedded systems, and features quick compile and interactive debugging. A complete reference guide to Dynamic C is contained in the Dynamic C User's Manual and in the Dynamic C Function Reference Manual.
You have a choice of doing your software development in the flash memory or in the SRAM included on the RCM3700. The flash memory and SRAM options are selected with the Options > Compiler menu.
The advantage of working in RAM is to save wear on the flash memory, which is limited to about 100,000 write cycles. The disadvantage is that the code and data might not both fit in RAM.
Developing software with Dynamic C is simple. Users can write, compile, and test C and assembly code without leaving the Dynamic C development environment. Debugging occurs while the application runs on the target. Alternatively, users can compile a program to an image file for later loading. Dynamic C runs on PCs under Windows 95 and later. Programs can be downloaded at baud rates of up to 460,800 bps after the program compiles.
Dynamic C has a number of standard features. Some of these standard features are listed below.
- Full-feature source and assembly-level debugger, no in-circuit emulator required.
- Royalty-free TCP/IP stack with source code and most common protocols.
- Hundreds of functions in source-code libraries and sample programs:
u exceptionally fast support for floating-point arithmetic and transcendental functions.
u RS-232 and RS-485 serial communication.
u analog and digital I/O drivers.
u LCD display and keypad drivers.
- Powerful language extensions for cooperative or preemptive multitasking
- Loader utility program (Rabbit Field Utility) to load binary images to Rabbit-based targets without the presence of Dynamic C.
- Provision for customers to create their own source code libraries and augment on-line help by creating "function description" block comments using a special format for library functions.
- Standard debugging features:
u BreakpointsSet breakpoints that can disable interrupts.
u Single-steppingStep into or over functions at a source or machine code level, µC/OS-II aware.
u Code disassemblyThe disassembly window displays addresses, opcodes, mnemonics, and machine cycle times. Switch between debugging at machine-code level and source-code level by simply opening or closing the disassembly window.
u Watch expressionsWatch expressions are compiled when defined, so complex expressions including function calls may be placed into watch expressions. Watch expressions can be updated with or without stopping program execution.
u Register windowAll processor registers and flags are displayed. The contents of general registers may be modified in the window by the user.
u Stack windowshows the contents of the top of the stack.
u Hex memory dumpdisplays the contents of memory at any address.
u STDIO window
printfoutputs to this window and keyboard input on the host PC can be detected for debugging purposes.printfoutput may also be sent to a serial port or file.5.2 Dynamic C Functions
The functions described in this section are for use with the Prototyping Board features. The source code is in the RCM37
xx.LIBlibrary in the Dynamic CSAMPLES\RCM3700or theSAMPLES\RCM3720folder, depending on which Prototyping Board you will be using, if you need to modify it for your own board design.Other generic functions applicable to all devices based on Rabbit microprocessors are described in the Dynamic C Function Reference Manual.
5.2.1 Board Initialization
void brdInit (void);
- Call this function at the beginning of your program. This function initializes Parallel Ports A through G for use with the RCM3700 Prototyping Board or the RCM3720 Prototyping Board.
- The
brdInitfunction is set up to a default I/O configuration based on the RabbitCore module detected at compile time: Any RCM3700 RabbitCore module (except the RCM3720) will have its I/O ports configured for an RCM3700 Prototyping Board.
An RCM3720 RabbitCore module will have its I/O ports configured for an RCM3720 Prototyping Board.
- You may override these default settings to run an RCM3720 RabbitCore module on the RCM3700 Prototyping Board or to run another RCM3700 RabbitCore module on the RCM3720 Prototyping Board by adding the following macro to the program you will be running.
To run an RCM3720 RabbitCore module on an RCM3700 Prototyping Board, add the following macro at the top of the program you will be running.
#define RCM3700_PROTOBOARDSample programs that are specifically designed for the RCM3700 Prototyping Board already have this macro included. When you run a sample program designed for the RCM3700 Prototyping Board on an RCM3720, a warning message will be displayed to inform you of that. You can disable the warning by commenting out the line indicated by the compiler.
To run an RCM3700 RabbitCore module (other than the RCM3720) on an RCM3720 Prototyping Board, add the following macro at the top of the program you will be running.
#define RCM3720_PROTOBOARD
- Summary of Initialization
1. I/O port pins are configured for Prototyping Board operation.
2. Unused configurable I/O are set as tied inputs or outputs.
3. The LCD/keypad module is disabled.
6. The IrDA transceiver is disabled.
8. The A/D converter is reset and SCLKB is to 57,600 bps (RCM3700 Prototyping Board only).
9. The A/D converter calibration constants are read (this function cannot run in RAM) (RCM3700 Prototyping Board only).
10. Ethernet select is disabled.
11. Serial flash select is disabled.
CAUTION: ![]()
Pin PB7 is connected as both switch S2 and as an external I/O bus on the RCM3700 Prototyping Board. Do not use S2 when the LCD/keypad module is installed.
Return Value
- None.
5.2.2 Analog Inputs
NOTE The function calls for the A/D converter in this section will work only with the RCM3700 Prototyping Board.
unsigned int anaInConfig(unsigned int instructionbyte, unsigned int cmd, long baud);
- Use this function to configure the ADS7870 A/D converter. This function will address the ADS7870 in Register Mode only, and will return error if you try the Direct Mode. Section B.1.5 provides additional addressing and command information for the ADS7870 A/D converter.
Parameters
instructionbyteis the instruction byte that will initiate a read or write operation at 8 or 16 bits on the designated register address. For example,
checkid = anaInConfig(0x5F, 0, 9600); // read ID and set baud rate
cmdrefers to the command data that configure the registers addressed by the instruction byte. Enter 0 if you are performing a read operation. For example,
i = anaInConfig(0x07, 0x3b, 0); // write ref/osc reg and enable
baudis the serial clock transfer rate of 9600 to 57,600 bps.baudmust be set the first time this function is called. Enter 0 for this parameter thereafter, for example,
anaInConfig(0x00, 0x00, 9600); // resets device and sets baudReturn Value
- 0 on write operations,
data value on read operationsSee Also
anaInDriver, anaIn, brdInit
unsigned int anaInDriver(unsigned int cmd, unsigned int len);
- Reads the voltage of an analog input channel by serial-clocking an 8-bit command to the ADS7870 A/D converter by the Direct Mode method. This function assumes that Mode1 (most significant byte first) and the A/D converter oscillator have been enabled. See
anaInConfig()for the setup.
- The conversion begins immediately after the last data bit has been transferred. An exception error will occur if Direct Mode bit D7 is not set.
Parameters
cmdcontains a gain code and a channel code as follows.D71; D6D4Gain Code; D3D0Channel Code
- Use the following calculation and the tables below to determine
cmd:
cmd = 0x80 | (gain_code*16) + channel_code
Gain Code Multiplier
Channel Code Differential Input Lines Channel Code Single-Ended Input Lines1 420 mA Lines
1 Negative input is ground.
2 Not accessible on RCM3700 Prototyping Board
len, the output bit length, is always 12 for 11-bit conversionsReturn Value
- A value corresponding to the voltage on the analog input channel:
02047 for 11-bit conversions (bit 12 for sign)
-1 overflow or out of range
-2 conversion incomplete, busy bit timeoutSee Also
anaInConfig, anaIn, brdInit
unsigned int anaIn(unsigned int channel, int opmode, int gaincode);
- Reads the value of an analog input channel using the direct method of addressing the ADS7870 A/D converter. The A/D converter is enabled the first time this function is calledthis will take approximately 1 second to ensure that the A/D converter capacitor is fully charged.
Parameters
channelis the channel number (0 to 7) corresponding to ADC_IN0 to ADC_IN7
opmodeis the mode of operation:
SINGLEsingle-ended input
DIFFdifferential inputmAMP420 mA input
channelSINGLEDIFFmAMP
1 Not accessible on RCM3700 Prototyping Board.
gaincodeis the gain code of 0 to 7
Gain Code Multiplier Voltage Range1
(V)
1 Applies to RCM3700 Prototyping Board.
Return Value
- A value corresponding to the voltage on the analog input channel:
02047 for 11-bit A/D conversions (signed 12th bit)
ADOVERFLOW(defined macro = -4096) if overflow or out of range
-4095 if conversion is incomplete or busy-bit timeoutSee Also
anaIn, anaInConfig, anaInDriver
int anaInCalib(int channel, int opmode, int gaincode, int value1, float volts1, int value2, float volts2);
- Calibrates the response of the desired A/D converter channel as a linear function using the two conversion points provided. Four values are calculated and placed into global tables to be later stored into simulated EEPROM using the function
anaInEEWr(). Each channel will have a linear constant and a voltage offset.Parameters
channelis the analog input channel number (0 to 7) corresponding to ADC_IN0 to ADC_IN7
opmodeis the mode of operation:
channelSINGLEDIFFmAMP
1 Not accessible on RCM3700 Prototyping Board.
gaincodeis the gain code of 0 to 7
Gain Code Multiplier Voltage Range1
(V)
1 Applies to RCM3700 Prototyping Board.
- value1 is the first A/D converter channel value (02047)
- volts1 is the voltage or current corresponding to the first A/D converter channel value (0 to +20 V or 4 to 20 mA)
- value2 is the second A/D converter channel value (02047)
- volts2 is the voltage or current corresponding to the first A/D converter channel value (0 to +20 V or 4 to 20 mA)
RETURN VALUE
- 0 if successful.
- -1 if not able to make calibration constants.
SEE ALSO
anaIn, anaInVolts, anaInmAmps, anaInDiff, anaInCalib, brdInit
float anaInVolts(unsigned int channel, unsigned int gaincode);
- Reads the state of a single-ended analog input channel and uses the calibration constants previously set using
anaInCalibto convert it to volts.Parameters
channelis the channel number (07)
Channel Code Single-Ended Input Lines1 Voltage Range2
(V)
1 Negative input is ground.
2 Applies to RCM3700 Prototyping Board.
3 Used for thermistor in sample program.
gaincodeis the gain code of 0 to 7Return Value
- A voltage value corresponding to the voltage on the analog input channel.
ADOVERFLOW(defined macro = -4096) if overflow or out of range.See Also
anaInCalib, anaIn, anaInmAmps, brdInit
float anaInDiff(unsigned int channel, unsigned int gaincode);
- Reads the state of differential analog input channels and uses the calibration constants previously set using
anaInCalibto convert it to volts.Parameters
channelis the analog input channel number (0 to 7) corresponding to ADC_IN0 to ADC_IN7
channelDIFFVoltage Range
(V)
1 Applies to RCM3700 Prototyping Board.
gaincodeis the gain code of 0 to 7Return Value
- A voltage value corresponding to the voltage on the analog input channel.
ADOVERFLOW(defined macro = -4096) if overflow or out of range.See Also
anaInCalib, anaIn, anaInmAmps, brdInit
float anaInmAmps(unsigned int channel);
- Reads the state of an analog input channel and uses the calibration constants previously set using
anaInCalibto convert it to current.Parameters
channelis the channel number (07)
Channel Code 420 mA
Input Lines1
1 Negative input is ground.
2 Applies to RCM3700 Prototyping Board.
RETURN VALUE
- A current value between 4.00 and 20.00 mA corresponding to the current on the analog input channel.
ADOVERFLOW(defined macro = -4096) if overflow or out of range.SEE ALSO
anaInCalib, anaIn, anaInVolts
root int anaInEERd(unsigned int channel, unsigned int opmode, unsigned int gaincode);
- Reads the calibration constants, gain, and offset for an input based on their designated position in the simulated EEPROM area of the flash memory, and places them into global tables for analog inputs. The constants are stored in the top 2K of the reserved user block memory area 0x1C000x1FFF. Depending on the flash size, the following macros can be used to identify the starting address for these locations.
ADC_CALIB_ADDRS, address start of single-ended analog input channels
ADC_CALIB_ADDRD, address start of differential analog input channels
ADC_CALIB_ADDRM, address start of milliamp analog input channels
NOTE This function cannot be run in RAM. PARAMETER
channelis the analog input channel number (0 to 7) corresponding to ADC_IN0 to ADC_IN7
opmodeis the mode of operation:
SINGLEsingle-ended input line
channelSINGLEDIFFmAMP
1 Not accessible on RCM3700 Prototyping Board.
gaincodeis the gain code of 0 to 7. Thegaincodeparameter is ignored whenchannelisALLCHAN.RETURN VALUE
- 0 if successful.
-1 if address is invalid or out of range.
-2 if there is no valid ID block.SEE ALSO
anaInEEWr, anaInCalib
int anaInEEWr(unsigned int channel, int opmode unsigned int gaincode);
- Writes the calibration constants, gain, and offset for an input based from global tables to designated positions in the simulated EEPROM area of the flash memory. The constants are stored in the top 2K of the reserved user block memory area 0x1C000x1FFF. Depending on the flash size, the following macros can be used to identify the starting address for these locations.
ADC_CALIB_ADDRS, address start of single-ended analog input channels
ADC_CALIB_ADDRD, address start of differential analog input channels
ADC_CALIB_ADDRM, address start of milliamp analog input channels
NOTE This function cannot be run in RAM. PARAMETER
channelis the analog input channel number (0 to 7) corresponding to ADC_IN0ADC_IN7
opmodeis the mode of operation:
SINGLEsingle-ended input line
channelSINGLEDIFFmAMP
1 Not accessible on RCM3700 Prototyping Board.
gaincodeis the gain code of 0 to 7. Thegaincodeparameter is ignored whenchannelisALLCHAN.RETURN VALUE
- 0 if successful
-1 if address is invalid or out of range.
-2 if there is no valid ID block.
-3 if there is an error writing to flash memory.SEE ALSO
anaInEEWr, anaInCalib
void digConfig(char statemask);
- Configures channels PIO0 to PIO3 on the A/D converter to allow them to be used as digital I/O via header JP4 on the RCM3700 Prototyping Board.
- Remember to execute the
brdInitfunction before calling this function to prevent a runtime error.Parameter
statemaskis a bitwise mask representing JP4 channels 1 to 4. Use logic 0 for inputs and logic 1 for outputs in these bit positions:RETURN VALUE
- None.
SEE ALSO
digOut, digIn
void digOut(int channel, int state);
- Writes a state to a digital output channel on header JP4 of the RCM3700 Prototyping Board. The PIO0 to PIO3 channels on the A/D converter chip are accessed via header JP4 on the RCM3700 Prototyping Board.
- A runtime error will occur if the
brdInitfunction was not executed before calling this function or if the channel is out of range.ParameterS
channelis channel 1 to 4 for JP4:1 to JP4:4
stateis a logic state of 0 or 1RETURN VALUE
- None.
SEE ALSO
brdInit, digIn
int digIn(int channel);
- Reads the state of a digital input channel on header JP4 of the RCM3700 Prototyping Board. The PIO0 to PIO3 channels on the A/D converter chip are accessed via header JP4 on the RCM3700 Prototyping Board.
- A runtime error will occur if the
brdInitfunction was not executed before calling this function or if the channel is out of range.ParameterS
channelis channel 1 to 4 for JP4:1 to JP4:4
stateis a logic state of 0 or 1RETURN VALUE
- The logic state of the input (0 or 1).
SEE ALSO
brdInit, digOut5.2.3 Digital I/O
The RCM3700 was designed to interface with other systems, and so there are no drivers written specifically for the I/O. The general Dynamic C read and write functions allow you to customize the parallel I/O to meet your specific needs. For example, use
WrPortI(PEDDR, &PEDDRShadow, 0x00);to set all the Port E bits as inputs, or use
WrPortI(PEDDR, &PEDDRShadow, 0xFF);