⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comedi_da.c

📁 linux驱动开发comedi的一些例子
💻 C
字号:
/* Digital to Analog: This is the COMEDI_DA.c file       *//* Creates and interface for using COMEDI Device Drivers *//* This file is from RTiC_Lab. The standard include file for device drivers */#include "main.h"/* This two include files are from COMEDI */#include "comedi_module.h"#include "comedi.h"/*************************************************//*    I need to include a header file called "device_config.h" to    configure the devices *//* #include "device_config.h" *//*************************************************//* Three functions have to be implemented. They are: * int RTiC_init_DA_card(void); * void RTiC_DA_run(void); * int RTiC_stop_DA_card(void);                          *//* There are few things that have to be planned before using COMEDI and   RTiC_lab together. For COMEDI the user has to device the minor number for   the device. She does it when "comedi_config /dev/comediX" is called. *//* COMEDI uses three structures when it calls the trig[0] functions. The   prototype for this call is:   int trig[0](comedi_device *,comedi_subdevice *,comedi_trig *)   We need the following structures:*/static comedi_device    *cd;static comedi_subdevice *cs;static comedi_trig      *ct;/* We need an data value for COMEDI ...*/static sampl_t comedi_data;/* ... and an unsigned int to tell COMEDI what channel to write to and how */static unsigned int comedi_channel;/*******************************************************************************//* NOTE: This three next values can be change by the user to fit his/her needs *//* The range for the analog to digital convertions     *//* Read the file from COMEDI:             */#ifndef COMEDI_RTIC_RANGE #define COMEDI_RTIC_RANGE 8#endif/* The reference for the analog to digital convertions */#ifndef COMEDI_RTIC_AREF#define COMEDI_RTIC_AREF  AREF_GROUND#endif/* According with the X value in "comedi_config /dev/comediX" */#ifndef RTiC_COMEDI_MINOR_DAC#define RTiC_COMEDI_MINOR_DAC 0#endif/*******************************************************************************//* This function is called at initialization by RTiC_lab */int RTiC_init_DA_card(void){  int i=0;  int right_subdevice = 0;  printk("In initialization \n");  /* Get comedi_device structure according with RTiC_COMEDI_MINOR_ADC */  cd = comedi_get_device_by_minor(RTiC_COMEDI_MINOR_DAC);    /* Allocate memory for the structure needed by COMEDI */    ct = (comedi_trig*) (kmalloc(sizeof(comedi_trig), GFP_KERNEL));  if(ct == NULL)    return -ENOMEM;  memset(ct,0,sizeof(comedi_trig));  /*  int n_subdevices;      comedi_subdevice *subdevices; */  /* Look up for the subdevice "COMEDI_SUBD_AI": Analog Input      by the end of this loop, cs will point to the apropriate subdevice */  for (i=0; i < cd->n_subdevices && (right_subdevice == 0); i++){    cs = cd->subdevices+i; /* Isn't it the same subdevices[i] than subdevices+i? */    if (cs->type == COMEDI_SUBD_AO)      right_subdevice = 1;  }    if (right_subdevice != 1)    return(-1); /* The device is not there. Maybe return ENXIO 6		   No such device or address                     */    /* Check that the value of NUM_CONTROL_INPUTS do not exceed the number of      available ADC channels                                                 */  if (NUM_CONTROL_OUTPUTS > cs->n_chan)    return (-1);  ct->data = &comedi_data;  ct->n_chan = 1;  return 0;}/* This function is called from RTiC_Lab code every period */void RTiC_DA_run(void){  int index;  /* In this function I have to write to the DACs from 0 to      NUM_CONTROL_OUTPUTS, the values are from RTiC_control array  */    /* Write to all the NUM_CONTROL_OUTPUTS channels */    for (index=0; index<NUM_CONTROL_OUTPUTS; index++)    {                 /* How should COMEDI write to the channels  */            comedi_channel = CR_PACK(index,COMEDI_RTIC_RANGE,COMEDI_RTIC_AREF );      ct->chanlist = &comedi_channel;      comedi_data = (sampl_t) ( (*(RTiC_control+index)) * 400);      ct->data = &comedi_data;      cs->trig[0](cd, cs, ct);            /* printk("[%d]->%X ", index, ct->data[0]);*/    }      printk("\n");}/* This function is called at the end from RTiC_lab */int RTiC_stop_DA_card(void){  printk("In stop card \n");  /* Free the memory for comedi_trig_struct */  kfree(ct);  /* The memory for comedi_device_struct is free by COMEDI */  return 0;}void RTiC_reset_DA(void){}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -