//Перевод ESP8266 в состояние RESET.
static FFaza FazaReset()
{
enum {SBUF_LEN = 100};
static char rep = 0;
int i;
u32 j, j1;
if (ApbClkState(concat(RCC_APB_UART, nUART_esp))) UartStop();
Shutdown(1);
Pclr(PIN_ESP_RST);
LogsCR(COL_FAZA S_ESP8266 ": Reset.");
IdleBegin(IDLE_READY_ESP);
OsTaskDelay(ms2tkt(500));
ILivePing(ILIVE_ESP);
InitVars();
EspConfigMdf(1 << CFGMDF_apList);
cntRestarts = N_RESTART + 1;
for (i = 1; ; OsTaskDelay(ms2tkt(100))) {
ConsoleICmdFull(0);
netConfigMdfLoc |= j = AtomicBicI(&netConfigMdf,
1 << CFGMDF_apList | 1 << CFGMDF_apPower | 1 << CFGMDF_proxy | 1 << CFGMDF_term | 1 << CFGMDF_sntp | 1 << CFGMDF_weather)
& (1 << CFGMDF_apList | 1 << CFGMDF_apPower | 1 << CFGMDF_proxy | 1 << CFGMDF_term | 1 << CFGMDF_sntp | 1 << CFGMDF_weather);
if (!j) continue;
if (WifiCfgReadTest()) break;
if (!i) continue;
Pclr(PIN_ESP_RST);
LogsCR(COL_FAZA S_ESP8266 ": Off.");
i = 0;
}
IdleEnd(IDLE_READY_ESP);
j1 = UART_RATE_INIT;
if (!(i = rep)) {
rep = 1;
j1 = UART_RATE_BOOT;
}
UartStart(j1);
Pset(PIN_ESP_RST);
if (!--i) return (FFaza)FazaInit;
#if LOG_ESP && LOG_ESP_IO
char sbuf[SBUF_LEN];
static char const split[] = PREFIX_BOOT " ----------------------------------------";
LogsCR(split);
#endif
uint c, cc = 0, i0, i1, n = 0;
for (j1 = sysTimer, i0 = inpR; ; ) {
i1 = inpW;
while (i0 != i1) {
c = inpBuf[i0];
if (++i0 >= sizeof(inpBuf)) i0 = 0;
if (c != '\n' && c != '\r') {
if (c < ' ' || c >= 127) n = SBUF_LEN + 2;
if (n >= SBUF_LEN + 2) continue;
if (n >= SBUF_LEN) n = SBUF_LEN + 1;
else {
#if LOG_ESP && LOG_ESP_IO
sbuf[n] = c;
#endif
n++;
}
continue;
}
if (c != cc && cc) {
cc = 0;
continue;
}
cc = c;
if (IN_RANGE(n, 1, SBUF_LEN + 1)) {
#if LOG_ESP && LOG_ESP_IO
if (!i) LogsCR(PREFIX_BOOT ":");
char const *s = "";
if (n == SBUF_LEN + 1) {
s = "...";
n--;
}
LogCR(PREFIX_BOOT ": \"" COL_NAVY "%.*s" COL_GRAY "\"%s", n, sbuf, s);
#endif
i = 1;
} else i >>= 1;
n = 0;
}
j = sysTimer;
if (i >= 0) if ((s32)(j - rxLastTime) >= (s32)ms2tkt(TIME_SIL_RDY)) break;
if (j - j1 >= ms2tkt(TIME_FW_START)) {
EspErrs(ertToutBoot);
return (FFaza)FailFazes;
}
OsFlagPendReset(&espEv, ms2tkt(10));
}
#if LOG_ESP && LOG_ESP_IO
LogsCR(split);
#endif
return (FFaza)FazaReset;
}