1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/***************************************************************************
lib/ibppc.c
-------------------
begin : Oct 2002
copyright : (C) 2002 by Frank Mori Hess
email : fmhess@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it 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. *
* *
***************************************************************************/
#include "ib_internal.h"
#include <stdlib.h>
int ppoll_configure_device(ibConf_t *conf, const Addr4882_t addressList[],
int ppc_configuration)
{
uint8_t *cmd;
int i;
int retval;
retval = is_cic(interfaceBoard(conf));
if (retval <= 0) {
if (retval == 0)
setIberr(ECIC);
return -1;
}
cmd = malloc(16 + 2 * numAddresses(addressList));
if (!cmd) {
setIberr(EDVR);
setIbcnt(ENOMEM);
return -1;
}
i = create_send_setup(interfaceBoard(conf), addressList, cmd);
cmd[i++] = PPC;
cmd[i++] = ppc_configuration;
retval = my_ibcmd(conf, conf->settings.usec_timeout, cmd, i);
free(cmd);
cmd = NULL;
if (retval < 0)
return -1;
return 0;
}
int device_ppc(ibConf_t *conf, int ppc_configuration)
{
Addr4882_t addressList[2];
addressList[0] = packAddress(conf->settings.pad, conf->settings.sad);
addressList [1] = NOADDR;
return ppoll_configure_device(conf, addressList, ppc_configuration);
}
int board_ppc(ibConf_t *conf, int ppc_configuration)
{
ibBoard_t *board;
int retval;
struct gpib_ppoll_config_ioctl cmd;
board = interfaceBoard(conf);
// check if we are in local ppoll configuration mode
retval = query_local_ppoll_mode(board);
if (retval < 0)
return retval;
if (retval == 0) {
setIberr(ECAP);
return -1;
}
retval = query_ppc(board);
if (retval < 0)
return retval;
conf->settings.ppoll_config = retval; // store old value
cmd.config = ppc_configuration;
cmd.set_ist = 0;
cmd.clear_ist = 0;
retval = ioctl(board->fileno, IBPPC, &cmd);
if (retval < 0) {
setIberr(EDVR);
setIbcnt(errno);
return -1;
}
return 0;
}
int internal_ibppc(ibConf_t *conf, int v)
{
static const int ppc_mask = 0xe0;
int retval;
if (v && (v & ppc_mask) != PPE) {
fprintf(stderr, "libgpib: illegal parallel poll configuration\n");
setIberr(EARG);
return -1;
}
if (!v || (v & PPC_DISABLE))
v = PPD;
if (conf->is_interface) {
retval = board_ppc(conf, v);
if (retval < 0)
return retval;
} else {
retval = device_ppc(conf, v);
if (retval < 0)
return retval;
}
setIberr(conf->settings.ppoll_config);
conf->settings.ppoll_config = v;
return 0;
}
int ibppc(int ud, int v)
{
ibConf_t *conf;
int retval;
conf = enter_library(ud);
if (!conf)
return exit_library(ud, 1);
retval = internal_ibppc(conf, v);
if (retval < 0)
return exit_library(ud, 1);
return exit_library(ud, 0);
}
void PPollConfig(int boardID, Addr4882_t address,
int dataLine, int lineSense)
{
ibConf_t *conf;
int retval;
int ppoll_config;
Addr4882_t addressList[2];
conf = enter_library(boardID);
if (!conf) {
exit_library(boardID, 1);
return;
}
if (!conf->is_interface) {
setIberr(EDVR);
exit_library(boardID, 1);
return;
}
if (dataLine < 1 || dataLine > 8 ||
!addressIsValid(address) || address == NOADDR) {
setIberr(EARG);
exit_library(boardID, 1);
return;
}
ppoll_config = PPE_byte(dataLine, lineSense);
addressList[0] = address;
addressList[1]= NOADDR;
retval = ppoll_configure_device(conf, addressList, ppoll_config);
if (retval < 0) {
exit_library(boardID, 1);
return;
}
exit_library(boardID, 0);
}
void PPollUnconfig(int boardID, const Addr4882_t addressList[])
{
ibConf_t *conf;
uint8_t cmd;
int retval;
conf = enter_library(boardID);
if (!conf) {
exit_library(boardID, 1);
return;
}
if (!conf->is_interface) {
setIberr(EDVR);
exit_library(boardID, 1);
return;
}
if (!addressListIsValid(addressList)) {
setIberr(EARG);
exit_library(boardID, 1);
return;
}
if (numAddresses(addressList)) {
retval = ppoll_configure_device(conf, addressList, PPD);
} else {
cmd = PPU;
retval = my_ibcmd(conf, conf->settings.usec_timeout, &cmd, 1);
}
if (retval < 0) {
exit_library(boardID, 1);
return;
}
exit_library(boardID, 0);
}
int internal_ibist(ibConf_t *conf, int ist)
{
int retval;
struct gpib_ppoll_config_ioctl cmd;
if (!conf->is_interface) {
setIberr(EARG);
return -1;
}
retval = query_ist(interfaceBoard(conf));
if (retval < 0)
return retval;
setIberr(retval); // set iberr to old ist value
cmd.config = 0;
cmd.set_ist = 0;
cmd.clear_ist = 0;
if (ist)
cmd.set_ist = 1;
else
cmd.clear_ist = 1;
retval = ioctl(interfaceBoard(conf)->fileno, IBPPC, &cmd);
if (retval < 0) {
setIberr(EDVR);
setIbcnt(errno);
return -1;
}
return 0;
}
int ibist(int ud, int ist)
{
ibConf_t *conf;
int retval;
conf = enter_library(ud);
if (!conf)
return exit_library(ud, 1);
retval = internal_ibist(conf, ist);
if (retval < 0)
return exit_library(ud, 1);
return exit_library(ud, 0);
}
|