Added FreeRTOS-Plus-TCP.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
84d34b6e62
commit
95ab96c39f
|
@ -7,3 +7,6 @@
|
||||||
[submodule "lib/esp_nano_hosted"]
|
[submodule "lib/esp_nano_hosted"]
|
||||||
path = lib/esp_nano_hosted
|
path = lib/esp_nano_hosted
|
||||||
url = https://git.minori.work/Embedded_Drivers/esp_nano_hosted.git
|
url = https://git.minori.work/Embedded_Drivers/esp_nano_hosted.git
|
||||||
|
[submodule "lib/freertos_plus_tcp/FreeRTOS-Plus-TCP"]
|
||||||
|
path = lib/freertos_plus_tcp/FreeRTOS-Plus-TCP
|
||||||
|
url = https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
[
|
|
||||||
{
|
|
||||||
"name": "ARM GNU Embedded Toolchain",
|
|
||||||
"toolchainFile": "${workspaceRoot}/arm-none-eabi.cmake"
|
|
||||||
}
|
|
||||||
]
|
|
|
@ -1,51 +0,0 @@
|
||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Launch debug in FLASH",
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"executable": "cmake-build-Debug/lpcxpresso_55s69_template_FLASH.elf",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "cortex-debug",
|
|
||||||
"runToEntryPoint": "main",
|
|
||||||
"showDevDebugOutput": "none",
|
|
||||||
"servertype": "pyocd",
|
|
||||||
"serverArgs": [
|
|
||||||
"-t",
|
|
||||||
"lpc55s69"
|
|
||||||
],
|
|
||||||
"numberOfProcessors": 2,
|
|
||||||
"targetProcessor":0,
|
|
||||||
"gdbPath": "arm-none-eabi-gdb"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Launch debug in SRAM",
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"executable": "cmake-build-Debug/lpcxpresso_55s69_template_RAM.elf",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "cortex-debug",
|
|
||||||
"runToEntryPoint": "main",
|
|
||||||
"servertype": "pyocd",
|
|
||||||
"serverArgs": [
|
|
||||||
"-t",
|
|
||||||
"lpc55s69"
|
|
||||||
],
|
|
||||||
"numberOfProcessors": 2,
|
|
||||||
"targetProcessor":0,
|
|
||||||
"gdbPath": "arm-none-eabi-gdb",
|
|
||||||
"overrideLaunchCommands": [
|
|
||||||
"-interpreter-exec console \"monitor reset halt\"",
|
|
||||||
"-target-download",
|
|
||||||
"-enable-pretty-printing"
|
|
||||||
],
|
|
||||||
"overrideRestartCommands": [
|
|
||||||
"-interpreter-exec console \"monitor reset halt\"",
|
|
||||||
"-target-download",
|
|
||||||
"-enable-pretty-printing"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
|
||||||
}
|
|
|
@ -68,6 +68,8 @@ set(TARGET_C_DEFINES
|
||||||
"CPU_LPC55S69JBD100_cm33_core0"
|
"CPU_LPC55S69JBD100_cm33_core0"
|
||||||
"FFR_INCLUDE=\"fsl_iap_ffr.h\""
|
"FFR_INCLUDE=\"fsl_iap_ffr.h\""
|
||||||
"MCUXPRESSO_SDK"
|
"MCUXPRESSO_SDK"
|
||||||
|
"PRINTF_FLOAT_ENABLE"
|
||||||
|
"PRINTF_ADVANCED_ENABLE"
|
||||||
"SDK_OS_FREE_RTOS"
|
"SDK_OS_FREE_RTOS"
|
||||||
"SERIAL_PORT_TYPE_UART=1"
|
"SERIAL_PORT_TYPE_UART=1"
|
||||||
"__STARTUP_CLEAR_BSS"
|
"__STARTUP_CLEAR_BSS"
|
||||||
|
@ -90,6 +92,7 @@ set(TARGET_LIBS
|
||||||
"c"
|
"c"
|
||||||
"esp_nano_hosted"
|
"esp_nano_hosted"
|
||||||
"freertos_kernel"
|
"freertos_kernel"
|
||||||
|
"freertos_plus_tcp"
|
||||||
"fro_calib_hardabi"
|
"fro_calib_hardabi"
|
||||||
"m"
|
"m"
|
||||||
"nosys"
|
"nosys"
|
||||||
|
@ -126,6 +129,9 @@ set(FREERTOS_PORT "GCC_ARM_CM33_NTZ_NONSECURE" CACHE STRING "")
|
||||||
set(FREERTOS_HEAP "4" CACHE STRING "")
|
set(FREERTOS_HEAP "4" CACHE STRING "")
|
||||||
add_subdirectory(lib/freertos)
|
add_subdirectory(lib/freertos)
|
||||||
|
|
||||||
|
set(FREERTOS_PLUS_IP_CONFIG_DIRECTORY "${CMAKE_SOURCE_DIR}/include" CACHE STRING "")
|
||||||
|
add_subdirectory(lib/freertos_plus_tcp)
|
||||||
|
|
||||||
# Shared sources, includes and definitions
|
# Shared sources, includes and definitions
|
||||||
add_compile_definitions(${TARGET_C_DEFINES})
|
add_compile_definitions(${TARGET_C_DEFINES})
|
||||||
include_directories(${TARGET_C_INCLUDES})
|
include_directories(${TARGET_C_INCLUDES})
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef FREERTOS_IP_CONFIG_H
|
||||||
|
#define FREERTOS_IP_CONFIG_H
|
||||||
|
|
||||||
|
/* Constants Affecting the TCP/IP Stack Task Execution Behaviour */
|
||||||
|
#define ipconfigIP_TASK_PRIORITY 2
|
||||||
|
|
||||||
|
/* Hardware and Driver Specific Settings */
|
||||||
|
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
|
||||||
|
#define ipconfigNETWORK_MTU 1526
|
||||||
|
|
||||||
|
/* TCP Specific Constants */
|
||||||
|
#define ipconfigTCP_MSS 1460
|
||||||
|
#define ipconfigTCP_RX_BUFFER_LENGTH (16 * ipconfigTCP_MSS)
|
||||||
|
#define ipconfigTCP_TX_BUFFER_LENGTH (16 * ipconfigTCP_MSS)
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,10 +1,11 @@
|
||||||
#ifndef APP_NH_IMPL_H
|
#ifndef APP_NH_IMPL_H
|
||||||
#define APP_NH_IMPL_H
|
#define APP_NH_IMPL_H
|
||||||
|
|
||||||
#include "nh_shared_if.h"
|
|
||||||
#include "nh_ctrl_api.h"
|
#include "nh_ctrl_api.h"
|
||||||
|
#include "nh_shared_if.h"
|
||||||
|
|
||||||
extern nh_ctrl_api_t g_nh_ctrl_api;
|
extern nh_ctrl_api_t g_nh_ctrl_api;
|
||||||
|
extern nh_shared_if_t g_nh_shared_if;
|
||||||
|
|
||||||
int app_nh_impl_init(void);
|
int app_nh_impl_init(void);
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9add7e515b450d4cb1ba5e369d59004ff661e6a2
|
Subproject commit 60a5a9fb07c3a0215cc9dede4a3507be4b48c5ef
|
|
@ -0,0 +1,42 @@
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
project(freertos_plus_tcp)
|
||||||
|
|
||||||
|
if(NOT DEFINED FREERTOS_PLUS_IP_CONFIG_DIRECTORY)
|
||||||
|
message(WARNING "FREERTOS_PLUS_IP_CONFIG_DIRECTORY not defined")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(F_TCP_SOURCES
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_ARP.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_DHCP.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_DNS.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_DNS_Cache.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_DNS_Callback.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_DNS_Networking.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_DNS_Parser.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_ICMP.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_IP.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_IP_Timers.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_IP_Utils.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_Sockets.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_Stream_Buffer.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_IP.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Reception.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_State_Handling.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Transmission.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_Utils.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_TCP_WIN.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_Tiny_TCP.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/FreeRTOS_UDP_IP.c"
|
||||||
|
"FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_2.c"
|
||||||
|
)
|
||||||
|
|
||||||
|
set(F_TCP_INCLUDES
|
||||||
|
"FreeRTOS-Plus-TCP/source/include"
|
||||||
|
"FreeRTOS-Plus-TCP/source/portable/Compiler/GCC"
|
||||||
|
${FREERTOS_PLUS_IP_CONFIG_DIRECTORY}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} ${F_TCP_SOURCES})
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC ${F_TCP_INCLUDES})
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE "freertos_kernel")
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit b65c139a4ebffdcdf8d92cee68c5a7aa8777aade
|
|
@ -69,7 +69,7 @@ static nh_osa_t s_nh_osa = {
|
||||||
.queue_destroy = app_impl_queue_destroy,
|
.queue_destroy = app_impl_queue_destroy,
|
||||||
};
|
};
|
||||||
|
|
||||||
static nh_shared_if_t s_nh_shared_if = {
|
nh_shared_if_t g_nh_shared_if = {
|
||||||
.osa = &s_nh_osa,
|
.osa = &s_nh_osa,
|
||||||
.ops =
|
.ops =
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,7 @@ static nh_shared_if_t s_nh_shared_if = {
|
||||||
|
|
||||||
nh_ctrl_api_t g_nh_ctrl_api = {
|
nh_ctrl_api_t g_nh_ctrl_api = {
|
||||||
.osa = &s_nh_osa,
|
.osa = &s_nh_osa,
|
||||||
.shared_if = &s_nh_shared_if,
|
.shared_if = &g_nh_shared_if,
|
||||||
.cb =
|
.cb =
|
||||||
{
|
{
|
||||||
.init = app_nh_impl_cb_init,
|
.init = app_nh_impl_cb_init,
|
||||||
|
@ -106,11 +106,11 @@ int app_nh_impl_init(void) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nh_shared_if_init(&s_nh_shared_if) != NH_RET_SUCCESS) {
|
if (nh_shared_if_init(&g_nh_shared_if) != NH_RET_SUCCESS) {
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xTaskCreate(app_nh_impl_shared_if_task, "NH_SHARED_IF", 512, &s_nh_shared_if, 2, NULL) != pdPASS) {
|
if (xTaskCreate(app_nh_impl_shared_if_task, "NH_IF", 512, &g_nh_shared_if, 2, NULL) != pdPASS) {
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ static int app_nh_impl_pin_init(void) {
|
||||||
PINT_Init(PINT);
|
PINT_Init(PINT);
|
||||||
|
|
||||||
PINT_PinInterruptConfig(PINT, kPINT_PinInt0, kPINT_PinIntEnableRiseEdge, app_nh_impl_hs_callback);
|
PINT_PinInterruptConfig(PINT, kPINT_PinInt0, kPINT_PinIntEnableRiseEdge, app_nh_impl_hs_callback);
|
||||||
PINT_EnableCallbackByIndex(PINT, kPINT_PinInt1);
|
PINT_EnableCallbackByIndex(PINT, kPINT_PinInt0);
|
||||||
|
|
||||||
PINT_PinInterruptConfig(PINT, kPINT_PinInt1, kPINT_PinIntEnableRiseEdge, app_nh_impl_drdy_callback);
|
PINT_PinInterruptConfig(PINT, kPINT_PinInt1, kPINT_PinIntEnableRiseEdge, app_nh_impl_drdy_callback);
|
||||||
PINT_EnableCallbackByIndex(PINT, kPINT_PinInt1);
|
PINT_EnableCallbackByIndex(PINT, kPINT_PinInt1);
|
||||||
|
@ -182,14 +182,14 @@ static inline bool app_nh_impl_is_isr(void) {
|
||||||
static void app_nh_impl_drdy_callback(pint_pin_int_t pintr, uint32_t pmatch_status) {
|
static void app_nh_impl_drdy_callback(pint_pin_int_t pintr, uint32_t pmatch_status) {
|
||||||
/* If there's a packet to be received by host, the DRDY is set high. */
|
/* If there's a packet to be received by host, the DRDY is set high. */
|
||||||
if (GPIO_PinRead(GPIO, BOARD_INITMIKROEPINS_ESP_HS_PORT, BOARD_INITMIKROEPINS_ESP_HS_PIN)) {
|
if (GPIO_PinRead(GPIO, BOARD_INITMIKROEPINS_ESP_HS_PORT, BOARD_INITMIKROEPINS_ESP_HS_PIN)) {
|
||||||
nh_shared_if_inject_data_ready(&s_nh_shared_if);
|
nh_shared_if_inject_data_ready(&g_nh_shared_if);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_nh_impl_hs_callback(pint_pin_int_t pintr, uint32_t pmatch_status) {
|
static void app_nh_impl_hs_callback(pint_pin_int_t pintr, uint32_t pmatch_status) {
|
||||||
/* If the DRDY is high when HS rises, there's another packet waiting... */
|
/* If the DRDY is high when HS rises, there's another packet waiting... */
|
||||||
if (GPIO_PinRead(GPIO, BOARD_INITMIKROEPINS_ESP_DRDY_PORT, BOARD_INITMIKROEPINS_ESP_DRDY_PIN)) {
|
if (GPIO_PinRead(GPIO, BOARD_INITMIKROEPINS_ESP_DRDY_PORT, BOARD_INITMIKROEPINS_ESP_DRDY_PIN)) {
|
||||||
nh_shared_if_inject_data_ready(&s_nh_shared_if);
|
nh_shared_if_inject_data_ready(&g_nh_shared_if);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ static nh_ret_t app_nh_impl_ops_xfer(void *handle, uint8_t *tx_data, uint8_t *rx
|
||||||
}
|
}
|
||||||
|
|
||||||
static void app_nh_impl_cb_startup(void *handle, nh_event_init_t *init_data) {
|
static void app_nh_impl_cb_startup(void *handle, nh_event_init_t *init_data) {
|
||||||
PRINTF("Received [INIT] event from ESP..\r\n");
|
PRINTF("Received init data and device capabilities from ESP:\r\n");
|
||||||
|
|
||||||
char *buf;
|
char *buf;
|
||||||
switch (init_data->chip_id) {
|
switch (init_data->chip_id) {
|
||||||
|
@ -436,7 +436,7 @@ static nh_ret_t app_impl_queue_destroy(void *handle, nh_osa_queue_t queue) {
|
||||||
|
|
||||||
static void app_nh_impl_shared_if_task(void *parameters) {
|
static void app_nh_impl_shared_if_task(void *parameters) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
nh_shared_if_task(&s_nh_shared_if);
|
nh_shared_if_task(&g_nh_shared_if);
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
|
|
50
src/main.c
50
src/main.c
|
@ -14,9 +14,14 @@
|
||||||
/* Private */
|
/* Private */
|
||||||
#include "app_nh_impl.h"
|
#include "app_nh_impl.h"
|
||||||
|
|
||||||
|
#define APP_DEFAULT_WIFI_SSID "Home-Dev_2"
|
||||||
|
#define APP_DEFAULT_WIFI_PASS "qwer1234"
|
||||||
|
|
||||||
static void initialization_task(void *params);
|
static void initialization_task(void *params);
|
||||||
|
|
||||||
static void report_mac_addresses(void);
|
static void report_mac_addresses(void);
|
||||||
|
static void scan_ap(void);
|
||||||
|
static void connect_default_wifi(void);
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
BOARD_InitBootPins();
|
BOARD_InitBootPins();
|
||||||
|
@ -46,11 +51,13 @@ static void initialization_task(void *params) {
|
||||||
PRINTF("Initialization task running...\r\n");
|
PRINTF("Initialization task running...\r\n");
|
||||||
|
|
||||||
/* Do initialization stuff here, since the scheduler is running now. */
|
/* Do initialization stuff here, since the scheduler is running now. */
|
||||||
if(app_nh_impl_init() != 0) {
|
if (app_nh_impl_init() != 0) {
|
||||||
PRINTF("Failed to init nano_hosted\r\n");
|
PRINTF("Failed to init nano_hosted\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
report_mac_addresses();
|
report_mac_addresses();
|
||||||
|
scan_ap();
|
||||||
|
connect_default_wifi();
|
||||||
|
|
||||||
PRINTF("Initialization completed, INIT task exit.\r\n");
|
PRINTF("Initialization completed, INIT task exit.\r\n");
|
||||||
|
|
||||||
|
@ -70,4 +77,45 @@ static void report_mac_addresses(void) {
|
||||||
} else {
|
} else {
|
||||||
PRINTF("AP mode MAC address: %s\r\n", mac_addr);
|
PRINTF("AP mode MAC address: %s\r\n", mac_addr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void scan_ap_callback(void *handle, nh_ctrl_ap_scan_item_t *item) {
|
||||||
|
PRINTF("AP: [%s]\r\nBSSID: %s\tSig: %lddB\tCH: %lu\r\n", item->ssid, item->bssid, item->rssi, item->channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void scan_ap(void) {
|
||||||
|
PRINTF("Scanning AP...\r\n");
|
||||||
|
if (nh_ctrl_api_get_ap_scan_list(&g_nh_ctrl_api, scan_ap_callback) != NH_RET_SUCCESS) {
|
||||||
|
PRINTF("Failed to scan AP list.\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
PRINTF("AP scan completed.\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void connect_default_wifi(void) {
|
||||||
|
char mac_addr[NH_CTRL_API_MAC_LENGTH + 1];
|
||||||
|
|
||||||
|
nh_ctrl_ap_conn_result_t result = {
|
||||||
|
.mac_addr = mac_addr,
|
||||||
|
};
|
||||||
|
|
||||||
|
nh_ctrl_ap_conn_params_t param = {
|
||||||
|
.ssid = APP_DEFAULT_WIFI_SSID,
|
||||||
|
.password = APP_DEFAULT_WIFI_PASS,
|
||||||
|
.bssid = "",
|
||||||
|
.wpa3_supported = false,
|
||||||
|
.listen_interval = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
PRINTF("Connecting to AP: %s\r\n", APP_DEFAULT_WIFI_SSID);
|
||||||
|
|
||||||
|
if (nh_ctrl_api_connect_ap(&g_nh_ctrl_api, ¶m, &result) != NH_RET_SUCCESS) {
|
||||||
|
PRINTF("Failed to connect to AP.\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status != NH_CTRL_CONNECT_SUCCESS) {
|
||||||
|
PRINTF("Connect to AP failed with result: %d\r\n", result.status);
|
||||||
|
} else {
|
||||||
|
PRINTF("Connected to AP: %s, MAC address: %s\r\n", APP_DEFAULT_WIFI_SSID, result.mac_addr);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue