diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a646dc57..e7b8e47c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -120,6 +120,8 @@ jobs: path: infineon/infineon-xmc4700_4800-lwip-rtx-rtos - name: zephyr path: zephyr + - name: ti + path: ti/ti-ek-tm4c1294xl-http-server name: ${{ matrix.example.name }} steps: - uses: actions/checkout@v3 diff --git a/examples/ti/ti-ek-tm4c1294xl-http-server/Makefile b/examples/ti/ti-ek-tm4c1294xl-http-server/Makefile new file mode 100644 index 00000000..eb0f5b12 --- /dev/null +++ b/examples/ti/ti-ek-tm4c1294xl-http-server/Makefile @@ -0,0 +1,10 @@ +NAME = ti-ek-tm4c1294xl-http-server +DOCKER ?= docker run -v $(CURDIR):/workspace mdashnet/ccs + +build: + git clone --depth 1 https://github.com/mongoose-examples/$(NAME) + cp ./../../../mongoose.[ch] $(NAME)/ + $(DOCKER) /opt/ti/ccs/eclipse/eclipse -noSplash -data /workspace -application com.ti.ccstudio.apps.projectBuild -ccs.autoImport -ccs.projects $(NAME) -ccs.configuration Release + +clean: + rm -rf $(NAME) diff --git a/mongoose.c b/mongoose.c index 1288a8f3..2f73e975 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2006,9 +2006,7 @@ static void logs(const char *buf, size_t len) { static void mg_log_stdout(const void *buf, size_t len, void *userdata) { (void) userdata, (void) buf, (void) len; -#if MG_ENABLE_FILE logs((const char *) buf, len); -#endif } static const char *s_spec = "2"; @@ -3156,6 +3154,9 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url, #define MG_SOCK_ERRNO errno typedef Socket_t SOCKET; #define INVALID_SOCKET FREERTOS_INVALID_SOCKET +#elif MG_ARCH == MG_ARCH_TIRTOS +#define MG_SOCK_ERRNO errno +#define closesocket(x) close(x) #else #define MG_SOCK_ERRNO errno #ifndef closesocket @@ -3319,6 +3320,16 @@ static void mg_set_non_blocking_mode(SOCKET fd) { lwip_fcntl(fd, F_SETFL, O_NONBLOCK); #elif MG_ARCH == MG_ARCH_AZURERTOS fcntl(fd, F_SETFL, O_NONBLOCK); +#elif MG_ARCH == MG_ARCH_TIRTOS + int val = 0; + setsockopt(fd, 0, SO_BLOCKING, &val, sizeof(val)); + int status = 0; + int res = SockStatus(fd, FDSTATUS_SEND, &status); + if (res == 0 && status > 0) { + val = status / 2; + int val_size = sizeof(val); + res = SockSet(fd, SOL_SOCKET, SO_SNDLOWAT, &val, val_size); + } #else fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); // Non-blocking mode fcntl(fd, F_SETFD, FD_CLOEXEC); // Set close-on-exec @@ -3436,7 +3447,7 @@ static void close_conn(struct mg_connection *c) { } static void setsockopts(struct mg_connection *c) { -#if MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_AZURERTOS +#if MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_AZURERTOS || MG_ARCH == MG_ARCH_TIRTOS (void) c; #else int on = 1; @@ -3477,6 +3488,7 @@ void mg_connect_resolved(struct mg_connection *c) { mg_error(c, "connect: %d", MG_SOCK_ERRNO); } } + (void)rc; MG_DEBUG(("%lu %p", c->id, c->fd)); } @@ -3502,7 +3514,7 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) { if (MG_SOCK_ERRNO != EAGAIN) #endif MG_ERROR(("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO)); -#if ((MG_ARCH != MG_ARCH_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP)) +#if (MG_ARCH != MG_ARCH_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP) && (MG_ARCH != MG_ARCH_TIRTOS) } else if ((long) fd >= FD_SETSIZE) { MG_ERROR(("%ld > %ld", (long) fd, (long) FD_SETSIZE)); closesocket(fd); diff --git a/mongoose.h b/mongoose.h index 7b36bd62..ac85d8c6 100644 --- a/mongoose.h +++ b/mongoose.h @@ -39,6 +39,7 @@ extern "C" { #define MG_ARCH_ZEPHYR 9 #define MG_ARCH_NEWLIB 10 #define MG_ARCH_RTX 11 +#define MG_ARCH_TIRTOS 12 #if !defined(MG_ARCH) #if defined(__unix__) || defined(__APPLE__) @@ -392,6 +393,27 @@ struct timeval { #endif +#if MG_ARCH == MG_ARCH_TIRTOS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +extern int SockStatus(SOCKET hSock, int request, int *results ); +extern int SockSet(SOCKET hSock, int Type, int Prop, void *pbuf, int size); + +#endif + + #if MG_ARCH == MG_ARCH_UNIX #define _DARWIN_UNLIMITED_SELECT 1 // No limit on file descriptors diff --git a/src/arch.h b/src/arch.h index c53be7de..9a7b1d10 100644 --- a/src/arch.h +++ b/src/arch.h @@ -12,6 +12,7 @@ #define MG_ARCH_ZEPHYR 9 #define MG_ARCH_NEWLIB 10 #define MG_ARCH_RTX 11 +#define MG_ARCH_TIRTOS 12 #if !defined(MG_ARCH) #if defined(__unix__) || defined(__APPLE__) diff --git a/src/arch_tirtos.h b/src/arch_tirtos.h new file mode 100644 index 00000000..ea4c2090 --- /dev/null +++ b/src/arch_tirtos.h @@ -0,0 +1,21 @@ +#pragma once + +#if MG_ARCH == MG_ARCH_TIRTOS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +extern int SockStatus(SOCKET hSock, int request, int *results ); +extern int SockSet(SOCKET hSock, int Type, int Prop, void *pbuf, int size); + +#endif diff --git a/src/log.c b/src/log.c index 6d3cb8bf..c9db9ac9 100644 --- a/src/log.c +++ b/src/log.c @@ -12,9 +12,7 @@ static void logs(const char *buf, size_t len) { static void mg_log_stdout(const void *buf, size_t len, void *userdata) { (void) userdata, (void) buf, (void) len; -#if MG_ENABLE_FILE logs((const char *) buf, len); -#endif } static const char *s_spec = "2"; diff --git a/src/sock.c b/src/sock.c index 6bc7d974..7460ed57 100644 --- a/src/sock.c +++ b/src/sock.c @@ -19,6 +19,9 @@ #define MG_SOCK_ERRNO errno typedef Socket_t SOCKET; #define INVALID_SOCKET FREERTOS_INVALID_SOCKET +#elif MG_ARCH == MG_ARCH_TIRTOS +#define MG_SOCK_ERRNO errno +#define closesocket(x) close(x) #else #define MG_SOCK_ERRNO errno #ifndef closesocket @@ -182,6 +185,16 @@ static void mg_set_non_blocking_mode(SOCKET fd) { lwip_fcntl(fd, F_SETFL, O_NONBLOCK); #elif MG_ARCH == MG_ARCH_AZURERTOS fcntl(fd, F_SETFL, O_NONBLOCK); +#elif MG_ARCH == MG_ARCH_TIRTOS + int val = 0; + setsockopt(fd, 0, SO_BLOCKING, &val, sizeof(val)); + int status = 0; + int res = SockStatus(fd, FDSTATUS_SEND, &status); + if (res == 0 && status > 0) { + val = status / 2; + int val_size = sizeof(val); + res = SockSet(fd, SOL_SOCKET, SO_SNDLOWAT, &val, val_size); + } #else fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); // Non-blocking mode fcntl(fd, F_SETFD, FD_CLOEXEC); // Set close-on-exec @@ -299,7 +312,7 @@ static void close_conn(struct mg_connection *c) { } static void setsockopts(struct mg_connection *c) { -#if MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_AZURERTOS +#if MG_ARCH == MG_ARCH_FREERTOS_TCP || MG_ARCH == MG_ARCH_AZURERTOS || MG_ARCH == MG_ARCH_TIRTOS (void) c; #else int on = 1; @@ -340,6 +353,7 @@ void mg_connect_resolved(struct mg_connection *c) { mg_error(c, "connect: %d", MG_SOCK_ERRNO); } } + (void)rc; MG_DEBUG(("%lu %p", c->id, c->fd)); } @@ -365,7 +379,7 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) { if (MG_SOCK_ERRNO != EAGAIN) #endif MG_ERROR(("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO)); -#if ((MG_ARCH != MG_ARCH_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP)) +#if (MG_ARCH != MG_ARCH_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP) && (MG_ARCH != MG_ARCH_TIRTOS) } else if ((long) fd >= FD_SETSIZE) { MG_ERROR(("%ld > %ld", (long) fd, (long) FD_SETSIZE)); closesocket(fd);