mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-09 16:21:45 +00:00
Update Zephyr examples
This commit is contained in:
1 parent
9c60a1bc10
commit
d846e67ec1
28 files changed
+26641
-73
No files matched your search
@@ -50,14 +50,14 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
}
|
||||
}
|
||||
|
||||
// We have no valid system time(), and we need it for TLS. Implement it
|
||||
time_t time(time_t *tp) {
|
||||
time_t t = s_boot_timestamp + k_uptime_get() / 1000;
|
||||
// example system time()-like function
|
||||
time_t ourtime(time_t *tp) {
|
||||
time_t t = s_boot_timestamp + mg_millis() / 1000;
|
||||
if (tp != NULL) *tp = t;
|
||||
return t;
|
||||
}
|
||||
|
||||
// SNTP callback. Modifies s_boot_timestamp, to make time() correct
|
||||
// SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct
|
||||
static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (ev == MG_EV_SNTP_TIME) {
|
||||
int64_t t = *(int64_t *) ev_data;
|
||||
@@ -85,7 +85,23 @@ static void timer_fn(void *arg) {
|
||||
if (s_boot_timestamp < 9999) mg_sntp_request(s_sntp_conn);
|
||||
}
|
||||
|
||||
// Zephyr: Define a semaphore and network management callback to be able to wait
|
||||
// until our IP address is ready. The main function will start and block on this
|
||||
// semaphore until this event handler releases it when the network is ready
|
||||
K_SEM_DEFINE(run, 0, 1);
|
||||
|
||||
static void zeh(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
|
||||
struct net_if *iface) {
|
||||
if (mgmt_event == NET_EVENT_L4_CONNECTED) k_sem_give(&run);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// Zephyr: Register the network management callback and block on the semaphore
|
||||
struct net_mgmt_event_callback ncb;
|
||||
net_mgmt_init_event_callback(&ncb, zeh, NET_EVENT_L4_CONNECTED);
|
||||
net_mgmt_add_event_callback(&ncb);
|
||||
k_sem_take(&run, K_FOREVER);
|
||||
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
|
||||
mg_mgr_init(&mgr);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user