next up previous
Next: The D/A Driver Up: Creating I/O Drivers Previous: Creating I/O Drivers

The A/D Driver

The most basic device driver for an A/D board should contain, as a minimum, the following template:

#include ``main.h''            /* needed */

int RTiC_init_AD_card(void)
{
  /* do all card initialization here */	
  return(RTIC_SUCCESS);        /* or RTIC_ERROR, depending */
}

void RTiC_AD1_run(void)
{
  /* do all periodic jobs here */
}

void RTiC_AD2_run(void)
{
  /* do all periodic jobs here */
}

int RTiC_stop_AD_card(void)
{
  /* do all card ``stopping'' functions here */
  return(RTIC_SUCCESS);        /* or RTIC_ERROR, depending */
}

The first function RTiC_init_AD_card is run immediately after the user releases the ``RUN'' button in xrtic. Similarly, the last function, RTiC_stop_AD_card is run immediately after the user releases the ``STOP'' button in xrtic. In both of these cases, the functions must return either ``RTIC_ERROR'' or ``RTIC_SUCCESS'', depending on whether an error was encountered or not, respectively.

The RTiC_AD1_run and RTiC_AD2_run functions, on the other hand, have a completely different use. These functions are called once per controller cycle. The first function, RTiC_AD1_run is used to trigger A/D conversions in the A/D cards. Then, sometime later, and prior to the execution of the user's controller, the function RTiC_AD2_run will be called, at which time this function should load the data vector pointer (float *RTiC_sensor) with the sampled data, for example:

for (i=0; i<NUM_CONTROL_INPUTS; i++)
   *(RTiC_sensor+i) = INW(AD_BASE);



Michael Barabanov 2001-06-19