📄 pci550x_dac0_clk.c
字号:
/* * pci550x user program - DAC0 Clocked Acquisition * * This test program uses a clock signal from either the internal DAC0 * PACER clock or the external clock source, DACLKIN, to clock the DAC. * Output data is written directly to the DAC0 FIFO register, and then * clocked to generate the voltage ouput at the DAC0 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 DAC0 FIFO is written continuously. If * the output rate exceeds the rate at which the DAC0 FIFO can be kept * non-empty by software, the DAC0 FIFO will underflow and DAC conversions * are automatically disabled by the hardware. * * Invoke this test program from the command line as follows: * * $ ./pci550x_dac0_clk -f /dev/pci550xN [-p] [-u] [-d USECS | -F NSECS] * [-g | -G | -t | -T] [-x | -X ] [-S] * * -f /dev/pci550xN = device node (N=device #) * -p = packed data mode * -u = unipolar * -d USECS = delay between DAC conversions in microseconds * -F NSECS = .25 usec delay between DAC conversions * -g = DAC external gate DATGIN (active low) * -G = DAC external gate DATGIN (active high) * -t = DAC external trigger DATGIN (falling edge) * -T = DAC external trigger DATGIN (rising edge) * -x = external clock DACLKIN (falling edge) * -X = external clock DACLKIN (rising edge) * -S = enable DAC1 sync * * EXAMPLE: run the test on device 3 in packed, unipolar data mode at * 10ms DAC conversion rate * * $ ./pci550x_dac0_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 dac0_status;int dac1_status;unsigned long udelay = PCI550X_NOMINAL_DAC_RATE;unsigned long ndelay = 64;int packed = PCI550X_DISABLE;int bipolar = PCI550X_ENABLE;int g = PCI550X_DISABLE; int G = PCI550X_DISABLE;int t = PCI550X_DISABLE; int T = PCI550X_DISABLE;int X = PCI550X_DISABLE; int x = PCI550X_DISABLE;int F = PCI550X_DISABLE; int S = PCI550X_DISABLE;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)); /* DAC gate disable */ if (g | G | t | T) { rc = ioctl(fd, PCI550X_IOCT_DA0_TGEN, PCI550X_DISABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_TGEN"); exit(1); } else { printf("DAC0 external gate disabled\n"); } } else { rc = ioctl(fd, PCI550X_IOCT_DA0_CGEN, PCI550X_DISABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_CGEN"); exit(1); } else { printf("DAC0 software gate disabled\n"); } } /* disable DAC0 to do conversions */ rc = ioctl(fd, PCI550X_IOCT_DA0_CVEN, PCI550X_DISABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_CVEN"); exit(1); } else { printf("DAC0 disabled to do conversions\n"); } /* DAC1 sync */ if (S) { 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 DAC0 FIFO */ rc = ioctl(fd, PCI550X_IOCT_DA0_STATUS_FFEN, PCI550X_DISABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_STATUS_FFEN"); exit(1); } else { printf("DAC0 FIFO disabled\n"); } /* DAC1 sync */ if (S) { 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:gGtTxXF:S")) != -1) switch(c) { case 'd': if ((sscanf(optarg, "%ld", &udelay)) == 0) udelay = PCI550X_NOMINAL_DAC_RATE; break; case 'F': if ((sscanf(optarg, "%ld", &ndelay)) == 0) ndelay = 64; F = PCI550X_ENABLE; 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_dac0_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"); printf("-F NSECS = .25 microseconds delay between " "DAC conversions\n"); printf("-g, DAC external gate DATGIN (active low)\n"); printf("-G, DAC external gate DATGIN (active high)\n"); printf("-t, DAC external trigger (falling edge)\n"); printf("-T, DAC external trigger (rising edge)\n"); printf("-x, external clock DACLKIN (falling edge)\n"); printf("-X, external clock DACLKIN (rising edge)\n"); printf("-S, enable DAC1 sync\n"); exit(0); case 'g': g = PCI550X_ENABLE; break; case 'G': G = PCI550X_ENABLE; break; case 't': t = PCI550X_ENABLE; break; case 'T': T = PCI550X_ENABLE; break; case 'X': X = PCI550X_ENABLE; break; case 'x': x = PCI550X_ENABLE; break; case 'S': S = PCI550X_ENABLE; break; 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 DAC0 PACER Clock Source */ if (x) { rc = ioctl(fd, PCI550X_IOCT_DA0_CLOCK_SOURCE, DAC0_EXF_CLK); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_CLOCK_SOURCE"); exit(1); } else { printf("External Clock Source (falling edge)\n"); } } else if (X) { rc = ioctl(fd, PCI550X_IOCT_DA0_CLOCK_SOURCE, DAC0_EXR_CLK); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_CLOCK_SOURCE"); exit(1); } else { printf("External Clock Source (rising edge)\n"); } } else { rc = ioctl(fd, PCI550X_IOCT_DA0_CLOCK_SOURCE, DAC0_IP_CLK); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_CLOCK_SOURCE"); exit(1); } else { printf("Internal Pacer Clock Source enabled\n"); } /* set the PACER CLOCK RATE */ if (F) { rc = ioctl(fd, PCI550X_IOCT_DA0_FPCEN, PCI550X_ENABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_FPCEN"); exit(1); } rc = ioctl(fd, PCI550X_IOCS_DAC0_FAST_CLOCK_RATE, &ndelay); if(rc == -1) { perror("ioctl " "PCI550X_IOCS_DAC0_FAST_CLOCK_RATE"); exit(1); } else { printf("DAC0 Pacer clock(0.25 usecs): %lu\n", ndelay); } } else { rc = ioctl(fd, PCI550X_IOCT_DA0_FPCEN, PCI550X_DISABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_FPCEN"); exit(1); } rc = ioctl(fd, PCI550X_IOCS_DAC0_PACER_CLOCK_RATE, &udelay); if(rc == -1) { perror("ioctl " "PCI550X_IOCS_DAC0_PACER_CLOCK_RATE"); exit(1); } else { printf("DAC0 Pacer clock(nsecs): %ld\n", udelay); } } } /* DAC1 sync */ if (S) { rc = ioctl(fd, PCI550X_IOCT_DA1_CLOCK_SOURCE, DAC1_DA0_CLK); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA1_CLOCK_SOURCE"); exit(1); } else { printf("DAC1 sync to DAC0 clock source\n"); } } /* enable DAC0 FIFO */ rc = ioctl(fd, PCI550X_IOCT_DA0_STATUS_FFEN, PCI550X_ENABLE); if(rc == -1) { perror("ioctl PCI550X_IOCT_DA0_STATUS_FFEN"); exit(1); } else { printf("%s:%s DAC0 FIFO enabled\n",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -