From 437821746228aa947599130cc120076eeb937977 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 1 May 2015 16:23:15 +0100 Subject: [PATCH] Improve sensortag external flash power management: * Explicitly put in deep sleep on device startup * Verify that the flash has actually dropped to deep sleep * Update CLK pin to match the one used on the v1.2 sensortag Obsoletes and Closes #988 --- platform/srf06-cc26xx/sensortag/board.c | 3 + platform/srf06-cc26xx/sensortag/board.h | 2 +- platform/srf06-cc26xx/sensortag/ext-flash.c | 108 +++++++++++--------- platform/srf06-cc26xx/sensortag/ext-flash.h | 13 +++ 4 files changed, 79 insertions(+), 47 deletions(-) diff --git a/platform/srf06-cc26xx/sensortag/board.c b/platform/srf06-cc26xx/sensortag/board.c index f2322082a..458438ef1 100644 --- a/platform/srf06-cc26xx/sensortag/board.c +++ b/platform/srf06-cc26xx/sensortag/board.c @@ -142,6 +142,9 @@ board_init() buzzer_init(); + /* Make sure the external flash is in the lower power mode */ + ext_flash_init(); + lpm_register_module(&sensortag_module); /* Re-enable interrupt if initially enabled. */ diff --git a/platform/srf06-cc26xx/sensortag/board.h b/platform/srf06-cc26xx/sensortag/board.h index 00afb98f2..d2b8549ea 100644 --- a/platform/srf06-cc26xx/sensortag/board.h +++ b/platform/srf06-cc26xx/sensortag/board.h @@ -156,7 +156,7 @@ */ #define BOARD_IOID_FLASH_CS IOID_14 #define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS) -#define BOARD_SPI_CLK_FLASH IOID_11 +#define BOARD_IOID_SPI_CLK_FLASH IOID_17 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/platform/srf06-cc26xx/sensortag/ext-flash.c b/platform/srf06-cc26xx/sensortag/ext-flash.c index 83d2758a4..d896473d3 100644 --- a/platform/srf06-cc26xx/sensortag/ext-flash.c +++ b/platform/srf06-cc26xx/sensortag/ext-flash.c @@ -72,7 +72,7 @@ /* Part specific constants */ #define BLS_MANUFACTURER_ID 0xEF -#define BLS_DEVICE_ID 0x11 +#define BLS_DEVICE_ID 0x12 #define BLS_PROGRAM_PAGE_SIZE 256 #define BLS_ERASE_SECTOR_SIZE 4096 @@ -140,50 +140,8 @@ wait_ready(void) } /*---------------------------------------------------------------------------*/ /** - * \brief Put the device in power save mode. No access to data; only - * the status register is accessible. - * \return True when SPI transactions succeed - */ -static bool -power_down(void) -{ - uint8_t cmd; - bool success; - - cmd = BLS_CODE_DP; - select(); - success = board_spi_write(&cmd, sizeof(cmd)); - deselect(); - - return success; -} -/*---------------------------------------------------------------------------*/ -/** - * \brief Take device out of power save mode and prepare it for normal operation - * \return True if the command was written successfully - */ -static bool -power_standby(void) -{ - uint8_t cmd; - bool success; - - cmd = BLS_CODE_RDP; - select(); - success = board_spi_write(&cmd, sizeof(cmd)); - - if(success) { - success = wait_ready() == 0; - } - - deselect(); - - return success; -} -/*---------------------------------------------------------------------------*/ -/** - * Verify the flash part. - * @return True when successful. + * \brief Verify the flash part. + * \return True when successful. */ static bool verify_part(void) @@ -210,6 +168,57 @@ verify_part(void) return true; } /*---------------------------------------------------------------------------*/ +/** + * \brief Put the device in power save mode. No access to data; only + * the status register is accessible. + */ +static void +power_down(void) +{ + uint8_t cmd; + uint8_t i; + + cmd = BLS_CODE_DP; + select(); + board_spi_write(&cmd, sizeof(cmd)); + deselect(); + + i = 0; + while(i < 10) { + if(!verify_part()) { + /* Verify Part failed: Device is powered down */ + return; + } + i++; + } + + /* Should not be required */ + deselect(); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Take device out of power save mode and prepare it for normal operation + * \return True if the command was written successfully + */ +static bool +power_standby(void) +{ + uint8_t cmd; + bool success; + + cmd = BLS_CODE_RDP; + select(); + success = board_spi_write(&cmd, sizeof(cmd)); + + if(success) { + success = wait_ready() == 0; + } + + deselect(); + + return success; +} +/*---------------------------------------------------------------------------*/ /** * \brief Enable write. * \return Zero when successful. @@ -232,7 +241,7 @@ write_enable(void) bool ext_flash_open() { - board_spi_open(4000000, BOARD_SPI_CLK_FLASH); + board_spi_open(4000000, BOARD_IOID_SPI_CLK_FLASH); /* GPIO pin configuration */ ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_FLASH_CS); @@ -406,4 +415,11 @@ ext_flash_test(void) return ret; } /*---------------------------------------------------------------------------*/ +void +ext_flash_init() +{ + ext_flash_open(); + ext_flash_close(); +} +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/platform/srf06-cc26xx/sensortag/ext-flash.h b/platform/srf06-cc26xx/sensortag/ext-flash.h index ca2ef80ea..3038872cd 100644 --- a/platform/srf06-cc26xx/sensortag/ext-flash.h +++ b/platform/srf06-cc26xx/sensortag/ext-flash.h @@ -54,6 +54,8 @@ bool ext_flash_open(void); /** * \brief Close the storage driver + * + * This call will put the device in its lower power mode (power down). */ void ext_flash_close(void); @@ -94,6 +96,17 @@ bool ext_flash_write(size_t offset, size_t length, const uint8_t *buf); * \return True when successful. */ bool ext_flash_test(void); + +/** + * \brief Initialise the external flash + * + * This function will explicitly put the part in its lowest power mode + * (power-down). + * + * In order to perform any operation, the caller must first wake the device + * up by calling ext_flash_open() + */ +void ext_flash_init(void); /*---------------------------------------------------------------------------*/ #endif /* EXT_FLASH_H_ */ /*---------------------------------------------------------------------------*/