From 668d8c61cf5254602beebf0b2a1bc5be5d6c2bd3 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 20 Jun 2011 17:42:48 -0300 Subject: [PATCH] tools/: added interrupt_wait support to atnet and atrf-proxy (untested) - atrf-proxy/PROTOCOL: WAIT is now implemented and takes a timeout argument - atrf-proxy/atrf-proxy.c (cmd_more): implemented WAIT command using atrf_interrupt_wait - lib/atnet.c (atnet_interrupt_wait, atnet_driver): added interrupt_wait (using WAIT) --- tools/atrf-proxy/PROTOCOL | 9 +++++---- tools/atrf-proxy/atrf-proxy.c | 12 ++++++++++++ tools/lib/atnet.c | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tools/atrf-proxy/PROTOCOL b/tools/atrf-proxy/PROTOCOL index f5a4c18..2a0cbd6 100644 --- a/tools/atrf-proxy/PROTOCOL +++ b/tools/atrf-proxy/PROTOCOL @@ -60,8 +60,8 @@ POLL +0|1 -message -WAIT -+0|1 +WAIT timeout_ms ++value -message @@ -84,8 +84,9 @@ The device is implicitly opened when establishing a TCP session. The device is implicitly closed when closing the TCP session. -Asynchrous interrupt notification (not implemented yet) +Asynchrous interrupt notification --------------------------------- The WAIT command is not answered until an interrupt or another command is -received. WAIT returns the interrupt status, just like POLL. +received. WAIT returns the value of the IRQ_STATUS register. If WAIT +times out before receiving an interrupt, it returns 0. diff --git a/tools/atrf-proxy/atrf-proxy.c b/tools/atrf-proxy/atrf-proxy.c index c1e9606..919cde4 100644 --- a/tools/atrf-proxy/atrf-proxy.c +++ b/tools/atrf-proxy/atrf-proxy.c @@ -168,6 +168,18 @@ static int cmd_more(struct atrf_dsc *dsc, struct netio *netio, const char *cmd) return netio_printf(netio, "-I/O error\n"); return netio_printf(netio, "+0x%02x\n", res); } + if (!strcasecmp(cmd, "wait")) { + uint8_t res; + + if (!n) + n = 1; + res = atrf_interrupt_wait(dsc, n); + if (atrf_error(dsc)) + return netio_printf(netio, "-I/O error\n"); + if (res < 0) + return netio_printf(netio, "-not supported\n"); + return netio_printf(netio, "+0x%02x\n", res); + } if (!strcasecmp(cmd, "getram")) { uint8_t res; diff --git a/tools/lib/atnet.c b/tools/lib/atnet.c index d51814f..41e17ae 100644 --- a/tools/lib/atnet.c +++ b/tools/lib/atnet.c @@ -463,6 +463,26 @@ static int atnet_interrupt(void *handle) } +int atnet_interrupt_wait(void *handle, int timeout_ms) +{ + struct atnet_dsc *dsc = handle; + unsigned long value; + char *end; + + if (dsc->error) + return 0; + if (dialog(dsc, "WAIT %d", timeout_ms) < 0) + return 0; + value = strtoul(dsc->reply+1, &end, 0); + if (*end || value > 1) { + fprintf(stderr, "invalid response \"%s\"\n", dsc->reply+1); + dsc->error = 1; + return 0; + } + return value; +} + + /* ----- CLKM handling ----------------------------------------------------- */ @@ -496,4 +516,5 @@ struct atrf_driver atnet_driver = { .sram_write = atnet_sram_write, .sram_read = atnet_sram_read, .interrupt = atnet_interrupt, + .interrupt_wait = atnet_interrupt_wait, };