Fixed strange SPI flash API error. Added word_of_aligned_array.

This commit is contained in:
Vowstar 2015-05-05 23:59:30 +08:00 committed by Orgmar
parent 32e9ac204a
commit 749e71d9cb
2 changed files with 16 additions and 1 deletions

View File

@ -396,11 +396,25 @@ uint8_t byte_of_aligned_array(const uint8_t *aligned_array, uint32_t index)
NODE_DBG("aligned_array is not 4-byte aligned.\n"); NODE_DBG("aligned_array is not 4-byte aligned.\n");
return 0; return 0;
} }
uint32_t v = ((uint32_t *)aligned_array)[ index / 4 ]; volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 4 ];
uint8_t *p = (uint8_t *) (&v); uint8_t *p = (uint8_t *) (&v);
return p[ (index % 4) ]; return p[ (index % 4) ];
} }
uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index)
{
if ( (((uint32_t)aligned_array) % 4) != 0 )
{
NODE_DBG("aligned_array is not 4-byte aligned.\n");
return 0;
}
volatile uint32_t v = ((uint32_t *)aligned_array)[ index / 2 ];
uint16_t *p = (uint16_t *) (&v);
return (index % 2 == 0) ? p[ 0 ] : p[ 1 ];
// return p[ (index % 2) ]; // -- why error???
// (byte_of_aligned_array((uint8_t *)aligned_array, index * 2 + 1) << 8) | byte_of_aligned_array((uint8_t *)aligned_array, index * 2);
}
// uint8_t flash_rom_get_checksum(void) // uint8_t flash_rom_get_checksum(void)
// { // {
// // SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR = flash_rom_getinfo(); // // SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR = flash_rom_getinfo();

View File

@ -107,6 +107,7 @@ bool flash_init_data_default(void);
bool flash_init_data_blank(void); bool flash_init_data_blank(void);
bool flash_self_destruct(void); bool flash_self_destruct(void);
uint8_t byte_of_aligned_array(const uint8_t* aligned_array, uint32_t index); uint8_t byte_of_aligned_array(const uint8_t* aligned_array, uint32_t index);
uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index);
// uint8_t flash_rom_get_checksum(void); // uint8_t flash_rom_get_checksum(void);
// uint8_t flash_rom_calc_checksum(void); // uint8_t flash_rom_calc_checksum(void);