From ffa89d033b08cf2a63bfcbd93a5e6c5fca6279fe Mon Sep 17 00:00:00 2001 From: OldManSteve Date: Thu, 9 Nov 2023 12:48:34 +0800 Subject: [PATCH] frontend sys freertos working --- frtos/frontend/CMakeLists.txt | 5 +- frtos/frontend/frontend.c | 70 +++++++++----- frtos/frontend/lwipopts.h | 102 +++++---------------- frtos/frontend/lwipopts_examples_common.h | 90 ++++++++++++++++++ frtos/frontend/makefsdata.exe | Bin 265302 -> 265302 bytes frtos/frontend/makefsdata.py | 106 ---------------------- 6 files changed, 160 insertions(+), 213 deletions(-) create mode 100644 frtos/frontend/lwipopts_examples_common.h delete mode 100644 frtos/frontend/makefsdata.py diff --git a/frtos/frontend/CMakeLists.txt b/frtos/frontend/CMakeLists.txt index 5edf451..37850db 100644 --- a/frtos/frontend/CMakeLists.txt +++ b/frtos/frontend/CMakeLists.txt @@ -24,8 +24,9 @@ target_link_libraries( frontend hardware_adc pico_stdlib - #FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap - pico_cyw43_arch_lwip_threadsafe_background + FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap + #pico_cyw43_arch_lwip_threadsafe_background + pico_cyw43_arch_lwip_sys_freertos pico_lwip_http ) diff --git a/frtos/frontend/frontend.c b/frtos/frontend/frontend.c index 10ffb7f..423c7e9 100644 --- a/frtos/frontend/frontend.c +++ b/frtos/frontend/frontend.c @@ -5,9 +5,9 @@ #include "ssi.h" #include "cgi.h" #include "lwip/inet.h" -//#include "FreeRTOS.h" -//#include "task.h" -#include "lwip/sockets.h" +#include "FreeRTOS.h" +#include "task.h" +//#include "lwip/sockets.h" // WIFI Credentials - take care if pushing to GitHub! const char WIFI_SSID[] = "XXX"; @@ -23,34 +23,54 @@ void print_ip_address() { } } -int main() { - stdio_init_all(); - - cyw43_arch_init(); - - cyw43_arch_enable_sta_mode(); - - // Connect to the WiFI network - loop until connected - while(cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000) != 0){ - printf("Attempting to connect...\n"); - } - // Print a success message once connected - printf("Connected! \n"); - - // Print the assigned IP address - print_ip_address(); - +static void webserver_run(){ // Initialize web server httpd_init(); printf("Http server initialized\n"); // Configure SSI and CGI handler - ssi_init(); + ssi_init(); printf("SSI Handler initialized\n"); cgi_init(); printf("CGI Handler initialized\n"); - - // Infinite loop - while(1); -} \ No newline at end of file + // Infinite loop + while (1) { + // Add any required delay or use other FreeRTOS features here if needed + vTaskDelay(pdMS_TO_TICKS(1000)); + } +} +static void webserver_task(){ + if (cyw43_arch_init()) + { + printf("failed to initialise\n"); + return; + } + + cyw43_arch_enable_sta_mode(); + + printf("Connecting to WiFi...\n"); + + // Connect to the WiFI network - loop until connected + while (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000) != 0) { + printf("Attempting to connect...\n"); + } + // Print a success message once connected + printf("Connected! \n"); + print_ip_address(); + + webserver_run(); + cyw43_arch_deinit(); +} +int main() { + stdio_init_all(); + + // Create the FreeRTOS task for the web server + TaskHandle_t task_handle; + xTaskCreate(webserver_task, "WebServerTask", configMINIMAL_STACK_SIZE, NULL, 1, &task_handle); + + // Start the FreeRTOS scheduler + vTaskStartScheduler(); + + while (1); +} diff --git a/frtos/frontend/lwipopts.h b/frtos/frontend/lwipopts.h index 8b4e785..db75e68 100644 --- a/frtos/frontend/lwipopts.h +++ b/frtos/frontend/lwipopts.h @@ -1,87 +1,29 @@ -// Common settings used in most of the pico_w examples -// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details)] +#ifndef _LWIPOPTS_H +#define _LWIPOPTS_H -// allow override in some examples -#ifndef NO_SYS -#define NO_SYS 1 -#endif -// allow override in some examples -#ifndef LWIP_SOCKET -#define LWIP_SOCKET 0 -#endif -#if PICO_CYW43_ARCH_POLL -#define MEM_LIBC_MALLOC 1 -#else -// MEM_LIBC_MALLOC is incompatible with non polling versions -#define MEM_LIBC_MALLOC 0 -#endif -#define MEM_ALIGNMENT 4 -#define MEM_SIZE 4000 -#define MEMP_NUM_TCP_SEG 32 -#define MEMP_NUM_ARP_QUEUE 10 -#define PBUF_POOL_SIZE 24 -#define LWIP_ARP 1 -#define LWIP_ETHERNET 1 -#define LWIP_ICMP 1 -#define LWIP_RAW 1 -#define TCP_WND (8 * TCP_MSS) -#define TCP_MSS 1460 -#define TCP_SND_BUF (8 * TCP_MSS) -#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) -#define LWIP_NETIF_STATUS_CALLBACK 1 -#define LWIP_NETIF_LINK_CALLBACK 1 -#define LWIP_NETIF_HOSTNAME 1 -#define LWIP_NETCONN 0 -#define MEM_STATS 0 -#define SYS_STATS 0 -#define MEMP_STATS 0 -#define LINK_STATS 0 -// #define ETH_PAD_SIZE 2 -#define LWIP_CHKSUM_ALGORITHM 3 -#define LWIP_DHCP 1 -#define LWIP_IPV4 1 -#define LWIP_TCP 1 -#define LWIP_UDP 1 -#define LWIP_DNS 1 -#define LWIP_TCP_KEEPALIVE 1 -#define LWIP_NETIF_TX_SINGLE_PBUF 1 -#define DHCP_DOES_ARP_CHECK 0 -#define LWIP_DHCP_DOES_ACD_CHECK 0 +// Generally you would define your own explicit list of lwIP options +// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) +// +// This example uses a common include to avoid repetition +#include "lwipopts_examples_common.h" -#ifndef NDEBUG -#define LWIP_DEBUG 1 -#define LWIP_STATS 1 -#define LWIP_STATS_DISPLAY 1 +#if !NO_SYS +#define TCPIP_THREAD_STACKSIZE 2048 +#define DEFAULT_THREAD_STACKSIZE 1024 +#define DEFAULT_RAW_RECVMBOX_SIZE 8 +#define TCPIP_MBOX_SIZE 8 + +#define DEFAULT_UDP_RECVMBOX_SIZE TCPIP_MBOX_SIZE +#define DEFAULT_TCP_RECVMBOX_SIZE TCPIP_MBOX_SIZE +#define DEFAULT_ACCEPTMBOX_SIZE TCPIP_MBOX_SIZE + +#define LWIP_TIMEVAL_PRIVATE 0 + +// not necessary, can be done either way +#define LWIP_TCPIP_CORE_LOCKING_INPUT 1 #endif -#define ETHARP_DEBUG LWIP_DBG_OFF -#define NETIF_DEBUG LWIP_DBG_OFF -#define PBUF_DEBUG LWIP_DBG_OFF -#define API_LIB_DEBUG LWIP_DBG_OFF -#define API_MSG_DEBUG LWIP_DBG_OFF -#define SOCKETS_DEBUG LWIP_DBG_OFF -#define ICMP_DEBUG LWIP_DBG_OFF -#define INET_DEBUG LWIP_DBG_OFF -#define IP_DEBUG LWIP_DBG_OFF -#define IP_REASS_DEBUG LWIP_DBG_OFF -#define RAW_DEBUG LWIP_DBG_OFF -#define MEM_DEBUG LWIP_DBG_OFF -#define MEMP_DEBUG LWIP_DBG_OFF -#define SYS_DEBUG LWIP_DBG_OFF -#define TCP_DEBUG LWIP_DBG_OFF -#define TCP_INPUT_DEBUG LWIP_DBG_OFF -#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF -#define TCP_RTO_DEBUG LWIP_DBG_OFF -#define TCP_CWND_DEBUG LWIP_DBG_OFF -#define TCP_WND_DEBUG LWIP_DBG_OFF -#define TCP_FR_DEBUG LWIP_DBG_OFF -#define TCP_QLEN_DEBUG LWIP_DBG_OFF -#define TCP_RST_DEBUG LWIP_DBG_OFF -#define UDP_DEBUG LWIP_DBG_OFF -#define TCPIP_DEBUG LWIP_DBG_OFF -#define PPP_DEBUG LWIP_DBG_OFF -#define SLIP_DEBUG LWIP_DBG_OFF -#define DHCP_DEBUG LWIP_DBG_OFF +#endif // This section enables HTTPD server with SSI, SGI // and tells server which converted HTML files to use diff --git a/frtos/frontend/lwipopts_examples_common.h b/frtos/frontend/lwipopts_examples_common.h new file mode 100644 index 0000000..9979320 --- /dev/null +++ b/frtos/frontend/lwipopts_examples_common.h @@ -0,0 +1,90 @@ +#ifndef _LWIPOPTS_EXAMPLE_COMMONH_H +#define _LWIPOPTS_EXAMPLE_COMMONH_H + + +// Common settings used in most of the pico_w examples +// (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) + +// allow override in some examples +#ifndef NO_SYS +#define NO_SYS 0 +#endif +// allow override in some examples +#ifndef LWIP_SOCKET +#define LWIP_SOCKET 1 +#endif +#if PICO_CYW43_ARCH_POLL +#define MEM_LIBC_MALLOC 1 +#else +// MEM_LIBC_MALLOC is incompatible with non polling versions +#define MEM_LIBC_MALLOC 0 +#endif +#define MEM_ALIGNMENT 4 +#define MEM_SIZE 4000 +#define MEMP_NUM_TCP_SEG 32 +#define MEMP_NUM_ARP_QUEUE 10 +#define PBUF_POOL_SIZE 24 +#define LWIP_ARP 1 +#define LWIP_ETHERNET 1 +#define LWIP_ICMP 1 +#define LWIP_RAW 1 +#define TCP_WND (8 * TCP_MSS) +#define TCP_MSS 1460 +#define TCP_SND_BUF (8 * TCP_MSS) +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) +#define LWIP_NETIF_STATUS_CALLBACK 1 +#define LWIP_NETIF_LINK_CALLBACK 1 +#define LWIP_NETIF_HOSTNAME 1 +#define LWIP_NETCONN 0 +#define MEM_STATS 0 +#define SYS_STATS 0 +#define MEMP_STATS 0 +#define LINK_STATS 0 +// #define ETH_PAD_SIZE 2 +#define LWIP_CHKSUM_ALGORITHM 3 +#define LWIP_DHCP 1 +#define LWIP_IPV4 1 +#define LWIP_TCP 1 +#define LWIP_UDP 1 +#define LWIP_DNS 1 +#define LWIP_TCP_KEEPALIVE 1 +#define LWIP_NETIF_TX_SINGLE_PBUF 1 +#define DHCP_DOES_ARP_CHECK 0 +#define LWIP_DHCP_DOES_ACD_CHECK 0 + +#ifndef NDEBUG +#define LWIP_DEBUG 1 +#define LWIP_STATS 1 +#define LWIP_STATS_DISPLAY 1 +#endif + +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define PPP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF + +#endif /* __LWIPOPTS_H__ */ \ No newline at end of file diff --git a/frtos/frontend/makefsdata.exe b/frtos/frontend/makefsdata.exe index 50286c449a54dfdb1d3763436a4079f500b20f12..ba1fd03b72bf411f73322934358ca4972045d4b4 100644 GIT binary patch delta 34 qcmcaML*UvBfe9VV=aPLUcKb5jcWb=WdW*637E|jj=B>9_YPbO$aSy!! delta 34 scmV+-0NwxAm=M;O5Rixi=Nvzgi%kOR|AE?t+5v^y0)^TGwb}%H3nU&8MgRZ+ diff --git a/frtos/frontend/makefsdata.py b/frtos/frontend/makefsdata.py deleted file mode 100644 index 6d2f98f..0000000 --- a/frtos/frontend/makefsdata.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/python3 - -# This script is by @rspeir on GitHub: -# https://github.com/krzmaz/pico-w-webserver-example/pull/1/files/4b3e78351dd236f213da9bebbb20df690d470476#diff-e675c4a367e382db6f9ba61833a58c62029d8c71c3156a9f238b612b69de279d -# Renamed output to avoid linking incorrect file - -import os -import binascii - -#Create file to write output into -output = open('htmldata.c', 'w') - -#Traverse directory, generate list of files -files = list() -os.chdir('./html_files') -for(dirpath, dirnames, filenames) in os.walk('.'): - files += [os.path.join(dirpath, file) for file in filenames] - -filenames = list() -varnames = list() - -#Generate appropriate HTTP headers -for file in files: - - if '404' in file: - header = "HTTP/1.0 404 File not found\r\n" - else: - header = "HTTP/1.0 200 OK\r\n" - - header += "Server: lwIP/pre-0.6 (http://www.sics.se/~adam/lwip/)\r\n" - - if '.html' in file: - header += "Content-type: text/html\r\n" - elif '.shtml' in file: - header += "Content-type: text/html\r\n" - elif '.jpg' in file: - header += "Content-type: image/jpeg\r\n" - elif '.gif' in file: - header += "Content-type: image/gif\r\n" - elif '.png' in file: - header += "Content-type: image/png\r\n" - elif '.class' in file: - header += "Content-type: application/octet-stream\r\n" - elif '.js' in file: - header += "Content-type: text/javascript\r\n" - elif '.css' in file: - header += "Content-type: text/css\r\n" - elif '.svg' in file: - header += "Content-type: image/svg+xml\r\n" - else: - header += "Content-type: text/plain\r\n" - - header += "\r\n" - - fvar = file[1:] #remove leading dot in filename - fvar = fvar.replace('/', '_') #replace *nix path separator with underscore - fvar = fvar.replace('\\', '_') #replace DOS path separator with underscore - fvar = fvar.replace('.', '_') #replace file extension dot with underscore - - output.write("static const unsigned char data{}[] = {{\n".format(fvar)) - output.write("\t/* {} */\n\t".format(file)) - - #first set of hex data encodes the filename - b = bytes(file[1:].replace('\\', '/'), 'utf-8') #change DOS path separator to forward slash - for byte in binascii.hexlify(b, b' ', 1).split(): - output.write("0x{}, ".format(byte.decode())) - output.write("0,\n\t") - - #second set of hex data is the HTTP header/mime type we generated above - b = bytes(header, 'utf-8') - count = 0 - for byte in binascii.hexlify(b, b' ', 1).split(): - output.write("0x{}, ".format(byte.decode())) - count = count + 1 - if(count == 10): - output.write("\n\t") - count = 0 - output.write("\n\t") - - #finally, dump raw hex data from files - with open(file, 'rb') as f: - count = 0 - while(byte := f.read(1)): - byte = binascii.hexlify(byte) - output.write("0x{}, ".format(byte.decode())) - count = count + 1 - if(count == 10): - output.write("\n\t") - count = 0 - output.write("};\n\n") - - filenames.append(file[1:]) - varnames.append(fvar) - -for i in range(len(filenames)): - prevfile = "NULL" - if(i > 0): - prevfile = "file" + varnames[i-1] - - output.write("const struct fsdata_file file{0}[] = {{{{ {1}, data{2}, ".format(varnames[i], prevfile, varnames[i])) - output.write("data{} + {}, ".format(varnames[i], len(filenames[i]) + 1)) - output.write("sizeof(data{}) - {}, ".format(varnames[i], len(filenames[i]) + 1)) - output.write("FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT}};\n") - -output.write("\n#define FS_ROOT file{}\n".format(varnames[-1])) -output.write("#define FS_NUMFILES {}\n".format(len(filenames))) \ No newline at end of file