Use 'char' instead of 'uint8_t' for character data
authorKeith Packard <keithp@keithp.com>
Thu, 30 Apr 2009 00:46:56 +0000 (17:46 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 30 Apr 2009 00:46:56 +0000 (17:46 -0700)
String and character constants are of char type, so using uint8_t causes
promotion to 16-bit types when comparing the two.

ao.h
ao_cmd.c
ao_config.c
ao_dbg.c
ao_flight_test.c
ao_gps.c
ao_ignite.c
ao_serial.c
ao_stdio.c
ao_test.c
ao_usb.c

diff --git a/ao.h b/ao.h
index 88bcc93a8f189625de326cefa4d7cf52cb7c6c42..12948ed3c55a422f1b48bce8cf536ec33d96a946 100644 (file)
--- a/ao.h
+++ b/ao.h
@@ -259,10 +259,10 @@ ao_led_init(uint8_t enable);
 
 /* Put one character to the USB output queue */
 void
 
 /* Put one character to the USB output queue */
 void
-ao_usb_putchar(uint8_t c);
+ao_usb_putchar(char c);
 
 /* Get one character from the USB input queue */
 
 /* Get one character from the USB input queue */
-uint8_t
+char
 ao_usb_getchar(void);
 
 /* Flush the USB output queue */
 ao_usb_getchar(void);
 
 /* Flush the USB output queue */
@@ -296,7 +296,7 @@ enum ao_cmd_status {
 };
 
 extern __xdata uint16_t ao_cmd_lex_i;
 };
 
 extern __xdata uint16_t ao_cmd_lex_i;
-extern __xdata uint8_t ao_cmd_lex_c;
+extern __xdata char    ao_cmd_lex_c;
 extern __xdata enum ao_cmd_status ao_cmd_status;
 
 void
 extern __xdata enum ao_cmd_status ao_cmd_status;
 
 void
@@ -318,7 +318,7 @@ void
 ao_cmd_decimal(void);
 
 struct ao_cmds {
 ao_cmd_decimal(void);
 
 struct ao_cmds {
-       uint8_t         cmd;
+       char            cmd;
        void            (*func)(void);
        const char      *help;
 };
        void            (*func)(void);
        const char      *help;
 };
@@ -462,7 +462,7 @@ struct ao_gps_pos {
 #define AO_LOG_POS_NONE                (~0UL)
 
 struct ao_log_record {
 #define AO_LOG_POS_NONE                (~0UL)
 
 struct ao_log_record {
-       uint8_t                 type;
+       char                    type;
        uint8_t                 csum;
        uint16_t                tick;
        union {
        uint8_t                 csum;
        uint16_t                tick;
        union {
@@ -654,11 +654,11 @@ void
 ao_serial_tx1_isr(void) interrupt 14;
 #endif
 
 ao_serial_tx1_isr(void) interrupt 14;
 #endif
 
-uint8_t
+char
 ao_serial_getchar(void) __critical;
 
 void
 ao_serial_getchar(void) __critical;
 
 void
-ao_serial_putchar(uint8_t c) __critical;
+ao_serial_putchar(char c) __critical;
 
 void
 ao_serial_init(void);
 
 void
 ao_serial_init(void);
index abab1463e7740ddd4abffffdd890889f0d7dd9b7..f0459a73fd4976b17b6077328d2c2b2c8ea13516 100644 (file)
--- a/ao_cmd.c
+++ b/ao_cmd.c
 #include "ao.h"
 
 __xdata uint16_t ao_cmd_lex_i;
 #include "ao.h"
 
 __xdata uint16_t ao_cmd_lex_i;
-__xdata uint8_t        ao_cmd_lex_c;
+__xdata char   ao_cmd_lex_c;
 __xdata enum ao_cmd_status ao_cmd_status;
 static __xdata uint8_t lex_echo;
 
 #define CMD_LEN        32
 
 __xdata enum ao_cmd_status ao_cmd_status;
 static __xdata uint8_t lex_echo;
 
 #define CMD_LEN        32
 
-static __xdata uint8_t cmd_line[CMD_LEN];
+static __xdata char    cmd_line[CMD_LEN];
 static __xdata uint8_t cmd_len;
 static __xdata uint8_t cmd_i;
 
 static void
 put_string(char *s)
 {
 static __xdata uint8_t cmd_len;
 static __xdata uint8_t cmd_i;
 
 static void
 put_string(char *s)
 {
-       __xdata uint8_t c;
+       __xdata char    c;
        while (c = *s++)
                putchar(c);
 }
        while (c = *s++)
                putchar(c);
 }
@@ -39,7 +39,7 @@ put_string(char *s)
 static void
 readline(void)
 {
 static void
 readline(void)
 {
-       __xdata uint8_t c;
+       __xdata char c;
        if (lex_echo)
                put_string("> ");
        cmd_len = 0;
        if (lex_echo)
                put_string("> ");
        cmd_len = 0;
@@ -212,7 +212,7 @@ echo(void)
        lex_echo = ao_cmd_lex_i != 0;
 }
 
        lex_echo = ao_cmd_lex_i != 0;
 }
 
-static const uint8_t help_txt[] = "All numbers are in hex";
+static const char help_txt[] = "All numbers are in hex";
 
 #define NUM_CMDS       11
 
 
 #define NUM_CMDS       11
 
@@ -256,7 +256,7 @@ ao_cmd_register(__code struct ao_cmds *cmds)
 void
 ao_cmd(void *parameters)
 {
 void
 ao_cmd(void *parameters)
 {
-       __xdata uint8_t c;
+       __xdata char    c;
        __xdata uint8_t cmd, cmds;
        __code struct ao_cmds * __xdata cs;
        void (*__xdata func)(void);
        __xdata uint8_t cmd, cmds;
        __code struct ao_cmds * __xdata cs;
        void (*__xdata func)(void);
index 593029f29dad4c0234001ae93ad6668f099eee13..9bb8fd1ae16f230384758c051a506811c83abd74 100644 (file)
@@ -188,7 +188,7 @@ ao_config_accel_zero_g_set(void) __reentrant
 }
 
 struct ao_config_var {
 }
 
 struct ao_config_var {
-       uint8_t         cmd;
+       char            cmd;
        void            (*set)(void) __reentrant;
        void            (*show)(void) __reentrant;
        const char      *help;
        void            (*set)(void) __reentrant;
        void            (*show)(void) __reentrant;
        const char      *help;
@@ -225,7 +225,7 @@ __code struct ao_config_var ao_config_vars[] = {
 void
 ao_config_set(void)
 {
 void
 ao_config_set(void)
 {
-       uint8_t c;
+       char    c;
        uint8_t cmd;
        void (*__xdata func)(void) __reentrant;
 
        uint8_t cmd;
        void (*__xdata func)(void) __reentrant;
 
index d100703f8673e9cdd71409a30960bdcdb2293164..8a11a444a786c7c9058098cc48b4210282ea04c0 100644 (file)
--- a/ao_dbg.c
+++ b/ao_dbg.c
@@ -287,7 +287,7 @@ debug_get(void)
 static uint8_t
 getnibble(void)
 {
 static uint8_t
 getnibble(void)
 {
-       __xdata uint8_t c;
+       __xdata char    c;
 
        c = getchar();
        if ('0' <= c && c <= '9')
 
        c = getchar();
        if ('0' <= c && c <= '9')
index aefe3da748ad2e0da07f6877d52b439eec2b4471..dea7b31ce05043ded361cde6f5991651b146dc7d 100644 (file)
@@ -108,7 +108,7 @@ const char const * const ao_state_names[] = {
 };
 
 struct ao_cmds {
 };
 
 struct ao_cmds {
-       uint8_t         cmd;
+       char            cmd;
        void            (*func)(void);
        const char      *help;
 };
        void            (*func)(void);
        const char      *help;
 };
index 353272f1badb4558a7825a13387d49b2b87b4564..e5a5a8842d9c38f76504afef3d5a65ba1508e385 100644 (file)
--- a/ao_gps.c
+++ b/ao_gps.c
 
 #define AO_GPS_LEADER          6
 
 
 #define AO_GPS_LEADER          6
 
-static const uint8_t ao_gps_header[] = "GPGGA,";
+static const char ao_gps_header[] = "GPGGA,";
 __xdata uint8_t ao_gps_mutex;
 __xdata uint8_t ao_gps_mutex;
-static __xdata uint8_t ao_gps_char;
+static __xdata char ao_gps_char;
 static __xdata uint8_t ao_gps_cksum;
 static __xdata uint8_t ao_gps_error;
 
 __xdata struct ao_gps_data     ao_gps_data;
 static __xdata struct ao_gps_data      ao_gps_next;
 
 static __xdata uint8_t ao_gps_cksum;
 static __xdata uint8_t ao_gps_error;
 
 __xdata struct ao_gps_data     ao_gps_data;
 static __xdata struct ao_gps_data      ao_gps_next;
 
-const uint8_t ao_gps_config[] =
+const char ao_gps_config[] =
        "$PSRF103,00,00,01,01*25\r\n"   /* GGA 1 per sec */
        "$PSRF103,01,00,00,01*25\r\n"   /* GLL disable */
        "$PSRF103,02,00,00,01*26\r\n"   /* GSA disable */
        "$PSRF103,00,00,01,01*25\r\n"   /* GGA 1 per sec */
        "$PSRF103,01,00,00,01*25\r\n"   /* GLL disable */
        "$PSRF103,02,00,00,01*26\r\n"   /* GSA disable */
@@ -137,7 +137,7 @@ ao_gps_parse_pos(__xdata struct ao_gps_pos * pos, uint8_t deg_width) __reentrant
 }
 
 static void
 }
 
 static void
-ao_gps_parse_flag(uint8_t yes_c, uint8_t yes, uint8_t no_c, uint8_t no) __reentrant
+ao_gps_parse_flag(char yes_c, uint8_t yes, char no_c, uint8_t no) __reentrant
 {
        ao_gps_skip_sep();
        if (ao_gps_char == yes_c)
 {
        ao_gps_skip_sep();
        if (ao_gps_char == yes_c)
@@ -153,7 +153,7 @@ ao_gps_parse_flag(uint8_t yes_c, uint8_t yes, uint8_t no_c, uint8_t no) __reentr
 void
 ao_gps(void) __reentrant
 {
 void
 ao_gps(void) __reentrant
 {
-       uint8_t c;
+       char    c;
        uint8_t i;
 
        for (i = 0; (c = ao_gps_config[i]); i++)
        uint8_t i;
 
        for (i = 0; (c = ao_gps_config[i]); i++)
@@ -238,9 +238,8 @@ ao_gps(void) __reentrant
                        ao_gps_skip_field();
                }
                if (ao_gps_char == '*') {
                        ao_gps_skip_field();
                }
                if (ao_gps_char == '*') {
-                       c = ao_gps_cksum ^ '*';
-                       i = ao_gps_hex(2);
-                       if (c != i)
+                       uint8_t cksum = ao_gps_cksum ^ '*';
+                       if (cksum != ao_gps_hex(2))
                                ao_gps_error = 1;
                } else 
                        ao_gps_error = 1;
                                ao_gps_error = 1;
                } else 
                        ao_gps_error = 1;
index b89fd2f7fbb254c9a8e1ff012703fe4a5d909148..be2915234b07d7a2c477e78c445baeb0e9f03866 100644 (file)
@@ -118,7 +118,7 @@ ao_igniter(void)
 }
 
 static uint8_t
 }
 
 static uint8_t
-ao_match_word(__code uint8_t *word)
+ao_match_word(__code char *word)
 {
        while (*word) {
                if (ao_cmd_lex_c != *word) {
 {
        while (*word) {
                if (ao_cmd_lex_c != *word) {
@@ -147,12 +147,12 @@ ao_ignite_manual(void)
        }
 }
 
        }
 }
 
-static __code uint8_t *igniter_status_names[] = {
+static __code char *igniter_status_names[] = {
        "unknown", "ready", "active", "open"
 };
 
 void
        "unknown", "ready", "active", "open"
 };
 
 void
-ao_ignite_print_status(enum ao_igniter igniter, __code uint8_t *name) __reentrant
+ao_ignite_print_status(enum ao_igniter igniter, __code char *name) __reentrant
 {
        enum ao_igniter_status status = ao_igniter_status(igniter);
        printf("Igniter: %6s Status: %s\n",
 {
        enum ao_igniter_status status = ao_igniter_status(igniter);
        printf("Igniter: %6s Status: %s\n",
index ae5e07640b5ba98367bb072dc2eff3e9b85e8cc7..20bb4f9683a5c4ed3003a4147e5df9906e3b86a8 100644 (file)
@@ -22,7 +22,7 @@
 struct ao_fifo {
        uint8_t insert;
        uint8_t remove;
 struct ao_fifo {
        uint8_t insert;
        uint8_t remove;
-       uint8_t fifo[SERIAL_FIFO];
+       char    fifo[SERIAL_FIFO];
 };
 
 volatile __xdata struct ao_fifo        ao_usart1_rx_fifo;
 };
 
 volatile __xdata struct ao_fifo        ao_usart1_rx_fifo;
@@ -71,10 +71,10 @@ ao_serial_tx1_isr(void) interrupt 14
        ao_wakeup(&ao_usart1_tx_fifo);
 }
 
        ao_wakeup(&ao_usart1_tx_fifo);
 }
 
-uint8_t
+char
 ao_serial_getchar(void) __critical
 {
 ao_serial_getchar(void) __critical
 {
-       uint8_t c;
+       char    c;
        while (ao_fifo_empty(ao_usart1_rx_fifo))
                ao_sleep(&ao_usart1_rx_fifo);
        ao_fifo_remove(ao_usart1_rx_fifo, c);
        while (ao_fifo_empty(ao_usart1_rx_fifo))
                ao_sleep(&ao_usart1_rx_fifo);
        ao_fifo_remove(ao_usart1_rx_fifo, c);
@@ -82,7 +82,7 @@ ao_serial_getchar(void) __critical
 }
 
 void
 }
 
 void
-ao_serial_putchar(uint8_t c) __critical
+ao_serial_putchar(char c) __critical
 {
        while (ao_fifo_full(ao_usart1_tx_fifo))
                ao_sleep(&ao_usart1_tx_fifo);
 {
        while (ao_fifo_full(ao_usart1_tx_fifo))
                ao_sleep(&ao_usart1_tx_fifo);
index da57f409f97824c52acc77dbcc9db8c49fddee03..fb8ce0937fc6cd9dd1b57b186bcf18eb4e7285ea 100644 (file)
@@ -26,7 +26,7 @@ putchar(char c)
 {
        if (c == '\n')
                ao_usb_putchar('\r');
 {
        if (c == '\n')
                ao_usb_putchar('\r');
-       ao_usb_putchar((uint8_t) c);
+       ao_usb_putchar(c);
 }
 
 void
 }
 
 void
@@ -38,5 +38,5 @@ flush(void)
 char
 getchar(void)
 {
 char
 getchar(void)
 {
-       return (char) ao_usb_getchar();
+       return ao_usb_getchar();
 }
 }
index 0fdfcfa1583fd1bfb21a600b7754f5398dd7470c..6d005ff6dcfae80a2414c152d766f3785812b5d4 100644 (file)
--- a/ao_test.c
+++ b/ao_test.c
@@ -87,7 +87,7 @@ beep(void)
 void
 echo(void)
 {
 void
 echo(void)
 {
-       uint8_t c;
+       char    c;
        for (;;) {
                ao_usb_flush();
                c = ao_usb_getchar();
        for (;;) {
                ao_usb_flush();
                c = ao_usb_getchar();
index d02bfac8878f5dbc182e412aea1612eaee85ec76..69f87fc4dd17a36e1ef53cfa8324984bb9857011 100644 (file)
--- a/ao_usb.c
+++ b/ao_usb.c
@@ -316,7 +316,7 @@ ao_usb_flush(void) __critical
 }
 
 void
 }
 
 void
-ao_usb_putchar(uint8_t c) __critical
+ao_usb_putchar(char c) __critical
 {
        for (;;) {
                USBINDEX = AO_USB_IN_EP;
 {
        for (;;) {
                USBINDEX = AO_USB_IN_EP;
@@ -332,10 +332,10 @@ ao_usb_putchar(uint8_t c) __critical
        }
 }
 
        }
 }
 
-uint8_t
+char
 ao_usb_getchar(void) __critical
 {
 ao_usb_getchar(void) __critical
 {
-       __xdata uint8_t c;
+       __xdata char    c;
        while (ao_usb_out_bytes == 0) {
                for (;;) {
                        USBINDEX = AO_USB_OUT_EP;
        while (ao_usb_out_bytes == 0) {
                for (;;) {
                        USBINDEX = AO_USB_OUT_EP;