/* * (c) 2003 Jiri Baum * * Offered to the public under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * This code is made available on the understanding that it will not be * used in safety-critical situations without a full and competent review. */ /* * this file interfaces to the comedi library to talk to various DAQ cards */ #include #include #include #include "comedi_syntax.h" const char *IO_MODULE_DEFAULT_NAME = "comedi"; typedef struct { unsigned char dev; char phys_init; int maxdata; comedi_range *rng; } misc_t; typedef struct { comedi_addr *reg; misc_t *misc; } my_io_addr_t; #define my_io_addr ((my_io_addr_t*)io_addr) #define c_addr (*(my_io_addr->reg)) #define c_misc (*(my_io_addr->misc)) #define c_dev (c_misc.dev) /* individual field access */ #define c_f (devs[c_dev] .f) typedef struct { char *filename; comedi_t *f; } device_t; device_t *devs = 0; unsigned char numdevs = 0; int io_hw_parse_config(void) { if (sizeof(my_io_addr_t)>sizeof(io_addr_t)) { plc_log_errmsg(1,"Datatype size problem."); return -1; } return 0; } int io_hw_parse_io_addr(io_addr_t *io_addr, const char *addr_stri, dir_t dir, int pt_len) { int i; my_io_addr->reg=malloc(sizeof(comedi_addr)); my_io_addr->misc=malloc(sizeof(misc_t)); if ((!my_io_addr->reg) || (!my_io_addr->misc)) { plc_log_errmsg(1,"Couldn't allocate memory"); return -1; } c_addr = parse_comedi_addr(addr_stri); if ((!c_addr.device) || (c_addr.type<0)) { plc_log_errmsg(1,"Couldn't understand address: %s", addr_stri); return -1; } c_misc.phys_init = 0; /* has this device already been used? */ for (i=0;i