mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-18 03:30:31 +00:00
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
This commit is contained in:
parent
cf99160706
commit
4378217462
@ -142,6 +142,9 @@ board_init()
|
|||||||
|
|
||||||
buzzer_init();
|
buzzer_init();
|
||||||
|
|
||||||
|
/* Make sure the external flash is in the lower power mode */
|
||||||
|
ext_flash_init();
|
||||||
|
|
||||||
lpm_register_module(&sensortag_module);
|
lpm_register_module(&sensortag_module);
|
||||||
|
|
||||||
/* Re-enable interrupt if initially enabled. */
|
/* Re-enable interrupt if initially enabled. */
|
||||||
|
@ -156,7 +156,7 @@
|
|||||||
*/
|
*/
|
||||||
#define BOARD_IOID_FLASH_CS IOID_14
|
#define BOARD_IOID_FLASH_CS IOID_14
|
||||||
#define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS)
|
#define BOARD_FLASH_CS (1 << BOARD_IOID_FLASH_CS)
|
||||||
#define BOARD_SPI_CLK_FLASH IOID_11
|
#define BOARD_IOID_SPI_CLK_FLASH IOID_17
|
||||||
/** @} */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
/* Part specific constants */
|
/* Part specific constants */
|
||||||
|
|
||||||
#define BLS_MANUFACTURER_ID 0xEF
|
#define BLS_MANUFACTURER_ID 0xEF
|
||||||
#define BLS_DEVICE_ID 0x11
|
#define BLS_DEVICE_ID 0x12
|
||||||
|
|
||||||
#define BLS_PROGRAM_PAGE_SIZE 256
|
#define BLS_PROGRAM_PAGE_SIZE 256
|
||||||
#define BLS_ERASE_SECTOR_SIZE 4096
|
#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
|
* \brief Verify the flash part.
|
||||||
* the status register is accessible.
|
* \return True when successful.
|
||||||
* \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.
|
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
verify_part(void)
|
verify_part(void)
|
||||||
@ -210,6 +168,57 @@ verify_part(void)
|
|||||||
return true;
|
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.
|
* \brief Enable write.
|
||||||
* \return Zero when successful.
|
* \return Zero when successful.
|
||||||
@ -232,7 +241,7 @@ write_enable(void)
|
|||||||
bool
|
bool
|
||||||
ext_flash_open()
|
ext_flash_open()
|
||||||
{
|
{
|
||||||
board_spi_open(4000000, BOARD_SPI_CLK_FLASH);
|
board_spi_open(4000000, BOARD_IOID_SPI_CLK_FLASH);
|
||||||
|
|
||||||
/* GPIO pin configuration */
|
/* GPIO pin configuration */
|
||||||
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_FLASH_CS);
|
ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_FLASH_CS);
|
||||||
@ -406,4 +415,11 @@ ext_flash_test(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ext_flash_init()
|
||||||
|
{
|
||||||
|
ext_flash_open();
|
||||||
|
ext_flash_close();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -54,6 +54,8 @@ bool ext_flash_open(void);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Close the storage driver
|
* \brief Close the storage driver
|
||||||
|
*
|
||||||
|
* This call will put the device in its lower power mode (power down).
|
||||||
*/
|
*/
|
||||||
void ext_flash_close(void);
|
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.
|
* \return True when successful.
|
||||||
*/
|
*/
|
||||||
bool ext_flash_test(void);
|
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_ */
|
#endif /* EXT_FLASH_H_ */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user