From e0c1b47937f95249bfeac4fb22a25d4a00d30139 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 13 May 2015 19:03:21 +0200 Subject: [PATCH 1/5] add some notes to the SPI functions (aligned to 32Bit) - Fatal exception (9) --- libraries/SPI/SPI.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index be4627740..c96c4fcb8 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -308,6 +308,13 @@ void SPIClass::write32(uint32_t data, bool msb) { while(SPI1CMD & SPIBUSY) {} } +/** + * Note: + * data need to be aligned to 32Bit + * or you get an Fatal exception (9) + * @param data uint8_t * + * @param size uint32_t + */ void SPIClass::writeBytes(uint8_t * data, uint32_t size) { while(size) { if(size > 64) { @@ -340,6 +347,15 @@ void SPIClass::writeBytes_(uint8_t * data, uint8_t size) { while(SPI1CMD & SPIBUSY) {} } + +/** + * Note: + * data need to be aligned to 32Bit + * or you get an Fatal exception (9) + * @param data uint8_t * + * @param size uint8_t max for size is 64Byte + * @param repeat uint32_t + */ void SPIClass::writePattern(uint8_t * data, uint8_t size, uint32_t repeat) { if(size > 64) return; //max Hardware FIFO @@ -376,6 +392,14 @@ void SPIClass::writePattern_(uint8_t * data, uint8_t size, uint8_t repeat) { writeBytes(&buffer[0], bytes); } +/** + * Note: + * in and out need to be aligned to 32Bit + * or you get an Fatal exception (9) + * @param out uint8_t * + * @param in uint8_t * + * @param size uint32_t + */ void SPIClass::transferBytes(uint8_t * out, uint8_t * in, uint32_t size) { while(size) { if(size > 64) { From 81d27b403e7934eaa4d15996b0ca3fc2a1ca5dc2 Mon Sep 17 00:00:00 2001 From: Makuna Date: Wed, 13 May 2015 11:27:54 -0700 Subject: [PATCH 2/5] PgmSpace working PSTR() and F() macros correctly place string into flash memory relying on PROGMEM PROGMEM uses ICACHE_RODATA_ATTR Print and String classes fixed up str* classes fixed up --- cores/esp8266/Print.cpp | 19 ++++ cores/esp8266/Print.h | 2 + cores/esp8266/WString.cpp | 42 ++++++++ cores/esp8266/WString.h | 19 +++- cores/esp8266/libc_replacements.c | 8 +- cores/esp8266/pgmspace.cpp | 161 ++++++++++++++++++++++++++++++ cores/esp8266/pgmspace.h | 73 ++++++++++---- 7 files changed, 295 insertions(+), 29 deletions(-) create mode 100644 cores/esp8266/pgmspace.cpp diff --git a/cores/esp8266/Print.cpp b/cores/esp8266/Print.cpp index 6d3687dee..c1405c9f7 100644 --- a/cores/esp8266/Print.cpp +++ b/cores/esp8266/Print.cpp @@ -18,6 +18,7 @@ Modified 23 November 2006 by David A. Mellis Modified December 2014 by Ivan Grokhotkov + Modified May 2015 by Michael C. Miller - esp8266 progmem support */ #include @@ -42,6 +43,18 @@ size_t ICACHE_FLASH_ATTR Print::write(const uint8_t *buffer, size_t size) { return n; } +size_t ICACHE_FLASH_ATTR Print::print(const __FlashStringHelper *ifsh) { + PGM_P p = reinterpret_cast(ifsh); + + size_t n = 0; + while (1) { + uint8_t c = pgm_read_byte(p++); + if (c == 0) break; + n += write(c); + } + return n; +} + size_t ICACHE_FLASH_ATTR Print::print(const String &s) { return write(s.c_str(), s.length()); } @@ -92,6 +105,12 @@ size_t ICACHE_FLASH_ATTR Print::print(double n, int digits) { return printFloat(n, digits); } +size_t ICACHE_FLASH_ATTR Print::println(const __FlashStringHelper *ifsh) { + size_t n = print(ifsh); + n += println(); + return n; +} + size_t ICACHE_FLASH_ATTR Print::print(const Printable& x) { return x.printTo(*this); } diff --git a/cores/esp8266/Print.h b/cores/esp8266/Print.h index 6a64ba4be..79358f157 100644 --- a/cores/esp8266/Print.h +++ b/cores/esp8266/Print.h @@ -63,6 +63,7 @@ class Print { return write((const uint8_t *) buffer, size); } + size_t print(const __FlashStringHelper *); size_t print(const String &); size_t print(const char[]); size_t print(char); @@ -74,6 +75,7 @@ class Print { size_t print(double, int = 2); size_t print(const Printable&); + size_t println(const __FlashStringHelper *); size_t println(const String &s); size_t println(const char[]); size_t println(char); diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index ab523677b..61fc5ac94 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -4,6 +4,7 @@ Copyright (c) 2009-10 Hernando Barragan. All rights reserved. Copyright 2011, Paul Stoffregen, paul@pjrc.com Modified by Ivan Grokhotkov, 2014 - esp8266 support + Modified by Michael C. Miller, 2015 - esp8266 progmem support This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -44,6 +45,11 @@ ICACHE_FLASH_ATTR String::String(const String &value) { *this = value; } +ICACHE_FLASH_ATTR String::String(const __FlashStringHelper *pstr) { + init(); + *this = pstr; // see operator = +} + #ifdef __GXX_EXPERIMENTAL_CXX0X__ ICACHE_FLASH_ATTR String::String(String &&rval) { init(); @@ -167,6 +173,16 @@ String & ICACHE_FLASH_ATTR String::copy(const char *cstr, unsigned int length) { return *this; } +String & ICACHE_FLASH_ATTR String::copy(const __FlashStringHelper *pstr, unsigned int length) { + if (!reserve(length)) { + invalidate(); + return *this; + } + len = length; + strcpy_P(buffer, (PGM_P)pstr); + return *this; +} + #ifdef __GXX_EXPERIMENTAL_CXX0X__ void ICACHE_FLASH_ATTR String::move(String &rhs) { if(buffer) { @@ -223,6 +239,14 @@ String & ICACHE_FLASH_ATTR String::operator =(const char *cstr) { return *this; } +String & ICACHE_FLASH_ATTR String::operator = (const __FlashStringHelper *pstr) +{ + if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); + else invalidate(); + + return *this; +} + // /*********************************************/ // /* concat */ // /*********************************************/ @@ -299,6 +323,17 @@ unsigned char ICACHE_FLASH_ATTR String::concat(double num) { return concat(string, strlen(string)); } +unsigned char ICACHE_FLASH_ATTR String::concat(const __FlashStringHelper * str) { + if (!str) return 0; + int length = strlen_P((PGM_P)str); + if (length == 0) return 1; + unsigned int newlen = len + length; + if (!reserve(newlen)) return 0; + strcpy_P(buffer + len, (PGM_P)str); + len = newlen; + return 1; +} + /*********************************************/ /* Concatenate */ /*********************************************/ @@ -373,6 +408,13 @@ StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, doubl return a; } +StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) +{ + StringSumHelper &a = const_cast(lhs); + if (!a.concat(rhs)) a.invalidate(); + return a; +} + // /*********************************************/ // /* Comparison */ // /*********************************************/ diff --git a/cores/esp8266/WString.h b/cores/esp8266/WString.h index 6ca037483..531fc88c8 100644 --- a/cores/esp8266/WString.h +++ b/cores/esp8266/WString.h @@ -26,15 +26,17 @@ #include #include #include -#define PROGMEM +#include // An inherited class for holding the result of a concatenation. These // result objects are assumed to be writable by subsequent concatenations. class StringSumHelper; -typedef char* __FlashStringHelper; -//#define F(str) []() -> const char * { static const char tmp[] ICACHE_RODATA_ATTR = str; return &tmp[0]; }() -#define F(str) str +// an abstract class used as a means to proide a unique pointer type +// but really has no body +class __FlashStringHelper; +#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) + // The string class class String { @@ -53,6 +55,7 @@ class String { // be false). String(const char *cstr = ""); String(const String &str); + String(const __FlashStringHelper *str); #ifdef __GXX_EXPERIMENTAL_CXX0X__ String(String &&rval); String(StringSumHelper &&rval); @@ -81,6 +84,7 @@ class String { // marked as invalid ("if (s)" will be false). String & operator =(const String &rhs); String & operator =(const char *cstr); + String & operator = (const __FlashStringHelper *str); #ifdef __GXX_EXPERIMENTAL_CXX0X__ String & operator =(String &&rval); String & operator =(StringSumHelper &&rval); @@ -101,6 +105,7 @@ class String { unsigned char concat(unsigned long num); unsigned char concat(float num); unsigned char concat(double num); + unsigned char concat(const __FlashStringHelper * str); // if there's not enough memory for the concatenated value, the string // will be left unchanged (but this isn't signalled in any way) @@ -144,6 +149,10 @@ class String { concat(num); return (*this); } + String & operator += (const __FlashStringHelper *str){ + concat(str); + return (*this); + } friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs); friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr); @@ -155,6 +164,7 @@ class String { friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num); friend StringSumHelper & operator +(const StringSumHelper &lhs, float num); friend StringSumHelper & operator +(const StringSumHelper &lhs, double num); + friend StringSumHelper & operator +(const StringSumHelper &lhs, const __FlashStringHelper *rhs); // comparison (only works w/ Strings and "strings") operator StringIfHelperType() const { @@ -237,6 +247,7 @@ class String { // copy and move String & copy(const char *cstr, unsigned int length); + String & copy(const __FlashStringHelper *pstr, unsigned int length); #ifdef __GXX_EXPERIMENTAL_CXX0X__ void move(String &rhs); #endif diff --git a/cores/esp8266/libc_replacements.c b/cores/esp8266/libc_replacements.c index c1abbcf6f..64efd94ab 100644 --- a/cores/esp8266/libc_replacements.c +++ b/cores/esp8266/libc_replacements.c @@ -116,7 +116,7 @@ char* strncpy(char * dest, const char * src, size_t n) { return ets_strncpy(dest, src, n); } -size_t strnlen(const char *s, size_t len) { +size_t ICACHE_FLASH_ATTR strnlen(const char *s, size_t len) { // there is no ets_strnlen const char *cp; for (cp = s; len != 0 && *cp != '\0'; cp++, len--); @@ -127,7 +127,7 @@ char* strstr(const char *haystack, const char *needle) { return ets_strstr(haystack, needle); } -char* strchr(const char * str, int character) { +char* ICACHE_FLASH_ATTR strchr(const char * str, int character) { while(1) { if(*str == 0x00) { return NULL; @@ -139,7 +139,7 @@ char* strchr(const char * str, int character) { } } -char * strrchr(const char * str, int character) { +char * ICACHE_FLASH_ATTR strrchr(const char * str, int character) { char * ret = NULL; while(1) { if(*str == 0x00) { @@ -223,7 +223,7 @@ char* ICACHE_FLASH_ATTR strtok(char * str, const char * delimiters) { return ret; } -int strcasecmp(const char * str1, const char * str2) { +int ICACHE_FLASH_ATTR strcasecmp(const char * str1, const char * str2) { int d = 0; while(1) { int c1 = tolower(*str1++); diff --git a/cores/esp8266/pgmspace.cpp b/cores/esp8266/pgmspace.cpp new file mode 100644 index 000000000..84af6264b --- /dev/null +++ b/cores/esp8266/pgmspace.cpp @@ -0,0 +1,161 @@ +/* +pgmspace.cpp - string functions that support PROGMEM +Copyright (c) 2015 Michael C. Miller. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include "pgmspace.h" + +size_t ICACHE_FLASH_ATTR strnlen_P(const char* s, size_t size) { + const char* cp; + for (cp = s; size != 0 && pgm_read_byte(cp) != '\0'; cp++, size--); + return (size_t)(cp - s); +} + +void* ICACHE_FLASH_ATTR memcpy_P(void* dest, const void* src, size_t count) { + const uint8_t* read = reinterpret_cast(src); + uint8_t* write = reinterpret_cast(dest); + + while (count) + { + *write++ = pgm_read_byte(read++); + count--; + } + + return dest; +} + +char* ICACHE_FLASH_ATTR strncpy_P(char* dest, const char* src, size_t size) { + const char* read = src; + char* write = dest; + char ch = '.'; + while (size > 0 && ch != '\0') + { + ch = pgm_read_byte(read++); + *write++ = ch; + size--; + } + + return dest; +} + +char* ICACHE_FLASH_ATTR strncat_P(char* dest, const char* src, size_t size) { + char* write = dest; + + while (*write != '\0') + { + write++; + } + + const char* read = src; + char ch = '.'; + + while (size > 0 && ch != '\0') + { + ch = pgm_read_byte(read++); + *write++ = ch; + + size--; + } + + if (ch != '\0') + { + *write = '\0'; + } + + return dest; +} + +int ICACHE_FLASH_ATTR strncmp_P(const char* str1, const char* str2P, size_t size) { + int result = 0; + + while (size > 0) + { + char ch1 = *str1++; + char ch2 = pgm_read_byte(str2P++); + result = ch1 - ch2; + if (result != 0 || ch2 == '\0') + { + break; + } + + size--; + } + + return result; +} + +int ICACHE_FLASH_ATTR strncasecmp_P(const char* str1, const char* str2P, size_t size) { + int result = 0; + + while (size > 0) + { + char ch1 = tolower(*str1++); + char ch2 = tolower(pgm_read_byte(str2P++)); + result = ch1 - ch2; + if (result != 0 || ch2 == '\0') + { + break; + } + + size--; + } + + return result; +} + +int ICACHE_FLASH_ATTR printf_P(const char* formatP, ...) { + int ret; + va_list arglist; + va_start(arglist, formatP); + + size_t fmtLen = strlen_P(formatP); + char* format = new char[fmtLen + 1]; + strcpy_P(format, formatP); + + ret = os_printf(format, arglist); + + delete [] format; + + va_end(arglist); + return ret; +} + +int ICACHE_FLASH_ATTR snprintf_P(char* str, size_t strSize, const char* formatP, ...) { + int ret; + va_list arglist; + va_start(arglist, formatP); + + ret = vsnprintf_P(str, strSize, formatP, arglist); + + va_end(arglist); + return ret; +} + +int ICACHE_FLASH_ATTR vsnprintf_P(char* str, size_t strSize, const char* formatP, va_list ap) { + int ret; + + size_t fmtLen = strlen_P(formatP); + char* format = new char[fmtLen + 1]; + strcpy_P(format, formatP); + + ret = ets_vsnprintf(str, strSize, format, ap); + + delete [] format; + + return ret; +} \ No newline at end of file diff --git a/cores/esp8266/pgmspace.h b/cores/esp8266/pgmspace.h index 506c8f8d3..695f2a50b 100644 --- a/cores/esp8266/pgmspace.h +++ b/cores/esp8266/pgmspace.h @@ -12,13 +12,11 @@ extern "C" { } #endif -#define PROGMEM +#define PROGMEM ICACHE_RODATA_ATTR #define PGM_P const char * -#define PSTR(str) (str) +#define PGM_VOID_P const void * +#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) -#define vsnprintf_P(...) ets_vsnprintf( __VA_ARGS__ ) -#define snprintf_P(...) snprintf( __VA_ARGS__ ) -#define printf_P(...) os_printf(__VA_ARGS__) #define _SFR_BYTE(n) (n) @@ -32,23 +30,56 @@ typedef uint16_t prog_uint16_t; typedef int32_t prog_int32_t; typedef uint32_t prog_uint32_t; -#define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) -#define strcpy_P(dest, src) strcpy((dest), (src)) -#define strcat_P(dest, src) strcat((dest), (src)) -#define strcmp_P(a, b) strcmp((a), (b)) -#define strstr_P(a, b) strstr((a), (b)) -#define strlen_P(s) strlen((const char *)(s)) -#define strcasecmp_P(a, b) strcasecmp((a), (b)) -#define strncpy_P(dest, src, size) strncpy((dest), (src), (size)) -#define strncat_P(dest, src, size) strncat((dest), (src), (size)) -#define strncmp_P(a, b, size) strncmp((a), (b), (size)) -#define strnlen_P(s, size) strnlen((const char *)(s), (size)) -#define strncasecmp_P(a, b, size) strncasecmp((a), (b), (size)) +#define SIZE_IRRELEVANT 0x7fffffff -#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) -#define pgm_read_word(addr) (*(const unsigned short *)(addr)) -#define pgm_read_dword(addr) (*(const unsigned long *)(addr)) -#define pgm_read_float(addr) (*(const float *)(addr)) +extern void* memcpy_P(void* dest, const void* src, size_t count); + +extern char* strncpy_P(char* dest, const char* src, size_t size); +#define strcpy_P(dest, src) strncpy_P((dest), (src), SIZE_IRRELEVANT) + +extern char* strncat_P(char* dest, const char* src, size_t size); +#define strcat_P(dest, src) strncat_P((dest), (src), SIZE_IRRELEVANT) + +extern int strncmp_P(const char* str1, const char* str2P, size_t size); +#define strcmp_P(str1, str2P) strncmp_P((str1), (str2P), SIZE_IRRELEVANT) + +extern int strncasecmp_P(const char* str1, const char* str2P, size_t size); +#define strcasecmp_P(str1, str2P) strncasecmp_P((str1), (str2P), SIZE_IRRELEVANT) + +extern size_t strnlen_P(const char *s, size_t size); +#define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT) + +extern int printf_P(const char *formatP, ...); +extern int snprintf_P(char *str, size_t strSize, const char *formatP, ...); +extern int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap); + +// flash memory must be read using 32 bit aligned addresses else a processor +// exception will be triggered +// order within the 32 bit values are +// -------------- +// b3, b2, b1, b0 +// w1, w0 + +#define pgm_read_byte(addr) \ +(__extension__({ \ + PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \ + ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \ + const uint32_t* __addr32 = reinterpret_cast(reinterpret_cast(__local)-__offset); \ + uint8_t __result = ((*__addr32) >> (__offset * 8)); \ + __result; \ +})) + +#define pgm_read_word(addr) \ +(__extension__({ \ + PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \ + ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \ + const uint32_t* __addr32 = reinterpret_cast(reinterpret_cast(__local) - __offset); \ + uint16_t __result = ((*__addr32) >> (__offset * 8)); \ + __result; \ +})) + +#define pgm_read_dword(addr) (*reinterpret_cast(addr)) +#define pgm_read_float(addr) (*reinterpret_cast(addr)) #define pgm_read_byte_near(addr) pgm_read_byte(addr) #define pgm_read_word_near(addr) pgm_read_word(addr) From a17aded8d651757a884580c99f1a7480dd817304 Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 13 May 2015 22:54:09 +0200 Subject: [PATCH 3/5] add hexdump function for easy debugging. Output: [HEXDUMP] Address: 0x3FFF5188 len: 0x200 (512) [0x3FFF5188] 0x00000000: E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 [0x3FFF5198] 0x00000010: E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 [0x3FFF51A8] 0x00000020: E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 [0x3FFF51B8] 0x00000030: E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 [0x3FFF51C8] 0x00000040: E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 [0x3FFF51D8] 0x00000050: E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 [0x3FFF51E8] 0x00000060: E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 E6 D1 .... --- cores/esp8266/Arduino.h | 3 +++ cores/esp8266/debug.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 cores/esp8266/debug.cpp diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 6db13a088..9cc4ad08b 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -229,6 +229,9 @@ long random(long, long); void randomSeed(unsigned int); long map(long, long, long, long, long); +// Debugging functions +void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16); + #endif #include "pins_arduino.h" diff --git a/cores/esp8266/debug.cpp b/cores/esp8266/debug.cpp new file mode 100644 index 000000000..c42016b04 --- /dev/null +++ b/cores/esp8266/debug.cpp @@ -0,0 +1,21 @@ +/* + * debug.c + * + * Created on: 13.05.2015 + * Author: Markus Sattler + */ + +#include "Arduino.h" + +void ICACHE_RAM_ATTR hexdump(uint8_t *mem, uint32_t len, uint8_t cols) { + os_printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", mem, len, len); + for(uint32_t i = 0; i < len; i++) { + if(i % cols == 0) { + os_printf("\n[0x%08X] 0x%08X: ", mem, i); + } + os_printf("%02X ", *mem); + mem++; + } + os_printf("\n"); +} + From ce73ac216bf87a084f006d694e722d4d6387c113 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 14 May 2015 02:47:39 +0300 Subject: [PATCH 4/5] fix SDWebServer sample --- .../examples/SDWebServer/SDWebServer.ino | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino b/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino index d9e230c77..762e4fe0d 100644 --- a/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino +++ b/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino @@ -55,7 +55,6 @@ void returnOK(){ message += "Access-Control-Allow-Origin: *\r\n"; message += "\r\n"; client.print(message); - message = 0; client.stop(); } @@ -69,7 +68,6 @@ void returnFail(String msg){ message += msg; message += "\r\n"; client.print(message); - message = 0; client.stop(); } @@ -108,8 +106,8 @@ bool loadFromSdCard(String path){ head += "\r\nAccess-Control-Allow-Origin: *"; head += "\r\n\r\n"; client.print(head); - dataType = 0; - path = 0; + dataType = String(); + path = String(); uint8_t obuf[WWW_BUF_SIZE]; @@ -172,11 +170,11 @@ void deleteRecursive(String path){ entry.close(); SD.remove((char *)entryPath.c_str()); } - entryPath = 0; + entryPath = String(); yield(); } SD.rmdir((char *)path.c_str()); - path = 0; + path = String(); file.close(); } @@ -186,7 +184,7 @@ void handleDelete(){ if(path == "/" || !SD.exists((char *)path.c_str())) return returnFail("BAD PATH"); deleteRecursive(path); returnOK(); - path = 0; + path = String(); } void handleCreate(){ @@ -203,7 +201,7 @@ void handleCreate(){ SD.mkdir((char *)path.c_str()); } returnOK(); - path = 0; + path = String(); } void printDirectory() { @@ -211,7 +209,7 @@ void printDirectory() { String path = server.arg("dir"); if(path != "/" && !SD.exists((char *)path.c_str())) return returnFail("BAD PATH"); File dir = SD.open((char *)path.c_str()); - path = 0; + path = String(); if(!dir.isDirectory()){ dir.close(); return returnFail("NOT DIR"); @@ -242,7 +240,7 @@ void printDirectory() { output += "]"; client.write(output.c_str(), output.length()); client.stop(); - output = 0; + output = String(); } void handleNotFound(){ From eb37830238220714e97f263e52bb6326379494e7 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 14 May 2015 02:48:30 +0300 Subject: [PATCH 5/5] move hexdump declaration to debug.h --- cores/esp8266/Arduino.h | 3 +-- cores/esp8266/debug.cpp | 24 +++++++++++++++++++----- cores/esp8266/debug.h | 5 ++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 9cc4ad08b..6b306eb2f 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -212,6 +212,7 @@ void loop(void); #include "HardwareSerial.h" #include "Esp.h" +#include "debug.h" uint16_t makeWord(uint16_t w); uint16_t makeWord(byte h, byte l); @@ -229,8 +230,6 @@ long random(long, long); void randomSeed(unsigned int); long map(long, long, long, long, long); -// Debugging functions -void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16); #endif diff --git a/cores/esp8266/debug.cpp b/cores/esp8266/debug.cpp index c42016b04..5e280122e 100644 --- a/cores/esp8266/debug.cpp +++ b/cores/esp8266/debug.cpp @@ -1,11 +1,25 @@ -/* - * debug.c - * - * Created on: 13.05.2015 - * Author: Markus Sattler +/* + debug.cpp - debug helper functions + Copyright (c) 2015 Markus Sattler. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "Arduino.h" +#include "debug.h" void ICACHE_RAM_ATTR hexdump(uint8_t *mem, uint32_t len, uint8_t cols) { os_printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", mem, len, len); diff --git a/cores/esp8266/debug.h b/cores/esp8266/debug.h index a312bfdfd..cf0830d3e 100644 --- a/cores/esp8266/debug.h +++ b/cores/esp8266/debug.h @@ -3,6 +3,9 @@ #include // #define DEBUGV(...) ets_printf(__VA_ARGS__) -#define DEBUGV(...) +#define DEBUGV(...) + +void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16); + #endif//ARD_DEBUG_H