-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new baud and port commands to dynamic config
- Loading branch information
dacb
committed
Dec 18, 2014
1 parent
a4068b5
commit e0a9c8c
Showing
5 changed files
with
189 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "user_interface.h" | ||
#include "spi_flash.h" | ||
#include "ets_sys.h" | ||
#include "c_types.h" | ||
#include "flash_param.h" | ||
|
||
#define FLASH_PARAM_START_SECTOR 0x3C | ||
#define FLASH_PARAM_ADDR (SPI_FLASH_SEC_SIZE * FLASH_PARAM_START_SECTOR) | ||
|
||
static int flash_param_loaded = 0; | ||
static flash_param_t flash_param; | ||
|
||
void ICACHE_FLASH_ATTR flash_param_read(flash_param_t *flash_param) { | ||
spi_flash_read(FLASH_PARAM_ADDR, (uint32 *)flash_param, sizeof(flash_param_t)); | ||
} | ||
|
||
void ICACHE_FLASH_ATTR flash_param_write(flash_param_t *flash_param) { | ||
ETS_UART_INTR_DISABLE(); | ||
spi_flash_erase_sector(FLASH_PARAM_START_SECTOR); | ||
spi_flash_write(FLASH_PARAM_ADDR, (uint32 *) flash_param, sizeof(flash_param_t)); | ||
ETS_UART_INTR_ENABLE(); | ||
} | ||
|
||
flash_param_t *ICACHE_FLASH_ATTR flash_param_get(void) { | ||
if (!flash_param_loaded) { | ||
flash_param_read(&flash_param); | ||
flash_param_loaded = 1; | ||
} | ||
return &flash_param; | ||
} | ||
|
||
void ICACHE_FLASH_ATTR flash_param_set(void) { | ||
flash_param_write(&flash_param); | ||
flash_param_t tmp; | ||
flash_param_read(&tmp); | ||
if (memcmp(&tmp, &flash_param, sizeof(flash_param_t)) != 0) { | ||
DCE_FAIL("flash_param verify failed"); | ||
} | ||
} | ||
|
||
void ICACHE_FLASH_ATTR flash_param_init_defaults(void) { | ||
flash_param_t *flash_param = flash_param_get(); | ||
flash_param->magic = FLASH_PARAM_MAGIC; | ||
flash_param->version = FLASH_PARAM_VERSION; | ||
flash_param->baud = 115200; | ||
flash_param->port = 23; | ||
flash_param_set(); | ||
} | ||
|
||
flash_param_t* ICACHE_FLASH_ATTR flash_param_init(void) { | ||
flash_param_t *flash_param = flash_param_get(); | ||
if (flash_param->magic != FLASH_PARAM_MAGIC || flash_param->version != FLASH_PARAM_VERSION) { | ||
flash_param_init_defaults(); | ||
} | ||
return flash_param; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef __FLASH_PARAM_H__ | ||
#define __FLASH_PARAM_H__ | ||
|
||
#define FLASH_PARAM_MAGIC 8255 | ||
#define FLASH_PARAM_VERSION 3 | ||
|
||
typedef struct flash_param { | ||
uint32_t magic; | ||
uint32_t version; | ||
uint32_t baud; | ||
uint32_t port; | ||
} flash_param_t; | ||
|
||
flash_param_t *flash_param_get(void); | ||
|
||
#endif /* __FLASH_PARAM_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters