Update Zephyr examples

This commit is contained in:
Sergio R. Caprile 2022-10-05 18:07:05 -03:00
parent 9c60a1bc10
commit d846e67ec1
28 changed files with 26641 additions and 73 deletions

View File

@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(http_server)
project(http_client)
#add_definitions(-DMG_ENABLE_LINES=1)
add_definitions(-DMG_ENABLE_MBEDTLS=1 -DMG_MBEDTLS_DEBUG_LEVEL=4)
target_sources(app PRIVATE src/main.c src/mongoose.c)

View File

@ -1,17 +1,59 @@
PROJECT_DIR ?= /mnt
ZEPHYR_DIR ?= /zephyrproject
BOARD ?= nucleo_f746zg
DOCKER ?= docker run -v $(realpath $(CURDIR)):/mnt mdashnet/zephyr
MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..)
DOCKER_PROJECT_DIR ?= /workdir
ZEPHYR_DIR ?= zephyrproject
PROJECT_NAME = $(notdir $(CURDIR))
PROJECT_PATH = $(realpath $(CURDIR))
ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR)
DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME)
DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR)
BOARD ?= qemu_x86
ifeq "$(BOARD)" "qemu_x86"
OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf
else
OVERLAY ?=
endif
SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb
SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host
DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH)
REPO ?= zephyrprojectrtos/ci
example:
true
build:
cp ../../../mongoose.c ../../../mongoose.h src/
$(DOCKER) /bin/sh -c 'cd $(ZEPHYR_DIR) && west build -b $(BOARD) -p auto $(PROJECT_DIR)'
cp $(MONGOOSE_ROOT)/mongoose.[c,h] src/
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \
west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build'
flash:
cd $(ZEPHYR_DIR) && west flash
run:
$(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build'
clean:
rm -rf */*/mongoose.*
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build'
pristine:
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build'
flash:
$(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west flash --build-dir $(DOCKER_PROJECT_PATH)/build'
debug:
$(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west debug --build-dir $(DOCKER_PROJECT_PATH)/build'
.PHONY: build flash zephyr clean pristine run
zephyr:
ifeq ($(wildcard $(ZEPHYR_PATH)/.*),)
mkdir $(ZEPHYR_PATH)
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)'
endif
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update'

View File

@ -0,0 +1 @@
../README.md

View File

@ -0,0 +1,7 @@
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_QEMU_ETHERNET=y
CONFIG_ETH_QEMU_IFACE_NAME="tap0"
CONFIG_PCIE=y
#CONFIG_ETHERNET_LOG_LEVEL_DBG=y

View File

@ -8,6 +8,7 @@ CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POLL_MAX=32
CONFIG_POSIX_MAX_FDS=32
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_LOG=y
CONFIG_LOG=y
@ -27,4 +28,4 @@ CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=131072
CONFIG_PRINTK=y
CONFIG_MBEDTLS_DEBUG=y
CONFIG_MBEDTLS_DEBUG_LEVEL=4
CONFIG_MBEDTLS_LOG_LEVEL_DBG=y

View File

@ -11,6 +11,7 @@ static const char *s_post_data = NULL; // POST data
static const int64_t s_timeout_ms = 1500; // Connect timeout in milliseconds
struct mg_mgr s_mgr;
static int s_connected = 0;
static bool done = false;
// Print HTTP response and signal that we're done
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
@ -54,25 +55,23 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
}
}
// We have no valid system time(), and we need it for TLS. Implement it
time_t time(time_t *tp) {
time_t t = s_boot_timestamp + k_uptime_get() / 1000;
// example system time()-like function
time_t ourtime(time_t *tp) {
time_t t = s_boot_timestamp + mg_millis() / 1000;
if (tp != NULL) *tp = t;
return t;
}
// SNTP callback. Modifies s_boot_timestamp, to make time() correct
// SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct
static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_SNTP_TIME) {
int64_t t = *(int64_t *) ev_data;
MG_INFO(("Got SNTP time: %lld ms from epoch", t));
s_boot_timestamp = (time_t) ((t - mg_millis()) / 1000);
// We need correct time in order to get HTTPs working, therefore,
// making https request from SMTP callback
if (!s_connected) {
MG_INFO(("Connecting to : [%s]", s_url));
mg_http_connect(&s_mgr, s_url, fn, NULL); // Create client connection
mg_http_connect(&s_mgr, s_url, fn, &done); // Create client connection
s_connected = 1;
}
} else if (ev == MG_EV_CLOSE) {
@ -87,17 +86,33 @@ static void timer_fn(void *arg) {
if (s_boot_timestamp < 9999) mg_sntp_request(s_sntp_conn);
}
// Zephyr: Define a semaphore and network management callback to be able to wait
// until our IP address is ready. The main function will start and block on this
// semaphore until this event handler releases it when the network is ready
K_SEM_DEFINE(run, 0, 1);
static void zeh(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
struct net_if *iface) {
if (mgmt_event == NET_EVENT_L4_CONNECTED) k_sem_give(&run);
}
int main(int argc, char *argv[]) {
// Zephyr: Register the network management callback and block on the semaphore
struct net_mgmt_event_callback ncb;
net_mgmt_init_event_callback(&ncb, zeh, NET_EVENT_L4_CONNECTED);
net_mgmt_add_event_callback(&ncb);
k_sem_take(&run, K_FOREVER);
mg_log_set(MG_LL_DEBUG);
mg_mgr_init(&s_mgr);
mg_timer_add(&s_mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn,
&s_mgr);
// Start infinite event loop
// Start event loop, exit when client is done
MG_INFO(("Mongoose version : v%s", MG_VERSION));
for (;;) mg_mgr_poll(&s_mgr, 1000);
while (!done) mg_mgr_poll(&s_mgr, 1000);
mg_mgr_free(&s_mgr);
return 0;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,13 @@
PROJECT_DIR ?= /workdir
MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..)
DOCKER_PROJECT_DIR ?= /workdir
ZEPHYR_DIR ?= zephyrproject
BOARD ?= qemu_x86
PROJECT_NAME = $(notdir $(CURDIR))
PROJECT_PATH = $(realpath $(CURDIR))
ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR)
DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME)
DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR)
BOARD ?= qemu_x86
ifeq "$(BOARD)" "qemu_x86"
OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf
else
@ -10,7 +16,7 @@ endif
SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb
SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host
DOCKER ?= docker run --rm -v $(realpath $(CURDIR)):$(PROJECT_DIR)
DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH)
REPO ?= zephyrprojectrtos/ci
@ -18,35 +24,36 @@ example:
true
build:
cp ../../../mongoose.[c,h] src/
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR)/zephyr && \
west build -b $(BOARD) -p auto $(PROJECT_DIR) $(OVERLAY) --build-dir $(PROJECT_DIR)/build'
cp $(MONGOOSE_ROOT)/mongoose.[c,h] src/
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \
west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build'
run:
$(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west build -t run --build-dir $(PROJECT_DIR)/build'
$(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build'
clean:
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west build -t clean --build-dir $(PROJECT_DIR)/build'
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build'
pristine:
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west build -t pristine --build-dir $(PROJECT_DIR)/build'
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build'
flash:
$(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west flash --build-dir $(PROJECT_DIR)/build'
$(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west flash --build-dir $(DOCKER_PROJECT_PATH)/build'
debug:
$(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && \
west debug --build-dir $(PROJECT_DIR)/build'
$(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west debug --build-dir $(DOCKER_PROJECT_PATH)/build'
.PHONY: build flash zephyr clean pristine run
zephyr:
ifeq ($(wildcard $(ZEPHYR_DIR)/.*),)
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR) && west init ./$(ZEPHYR_DIR)'
zephyr:
ifeq ($(wildcard $(ZEPHYR_PATH)/.*),)
mkdir $(ZEPHYR_PATH)
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)'
endif
$(DOCKER) $(REPO) /bin/sh -c 'cd $(PROJECT_DIR)/$(ZEPHYR_DIR) && west update'
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update'

View File

@ -0,0 +1,7 @@
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_QEMU_ETHERNET=y
CONFIG_ETH_QEMU_IFACE_NAME="tap0"
CONFIG_PCIE=y
#CONFIG_ETHERNET_LOG_LEVEL_DBG=y

View File

@ -43,14 +43,14 @@ static void wcb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
}
}
// We have no valid system time(), and we need it for TLS. Implement it
time_t time(time_t *tp) {
time_t t = s_boot_timestamp + k_uptime_get() / 1000;
// example system time()-like function
time_t ourtime(time_t *tp) {
time_t t = s_boot_timestamp + mg_millis() / 1000;
if (tp != NULL) *tp = t;
return t;
}
// SNTP callback. Modifies s_boot_timestamp, to make time() correct
// SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct
static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_SNTP_TIME) {
int64_t t = *(int64_t *) ev_data;

View File

@ -5614,6 +5614,7 @@ uint64_t mg_millis(void) {
}
#endif
#ifdef MG_ENABLE_LINES
#line 1 "src/ws.c"
#endif

View File

@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(http_server)
project(mqtt_aws_client)
#add_definitions(-DMG_ENABLE_LINES=1)
add_definitions(-DMG_ENABLE_MBEDTLS=1 -DMG_MBEDTLS_DEBUG_LEVEL=4)
target_sources(app PRIVATE src/main.c src/mongoose.c)

View File

@ -1,17 +1,59 @@
PROJECT_DIR ?= /mnt
ZEPHYR_DIR ?= /zephyrproject
BOARD ?= nucleo_f746zg
DOCKER ?= docker run -v $(realpath $(CURDIR)):/mnt mdashnet/zephyr
MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..)
DOCKER_PROJECT_DIR ?= /workdir
ZEPHYR_DIR ?= zephyrproject
PROJECT_NAME = $(notdir $(CURDIR))
PROJECT_PATH = $(realpath $(CURDIR))
ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR)
DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME)
DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR)
BOARD ?= qemu_x86
ifeq "$(BOARD)" "qemu_x86"
OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf
else
OVERLAY ?=
endif
SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb
SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host
DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH)
REPO ?= zephyrprojectrtos/ci
example:
true
build:
cp ../../../mongoose.c ../../../mongoose.h src/
$(DOCKER) /bin/sh -c 'cd $(ZEPHYR_DIR) && west build -b $(BOARD) -p auto $(PROJECT_DIR)'
cp $(MONGOOSE_ROOT)/mongoose.[c,h] src/
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \
west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build'
flash:
cd $(ZEPHYR_DIR) && west flash
run:
$(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build'
clean:
rm -rf */*/mongoose.*
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build'
pristine:
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build'
flash:
$(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west flash --build-dir $(DOCKER_PROJECT_PATH)/build'
debug:
$(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west debug --build-dir $(DOCKER_PROJECT_PATH)/build'
.PHONY: build flash zephyr clean pristine run
zephyr:
ifeq ($(wildcard $(ZEPHYR_PATH)/.*),)
mkdir $(ZEPHYR_PATH)
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)'
endif
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update'

View File

@ -0,0 +1 @@
../README.md

View File

@ -0,0 +1,7 @@
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_QEMU_ETHERNET=y
CONFIG_ETH_QEMU_IFACE_NAME="tap0"
CONFIG_PCIE=y
#CONFIG_ETHERNET_LOG_LEVEL_DBG=y

View File

@ -8,6 +8,7 @@ CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POLL_MAX=32
CONFIG_POSIX_MAX_FDS=32
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_LOG=y
CONFIG_LOG=y
@ -27,4 +28,4 @@ CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=131072
CONFIG_PRINTK=y
CONFIG_MBEDTLS_DEBUG=y
CONFIG_MBEDTLS_DEBUG_LEVEL=4
CONFIG_MBEDTLS_LOG_LEVEL_DBG=y

View File

@ -50,14 +50,14 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
}
}
// We have no valid system time(), and we need it for TLS. Implement it
time_t time(time_t *tp) {
time_t t = s_boot_timestamp + k_uptime_get() / 1000;
// example system time()-like function
time_t ourtime(time_t *tp) {
time_t t = s_boot_timestamp + mg_millis() / 1000;
if (tp != NULL) *tp = t;
return t;
}
// SNTP callback. Modifies s_boot_timestamp, to make time() correct
// SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct
static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_SNTP_TIME) {
int64_t t = *(int64_t *) ev_data;
@ -85,7 +85,23 @@ static void timer_fn(void *arg) {
if (s_boot_timestamp < 9999) mg_sntp_request(s_sntp_conn);
}
// Zephyr: Define a semaphore and network management callback to be able to wait
// until our IP address is ready. The main function will start and block on this
// semaphore until this event handler releases it when the network is ready
K_SEM_DEFINE(run, 0, 1);
static void zeh(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
struct net_if *iface) {
if (mgmt_event == NET_EVENT_L4_CONNECTED) k_sem_give(&run);
}
int main(int argc, char *argv[]) {
// Zephyr: Register the network management callback and block on the semaphore
struct net_mgmt_event_callback ncb;
net_mgmt_init_event_callback(&ncb, zeh, NET_EVENT_L4_CONNECTED);
net_mgmt_add_event_callback(&ncb);
k_sem_take(&run, K_FOREVER);
mg_log_set(MG_LL_DEBUG);
mg_mgr_init(&mgr);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(http_server)
project(websocket_server)
#add_definitions(-DMG_ENABLE_LINES=1)
add_definitions(-DMG_ENABLE_MBEDTLS=1)
target_sources(app PRIVATE src/main.c src/mongoose.c)

View File

@ -1,17 +1,59 @@
PROJECT_DIR ?= /mnt
ZEPHYR_DIR ?= /zephyrproject
BOARD ?= nucleo_f746zg
DOCKER ?= docker run -v $(realpath $(CURDIR)):/mnt mdashnet/zephyr
MONGOOSE_ROOT ?= $(realpath $(CURDIR)/../../..)
DOCKER_PROJECT_DIR ?= /workdir
ZEPHYR_DIR ?= zephyrproject
PROJECT_NAME = $(notdir $(CURDIR))
PROJECT_PATH = $(realpath $(CURDIR))
ZEPHYR_PATH = $(realpath $(CURDIR)/..)/$(ZEPHYR_DIR)
DOCKER_PROJECT_PATH = $(DOCKER_PROJECT_DIR)/$(PROJECT_NAME)
DOCKER_ZEPHYR_PATH = $(DOCKER_PROJECT_DIR)/$(ZEPHYR_DIR)
BOARD ?= qemu_x86
ifeq "$(BOARD)" "qemu_x86"
OVERLAY ?= -DOVERLAY_CONFIG=overlay-e1000.conf
else
OVERLAY ?=
endif
SHAREUSB ?= --privileged -v /dev/bus/usb/:/dev/bus/usb
SHARETUN ?= --cap-add=NET_ADMIN --device /dev/net/tun --net=host
DOCKER ?= docker run --rm -v $(PROJECT_PATH):$(DOCKER_PROJECT_PATH) -v $(ZEPHYR_PATH):$(DOCKER_ZEPHYR_PATH)
REPO ?= zephyrprojectrtos/ci
example:
true
build:
cp ../../../mongoose.c ../../../mongoose.h src/
$(DOCKER) /bin/sh -c 'cd $(ZEPHYR_DIR) && west build -b $(BOARD) -p auto $(PROJECT_DIR)'
cp $(MONGOOSE_ROOT)/mongoose.[c,h] src/
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH)/zephyr && \
west build -b $(BOARD) -p auto $(DOCKER_PROJECT_PATH) $(OVERLAY) --build-dir $(DOCKER_PROJECT_PATH)/build'
flash:
cd $(ZEPHYR_DIR) && west flash
run:
$(DOCKER) -it $(SHARETUN) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t run --build-dir $(DOCKER_PROJECT_PATH)/build'
clean:
rm -rf */*/mongoose.*
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t clean --build-dir $(DOCKER_PROJECT_PATH)/build'
pristine:
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west build -t pristine --build-dir $(DOCKER_PROJECT_PATH)/build'
flash:
$(DOCKER) $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west flash --build-dir $(DOCKER_PROJECT_PATH)/build'
debug:
$(DOCKER) -it $(SHAREUSB) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && \
west debug --build-dir $(DOCKER_PROJECT_PATH)/build'
.PHONY: build flash zephyr clean pristine run
zephyr:
ifeq ($(wildcard $(ZEPHYR_PATH)/.*),)
mkdir $(ZEPHYR_PATH)
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_PROJECT_DIR) && west init ./$(ZEPHYR_DIR)'
endif
$(DOCKER) $(REPO) /bin/sh -c 'cd $(DOCKER_ZEPHYR_PATH) && west update'

View File

@ -0,0 +1 @@
../README.md

View File

@ -0,0 +1,7 @@
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_QEMU_ETHERNET=y
CONFIG_ETH_QEMU_IFACE_NAME="tap0"
CONFIG_PCIE=y
#CONFIG_ETHERNET_LOG_LEVEL_DBG=y

View File

@ -8,6 +8,7 @@ CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POLL_MAX=32
CONFIG_POSIX_MAX_FDS=32
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_LOG=y
CONFIG_LOG=y

View File

@ -32,19 +32,20 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
} else if (ev == MG_EV_WS_MSG) {
// Got websocket frame. Received data is wm->data. Echo it back!
struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;
MG_INFO(("Got wm: %p, data: %p, %d = %*.s", wm, wm->data.ptr, wm->data.len, wm->data.len, wm->data.ptr));
mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT);
}
(void) fn_data;
}
// We have no valid system time(), and we need it for TLS. Implement it
time_t time(time_t *tp) {
time_t t = s_boot_timestamp + k_uptime_get() / 1000;
// example system time()-like function
time_t ourtime(time_t *tp) {
time_t t = s_boot_timestamp + mg_millis() / 1000;
if (tp != NULL) *tp = t;
return t;
}
// SNTP callback. Modifies s_boot_timestamp, to make time() correct
// SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct
static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_SNTP_TIME) {
int64_t t = *(int64_t *) ev_data;
@ -62,7 +63,23 @@ static void timer_fn(void *arg) {
if (s_boot_timestamp < 9999) mg_sntp_request(s_sntp_conn);
}
// Zephyr: Define a semaphore and network management callback to be able to wait
// until our IP address is ready. The main function will start and block on this
// semaphore until this event handler releases it when the network is ready
K_SEM_DEFINE(run, 0, 1);
static void zeh(struct net_mgmt_event_callback *cb, uint32_t mgmt_event,
struct net_if *iface) {
if (mgmt_event == NET_EVENT_L4_CONNECTED) k_sem_give(&run);
}
int main(int argc, char *argv[]) {
// Zephyr: Register the network management callback and block on the semaphore
struct net_mgmt_event_callback ncb;
net_mgmt_init_event_callback(&ncb, zeh, NET_EVENT_L4_CONNECTED);
net_mgmt_add_event_callback(&ncb);
k_sem_take(&run, K_FOREVER);
struct mg_mgr mgr;
mg_mgr_init(&mgr);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff