Skip to content

Commit

Permalink
tested BAUD and PORT
Browse files Browse the repository at this point in the history
  • Loading branch information
dacb committed Dec 19, 2014
1 parent e0a9c8c commit 6e90eac
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
Binary file modified bin/eagle.app.v6.flash.bin
Binary file not shown.
Binary file modified bin/eagle.app.v6.irom0text.bin
Binary file not shown.
22 changes: 18 additions & 4 deletions user/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void config_execute(void) {
mode = wifi_get_opmode();
if (mode != STATIONAP_MODE) {
wifi_set_opmode(STATIONAP_MODE);
os_delay_us(10000);
system_restart();
}

Expand Down Expand Up @@ -199,8 +200,10 @@ void config_cmd_baud(struct espconn *conn, uint8_t argc, char *argv[]) {
os_delay_us(10000);
uart_div_modify(0, UART_CLK_FREQ / baud);
flash_param->baud = baud;
flash_param_set();
espconn_sent(conn, MSG_OK, strlen(MSG_OK));
if (flash_param_set())
espconn_sent(conn, MSG_OK, strlen(MSG_OK));
else
espconn_sent(conn, MSG_ERROR, strlen(MSG_ERROR));
}
}
}
Expand All @@ -223,14 +226,24 @@ void config_cmd_port(struct espconn *conn, uint8_t argc, char *argv[]) {
} else {
if (port != flash_param->port) {
flash_param->port = port;
flash_param_set();
espconn_sent(conn, MSG_OK, strlen(MSG_OK));
if (flash_param_set())
espconn_sent(conn, MSG_OK, strlen(MSG_OK));
else
espconn_sent(conn, MSG_ERROR, strlen(MSG_ERROR));
os_delay_us(10000);
system_restart();
} else {
espconn_sent(conn, MSG_OK, strlen(MSG_OK));
}
}
}
// debug
{
char buf[1024];
flash_param = flash_param_get();
os_sprintf(buf, "flash param:\n\tmagic\t%d\n\tversion\t%d\n\tbaud\t%d\n\tport\t%d\n", flash_param->magic, flash_param->version, flash_param->baud, flash_param->port);
espconn_sent(conn, buf, strlen(buf));
}
}

void config_cmd_mode(struct espconn *conn, uint8_t argc, char *argv[]) {
Expand All @@ -252,6 +265,7 @@ void config_cmd_mode(struct espconn *conn, uint8_t argc, char *argv[]) {
wifi_set_opmode(mode);
ETS_UART_INTR_ENABLE();
espconn_sent(conn, MSG_OK, strlen(MSG_OK));
os_delay_us(10000);
system_restart();
} else {
espconn_sent(conn, MSG_OK, strlen(MSG_OK));
Expand Down
8 changes: 8 additions & 0 deletions user/config_wifi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#undef STA_SSID
#define STA_SSID "root"
#undef STA_PASSWORD
#define STA_PASSWORD "conortimothy"
#undef AP_SSID
#define AP_SSID "toor"
#undef AP_PASSWORD
#define AP_PASSWORD "conortimothy"
11 changes: 6 additions & 5 deletions user/flash_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "flash_param.h"

#define FLASH_PARAM_START_SECTOR 0x3C
#define FLASH_PARAM_ADDR (SPI_FLASH_SEC_SIZE * FLASH_PARAM_START_SECTOR)
#define FLASH_PARAM_SECTOR (FLASH_PARAM_START_SECTOR + 0)
#define FLASH_PARAM_ADDR (SPI_FLASH_SEC_SIZE * FLASH_PARAM_SECTOR)

static int flash_param_loaded = 0;
static flash_param_t flash_param;
Expand All @@ -16,7 +17,7 @@ void ICACHE_FLASH_ATTR flash_param_read(flash_param_t *flash_param) {

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_erase_sector(FLASH_PARAM_SECTOR);
spi_flash_write(FLASH_PARAM_ADDR, (uint32 *) flash_param, sizeof(flash_param_t));
ETS_UART_INTR_ENABLE();
}
Expand All @@ -29,13 +30,14 @@ flash_param_t *ICACHE_FLASH_ATTR flash_param_get(void) {
return &flash_param;
}

void ICACHE_FLASH_ATTR flash_param_set(void) {
int 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");
return 0;
}
return 1;
}

void ICACHE_FLASH_ATTR flash_param_init_defaults(void) {
Expand All @@ -54,4 +56,3 @@ flash_param_t* ICACHE_FLASH_ATTR flash_param_init(void) {
}
return flash_param;
}

1 change: 1 addition & 0 deletions user/flash_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ typedef struct flash_param {
} flash_param_t;

flash_param_t *flash_param_get(void);
int flash_param_set(void);

#endif /* __FLASH_PARAM_H__ */
5 changes: 4 additions & 1 deletion user/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "task.h"

#include "server.h"
#include "config.h"
#include "flash_param.h"

os_event_t recvTaskQueue[recvTaskQueueLen];
Expand Down Expand Up @@ -64,7 +65,9 @@ void user_init(void)


#ifdef CONFIG_DYNAMIC
flash_param_t *flash_param = flash_param_get();
flash_param_t *flash_param;
flash_param_init();
flash_param = flash_param_get();
uart_init(flash_param->baud, BIT_RATE_115200);
#else
uart_init(BIT_RATE_115200, BIT_RATE_115200);
Expand Down

0 comments on commit 6e90eac

Please sign in to comment.