-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathmain.cpp
171 lines (138 loc) · 3.28 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright (c) 2016-2023 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK Runtime.
*
* The Moddable SDK Runtime 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 3 of the License, or
* (at your option) any later version.
*
* The Moddable SDK Runtime 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 the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define __XS6PLATFORMMINIMAL__
#include <Arduino.h>
#include "xs.h"
#include "xsHost.h"
#include "xsHosts.h"
#include "modTimer.h"
#include "modInstrumentation.h"
extern "C" {
#include "user_interface.h" // to get system_soft_wdt_feed
extern void fx_putc(void *refcon, char c);
extern void __wrap_espconn_init(void);
extern uint8_t uart_set_baud(uart_t* uart, int baudrate);
}
void __wrap_espconn_init(void)
{
}
/*
Wi-Fi configuration and xsbug IP address
IP address either:
0,0,0,0 - no xsbug connection
127,0,0,7 - xsbug over serial
w,x,y,z - xsbug over TCP (address of computer running xsbug)
*/
#define XSDEBUG_NONE 0,0,0,0
#define XSDEBUG_SERIAL 127,0,0,7
#ifndef DEBUG_IP
#define DEBUG_IP XSDEBUG_SERIAL
#endif
#ifdef mxDebug
unsigned char gXSBUG[4] = {DEBUG_IP};
static xsMachine *gThe; // root virtual machine
#endif
static uart_t *gUART;
#ifndef DEBUGGER_SPEED
#define DEBUGGER_SPEED 921600
#endif
void setup()
{
#if kESP8266Version >= 24
gUART = uart_init(UART0, DEBUGGER_SPEED, SERIAL_8N1, SERIAL_FULL, 1, 128);
#else
gUART = uart_init(UART0, DEBUGGER_SPEED, SERIAL_8N1, SERIAL_FULL, 1); // ESP8266 boots to 74880
#endif
system_set_os_print(0);
modPrelaunch();
wifi_set_opmode_current(NULL_MODE);
#ifdef mxDebug
gThe = modCloneMachine(NULL, NULL);
if (!gThe) {
modLog("can't clone: no memory?");
while (true)
;
}
modRunMachineSetup(gThe);
#else
modRunMachineSetup(modCloneMachine(NULL, NULL));
#endif
}
void loop(void)
{
#ifdef mxDebug
fxReceiveLoop();
#endif
modTimersExecute();
if (0 == modMessageService()) {
int delayMS = modTimersNext();
if (delayMS)
modDelayMilliseconds(delayMS);
}
#ifdef mxInstrument
modInstrumentationAdjust(Turns, +1);
#endif
}
/*
Required functions provided by application
to enable serial port for diagnostic information and debugging
*/
void modLog_transmit(const char *msg)
{
uint8_t c;
#ifdef mxDebug
if (gThe) {
while (c = c_read8(msg++))
fx_putc(gThe, c);
fx_putc(gThe, 0);
}
else
#endif
{
while (c = c_read8(msg++))
ESP_putc(c);
ESP_putc(13);
ESP_putc(10);
}
}
void ESP_putc(int c)
{
system_soft_wdt_feed();
uart_write_char(gUART, c);
}
void ESP_put(uint8_t *c, int count)
{
system_soft_wdt_feed();
while (count--)
uart_write_char(gUART, *c++);
}
int ESP_getc(void)
{
system_soft_wdt_feed();
return uart_read_char(gUART);
}
uint8_t ESP_isReadable()
{
return uart_rx_available(gUART);
}
uint8_t ESP_setBaud(int baud)
{
return uart_set_baud(gUART, baud);
}