|
| 1 | +#include <stdlib.h> |
1 | 2 | #include "osapi.h" |
2 | 3 | #include "c_types.h" |
3 | 4 | #include "at.h" |
4 | 5 | #include "at_baseCmd.h" |
5 | 6 | #include "user_interface.h" |
6 | 7 | #include "at_version.h" |
7 | 8 | #include "version.h" |
| 9 | +#include "driver/uart_register.h" |
8 | 10 |
|
9 | 11 | /** @defgroup AT_BASECMD_Functions |
10 | 12 | * @{ |
11 | 13 | */ |
12 | 14 |
|
13 | 15 | extern BOOL echoFlag; |
| 16 | + |
| 17 | +typedef struct |
| 18 | +{ |
| 19 | + char flag; |
| 20 | + char reserve[3]; |
| 21 | +}updateFlagType; |
14 | 22 |
|
15 | 23 | /** |
16 | 24 | * @brief Execution commad of AT. |
@@ -69,13 +77,175 @@ at_exeCmdRst(uint8_t id) |
69 | 77 | void ICACHE_FLASH_ATTR |
70 | 78 | at_exeCmdGmr(uint8_t id) |
71 | 79 | { |
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; |
73 | 101 |
|
74 | | - os_sprintf(temp,"%04X%06X\r\n", |
75 | | - AT_VERSION,SDK_VERSION); |
| 102 | + os_sprintf(temp,"Is about to restart\r\n"); |
76 | 103 | 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)); |
77 | 246 | at_backOk; |
78 | 247 | } |
79 | 248 | /** |
80 | 249 | * @} |
81 | 250 | */ |
| 251 | + |
0 commit comments