mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-30 21:18:25 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3566f7c7fe | ||
|
|
a688c0a0f0 |
No files matched your search
@@ -490,7 +490,7 @@ jobs:
|
|||||||
- uses: webfactory/ssh-agent@v0.10.0
|
- uses: webfactory/ssh-agent@v0.10.0
|
||||||
with:
|
with:
|
||||||
ssh-private-key: ${{ secrets.HEALTH_TESTS_SSH_KEY }}
|
ssh-private-key: ${{ secrets.HEALTH_TESTS_SSH_KEY }}
|
||||||
- run: sudo apt -y install libpcap-dev
|
- run: sudo apt -y update && sudo apt -y install libpcap-dev
|
||||||
- run: make -C test tutorials CFLAGS_EXTRA="${{ matrix.ssl }}" > log
|
- run: make -C test tutorials CFLAGS_EXTRA="${{ matrix.ssl }}" > log
|
||||||
- if: success() || failure()
|
- if: success() || failure()
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
+64
-64
@@ -16778,67 +16778,6 @@ bool mg_str_to_num(struct mg_str str, int base, void *val, size_t val_len) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The clock lives in mg_micros(), mg_millis() is derived from it. Either one
|
|
||||||
// can be replaced, see MG_ENABLE_CUSTOM_MICROS and MG_ENABLE_CUSTOM_MILLIS
|
|
||||||
#if MG_ENABLE_CUSTOM_MICROS == 0
|
|
||||||
uint64_t mg_micros(void) {
|
|
||||||
#if MG_ARCH == MG_ARCH_ESP32
|
|
||||||
return (uint64_t) esp_timer_get_time();
|
|
||||||
#elif MG_ENABLE_FREERTOS
|
|
||||||
return (uint64_t) xTaskGetTickCount() * portTICK_PERIOD_MS * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_THREADX
|
|
||||||
return (uint64_t) tx_time_get() *
|
|
||||||
(1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND) * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_TIRTOS
|
|
||||||
return (uint64_t) Clock_getTicks() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_ZEPHYR
|
|
||||||
return k_ticks_to_us_floor64((uint64_t) k_uptime_ticks());
|
|
||||||
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS1
|
|
||||||
return (uint64_t) rt_time_get() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS2
|
|
||||||
return (uint64_t) ((osKernelGetTickCount() * 1000) / osKernelGetTickFreq()) *
|
|
||||||
1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_RTTHREAD
|
|
||||||
return (uint64_t) ((rt_tick_get() * 1000) / RT_TICK_PER_SECOND) * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_WIN32
|
|
||||||
return (uint64_t) GetTickCount() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_PICOSDK
|
|
||||||
return time_us_64();
|
|
||||||
#elif MG_ARCH == MG_ARCH_CUBE
|
|
||||||
return (uint64_t) HAL_GetTick() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
|
|
||||||
// Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
|
|
||||||
// Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux
|
|
||||||
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_UNIX
|
|
||||||
struct timespec ts = {0, 0};
|
|
||||||
// See #1615 - prefer monotonic clock
|
|
||||||
#if defined(CLOCK_MONOTONIC_RAW)
|
|
||||||
// Raw hardware-based time that is not subject to NTP adjustment
|
|
||||||
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
|
||||||
#elif defined(CLOCK_MONOTONIC)
|
|
||||||
// Affected by the incremental adjustments performed by adjtime and NTP
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
#else
|
|
||||||
// Affected by discontinuous jumps in the system time and by the incremental
|
|
||||||
// adjustments performed by adjtime and NTP
|
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
|
||||||
#endif
|
|
||||||
return ((uint64_t) ts.tv_sec * 1000000 + (uint64_t) ts.tv_nsec / 1000);
|
|
||||||
#elif defined(ARDUINO)
|
|
||||||
return (uint64_t) micros();
|
|
||||||
#else
|
|
||||||
return (uint64_t) time(NULL) * 1000000;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MG_ENABLE_CUSTOM_MILLIS == 0
|
|
||||||
uint64_t mg_millis(void) {
|
|
||||||
return mg_micros() / 1000;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void mg_timer_init(struct mg_timer **head, struct mg_timer *t, uint64_t ms,
|
void mg_timer_init(struct mg_timer **head, struct mg_timer *t, uint64_t ms,
|
||||||
unsigned flags, void (*fn)(void *), void *arg) {
|
unsigned flags, void (*fn)(void *), void *arg) {
|
||||||
t->period_ms = ms, t->expire = 0;
|
t->period_ms = ms, t->expire = 0;
|
||||||
@@ -18034,7 +17973,6 @@ int mg_aes_gcm_decrypt(unsigned char *output, const unsigned char *input,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if MG_TLS == MG_TLS_BUILTIN
|
#if MG_TLS == MG_TLS_BUILTIN
|
||||||
|
|
||||||
#ifndef MG_MAX_TLSOID_DEPTH
|
#ifndef MG_MAX_TLSOID_DEPTH
|
||||||
@@ -29997,6 +29935,67 @@ bool mg_path_is_sane(const struct mg_str path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The clock lives in mg_micros(), mg_millis() is derived from it. Either one
|
||||||
|
// can be replaced, see MG_ENABLE_CUSTOM_MICROS and MG_ENABLE_CUSTOM_MILLIS
|
||||||
|
#if MG_ENABLE_CUSTOM_MICROS == 0
|
||||||
|
uint64_t mg_micros(void) {
|
||||||
|
#if MG_ARCH == MG_ARCH_ESP32
|
||||||
|
return (uint64_t) esp_timer_get_time();
|
||||||
|
#elif MG_ENABLE_FREERTOS
|
||||||
|
return (uint64_t) xTaskGetTickCount() * portTICK_PERIOD_MS * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_THREADX
|
||||||
|
return (uint64_t) tx_time_get() *
|
||||||
|
(1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND) * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_TIRTOS
|
||||||
|
return (uint64_t) Clock_getTicks() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_ZEPHYR
|
||||||
|
return k_ticks_to_us_floor64((uint64_t) k_uptime_ticks());
|
||||||
|
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS1
|
||||||
|
return (uint64_t) rt_time_get() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS2
|
||||||
|
return (uint64_t) ((osKernelGetTickCount() * 1000) / osKernelGetTickFreq()) *
|
||||||
|
1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_RTTHREAD
|
||||||
|
return (uint64_t) ((rt_tick_get() * 1000) / RT_TICK_PER_SECOND) * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_WIN32
|
||||||
|
return (uint64_t) GetTickCount() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_PICOSDK
|
||||||
|
return time_us_64();
|
||||||
|
#elif MG_ARCH == MG_ARCH_CUBE
|
||||||
|
return (uint64_t) HAL_GetTick() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
|
||||||
|
// Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
|
||||||
|
// Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux
|
||||||
|
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_UNIX
|
||||||
|
struct timespec ts = {0, 0};
|
||||||
|
// See #1615 - prefer monotonic clock
|
||||||
|
#if defined(CLOCK_MONOTONIC_RAW)
|
||||||
|
// Raw hardware-based time that is not subject to NTP adjustment
|
||||||
|
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||||
|
#elif defined(CLOCK_MONOTONIC)
|
||||||
|
// Affected by the incremental adjustments performed by adjtime and NTP
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
#else
|
||||||
|
// Affected by discontinuous jumps in the system time and by the incremental
|
||||||
|
// adjustments performed by adjtime and NTP
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
#endif
|
||||||
|
return ((uint64_t) ts.tv_sec * 1000000 + (uint64_t) ts.tv_nsec / 1000);
|
||||||
|
#elif defined(ARDUINO)
|
||||||
|
return (uint64_t) micros();
|
||||||
|
#else
|
||||||
|
return (uint64_t) time(NULL) * 1000000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MG_ENABLE_CUSTOM_MILLIS == 0
|
||||||
|
uint64_t mg_millis(void) {
|
||||||
|
return mg_micros() / 1000;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// network format equates big endian order
|
// network format equates big endian order
|
||||||
uint16_t mg_ntohs(uint16_t net) {
|
uint16_t mg_ntohs(uint16_t net) {
|
||||||
return MG_LOAD_BE16(&net);
|
return MG_LOAD_BE16(&net);
|
||||||
@@ -33797,15 +33796,16 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
|
|
||||||
if (config & MG_PHY_RGMII) {
|
if (config & MG_PHY_RGMII) {
|
||||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||||
|
// assume PHY has been hardware strapped properly
|
||||||
|
#if 0
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
|
||||||
// We temporarily force enabling autoneg, until a workaround is found.
|
|
||||||
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
||||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
||||||
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
||||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||||
|
#endif
|
||||||
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||||
phy->write_reg(phy_addr, 0x0d,
|
phy->write_reg(phy_addr, 0x0d,
|
||||||
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||||
|
|||||||
+27
-28
@@ -1807,33 +1807,6 @@ void mg_log_set_fn(mg_pfn_t fn, void *param);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Return microseconds since boot. Never goes backwards.
|
|
||||||
// To define your own implementation, set MG_ENABLE_CUSTOM_MICROS=1
|
|
||||||
uint64_t mg_micros(void);
|
|
||||||
|
|
||||||
// Return milliseconds since boot. Never goes backwards. Calls mg_micros().
|
|
||||||
// To define your own implementation, set MG_ENABLE_CUSTOM_MILLIS=1
|
|
||||||
// Deprecated: use mg_micros() instead.
|
|
||||||
uint64_t mg_millis(void);
|
|
||||||
|
|
||||||
// Checks whether a periodic deadline has expired.
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// True when the timer has fired; false otherwise.
|
|
||||||
// Example:
|
|
||||||
// uint64_t timer = 0;
|
|
||||||
// if (mg_timer_expired(&timer, 1000, mg_millis())) {
|
|
||||||
// MG_INFO(("every second"));
|
|
||||||
// }
|
|
||||||
// Full examples:
|
|
||||||
// tutorials/mqtt/mqtt-client
|
|
||||||
// Related APIs:
|
|
||||||
// mg_millis(), mg_now()
|
|
||||||
// Notes:
|
|
||||||
// Initialise *expiration to 0 before first use. On expiry, this function
|
|
||||||
// advances *expiration by period and handles time wrap-around.
|
|
||||||
bool mg_timer_expired(uint64_t *expiration, uint64_t period, uint64_t now);
|
|
||||||
|
|
||||||
struct mg_timer {
|
struct mg_timer {
|
||||||
uint64_t period_ms; // Timer period in milliseconds
|
uint64_t period_ms; // Timer period in milliseconds
|
||||||
uint64_t expire; // Expiration timestamp in milliseconds
|
uint64_t expire; // Expiration timestamp in milliseconds
|
||||||
@@ -3502,12 +3475,20 @@ size_t mg_ws_wrap(struct mg_connection *, size_t len, int op);
|
|||||||
size_t mg_ws_printf(struct mg_connection *c, int op, const char *fmt, ...);
|
size_t mg_ws_printf(struct mg_connection *c, int op, const char *fmt, ...);
|
||||||
size_t mg_ws_vprintf(struct mg_connection *c, int op, const char *fmt,
|
size_t mg_ws_vprintf(struct mg_connection *c, int op, const char *fmt,
|
||||||
va_list *);
|
va_list *);
|
||||||
// SNTP functions
|
// Time / SNTP functions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Return microseconds since boot. Never goes backwards.
|
||||||
|
// To define your own implementation, set MG_ENABLE_CUSTOM_MICROS=1
|
||||||
|
uint64_t mg_micros(void);
|
||||||
|
|
||||||
|
// Return milliseconds since boot. Never goes backwards. Calls mg_micros().
|
||||||
|
// To define your own implementation, set MG_ENABLE_CUSTOM_MILLIS=1
|
||||||
|
// Deprecated: use mg_micros() instead.
|
||||||
|
uint64_t mg_millis(void);
|
||||||
|
|
||||||
// Boot timestamp in ms since Epoch. 0 until the first successful SNTP sync;
|
// Boot timestamp in ms since Epoch. 0 until the first successful SNTP sync;
|
||||||
// updated automatically by mg_sntp_connect() on each successful response.
|
// updated automatically by mg_sntp_connect() on each successful response.
|
||||||
@@ -3517,6 +3498,24 @@ extern uint64_t mg_boot_timestamp_ms;
|
|||||||
// Until a successful SNTP request completes, this is identical to mg_millis().
|
// Until a successful SNTP request completes, this is identical to mg_millis().
|
||||||
uint64_t mg_now(void);
|
uint64_t mg_now(void);
|
||||||
|
|
||||||
|
// Checks whether a periodic deadline has expired.
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// True when the timer has fired; false otherwise.
|
||||||
|
// Example:
|
||||||
|
// uint64_t timer = 0;
|
||||||
|
// if (mg_timer_expired(&timer, 1000, mg_millis())) {
|
||||||
|
// MG_INFO(("every second"));
|
||||||
|
// }
|
||||||
|
// Full examples:
|
||||||
|
// tutorials/mqtt/mqtt-client
|
||||||
|
// Related APIs:
|
||||||
|
// mg_millis(), mg_now()
|
||||||
|
// Notes:
|
||||||
|
// Initialise *expiration to 0 before first use. On expiry, this function
|
||||||
|
// advances *expiration by period and handles time wrap-around.
|
||||||
|
bool mg_timer_expired(uint64_t *expiration, uint64_t period, uint64_t now);
|
||||||
|
|
||||||
// Connect to an SNTP server and send a time request.
|
// Connect to an SNTP server and send a time request.
|
||||||
// `url` defaults to "udp://time.google.com:123" when NULL.
|
// `url` defaults to "udp://time.google.com:123" when NULL.
|
||||||
// On success the internal boot timestamp is updated so that mg_now() returns
|
// On success the internal boot timestamp is updated so that mg_now() returns
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "net_builtin.h"
|
#include "net_builtin.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "timer.h"
|
#include "sntp.h"
|
||||||
|
|
||||||
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_ATCMD) && MG_ENABLE_DRIVER_ATCMD
|
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_ATCMD) && MG_ENABLE_DRIVER_ATCMD
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -87,15 +87,16 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
|
|||||||
|
|
||||||
if (config & MG_PHY_RGMII) {
|
if (config & MG_PHY_RGMII) {
|
||||||
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
|
||||||
|
// assume PHY has been hardware strapped properly
|
||||||
|
#if 0
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
|
|
||||||
// We temporarily force enabling autoneg, until a workaround is found.
|
|
||||||
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
|
||||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
|
||||||
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
|
||||||
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
|
||||||
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
|
||||||
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
|
||||||
|
#endif
|
||||||
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
|
||||||
phy->write_reg(phy_addr, 0x0d,
|
phy->write_reg(phy_addr, 0x0d,
|
||||||
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
#include "rpc.h"
|
#include "rpc.h"
|
||||||
#include "timer.h"
|
#include "sntp.h"
|
||||||
#include "tls.h"
|
#include "tls.h"
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "ws.h"
|
#include "ws.h"
|
||||||
|
|||||||
+28
-2
@@ -1,9 +1,17 @@
|
|||||||
// SNTP functions
|
// Time / SNTP functions
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "timer.h"
|
|
||||||
|
// Return microseconds since boot. Never goes backwards.
|
||||||
|
// To define your own implementation, set MG_ENABLE_CUSTOM_MICROS=1
|
||||||
|
uint64_t mg_micros(void);
|
||||||
|
|
||||||
|
// Return milliseconds since boot. Never goes backwards. Calls mg_micros().
|
||||||
|
// To define your own implementation, set MG_ENABLE_CUSTOM_MILLIS=1
|
||||||
|
// Deprecated: use mg_micros() instead.
|
||||||
|
uint64_t mg_millis(void);
|
||||||
|
|
||||||
// Boot timestamp in ms since Epoch. 0 until the first successful SNTP sync;
|
// Boot timestamp in ms since Epoch. 0 until the first successful SNTP sync;
|
||||||
// updated automatically by mg_sntp_connect() on each successful response.
|
// updated automatically by mg_sntp_connect() on each successful response.
|
||||||
@@ -13,6 +21,24 @@ extern uint64_t mg_boot_timestamp_ms;
|
|||||||
// Until a successful SNTP request completes, this is identical to mg_millis().
|
// Until a successful SNTP request completes, this is identical to mg_millis().
|
||||||
uint64_t mg_now(void);
|
uint64_t mg_now(void);
|
||||||
|
|
||||||
|
// Checks whether a periodic deadline has expired.
|
||||||
|
//
|
||||||
|
// Returns:
|
||||||
|
// True when the timer has fired; false otherwise.
|
||||||
|
// Example:
|
||||||
|
// uint64_t timer = 0;
|
||||||
|
// if (mg_timer_expired(&timer, 1000, mg_millis())) {
|
||||||
|
// MG_INFO(("every second"));
|
||||||
|
// }
|
||||||
|
// Full examples:
|
||||||
|
// tutorials/mqtt/mqtt-client
|
||||||
|
// Related APIs:
|
||||||
|
// mg_millis(), mg_now()
|
||||||
|
// Notes:
|
||||||
|
// Initialise *expiration to 0 before first use. On expiry, this function
|
||||||
|
// advances *expiration by period and handles time wrap-around.
|
||||||
|
bool mg_timer_expired(uint64_t *expiration, uint64_t period, uint64_t now);
|
||||||
|
|
||||||
// Connect to an SNTP server and send a time request.
|
// Connect to an SNTP server and send a time request.
|
||||||
// `url` defaults to "udp://time.google.com:123" when NULL.
|
// `url` defaults to "udp://time.google.com:123" when NULL.
|
||||||
// On success the internal boot timestamp is updated so that mg_now() returns
|
// On success the internal boot timestamp is updated so that mg_now() returns
|
||||||
|
|||||||
-61
@@ -2,67 +2,6 @@
|
|||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
// The clock lives in mg_micros(), mg_millis() is derived from it. Either one
|
|
||||||
// can be replaced, see MG_ENABLE_CUSTOM_MICROS and MG_ENABLE_CUSTOM_MILLIS
|
|
||||||
#if MG_ENABLE_CUSTOM_MICROS == 0
|
|
||||||
uint64_t mg_micros(void) {
|
|
||||||
#if MG_ARCH == MG_ARCH_ESP32
|
|
||||||
return (uint64_t) esp_timer_get_time();
|
|
||||||
#elif MG_ENABLE_FREERTOS
|
|
||||||
return (uint64_t) xTaskGetTickCount() * portTICK_PERIOD_MS * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_THREADX
|
|
||||||
return (uint64_t) tx_time_get() *
|
|
||||||
(1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND) * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_TIRTOS
|
|
||||||
return (uint64_t) Clock_getTicks() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_ZEPHYR
|
|
||||||
return k_ticks_to_us_floor64((uint64_t) k_uptime_ticks());
|
|
||||||
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS1
|
|
||||||
return (uint64_t) rt_time_get() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS2
|
|
||||||
return (uint64_t) ((osKernelGetTickCount() * 1000) / osKernelGetTickFreq()) *
|
|
||||||
1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_RTTHREAD
|
|
||||||
return (uint64_t) ((rt_tick_get() * 1000) / RT_TICK_PER_SECOND) * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_WIN32
|
|
||||||
return (uint64_t) GetTickCount() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_PICOSDK
|
|
||||||
return time_us_64();
|
|
||||||
#elif MG_ARCH == MG_ARCH_CUBE
|
|
||||||
return (uint64_t) HAL_GetTick() * 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
|
|
||||||
// Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
|
|
||||||
// Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux
|
|
||||||
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000;
|
|
||||||
#elif MG_ARCH == MG_ARCH_UNIX
|
|
||||||
struct timespec ts = {0, 0};
|
|
||||||
// See #1615 - prefer monotonic clock
|
|
||||||
#if defined(CLOCK_MONOTONIC_RAW)
|
|
||||||
// Raw hardware-based time that is not subject to NTP adjustment
|
|
||||||
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
|
||||||
#elif defined(CLOCK_MONOTONIC)
|
|
||||||
// Affected by the incremental adjustments performed by adjtime and NTP
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
#else
|
|
||||||
// Affected by discontinuous jumps in the system time and by the incremental
|
|
||||||
// adjustments performed by adjtime and NTP
|
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
|
||||||
#endif
|
|
||||||
return ((uint64_t) ts.tv_sec * 1000000 + (uint64_t) ts.tv_nsec / 1000);
|
|
||||||
#elif defined(ARDUINO)
|
|
||||||
return (uint64_t) micros();
|
|
||||||
#else
|
|
||||||
return (uint64_t) time(NULL) * 1000000;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if MG_ENABLE_CUSTOM_MILLIS == 0
|
|
||||||
uint64_t mg_millis(void) {
|
|
||||||
return mg_micros() / 1000;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void mg_timer_init(struct mg_timer **head, struct mg_timer *t, uint64_t ms,
|
void mg_timer_init(struct mg_timer **head, struct mg_timer *t, uint64_t ms,
|
||||||
unsigned flags, void (*fn)(void *), void *arg) {
|
unsigned flags, void (*fn)(void *), void *arg) {
|
||||||
t->period_ms = ms, t->expire = 0;
|
t->period_ms = ms, t->expire = 0;
|
||||||
|
|||||||
-27
@@ -2,33 +2,6 @@
|
|||||||
|
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
|
|
||||||
// Return microseconds since boot. Never goes backwards.
|
|
||||||
// To define your own implementation, set MG_ENABLE_CUSTOM_MICROS=1
|
|
||||||
uint64_t mg_micros(void);
|
|
||||||
|
|
||||||
// Return milliseconds since boot. Never goes backwards. Calls mg_micros().
|
|
||||||
// To define your own implementation, set MG_ENABLE_CUSTOM_MILLIS=1
|
|
||||||
// Deprecated: use mg_micros() instead.
|
|
||||||
uint64_t mg_millis(void);
|
|
||||||
|
|
||||||
// Checks whether a periodic deadline has expired.
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// True when the timer has fired; false otherwise.
|
|
||||||
// Example:
|
|
||||||
// uint64_t timer = 0;
|
|
||||||
// if (mg_timer_expired(&timer, 1000, mg_millis())) {
|
|
||||||
// MG_INFO(("every second"));
|
|
||||||
// }
|
|
||||||
// Full examples:
|
|
||||||
// tutorials/mqtt/mqtt-client
|
|
||||||
// Related APIs:
|
|
||||||
// mg_millis(), mg_now()
|
|
||||||
// Notes:
|
|
||||||
// Initialise *expiration to 0 before first use. On expiry, this function
|
|
||||||
// advances *expiration by period and handles time wrap-around.
|
|
||||||
bool mg_timer_expired(uint64_t *expiration, uint64_t period, uint64_t now);
|
|
||||||
|
|
||||||
struct mg_timer {
|
struct mg_timer {
|
||||||
uint64_t period_ms; // Timer period in milliseconds
|
uint64_t period_ms; // Timer period in milliseconds
|
||||||
uint64_t expire; // Expiration timestamp in milliseconds
|
uint64_t expire; // Expiration timestamp in milliseconds
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
#include "sntp.h"
|
|
||||||
#include "tls.h"
|
#include "tls.h"
|
||||||
#include "tls_aes128.h"
|
#include "tls_aes128.h"
|
||||||
#include "tls_chacha20.h"
|
#include "tls_chacha20.h"
|
||||||
|
|||||||
+61
@@ -197,6 +197,67 @@ bool mg_path_is_sane(const struct mg_str path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The clock lives in mg_micros(), mg_millis() is derived from it. Either one
|
||||||
|
// can be replaced, see MG_ENABLE_CUSTOM_MICROS and MG_ENABLE_CUSTOM_MILLIS
|
||||||
|
#if MG_ENABLE_CUSTOM_MICROS == 0
|
||||||
|
uint64_t mg_micros(void) {
|
||||||
|
#if MG_ARCH == MG_ARCH_ESP32
|
||||||
|
return (uint64_t) esp_timer_get_time();
|
||||||
|
#elif MG_ENABLE_FREERTOS
|
||||||
|
return (uint64_t) xTaskGetTickCount() * portTICK_PERIOD_MS * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_THREADX
|
||||||
|
return (uint64_t) tx_time_get() *
|
||||||
|
(1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND) * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_TIRTOS
|
||||||
|
return (uint64_t) Clock_getTicks() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_ZEPHYR
|
||||||
|
return k_ticks_to_us_floor64((uint64_t) k_uptime_ticks());
|
||||||
|
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS1
|
||||||
|
return (uint64_t) rt_time_get() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_CMSIS_RTOS2
|
||||||
|
return (uint64_t) ((osKernelGetTickCount() * 1000) / osKernelGetTickFreq()) *
|
||||||
|
1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_RTTHREAD
|
||||||
|
return (uint64_t) ((rt_tick_get() * 1000) / RT_TICK_PER_SECOND) * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_WIN32
|
||||||
|
return (uint64_t) GetTickCount() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_PICOSDK
|
||||||
|
return time_us_64();
|
||||||
|
#elif MG_ARCH == MG_ARCH_CUBE
|
||||||
|
return (uint64_t) HAL_GetTick() * 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
|
||||||
|
// Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
|
||||||
|
// Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux
|
||||||
|
return clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000;
|
||||||
|
#elif MG_ARCH == MG_ARCH_UNIX
|
||||||
|
struct timespec ts = {0, 0};
|
||||||
|
// See #1615 - prefer monotonic clock
|
||||||
|
#if defined(CLOCK_MONOTONIC_RAW)
|
||||||
|
// Raw hardware-based time that is not subject to NTP adjustment
|
||||||
|
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||||
|
#elif defined(CLOCK_MONOTONIC)
|
||||||
|
// Affected by the incremental adjustments performed by adjtime and NTP
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
#else
|
||||||
|
// Affected by discontinuous jumps in the system time and by the incremental
|
||||||
|
// adjustments performed by adjtime and NTP
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
#endif
|
||||||
|
return ((uint64_t) ts.tv_sec * 1000000 + (uint64_t) ts.tv_nsec / 1000);
|
||||||
|
#elif defined(ARDUINO)
|
||||||
|
return (uint64_t) micros();
|
||||||
|
#else
|
||||||
|
return (uint64_t) time(NULL) * 1000000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MG_ENABLE_CUSTOM_MILLIS == 0
|
||||||
|
uint64_t mg_millis(void) {
|
||||||
|
return mg_micros() / 1000;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// network format equates big endian order
|
// network format equates big endian order
|
||||||
uint16_t mg_ntohs(uint16_t net) {
|
uint16_t mg_ntohs(uint16_t net) {
|
||||||
return MG_LOAD_BE16(&net);
|
return MG_LOAD_BE16(&net);
|
||||||
|
|||||||
+1
-1
@@ -3,8 +3,8 @@
|
|||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "sntp.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "timer.h"
|
|
||||||
|
|
||||||
#if MG_ENABLE_ASSERT
|
#if MG_ENABLE_ASSERT
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_ele_base_api.c
|
|||||||
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_s3mu.c
|
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_s3mu.c
|
||||||
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_trdc.c
|
SOURCES += cmsis_rt1186/devices/MIMXRT1186/drivers/fsl_trdc.c
|
||||||
|
|
||||||
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS -DMG_HAL_DISABLE_RANDOM
|
CFLAGS += -D__ATOLLIC__ -D__STARTUP_CLEAR_BSS -DMG_HAL_DISABLE_RANDOM -DMG_HAL_ENABLE_PHY_STRAP
|
||||||
|
|
||||||
all build: firmware.bin
|
all build: firmware.bin
|
||||||
|
|
||||||
|
|||||||
@@ -586,9 +586,6 @@ static inline void hal_netc_pins_init(void) {
|
|||||||
CLOCK_EnableClock(kCLOCK_Iomuxc1);
|
CLOCK_EnableClock(kCLOCK_Iomuxc1);
|
||||||
CLOCK_EnableClock(kCLOCK_Iomuxc2);
|
CLOCK_EnableClock(kCLOCK_Iomuxc2);
|
||||||
|
|
||||||
hal_gpio_output(HAL_NETC_PHY0_RESET);
|
|
||||||
hal_gpio_write(HAL_NETC_PHY0_RESET, true);
|
|
||||||
|
|
||||||
hal_gpio_mux_config(kIOMUXC_SW_MUX_CTL_PAD_GPIO_AD_30, 7U); // EMDC
|
hal_gpio_mux_config(kIOMUXC_SW_MUX_CTL_PAD_GPIO_AD_30, 7U); // EMDC
|
||||||
hal_gpio_pad_config(kIOMUXC_SW_PAD_CTL_PAD_GPIO_AD_30,
|
hal_gpio_pad_config(kIOMUXC_SW_PAD_CTL_PAD_GPIO_AD_30,
|
||||||
HAL_GPIO_OTYPE_PUSH_PULL, HAL_GPIO_SPEED_HIGH,
|
HAL_GPIO_OTYPE_PUSH_PULL, HAL_GPIO_SPEED_HIGH,
|
||||||
@@ -648,13 +645,27 @@ static inline bool hal_netc_ierb_init(void) {
|
|||||||
static inline void hal_ethernet_init(void) {
|
static inline void hal_ethernet_init(void) {
|
||||||
hal_netc_trdc_init();
|
hal_netc_trdc_init();
|
||||||
CLOCK_EnableClock(kCLOCK_Netc);
|
CLOCK_EnableClock(kCLOCK_Netc);
|
||||||
hal_netc_pins_init();
|
hal_gpio_output(HAL_NETC_PHY0_RESET);
|
||||||
if (!hal_netc_ierb_init()) return;
|
|
||||||
|
|
||||||
hal_gpio_write(HAL_NETC_PHY0_RESET, false);
|
hal_gpio_write(HAL_NETC_PHY0_RESET, false);
|
||||||
SDK_DelayAtLeastUs(10000U, SYS_FREQUENCY);
|
#if MG_HAL_ENABLE_PHY_STRAP
|
||||||
|
hal_gpio_output(PIN('3', 10)); // RX_CLK PHY ADDR1
|
||||||
|
hal_gpio_output(PIN('3', 11)); // RX_DATA_2 CFG_MODE1
|
||||||
|
hal_gpio_output(PIN('3', 12)); // RX_DATA_3 CFG_MODE2
|
||||||
|
hal_gpio_output(PIN('3', 20)); // RX_DATA_1 CFG_MODE0
|
||||||
|
hal_gpio_write(PIN('3', 10), false); // PHY ADDR b101 = 5
|
||||||
|
hal_gpio_write(PIN('3', 12), false); // CFG_MODE 000: RGMII
|
||||||
|
hal_gpio_write(PIN('3', 11), false); //
|
||||||
|
hal_gpio_write(PIN('3', 20), false); //
|
||||||
|
#endif
|
||||||
|
SDK_DelayAtLeastUs(15000U, SYS_FREQUENCY);
|
||||||
hal_gpio_write(HAL_NETC_PHY0_RESET, true);
|
hal_gpio_write(HAL_NETC_PHY0_RESET, true);
|
||||||
SDK_DelayAtLeastUs(150000U, SYS_FREQUENCY);
|
__DSB(); // ensure pin config happens AFTER reset is released
|
||||||
|
SDK_DelayAtLeastUs(10U, SYS_FREQUENCY); // provide some hold time
|
||||||
|
hal_netc_pins_init(); // release straps, set as Ethernet pins
|
||||||
|
if (!hal_netc_ierb_init())
|
||||||
|
return;
|
||||||
|
SDK_DelayAtLeastUs(15000U, SYS_FREQUENCY);
|
||||||
|
|
||||||
NVIC_EnableIRQ(MSGINTR1_IRQn);
|
NVIC_EnableIRQ(MSGINTR1_IRQn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -664,3 +675,4 @@ static inline void hal_rng_init(void) {
|
|||||||
static inline uint32_t hal_rng_read(void) {
|
static inline uint32_t hal_rng_read(void) {
|
||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user