Don't set ao_flash_setup_done until we're actually done.
authorKeith Packard <keithp@keithp.com>
Sun, 10 Jan 2010 04:42:57 +0000 (20:42 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 10 Jan 2010 04:42:57 +0000 (20:42 -0800)
Because we're accessing this variable outside of the mutex, we need to
make sure it isn't set until the data it covers has been initialized.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao_flash.c
src/at45db161d.h

index 0120382..3ea3e40 100644 (file)
@@ -169,6 +169,7 @@ static __pdata uint8_t  ao_flash_write_pending;
 static __pdata uint8_t ao_flash_setup_done;
 static __data uint32_t ao_flash_device_size;
 static __data uint8_t  ao_flash_block_shift;
+static __data uint16_t ao_flash_block_size;
 
 static void
 ao_flash_setup(void)
@@ -183,7 +184,6 @@ ao_flash_setup(void)
                ao_mutex_put(&ao_flash_mutex);
                return;
        }
-       ao_flash_setup_done = 1;
 
        /* On first use, check to see if the flash chip has
         * been programmed to use 512 byte pages. If not, do so.
@@ -238,6 +238,8 @@ ao_flash_setup(void)
        default:
                ao_panic(AO_PANIC_FLASH);
        }
+       ao_flash_block_size = 1 << ao_flash_block_shift;
+       ao_flash_setup_done = 1;
        ao_mutex_put(&ao_flash_mutex);
 }
 
index 6686973..8b72e64 100644 (file)
@@ -28,7 +28,7 @@
 
 #define FLASH_BLOCK_SIZE_MAX   512
 #define FLASH_BLOCK_SHIFT      (ao_flash_block_shift)
-#define FLASH_BLOCK_SIZE       (1 << FLASH_BLOCK_SHIFT)
+#define FLASH_BLOCK_SIZE       (ao_flash_block_size)
 #define FLASH_BLOCK_MASK       (FLASH_BLOCK_SIZE - 1)
 #define FLASH_DEVICE_SIZE      (ao_flash_device_size)
 #define FLASH_DATA_SIZE                (FLASH_DEVICE_SIZE - (uint32_t) FLASH_BLOCK_SIZE)