frontend sys freertos working
This commit is contained in:
parent
5cb4fae0c9
commit
ffa89d033b
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__ */
|
Binary file not shown.
|
@ -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)))
|
Loading…
Reference in New Issue