Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow test framework to use cores/esp8266/Arduino.h directly #7377

Merged
merged 23 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
84d8866
Allow test framework to use cores/esp8266/Arduino.h directly
mcspr Jun 14, 2020
c89d0f6
fix wps debugging
mcspr Jun 14, 2020
0e0849d
some more missing debug.h
mcspr Jun 14, 2020
65fab13
Merge remote-tracking branch 'origin/master' into tests/sync-arduino-h
mcspr Jul 17, 2020
555c272
Hunt down debug.h and roll-back
mcspr Jul 17, 2020
6b36f6e
Move abs+round checks to test/device/test_sw
mcspr Jul 17, 2020
ffc3744
Restore macros for C code
mcspr Jul 17, 2020
6db24f8
fixup! Move abs+round checks to test/device/test_sw
mcspr Jul 18, 2020
e59f926
Fix bad c/p, actually try round with ints
mcspr Jul 18, 2020
0c8c7ab
Merge branch 'master' into tests/sync-arduino-h
d-a-v Jul 28, 2020
1f14878
tweak c macros per review
mcspr Aug 16, 2020
9e1b019
Merge remote-tracking branch 'origin/master' into tests/sync-arduino-h
mcspr Aug 17, 2020
247c6c3
fix gcc-10 missing cerrno include
mcspr Aug 17, 2020
685c25f
amend 555c272, again
mcspr Aug 17, 2020
60de322
fixup! Merge remote-tracking branch 'origin/master' into tests/sync-a…
mcspr Aug 17, 2020
1a2fd27
fixup! amend 555c272, again
mcspr Aug 17, 2020
8c89d90
switch to the current -std=... opts
mcspr Aug 17, 2020
f48cd49
Revert "switch to the current -std=... opts"
mcspr Aug 17, 2020
481b351
trying to fix CI, clean-up configTime decl + def
mcspr Aug 17, 2020
b496509
Merge branch 'master' into tests/sync-arduino-h
mcspr Sep 9, 2020
8e7a003
Merge remote-tracking branch 'origin/master' into tests/sync-arduino-h
mcspr Oct 6, 2020
1fa62d4
Merge branch 'master' into tests/sync-arduino-h
mcspr Oct 6, 2020
3d7379f
Merge branch 'master' into tests/sync-arduino-h
d-a-v Oct 6, 2020
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
48 changes: 31 additions & 17 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern "C" {
#include "binary.h"
#include "esp8266_peri.h"
#include "twi.h"

#include "core_esp8266_features.h"
#include "core_esp8266_version.h"

Expand Down Expand Up @@ -127,21 +128,26 @@ void timer0_isr_init(void);
void timer0_attachInterrupt(timercallback userFunc);
void timer0_detachInterrupt(void);

// undefine stdlib's abs if encountered
// undefine stdlib's definitions when encountered, provide abs that supports floating point for C code
// in case we are using c++, these will either be:
// - undef'ed by the algorithm include down below, implicitly including cstdlib
// - undef'ed by the stdlib.h header up above in a more recent versions of gcc
#ifdef abs
#undef abs
#define abs(x) ((x)>0?(x):-(x))
#endif

#define abs(x) ((x)>0?(x):-(x))
#ifdef round
#undef round
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#endif

// the rest of math definitions are from Arduino
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))

void ets_intr_lock();
void ets_intr_unlock();

#define interrupts() xt_rsil(0)
#define noInterrupts() xt_rsil(15)

Expand Down Expand Up @@ -170,11 +176,12 @@ typedef uint16_t word;
typedef bool boolean;
typedef uint8_t byte;

void ets_intr_lock();
void ets_intr_unlock();

void init(void);
void initVariant(void);

int atexit(void (*func)()) __attribute__((weak));

void pinMode(uint8_t pin, uint8_t mode);
void digitalWrite(uint8_t pin, uint8_t val);
int digitalRead(uint8_t pin);
Expand Down Expand Up @@ -233,25 +240,22 @@ const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256;



// from this point onward, we need to configure the c++ environment
#ifdef __cplusplus

#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <pgmspace.h>

#include "WCharacter.h"
#include "WString.h"

#include "HardwareSerial.h"
#include "Esp.h"
#include "Updater.h"
#include "debug.h"

using std::min;
using std::max;
using std::isinf;
using std::isnan;

// these are important, as we may end up using C versions otherwise
using std::abs;
using std::round;

#define _min(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a < _b? _a : _b; })
#define _max(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a > _b? _a : _b; })

Expand Down Expand Up @@ -291,6 +295,16 @@ inline void configTzTime(const char* tz, const char* server1,
configTime(tz, server1, server2, server3);
}

// Everything we expect to be implicitly loaded for the sketch
#include <pgmspace.h>

#include "WCharacter.h"
#include "WString.h"

#include "HardwareSerial.h"
#include "Esp.h"
#include "Updater.h"

#endif // __cplusplus

#include "pins_arduino.h"
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "MD5Builder.h"
#include "umm_malloc/umm_malloc.h"
#include "cont.h"

#include "coredecls.h"
#include <pgmspace.h>

extern "C" {
#include "user_interface.h"
Expand Down
14 changes: 4 additions & 10 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define ESP_H

#include <Arduino.h>
#include "core_esp8266_features.h"
#include "spi_vendors.h"

/**
Expand Down Expand Up @@ -168,21 +169,14 @@ class EspClass {
uint32_t random() const;

#ifndef CORE_MOCK
inline uint32_t getCycleCount() __attribute__((always_inline));
uint32_t getCycleCount() __attribute__((always_inline)) {
return esp_get_cycle_count();
}
#else
uint32_t getCycleCount();
#endif
};

#ifndef CORE_MOCK

uint32_t EspClass::getCycleCount()
{
return esp_get_cycle_count();
}

#endif // !defined(CORE_MOCK)

extern EspClass ESP;

#endif //ESP_H
13 changes: 11 additions & 2 deletions cores/esp8266/core_esp8266_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

#ifdef __cplusplus

#include <pgmspace.h>

namespace arduino
{
extern "C++"
Expand Down Expand Up @@ -82,7 +84,13 @@ namespace arduino
// level 15 will disable ALL interrupts,
// level 0 will enable ALL interrupts,
//
#ifndef CORE_MOCK
#ifdef CORE_MOCK

#define xt_rsil(level) (level)
#define xt_wsr_ps(state) do { (void)(state); } while (0)

#else

#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")

Expand All @@ -92,7 +100,8 @@ inline uint32_t esp_get_cycle_count() {
__asm__ __volatile__("rsr %0,ccount":"=a"(ccount));
return ccount;
}
#endif // not CORE_MOCK

#endif // ifdef CORE_MOCK


// Tools for preloading code into the flash cache
Expand Down
5 changes: 5 additions & 0 deletions cores/esp8266/esp8266_peri.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#ifndef ESP8266_PERI_H_INCLUDED
#define ESP8266_PERI_H_INCLUDED

// we expect mocking framework to provide these
#ifndef CORE_MOCK

#include "c_types.h"
#include "esp8266_undocumented.h"

Expand Down Expand Up @@ -847,4 +850,6 @@ extern volatile uint32_t* const esp8266_gpioToFn[16];
**/
#define RANDOM_REG32 ESP8266_DREG(0x20E44)

#endif // ifndef CORE_MOCK

#endif
1 change: 1 addition & 0 deletions cores/esp8266/libc_replacements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void _exit(int status) {
abort();
}

int atexit(void (*func)()) __attribute__((weak));
int atexit(void (*func)()) {
(void) func;
return 0;
Expand Down
30 changes: 30 additions & 0 deletions libraries/esp8266/examples/math/math.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Small math example, checking whether we can support various Arduino math operations.
Meant for debugging **only**

Released to public domain
*/

void setup() {
Serial.begin(115200);

// checking if we can support Arduino functions
Serial.printf("abs(-3)\n = %d", abs(-3));
Serial.printf("abs(+3)\n = %d", abs(3));
Serial.printf("abs(-3.5)\n = %f", abs(-3.5));
Serial.printf("abs(+3.5)\n = %f", abs(3.5));
Serial.printf("round(2.9)\n = %f", round(2.9));
Serial.printf("constrain(5, 1, 15) = %d\n", constrain(5, 1, 15));
Serial.printf("constrain(16, 1, 15) = %d\n", constrain(16, 1, 15));

// the same thing, but with c++ std::..., which should not cause any conflicts
Serial.printf("std::abs(-3) = %d\n", std::abs(-3));
Serial.printf("std::abs(+3) = %d\n", std::abs(3));
Serial.printf("std::abs(-3.5) = %f\n", std::abs(-3.5));
Serial.printf("std::abs(+3.5) = %f\n", std::abs(3.5));
Serial.printf("std::round(2.9) = %f\n", std::round(2.9));
}

void loop() {
}

1 change: 1 addition & 0 deletions tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ FLAGS += -DHTTPCLIENT_1_1_COMPATIBLE=0
FLAGS += -DLWIP_IPV6=0
FLAGS += -DHOST_MOCK=1
FLAGS += -DNONOSDK221=1
FLAGS += -DF_CPU=80000000
FLAGS += $(MKFLAGS)
FLAGS += -Wimplicit-fallthrough=2 # allow "// fall through" comments to stop spurious warnings
CXXFLAGS += -std=c++11 -fno-rtti $(FLAGS) -funsigned-char
Expand Down
Loading