From 0420b6d72f0bf8eae78ccca3e57ac5014cc4bc88 Mon Sep 17 00:00:00 2001 From: HuangRui Date: Fri, 2 Jan 2015 17:56:34 +0800 Subject: [PATCH] Add definition of NODE_STORE_TYPEDEF_ATTR and NODE_STORE_ATTR. --- app/include/user_config.h | 3 ++- app/platform/flash_api.c | 26 +++++++------------------- app/platform/flash_api.h | 3 ++- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/app/include/user_config.h b/app/include/user_config.h index 9f4512c7..e0c04807 100644 --- a/app/include/user_config.h +++ b/app/include/user_config.h @@ -35,7 +35,8 @@ #define NODE_ERR #endif /* NODE_ERROR */ -#define NODE_STORE_ATTR __attribute__((aligned(4),packed)) +#define NODE_STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed)) +#define NODE_STORE_ATTR __attribute__((aligned(4))) #define CLIENT_SSL_ENABLE #define GPIO_INTERRUPT_ENABLE diff --git a/app/platform/flash_api.c b/app/platform/flash_api.c index 53f95af1..7a85e5bf 100644 --- a/app/platform/flash_api.c +++ b/app/platform/flash_api.c @@ -7,12 +7,10 @@ #include "flash_api.h" #include "spi_flash.h" -#include "c_stdio.h" - SPIFlashInfo *ICACHE_FLASH_ATTR flash_get_info(void) -{ - static SPIFlashInfo spi_flash_info __attribute__((aligned(4))); +{ + static SPIFlashInfo spi_flash_info NODE_STORE_ATTR; static bool is_spi_flash_info_initialized = false; // Make the code more fast if (!is_spi_flash_info_initialized) @@ -20,7 +18,8 @@ flash_get_info(void) SPIRead(0, &spi_flash_info, sizeof(spi_flash_info)); is_spi_flash_info_initialized = true; } - return &spi_flash_info; + // return (SPIFlashInfo *)(0x40200000); + return &spi_flash_info; } uint8_t ICACHE_FLASH_ATTR @@ -75,8 +74,7 @@ flash_set_size(uint8_t size) // Dangerous, here are dinosaur infested!!!!! // Reboot required!!! // If you don't know what you're doing, your nodemcu may turn into stone ... - c_printf("\nSet size!!! %d\n", size); - uint8_t data[SPI_FLASH_SEC_SIZE] __attribute__((aligned(4))); + uint8_t data[SPI_FLASH_SEC_SIZE] NODE_STORE_ATTR; SPIRead(0, data, sizeof(data)); SPIFlashInfo *p_spi_flash_info = (SPIFlashInfo *)(data); p_spi_flash_info->size = size; @@ -195,19 +193,9 @@ flash_init_data_default(void) // Dangerous, here are dinosaur infested!!!!! // Reboot required!!! // It will init system data to default! - uint8_t flash_init_data[128] __attribute__((aligned(4))) = - { - 0x05, 0x00, 0x04, 0x02, 0x05, 0x05, 0x05, 0x02, 0x05, 0x00, 0x04, 0x05, 0x05, 0x04, 0x05, 0x05, - 0x04, 0xFE, 0xFD, 0xFF, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xE1, 0x0A, 0xFF, 0xFF, 0xF8, 0x00, - 0xF8, 0xF8, 0x52, 0x4E, 0x4A, 0x44, 0x40, 0x38, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xE1, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x93, 0x43, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + SPIEraseSector((flash_get_sec_num() - 4)); - SPIWrite((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, flash_init_data, sizeof(flash_init_data)); + SPIWrite((flash_get_sec_num() - 4) * SPI_FLASH_SEC_SIZE, 0x10000 - SPI_FLASH_SEC_SIZE + (0), 128); return true; } diff --git a/app/platform/flash_api.h b/app/platform/flash_api.h index 6ba98120..a88e0504 100644 --- a/app/platform/flash_api.h +++ b/app/platform/flash_api.h @@ -2,6 +2,7 @@ #define __FLASH_API_H__ #include "ets_sys.h" #include "user_config.h" + typedef struct { uint8_t unknown0; @@ -28,7 +29,7 @@ typedef struct SIZE_16MBIT = 3, SIZE_32MBIT = 4, } size : 4; -} NODE_STORE_ATTR SPIFlashInfo; +} NODE_STORE_TYPEDEF_ATTR SPIFlashInfo; SPIFlashInfo *flash_get_info(void); uint8_t flash_get_size(void);