Coyote (BL2500)
User's Manual
PREV INDEX NEXT


4. Software

Dynamic C is an integrated development system for writing embedded software. It runs on an IBM-compatible PC and is designed for use with single-board computers and other devices based on the Rabbit® microprocessor.

Chapter 4 provides the libraries, function calls, and sample programs related to the Coyote.

4.1 Running Dynamic C

You have a choice of doing your software development in the flash memory or in the static RAM included on the Coyote. The flash memory and SRAM options are selected with the Options > Project 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.

NOTE An application can be developed in RAM, but cannot run standalone from RAM after the programming cable is disconnected. Standalone applications can only run from flash memory.
NOTE Do not depend on the flash memory sector size or type. Due to the volatility of the flash memory market, the Coyote and Dynamic C were designed to accommodate flash devices with various sector sizes.

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, 98, 2000, NT, Me, and XP. 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:

4.1.1 Upgrading Dynamic C

4.1.1.1 Patches and Bug Fixes

Dynamic C patches that focus on bug fixes are available from time to time. Check the Web site at www.rabbit.com/support/ for the latest patches, workarounds, and bug fixes.

The default installation of a patch or bug fix is to install the file in a directory (folder) different from that of the original Dynamic C installation. Rabbit Semiconductor recommends using a different directory so that you can verify the operation of the patch without overwriting the existing Dynamic C installation. If you have made any changes to the BIOS or to libraries, or if you have programs in the old directory (folder), make these same changes to the BIOS or libraries in the new directory containing the patch. Do not simply copy over an entire file since you may overwrite a bug fix. Once you are sure the new patch works entirely to your satisfaction, you may retire the existing installation, but keep it available to handle legacy applications.

4.1.1.2 Upgrades

Dynamic C installations are designed for use with the board they are included with, and are included at no charge as part of our low-cost kits. Dynamic C is a complete software development system, but does not include all the Dynamic C features. Rabbit Semiconductor also offers add-on Dynamic C modules containing the popular µC/OS-II real-time operating system, as well as PPP, Advanced Encryption Standard (AES), and other select libraries. In addition to the Web-based technical support included at no extra charge, a one-year telephone-based technical support module is also available for purchase.

4.1.2 Accessing and Downloading Dynamic C Libraries

The libraries needed to run the Coyote are available on the CD included with the Development Kit, or they may be downloaded from http://www.rabbit.com/support/downloads/ on Rabbit Semiconductor's Web site. You may need to download upgraded or additional libraries to run selected RabbitNet peripheral cards.

When downloading the libraries from the Web site, click on the product-specific links until you reach the links for the BL2500 download. Once you have downloaded the self-extracting ZIP file, the following instructions will help you to add the libraries and sample programs to your existing Dynamic C installation.

  1. Double-click on the file name of the self-extracting ZIP file.

  2. The extracting program will prompt you for a folder in which to place the files.

  3. Enter the drive letter and the name of the Dynamic C folder where the libraries and samples are to be added, for example, C:\DCRabbit801.

  4. Click the UnZip button.

The files from the ZIP directory will then load automatically in your Dynamic C folder. Additional folders will be created as needed, and the LIB.DIR, DEFAULT.H, and BOARDTYPES.LIB files will be overwritten with the information needed to use the Coyote.

You will be able to use the revamped Dynamic C installation with the Coyote and you will continue to be able to use this installation with all the other Rabbit Semiconductor products you were able to use before.

4.2 Sample Programs

Sample programs are provided in the Dynamic C SAMPLES folder. The sample program PONG.C demonstrates the output to the STDIO window. The various directories in the SAMPLES folder contain specific sample programs that illustrate the use of the corresponding Dynamic C libraries.

The SAMPLES\BL2500 folder provides sample programs specific to the Coyote. Each sample program has comments that describe the purpose and function of the program. Follow the instructions at the beginning of the sample program.

To run a sample program, open it with the File menu (if it is not still open), compile it using the Compile menu, and then run it by selecting Run in the Run menu. The Coyote must be in Program mode (see Section 3.6, "Serial Programming Cable") and must be connected to a PC using the programming cable as described in Section 2.2, "BL2500 Connections."

More complete information on Dynamic C is provided in the Dynamic C User's Manual.

4.2.1 General Coyote Operation

The following sample programs are found in the SAMPLES\BL2500.

4.2.2 Digital I/O

The following sample programs are found in the IO subdirectory in SAMPLES\BL2500.

4.2.3 Serial Communication

The following sample programs are found in the SERIAL subdirectory in SAMPLES\BL2500.

4.2.4 A/D Converter Inputs

The following sample programs are found in the ADC subdirectory in SAMPLES\BL2500.

4.2.5 D/A Converter Outputs

The following sample program is found in the DAC subdirectory in SAMPLES\BL2500.

4.2.6 Using System Information from the RabbitCore Module

Calibration constants for the A/D converter are stored in the simulated EEPROM area of the flash memory. You may find it useful to retrieve the calibration constants and save them for future use, for example, if you should need to replace the RabbitCore module on the Coyote.

The following sample programs, found in the ADC subdirectory in SAMPLES\BL2500\, illustrate how to save or retrieve the calibration constants. Note that both sample programs prompt you to use a serial number for the Coyote. This serial number can be any 5-digit number of your choice, and will be unique to a particular Coyote. Do not use the MAC address on the bar code label of the RabbitCore module attached to the Coyote since you may at some later time use that particular RabbitCore module on another Coyote, and the previously saved calibration data would no longer apply.

NOTE Use the sample program DNLOADCALIB.C to retrieve the data and rewrite it to the single-board computer.

NOTE Calibration data must be saved previously in a file by the sample program UPLOADCALIB.C.
NOTE In addition to loading the calibration constants on the replacement RabbitCore module, you will also have to add the product information for the Coyote to the ID block associated with the RabbitCore module. The sample program WRITE_IDBLOCK.C, available on the Rabbit Semiconductor Web site at www.rabbit.com/support/feature_downloads.shtml, provides specific instructions and an example.

4.2.7 Real-Time Clock

If you plan to use the real-time clock functionality in your application, you will need to set the real-time clock. Set the real-time clock using the SETRTCKB.C sample program from the Dynamic C SAMPLES\RTCLOCK folder, using the onscreen prompts. The RTC_TEST.C sample program in the Dynamic C SAMPLES\RTCLOCK folder provides additional examples of how to read and set the real-time clock.

4.3 Coyote Libraries

With Dynamic C running, click File > Open, and select Lib. The following list of Dynamic C libraries and library directories will be displayed. Two library directories provide libraries of function calls that are used to develop applications for the Coyote.

Other generic functions applicable to all devices based on the Rabbit 3000 microprocessor are described in the Dynamic C Function Reference Manual.

4.4 Coyote Function Calls

4.4.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 Coyote. The ports are initialized according to Table A-3.
Summary of initialization
1. RS-485 is not initialized.
2. RS-232 is not initialized.
3. Unused configurable I/O are either pulled-up inputs or outputs set high.
4. PWM for DA0 and DA1 set to 57,600 Hz, and output voltage is zero. Uses functions pwm_init(), pwmOutConfig(), and pwmOut().
5. Calibration constants for analog channels AD0, DA0, and DA1 are read from flash user block.

4.4.2 Digital I/O

void digOut(int channel, int value);


Sets the state of digital outputs OUT0-OUT7, whereOUT0-OUT7 are sinking outputs.
A run-time error will occur for the following conditions:
1. channel or value is out of range.
2. brdInit was not called first.
Parameters
channel is the digital output channels (0-7)
value is the output value (0 or 1)
Return Value
None.
SEE ALSO

void digBankOut(int bank, int value);


Writes the state of a block of designated digital output channels. The bank consists of OUT0-OUT7. This call is faster than setting the individual channels, but does not output states simultaneously. States are written in succession from OUT7-OUT0.
A run-time error will occur for the following conditions:
1. bank or value is out of range.
2. brdInit was not called first.
Parameters
bank is 0 for the bank of digital output channels (0-7)
value is an 8-bit output value, where each bit corresponds to one channel. OUT0 is the least significant bit 0
Return Value
None.
Example
To send out odd channels high:
See Also

int digIn(int channel);


Reads the state of an input channel (IN00-IN15).
A run-time error will occur for the following conditions:
1. channel out of range.
2. brdInit was not executed before executing digIn.
PARAMETER
channel is the input channel number (0-15)
RETURN VALUE
The logic state of the input (0 or 1).
SEE ALSO

int digBankIn(int bank);


Reads the state of a block of designated digital input channels. One bank consists of IN0-IN07, and the other bank consists of IN08-IN15. This call is faster than reading the individual channels, but does not read the states simultaneously. States are read in succession from IN15-IN08 or from IN07-IN00.
A run-time error will occur for the following conditions:
1. bank is out of range.
2. brdInit was not called first.
Parameter
bank is 0 for the bank of digital inputs IN00-IN07, 1 for the bank of digital inputs IN08-IN15
RETURN VALUE
An input value in the lower byte, where each bit corresponds to one channel. IN00 and IN08 are in the bit 0 place.
Example
To read inputs 8 to 15:
SEE ALSO

4.4.3 LEDs

void ledOut(int led, int value);


LED on/off control.
Parameters
led is the LED to control
0 = LED DS1
1 = LED DS2
2 = LED DS3
3 = LED DS4
value is used to control whether the LED is on or off
0 = OFF
1 = ON
Return Value
None.

4.4.4 Serial Communication

Library files included with Dynamic C provide a full range of serial communications support. The RS232.LIB library provides a set of circular-buffer-based serial functions. The PACKET.LIB library provides packet-based serial functions where packets can be delimited by the 9th bit, by transmission gaps, or with user-defined special characters. Both libraries provide blocking functions, which do not return until they are finished transmitting or receiving, and nonblocking functions, which must be called repeatedly until they are finished. For more information, see the Dynamic C Function Reference Manual and Technical Note 213, Rabbit 2000 Serial Port Software.

Use the following function calls with the Coyote.

void ser485Tx(void);


Enables the RS485 transmitter. Transmitted data get echo'ed back into the receive data buffer. These echo'ed data could be used to know when to disable the transmitter by using one of the following methods:
Byte mode--disable the transmitter after the same byte that is transmitted is detected in the receive data buffer.
Block data mode--disable the transmitter after the same number of bytes transmitted is detected in the receive data buffer.
Return Value
None.
SEE ALSO

void ser485Rx(void);


Disables the RS-485 transmitter. This puts the Coyote in listen mode, which allows it to receive data from the RS-485 interface.
Return Value
None.
SEE ALSO

4.4.5 Analog Inputs

unsigned int anaIn(unsigned int channel);


Uses D/A converter channel DA0 to search through the full voltage range for a match to the input voltage on channel AD0. This is done using a 10-step successive-approximation binary search, which nominally takes 86 ms.
Call pwmOutConfig() and pwm_init() before using this function. An exception error will occur if these functions were not been called previously.

NOTE DA0 should not be used when AD0 is in use.

Parameter
channel is 0 for channel AD0.
Return Value
An integer value between 0 and 1023 that corresponds to a voltage between 0.0 and 3.3 V on the analog input channel.
-1 if the return value is out of range.
SEE ALSO

void cof_anaIn(int channel);


This function is the cofunction version of the analog input for analog input channel AD0. This version will "yield" on each step approximation in a costate, and will take 10 steps to complete the A/D conversion. The function will also process costates while waiting for each approximation to settle.

NOTE All the restrictions for anaIn apply to cof_anaIn.

Parameters
channel is 0 for channel AD0
Return Value
An integer value between 0 and 1023 that corresponds to a voltage between 0.0 and 3.3 V on the analog input channel.
-1 if the return value is out of range.
SEE ALSO

float anaInVolts(unsigned int channel);


Reads the voltage of a single-ended analog input channel using D/A channel DA0 for comparison to find a match to the input voltage on channel AD0. This is done using a 10-step successive-approximation binary search, which nominally takes 86 ms.
Call pwmOutConfig() and pwm_init() before using this function. An exception error will occur if these functions were not been called previously.

NOTE DA0 should not be used when AD0 is in use.

Parameter
channel is 0 for channel AD0
Return Value
A voltage value between 0 and 3.1 V for the analog input channel.
ADOVERFLOW is returned (defined macro = -4096) on overflow or if the return value is out of range.
SEE ALSO

int anaInCalib(int channel, int value1, float volts1,int value2, float volts2);


Calibrates the response of the A/D converter channel as a linear function using the two conversion points provided. Values are calculated and placed into global table _adcCalibS for analog inputs to be stored later into simulated EEPROM using the function anaInEEWr().
Each channel will have a linear constant and a voltage offset.
Parameters
channel is 0 for channel AD0
value1 is the first A/D converter value (0-1023), usually a value of 310 that corresponds to 1.0 V
volts1 is the voltage corresponding to the first A/D converter value (0-3.3 V)
value2 is the second A/D converter value (0-1023), usually a value of 930 that corresponds to 3.0 V
volts2 is the voltage corresponding to the second A/D converter value (0-3.3 V)
Return Value
0 if successful
-1 if not able to make calibration constants
SEE ALSO

int anaInEERd(unsigned int channel);


Reads the calibration constants, gain, and offset for an input based on its designated channel code position into global table _adcCalibS. The constants are stored in the top 1K of the reserved user block memory area. Use the sample program USERBLOCKINFOR.C in SAMPLES\BL2500 to get the addresses reserved for the calibration data constants and the addresses available for use by your application program.

NOTE This function cannot be run in RAM.

Parameters
channel is 0 for channel AD0
Return Value
0 if successful
-1 if invalid address or range
SEE ALSO

int anaInEEWr(unsigned int channel);


Writes the calibration constants, gain, and offset for an input based on its designated channel code position from global table _adcCalibS. The constants are stored in the top 1K of the reserved user block memory area. Use the sample program USERBLOCKINFOR.C in SAMPLES\BL2500 to get the addresses reserved for the calibration data constants and the addresses available for use by your application program.

NOTE This function cannot be run in RAM.

Parameter
channel is 0 for channel AD0
Return Value
0 if successful
-1 if invalid address or range
SEE ALSO

4.4.6 Analog Outputs

unsigned long pwm_init(unsigned long frequency);


This function from the R3000.LIB library in Lib\Rabbit3000 sets the base frequency for the PWM pulses and enables the PWM driver on all four channels. The base frequency is the frequency without pulse spreading. Pulse spreading will increase the frequency by a factor of 4.
Parameter
frequency is the frequency (in Hz)
Return Value
Actual frequency set. This will be the closest possible match to the requested frequency.

void pwmOutConfig(unsigned int channel, int pwmoption);


Option flags are used to enable features on an individual PWM channels. Use pwm_init() to set the frequency.
An exception error will occur if brdInit() has not been called previously.
Parameters
channel is the PWM output channel to set: 0 for DA0, 1 for DA1.
pwmoption is used to set the PWM options as a combination of the following bit masks:
PWM_NORMAL--sets normal push-pull logic output.
PWM_SPREAD--Set pulse spreading. The duty cycle is spread over four separate pulses to increase the pulse frequency. Use this option for A/D and D/A conversions.
PWM_OPENDRAIN--sets the PWM output pin to be open-drain. This mask is usually not used.
Return Value
None.
SEE ALSO

int pwmOut(unsigned int channel, int rawdata);


Sets a voltage (0 to Vdd) on an analog output channel given a data point on the 1024 clock count cycle.
Call pwmOutConfig() and pwm_init() before using this function. (An exception error will occur if these functions were not been called previously.)
Parameters
channel is the PWM output channel to write: 0 for DA0, 1 for DA1
rawdata is data value (0-1024) for a 1024 clock count cycle. The value may be calculated using the percent duty cycle value (percentage that is on or high) of the 1024 clock count cycle, for example, 0.25*1024.
Return Value
0 if successful
SEE ALSO

void pwmOutVolts(unsigned int channel, int rawdata);


Sets the voltage of an analog output channel by using the previously set calibration constants to calculate the correct data values.
Call pwmOutConfig() and pwm_init() before using this function. (An exception error will occur if these functions were not been called previously.)
Parameters
channel is the output channel 0 or 1 to write: 0 for DA0, 1 for DA1
voltage is the voltage desired on the output channel (0-3.3 V)
Return Value
None.
See Also

int anaOutCalib(int channel, int value1, float volts1,int value2, float volts2);


Calibrates the response of the D/A converter channel as a linear function using the two conversion points provided. Values are calculated and placed into global table _dacCalibS for analog inputs to be stored later into simulated EEPROM using the function anaOutEEWr().
Each channel will have a linear constant and a voltage offset.
Parameters
channel is the output channel 0 or 1: 0 for DA0, 1 for DA1
value1 is the first D/A converter value (0-1023), usually a value of 310 that corresponds to 1.0 V
volts1 is the voltage corresponding to the first D/A converter value (0-3.3 V or Vref)
value2 is the second D/A converter value (0-1023), usually a value of 930 that corresponds to 3.0 V
volts2 is the voltage corresponding to the second D/A converter value (0-3.3 V or Vref)
Return Value
0 if successful
-1 if not able to make calibration constants
SEE ALSO

int anaOutEERd(unsigned int channel);


Reads the calibration constants, gain, and offset for an output based on its designated channel code position into global table _adcCalibS. The constants are stored in the top 1K of the reserved user block memory area. Use the sample program USERBLOCKINFOR.C in SAMPLES\BL2500 to get the addresses reserved for the calibration data constants and the addresses available for use by your application program.

NOTE This function cannot be run in RAM.

Parameters
channel is the output channel 0 or 1: 0 for DA0, 1 for DA1
Return Value
0 if successful
-1 if invalid address or range
SEE ALSO

int anaOutEEWr(unsigned int channel);


Writes the calibration constants, gain, and offset for an output based on its designated channel code position from global table _adcCalibS. The constants are stored in the top 1K of the reserved user block memory area. Use the sample program USERBLOCKINFOR.C in SAMPLES\BL2500 to get the addresses reserved for the calibration data constants and the addresses available for use by your application program.

NOTE This function cannot be run in RAM.

Parameter
channel is the output channel 0 or 1: 0 for DA0, 1 for DA1
Return Value
0 if successful
-1 if invalid address or range
SEE ALSO

4.4.7 RabbitNet Port

The function calls described in this section are used to configure the BL2500 for use with RabbitNet peripheral cards. The user's manual for the specific peripheral card you are using contains additional function calls related to the RabbitNet protocol and the individual peripheral card.

Add the following lines at the start of your program.

Set the following bits in RNSTATUSABORT to abort transmitting data after the status byte is returned. This does not affect the status byte and still can be interpreted. Set any bit combination to abort:

bit 7--device busy is hard-coded into driver
bit 5--identifies router or slave
bits 4,3,2--peripheral-board-specific bits
bit 1--command rejected
bit 0--watchdog timeout

void rn_sp_info();


Provides rn_init() with the serial port control information needed for BL2500 series controllers.
Return Value
None.

void rn_sp_close(int port);


Deactivates the BL2500 RabbitNet port as a clocked serial port. This call is also used by rn_init().
Parameters
portnum = 0
Return Value
None

void rn_sp_enable(int portnum);


This is a macro that enables or asserts the BL2500 RabbitNet port select prior to data transfer.
Parameters
portnum = 0
Return Value
None

void rn_sp_disable(int portnum);


This is a macro that disables or deasserts the BL2500 RabbitNet port select to invalidate data transfer.
Parameters
portnum = 0
Return Value
None.

Rabbit Semiconductor
www.rabbit.com
PREV INDEX NEXT