diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index fc270cfed..129b55eda 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -1,168 +1,168 @@ -/* - HardwareSerial.cpp - esp8266 UART support - - Copyright (c) 2014 Ivan Grokhotkov. 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 - - Modified 31 March 2015 by Markus Sattler (rewrite the code for UART0 + UART1 support in ESP8266) - Modified 25 April 2015 by Thomas Flayols (add configuration different from 8N1 in ESP8266) - Modified 3 May 2015 by Hristo Gochkov (change register access methods) - */ - -#include -#include -#include -#include -#include -#include "Arduino.h" -#include "HardwareSerial.h" -#include "Esp.h" - -HardwareSerial::HardwareSerial(int uart_nr) - : _uart_nr(uart_nr), _rx_size(256) -{} - -void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin) -{ - end(); - _uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size); -#if defined(DEBUG_ESP_PORT) && !defined(NDEBUG) - if (static_cast(this) == static_cast(&DEBUG_ESP_PORT)) - { - setDebugOutput(true); - println(); - println(ESP.getFullVersion()); - } -#endif -} - -void HardwareSerial::end() -{ - if(uart_get_debug() == _uart_nr) { - uart_set_debug(UART_NO); - } - - uart_uninit(_uart); - _uart = NULL; -} - -void HardwareSerial::updateBaudRate(unsigned long baud) -{ - if(!_uart) { - return; - } - - uart_set_baudrate(_uart, baud); -} - -size_t HardwareSerial::setRxBufferSize(size_t size){ - if(_uart) { - _rx_size = uart_resize_rx_buffer(_uart, size); - } else { - _rx_size = size; - } - return _rx_size; -} - -void HardwareSerial::setDebugOutput(bool en) -{ - if(!_uart) { - return; - } - if(en) { - if(uart_tx_enabled(_uart)) { - uart_set_debug(_uart_nr); - } else { - uart_set_debug(UART_NO); - } - } else { - // disable debug for this interface - if(uart_get_debug() == _uart_nr) { - uart_set_debug(UART_NO); - } - } -} - -int HardwareSerial::available(void) -{ - int result = static_cast(uart_rx_available(_uart)); - if (!result) { - optimistic_yield(10000); - } - return result; -} - -void HardwareSerial::flush() -{ +/* + HardwareSerial.cpp - esp8266 UART support + + Copyright (c) 2014 Ivan Grokhotkov. 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 + + Modified 31 March 2015 by Markus Sattler (rewrite the code for UART0 + UART1 support in ESP8266) + Modified 25 April 2015 by Thomas Flayols (add configuration different from 8N1 in ESP8266) + Modified 3 May 2015 by Hristo Gochkov (change register access methods) + */ + +#include +#include +#include +#include +#include +#include "Arduino.h" +#include "HardwareSerial.h" +#include "Esp.h" + +HardwareSerial::HardwareSerial(int uart_nr) + : _uart_nr(uart_nr), _rx_size(256) +{} + +void HardwareSerial::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin) +{ + end(); + _uart = uart_init(_uart_nr, baud, (int) config, (int) mode, tx_pin, _rx_size); +#if defined(DEBUG_ESP_PORT) && !defined(NDEBUG) + if (static_cast(this) == static_cast(&DEBUG_ESP_PORT)) + { + setDebugOutput(true); + println(); + println(ESP.getFullVersion()); + } +#endif +} + +void HardwareSerial::end() +{ + if(uart_get_debug() == _uart_nr) { + uart_set_debug(UART_NO); + } + + uart_uninit(_uart); + _uart = NULL; +} + +void HardwareSerial::updateBaudRate(unsigned long baud) +{ + if(!_uart) { + return; + } + + uart_set_baudrate(_uart, baud); +} + +size_t HardwareSerial::setRxBufferSize(size_t size){ + if(_uart) { + _rx_size = uart_resize_rx_buffer(_uart, size); + } else { + _rx_size = size; + } + return _rx_size; +} + +void HardwareSerial::setDebugOutput(bool en) +{ + if(!_uart) { + return; + } + if(en) { + if(uart_tx_enabled(_uart)) { + uart_set_debug(_uart_nr); + } else { + uart_set_debug(UART_NO); + } + } else { + // disable debug for this interface + if(uart_get_debug() == _uart_nr) { + uart_set_debug(UART_NO); + } + } +} + +int HardwareSerial::available(void) +{ + int result = static_cast(uart_rx_available(_uart)); + if (!result) { + optimistic_yield(10000); + } + return result; +} + +void HardwareSerial::flush() +{ uint8_t bit_length = 0; - if(!_uart || !uart_tx_enabled(_uart)) { - return; - } - + if(!_uart || !uart_tx_enabled(_uart)) { + return; + } + bit_length = uart_get_bit_length(_uart_nr); // data width, parity and stop - uart_wait_tx_empty(_uart); - //Workaround for a bug in serial not actually being finished yet - //Wait for 8 data bits, 1 parity and 2 stop bits, just in case - delayMicroseconds(bit_length * 1000000 / uart_get_baudrate(_uart) + 1); -} - -void HardwareSerial::startDetectBaudrate() -{ - uart_start_detect_baudrate(_uart_nr); -} - -unsigned long HardwareSerial::testBaudrate() -{ - return uart_detect_baudrate(_uart_nr); -} - -unsigned long HardwareSerial::detectBaudrate(time_t timeoutMillis) -{ - esp8266::polledTimeout::oneShotFastMs timeOut(timeoutMillis); - unsigned long detectedBaudrate; - while (!timeOut) { - if ((detectedBaudrate = testBaudrate())) { - break; - } - yield(); - delay(100); - } - return detectedBaudrate; -} - -size_t HardwareSerial::readBytes(char* buffer, size_t size) -{ - size_t got = 0; - - while (got < size) - { - esp8266::polledTimeout::oneShotFastMs timeOut(_timeout); - size_t avail; - while ((avail = available()) == 0 && !timeOut); - if (avail == 0) - break; - got += read(buffer + got, std::min(size - got, avail)); - } - return got; -} - -#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) -HardwareSerial Serial(UART0); -#endif -#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1) -HardwareSerial Serial1(UART1); -#endif + uart_wait_tx_empty(_uart); + //Workaround for a bug in serial not actually being finished yet + //Wait for 8 data bits, 1 parity and 2 stop bits, just in case + delayMicroseconds(bit_length * 1000000 / uart_get_baudrate(_uart) + 1); +} + +void HardwareSerial::startDetectBaudrate() +{ + uart_start_detect_baudrate(_uart_nr); +} + +unsigned long HardwareSerial::testBaudrate() +{ + return uart_detect_baudrate(_uart_nr); +} + +unsigned long HardwareSerial::detectBaudrate(time_t timeoutMillis) +{ + esp8266::polledTimeout::oneShotFastMs timeOut(timeoutMillis); + unsigned long detectedBaudrate; + while (!timeOut) { + if ((detectedBaudrate = testBaudrate())) { + break; + } + yield(); + delay(100); + } + return detectedBaudrate; +} + +size_t HardwareSerial::readBytes(char* buffer, size_t size) +{ + size_t got = 0; + + while (got < size) + { + esp8266::polledTimeout::oneShotFastMs timeOut(_timeout); + size_t avail; + while ((avail = available()) == 0 && !timeOut); + if (avail == 0) + break; + got += read(buffer + got, std::min(size - got, avail)); + } + return got; +} + +#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) +HardwareSerial Serial(UART0); +#endif +#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1) +HardwareSerial Serial1(UART1); +#endif diff --git a/cores/esp8266/StreamString.h b/cores/esp8266/StreamString.h index 1fedc18de..2e81fa14a 100644 --- a/cores/esp8266/StreamString.h +++ b/cores/esp8266/StreamString.h @@ -1,39 +1,39 @@ -/** - StreamString.h - - 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 - -*/ - -#ifndef STREAMSTRING_H_ -#define STREAMSTRING_H_ - - -class StreamString: public Stream, public String { -public: - size_t write(const uint8_t *buffer, size_t size) override; - size_t write(uint8_t data) override; - - int available() override; - int read() override; - int peek() override; - void flush() override; -}; - - -#endif /* STREAMSTRING_H_ */ +/** + StreamString.h + + 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 + +*/ + +#ifndef STREAMSTRING_H_ +#define STREAMSTRING_H_ + + +class StreamString: public Stream, public String { +public: + size_t write(const uint8_t *buffer, size_t size) override; + size_t write(uint8_t data) override; + + int available() override; + int read() override; + int peek() override; + void flush() override; +}; + + +#endif /* STREAMSTRING_H_ */ diff --git a/cores/esp8266/base64.cpp b/cores/esp8266/base64.cpp index 7771153b0..f0d079352 100644 --- a/cores/esp8266/base64.cpp +++ b/cores/esp8266/base64.cpp @@ -1,71 +1,71 @@ -/** - * base64.cpp - * - * Created on: 09.12.2015 - * - * Copyright (c) 2015 Markus Sattler. All rights reserved. - * This file is part of the ESP8266 core for Arduino. - * - * 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" -extern "C" { -#include "libb64/cdecode.h" -#include "libb64/cencode.h" -} -#include "base64.h" - -/** - * convert input data to base64 - * @param data const uint8_t * - * @param length size_t - * @return String - */ -String base64::encode(const uint8_t * data, size_t length, bool doNewLines) { - // base64 needs more size then the source data, use cencode.h macros - size_t size = ((doNewLines ? base64_encode_expected_len(length) - : base64_encode_expected_len_nonewlines(length)) + 1); - char * buffer = (char *) malloc(size); - if(buffer) { - base64_encodestate _state; - if(doNewLines) - { - base64_init_encodestate(&_state); - } - else - { - base64_init_encodestate_nonewlines(&_state); - } - int len = base64_encode_block((const char *) &data[0], length, &buffer[0], &_state); - len = base64_encode_blockend((buffer + len), &_state); - - String base64 = String(buffer); - free(buffer); - return base64; - } - return String("-FAIL-"); -} - -/** - * convert input data to base64 - * @param text const String& - * @return String - */ -String base64::encode(const String& text, bool doNewLines) { - return base64::encode((const uint8_t *) text.c_str(), text.length(), doNewLines); -} - +/** + * base64.cpp + * + * Created on: 09.12.2015 + * + * Copyright (c) 2015 Markus Sattler. All rights reserved. + * This file is part of the ESP8266 core for Arduino. + * + * 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" +extern "C" { +#include "libb64/cdecode.h" +#include "libb64/cencode.h" +} +#include "base64.h" + +/** + * convert input data to base64 + * @param data const uint8_t * + * @param length size_t + * @return String + */ +String base64::encode(const uint8_t * data, size_t length, bool doNewLines) { + // base64 needs more size then the source data, use cencode.h macros + size_t size = ((doNewLines ? base64_encode_expected_len(length) + : base64_encode_expected_len_nonewlines(length)) + 1); + char * buffer = (char *) malloc(size); + if(buffer) { + base64_encodestate _state; + if(doNewLines) + { + base64_init_encodestate(&_state); + } + else + { + base64_init_encodestate_nonewlines(&_state); + } + int len = base64_encode_block((const char *) &data[0], length, &buffer[0], &_state); + len = base64_encode_blockend((buffer + len), &_state); + + String base64 = String(buffer); + free(buffer); + return base64; + } + return String("-FAIL-"); +} + +/** + * convert input data to base64 + * @param text const String& + * @return String + */ +String base64::encode(const String& text, bool doNewLines) { + return base64::encode((const uint8_t *) text.c_str(), text.length(), doNewLines); +} + diff --git a/cores/esp8266/base64.h b/cores/esp8266/base64.h index 2816877da..1d6e22fac 100644 --- a/cores/esp8266/base64.h +++ b/cores/esp8266/base64.h @@ -1,39 +1,39 @@ -/** - * base64.h - * - * Created on: 09.12.2015 - * - * Copyright (c) 2015 Markus Sattler. All rights reserved. - * This file is part of the ESP8266 core for Arduino. - * - * 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 - * - */ - -#ifndef CORE_BASE64_H_ -#define CORE_BASE64_H_ - -class base64 { - public: - // NOTE: The default behaviour of backend (lib64) - // is to add a newline every 72 (encoded) characters output. - // This may 'break' longer uris and json variables - static String encode(const uint8_t * data, size_t length, bool doNewLines = true); - static String encode(const String& text, bool doNewLines = true); - private: -}; - - -#endif /* CORE_BASE64_H_ */ +/** + * base64.h + * + * Created on: 09.12.2015 + * + * Copyright (c) 2015 Markus Sattler. All rights reserved. + * This file is part of the ESP8266 core for Arduino. + * + * 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 + * + */ + +#ifndef CORE_BASE64_H_ +#define CORE_BASE64_H_ + +class base64 { + public: + // NOTE: The default behaviour of backend (lib64) + // is to add a newline every 72 (encoded) characters output. + // This may 'break' longer uris and json variables + static String encode(const uint8_t * data, size_t length, bool doNewLines = true); + static String encode(const String& text, bool doNewLines = true); + private: +}; + + +#endif /* CORE_BASE64_H_ */ diff --git a/cores/esp8266/core_esp8266_features.h b/cores/esp8266/core_esp8266_features.h index 6b8e22c9b..05bbc4c5c 100644 --- a/cores/esp8266/core_esp8266_features.h +++ b/cores/esp8266/core_esp8266_features.h @@ -1,50 +1,50 @@ -/* - core_esp8266_features.h - list of features integrated in to ESP8266 core - - Copyright (c) 2014 Ivan Grokhotkov. 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 - - */ - - -#ifndef CORE_ESP8266_FEATURES_H -#define CORE_ESP8266_FEATURES_H - - -#define CORE_HAS_LIBB64 -#define CORE_HAS_BASE64_CLASS -#define CORE_HAS_CXA_GUARD -#define CORE_HAS_UMM - -#define WIFI_HAS_EVENT_CALLBACK - -#ifdef __cplusplus - -#include // malloc() -#include // size_t - +/* + core_esp8266_features.h - list of features integrated in to ESP8266 core + + Copyright (c) 2014 Ivan Grokhotkov. 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 + + */ + + +#ifndef CORE_ESP8266_FEATURES_H +#define CORE_ESP8266_FEATURES_H + + +#define CORE_HAS_LIBB64 +#define CORE_HAS_BASE64_CLASS +#define CORE_HAS_CXA_GUARD +#define CORE_HAS_UMM + +#define WIFI_HAS_EVENT_CALLBACK + +#ifdef __cplusplus + +#include // malloc() +#include // size_t + namespace arduino -{ +{ extern "C++" template T* new0 (size_t n, TConstructorArgs... TconstructorArgs) - { - // n==0: single allocation, otherwise it is an array - size_t offset = n? sizeof(size_t): 0; + { + // n==0: single allocation, otherwise it is an array + size_t offset = n? sizeof(size_t): 0; size_t arraysize = n? n: 1; T* ptr = (T*)malloc(offset + (arraysize * sizeof(T))); if (ptr) @@ -54,43 +54,43 @@ namespace arduino for (size_t i = 0; i < arraysize; i++) new (ptr + offset + i * sizeof(T)) T(TconstructorArgs...); return ptr + offset; - } + } return nullptr; } } - -#define arduino_new(Type, ...) arduino::new0(0, ##__VA_ARGS__) -#define arduino_newarray(Type, n, ...) arduino::new0(n, ##__VA_ARGS__) - -#endif // __cplusplus - -#ifndef __STRINGIFY -#define __STRINGIFY(a) #a -#endif - -// these low level routines provide a replacement for SREG interrupt save that AVR uses -// but are esp8266 specific. A normal use pattern is like -// -//{ -// uint32_t savedPS = xt_rsil(1); // this routine will allow level 2 and above -// // do work here -// xt_wsr_ps(savedPS); // restore the state -//} -// -// level (0-15), interrupts of the given level and above will be active -// level 15 will disable ALL interrupts, -// level 0 will enable ALL interrupts, -// -#ifndef CORE_MOCK -#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state) :: "memory"); state;})) -#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory") - + +#define arduino_new(Type, ...) arduino::new0(0, ##__VA_ARGS__) +#define arduino_newarray(Type, n, ...) arduino::new0(n, ##__VA_ARGS__) + +#endif // __cplusplus + +#ifndef __STRINGIFY +#define __STRINGIFY(a) #a +#endif + +// these low level routines provide a replacement for SREG interrupt save that AVR uses +// but are esp8266 specific. A normal use pattern is like +// +//{ +// uint32_t savedPS = xt_rsil(1); // this routine will allow level 2 and above +// // do work here +// xt_wsr_ps(savedPS); // restore the state +//} +// +// level (0-15), interrupts of the given level and above will be active +// level 15 will disable ALL interrupts, +// level 0 will enable ALL interrupts, +// +#ifndef CORE_MOCK +#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state) :: "memory"); state;})) +#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory") + inline uint32_t esp_get_cycle_count() __attribute__((always_inline)); inline uint32_t esp_get_cycle_count() { - uint32_t ccount; - __asm__ __volatile__("rsr %0,ccount":"=a"(ccount)); - return ccount; -} -#endif // not CORE_MOCK - -#endif // CORE_ESP8266_FEATURES_H + uint32_t ccount; + __asm__ __volatile__("rsr %0,ccount":"=a"(ccount)); + return ccount; +} +#endif // not CORE_MOCK + +#endif // CORE_ESP8266_FEATURES_H diff --git a/cores/esp8266/debug.cpp b/cores/esp8266/debug.cpp index d8bf8bb11..0d0bde2df 100644 --- a/cores/esp8266/debug.cpp +++ b/cores/esp8266/debug.cpp @@ -1,36 +1,36 @@ -/* - 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(const void *mem, uint32_t len, uint8_t cols) { - const uint8_t* src = (const uint8_t*) mem; - os_printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); - for(uint32_t i = 0; i < len; i++) { - if(i % cols == 0) { - os_printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); - yield(); - } - os_printf("%02X ", *src); - src++; - } - os_printf("\n"); -} +/* + 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(const void *mem, uint32_t len, uint8_t cols) { + const uint8_t* src = (const uint8_t*) mem; + os_printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); + for(uint32_t i = 0; i < len; i++) { + if(i % cols == 0) { + os_printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); + yield(); + } + os_printf("%02X ", *src); + src++; + } + os_printf("\n"); +}