ao-tools: move 16/32-bit readers from ao-stmload to lib
authorKeith Packard <keithp@keithp.com>
Thu, 28 Nov 2013 17:52:01 +0000 (09:52 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 28 Nov 2013 17:52:01 +0000 (09:52 -0800)
ao-tools/ao-stmload/ao-stmload.c
ao-tools/lib/ao-selfload.c

index 71d1ec572409e6ebd54d71a7ea40e90db22869aa..7f521bbc58f02c83e52cd0213d9efe727fb797ce 100644 (file)
@@ -56,10 +56,8 @@ struct ao_sym ao_symbols[] = {
 };
 
 #define NUM_SYMBOLS            5
-#define NUM_REQUIRED_SYMBOLS   3
 
 int ao_num_symbols = NUM_SYMBOLS;
-int ao_num_required_symbols = NUM_REQUIRED_SYMBOLS;
 
 /*
  * Edit the to-be-written memory block
@@ -82,40 +80,6 @@ rewrite(struct ao_hex_image *load, unsigned address, uint8_t *data, int length)
        memcpy(load->data + address - load->address, data, length);
 }
 
-/*
- * Read a 16-bit value from the USB target
- */
-
-static uint16_t
-get_uint16_cc(struct cc_usb *cc, uint32_t addr)
-{
-       struct ao_hex_image     *hex = ao_self_read(cc, addr, 2);
-       uint16_t                v;
-       uint8_t                 *data;
-
-       if (!hex)
-               return 0;
-       data = hex->data + addr - hex->address;
-       v = data[0] | (data[1] << 8);
-       free(hex);
-       return v;
-}
-
-static uint32_t
-get_uint32_cc(struct cc_usb *cc, uint32_t addr)
-{
-       struct ao_hex_image     *hex = ao_self_read(cc, addr, 4);
-       uint32_t                v;
-       uint8_t                 *data;
-
-       if (!hex)
-               return 0;
-       data = hex->data + addr - hex->address;
-       v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
-       free(hex);
-       return v;
-}
-
 /*
  * Read a 16-bit value from the target device with arbitrary
  * alignment
@@ -148,7 +112,7 @@ get_uint16(stlink_t *sl, struct cc_usb *cc, uint32_t addr)
 {
        uint16_t        result;
        if (cc)
-               result = get_uint16_cc(cc, addr);
+               result = ao_self_get_uint16(cc, addr);
        else
                result = get_uint16_sl(sl, addr);
        printf ("read 0x%08x = 0x%04x\n", addr, result);
@@ -193,7 +157,7 @@ get_uint32(stlink_t *sl, struct cc_usb *cc, uint32_t addr)
        uint32_t        result;
 
        if (cc)
-               result = get_uint32_cc(cc, addr);
+               result = ao_self_get_uint32(cc, addr);
        else
                result = get_uint32_sl(sl, addr);
        printf ("read 0x%08x = 0x%08x\n", addr, result);
index bf036f33daccd19c9c0de1afcd28b1c9549815c8..41e45adc4f8f21009a5f1bed4264993955776fd5 100644 (file)
@@ -122,3 +122,37 @@ ao_self_write(struct cc_usb *cc, struct ao_hex_image *image)
        cc_usb_printf(cc,"a\n");
        return 1;
 }
+
+/*
+ * Read a 16-bit value from the USB target
+ */
+
+uint16_t
+ao_self_get_uint16(struct cc_usb *cc, uint32_t addr)
+{
+       struct ao_hex_image     *hex = ao_self_read(cc, addr, 2);
+       uint16_t                v;
+       uint8_t                 *data;
+
+       if (!hex)
+               return 0;
+       data = hex->data + addr - hex->address;
+       v = data[0] | (data[1] << 8);
+       free(hex);
+       return v;
+}
+
+uint32_t
+ao_self_get_uint32(struct cc_usb *cc, uint32_t addr)
+{
+       struct ao_hex_image     *hex = ao_self_read(cc, addr, 4);
+       uint32_t                v;
+       uint8_t                 *data;
+
+       if (!hex)
+               return 0;
+       data = hex->data + addr - hex->address;
+       v = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+       free(hex);
+       return v;
+}