?? pci550x_dac1_clk.c
字號:
/* * pci550x user program - DAC1 Clocked Acquisition * * This test program uses a clock signal from either the internal DAC1 * PACER clock or the external clock source, DACLKIN, to clock the DAC. * Output data is written directly to the DAC1 FIFO register, and then * clocked to generate the voltage ouput at the DAC1 port. This mode of * operation is referred to as "programmed I/O", meaning that no interrupts * or DMA functions are used to output the sample data. In this method of * operating the DAC, the non-full DAC1 FIFO is written continuously. If * the output rate exceeds the rate at which the DAC1 FIFO can be kept * non-empty by software, the DAC1 FIFO will underflow and DAC conversions * are automatically disabled by the hardware. * * Invoke this test program from the command line as follows: * * $ ./pci550x_dac1_clk -f /dev/pci550xN [-p] [-u] [-d USECS] * * -f /dev/pci550xN = device node (N=device #) * -p = packed data mode * -u = unipolar * -d USECS = delay between DAC conversions in microseconds * * EXAMPLE: run the test on device 3 in packed, unipolar data mode at * 10ms DAC conversion rate * * $ ./pci550x_dac1_clk -f /dev/pci550x3 -p -u 10000 */#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/fcntl.h>#include <sys/ioctl.h>#include <signal.h>#include <unistd.h>#include <linux/limits.h>#include <getopt.h>#define __USE_GNU#include <string.h>#define _PCI550X_USE_DAC_RANGE_TABLES#include "pci550x.h"/* GLOBLA DATA */int c;int dac1_status;unsigned long udelay = PCI550X_NOMINAL_DAC_RATE;int packed = PCI550X_DISABLE;int bipolar = PCI550X_ENABLE;char device[PATH_MAX] = "/dev/pci550x0";int i = 0;int j = 0;int filled = PCI550X_FALSE;int gate_enabled = PCI550X_FALSE;unsigned int dac_fifo;union {unsigned int dac_fifo;short bp_dac_fifo[2];unsigned short up_dac_fifo[2];} u1[PCI550X_DAC_FIFO];int fd, rc;int brd_type;void sighandler(int signum) { /* user wants to quit */ if (signum) printf("received signal: %s, cleaning up...\n", strsignal(signum)); /* disable DAC1 to do conversions */ rc = ioctl(fd, PCI550X_IOCT_DA1_CVEN, PCI550X_DISABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_CVEN"); exit(1); } else { printf("DAC1 disabled to do conversions\n"); } /* disable DAC1 FIFO */ rc = ioctl(fd, PCI550X_IOCT_DA1_STATUS_FFEN, PCI550X_DISABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_STATUS_FFEN"); exit(1); } else { printf("DAC1 FIFO disabled\n"); } close(fd); exit(0);}int main(int argc, char **argv) { /* get command line args */ opterr = 0; while ((c = getopt(argc, argv, "f:uphd:")) != -1) switch(c) { case 'd': if ((sscanf(optarg, "%ld", &udelay)) == 0) udelay = PCI550X_NOMINAL_DAC_RATE; break; case 'f': strncpy(device, optarg, PATH_MAX); break; case 'u': bipolar = PCI550X_DISABLE; break; case 'p': packed = PCI550X_ENABLE; break; case 'h': printf("usage: pci550x_dac1_clk -f /dev/pci550xN " "[-p] [-u] [-d USECS | -F NSECS] " "[-g | -G | -t | -T] [-x | -X]\n"); printf("-f /dev/pci550xN where N = board number\n"); printf("-p, packed data mode\n"); printf("-u, unipolar mode\n"); printf("-d USECS = microseconds delay between " "DAC conversions\n"); exit(0); default: break; } /* open the device */ fd = open(device, O_RDWR); if(fd == -1) { perror("open failed"); exit(1); } else { printf("open succeeded on %s\n", device); } /* query device type */ rc = ioctl(fd, PCI550X_IOCG_BRD_TYPE, &brd_type); if(rc == -1) { perror("ioctl PCI550X_IOCG_BRD_TYPE"); exit(1); } else { printf("ADAC Board Type: %s\n", brd_names[brd_type]); } /* install the signal handler */ signal(SIGINT, &sighandler); /* select PACER Clock Convert */ rc = ioctl(fd, PCI550X_IOCT_DA1_CLOCK_SOURCE, DAC1_IP_CLK); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_CLOCK_SOURCE"); exit(1); } else { printf("Internal Pacer Clock Source enabled\n"); } /* set the PACER CLOCK RATE */ rc = ioctl(fd, PCI550X_IOCS_DAC1_PACER_CLOCK_RATE, &udelay); if(rc == -1) { perror("ioctl PCI550X_IOCS_DAC1_PACER_CLOCK_RATE"); exit(1); } else { printf("DAC1 Pacer clock(nsecs): %ld\n", udelay); } /* enable DAC1 FIFO */ rc = ioctl(fd, PCI550X_IOCT_DA1_STATUS_FFEN, PCI550X_ENABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_STATUS_FFEN"); exit(1); } else { printf("DAC1 FIFO enabled\n"); } /* disable/enable packed data mode */ rc = ioctl(fd, PCI550X_IOCT_DA1_PDM, packed); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_PDM"); exit(1); } else { if (packed) printf("PDM enabled\n"); else printf("PDM disabled\n"); } /* select bipolar/unipolar mode */ rc = ioctl(fd, PCI550X_IOCT_DA1_UB, bipolar); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_UB"); exit(1); } else { if (bipolar) { printf("Bipolar mode enabled\n"); } else { printf("Unipolar mode enabled\n"); } } /* set initial DAC value at minimum of the range */ if (packed && bipolar) { u1[i].bp_dac_fifo[0] = drt.bp_min; u1[i].bp_dac_fifo[1] = drt.bp_min + 1; } else if (packed && (!(bipolar))) { u1[i].up_dac_fifo[0] = drt.up_min; u1[i].up_dac_fifo[1] = drt.up_min + 1; } else if (bipolar) { u1[i].bp_dac_fifo[0] = drt.bp_min; u1[i].bp_dac_fifo[1] = 0; } else { u1[i].up_dac_fifo[0] = drt.up_min; u1[i].up_dac_fifo[1] = 0; } while(1) { /* DAC1 status */ rc = ioctl(fd, PCI550X_IOCG_DA1_STATUS, &dac1_status); if(rc == -1) { perror("ioctl PCI550X_IOCG_DA1_STATUS"); exit(1); } /* exit on errors */ if (dac1_status & DA1_STATUS_CERR) { printf("DAC1 clocking error\n"); exit(1); } else if (dac1_status & DA1_STATUS_DERR) { printf("DAC1 pipeline underflow\n"); exit(1); } /* write data to DAC1 FIFO if it isn't full */ if (!(dac1_status & DA1_STATUS_FF)) { rc = ioctl(fd, PCI550X_IOCS_DA1_FIFO, &u1[i].dac_fifo); if(rc == -1) { perror("ioctl PCI550X_IOCS_DA1_FIFO"); exit(1); } else { if (packed && bipolar && filled) printf("%s:%s DAC1 (P,B): 0x%04hx = " "%f Volts\n" "%s:%s DAC1 (P,B): 0x%04hx = " "%f Volts\n", device, brd_names[brd_type], u1[j].bp_dac_fifo[0], u1[j].bp_dac_fifo[0] * drt.bp_res, device, brd_names[brd_type], u1[j].bp_dac_fifo[1], u1[j].bp_dac_fifo[1] * drt.bp_res); else if (packed && (!bipolar) && filled) printf("%s:%s DAC1 (P,U): 0x%04hx = " "%f Volts\n" "%s:%s DAC1 (P,U): 0x%04hx = " "%f Volts\n", device, brd_names[brd_type], u1[j].up_dac_fifo[0], u1[j].up_dac_fifo[0] * drt.up_res, device, brd_names[brd_type], u1[j].up_dac_fifo[1], u1[j].up_dac_fifo[1] * drt.up_res); else if (bipolar && filled) printf("%s:%s DAC1 (U,B): 0x%04hx = " "%f Volts\n", device, brd_names[brd_type], u1[j].bp_dac_fifo[0], u1[j].bp_dac_fifo[0] * drt.bp_res); else if (filled) printf("%s:%s DAC1 (U,U): 0x%04hx = " "%f Volts\n", device, brd_names[brd_type], u1[j].up_dac_fifo[0], u1[j].up_dac_fifo[0] * drt.up_res); } /* wrap around */ dac_fifo = u1[i].dac_fifo; i = (i + 1) % PCI550X_DAC_FIFO; u1[i].dac_fifo = dac_fifo; if (filled) j = (j + 1) % PCI550X_DAC_FIFO; /* ramp the output values */ if (packed && bipolar) if (u1[i].bp_dac_fifo[1] >= (drt.bp_max)) { u1[i].bp_dac_fifo[0] = drt.bp_min; u1[i].bp_dac_fifo[1] = drt.bp_min + 1; } else { u1[i].bp_dac_fifo[0] += 2; u1[i].bp_dac_fifo[1] += 2; } else if (packed && (!bipolar)) if (u1[i].up_dac_fifo[1] >= (drt.up_max)) { u1[i].up_dac_fifo[0] = drt.up_min; u1[i].up_dac_fifo[1] = drt.up_min + 1; } else { u1[i].up_dac_fifo[0] += 2; u1[i].up_dac_fifo[1] += 2; } else if (bipolar) if (u1[i].bp_dac_fifo[0] >= (drt.bp_max)) { u1[i].bp_dac_fifo[0] = drt.bp_min; } else { u1[i].bp_dac_fifo[0]++; } else if (u1[i].up_dac_fifo[1] >= (drt.up_max)) { u1[i].up_dac_fifo[0] = drt.up_min; } else { u1[i].up_dac_fifo[0]++; } } else if (!(gate_enabled)) { /* enable DAC1 to do conversions */ rc = ioctl(fd, PCI550X_IOCT_DA1_CVEN, PCI550X_ENABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_CVEN"); exit(1); } else { printf("DAC1 enabled to do conversions\n"); } gate_enabled = PCI550X_TRUE; } /* end FIFO Full check */ if (dac1_status & DA1_STATUS_FF) filled = PCI550X_TRUE; } /* end while */ close(fd); return(0); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -