From 05bb953830604721c9a49dd56256b86f3666b5ff Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 9 Jan 2010 20:42:57 -0800 Subject: [PATCH] Don't set ao_flash_setup_done until we're actually done. 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 --- src/ao_flash.c | 4 +++- src/at45db161d.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ao_flash.c b/src/ao_flash.c index 0120382d..3ea3e40b 100644 --- a/src/ao_flash.c +++ b/src/ao_flash.c @@ -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); } diff --git a/src/at45db161d.h b/src/at45db161d.h index 66869733..8b72e647 100644 --- a/src/at45db161d.h +++ b/src/at45db161d.h @@ -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) -- 2.30.2