mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-16 18:39:18 +08:00
52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
// Copyright (c) 2022-2023 Cesanta Software Limited
|
|
// All rights reserved
|
|
|
|
#include "hal.h"
|
|
#include "mongoose.h"
|
|
#include "net.h"
|
|
|
|
#define BLINK_PERIOD_MS 1000 // LED blinking period in millis
|
|
|
|
static volatile uint64_t s_ticks; // Milliseconds since boot
|
|
void SysTick_Handler(void) { // SyStick IRQ handler, triggered every 1ms
|
|
s_ticks++;
|
|
}
|
|
|
|
uint64_t mg_millis(void) { // Let Mongoose use our uptime function
|
|
return s_ticks; // Return number of milliseconds since boot
|
|
}
|
|
|
|
void mg_random(void *buf, size_t len) { // Use on-board RNG
|
|
for (size_t n = 0; n < len; n += sizeof(uint32_t)) {
|
|
uint32_t r = rng_read();
|
|
memcpy((char *) buf + n, &r, n + sizeof(r) > len ? len - n : sizeof(r));
|
|
}
|
|
}
|
|
|
|
static void timer_fn(void *arg) {
|
|
gpio_toggle(LED); // Blink LED
|
|
(void) arg;
|
|
}
|
|
|
|
int main(void) {
|
|
gpio_output(LED); // Setup blue LED
|
|
uart_init(UART_DEBUG, 115200); // Initialise debug printf
|
|
ethernet_init(); // Initialise ethernet pins
|
|
MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000));
|
|
|
|
struct mg_mgr mgr; // Initialise
|
|
mg_mgr_init(&mgr); // Mongoose event manager
|
|
mg_log_set(MG_LL_DEBUG); // Set log level
|
|
mg_timer_add(&mgr, BLINK_PERIOD_MS, MG_TIMER_REPEAT, timer_fn, NULL);
|
|
|
|
MG_INFO(("Initialising application..."));
|
|
web_init(&mgr);
|
|
|
|
MG_INFO(("Starting event loop"));
|
|
for (;;) {
|
|
mg_mgr_poll(&mgr, 0);
|
|
}
|
|
|
|
return 0;
|
|
}
|