altos: Write xdata versions of memory functions 1.0.9.1
authorKeith Packard <keithp@keithp.com>
Fri, 7 Oct 2011 15:53:09 +0000 (09:53 -0600)
committerKeith Packard <keithp@keithp.com>
Fri, 7 Oct 2011 15:54:32 +0000 (09:54 -0600)
These are significantly smaller than the general pointer versions from
libc on the cc1111.

Signed-off-by: Keith Packard <keithp@keithp.com>
Conflicts:

src/Makefile.proto
src/cc1111/ao_adc.c
src/cc1111/ao_packet_master.c
src/core/ao.h

Fix up the new makefiles

25 files changed:
src/cc1111/ao_adc.c
src/cc1111/ao_arch.h
src/cc1111/ao_intflash.c
src/cc1111/ao_packet.c
src/cc1111/ao_packet_master.c
src/cc1111/ao_packet_slave.c
src/core/ao.h
src/core/ao_cmd.c
src/core/ao_config.c
src/core/ao_ee_fake.c
src/core/ao_gps_report.c
src/core/ao_host.h
src/core/ao_monitor.c
src/core/ao_telemetry.c
src/drivers/ao_25lc1024.c
src/drivers/ao_at45db161d.c
src/drivers/ao_gps_skytraq.c
src/product/Makefile.telebt
src/product/Makefile.teledongle
src/product/Makefile.telelaunch
src/product/Makefile.telemetrum
src/product/Makefile.telemini
src/product/Makefile.telenano
src/test/ao_flight_test.c
src/tidongle/Makefile

index 6aa6e01..1688ece 100644 (file)
@@ -46,7 +46,7 @@ ao_adc_get(__xdata struct ao_adc *packet)
 #else
        uint8_t i = ao_adc_ring_prev(ao_adc_head);
 #endif
-       memcpy(packet, &ao_adc_ring[i], sizeof (struct ao_adc));
+       ao_xmemcpy(packet, &ao_adc_ring[i], sizeof (struct ao_adc));
 }
 
 void
index 8a41791..02e3618 100644 (file)
@@ -204,4 +204,21 @@ struct ao_adc {
 
 #define AO_ADC_RING    32
 
+/* ao_string.c */
+
+void
+_ao_xmemcpy(__xdata uint8_t *dst, __xdata uint8_t *src, uint8_t count);
+
+#define ao_xmemcpy(d,s,c) _ao_xmemcpy((__xdata uint8_t *) (d), (__xdata uint8_t *) (s), (c))
+
+void
+_ao_xmemset(__xdata uint8_t *dst, uint8_t value, uint8_t count);
+
+#define ao_xmemset(d,v,c) _ao_xmemset((__xdata uint8_t *) (d), (v), (c))
+
+int8_t
+_ao_xmemcmp(__xdata uint8_t *a, __xdata uint8_t *b, uint8_t count);
+
+#define ao_xmemcmp(d,s,c) _ao_xmemcmp((__xdata uint8_t *) (d), (__xdata uint8_t *) (s), (c))
+
 #endif /* _AO_ARCH_H_ */
index d76d954..632e2a8 100644 (file)
@@ -180,7 +180,7 @@ ao_storage_device_read(uint32_t pos, __xdata void *d, uint16_t len) __reentrant
 {
        if (pos >= ao_storage_total || pos + len > ao_storage_total)
                return 0;
-       memcpy(d, ao_intflash+pos, len);
+       ao_xmemcpy(d, ao_intflash+pos, len);
        return 1;
 }
 
index f627e02..37ba92e 100644 (file)
@@ -35,7 +35,7 @@ ao_packet_send(void)
        ao_led_on(AO_LED_RED);
        /* If any tx data is pending then copy it into the tx packet */
        if (ao_packet_tx_used && ao_tx_packet.len == 0) {
-               memcpy(&ao_tx_packet.d, tx_data, ao_packet_tx_used);
+               ao_xmemcpy(&ao_tx_packet.d, tx_data, ao_packet_tx_used);
                ao_tx_packet.len = ao_packet_tx_used;
                ao_tx_packet.seq++;
                ao_packet_tx_used = 0;
@@ -80,7 +80,7 @@ ao_packet_recv(void)
                        /* Copy data to the receive data buffer and set up the
                         * offsets
                         */
-                       memcpy(rx_data, ao_rx_packet.packet.d, ao_rx_packet.packet.len);
+                       ao_xmemcpy(rx_data, ao_rx_packet.packet.d, ao_rx_packet.packet.len);
                        ao_packet_rx_used = 0;
                        ao_packet_rx_len = ao_rx_packet.packet.len;
 
index 0d0be30..ab19f97 100644 (file)
@@ -81,7 +81,7 @@ ao_packet_master(void)
        ao_packet_master_delay = AO_PACKET_MASTER_DELAY_SHORT;
        while (ao_packet_enable) {
                uint8_t r;
-               memcpy(ao_tx_packet.callsign, ao_config.callsign, AO_MAX_CALLSIGN);
+               ao_xmemcpy(ao_tx_packet.callsign, ao_config.callsign, AO_MAX_CALLSIGN);
                ao_packet_send();
                if (ao_tx_packet.len)
                        ao_packet_master_busy();
index d7cafa6..fd5d443 100644 (file)
@@ -24,7 +24,7 @@ ao_packet_slave(void)
        ao_tx_packet.len = AO_PACKET_SYN;
        while (ao_packet_enable) {
                if (ao_packet_recv()) {
-                       memcpy(&ao_tx_packet.callsign, &ao_rx_packet.packet.callsign, AO_MAX_CALLSIGN);
+                       ao_xmemcpy(&ao_tx_packet.callsign, &ao_rx_packet.packet.callsign, AO_MAX_CALLSIGN);
 #if HAS_FLIGHT
                        ao_flight_force_idle = TRUE;
 #endif
index 04610fe..c047472 100644 (file)
@@ -1817,4 +1817,10 @@ ao_log_single(void);
 
 #define AO_TELEPYRO_NUM_ADC    9
 
+#ifndef ao_xmemcpy
+#define ao_xmemcpy(d,s,c) memcpy(d,s,c)
+#define ao_xmemset(d,v,c) memset(d,v,c)
+#define ao_xmemcmp(d,s,c) memcmp(d,s,c)
+#endif
+
 #endif /* _AO_H_ */
index 2b64b8c..0c902f6 100644 (file)
@@ -265,8 +265,8 @@ help(void)
                cs = ao_cmds[cmds];
                for (cmd = 0; cs[cmd].func; cmd++)
                        printf("%-45s %s\n",
-                               cs[cmd].help,
-                               cs[cmd].help+1+strlen(cs[cmd].help));
+                              cs[cmd].help,
+                              cs[cmd].help+1+strlen(cs[cmd].help));
        }
 }
 
index a653bed..08cc79b 100644 (file)
@@ -78,8 +78,8 @@ _ao_config_get(void)
                /* Version 0 stuff */
                ao_config.main_deploy = AO_CONFIG_DEFAULT_MAIN_DEPLOY;
                ao_config.radio_channel = AO_CONFIG_DEFAULT_RADIO_CHANNEL;
-               memset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
-               memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
+               ao_xmemset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
+               ao_xmemcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,
                       sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
                ao_config_dirty = 1;
        }
@@ -148,7 +148,7 @@ ao_config_callsign_set(void) __reentrant
        uint8_t c;
        static __xdata char callsign[AO_MAX_CALLSIGN + 1];
 
-       memset(callsign, '\0', sizeof callsign);
+       ao_xmemset(callsign, '\0', sizeof callsign);
        ao_cmd_white();
        c = 0;
        while (ao_cmd_lex_c != '\n') {
@@ -161,7 +161,7 @@ ao_config_callsign_set(void) __reentrant
        if (ao_cmd_status != ao_cmd_success)
                return;
        _ao_config_edit_start();
-       memcpy(&ao_config.callsign, &callsign,
+       ao_xmemcpy(&ao_config.callsign, &callsign,
               AO_MAX_CALLSIGN + 1);
        _ao_config_edit_finish();
 }
@@ -535,7 +535,8 @@ ao_config_help(void) __reentrant
        for (cmd = 0; ao_config_vars[cmd].str != NULL; cmd++)
                printf("%-20s %s\n",
                       ao_config_vars[cmd].str,
-                      ao_config_vars[cmd].str+1+strlen(ao_config_vars[cmd].str));
+                      ao_config_vars[cmd].str+1+
+                      strlen(ao_config_vars[cmd].str));
 }
 
 static void
index b0c1d61..7fcfcab 100644 (file)
@@ -32,6 +32,6 @@ ao_ee_write_config(uint8_t *buf, uint16_t len) __reentrant
 uint8_t
 ao_ee_read_config(uint8_t *buf, uint16_t len) __reentrant
 {
-       memset(buf, '\0', len);
+       ao_xmemset(buf, '\0', len);
        return 1;
 }
index e57f874..c52ef62 100644 (file)
@@ -27,7 +27,7 @@ ao_gps_report(void)
        for (;;) {
                ao_sleep(&ao_gps_data);
                ao_mutex_get(&ao_gps_mutex);
-               memcpy(&gps_data, &ao_gps_data, sizeof (ao_gps_data));
+               ao_xmemcpy(&gps_data, &ao_gps_data, sizeof (ao_gps_data));
                ao_mutex_put(&ao_gps_mutex);
 
                if (!(gps_data.flags & AO_GPS_VALID))
@@ -72,7 +72,7 @@ ao_gps_tracking_report(void)
                ao_sleep(&ao_gps_tracking_data);
                ao_mutex_get(&ao_gps_mutex);
                gps_log.tick = ao_gps_tick;
-               memcpy(&gps_tracking_data, &ao_gps_tracking_data, sizeof (ao_gps_tracking_data));
+               ao_xmemcpy(&gps_tracking_data, &ao_gps_tracking_data, sizeof (ao_gps_tracking_data));
                ao_mutex_put(&ao_gps_mutex);
 
                if (!(n = gps_tracking_data.channels))
index 65c25fe..f2b2f0c 100644 (file)
@@ -125,3 +125,7 @@ struct ao_config {
 #define ao_config_get()
 
 struct ao_config ao_config = { 250, 16000 };
+
+#define ao_xmemcpy(d,s,c) memcpy(d,s,c)
+#define ao_xmemset(d,v,c) memset(d,v,c)
+#define ao_xmemcmp(d,s,c) memcmp(d,s,c)
index 56d7604..1a8bb52 100644 (file)
@@ -94,7 +94,7 @@ ao_monitor_put(void)
 
                        /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
                        rssi = (int16_t) (recv_orig.rssi >> 1) - 74;
-                       memcpy(callsign, recv_orig.telemetry_orig.callsign, AO_MAX_CALLSIGN);
+                       ao_xmemcpy(callsign, recv_orig.telemetry_orig.callsign, AO_MAX_CALLSIGN);
                        if (state > ao_flight_invalid)
                                state = ao_flight_invalid;
                        if (recv_orig.status & PKT_APPEND_STATUS_1_CRC_OK) {
@@ -171,7 +171,7 @@ ao_monitor_put(void)
 
                        /* Typical RSSI offset for 38.4kBaud at 433 MHz is 74 */
                        rssi = (int16_t) (recv_tiny.rssi >> 1) - 74;
-                       memcpy(callsign, recv_tiny.telemetry_tiny.callsign, AO_MAX_CALLSIGN);
+                       ao_xmemcpy(callsign, recv_tiny.telemetry_tiny.callsign, AO_MAX_CALLSIGN);
                        if (state > ao_flight_invalid)
                                state = ao_flight_invalid;
                        if (recv_tiny.status & PKT_APPEND_STATUS_1_CRC_OK) {
index 26e4e2a..95e5391 100644 (file)
@@ -131,10 +131,10 @@ ao_send_configuration(void)
                telemetry.configuration.apogee_delay = ao_config.apogee_delay;
                telemetry.configuration.main_deploy = ao_config.main_deploy;
                telemetry.configuration.flight_log_max = ao_config.flight_log_max >> 10;
-               memcpy (telemetry.configuration.callsign,
+               ao_xmemcpy (telemetry.configuration.callsign,
                        ao_config.callsign,
                        AO_MAX_CALLSIGN);
-               memcpy (telemetry.configuration.version,
+               ao_xmemcpy (telemetry.configuration.version,
                        ao_version,
                        AO_MAX_VERSION);
                ao_radio_send(&telemetry, sizeof (telemetry));
@@ -150,7 +150,7 @@ ao_send_location(void)
        {
                telemetry.generic.type = AO_TELEMETRY_LOCATION;
                ao_mutex_get(&ao_gps_mutex);
-               memcpy(&telemetry.location.flags,
+               ao_xmemcpy(&telemetry.location.flags,
                       &ao_gps_data.flags,
                       26);
                ao_mutex_put(&ao_gps_mutex);
@@ -167,7 +167,7 @@ ao_send_satellite(void)
                telemetry.generic.type = AO_TELEMETRY_SATELLITE;
                ao_mutex_get(&ao_gps_mutex);
                telemetry.satellite.channels = ao_gps_tracking_data.channels;
-               memcpy(&telemetry.satellite.sats,
+               ao_xmemcpy(&telemetry.satellite.sats,
                       &ao_gps_tracking_data.sats,
                       AO_MAX_GPS_TRACKING * sizeof (struct ao_telemetry_satellite_info));
                ao_mutex_put(&ao_gps_mutex);
@@ -187,7 +187,7 @@ ao_send_companion(void)
                telemetry.companion.update_period = ao_companion_setup.update_period;
                telemetry.companion.channels = ao_companion_setup.channels;
                ao_mutex_get(&ao_companion_mutex);
-               memcpy(&telemetry.companion.companion_data,
+               ao_xmemcpy(&telemetry.companion.companion_data,
                       ao_companion_data,
                       ao_companion_setup.channels * 2);
                ao_mutex_put(&ao_companion_mutex);
index 738f8ce..2d047a4 100644 (file)
@@ -167,7 +167,7 @@ ao_storage_device_write(uint32_t pos, __xdata void *buf, uint16_t len) __reentra
                        ao_ee_flush_internal();
                        ao_ee_block = block;
                }
-               memcpy(ao_ee_data + (uint16_t) (pos & 0xff), buf, len);
+               ao_xmemcpy(ao_ee_data + (uint16_t) (pos & 0xff), buf, len);
                ao_ee_block_dirty = 1;
        } ao_mutex_put(&ao_ee_mutex);
        return 1;
@@ -181,7 +181,7 @@ ao_storage_device_read(uint32_t pos, __xdata void *buf, uint16_t len) __reentran
        /* Transfer the data */
        ao_mutex_get(&ao_ee_mutex); {
                ao_ee_fill(block);
-               memcpy(buf, ao_ee_data + (uint16_t) (pos & 0xff), len);
+               ao_xmemcpy(buf, ao_ee_data + (uint16_t) (pos & 0xff), len);
        } ao_mutex_put(&ao_ee_mutex);
        return 1;
 }
@@ -200,7 +200,7 @@ ao_storage_erase(uint32_t pos) __reentrant
        ao_mutex_get(&ao_ee_mutex); {
                ao_ee_flush_internal();
                ao_ee_block = (uint16_t) (pos >> EE_BLOCK_SHIFT);
-               memset(ao_ee_data, 0xff, EE_BLOCK_SIZE);
+               ao_xmemset(ao_ee_data, 0xff, EE_BLOCK_SIZE);
                ao_ee_block_dirty = 1;
        } ao_mutex_put(&ao_ee_mutex);
        return 1;
index aee9877..6cd689e 100644 (file)
@@ -245,7 +245,7 @@ ao_storage_device_write(uint32_t pos, __xdata void *buf, uint16_t len) __reentra
                        ao_flash_flush_internal();
                        ao_flash_block = block;
                }
-               memcpy(ao_flash_data + (uint16_t) (pos & ao_flash_block_mask),
+               ao_xmemcpy(ao_flash_data + (uint16_t) (pos & ao_flash_block_mask),
                       buf,
                       len);
                ao_flash_block_dirty = 1;
@@ -261,7 +261,7 @@ ao_storage_device_read(uint32_t pos, __xdata void *buf, uint16_t len) __reentran
        /* Transfer the data */
        ao_mutex_get(&ao_flash_mutex); {
                ao_flash_fill(block);
-               memcpy(buf,
+               ao_xmemcpy(buf,
                       ao_flash_data + (uint16_t) (pos & ao_flash_block_mask),
                       len);
        } ao_mutex_put(&ao_flash_mutex);
@@ -282,7 +282,7 @@ ao_storage_erase(uint32_t pos) __reentrant
        ao_mutex_get(&ao_flash_mutex); {
                ao_flash_flush_internal();
                ao_flash_block = (uint16_t) (pos >> ao_flash_block_shift);
-               memset(ao_flash_data, 0xff, ao_flash_block_size);
+               ao_xmemset(ao_flash_data, 0xff, ao_flash_block_size);
                ao_flash_block_dirty = 1;
        } ao_mutex_put(&ao_flash_mutex);
        return 1;
index 7ac2694..6e65d65 100644 (file)
@@ -265,7 +265,7 @@ ao_nmea_gga()
        if (!ao_gps_error) {
                ao_mutex_get(&ao_gps_mutex);
                ao_gps_tick = ao_gps_next_tick;
-               memcpy(&ao_gps_data, &ao_gps_next, sizeof (ao_gps_data));
+               ao_xmemcpy(&ao_gps_data, &ao_gps_next, sizeof (ao_gps_data));
                ao_mutex_put(&ao_gps_mutex);
                ao_wakeup(&ao_gps_data);
        }
@@ -327,7 +327,7 @@ ao_nmea_gsv(void)
                ao_gps_tracking_next.channels = 0;
        else if (done) {
                ao_mutex_get(&ao_gps_mutex);
-               memcpy(&ao_gps_tracking_data, &ao_gps_tracking_next,
+               ao_xmemcpy(&ao_gps_tracking_data, &ao_gps_tracking_next,
                       sizeof(ao_gps_tracking_data));
                ao_mutex_put(&ao_gps_mutex);
                ao_wakeup(&ao_gps_tracking_data);
index 46c87db..8f7c742 100644 (file)
@@ -41,6 +41,7 @@ CC1111_SRC = \
        ao_radio_cmac.c \
        ao_romconfig.c \
        ao_serial.c \
+       ao_string.c \
        ao_timer.c \
        ao_usb.c \
        _bp.c
index 56182b8..c1b422c 100644 (file)
@@ -43,6 +43,7 @@ CC1111_SRC = \
        ao_radio.c \
        ao_radio_cmac.c \
        ao_romconfig.c \
+       ao_string.c \
        ao_timer.c \
        ao_usb.c \
        _bp.c
index 5da42e4..b40f61a 100644 (file)
@@ -45,6 +45,7 @@ CC1111_SRC = \
        ao_romconfig.c \
        ao_serial.c \
        ao_spi.c \
+       ao_string.c \
        ao_timer.c \
        ao_usb.c \
        _bp.c
index 2759ac5..4f4195a 100644 (file)
@@ -54,6 +54,7 @@ CC1111_SRC = \
        ao_radio.c \
        ao_romconfig.c \
        ao_serial.c \
+       ao_string.c \
        ao_spi.c \
        ao_timer.c \
        ao_usb.c \
index 7f25189..9f90b01 100644 (file)
@@ -45,6 +45,7 @@ CC1111_SRC = \
        ao_packet_slave.c \
        ao_radio.c \
        ao_romconfig.c \
+       ao_string.c \
        ao_timer.c \
        _bp.c
 
index c47e95f..eff3ea9 100644 (file)
@@ -44,6 +44,7 @@ CC1111_SRC = \
        ao_packet_slave.c \
        ao_radio.c \
        ao_romconfig.c \
+       ao_string.c \
        ao_timer.c \
        _bp.c
 
index 56733c8..921d44e 100644 (file)
@@ -173,6 +173,10 @@ struct ao_cmds {
        const char      *help;
 };
 
+#define ao_xmemcpy(d,s,c) memcpy(d,s,c)
+#define ao_xmemset(d,v,c) memset(d,v,c)
+#define ao_xmemcmp(d,s,c) memcmp(d,s,c)
+
 #include "ao_convert.c"
 
 struct ao_config {
@@ -542,7 +546,7 @@ ao_sleep(void *wchan)
                                        ao_flight_started = 1;
                                }
                        } else if (nword == 2 && strcmp(words[0], "TELEM") == 0) {
-                               char    *hex = words[1];
+                               __xdata char    *hex = words[1];
                                char    elt[3];
                                int     i, len;
                                uint8_t sum;
@@ -574,7 +578,7 @@ ao_sleep(void *wchan)
                                        continue;
                                }
                                if (len == 36) {
-                                       memcpy(&telem, bytes + 1, 32);
+                                       ao_xmemcpy(&telem, bytes + 1, 32);
                                        tick = telem.generic.tick;
                                        switch (telem.generic.type) {
                                        case AO_TELEMETRY_SENSOR_TELEMETRUM:
index 057e420..58b9d73 100644 (file)
@@ -38,6 +38,7 @@ CC1111_SRC = \
        ao_radio.c \
        ao_radio_cmac.c \
        ao_romconfig.c \
+       ao_string.c \
        ao_timer.c \
        ao_usb.c \
        _bp.c