2021-05-11 16:12:06 +08:00
|
|
|
// Copyright (c) 2021 Cesanta Software Limited
|
|
|
|
// All rights reserved
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
#include "mongoose.h"
|
|
|
|
|
2021-05-12 15:43:34 +08:00
|
|
|
static const char *s_debug_level = "2";
|
|
|
|
static const char *s_listening_address = "http://0.0.0.0:80";
|
2021-05-11 16:12:06 +08:00
|
|
|
|
|
|
|
// Event handler for the listening connection.
|
2021-05-12 15:43:34 +08:00
|
|
|
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|
|
|
if (ev == MG_EV_HTTP_MSG) {
|
|
|
|
mg_http_reply(c, 200, "", "hello, %s!\n", "world");
|
|
|
|
}
|
|
|
|
(void) fn_data;
|
|
|
|
(void) ev_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void server(void *args) {
|
|
|
|
struct mg_mgr mgr;
|
|
|
|
mg_log_set(s_debug_level);
|
|
|
|
mg_mgr_init(&mgr);
|
|
|
|
mg_http_listen(&mgr, s_listening_address, cb, &mgr); // Web listener
|
|
|
|
while (args == NULL) mg_mgr_poll(&mgr, 1000); // Infinite event loop
|
|
|
|
mg_mgr_free(&mgr); // Unreachable
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blinker(void *args) {
|
2021-05-13 22:05:09 +08:00
|
|
|
uint16_t pin = ((char *) args)[0] == '1' ? LED2 : LED3;
|
2021-05-14 05:03:46 +08:00
|
|
|
int ms = pin == LED2 ? 750 : 1130;
|
2021-05-13 22:05:09 +08:00
|
|
|
for (;;) {
|
|
|
|
gpio_toggle(pin);
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(ms));
|
2021-05-14 05:03:46 +08:00
|
|
|
LOG(LL_INFO, ("blink %s", (char *) args));
|
2021-05-12 15:43:34 +08:00
|
|
|
}
|
2021-05-11 16:12:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
init_hardware();
|
2021-05-14 05:03:46 +08:00
|
|
|
#ifdef SEMIHOSTING
|
|
|
|
extern void initialise_monitor_handles(void);
|
|
|
|
initialise_monitor_handles();
|
|
|
|
#endif
|
2021-05-13 21:56:14 +08:00
|
|
|
xTaskCreate(server, "server", 4096, NULL, configMAX_PRIORITIES - 1, NULL);
|
2021-05-14 05:03:46 +08:00
|
|
|
xTaskCreate(blinker, "blinker", 256, "1", configMAX_PRIORITIES - 1, NULL);
|
|
|
|
xTaskCreate(blinker, "blinker", 256, "2", configMAX_PRIORITIES - 1, NULL);
|
2021-05-12 03:44:14 +08:00
|
|
|
vTaskStartScheduler(); // This blocks
|
|
|
|
return 0; // Unreachable
|
2021-05-11 16:12:06 +08:00
|
|
|
}
|
2021-05-12 15:43:34 +08:00
|
|
|
|
|
|
|
// Stubs for FreeRTOS-TCP network interface
|
2021-05-14 05:03:46 +08:00
|
|
|
uint32_t ulApplicationGetNextSequenceNumber(uint32_t a, uint16_t b, uint32_t c,
|
|
|
|
uint16_t d) {
|
|
|
|
return a ^ b ^ c ^ d;
|
|
|
|
}
|
|
|
|
BaseType_t xApplicationGetRandomNumber(uint32_t *p) {
|
|
|
|
*p = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
uint32_t SystemCoreClock = 216000000;
|
|
|
|
uint32_t HAL_GetTick(void) {
|
|
|
|
return 250;
|
|
|
|
}
|
|
|
|
uint32_t HAL_RCC_GetHCLKFreq(void) {
|
|
|
|
return SystemCoreClock;
|
2021-05-12 15:43:34 +08:00
|
|
|
}
|