2021-05-29 06:49:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if MG_ARCH == MG_ARCH_FREERTOS_LWIP
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2021-08-11 14:56:46 +08:00
|
|
|
#include <string.h>
|
2021-05-29 06:49:26 +08:00
|
|
|
|
|
|
|
#if defined(__GNUC__)
|
2021-07-24 10:44:00 +08:00
|
|
|
#include <sys/stat.h>
|
2021-05-29 06:49:26 +08:00
|
|
|
#include <sys/time.h>
|
|
|
|
#else
|
|
|
|
typedef long suseconds_t;
|
|
|
|
struct timeval {
|
|
|
|
time_t tv_sec;
|
|
|
|
suseconds_t tv_usec;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
|
|
|
|
|
|
|
#include <lwip/sockets.h>
|
|
|
|
|
2021-08-11 14:56:46 +08:00
|
|
|
#if LWIP_SOCKET != 1
|
|
|
|
// Sockets support disabled in LWIP by default
|
|
|
|
#error Set LWIP_SOCKET variable to 1 (in lwipopts.h)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if LWIP_POSIX_SOCKETS_IO_NAMES != 0
|
|
|
|
// LWIP_POSIX_SOCKETS_IO_NAMES must be disabled in posix-compatible OS enviroment
|
|
|
|
// (freertos mimics to one) otherwise names like `read` and `write` conflict
|
|
|
|
#error LWIP_POSIX_SOCKETS_IO_NAMES must be set to 0 (in lwipopts.h) for FreeRTOS
|
|
|
|
#endif
|
|
|
|
|
2021-05-29 06:49:26 +08:00
|
|
|
#define MG_INT64_FMT "%lld"
|
|
|
|
#define MG_DIRSEP '/'
|
|
|
|
|
|
|
|
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
|
|
|
|
static inline void *mg_calloc(int cnt, size_t size) {
|
|
|
|
void *p = pvPortMalloc(cnt * size);
|
|
|
|
if (p != NULL) memset(p, 0, size);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
#define calloc(a, b) mg_calloc((a), (b))
|
|
|
|
#define free(a) vPortFree(a)
|
|
|
|
#define malloc(a) pvPortMalloc(a)
|
|
|
|
|
|
|
|
#define gmtime_r(a, b) gmtime(a)
|
|
|
|
|
|
|
|
#endif // MG_ARCH == MG_ARCH_FREERTOS_LWIP
|