Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make esp-open-rtos compatable #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ HTTP auth implementation. Only does basic authentication for now.
*/


#include <esp8266.h>
#include "auth.h"
#include <libesphttpd/esp8266.h>
#include <libesphttpd/auth.h>
#include "base64.h"

int ICACHE_FLASH_ATTR authBasic(HttpdConnData *connData) {
Expand Down
2 changes: 1 addition & 1 deletion core/base64.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* base64.c : base-64 / MIME encode/decode */
/* PUBLIC DOMAIN - Jon Mayo - November 13, 2003 */
#include <esp8266.h>
#include <libesphttpd/esp8266.h>
#include "base64.h"

static const int base64dec_tab[256] ICACHE_RODATA_ATTR={
Expand Down
37 changes: 19 additions & 18 deletions core/httpd-freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ ESP8266 web server - platform-dependent routines, FreeRTOS version

Thanks to my collague at Espressif for writing the foundations of this code.
*/
#ifdef FREERTOS
#include <libesphttpd/esp8266.h>

#ifdef FREERTOS

#include <esp8266.h>
#include "httpd.h"
#include "platform.h"
#include <libesphttpd/httpd.h>
#include "httpd-platform.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include <string.h>

#include "lwip/lwip/sockets.h"
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <semphr.h>

#include "lwip/sockets.h"


static int httpPort;
static int httpMaxConnCt;
static xQueueHandle httpdMux;
static QueueHandle_t httpdMux;


struct RtosConnType{
Expand Down Expand Up @@ -61,10 +62,10 @@ void ICACHE_FLASH_ATTR httpdPlatUnlock() {

#define RECV_BUF_SIZE 2048
static void platHttpServerTask(void *pvParameters) {
int32 listenfd;
int32 remotefd;
int32 len;
int32 ret;
int32_t listenfd;
int32_t remotefd;
int32_t len;
int32_t ret;
int x;
int maxfdp = 0;
char *precvbuf;
Expand Down Expand Up @@ -92,7 +93,7 @@ static void platHttpServerTask(void *pvParameters) {
listenfd = socket(AF_INET, SOCK_STREAM, 0);
if (listenfd == -1) {
httpd_printf("platHttpServerTask: failed to create sock!\n");
vTaskDelay(1000/portTICK_RATE_MS);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
} while(listenfd == -1);

Expand All @@ -101,7 +102,7 @@ static void platHttpServerTask(void *pvParameters) {
ret = bind(listenfd, (struct sockaddr *)&server_addr, sizeof(server_addr));
if (ret != 0) {
httpd_printf("platHttpServerTask: failed to bind!\n");
vTaskDelay(1000/portTICK_RATE_MS);
vTaskDelay(1000/portTICK_PERIOD_MS);
}
} while(ret != 0);

Expand All @@ -110,7 +111,7 @@ static void platHttpServerTask(void *pvParameters) {
ret = listen(listenfd, HTTPD_MAX_CONNECTIONS);
if (ret != 0) {
httpd_printf("platHttpServerTask: failed to listen!\n");
vTaskDelay(1000/portTICK_RATE_MS);
vTaskDelay(1000/portTICK_PERIOD_MS);
}

} while(ret != 0);
Expand Down Expand Up @@ -263,4 +264,4 @@ void ICACHE_FLASH_ATTR httpdPlatInit(int port, int maxConnCt) {
}


#endif
#endif
7 changes: 3 additions & 4 deletions core/httpd-nonos.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
ESP8266 web server - platform-dependent routines, nonos version
*/

#include <esp8266.h>
#include "httpd.h"
#include "platform.h"
#include <libesphttpd/esp8266.h>
#include <libesphttpd/httpd.h>
#include "httpd-platform.h"

#ifndef FREERTOS
Expand Down Expand Up @@ -85,4 +84,4 @@ void ICACHE_FLASH_ATTR httpdPlatInit(int port, int maxConnCt) {
}


#endif
#endif
4 changes: 2 additions & 2 deletions core/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Esp8266 http server - core routines
*/


#include <esp8266.h>
#include "httpd.h"
#include <libesphttpd/esp8266.h>
#include <libesphttpd/httpd.h>
#include "httpd-platform.h"

//This gets set at init time.
Expand Down
8 changes: 4 additions & 4 deletions core/httpdespfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Connector to let httpd use the espfs filesystem to serve the files in it.
* ----------------------------------------------------------------------------
*/

#include <esp8266.h>
#include "httpdespfs.h"
#include "espfs.h"
#include "espfsformat.h"
#include <libesphttpd/esp8266.h>
#include <libesphttpd/httpdespfs.h>
#include <libesphttpd/espfs.h>
#include <espfs/espfsformat.h>

// The static files marked with FLAG_GZIP are compressed and will be served with GZIP compression.
// If the client does not advertise that he accepts GZIP send following warning message (telnet users for e.g.)
Expand Down
7 changes: 2 additions & 5 deletions core/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
*/
// gcc -Wall -DSHA1TEST -o sha1test sha1.c && ./sha1test

#include <esp8266.h>
#include <stdint.h>
#include <string.h>

#include "sha1.h"
#include <libesphttpd/esp8266.h>
#include <libesphttpd/sha1.h>

//according to http://ip.cadence.com/uploads/pdf/xtensalx_overview_handbook.pdf
// the cpu is normally defined as little ending, but can be big endian too.
Expand Down
15 changes: 9 additions & 6 deletions espfs/espfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ It's written for use with httpd, but doesn't need to be used as such.

#ifdef __ets__
//esp build
#include <esp8266.h>
#include <libesphttpd/esp8266.h>
#include <spiflash.h>
#define spi_flash_read spiflash_read
#else
//Test build
#include <stdio.h>
Expand All @@ -30,8 +32,9 @@ It's written for use with httpd, but doesn't need to be used as such.
#define ICACHE_FLASH_ATTR
#endif


#include <libesphttpd/espfs.h>
#include "espfsformat.h"
#include "espfs.h"

#ifdef ESPFS_HEATSHRINK
#include "heatshrink_config_custom.h"
Expand Down Expand Up @@ -86,7 +89,7 @@ EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) {

// check if there is valid header at address
EspFsHeader testHeader;
spi_flash_read((uint32)flashAddress, (uint32*)&testHeader, sizeof(EspFsHeader));
spi_flash_read((uint32_t)flashAddress, (uint8_t*)&testHeader, sizeof(EspFsHeader));
if (testHeader.magic != ESPFS_MAGIC) {
return ESPFS_INIT_RESULT_NO_IMAGE;
}
Expand All @@ -105,7 +108,7 @@ void ICACHE_FLASH_ATTR readFlashUnaligned(char *dst, char *src, int len) {
uint32_t src_address = ((uint32_t)src) - src_offset;

uint32_t tmp_buf[len/4 + 2];
spi_flash_read((uint32)src_address, (uint32*)tmp_buf, len+src_offset);
spi_flash_read((uint32_t)src_address, (uint8_t*)tmp_buf, len+src_offset);
memcpy(dst, ((uint8_t*)tmp_buf)+src_offset, len);
}
#else
Expand Down Expand Up @@ -141,7 +144,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
while(1) {
hpos=p;
//Grab the next file header.
spi_flash_read((uint32)p, (uint32*)&h, sizeof(EspFsHeader));
spi_flash_read((uint32_t)p, (uint8_t*)&h, sizeof(EspFsHeader));

if (h.magic!=ESPFS_MAGIC) {
httpd_printf("Magic mismatch. EspFS image broken.\n");
Expand All @@ -153,7 +156,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) {
}
//Grab the name of the file.
p+=sizeof(EspFsHeader);
spi_flash_read((uint32)p, (uint32*)&namebuf, sizeof(namebuf));
spi_flash_read((uint32_t)p, (uint8_t*)&namebuf, sizeof(namebuf));
// httpd_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n",
// namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags);
if (strcmp(namebuf, fileName)==0) {
Expand Down
4 changes: 2 additions & 2 deletions espfs/heatshrink_decoder.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "espfs.h"
#include <libesphttpd/espfs.h>
#ifdef ESPFS_HEATSHRINK
//Stupid wrapper so we don't have to move c-files around
//Also loads httpd-specific config.

#ifdef __ets__
//esp build

#include <esp8266.h>
#include <libesphttpd/esp8266.h>

#endif

Expand Down
4 changes: 2 additions & 2 deletions espfs/mkespfsimage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifdef __MINGW32__
#include <io.h>
#endif
#include "espfs.h"
#include "espfsformat.h"
#include <libesphttpd/espfs.h>
#include <espfsformat.h>

//Heatshrink
#ifdef ESPFS_HEATSHRINK
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 9 additions & 3 deletions include/esp8266.h → include/libesphttpd/esp8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
// Actually misnamed, as it also works for ESP32.
// ToDo: Figure out better name


#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef ESPOPENRTOS
#define FREERTOS
#include <esp8266.h>
#endif

#ifdef FREERTOS
#include <stdint.h>

Expand All @@ -29,6 +33,8 @@
#include <upgrade.h>
#endif

#include "platform.h"
#include "espmissingincludes.h"
#include <libesphttpd/platform.h>

#ifndef ESPOPENRTOS
#include "espmissingincludes.h"
#endif
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions include/httpd.h → include/libesphttpd/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#define HTTPDVER "0.4"

#include <libesphttpd/esp8266.h>

//Max length of request head. This is statically allocated for each connection.
#define HTTPD_MAX_HEAD_LEN 1024
//Max post buffer len. This is dynamically malloc'ed if needed.
Expand Down Expand Up @@ -48,8 +50,8 @@ struct HttpdConnData {
cgiRecvHandler recvHdl; // Handler for data received after headers, if any
HttpdPostData *post; // POST data structure
int remote_port; // Remote TCP port
uint8 remote_ip[4]; // IP address of client
uint8 slot; // Slot ID
uint8_t remote_ip[4]; // IP address of client
uint8_t slot; // Slot ID
};

//A struct describing the POST data sent inside the http connection. This is used by the CGI functions
Expand Down Expand Up @@ -96,4 +98,4 @@ void httpdDisconCb(ConnTypePtr conn, char *remIp, int remPort);
int httpdConnectCb(ConnTypePtr conn, char *remIp, int remPort);


#endif
#endif
4 changes: 2 additions & 2 deletions include/httpdespfs.h → include/libesphttpd/httpdespfs.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef HTTPDESPFS_H
#define HTTPDESPFS_H

#include "httpd.h"
#include <libesphttpd/httpd.h>

int cgiEspFsHook(HttpdConnData *connData);
int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData);

#endif
#endif
12 changes: 11 additions & 1 deletion include/platform.h → include/libesphttpd/platform.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#ifndef PLATFORM_H
#define PLATFORM_H

#ifdef ESPOPENRTOS
#define FREERTOS
#endif

#ifdef FREERTOS
//#include "esp_timer.h"
typedef struct RtosConnType RtosConnType;
typedef RtosConnType* ConnTypePtr;
#if defined(ESPOPENRTOS)
#define ICACHE_FLASH_ATTR
#define ICACHE_RODATA_ATTR
#define httpd_printf(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#if 0
//Unfortunately, this does not always work... the latest esp32 sdk, for example, breaks this.
#define httpd_printf(fmt, ...) do { \
Expand All @@ -14,6 +23,7 @@ typedef RtosConnType* ConnTypePtr;
#else
#define httpd_printf(fmt, ...) os_printf(fmt, ##__VA_ARGS__)
#endif
#endif
#else
#define printf(...) os_printf(__VA_ARGS__)
#define sprintf(str, ...) os_sprintf(str, __VA_ARGS__)
Expand All @@ -35,4 +45,4 @@ typedef struct espconn* ConnTypePtr;



#endif
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions util/captdns.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ be used to send mobile phones, tablets etc which connect to the ESP in AP mode d
the internal webserver.
*/

#include <esp8266.h>
#include <libesphttpd/esp8266.h>
#ifdef FREERTOS

#include "FreeRTOS.h"
Expand Down Expand Up @@ -331,4 +331,4 @@ void ICACHE_FLASH_ATTR captdnsInit(void) {
espconn_create(&conn);
}

#endif
#endif
16 changes: 6 additions & 10 deletions util/cgiflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ Some flash handling cgi routines. Used for updating the ESPFS/OTA image.
//This doesn't work yet on the ESP32. ToDo: figure out how to make it work.
#ifndef ESP32

#include <esp8266.h>
#include "cgiflash.h"
#include "espfs.h"
#include "cgiflash.h"
#include "espfs.h"

//#include <osapi.h>
#include "cgiflash.h"
#include "espfs.h"
#include <libesphttpd/esp8266.h>
#include <libesphttpd/cgiflash.h>
#include <libesphttpd/espfs.h>
#include <libesphttpd/cgiflash.h>
#include <libesphttpd/espfs.h>

#ifndef UPGRADE_FLAG_FINISH
#define UPGRADE_FLAG_FINISH 0x02
Expand Down Expand Up @@ -299,4 +295,4 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) {
return HTTPD_CGI_DONE;
}

#endif
#endif
Loading