mirror of
https://github.com/nodemcu/nodemcu-firmware.git
synced 2025-01-16 20:52:57 +08:00
Fixed strange SPI flash API error. Added word_of_aligned_array.
This commit is contained in:
parent
32e9ac204a
commit
749e71d9cb
@ -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");
|
||||
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);
|
||||
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)
|
||||
// {
|
||||
// // SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR = flash_rom_getinfo();
|
||||
|
@ -107,6 +107,7 @@ bool flash_init_data_default(void);
|
||||
bool flash_init_data_blank(void);
|
||||
bool flash_self_destruct(void);
|
||||
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_calc_checksum(void);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user