summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2012-11-30 15:04:21 -0800
committerKeith Packard <keithp@keithp.com>2012-11-30 15:04:21 -0800
commit81648829defbaf49fc98c4520540f7a20c50c417 (patch)
treec79636a61586d93f5baaf0d4985acf77612bc329 /src
parent289ead258e217bc10493caab12a8b477f1bc2865 (diff)
altos: Share getnibble function
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>
Diffstat (limited to 'src')
-rw-r--r--src/cc1111/ao_dbg.c20
-rw-r--r--src/core/ao.h4
-rw-r--r--src/core/ao_cmd.c16
-rw-r--r--src/core/ao_send_packet.c20
4 files changed, 24 insertions, 36 deletions
diff --git a/src/cc1111/ao_dbg.c b/src/cc1111/ao_dbg.c
index 847b5aaf..214cb013 100644
--- a/src/cc1111/ao_dbg.c
+++ b/src/cc1111/ao_dbg.c
@@ -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);
diff --git a/src/core/ao.h b/src/core/ao.h
index 81d92e72..1aff3d49 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -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);
diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c
index 1814cecf..a3330974 100644
--- a/src/core/ao_cmd.c
+++ b/src/core/ao_cmd.c
@@ -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)
{
diff --git a/src/core/ao_send_packet.c b/src/core/ao_send_packet.c
index 1a8e74de..66315d22 100644
--- a/src/core/ao_send_packet.c
+++ b/src/core/ao_send_packet.c
@@ -21,22 +21,6 @@
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;