diff --git a/examples/rp2040/pico-w5500/main.c b/examples/rp2040/pico-w5500/main.c index c5c727bf..16e900a0 100644 --- a/examples/rp2040/pico-w5500/main.c +++ b/examples/rp2040/pico-w5500/main.c @@ -35,9 +35,9 @@ void mg_random(void *buf, size_t len) { static void timer_fn(void *arg) { gpio_put(PICO_DEFAULT_LED_PIN, - !gpio_get_out_level(PICO_DEFAULT_LED_PIN)); // Blink LED - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + !gpio_get_out_level(PICO_DEFAULT_LED_PIN)); // Blink LED + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); diff --git a/examples/stm32/nucleo-f429zi-freertos/main.c b/examples/stm32/nucleo-f429zi-freertos/main.c index 90cf9229..49dddf07 100644 --- a/examples/stm32/nucleo-f429zi-freertos/main.c +++ b/examples/stm32/nucleo-f429zi-freertos/main.c @@ -20,8 +20,8 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); @@ -43,7 +43,6 @@ static void ethernet_init(void) { RCC_AHB1ENR_ETHMACEN | RCC_AHB1ENR_ETHMACTXEN | RCC_AHB1ENR_ETHMACRXEN; } - static void server(void *args) { struct mg_mgr mgr; // Initialise Mongoose event manager mg_mgr_init(&mgr); // and attach it to the interface diff --git a/examples/stm32/nucleo-f429zi-make-baremetal-builtin/main.c b/examples/stm32/nucleo-f429zi-make-baremetal-builtin/main.c index f1b2457b..1ee4ac27 100644 --- a/examples/stm32/nucleo-f429zi-make-baremetal-builtin/main.c +++ b/examples/stm32/nucleo-f429zi-make-baremetal-builtin/main.c @@ -24,9 +24,9 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - gpio_toggle(LED); // Blink LED - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + gpio_toggle(LED); // Blink LED + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); diff --git a/examples/stm32/nucleo-f746zg-freertos/main.c b/examples/stm32/nucleo-f746zg-freertos/main.c index 90cf9229..49dddf07 100644 --- a/examples/stm32/nucleo-f746zg-freertos/main.c +++ b/examples/stm32/nucleo-f746zg-freertos/main.c @@ -20,8 +20,8 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); @@ -43,7 +43,6 @@ static void ethernet_init(void) { RCC_AHB1ENR_ETHMACEN | RCC_AHB1ENR_ETHMACTXEN | RCC_AHB1ENR_ETHMACRXEN; } - static void server(void *args) { struct mg_mgr mgr; // Initialise Mongoose event manager mg_mgr_init(&mgr); // and attach it to the interface diff --git a/examples/stm32/nucleo-f746zg-keil-baremetal/main.c b/examples/stm32/nucleo-f746zg-keil-baremetal/main.c index b2b4112a..1511c8cd 100644 --- a/examples/stm32/nucleo-f746zg-keil-baremetal/main.c +++ b/examples/stm32/nucleo-f746zg-keil-baremetal/main.c @@ -2,14 +2,14 @@ // All rights reserved #include "hal.h" -#include "mongoose.h" #include "main.h" +#include "mongoose.h" #include "net.h" #define BLINK_PERIOD_MS 1000 // LED blinking period in millis -uint64_t mg_millis(void) { // Let Mongoose use our uptime function - return (uint64_t)HAL_GetTick(); // Return number of milliseconds since boot +uint64_t mg_millis(void) { // Let Mongoose use our uptime function + return (uint64_t) HAL_GetTick(); // Return number of milliseconds since boot } void mg_random(void *buf, size_t len) { // Use on-board RNG @@ -22,9 +22,9 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); @@ -33,9 +33,9 @@ static void timer_fn(void *arg) { extern void mx_init(void); int main(void) { - mx_init(); // Setup clock and all peripherals configured in CubeMX - // Initialise random number generator - // Initialise ethernet pins + mx_init(); // Setup clock and all peripherals configured in CubeMX + // Initialise random number generator + // Initialise ethernet pins test_init(); // for internal testing purposes only MG_INFO(("Starting, CPU freq %g MHz", (double) SystemCoreClock / 1000000)); diff --git a/examples/stm32/nucleo-f746zg-keil-freertos/main.c b/examples/stm32/nucleo-f746zg-keil-freertos/main.c index 70e0b468..f56f1011 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos/main.c +++ b/examples/stm32/nucleo-f746zg-keil-freertos/main.c @@ -2,16 +2,17 @@ // All rights reserved #include "hal.h" -#include "mongoose.h" #include "main.h" +#include "mongoose.h" #include "net.h" #define BLINK_PERIOD_MS 1000 // LED blinking period in millis extern void xPortSysTickHandler(void); -void SysTick_Handler (void) { +void SysTick_Handler(void) { HAL_IncTick(); - // xPortSysTickHandler() must be called after vTaskStartScheduler() and mx_init() takes longer than 1ms + // xPortSysTickHandler() must be called after vTaskStartScheduler() and + // mx_init() takes longer than 1ms if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) xPortSysTickHandler(); } @@ -26,8 +27,8 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); @@ -63,7 +64,7 @@ static void server(void *args) { static void blinker(void *args) { for (;;) { - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED + HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED vTaskDelay(pdMS_TO_TICKS(BLINK_PERIOD_MS)); } (void) args; @@ -72,9 +73,9 @@ static void blinker(void *args) { extern void mx_init(void); int main(void) { - mx_init(); // Setup clock and all peripherals configured in CubeMX - // Initialise random number generator - // Initialise ethernet pins + mx_init(); // Setup clock and all peripherals configured in CubeMX + // Initialise random number generator + // Initialise ethernet pins // Start tasks. NOTE: stack sizes are in 32-bit words xTaskCreate(blinker, "blinker", 128, ":)", configMAX_PRIORITIES - 1, NULL); xTaskCreate(server, "server", 2048, 0, configMAX_PRIORITIES - 1, NULL); diff --git a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/main.c b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/main.c index 04b97498..0920a0f4 100644 --- a/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/main.c +++ b/examples/stm32/nucleo-f746zg-keil-freertos_cmsis2/main.c @@ -1,15 +1,14 @@ // Copyright (c) 2023 Cesanta Software Limited // All rights reserved +#include "cmsis_os2.h" #include "hal.h" -#include "mongoose.h" #include "main.h" +#include "mongoose.h" #include "net.h" -#include "cmsis_os2.h" #define BLINK_PERIOD_MS 1000 // LED blinking period in millis - void mg_random(void *buf, size_t len) { // Use on-board RNG extern RNG_HandleTypeDef hrng; for (size_t n = 0; n < len; n += sizeof(uint32_t)) { @@ -20,8 +19,8 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); @@ -57,7 +56,7 @@ static void server(void *args) { static void blinker(void *args) { for (;;) { - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED + HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED osDelay((osKernelGetTickFreq() * BLINK_PERIOD_MS) / 1000U); } (void) args; @@ -66,16 +65,17 @@ static void blinker(void *args) { extern void mx_init(void); int main(void) { - mx_init(); // Setup clock and all peripherals configured in CubeMX - // Initialise random number generator - // Initialise ethernet pins - osKernelInitialize(); // Initialize CMSIS-RTOS - osThreadNew(blinker, NULL, NULL); // Create the blinker thread with a default stack size + mx_init(); // Setup clock and all peripherals configured in CubeMX + // Initialise random number generator + // Initialise ethernet pins + osKernelInitialize(); // Initialize CMSIS-RTOS + osThreadNew(blinker, NULL, + NULL); // Create the blinker thread with a default stack size const osThreadAttr_t server_attr = { - .stack_size = 8192 // Create the server thread with a stack size of 8KB bytes + .stack_size = + 8192 // Create the server thread with a stack size of 8KB bytes }; osThreadNew(server, NULL, &server_attr); - osKernelStart(); // This blocks + osKernelStart(); // This blocks return 0; } - diff --git a/examples/stm32/nucleo-f746zg-keil-rtx/main.c b/examples/stm32/nucleo-f746zg-keil-rtx/main.c index f6690c51..4729792f 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx/main.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx/main.c @@ -1,15 +1,14 @@ // Copyright (c) 2023 Cesanta Software Limited // All rights reserved +#include "cmsis_os.h" #include "hal.h" -#include "mongoose.h" #include "main.h" +#include "mongoose.h" #include "net.h" -#include "cmsis_os.h" #define BLINK_PERIOD_MS 1000 // LED blinking period in millis - void mg_random(void *buf, size_t len) { // Use on-board RNG extern RNG_HandleTypeDef hrng; for (size_t n = 0; n < len; n += sizeof(uint32_t)) { @@ -20,8 +19,8 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); @@ -57,24 +56,25 @@ static void server(const void *args) { static void blinker(const void *args) { for (;;) { - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED - osDelay(BLINK_PERIOD_MS); // CMSIS-RTOS v1 uses milliseconds + HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED + osDelay(BLINK_PERIOD_MS); // CMSIS-RTOS v1 uses milliseconds } (void) args; } extern void mx_init(void); -osThreadDef(server, osPriorityNormal, 1, 8192); // Create the server thread with a stack size of 8KB -osThreadDef(blinker, osPriorityNormal, 1, 0); // Create the blinker thread with default stack size - -int main(void) { // this is not actually baremetal main() but the "main" thread - osKernelInitialize(); // Stop kernel - mx_init(); // Setup clock and all peripherals configured in CubeMX - // Initialise random number generator - // Initialise ethernet pins +osThreadDef(server, osPriorityNormal, 1, + 8192); // Create the server thread with a stack size of 8KB +osThreadDef(blinker, osPriorityNormal, 1, + 0); // Create the blinker thread with default stack size + +int main(void) { // this is not actually baremetal main() but the "main" thread + osKernelInitialize(); // Stop kernel + mx_init(); // Setup clock and all peripherals configured in CubeMX + // Initialise random number generator + // Initialise ethernet pins osThreadCreate(osThread(blinker), NULL); // Create the blinker thread - osThreadCreate(osThread(server), NULL); // Create the server thread + osThreadCreate(osThread(server), NULL); // Create the server thread osKernelStart(); // Start kernel again and exit main thread return 0; } - diff --git a/examples/stm32/nucleo-f746zg-keil-rtx5/main.c b/examples/stm32/nucleo-f746zg-keil-rtx5/main.c index 1924cad4..b4400200 100644 --- a/examples/stm32/nucleo-f746zg-keil-rtx5/main.c +++ b/examples/stm32/nucleo-f746zg-keil-rtx5/main.c @@ -1,15 +1,14 @@ // Copyright (c) 2023 Cesanta Software Limited // All rights reserved +#include "cmsis_os2.h" #include "hal.h" -#include "mongoose.h" #include "main.h" +#include "mongoose.h" #include "net.h" -#include "cmsis_os2.h" #define BLINK_PERIOD_MS 1000 // LED blinking period in millis - void mg_random(void *buf, size_t len) { // Use on-board RNG extern RNG_HandleTypeDef hrng; for (size_t n = 0; n < len; n += sizeof(uint32_t)) { @@ -20,8 +19,8 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); @@ -57,7 +56,7 @@ static void server(void *args) { static void blinker(void *args) { for (;;) { - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED + HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); // Blink On-board blue LED osDelay((osKernelGetTickFreq() * BLINK_PERIOD_MS) / 1000U); } (void) args; @@ -66,16 +65,16 @@ static void blinker(void *args) { extern void mx_init(void); int main(void) { - mx_init(); // Setup clock and all peripherals configured in CubeMX - // Initialise random number generator - // Initialise ethernet pins - osKernelInitialize(); // Initialize CMSIS-RTOS - osThreadNew(blinker, NULL, NULL); // Create the blinker thread with a default stack size + mx_init(); // Setup clock and all peripherals configured in CubeMX + // Initialise random number generator + // Initialise ethernet pins + osKernelInitialize(); // Initialize CMSIS-RTOS + osThreadNew(blinker, NULL, + NULL); // Create the blinker thread with a default stack size const osThreadAttr_t server_attr = { - .stack_size = 8192 // Create the server thread with a stack size of 8KB + .stack_size = 8192 // Create the server thread with a stack size of 8KB }; osThreadNew(server, NULL, &server_attr); - osKernelStart(); // This blocks + osKernelStart(); // This blocks return 0; } - diff --git a/examples/stm32/nucleo-f746zg-make-baremetal-builtin/main.c b/examples/stm32/nucleo-f746zg-make-baremetal-builtin/main.c index f1b2457b..1ee4ac27 100644 --- a/examples/stm32/nucleo-f746zg-make-baremetal-builtin/main.c +++ b/examples/stm32/nucleo-f746zg-make-baremetal-builtin/main.c @@ -24,9 +24,9 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - gpio_toggle(LED); // Blink LED - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + gpio_toggle(LED); // Blink LED + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); diff --git a/examples/stm32/nucleo-h743zi-make-baremetal-builtin/main.c b/examples/stm32/nucleo-h743zi-make-baremetal-builtin/main.c index 13c51fbc..cc8bf28e 100644 --- a/examples/stm32/nucleo-h743zi-make-baremetal-builtin/main.c +++ b/examples/stm32/nucleo-h743zi-make-baremetal-builtin/main.c @@ -24,9 +24,9 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } static void timer_fn(void *arg) { - gpio_toggle(LED); // Blink LED - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + gpio_toggle(LED); // Blink LED + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); diff --git a/examples/ti/ek-tm4c1294xl-baremetal/main.c b/examples/ti/ek-tm4c1294xl-baremetal/main.c index 326793bf..e10ed89a 100644 --- a/examples/ti/ek-tm4c1294xl-baremetal/main.c +++ b/examples/ti/ek-tm4c1294xl-baremetal/main.c @@ -23,9 +23,9 @@ uint64_t mg_millis(void) { // Let Mongoose use our uptime function } static void timer_fn(void *arg) { - gpio_toggle(LED); // Blink LED - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + gpio_toggle(LED); // Blink LED + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr)); diff --git a/examples/ti/ek-tm4c1294xl-freertos/main.c b/examples/ti/ek-tm4c1294xl-freertos/main.c index 444959d5..e0a06506 100644 --- a/examples/ti/ek-tm4c1294xl-freertos/main.c +++ b/examples/ti/ek-tm4c1294xl-freertos/main.c @@ -14,8 +14,8 @@ #define BLINK_PERIOD_MS 1000 // LED blinking period in millis static void timer_fn(void *arg) { - struct mg_tcpip_if *ifp = arg; // And show - const char *names[] = {"down", "up", "ready"}; // network stats + struct mg_tcpip_if *ifp = arg; // And show + const char *names[] = {"down", "up", "req", "ready"}; // network stats MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop, ifp->nerr));