Merge pull request #437 from ourairquality/oaq-merge-1

* bmp180: comment typo
* ds3231: minor code style fixes. Comment, on the week day start.
* Reverse engineered ets_timers.o Switch from FreeRTOS queue to task notification. Removed unknown/unused code. Rename sdk_ets_handler_isr to process_pending_timers. Add function for microseconds Simplify time to ticks conversion
* ets_timer: code for using the FreeRTOS timers, and remove from libs.
* libc: update to a recent newlib version.
* LwIP v2 support
* spi_write: use uint32_t for the page iteration counter. The page counter was using an uint8_t which seems unnecessary and might wrap.
* sysparam_get_bool: memcpy the binary values out.
* FreeRTOS 9.0.1
* Add an argument to ISRs. Disable interrupts while masking them.
* sysparam: reserve one more flash sector before placing the sysparams. This is to help work with recent SDKs that add a RF cal sector by default in the fifth last sector - just so the sysparam sectors do not jump around when using different SDK versions.
* upnp example: strip down the lwipopts.h file
* sysparam editor: accept newline to end a line of input.
* Add Wificfg. Uses the sysparam store to save the wifi configuration. Adds a basic http server for configuration.
* lwip: disable the tcpip_core_locking_input option. With this option enabled some lwip input processing occurs in the pp task which works well for some uses but some code uses a lot of stack (e.g. mdns) and will overflow the pp task stask, or might unnecessarily slow the critical pp task,
so disable this by default and if not already defined.
* sdk_cnx_add_rc: fix overflow of the table, when no match is found. Also adds source code for sdk_cnx_rc_search, adding a null pointer dereference. Check (that is not expected to be seen), and source code for sdk_cnx_remove_rc.
* http_get example: fix compilation with ipv6 disabled.
* lwip: update to master branch.
* wificfg: allow the AP channel to be 1.
* lwip: rework the tcp ooseq handling. It now accounts for the number of rx pool buffers used and the
available memory when deciding the number of ooseq buffers to retain. Enable the TCP Selective ACK support which appears to help a lot on lossy wifi when using the OOSEQ option.
* Update lwip, fixes losses of pcbs and associated problems.
* lwip: revise the tcp ooseq limit calulations. Was making a mess of the calculation sign. Also added a COPY_PP_RX_PBUFS define to include appropriate limits for this option.
* lwip: ooseq_max_bytes() - set a practical target memory size.
* lwip: revise ooseq handling. Modified for lwip backwards compatibility based on upstream feedback.
* lwip: update to the 2.0.3 release
* lwip: merge upstream master.
* libc: update to upstream master.
* lwip: fix building without TCP_QUEUE_OOSEQ
This commit is contained in:
Ruslan V. Uss 2017-10-02 04:50:35 +05:00 committed by GitHub
commit 546cc47121
183 changed files with 10793 additions and 11817 deletions

View file

@ -214,8 +214,8 @@ void IRAM sdk_user_start(void) {
memcpy(&sdk_g_ic.s, buf32, sizeof(struct sdk_g_ic_saved_st));
// By default, put the sysparam region just below the config sectors at the
// top of the flash space
sysparam_addr = flash_size - (4 + DEFAULT_SYSPARAM_SECTORS) * sdk_flashchip.sector_size;
// top of the flash space, and allowing one extra sector spare.
sysparam_addr = flash_size - (5 + DEFAULT_SYSPARAM_SECTORS) * sdk_flashchip.sector_size;
status = sysparam_init(sysparam_addr, flash_size);
if (status == SYSPARAM_NOTFOUND) {
status = sysparam_create_area(sysparam_addr, DEFAULT_SYSPARAM_SECTORS, false);
@ -311,8 +311,8 @@ static void init_g_ic(void) {
if (sdk_g_ic.s._unknown310 > 4) {
sdk_g_ic.s._unknown310 = 4;
}
if (sdk_g_ic.s._unknown1e4._unknown1e4 == 0xffffffff) {
bzero(&sdk_g_ic.s._unknown1e4, sizeof(sdk_g_ic.s._unknown1e4));
if (sdk_g_ic.s.sta_ssid.ssid_length == 0xffffffff) {
bzero(&sdk_g_ic.s.sta_ssid, sizeof(sdk_g_ic.s.sta_ssid));
bzero(&sdk_g_ic.s.sta_password, sizeof(sdk_g_ic.s.sta_password));
}
sdk_g_ic.s.wifi_led_enable = 0;

View file

@ -58,17 +58,17 @@ void gpio_set_pullup(uint8_t gpio_num, bool enabled, bool enabled_during_sleep)
static gpio_interrupt_handler_t gpio_interrupt_handlers[16] = { 0 };
void __attribute__((weak)) IRAM gpio_interrupt_handler(void)
void __attribute__((weak)) IRAM gpio_interrupt_handler(void *arg)
{
uint32_t status_reg = GPIO.STATUS;
GPIO.STATUS_CLEAR = status_reg;
uint8_t gpio_idx;
while((gpio_idx = __builtin_ffs(status_reg)))
while ((gpio_idx = __builtin_ffs(status_reg)))
{
gpio_idx--;
status_reg &= ~BIT(gpio_idx);
if(FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_idx])) {
if (FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[gpio_idx])) {
gpio_interrupt_handler_t handler = gpio_interrupt_handlers[gpio_idx];
if (handler) {
handler(gpio_idx);
@ -82,8 +82,8 @@ void gpio_set_interrupt(const uint8_t gpio_num, const gpio_inttype_t int_type, g
gpio_interrupt_handlers[gpio_num] = handler;
GPIO.CONF[gpio_num] = SET_FIELD(GPIO.CONF[gpio_num], GPIO_CONF_INTTYPE, int_type);
if(int_type != GPIO_INTTYPE_NONE) {
_xt_isr_attach(INUM_GPIO, gpio_interrupt_handler);
if (int_type != GPIO_INTTYPE_NONE) {
_xt_isr_attach(INUM_GPIO, gpio_interrupt_handler, NULL);
_xt_isr_unmask(1<<INUM_GPIO);
}
}

View file

@ -7,13 +7,19 @@
*/
#include <esp/interrupts.h>
_xt_isr isr[16];
typedef struct _xt_isr_entry_ {
_xt_isr handler;
void *arg;
} _xt_isr_entry;
_xt_isr_entry isr[16];
bool esp_in_isr;
void IRAM _xt_isr_attach(uint8_t i, _xt_isr func)
void IRAM _xt_isr_attach(uint8_t i, _xt_isr func, void *arg)
{
isr[i] = func;
isr[i].handler = func;
isr[i].arg = arg;
}
/* Generic ISR handler.
@ -25,17 +31,20 @@ uint16_t IRAM _xt_isr_handler(uint16_t intset)
esp_in_isr = true;
/* WDT has highest priority (occasional WDT resets otherwise) */
if(intset & BIT(INUM_WDT)) {
if (intset & BIT(INUM_WDT)) {
_xt_clear_ints(BIT(INUM_WDT));
isr[INUM_WDT]();
isr[INUM_WDT].handler(NULL);
intset -= BIT(INUM_WDT);
}
while(intset) {
while (intset) {
uint8_t index = __builtin_ffs(intset) - 1;
uint16_t mask = BIT(index);
_xt_clear_ints(mask);
isr[index]();
_xt_isr handler = isr[index].handler;
if (handler) {
handler(isr[index].arg);
}
intset -= mask;
}

View file

@ -150,7 +150,7 @@ typedef void (* gpio_interrupt_handler_t)(uint8_t gpio_num);
*
* Example:
*
* void IRAM gpio_interrupt_handler(void) {
* void IRAM gpio_interrupt_handler(void *arg) {
* // check GPIO.STATUS
* // write GPIO.STATUS_CLEAR
* // Do something when GPIO changes

View file

@ -35,19 +35,37 @@ typedef enum {
INUM_TIMER_FRC2 = 10,
} xt_isr_num_t;
void sdk__xt_int_exit (void);
void _xt_user_exit (void);
void sdk__xt_tick_timer_init (void);
void sdk__xt_timer_int(void);
void sdk__xt_int_exit(void);
void _xt_user_exit(void);
void sdk__xt_tick_timer_init(void);
void sdk__xt_timer_int(void *);
void sdk__xt_timer_int1(void);
/* The normal running level is 0.
* The system tick isr, timer frc2_isr, sv_isr etc run at level 1.
* Debug exceptions run at level 2?
* The wdev nmi runs at level 3.
*/
static inline uint32_t _xt_get_intlevel(void)
{
uint32_t level;
__asm__ volatile("rsr %0, intlevel" : "=a"(level));
return level;
__asm__ volatile("rsr %0, ps" : "=a"(level));
return level & 0xf;
}
/*
* There are conflicting definitions for XCHAL_EXCM_LEVEL. Newlib
* defines it to be 1 and xtensa_rtos.h defines it to be 3. Don't want
* 3 as that is for the NMI and might want to check that the OS apis
* are not entered in level 3. Setting the interrupt level to 3 does
* not disable the NMI anyway. So set the level to 2.
*/
#ifdef XCHAL_EXCM_LEVEL
#undef XCHAL_EXCM_LEVEL
#define XCHAL_EXCM_LEVEL 2
#endif
/* Disable interrupts and return the old ps value, to pass into
_xt_restore_interrupts later.
@ -68,25 +86,27 @@ static inline void _xt_restore_interrupts(uint32_t new_ps)
__asm__ volatile ("wsr %0, ps; rsync" :: "a" (new_ps));
}
/* ESPTODO: the mask/unmask functions aren't thread safe */
static inline void _xt_isr_unmask(uint32_t unmask)
static inline uint32_t _xt_isr_unmask(uint32_t unmask)
{
uint32_t old_level = _xt_disable_interrupts();
uint32_t intenable;
asm volatile ("rsr %0, intenable" : "=a" (intenable));
intenable |= unmask;
asm volatile ("wsr %0, intenable; esync" :: "a" (intenable));
asm volatile ("wsr %0, intenable;" :: "a" (intenable | unmask));
_xt_restore_interrupts(old_level);
return intenable;
}
static inline void _xt_isr_mask (uint32_t mask)
static inline uint32_t _xt_isr_mask(uint32_t mask)
{
uint32_t old_level = _xt_disable_interrupts();
uint32_t intenable;
asm volatile ("rsr %0, intenable" : "=a" (intenable));
intenable &= ~mask;
asm volatile ("wsr %0, intenable; esync" :: "a" (intenable));
asm volatile ("wsr %0, intenable;" :: "a" (intenable & ~mask));
_xt_restore_interrupts(old_level);
return intenable;
}
static inline uint32_t _xt_read_ints (void)
static inline uint32_t _xt_read_ints(void)
{
uint32_t interrupt;
asm volatile ("rsr %0, interrupt" : "=a" (interrupt));
@ -98,9 +118,7 @@ static inline void _xt_clear_ints(uint32_t mask)
asm volatile ("wsr %0, intclear; esync" :: "a" (mask));
}
typedef void (* _xt_isr)(void);
/* This function is implemeneted in FreeRTOS port.c at the moment,
should be moved or converted to an inline */
void _xt_isr_attach (uint8_t i, _xt_isr func);
typedef void (* _xt_isr)(void *arg);
void _xt_isr_attach (uint8_t i, _xt_isr func, void *arg);
#endif

View file

@ -14,25 +14,25 @@
// 'info' is declared in app_main.o at .bss+0x4
struct sdk_info_st {
ip_addr_t softap_ipaddr; // 0x00
ip_addr_t softap_netmask; // 0x04
ip_addr_t softap_gw; // 0x08
ip_addr_t sta_ipaddr; // 0x0c
ip_addr_t sta_netmask; // 0x10
ip_addr_t sta_gw; // 0x14
ip4_addr_t softap_ipaddr; // 0x00
ip4_addr_t softap_netmask; // 0x04
ip4_addr_t softap_gw; // 0x08
ip4_addr_t sta_ipaddr; // 0x0c
ip4_addr_t sta_netmask; // 0x10
ip4_addr_t sta_gw; // 0x14
uint8_t softap_mac_addr[6]; // 0x18
uint8_t sta_mac_addr[6]; // 0x1e
};
struct _unknown_info1 {
struct wl_channel {
uint8_t _unknown00;
uint8_t _unknown01;
uint8_t _unknown02;
uint8_t _unknown03;
uint8_t _unknown04;
uint8_t _unknown05;
uint8_t channel; // eagle_auth_done
uint8_t num; // eagle_auth_done
};
@ -83,7 +83,7 @@ struct _unknown_wpa1 {
};
struct sdk_netif_conninfo {
struct sdk_cnx_node {
uint8_t mac_addr[6];
uint8_t _unknown07[2];
@ -98,17 +98,19 @@ struct sdk_netif_conninfo {
uint32_t _unknown1c[23];
struct _unknown_info1 *_unknown78; // eagle_auth_done
struct wl_channel *channel; // 0x78 eagle_auth_done
uint32_t _unknown7c[8];
uint16_t _unknown9c; // ieee80211_hostap. increases by one one each timer func called.
uint16_t _unknown9e;
uint32_t _unknowna0[18];
uint32_t _unknowna0[17];
int8_t _unknowne8; //
int8_t _unknowne9; // ppInstallKey
void *_unknowne4;
uint8_t _unknowne8; //
uint8_t _unknowne9; // ppInstallKey
int8_t _unknownea;
int8_t _unknowneb;
@ -128,9 +130,9 @@ struct sdk_g_ic_netif_info {
uint32_t _unknown48; // 0x48
uint8_t _unknown4c; // 0x4c
uint8_t _unknown4d[59]; // 0x4d - 0x88
struct sdk_netif_conninfo *_unknown88; // 0x88
struct sdk_cnx_node *_unknown88; // 0x88
uint32_t _unknown8c; // 0x8c
struct sdk_netif_conninfo *conninfo[6]; // 0x90 - 0xa8
struct sdk_cnx_node *cnx_nodes[6]; // 0x90 - 0xa8
uint8_t _unknowna8[12]; // 0xa8 - 0xb4
struct _unknown_softap1 *_unknownb4;
uint8_t statusb8; // 0xb8 (arg of sta_status_set)
@ -206,10 +208,9 @@ struct sdk_g_ic_volatile_st {
};
struct sdk_g_ic_unk0_st {
uint16_t _unknown1e4; // sdk_wpa_config_profile
uint16_t _unknown1e6; // sdk_wpa_config_profile
uint8_t sta_ssid[32]; // 0x1e8 Station ssid. Null terminated string.
struct sdk_g_ic_ssid_with_length {
uint32_t ssid_length; // 0x1e4 sdk_wpa_config_profile
uint8_t ssid[32]; // 0x1e8 Station ssid. Null terminated string.
};
// This is the portion of g_ic which is loaded/saved to the flash ROM, and thus
@ -224,7 +225,8 @@ struct sdk_g_ic_saved_st {
uint8_t wifi_led_gpio;
uint8_t wifi_led_state; // 0 or 1.
struct sdk_g_ic_unk0_st _unknown1e4;
// Current station ap config ssid and length.
struct sdk_g_ic_ssid_with_length sta_ssid; // 0x1e4
uint8_t _unknown208;
uint8_t _unknown209; // sdk_wpa_config_profile
@ -260,7 +262,7 @@ struct sdk_g_ic_saved_st {
uint8_t _unknown30d; // result of ieee80211_chan2ieee
uint8_t _unknown30e;
uint8_t _unknown30f;
uint8_t _unknown310; // count of entries in the softap conninfo array, less two.
uint8_t _unknown310; // count of entries in the softap cnx_node array, less two.
uint8_t _unknown311[3];
@ -320,7 +322,7 @@ struct esf_buf {
_Static_assert(sizeof(struct sdk_info_st) == 0x24, "info_st is the wrong size!");
_Static_assert(offsetof(struct sdk_info_st, sta_mac_addr) == 0x1e, "bad struct");
_Static_assert(offsetof(struct _unknown_info1, channel) == 0x06, "bad struct");
_Static_assert(offsetof(struct wl_channel, num) == 0x06, "bad struct");
_Static_assert(sizeof(struct _unknown_softap2) == 0xcc, "_unknown_softap2 is the wrong size!");
_Static_assert(offsetof(struct _unknown_softap2, _unknownb8) == 0xb8, "bad struct");
@ -331,8 +333,8 @@ _Static_assert(offsetof(struct _unknown_softap1, _unknown18) == 0x18, "bad struc
_Static_assert(sizeof(struct _unknown_wpa1) == 0x4c, "_unknown_wpa1 is the wrong size!");
_Static_assert(offsetof(struct _unknown_wpa1, _unknown48) == 0x48, "bad struct");
_Static_assert(offsetof(struct sdk_netif_conninfo, _unknown78) == 0x78, "bad struct");
_Static_assert(offsetof(struct sdk_netif_conninfo, _unknown108) == 0x108, "bad struct");
_Static_assert(offsetof(struct sdk_cnx_node, channel) == 0x78, "bad struct");
_Static_assert(offsetof(struct sdk_cnx_node, _unknown108) == 0x108, "bad struct");
_Static_assert(offsetof(struct sdk_g_ic_netif_info, started) == 0xbb, "bad struct");
@ -340,7 +342,7 @@ _Static_assert(sizeof(struct sdk_g_ic_volatile_st) == 0x1d8, "sdk_g_ic_volatile_
_Static_assert(offsetof(struct sdk_g_ic_volatile_st, _unknown1d5) == 0x1d5, "bad struct");
_Static_assert(sizeof(struct sdk_g_ic_saved_st) == 0x370, "sdk_g_ic_saved_st is the wrong size!");
_Static_assert(offsetof(struct sdk_g_ic_saved_st, _unknown1e4) == 0x1e4 - 0x1d8, "bad struct");
_Static_assert(offsetof(struct sdk_g_ic_saved_st, sta_ssid) == 0x1e4 - 0x1d8, "bad struct");
_Static_assert(offsetof(struct sdk_g_ic_saved_st, _unknown546) == 0x546 - 0x1d8, "bad struct");
_Static_assert(sizeof(struct sdk_g_ic_st) == 0x548, "sdk_g_ic_st is the wrong size!");
@ -357,21 +359,16 @@ _Static_assert(offsetof(struct esf_buf, length) == 0x16, "bad struct");
// ieee80211_output_pbuf and perhaps elsewhere. The value is just passed through
// lwip and and not used by lwip so just ensure this slot is at the expected
// offset.
_Static_assert(offsetof(struct netif, state) == 28, "netif->state offset wrong!");
_Static_assert(offsetof(struct netif, state) == 4, "netif->state offset wrong!");
// Some sdk uses of netif->hwaddr have been converted to source code, but many
// remain, but the content of this slot should not change in future versions of
// lwip, so just ensure it is at the expected offset.
_Static_assert(offsetof(struct netif, hwaddr) == 41, "netif->hwaddr offset wrong!");
// lwip, so just ensure it is at the expected offset. Note the sdk binary
// libraries have been patched to move this offset from 41 to 42 to keep it
// 16-bit aligned to keep lwip v2 happy.
_Static_assert(offsetof(struct netif, hwaddr) == 8, "netif->hwaddr offset wrong!");
// Most sdk uses of the netif->flags have been converted to source code. One
// known sdk binary read of the flags remains in wl_cnx.o:sdk_cnx_sta_leave
// which checks the NETIF_FLAG_DHCP flag. The NETIF_FLAG_DHCP has been removed
// in lwip v2, so some lwip hacks are needed to handle this for now until
// wl_cnx.o is converted so source code too.
_Static_assert(offsetof(struct netif, flags) == 47, "netif->flags offset wrong!");
_Static_assert(offsetof(struct pbuf, eb) == 16, "pbuf->eb offset wrong!");
_Static_assert(offsetof(struct pbuf, esf_buf) == 16, "pbuf->esf_buf offset wrong!");
/// Misc.

View file

@ -13,6 +13,7 @@
#include <esp/uart.h>
#include <stdlib.h>
#include <stdout_redirect.h>
#include <sys/time.h>
extern void *xPortSupervisorStackPointer;
@ -135,6 +136,14 @@ int _stat_r(struct _reent *r, const char *pathname, void *buf);
__attribute__((weak, alias("syscall_returns_enosys")))
off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence);
__attribute__((weak, alias("_gettimeofday_r")))
int _gettimeofday_r _PARAMS ((struct _reent *r, struct timeval *now, void *p)) {
now->tv_sec = 0;
now->tv_usec = 0;
errno = ENOSYS;
return -1;
}
/* Generic stub for any newlib syscall that fails with errno ENOSYS
("Function not implemented") and a return value equivalent to
(int)-1. */

View file

@ -133,7 +133,7 @@ static bool IRAM spi_write(uint32_t addr, uint8_t *dst, uint32_t size)
uint32_t offset = write_bytes_to_page;
uint32_t pages_to_write = (size - offset) / sdk_flashchip.page_size;
for (uint8_t i = 0; i != pages_to_write; i++) {
for (uint32_t i = 0; i < pages_to_write; i++) {
if (!spi_write_page(&sdk_flashchip, addr + offset,
dst + offset, sdk_flashchip.page_size)) {
return false;

View file

@ -801,9 +801,13 @@ sysparam_status_t sysparam_get_bool(const char *key, bool *result) {
do {
if (binary) {
if (data_len == 1) { // int8 value
*result = (int8_t)(*buf) ? true : false;
uint8_t value;
memcpy(&value, buf, sizeof(value));
*result = value ? true : false;
} else if (data_len == 4) { // int32 value
*result = (int32_t)(*buf) ? true : false;
uint32_t value;
memcpy(&value, buf, sizeof(value));
*result = value ? true : false;
} else {
status = SYSPARAM_PARSEFAILED;
}