Appendix b. double buffering example – Comtrol API (6508) for the MS-DOS User Manual
Page 36
![background image](/manuals/672111/36/background.png)
36
Troubleshooting
This appendix contains a copy of the
\ROCKET\SAMPLE\DBUF.C
file for your
convenience.
File:
DBUF.C
Project:
RocketPort
DOS API
Purpose:
Double buffering sample program
Comments:
This program shows how to use the periodic event function to
double buffer Tx data, and how to use the receive event function
to double buffer Rx data. The double buffering is done in a pair of
queues for each device, these are defined in the
Q_T
structure.
Operation:
Install a loopback plug on port 0. At the
DOS
command line type
"
DBUF
." Each time transmit data is enqueued to the device 0, the
Tx buffer the count is displayed. Each time data is dequeued from
the device 0; the Rx buffer, the count, and Rx string are
displayed.
********************************************************/
#include
#include
#include
#include
#include
#include
#include
#include "api.h"
#define NUMDEV 8
/* num devices this app supports */
#define TXBUF_SIZE 1024 /* transmit buffer size */
#define RXBUF_SIZE 1024 /* receive buffer size */
void EvRxData(int);
/* function prototypes */
void EvPeriodic(void);
int EnqTxData(int,unsigned char *,int);
int DeqRxData(int,unsigned char *,int);
typedef struct‘
/* transmit and receive queues */
{
int OpenTx;
/* TRUE if device open for Tx */
int TxIn;
/* index to add Tx data at */
int TxOut;
/* index to remove Tx data at */
unsigned char TxBuf[TXBUF_SIZE]; /* buffer for Tx data */
int RxIn;
/* index to add Rx data at */
int RxOut;
/* index to remove Rx data at */
unsigned char RxBuf[RXBUF_SIZE]; /* buffer to Rx data */
} Q_T;
Q_T q[NUMDEV];/* Tx and Rx queues for each dev */
/********************************************************
Function:
main
Purpose:
Initialization, test Tx and Rx double buffering.
*/
main()
{
int Dev;
int Err;
unsigned char Buf[100];
int Cnt;
/* Initialize controller */
aaInstallCtrlCHandler();
if((Err = aaInit()) != NO_ERR)
{
printf("Initialization Failure %x\n",Err);
aaExit();
exit(1);
}
/* Clear queues */
for(Dev = 0;Dev < NUMDEV;Dev++)
{
q[Dev].OpenTx = FALSE;
q[Dev].TxIn = 0;
q[Dev].TxOut = 0;
q[Dev].RxIn = 0;
q[Dev].RxOut = 0;
}
/* Set up application event functions */
aaInstallRxEvent(EvRxData);
aaInstallPeriodicEvent(EvPeriodic);
Appendix B. Double Buffering Example