altos: Share getnibble function
authorKeith Packard <keithp@keithp.com>
Fri, 30 Nov 2012 23:04:21 +0000 (15:04 -0800)
committerKeith Packard <keithp@keithp.com>
Fri, 30 Nov 2012 23:04:21 +0000 (15:04 -0800)
Two implementations of the same function, one in cc1111/ao_dbg.c and
the other in core/ao_send_packet.c.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/cc1111/ao_dbg.c
src/core/ao.h
src/core/ao_cmd.c
src/core/ao_send_packet.c

index 847b5aaf857da6b602aeb28ee13e862e614daf35..214cb013154d2a7ceb9a9904bee3a4745e6b6c44 100644 (file)
@@ -281,22 +281,6 @@ debug_get(void)
        putchar('\n');
 }
 
-static uint8_t
-getnibble(void)
-{
-       __pdata char    c;
-
-       c = getchar();
-       if ('0' <= c && c <= '9')
-               return c - '0';
-       if ('a' <= c && c <= 'f')
-               return c - ('a' - 10);
-       if ('A' <= c && c <= 'F')
-               return c - ('A' - 10);
-       ao_cmd_status = ao_cmd_lex_error;
-       return 0;
-}
-
 static void
 debug_input(void)
 {
@@ -338,8 +322,8 @@ debug_output(void)
                return;
        ao_dbg_start_transfer(addr);
        while (count--) {
-               b = getnibble() << 4;
-               b |= getnibble();
+               b = ao_getnibble() << 4;
+               b |= ao_getnibble();
                if (ao_cmd_status != ao_cmd_success)
                        return;
                ao_dbg_write_byte(b);
index 81d92e72b2d512483b4640a08cf9c1651a2abab3..1aff3d49e708d3d113a30be13f98d3a2c222462d 100644 (file)
@@ -170,6 +170,10 @@ ao_cmd_hex(void);
 void
 ao_cmd_decimal(void);
 
+/* Read a single hex nibble off stdin. */
+uint8_t
+ao_getnibble(void);
+
 uint8_t
 ao_match_word(__code char *word);
 
index 1814cecf5021848e4fe88b8fc3841dd10e6a491f..a33309745430d51d8dd3137df057ec1e7752cf1b 100644 (file)
@@ -110,6 +110,22 @@ putnibble(uint8_t v)
                putchar(v + ('a' - 10));
 }
 
+uint8_t
+ao_getnibble(void)
+{
+       char    c;
+
+       c = getchar();
+       if ('0' <= c && c <= '9')
+               return c - '0';
+       if ('a' <= c && c <= 'f')
+               return c - ('a' - 10);
+       if ('A' <= c && c <= 'F')
+               return c - ('A' - 10);
+       ao_cmd_status = ao_cmd_lex_error;
+       return 0;
+}
+
 void
 ao_cmd_put16(uint16_t v)
 {
index 1a8e74de9e586adbd87805c141e8a1df4d5da87d..66315d227e8e05ac8a620e6727e11d44586f00ca 100644 (file)
 
 static __xdata uint8_t ao_send[AO_MAX_SEND];
 
-static uint8_t
-getnibble(void)
-{
-       char    c;
-
-       c = getchar();
-       if ('0' <= c && c <= '9')
-               return c - '0';
-       if ('a' <= c && c <= 'f')
-               return c - ('a' - 10);
-       if ('A' <= c && c <= 'F')
-               return c - ('A' - 10);
-       ao_cmd_status = ao_cmd_lex_error;
-       return 0;
-}
-
 static void
 ao_send_packet(void)
 {
@@ -53,8 +37,8 @@ ao_send_packet(void)
                return;
        }
        for (i = 0; i < count; i++) {
-               b = getnibble() << 4;
-               b |= getnibble();
+               b = ao_getnibble() << 4;
+               b |= ao_getnibble();
                if (ao_cmd_status != ao_cmd_success)
                        return;
                ao_send[i] = b;