FreeCalypso > hg > freecalypso-tools
changeset 776:fac3176de18d
simagent: bare Tx implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Mar 2021 23:36:46 +0000 |
parents | 6ec781e61e68 |
children | 0cffc53991f9 |
files | target-utils/simagent/Makefile target-utils/simagent/cmdtab.c target-utils/simagent/stringarg.c target-utils/simagent/tx.c |
diffstat | 4 files changed, 95 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/target-utils/simagent/Makefile Fri Mar 12 22:08:07 2021 +0000 +++ b/target-utils/simagent/Makefile Fri Mar 12 23:36:46 2021 +0000 @@ -7,7 +7,7 @@ INSTDIR=/opt/freecalypso/target-bin PROG= simagent -OBJS= crt0.o byterx.o cmdtab.o invtable.o main.o simup.o +OBJS= crt0.o byterx.o cmdtab.o invtable.o main.o simup.o stringarg.o tx.o LIBS= ../libcommon/libcommon.a ../libprintf/libprintf.a ../libbase/libbase.a \ ../libc/libc.a LIBGCC= `${CC} -print-file-name=libgcc.a`
--- a/target-utils/simagent/cmdtab.c Fri Mar 12 22:08:07 2021 +0000 +++ b/target-utils/simagent/cmdtab.c Fri Mar 12 23:36:46 2021 +0000 @@ -9,6 +9,7 @@ extern void cmd_r32(); extern void cmd_sertimeout(); extern void cmd_sim_up(); +extern void cmd_tx(); extern void cmd_w8(); extern void cmd_w16(); extern void cmd_w32(); @@ -32,6 +33,7 @@ {"r32", cmd_r32}, {"sertimeout", cmd_sertimeout}, {"sim-up", cmd_sim_up}, + {"tx", cmd_tx}, {"w8", cmd_w8}, {"w16", cmd_w16}, {"w32", cmd_w32},
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/simagent/stringarg.c Fri Mar 12 23:36:46 2021 +0000 @@ -0,0 +1,43 @@ +/* + * This module contains the function that parses our hex string arguments. + */ + +#include <ctype.h> +#include "types.h" + +static +decode_hex_digit(c) +{ + if (isdigit(c)) + return c - '0'; + else if (islower(c)) + return c - 'a' + 10; + else + return c - 'A' + 10; +} + +decode_hex_string_arg(arg, buf, maxlen) + char *arg; + u8 *buf; + unsigned maxlen; +{ + unsigned count; + + for (count = 0; ; ) { + while (isspace(*arg)) + arg++; + if (!*arg) + break; + if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { + printf("ERROR: invalid hex string input\n"); + return; + } + if (count >= maxlen) { + printf("ERROR: hex string input is too long\n"); + return; + } + buf[count++] = (decode_hex_digit(arg[0]) << 4) | + decode_hex_digit(arg[1]); + } + return count; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/target-utils/simagent/tx.c Fri Mar 12 23:36:46 2021 +0000 @@ -0,0 +1,49 @@ +/* + * This module implements transmission of bytes toward the SIM. + */ + +#include "types.h" +#include "simregs.h" + +extern u16 conf1_reg; + +send_to_sim(bytes, count) + u8 *bytes; + unsigned count; +{ + unsigned n, timeout; + + SIMREGS.conf1 = conf1_reg |= SIM_CONF1_TXRX; + if (count == 1) + wait_ARM_cycles(372 * 4); /* wait 1 etu */ + for (n = 0; ; ) { + SIMREGS.dtx = bytes[n++]; + if (n == count) { + SIMREGS.conf1 = conf1_reg &= ~SIM_CONF1_TXRX; + return(0); + } + for (timeout = 12000; timeout; timeout--) + if (SIMREGS.it & SIM_IT_ITTX) + break; + if (!timeout) { + printf("ERROR: SIM interface Tx timeout\n"); + return(-1); + } + } +} + +cmd_tx(argstr) + char *argstr; +{ + u8 bytes[5]; + int rc; + + rc = decode_hex_string_arg(argstr, bytes, sizeof bytes); + if (rc < 0) + return; + if (rc == 0) { + printf("ERROR: empty hex string argument\n"); + return; + } + send_to_sim(bytes, rc); +}