feat: Recovery-Download beim Booten
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "wm_include.h"
|
||||
#include "wm_efuse.h"
|
||||
#include "wm_watchdog.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/netif.h" /* struct netif is only forward-declared by wm_netif2.0.3.h */
|
||||
|
||||
@@ -324,3 +325,42 @@ void nl_wifi_status(nl_wifi_status_t *out)
|
||||
const char *nl_wifi_hostname(void) { return s_hostname; }
|
||||
|
||||
void nl_wifi_mac(uint8_t mac[6]) { memcpy(mac, s_mac, 6); }
|
||||
|
||||
/* --- boot recovery: join a station directly, ahead of nl_wifi_start()/nl_wifi_sm --- */
|
||||
|
||||
static volatile bool s_recovery_join_done;
|
||||
static volatile bool s_recovery_join_ok;
|
||||
|
||||
static void recovery_join_event(u8 status)
|
||||
{
|
||||
if (status == NETIF_IP_NET_UP) {
|
||||
s_recovery_join_ok = true;
|
||||
s_recovery_join_done = true;
|
||||
} else if (status == NETIF_WIFI_JOIN_FAILED) {
|
||||
s_recovery_join_done = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool nl_wifi_join_blocking(const char *ssid, const char *pass, uint32_t timeout_ms)
|
||||
{
|
||||
uint32_t waited = 0;
|
||||
|
||||
s_recovery_join_done = false;
|
||||
s_recovery_join_ok = false;
|
||||
tls_netif_add_status_event(recovery_join_event);
|
||||
if (tls_wifi_connect((u8 *)ssid, (u8)strlen(ssid), (u8 *)pass, (u8)strlen(pass)) != WM_SUCCESS) {
|
||||
tls_netif_remove_status_event(recovery_join_event);
|
||||
return false;
|
||||
}
|
||||
while (!s_recovery_join_done && waited < timeout_ms) {
|
||||
tls_watchdog_clr(); /* boot phase: called before app_task's own heartbeat gate exists */
|
||||
tls_os_time_delay(HZ / 10);
|
||||
waited += 100;
|
||||
}
|
||||
tls_netif_remove_status_event(recovery_join_event);
|
||||
if (!s_recovery_join_ok) {
|
||||
tls_wifi_disconnect(); /* cancel a stuck/timed-out join attempt */
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user