summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-11 13:38:40 +0900
committerdaniel <danieruru@gmail.com>2013-01-11 13:38:40 +0900
commit939ce4d4b67c068055be6e2ab27cc6144a53d546 (patch)
tree188cc349bb49a4fc6d89a8849969a48c2b5c508a
parent557169f71b442ff10406ed764200f95084816fa8 (diff)
add the missing srq enable, disable checks in gpib for now
-rw-r--r--gpib.c8
-rw-r--r--libvxi11client/client.c16
-rw-r--r--libvxi11client/libvxi11client.c69
-rw-r--r--libvxi11client/libvxi11client.h1
-rw-r--r--vxi11_server.c25
5 files changed, 102 insertions, 17 deletions
diff --git a/gpib.c b/gpib.c
index 2218b1a..b2b24b7 100644
--- a/gpib.c
+++ b/gpib.c
@@ -784,9 +784,9 @@ void GPIB_and_VXI_start_query_response(gpointer ignore_this, gchar *in_string)
g_assert (ignore_this == NULL);
g_assert (in_string != NULL);
- if (!globals.HWDetect.gpib) {
- return;
- }
+ //if (!globals.HWDetect.gpib) {
+ // return;
+ //}
if (globals.Registers.pending_output_message != NULL) {
queue_error_for_gpib_only(query_error_interrupted);
@@ -795,7 +795,7 @@ void GPIB_and_VXI_start_query_response(gpointer ignore_this, gchar *in_string)
}
globals.Registers.pending_output_message = g_strdup_printf ("%s\n", in_string);
- TNT_4882_Status(STB,0x10,SET); // Set MAV bit
+ //TNT_4882_Status(STB,0x10,SET); // Set MAV bit
}
diff --git a/libvxi11client/client.c b/libvxi11client/client.c
index 04753a8..804ef91 100644
--- a/libvxi11client/client.c
+++ b/libvxi11client/client.c
@@ -14,6 +14,8 @@ static char* geterrorstring(int errorcode) {
return "channel not established";
case -8:
return "operation not supported";
+ case -9:
+ return "out of resources";
case -11:
return "device locked by another link";
case -12:
@@ -133,7 +135,21 @@ int main(int argc, char *argv[]) {
// create interrupt channel
if ((err = vxi11_create_intr_chan()) > 0) {
printf("Created interrupt channel\n");
+
+ // enable interrupts
+ if ((err = vxi11_enable_srq(true, "handle")) > 0)
+ printf("Enabled interrupts\n");
+ else
+ printf("Error enabling interrupts; %s\n", geterrorstring(err));
+
sleep(10);
+
+ // disable interrupts
+ if ((err = vxi11_enable_srq(false, NULL)) > 0)
+ printf("Disabled interrupts\n");
+ else
+ printf("Error disabling interrupts; %s\n", geterrorstring(err));
+
// destroy interrupt channel
if ((err = vxi11_destroy_intr_chan()) > 0)
printf("Destroyed interrupt channel\n");
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index 2f36147..b212487 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -30,6 +30,9 @@ static GThread* interruptthread;
static bool interruptchannelopen = false;
static void killinterruptthreadandwait() {
+#ifdef DEBUG
+ printf("Waiting for interrupt thread to die\n");
+#endif
interruptchannelopen = false;
g_thread_join(interruptthread);
interruptthread = NULL;
@@ -361,27 +364,46 @@ static gpointer interruptthreadfunc(gpointer data) {
}
*((unsigned int*) data) = transp->xp_port;
- int no_of_fds;
int i;
- struct pollfd pollfd_set[1024];
+ struct pollfd *my_pollfd = NULL;
+ int last_max_pollfd = 0;
- //svc_run();
- // stolen from: http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.commtechref%2Fdoc%2Fcommtrf1%2Fsvc_getreq_poll.htm
while (interruptchannelopen) {
- /* initialize the pollfd_set array and
- get no of file descriptors in "no_of_fds"*/
+ int max_pollfd = svc_max_pollfd;
+ if (max_pollfd == 0 && svc_pollfd == NULL)
+ break;
+
+ if (last_max_pollfd != max_pollfd) {
+ struct pollfd *new_pollfd = realloc(my_pollfd, sizeof(struct pollfd) * max_pollfd);
+
+ if (new_pollfd == NULL) {
+ break;
+ }
+
+ my_pollfd = new_pollfd;
+ last_max_pollfd = max_pollfd;
+ }
- /* Keep polling on file descriptors */
- switch (i = poll(pollfd_set, no_of_fds, -1)) {
+ for (i = 0; i < max_pollfd; ++i) {
+ my_pollfd[i].fd = svc_pollfd[i].fd;
+ my_pollfd[i].events = svc_pollfd[i].events;
+ my_pollfd[i].revents = 0;
+ }
+
+ switch (i = poll(my_pollfd, max_pollfd, VXI11_DEFAULT_TIMEOUT)) {
case -1:
+ break;
case 0:
continue;
default:
- /* Handle RPC request on each file descriptor */
- svc_getreq_poll(pollfd_set, i);
+ svc_getreq_poll(my_pollfd, i);
+ continue;
}
+ break;
}
+ free(my_pollfd);
+
#ifdef DEBUG
printf("Interrupt channel thread ended\n");
#endif
@@ -449,6 +471,33 @@ int vxi11_destroy_intr_chan() {
}
/**
+ * enable interrupts
+ */
+
+int vxi11_enable_srq(bool enable, char* handle) {
+ if (!interruptchannelopen)
+ return 0;
+ else if (clnt == NULL)
+ return 0;
+ else if (interruptthread == NULL)
+ return 0;
+
+ Device_EnableSrqParms params = { .lid = link, .enable = enable };
+ if (handle != NULL) {
+ params.handle.handle_val = handle;
+ params.handle.handle_len = strlen(handle);
+ }
+ Device_Error* error = device_enable_srq_1(&params, clnt);
+ if (error != NULL && error->error == 0) {
+ return 1;
+ }
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
+}
+
+/**
* send an abort to the connected device
*/
diff --git a/libvxi11client/libvxi11client.h b/libvxi11client/libvxi11client.h
index c9779e4..bf247a5 100644
--- a/libvxi11client/libvxi11client.h
+++ b/libvxi11client/libvxi11client.h
@@ -28,5 +28,6 @@ int vxi11_remote(bool waitforlock);
int vxi11_readstatusbyte(bool waitforlock);
int vxi11_create_intr_chan(void);
int vxi11_destroy_intr_chan(void);
+int vxi11_enable_srq(bool enable, char* handle);
int vxi11_docmd(unsigned long cmd, bool waitforlock);
int vxi11_close(void);
diff --git a/vxi11_server.c b/vxi11_server.c
index e852855..2382966 100644
--- a/vxi11_server.c
+++ b/vxi11_server.c
@@ -33,6 +33,9 @@
static CLIENT* intclient = NULL;
+static bool intenabled = false;
+static char* inthandler = NULL;
+
typedef struct {
} ActiveLink;
@@ -122,6 +125,10 @@ create_link_1_svc(Create_LinkParms *argp, struct svc_req *rqstp) {
break;
}
}
+ globals.Remote.vxi_connections++;
+#ifdef DEBUG
+ printf("created link %d, %d active links\n", linkid, globals.Remote.vxi_connections);
+#endif
struct sockaddr_in sin;
socklen_t len = sizeof(sin);
@@ -129,7 +136,6 @@ create_link_1_svc(Create_LinkParms *argp, struct svc_req *rqstp) {
result.error = 0;
result.abortPort = ntohs(sin.sin_port);
result.lid = linkid;
- globals.Remote.vxi_connections++;
}
}
return &result;
@@ -327,7 +333,19 @@ device_enable_srq_1_svc(Device_EnableSrqParms *argp, struct svc_req *rqstp) {
if (!isValidLink(argp->lid))
result.error = ERR_INVALIDLINKINDENTIFIER;
else {
+ if (inthandler != NULL)
+ free(inthandler);
+ if (argp->enable) {
+ if (argp->handle.handle_val != NULL) {
+ inthandler = malloc(argp->handle.handle_len);
+ strncpy(inthandler, argp->handle.handle_val, argp->handle.handle_len);
+#ifdef DEBUG
+ printf("Interrupt handle set to %s\n", inthandler);
+#endif
+ }
+ }
result.error = 0;
+ intenabled = argp->enable;
}
return &result;
}
@@ -360,14 +378,15 @@ destroy_link_1_svc(Device_Link *argp, struct svc_req *rqstp) {
if (!isValidLink(lid))
result.error = ERR_INVALIDLINKINDENTIFIER;
else {
+ globals.Remote.vxi_connections--;
#ifdef DEBUG
- printf("link %d destroyed\n", lid);
+ printf("link %d destroyed, %d active links\n", lid, globals.Remote.vxi_connections);
#endif
+ result.error = 0;
free(links[lid]);
links[lid] = NULL;
}
- globals.Remote.vxi_connections--;
return &result;
}