diff options
author | daniel <danieruru@gmail.com> | 2013-01-11 13:38:40 +0900 |
---|---|---|
committer | daniel <danieruru@gmail.com> | 2013-01-11 13:38:40 +0900 |
commit | 939ce4d4b67c068055be6e2ab27cc6144a53d546 (patch) | |
tree | 188cc349bb49a4fc6d89a8849969a48c2b5c508a /libvxi11client | |
parent | 557169f71b442ff10406ed764200f95084816fa8 (diff) |
add the missing srq enable, disable checks in gpib for now
Diffstat (limited to 'libvxi11client')
-rw-r--r-- | libvxi11client/client.c | 16 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.c | 69 | ||||
-rw-r--r-- | libvxi11client/libvxi11client.h | 1 |
3 files changed, 76 insertions, 10 deletions
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(¶ms, 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); |