<< Previous | Next >>

pktXopen

int pktXopen( long baud, int mode, char options, int (*test_packet)() ); /* X is A-F */

Description

Opens serial port X. The functions pktEopen() and pktFopen() may be used with the Rabbit 3000 and Rabbit 4000.

The packet driver is meant to be used with a variety of transceiver hardware, so some functions must be defined by the user. Each of these functions, listed below, take no arguments and return nothing.

  • pktXinit() - Initializes the communication hardware. Called inside pktXopen(). This function may be written in C. It will only be called once each time the packet driver is opened, so speed is not a major concern. This is where I/O pins should be configured and any other setup should be performed.

  • pktXrx() - Sets the hardware to receive data. This function must be written in assembly. Any registers besides the 8-bit accumulator A must be preserved first, and restored before returning. This function is called when the driver switches from transmit to receive mode once there are no packets to send. This function is necessary for half-duplex connections and other types of shared bus schemes so that the transmitter can be disabled, allowing other nodes to use the lines.

  • pktXtx() - Sets the hardware to transmit data. This function must be written in assembly. The same rules for register usage as for pktXrx() apply. This function is called whenever the driver switches from receive to transmit mode in response to an additional packet or packets being available for sending. A typical use of this function is to enable any necessary transmitter hardware.

See the sample program Samples/PKTDEMO.C for an example of how to write these user- supplied functions. See technical note TN213 "Rabbit Serial Port Software" for more information on the packet driver.

Parameters

baud
Bits per second of data transfer: minimum is 2400.

mode
Type of packet scheme used, the options are:

  • PKT_GAPMODE

  • PKT_9BITMODE

  • PKT_CHARMODE

options
Further specification for the packet scheme. The value of this depends on the mode used:

  • gap mode - minimum gap size (in byte times)

  • 9-bit mode - type of 9-bit protocol

· PKT_RABBITSTARTBYTE
· PKT_LOWSTARTBYTE
· PKT_HIGHSTARTBYTE
  • char mode - character marking start of packet

test_packet
Pointer to a function that tests for completeness of a packet. The function should return 1 if the packet is complete, or 0 if more data should be read in. For gap mode the test function is not used and should be set to null.

Return value

1: The Rabbit's bps setting is within 5% of the input baud.
0: The Rabbit's bps setting differs by more than 5% of the input baud

Library

PACKET.LIB


Dynamic C Functions << Previous | Next >> rabbit.com