Commit f3e2a3af authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Initial pass at switching to RTOS SDK.

This compiles, links, and starts the RTOS without crashing and burning.

Lua environment does not yet start due to the different task architecture.

Known pain points:

  - task implementation needs to be rewritten for RTOS (next up on my TODO)

  - secure espconn does not exist, all secure espconn stuff has been #if 0'd

  - lwip now built from within the RTOS SDK, but does not appear to include
    MDNS support. Investigation needed.

  - there is no access to FRC1 NMI, not sure if we ever actually used that
    however. Also #if 0'd out for now.

  - new timing constraints introduced by the RTOS, all use of ets_delay_us()
    and os_delay_us() needs to be reviewed (the tsl2561 driver in particular).

  - even more confusion with ets_ vs os_ vs c_ vs non-prefixed versions.
    In the long run everything should be switched to non-prefixed versions.

  - system_set_os_print() not available, needs to be reimplemented

  - all the RTOS rodata is loaded into RAM, as it apparently uses some
    constants while the flash isn't mapped, so our exception handler can't
    work its magic. This should be narrowed down to the minimum possible
    at some point.

  - with each task having its own stack in RTOS, we probably need change
    flash-page buffers from the stack to the heap in a bunch of places.
    A single, shared, page buffer *might* be possible if we limit ourselves
    to running NodeMCU in a single task.

  - there's a ton of junk in the sdk-overrides now; over time the core code
    should be updated to not need those shims
parent afd974c5
......@@ -21,6 +21,7 @@
#include "lauxlib.h"
#include "platform.h"
#include "lwip/udp.h"
#include "esp_misc.h"
#include <errno.h>
static const uint32_t am2320_i2c_id = 0;
......
......@@ -12,6 +12,7 @@
#include "lauxlib.h"
#include "platform.h"
#include "c_math.h"
#include "user_interface.h"
/****************************************************/
/**\name registers definition */
......
......@@ -3,6 +3,7 @@
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "esp_misc.h"
static const uint32_t bmp085_i2c_id = 0;
static const uint8_t bmp085_i2c_addr = 0x77;
......
......@@ -12,6 +12,7 @@
#include "lwip/ip_addr.h"
#include "espconn.h"
#include "driver/uart.h"
#include "esp_misc.h"
#include "coap.h"
#include "uri.h"
......
......@@ -35,18 +35,18 @@
#include "module.h"
#include "lauxlib.h"
#include "lwip/tcp.h"
#include "lwip/pbuf.h"
#include "lmem.h"
#include "platform.h"
#include "c_stdlib.h"
#include "c_stdio.h"
#include "c_string.h"
#include "ctype.h"
#include "user_interface.h"
#include "espconn.h"
#include "lwip/tcp.h"
#include "lwip/pbuf.h"
#include "flash_fs.h"
#include "task/task.h"
#include "esp_wifi.h"
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define LITLEN(strliteral) (sizeof (strliteral) -1)
......
......@@ -9,6 +9,8 @@
#include "c_string.h"
#include "gpio.h"
#undef INTERRUPT
#define PULLUP PLATFORM_GPIO_PULLUP
#define FLOAT PLATFORM_GPIO_FLOAT
#define OUTPUT PLATFORM_GPIO_OUTPUT
......
......@@ -7,6 +7,8 @@
#include "c_stdlib.h"
#include "c_string.h"
#include "user_interface.h"
#include "esp_system.h"
static uint8_t data_pin;
static uint8_t clk_pin;
......
......@@ -15,6 +15,8 @@
#include "mqtt_msg.h"
#include "msg_queue.h"
#include "esp_misc.h"
#include "esp_system.h"
#include "user_interface.h"
#define MQTT_BUF_SIZE 1024
......
......@@ -13,6 +13,7 @@
#include "lwip/ip_addr.h"
#include "espconn.h"
#include "lwip/dns.h"
#include "esp_misc.h"
#define TCP ESPCONN_TCP
#define UDP ESPCONN_UDP
......@@ -1573,8 +1574,9 @@ static int net_cert_auth(lua_State *L)
enable = lua_toboolean(L, 1);
}
bool rc;
bool rc = false;
#if 0
if (enable) {
// See if there is a cert there
if (net_client_cert_area[0] == 0x00 || net_client_cert_area[0] == 0xff) {
......@@ -1584,6 +1586,7 @@ static int net_cert_auth(lua_State *L)
} else {
rc = espconn_secure_cert_req_disable(1);
}
#endif
lua_pushboolean(L, rc);
return 1;
......@@ -1614,8 +1617,9 @@ static int net_cert_verify(lua_State *L)
enable = lua_toboolean(L, 1);
}
bool rc;
bool rc = false;
#if 0
if (enable) {
// See if there is a cert there
if (net_server_cert_area[0] == 0x00 || net_server_cert_area[0] == 0xff) {
......@@ -1625,6 +1629,7 @@ static int net_cert_verify(lua_State *L)
} else {
rc = espconn_secure_ca_disable(1);
}
#endif
lua_pushboolean(L, rc);
return 1;
......
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "rom.h"
#include "esp_misc.h"
//#include "driver/easygpio.h"
//static Ping_Data pingA;
#define defPulseLen 185
......
......@@ -143,7 +143,7 @@ static int lrotary_setup( lua_State* L )
callback_free(L, id, ROTARY_ALL);
if (!data[id]) {
data[id] = (DATA *) c_zalloc(sizeof(DATA));
data[id] = (DATA *) os_zalloc(sizeof(DATA));
if (!data[id]) {
return -1;
}
......@@ -202,7 +202,7 @@ static int lrotary_close( lua_State* L )
DATA *d = data[id];
if (d) {
data[id] = NULL;
c_free(d);
os_free(d);
}
if (rotary_close( id )) {
......
......@@ -75,7 +75,7 @@ typedef struct{
uint32_t interval;
uint8_t mode;
}timer_struct_t;
typedef timer_struct_t* timer_t;
typedef timer_struct_t* ptimer_t;
// The previous implementation extended the rtc counter to 64 bits, and then
// applied rtc2sec with the current calibration value to that 64 bit value.
......@@ -95,7 +95,7 @@ static timer_struct_t alarm_timers[NUM_TMR];
static os_timer_t rtc_timer;
static void alarm_timer_common(void* arg){
timer_t tmr = &alarm_timers[(uint32_t)arg];
ptimer_t tmr = &alarm_timers[(uint32_t)arg];
lua_State* L = lua_getstate();
if(tmr->lua_ref == LUA_NOREF)
return;
......@@ -116,9 +116,9 @@ static int tmr_delay( lua_State* L ){
sint32_t us = luaL_checkinteger(L, 1);
if(us <= 0)
return luaL_error(L, "wrong arg range");
while(us >= 1000000){
us -= 1000000;
os_delay_us(1000000);
while(us >= 65000){
us -= 65000;
os_delay_us(65000);
system_soft_wdt_feed ();
}
if(us>0){
......@@ -148,7 +148,7 @@ static int tmr_register(lua_State* L){
//get the lua function reference
lua_pushvalue(L, 4);
sint32_t ref = luaL_ref(L, LUA_REGISTRYINDEX);
timer_t tmr = &alarm_timers[id];
ptimer_t tmr = &alarm_timers[id];
if(!(tmr->mode & TIMER_IDLE_FLAG) && tmr->mode != TIMER_MODE_OFF)
ets_timer_disarm(&tmr->os);
//there was a bug in this part, the second part of the following condition was missing
......@@ -165,7 +165,7 @@ static int tmr_register(lua_State* L){
static int tmr_start(lua_State* L){
uint8_t id = luaL_checkinteger(L, 1);
MOD_CHECK_ID(tmr,id);
timer_t tmr = &alarm_timers[id];
ptimer_t tmr = &alarm_timers[id];
//we return false if the timer is not idle
if(!(tmr->mode&TIMER_IDLE_FLAG)){
lua_pushboolean(L, 0);
......@@ -187,7 +187,7 @@ static int tmr_alarm(lua_State* L){
static int tmr_stop(lua_State* L){
uint8_t id = luaL_checkinteger(L, 1);
MOD_CHECK_ID(tmr,id);
timer_t tmr = &alarm_timers[id];
ptimer_t tmr = &alarm_timers[id];
//we return false if the timer is idle (of not registered)
if(!(tmr->mode & TIMER_IDLE_FLAG) && tmr->mode != TIMER_MODE_OFF){
tmr->mode |= TIMER_IDLE_FLAG;
......@@ -203,7 +203,7 @@ static int tmr_stop(lua_State* L){
static int tmr_unregister(lua_State* L){
uint8_t id = luaL_checkinteger(L, 1);
MOD_CHECK_ID(tmr,id);
timer_t tmr = &alarm_timers[id];
ptimer_t tmr = &alarm_timers[id];
if(!(tmr->mode & TIMER_IDLE_FLAG) && tmr->mode != TIMER_MODE_OFF)
ets_timer_disarm(&tmr->os);
if(tmr->lua_ref != LUA_NOREF)
......@@ -217,7 +217,7 @@ static int tmr_unregister(lua_State* L){
static int tmr_interval(lua_State* L){
uint8_t id = luaL_checkinteger(L, 1);
MOD_CHECK_ID(tmr,id);
timer_t tmr = &alarm_timers[id];
ptimer_t tmr = &alarm_timers[id];
uint32_t interval = luaL_checkinteger(L, 2);
luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR);
if(tmr->mode != TIMER_MODE_OFF){
......@@ -234,7 +234,7 @@ static int tmr_interval(lua_State* L){
static int tmr_state(lua_State* L){
uint8_t id = luaL_checkinteger(L, 1);
MOD_CHECK_ID(tmr,id);
timer_t tmr = &alarm_timers[id];
ptimer_t tmr = &alarm_timers[id];
if(tmr->mode == TIMER_MODE_OFF){
lua_pushnil(L);
return 1;
......
......@@ -3,6 +3,7 @@
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "esp_misc.h"
#include "c_stdlib.h"
......
......@@ -3,6 +3,7 @@
#include "module.h"
#include "lauxlib.h"
#include "platform.h"
#include "esp_misc.h"
#include "c_stdlib.h"
......
......@@ -15,6 +15,8 @@
#include "wifi_common.h"
#define event event_id
#if defined(LUA_USE_MODULES_WIFI)
#ifdef WIFI_STATION_STATUS_MONITOR_ENABLE
......
......@@ -3,6 +3,7 @@
#include "platform.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "esp_misc.h"
/**
* Code is based on https://github.com/CHERTS/esp8266-devkit/blob/master/Espressif/examples/EspLightNode/user/ws2801.c
......
......@@ -40,7 +40,7 @@
* Includes
*----------------------------------------------------------------------------*/
#include "lwip/opt.h"
#if LWIP_MDNS /* don't build if not configured for use in lwipopts.h */
#ifdef LWIP_MDNS /* don't build if not configured for use in lwipopts.h */
#include "lwip/mdns.h"
#include "lwip/udp.h"
#include "lwip/mem.h"
......
#ifndef __CPU_ESP8266_H__
#define __CPU_ESP8266_H__
#include "c_types.h"
#include "os_type.h"
#include "spi_flash.h"
#include "pin_map.h"
#include "user_config.h"
#include "flash_api.h"
#include "eagle_soc.h"
#include "esp8266/gpio_register.h"
#include "esp8266/pin_mux_register.h"
// Number of resources (0 if not available/not implemented)
#define NUM_GPIO GPIO_PIN_NUM
#define NUM_SPI 2
......
......@@ -145,11 +145,13 @@ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type
DIVIDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT);
}
#if 0
if (source_type == NMI_SOURCE) {
ETS_FRC_TIMER1_NMI_INTR_ATTACH(hw_timer_nmi_cb);
} else {
#endif
ETS_FRC_TIMER1_INTR_ATTACH(hw_timer_isr_cb, NULL);
}
// }
TM1_EDGE_INT_ENABLE();
ETS_FRC1_INTR_ENABLE();
......
#ifndef _HW_TIMER_H
#define _HW_TIMER_H
#include "eagle_soc.h"
#if APB_CLK_FREQ == 80 * 1000000
// 80 MHz divided by 16 is 5 MHz count rate.
#define US_TO_RTC_TIMER_TICKS(t) ((t) * 5)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment