Dump config block from read/write config and flash_status commands
[fw/altos] / src / ao_flash.c
index 86b94765e984909878bfb8c78e0f1b2ad2172901..0120382d07615819ada2fb00545edcece3d9de8b 100644 (file)
@@ -397,6 +397,30 @@ ao_ee_flush(void) __reentrant
  * Read/write the config block, which is in
  * the last block of the flash
  */
+
+void
+ao_ee_dump_config(void) __reentrant
+{
+       uint16_t        i;
+       printf("Configuration block %d\n", FLASH_CONFIG_BLOCK);
+       ao_mutex_get(&ao_flash_mutex); {
+               ao_flash_flush_internal();
+               ao_flash_block = FLASH_BLOCK_NONE;
+               ao_flash_fill(FLASH_CONFIG_BLOCK);
+               i = 0;
+               do {
+                       if ((i & 7) == 0) {
+                               if (i)
+                                       putchar('\n');
+                               ao_cmd_put16((uint16_t) i);
+                       }
+                       putchar(' ');
+                       ao_cmd_put8(ao_flash_data[i]);
+                       ++i;
+               } while (i < sizeof (ao_config));
+       } ao_mutex_put(&ao_flash_mutex);
+}
+
 uint8_t
 ao_ee_write_config(uint8_t *buf, uint16_t len) __reentrant
 {
@@ -404,11 +428,13 @@ ao_ee_write_config(uint8_t *buf, uint16_t len) __reentrant
        if (len > FLASH_BLOCK_SIZE)
                return 0;
        ao_mutex_get(&ao_flash_mutex); {
+               printf("FLASH_CONFIG_BLOCK: %d\n", FLASH_CONFIG_BLOCK);
                ao_flash_fill(FLASH_CONFIG_BLOCK);
                memcpy(ao_flash_data, buf, len);
                ao_flash_block_dirty = 1;
                ao_flash_flush_internal();
        } ao_mutex_put(&ao_flash_mutex);
+       ao_ee_dump_config();
        return 1;
 }
 
@@ -418,6 +444,7 @@ ao_ee_read_config(uint8_t *buf, uint16_t len) __reentrant
        ao_flash_setup();
        if (len > FLASH_BLOCK_SIZE)
                return 0;
+       ao_ee_dump_config();
        ao_mutex_get(&ao_flash_mutex); {
                ao_flash_fill(FLASH_CONFIG_BLOCK);
                memcpy(buf, ao_flash_data, len);
@@ -480,9 +507,29 @@ flash_store(void) __reentrant
        ao_ee_flush();
 }
 
+static void
+flash_status(void) __reentrant
+{
+       uint8_t status;
+
+       ao_flash_setup();
+       ao_mutex_get(&ao_flash_mutex); {
+               status = ao_flash_read_status();
+               printf ("Flash status: 0x%02x\n", status);
+               printf ("Flash block shift: %d\n", FLASH_BLOCK_SHIFT);
+               printf ("Flash block size: %d\n", FLASH_BLOCK_SIZE);
+               printf ("Flash block mask: %d\n", FLASH_BLOCK_MASK);
+               printf ("Flash device size: %ld\n", FLASH_DEVICE_SIZE);
+               printf ("Flash data size: %ld\n", FLASH_DATA_SIZE);
+               printf ("Flash config block: %d\n", FLASH_CONFIG_BLOCK);
+       } ao_mutex_put(&ao_flash_mutex);
+       ao_ee_dump_config();
+}
+
 __code struct ao_cmds ao_flash_cmds[] = {
        { 'e', flash_dump,      "e <block>                          Dump a block of flash data" },
        { 'w', flash_store,     "w <block> <start> <len> <data> ... Write data to flash" },
+       { 'f', flash_status,    "f                                  Show flash status register" },
        { 0,   flash_store, NULL },
 };