Skip to content

Commit c2f8b45

Browse files
committed
WIP
1 parent c29a35d commit c2f8b45

File tree

17 files changed

+569
-39
lines changed

17 files changed

+569
-39
lines changed

cores/esp8266/Esp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "flash_utils.h"
2323
#include "eboot_command.h"
2424
#include <memory>
25-
#include "interrupts.h"
25+
#include <interrupts.h>
2626
#include "MD5Builder.h"
2727
#include "umm_malloc/umm_malloc.h"
2828
#include "cont.h"
@@ -165,6 +165,7 @@ void EspClass::restart(void)
165165
uint16_t EspClass::getVcc(void)
166166
{
167167
InterruptLock lock;
168+
(void)lock;
168169
return system_get_vdd33();
169170
}
170171

@@ -480,7 +481,7 @@ uint32_t EspClass::getFreeSketchSpace() {
480481
uint32_t usedSize = getSketchSize();
481482
// round one sector up
482483
uint32_t freeSpaceStart = (usedSize + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
483-
uint32_t freeSpaceEnd = (uint32_t)&_SPIFFS_start - 0x40200000;
484+
uint32_t freeSpaceEnd = (uint32_t)(unsigned long)&_SPIFFS_start - 0x40200000;
484485

485486
#ifdef DEBUG_SERIAL
486487
DEBUG_SERIAL.printf("usedSize=%u freeSpaceStart=%u freeSpaceEnd=%u\r\n", usedSize, freeSpaceStart, freeSpaceEnd);

cores/esp8266/Updater.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "Updater.h"
22
#include "Arduino.h"
33
#include "eboot_command.h"
4-
#include "interrupts.h"
5-
#include "esp8266_peri.h"
4+
#include <interrupts.h>
5+
#include <esp8266_peri.h>
66

77
//#define DEBUG_UPDATER Serial
88

@@ -89,7 +89,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
8989
//size of current sketch rounded to a sector
9090
uint32_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
9191
//address of the end of the space available for sketch and update
92-
uint32_t updateEndAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
92+
uint32_t updateEndAddress = (uint32_t)(unsigned long)&_SPIFFS_start - 0x40200000;
9393
//size of the update rounded to a sector
9494
uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
9595
//address where we will start writing the update
@@ -108,7 +108,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
108108
}
109109
}
110110
else if (command == U_SPIFFS) {
111-
updateStartAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
111+
updateStartAddress = (uint32_t)(unsigned long)&_SPIFFS_start - 0x40200000;
112112
}
113113
else {
114114
// unknown command
@@ -133,7 +133,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
133133
#ifdef DEBUG_UPDATER
134134
DEBUG_UPDATER.printf("[begin] _startAddress: 0x%08X (%d)\n", _startAddress, _startAddress);
135135
DEBUG_UPDATER.printf("[begin] _currentAddress: 0x%08X (%d)\n", _currentAddress, _currentAddress);
136-
DEBUG_UPDATER.printf("[begin] _size: 0x%08X (%d)\n", _size, _size);
136+
DEBUG_UPDATER.printf("[begin] _size: 0x%08X (%d)\n", (unsigned)_size, (unsigned)_size);
137137
#endif
138138

139139
_md5.begin();
@@ -159,7 +159,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
159159

160160
if(hasError() || (!isFinished() && !evenIfRemaining)){
161161
#ifdef DEBUG_UPDATER
162-
DEBUG_UPDATER.printf("premature end: res:%u, pos:%u/%u\n", getError(), progress(), _size);
162+
DEBUG_UPDATER.printf("premature end: res:%u, pos:%u/%u\n", getError(), (unsigned)progress(), (unsigned)_size);
163163
#endif
164164

165165
_reset();
@@ -199,10 +199,10 @@ bool UpdaterClass::end(bool evenIfRemaining){
199199
eboot_command_write(&ebcmd);
200200

201201
#ifdef DEBUG_UPDATER
202-
DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08X\n", _startAddress, _size);
202+
DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08X\n", _startAddress, (unsigned)_size);
203203
}
204204
else if (_command == U_SPIFFS) {
205-
DEBUG_UPDATER.printf("SPIFFS: address:0x%08X, size:0x%08X\n", _startAddress, _size);
205+
DEBUG_UPDATER.printf("SPIFFS: address:0x%08X, size:0x%08X\n", _startAddress, (unsigned)_size);
206206
#endif
207207
}
208208

libraries/DNSServer/src/DNSServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
DNSServer::DNSServer()
1212
{
13-
_ttl = htonl(60);
13+
_ttl = lwip_htonl(60);
1414
_errorReplyCode = DNSReplyCode::NonExistentDomain;
1515
}
1616

@@ -35,7 +35,7 @@ void DNSServer::setErrorReplyCode(const DNSReplyCode &replyCode)
3535

3636
void DNSServer::setTTL(const uint32_t &ttl)
3737
{
38-
_ttl = htonl(ttl);
38+
_ttl = lwip_htonl(ttl);
3939
}
4040

4141
void DNSServer::stop()
@@ -81,7 +81,7 @@ void DNSServer::processNextRequest()
8181

8282
bool DNSServer::requestIncludesOnlyOneQuestion(const DNSHeader* dnsHeader)
8383
{
84-
return ntohs(dnsHeader->QDCount) == 1 &&
84+
return lwip_ntohs(dnsHeader->QDCount) == 1 &&
8585
dnsHeader->ANCount == 0 &&
8686
dnsHeader->NSCount == 0 &&
8787
dnsHeader->ARCount == 0;

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
734734
free(buff);
735735

736736
if(size && (int) size != bytesWritten) {
737-
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, size);
737+
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, (int)size);
738738
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
739739
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
740740
} else {

tests/host/Makefile

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ PREINCLUDES := \
8080
-include common/mock.h \
8181
-include common/c_types.h \
8282

83+
ifneq ($(D),)
8384
DEBUG += -DDEBUG_ESP_PORT=Serial
8485
DEBUG += -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_CORE -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_ESP_MDNS
86+
endif
8587

8688
CXXFLAGS += $(DEBUG) -std=c++11 -Wall -Werror -coverage -O0 -fno-common -g
8789
CFLAGS += -std=c99 -Wall -Werror -coverage -O0 -fno-common -g
8890
LDFLAGS += -coverage -O0 -g
8991
VALGRINDFLAGS += --leak-check=full --track-origins=yes --error-limit=no --show-leak-kinds=all --error-exitcode=999
9092
#
9193
CXXFLAGS += -Wno-nonnull-compare # libraries/ESP8266WiFi/src/include/UdpContext.h:85:9: error: nonnull argument ‘this’ compared to NULL [-Werror=nonnull-compare] -- (if(this != 0))
94+
CXXFLAGS += -Wno-error=format-security # cores/esp8266/Print.cpp:42:24: error: format not a string literal and no format arguments [-Werror=format-security] -- (os_printf_plus(not_the_best_way))
9295

9396
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
9497

@@ -157,7 +160,11 @@ $(OUTPUT_BINARY): $(CPP_OBJECTS_TESTS) $(BINDIR)/core.a
157160
#################################################
158161
# building ino sources
159162

160-
MOCK_ARDUINO_LIBS := \
163+
ARDUINO_LIBS := \
164+
$(addprefix $(CORE_PATH)/,\
165+
IPAddress.cpp \
166+
Updater.cpp \
167+
) \
161168
$(addprefix ../../libraries/,\
162169
$(addprefix ESP8266WiFi/src/,\
163170
ESP8266WiFi.cpp \
@@ -176,23 +183,27 @@ MOCK_ARDUINO_LIBS := \
176183
detail/mimetable.cpp \
177184
) \
178185
ESP8266mDNS/ESP8266mDNS.cpp \
179-
)
186+
ArduinoOTA/ArduinoOTA.cpp \
187+
DNSServer/src/DNSServer.cpp \
188+
ESP8266AVRISP/src/ESP8266AVRISP.cpp \
189+
ESP8266HTTPClient/src/ESP8266HTTPClient.cpp \
190+
) \
180191

181192

182193

183-
MOCK_ARDUINO_LIBS += \
194+
MOCK_ARDUINO_LIBS := \
184195
common/MockClientContextSocket.cpp \
185196
common/MockClientContext.cpp \
186197
common/MockWiFiServerSocket.cpp \
187198
common/MockWiFiServer.cpp \
188199
common/MockUDPSocket.cpp \
189200
common/ArduinoWire.cpp \
190201
common/MockTools.cpp \
202+
common/MockEsp.cpp \
203+
common/MockEEPROM.cpp \
204+
common/MockSPI.cpp \
191205

192-
ARDUINO_LIBS += $(addprefix $(CORE_PATH)/,\
193-
IPAddress.cpp \
194-
)
195-
206+
ARDUINO_LIBS +=
196207
CPP_SOURCES_CORE_EMU = \
197208
$(MOCK_CPP_FILES_EMU) \
198209
$(CORE_CPP_FILES) \
@@ -206,18 +217,37 @@ bin/fullcore.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE_EMU)
206217
ranlib -c $@
207218

208219
.PRECIOUS: %.cpp.o
209-
%: %.cpp.o bin/fullcore.a
220+
%: %.ino.cpp.o bin/fullcore.a
210221
$(CXX) $(LDFLAGS) $< bin/fullcore.a -o $@
211222
ln -sf ../$@ $(BINDIR)
212223

213224
.PRECIOUS: %.cpp
214-
%.cpp: %.ino
215-
cp $< $@
225+
%.ino.cpp: %.ino
226+
@s=$<; \
227+
n=$${s##*/}; \
228+
(cd $${s%/*}; \
229+
echo "#include \"$$n\""; \
230+
for i in *.ino; do \
231+
test "$$i" = "$$n" || echo "#include \"$$i\""; \
232+
done; \
233+
) > $@
216234

217235
#################################################
218236
# Makefile.inc.ino generation
219237
-include $(BINDIR)/Makefile.inc.ino
220238

239+
.PHONY: list
240+
list:
241+
# copy examples locally
242+
@for dir in ../../libraries/*/examples; do \
243+
exampledir=$${dir%/*}; \
244+
exampledirname=$${exampledir##*/}; \
245+
for subdir in $$dir/*; do \
246+
exname=$${subdir##*/}; \
247+
echo "$$subdir/$$exname"; \
248+
done; \
249+
done; \
250+
221251
$(BINDIR)/Makefile.inc.ino:
222252
# copy examples locally
223253
all=""; \

tests/host/common/Arduino.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,22 @@ extern "C" unsigned long millis()
2525
return (time.tv_sec * 1000) + (time.tv_usec / 1000);
2626
}
2727

28+
extern "C" unsigned long micros()
29+
{
30+
timeval time;
31+
gettimeofday(&time, NULL);
32+
return (time.tv_sec * 1000000) + time.tv_usec;
33+
}
34+
2835

2936
extern "C" void yield()
3037
{
3138
}
3239

40+
extern "C" void esp_yield()
41+
{
42+
}
43+
3344

3445
extern "C" void __panic_func(const char* file, int line, const char* func) {
3546
abort();
@@ -39,3 +50,8 @@ extern "C" void delay(unsigned long ms)
3950
{
4051
usleep(ms * 1000);
4152
}
53+
54+
extern "C" void delayMicroseconds(unsigned int us)
55+
{
56+
usleep(us);
57+
}

tests/host/common/ArduinoMain.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <poll.h>
1212

1313
#include <unistd.h> // usleep
14+
#include <getopt.h>
15+
1416
#include <map>
1517

1618
std::map<int,UdpContext*> udps;
@@ -23,9 +25,43 @@ void register_udp (int sock, UdpContext* udp)
2325
udps.erase(sock);
2426
}
2527

28+
const char* host_interface = nullptr;
29+
30+
void help (const char* argv0, int exitcode)
31+
{
32+
printf(
33+
"%s - compiled with esp8266/arduino emulator\n"
34+
"options:\n"
35+
" -h\n"
36+
" -i <interface>\n"
37+
,argv0);
38+
exit(exitcode);
39+
}
40+
41+
static struct option options[] =
42+
{
43+
{ "help", no_argument, NULL, 'h' },
44+
{ "interface", required_argument, NULL, 'i' },
45+
};
2646

27-
int main (void)
47+
int main (int argc, char* const argv [])
2848
{
49+
for (;;)
50+
{
51+
int n = getopt_long(argc, argv, "hi:", options, NULL);
52+
if (n < 0)
53+
break;
54+
switch (n)
55+
{
56+
case 'h':
57+
help(argv[0], EXIT_SUCCESS);
58+
break;
59+
case 'i':
60+
host_interface = optarg;
61+
break;
62+
}
63+
}
64+
2965
setup();
3066
while (true)
3167
{

tests/host/common/ArduinoWire.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ void digitalWrite(uint8_t pin, uint8_t val)
2424
fprintf(stderr, MOCK "digitalWrite(pin=%d val=%d)\n", pin, val);
2525
}
2626

27+
void analogWrite(uint8_t pin, int val)
28+
{
29+
fprintf(stderr, MOCK "analogWrite(pin=%d, val=%d\n", pin, val);
30+
}
31+
32+
int analogRead(uint8_t pin)
33+
{
34+
(void)pin;
35+
return 512;
36+
}
37+
38+
void analogWriteRange(uint32_t range)
39+
{
40+
fprintf(stderr, MOCK "analogWriteRange(range=%d)\n", range);
41+
}

tests/host/common/EEPROM.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
#ifndef EEPROM_MOCK
3+
#define EEPROM_MOCK
4+
5+
class EEPROMClass {
6+
public:
7+
EEPROMClass(uint32_t sector);
8+
EEPROMClass(void);
9+
~EEPROMClass();
10+
11+
void begin(size_t size);
12+
uint8_t read(int address);
13+
void write(int address, uint8_t val);
14+
bool commit();
15+
void end();
16+
17+
template<typename T>
18+
T& get(int const address, T& t)
19+
{
20+
if (address < 0 || address + sizeof(T) > _size)
21+
return t;
22+
for (size_t i = 0; i < sizeof(T); i++)
23+
((uint8_t*)&t)[i] = read(i);
24+
return t;
25+
}
26+
27+
template<typename T>
28+
const T& put(int const address, const T& t)
29+
{
30+
if (address < 0 || address + sizeof(T) > _size)
31+
return t;
32+
for (size_t i = 0; i < sizeof(T); i++)
33+
write(i, ((uint8_t*)&t)[i]);
34+
return t;
35+
}
36+
37+
size_t length() { return _size; }
38+
39+
//uint8_t& operator[](int const address) { return read(address); }
40+
uint8_t operator[] (int address) { return read(address); }
41+
42+
protected:
43+
size_t _size = 0;
44+
int _fd = -1;
45+
};
46+
47+
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
48+
extern EEPROMClass EEPROM;
49+
#endif
50+
51+
#endif

0 commit comments

Comments
 (0)