/****************************************************************************** * This demo application illustrates how to use the VXI Word Serial Char Driver * and an M-Module ANSI-C driver to control an M-Module instrument on C&H's * VX406C Intelligent M-Module Carrier. The VXI Word Serial Char Driver is part * of C&H's Embedded Linux Distribution for the intelligent carriers. * * This particular example was written for the VX406C however the concept carriers * over to all of C&H's VXI Intelligent Carrier (VX406C, VX407C, VX411C). * * The application should be compiled and linked to run on the MPC8245 resident * on the carrier. The recommended toolchain is ELDK available from www.denx.de. * * This demo uses the M395 DAC M-Module. The demo will open the VXI Word Serial * Char Driver using Non-Blocking I/O (Blocking I/O is also available) and wait * for a word serial message from the VXI host. When a message is received it * perform the function of the command. * * Commands can be cutomized to be any sequence of ASCII characters up top 256 * bytes. The commands implemented in this demo are as follows: * * volt - Set the DAC output voltage to the value specified * sweep - Causes the DAC to sweep from 0 to 5 votls with a 1ms * delay at each volatge. An VXI interrupt is generated * when the sweeping is done. * volt? - Return the current DAC output value * clearirq - Clears the pending VXI interrupt. * * *******************************************************************************/ #include #include "apis.h" #include "m395defs.h" #include #include int main (void) { APIS_HANDLE m395; int i; int fd; char command[256], string[256]; int value; int current_value; printf("M395 Demo Program\n\n"); fd = open("//dev//VXI", O_RDWR | O_NONBLOCK); //We could also perform Blocking I/O m395_open (0, &m395); //Open and init the driver m395_boot (m395); //M395 must be booted m395_select_range (m395, V10UNI); //Set range to +10V unipolar m395_select_upd_mode(m395, CONT); //Set update mode to continuous while(1) { if(read(fd, command, 1) == 1) //Read a command from the VXI bus { if(strncmp(command, "volt ", 5) == 0) { sscanf(command, "volt %x", &value); m395_setchan(m395, 0, value); current_value = value; } else if(strncmp(command, "sweep", 5) == 0) { for(i=0; i<0x800; i++) { apis_delay(1); m395_setchan(m395, 0, i); current_value = i; } chvx406clinux_GenerateVxiInterrupt(m395, 0xAA); //Send VXI interrupt when done sweeping } else if(strncmp(command, "volt?", 5) == 0) { sprintf(string, "0x%x", current_value); write(fd, string, strlen(string)); //Send the result to VXI bus } else if(strncmp(command, "clearirq", 8) == 0) chvx406clinux_ClearVxiInterrupt(m395); } } m395_close (m395); return 0; }