Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit dc3ca30

Browse files
author
atdeve
committed
add uart baud, feature auto connect when discon in transparent mode, fix several busys bug
1 parent e6930b6 commit dc3ca30

10 files changed

Lines changed: 612 additions & 110 deletions

File tree

at/include/at.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//#define at_busyTaskPrio 1
77
//#define at_busyTaskQueueLen 4
88

9+
//#define ali
910

1011
#define at_recvTaskPrio 0
1112
#define at_recvTaskQueueLen 64
@@ -45,6 +46,12 @@ typedef struct
4546
void (*at_exeCmd)(uint8_t id);
4647
}at_funcationType;
4748

49+
typedef struct
50+
{
51+
uint32_t baud;
52+
uint32_t saved;
53+
}at_uartType;
54+
4855
void at_init(void);
4956
void at_cmdProcess(uint8_t *pAtRcvData);
5057

at/include/at_version.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define AT_VERSION_main 0x00
55
#define AT_VERSION_sub 0x19
66

7-
#define AT_VERSION (AT_VERSION_main << 8 | AT_VERSION_sub)
7+
//#define AT_VERSION (AT_VERSION_main << 8 | AT_VERSION_sub)
8+
#define AT_VERSION "AT 0020"
89

910
#endif

at/user/at_baseCmd.c

Lines changed: 173 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
#include <stdlib.h>
12
#include "osapi.h"
23
#include "c_types.h"
34
#include "at.h"
45
#include "at_baseCmd.h"
56
#include "user_interface.h"
67
#include "at_version.h"
78
#include "version.h"
9+
#include "driver/uart_register.h"
810

911
/** @defgroup AT_BASECMD_Functions
1012
* @{
1113
*/
1214

1315
extern BOOL echoFlag;
16+
17+
typedef struct
18+
{
19+
char flag;
20+
char reserve[3];
21+
}updateFlagType;
1422

1523
/**
1624
* @brief Execution commad of AT.
@@ -69,13 +77,175 @@ at_exeCmdRst(uint8_t id)
6977
void ICACHE_FLASH_ATTR
7078
at_exeCmdGmr(uint8_t id)
7179
{
72-
char temp[128];
80+
char temp[64];
81+
82+
os_sprintf(temp, AT_VERSION);
83+
uart0_sendStr(temp);
84+
os_sprintf(temp,"%06X\r\n", SDK_VERSION);
85+
uart0_sendStr(temp);
86+
at_backOk;
87+
}
88+
89+
#ifdef ali
90+
//#define upFlagSector 60
91+
/**
92+
* @brief Through uart to update
93+
* @param id: commad id number
94+
* @retval None
95+
*/
96+
void ICACHE_FLASH_ATTR
97+
at_exeCmdUpdate(uint8_t id)
98+
{
99+
char temp[32];
100+
updateFlagType upFlag;
73101

74-
os_sprintf(temp,"%04X%06X\r\n",
75-
AT_VERSION,SDK_VERSION);
102+
os_sprintf(temp,"Is about to restart\r\n");
76103
uart0_sendStr(temp);
104+
105+
spi_flash_read(60 * 4096, (uint32 *)&upFlag, sizeof(updateFlagType));
106+
// os_printf("%X\r\n",upFlag.flag);
107+
// os_printf("%X\r\n",upFlag.reserve[0]);
108+
// os_printf("%X\r\n",upFlag.reserve[1]);
109+
// os_printf("%X\r\n",upFlag.reserve[2]);
110+
upFlag.flag = 1;
111+
spi_flash_erase_sector(60);
112+
spi_flash_write(60 * 4096, (uint32 *)&upFlag, sizeof(updateFlagType));
113+
// spi_flash_read(60 * 4096, (uint32 *)&upFlag, sizeof(updateFlagType));
114+
// os_printf("%X\r\n",upFlag.flag);
115+
// os_printf("%X\r\n",upFlag.reserve[0]);
116+
// os_printf("%X\r\n",upFlag.reserve[1]);
117+
// os_printf("%X\r\n",upFlag.reserve[2]);
118+
os_delay_us(10000);
119+
system_reboot_from(0x00);
120+
}
121+
#endif
122+
123+
#ifdef ali
124+
void ICACHE_FLASH_ATTR
125+
at_setupCmdMpinfo(uint8_t id, char *pPara)
126+
{
127+
uint32 t;
128+
char temp[32];
129+
130+
pPara++;
131+
t = strtol(pPara,NULL,16);
132+
os_sprintf(temp,"1st:%x\r\n",t);
133+
uart0_sendStr(temp);
134+
135+
pPara = strchr(pPara, ',');
136+
137+
pPara++;
138+
t = strtol(pPara,NULL,16);
139+
os_sprintf(temp,"2nd:%x\r\n",t);
140+
uart0_sendStr(temp);
141+
}
142+
#endif
143+
144+
145+
#define ESP_PARAM_START_SEC 0x3C
146+
147+
#define ESP_PARAM_SAVE_0 1
148+
#define ESP_PARAM_SAVE_1 2
149+
#define ESP_PARAM_FLAG 3
150+
struct esp_platform_sec_flag_param {
151+
uint8 flag;
152+
uint8 pad[3];
153+
};
154+
155+
/******************************************************************************
156+
* FunctionName : user_esp_platform_load_param
157+
* Description : load parameter from flash, toggle use two sector by flag value.
158+
* Parameters : param--the parame point which write the flash
159+
* Returns : none
160+
*******************************************************************************/
161+
void ICACHE_FLASH_ATTR
162+
user_esp_platform_load_param(void *param, uint16 len)
163+
{
164+
struct esp_platform_sec_flag_param flag;
165+
166+
spi_flash_read((ESP_PARAM_START_SEC + ESP_PARAM_FLAG) * SPI_FLASH_SEC_SIZE,
167+
(uint32 *)&flag, sizeof(struct esp_platform_sec_flag_param));
168+
169+
if (flag.flag == 0) {
170+
spi_flash_read((ESP_PARAM_START_SEC + ESP_PARAM_SAVE_0) * SPI_FLASH_SEC_SIZE,
171+
(uint32 *)param, len);
172+
} else {
173+
spi_flash_read((ESP_PARAM_START_SEC + ESP_PARAM_SAVE_1) * SPI_FLASH_SEC_SIZE,
174+
(uint32 *)param, len);
175+
}
176+
}
177+
178+
/******************************************************************************
179+
* FunctionName : user_esp_platform_save_param
180+
* Description : toggle save param to two sector by flag value,
181+
* : protect write and erase data while power off.
182+
* Parameters : param -- the parame point which write the flash
183+
* Returns : none
184+
*******************************************************************************/
185+
void ICACHE_FLASH_ATTR
186+
user_esp_platform_save_param(void *param, uint16 len)
187+
{
188+
struct esp_platform_sec_flag_param flag;
189+
190+
spi_flash_read((ESP_PARAM_START_SEC + ESP_PARAM_FLAG) * SPI_FLASH_SEC_SIZE,
191+
(uint32 *)&flag, sizeof(struct esp_platform_sec_flag_param));
192+
193+
if (flag.flag == 0) {
194+
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_SAVE_1);
195+
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_SAVE_1) * SPI_FLASH_SEC_SIZE,
196+
(uint32 *)param, len);
197+
flag.flag = 1;
198+
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_FLAG);
199+
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_FLAG) * SPI_FLASH_SEC_SIZE,
200+
(uint32 *)&flag, sizeof(struct esp_platform_sec_flag_param));
201+
} else {
202+
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_SAVE_0);
203+
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_SAVE_0) * SPI_FLASH_SEC_SIZE,
204+
(uint32 *)param, len);
205+
flag.flag = 0;
206+
spi_flash_erase_sector(ESP_PARAM_START_SEC + ESP_PARAM_FLAG);
207+
spi_flash_write((ESP_PARAM_START_SEC + ESP_PARAM_FLAG) * SPI_FLASH_SEC_SIZE,
208+
(uint32 *)&flag, sizeof(struct esp_platform_sec_flag_param));
209+
}
210+
}
211+
212+
213+
void ICACHE_FLASH_ATTR
214+
at_setupCmdIpr(uint8_t id, char *pPara)
215+
{
216+
at_uartType tempUart;
217+
218+
pPara++;
219+
tempUart.baud = atoi(pPara);
220+
if((tempUart.baud>(UART_CLK_FREQ / 16))||(tempUart.baud == 0))
221+
{
222+
at_backError;
223+
return;
224+
}
225+
while(TRUE)
226+
{
227+
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(0)) & (UART_TXFIFO_CNT<<UART_TXFIFO_CNT_S);
228+
if((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) == 0)
229+
{
230+
break;
231+
}
232+
}
233+
os_delay_us(10000);
234+
uart_div_modify(0, UART_CLK_FREQ / tempUart.baud);
235+
tempUart.saved = 1;
236+
user_esp_platform_save_param((uint32 *)&tempUart, sizeof(at_uartType));
237+
// spi_flash_read(60 * 4096, (uint32 *)&upFlag, sizeof(updateFlagType));
238+
// // os_printf("%X\r\n",upFlag.flag);
239+
// // os_printf("%X\r\n",upFlag.reserve[0]);
240+
// // os_printf("%X\r\n",upFlag.reserve[1]);
241+
// // os_printf("%X\r\n",upFlag.reserve[2]);
242+
// upFlag.flag = 1;
243+
// spi_flash_erase_sector(60);
244+
// spi_flash_write(60 * 4096, (uint32 *)&upFlag, sizeof(updateFlagType));
245+
// // spi_flash_read(60 * 4096, (uint32 *)&upFlag, sizeof(updateFlagType));
77246
at_backOk;
78247
}
79248
/**
80249
* @}
81250
*/
251+

at/user/at_baseCmd.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ void at_exeCmdNull(uint8_t id);
55
void at_setupCmdE(uint8_t id, char *pPara);
66
void at_exeCmdRst(uint8_t id);
77
void at_exeCmdGmr(uint8_t id);
8-
8+
#ifdef ali
9+
void at_exeCmdUpdate(uint8_t id);
10+
#endif
11+
void at_setupCmdIpr(uint8_t id, char *pPara);
12+
#ifdef ali
13+
void at_setupCmdMpinfo(uint8_t id, char *pPara);
14+
#endif
915
#endif

at/user/at_cmd.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
#include "at_ipCmd.h"
77
#include "at_baseCmd.h"
88

9-
#define at_cmdNum 20
9+
#define at_cmdNum 25
1010

1111
at_funcationType at_fun[at_cmdNum]={
1212
{NULL, 0, NULL, NULL, NULL, at_exeCmdNull},
1313
{"E", 1, NULL, NULL, at_setupCmdE, NULL},
1414
{"+RST", 4, NULL, NULL, NULL, at_exeCmdRst},
1515
{"+GMR", 4, NULL, NULL, NULL, at_exeCmdGmr},
16+
{"+IPR", 4, NULL, NULL, at_setupCmdIpr, NULL},
17+
#ifdef ali
18+
{"+UPDATE", 7, NULL, NULL, NULL, at_exeCmdUpdate},
19+
#endif
1620
{"+CWMODE", 7, at_testCmdCwmode, at_queryCmdCwmode, at_setupCmdCwmode, NULL},
1721
{"+CWJAP", 6, NULL, at_queryCmdCwjap, at_setupCmdCwjap, NULL},
1822
{"+CWLAP", 6, NULL, NULL, at_setupCmdCwlap, at_exeCmdCwlap},
@@ -28,7 +32,11 @@ at_funcationType at_fun[at_cmdNum]={
2832
{"+CIPSERVER", 10, NULL, NULL,at_setupCmdCipserver, NULL},
2933
{"+CIPMODE", 8, NULL, at_queryCmdCipmode, at_setupCmdCipmode, NULL},
3034
{"+CIPSTO", 7, NULL, at_queryCmdCipsto, at_setupCmdCipsto, NULL},
31-
{"+CIUPDATE", 9, NULL, NULL, NULL, at_exeCmdUpdate}
35+
{"+CIUPDATE", 9, NULL, NULL, NULL, at_exeCmdCiupdate},
36+
{"+CIPING", 7, NULL, NULL, NULL, at_exeCmdCiping},
37+
#ifdef ali
38+
{"+MPINFO", 7, NULL, NULL, at_setupCmdMpinfo, NULL}
39+
#endif
3240
};
3341

3442
#endif

0 commit comments

Comments
 (0)