| LAT Communication Board Driver: Software Architecture and Interfaces | ||
|---|---|---|
| Prev | Chapter 3. Polled Mode Driver | Next |
This sections covers examples for initializing the polled mode LCBD, for dispatching results in a polled event loop and for sending bulk data.
An example of initializing the polled mode LCBD follows:
// global LCB handle
static LCB *lcb; // LCB handle
int initLCB() {
int status = LCB_OK;
void *pCmdList; // command list
void *pRstList; // result list
void *pBaseAddr; // base address of circular buffer
// allocate memory for the command list -- suitably aligned
pCmdList = mallocCommandList( 4096);
// allocate memory for the result list -- suitably aligned
pRstList = mallocResultList( 4096);
// allocate memory for the LCB handle
lcb = malloc( LCB_SizeOf());
// assign base address for circular buffer
pBaseAddr = LCB_CIRC_BASE_ADDR;
// initialize the LCB handle
status = LCB_PollInit( lcb, pCmdList, pRstList, pBaseAddr);
if ( status != LCB_OK) {
free(lcb);
free(pRstList);
free(pCmdList);
return status;
}
// the LCB is now initialized, but not enabled
return status;
}
|
This section describe the polled event loop. First the reception of unsolicited data is enabled and then the driver enters an infinite loop waiting for LCB messages. As messages are found they are processed.
int eventLoop( unsigned int usrData) {
int status = LCB_OK;
LCB_msg msg;
// enable the LCB for receiving event data
status = LCB_PollStart( lcb);
if ( status != LCB_OK) {
return status;
}
// enter infinite loop
while ( 1) {
if ( msg = LCB_PollQuery( lcb)) {
// message found, process it.
if ( msg->error) {
// record/report error
status = msg->error;
}
else {
// proces the message. The user could also make a copy of
// the bulk data at this time.
status = processData( usrData, msg->bulkData);
}
// free unsolicited data
LCB_msgFree( msg);
}
// sleep, or poll other devices, etc...
}
return status;
}
|
This section describes sending bulk data on the event fabric.
int sendData( LCB *lcb) {
int status = LCB_OK;
unsigned int nBytes = 4000; // number of bytes to send
unsigned int *data;
short destAddr = 0x41 // destination LATp node address
short proto = 3; // LATp prototcol to use
data = (unsigned int *)malloc( nBytes);
// fill *data with interesting data to send
status = LCB_PollSend( lcb, destAddr, proto, nBytes, data);
free( data);
return status;
}
|