mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu/esp_common: vendor files changed for RTOS SDK
This commit is contained in:
parent
a6d01fc2de
commit
dca6d59b60
@ -24,16 +24,12 @@
|
||||
#include "cpu_conf.h"
|
||||
#include "net/netdev.h"
|
||||
#include "net/gnrc.h"
|
||||
#include "esp_common_log.h"
|
||||
#include "esp_now_params.h"
|
||||
#include "esp_now_netdev.h"
|
||||
#include "esp_now_gnrc.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
|
||||
#ifdef MCU_ESP8266
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
#endif
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
|
@ -27,25 +27,17 @@
|
||||
#include "net/gnrc.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
#include "esp_common.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_now.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "nvs_flash/include/nvs_flash.h"
|
||||
#else
|
||||
#include "common.h"
|
||||
#include "espressif/c_types.h"
|
||||
#include "espnow.h"
|
||||
#include "esp/common_macros.h"
|
||||
#include "sdk/sdk.h"
|
||||
#endif /* MCU_ESP32 */
|
||||
|
||||
#include "irq_arch.h"
|
||||
#include "od.h"
|
||||
|
||||
#include "nvs_flash/include/nvs_flash.h"
|
||||
|
||||
#include "esp_now_params.h"
|
||||
#include "esp_now_netdev.h"
|
||||
|
||||
@ -61,50 +53,25 @@
|
||||
#define ESP_NOW_AP_PREFIX "RIOT_ESP_"
|
||||
#define ESP_NOW_AP_PREFIX_LEN (strlen(ESP_NOW_AP_PREFIX))
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
|
||||
#define esp_now_set_self_role(r)
|
||||
|
||||
#else
|
||||
|
||||
#define ESP_NOW_ROLE_IDLE (0)
|
||||
#define ESP_NOW_ROLE_CONTROLLER (1)
|
||||
#define ESP_NOW_ROLE_SLAVE (2)
|
||||
#define ESP_NOW_ROLE_COMBO (3)
|
||||
#define ESP_NOW_KEY_LEN (16)
|
||||
|
||||
#define ESP_OK (0)
|
||||
|
||||
#ifndef IRAM_ATTR
|
||||
#define IRAM_ATTR IRAM
|
||||
#endif
|
||||
|
||||
#endif /* MCU_ESP8266 */
|
||||
|
||||
#if MODULE_ESP_WIFI && !ESP_NOW_UNICAST
|
||||
#error If module esp_wifi is used, module esp_now has to be used in unicast mode
|
||||
#endif
|
||||
|
||||
/**
|
||||
* There is only one ESP-NOW device. We define it as static device variable
|
||||
* to have accesss to the device inside ESP-NOW interrupt routines which do
|
||||
* to have access to the device inside ESP-NOW interrupt routines which do
|
||||
* not provide an argument that could be used as pointer to the ESP-NOW
|
||||
* device which triggers the interrupt.
|
||||
*/
|
||||
static esp_now_netdev_t _esp_now_dev;
|
||||
static esp_now_netdev_t _esp_now_dev = { 0 };
|
||||
static const netdev_driver_t _esp_now_driver;
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
static bool _esp_now_add_peer(const uint8_t* bssid, uint8_t channel, uint8_t* key)
|
||||
#else
|
||||
static bool _esp_now_add_peer(uint8_t* bssid, uint8_t channel, uint8_t* key)
|
||||
#endif
|
||||
{
|
||||
if (esp_now_is_peer_exist(bssid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
esp_now_peer_info_t peer = {};
|
||||
|
||||
memcpy(peer.peer_addr, bssid, ESP_NOW_ETH_ALEN);
|
||||
@ -117,11 +84,6 @@ static bool _esp_now_add_peer(uint8_t* bssid, uint8_t channel, uint8_t* key)
|
||||
}
|
||||
|
||||
esp_err_t ret = esp_now_add_peer(&peer);
|
||||
#else
|
||||
int ret = esp_now_add_peer(bssid, ESP_NOW_ROLE_COMBO, channel,
|
||||
esp_now_params.key,
|
||||
esp_now_params.key ? ESP_NOW_KEY_LEN : 0);
|
||||
#endif
|
||||
DEBUG("esp_now_add_peer node %02x:%02x:%02x:%02x:%02x:%02x "
|
||||
"added with return value %d\n",
|
||||
bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], ret);
|
||||
@ -133,8 +95,6 @@ static bool _esp_now_add_peer(uint8_t* bssid, uint8_t channel, uint8_t* key)
|
||||
static xtimer_t _esp_now_scan_peers_timer;
|
||||
static bool _esp_now_scan_peers_done = false;
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
|
||||
#define ESP_NOW_APS_BLOCK_SIZE 8 /* has to be power of two */
|
||||
|
||||
static wifi_ap_record_t* aps = NULL;
|
||||
@ -207,64 +167,14 @@ static void IRAM_ATTR esp_now_scan_peers_done(void)
|
||||
mutex_unlock(&_esp_now_dev.dev_lock);
|
||||
}
|
||||
|
||||
#else /* MCU_ESP32 */
|
||||
|
||||
static const struct scan_config scan_cfg = {
|
||||
.ssid = 0,
|
||||
.bssid = 0,
|
||||
.channel = ESP_NOW_CHANNEL,
|
||||
.show_hidden = true
|
||||
};
|
||||
|
||||
static void IRAM esp_now_scan_peers_done(void *arg, STATUS status)
|
||||
{
|
||||
/* This function is executed in interrupt context */
|
||||
|
||||
DEBUG("%s: %p %d\n", __func__, arg, status);
|
||||
|
||||
CHECK_PARAM (status == OK);
|
||||
CHECK_PARAM (arg != NULL);
|
||||
|
||||
critical_enter();
|
||||
|
||||
struct bss_info *bss_link = (struct bss_info*)arg;
|
||||
|
||||
/* iterate over APs records */
|
||||
while (bss_link) {
|
||||
/* check whether the AP is an ESP_NOW node */
|
||||
if (strncmp((char*)bss_link->ssid, ESP_NOW_AP_PREFIX, ESP_NOW_AP_PREFIX_LEN) == 0) {
|
||||
/* add the AP as peer */
|
||||
_esp_now_add_peer(bss_link->bssid, bss_link->channel, esp_now_params.key);
|
||||
}
|
||||
bss_link = STAILQ_NEXT(bss_link, next);
|
||||
}
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
uint8_t peers_all;
|
||||
uint8_t peers_enc;
|
||||
esp_now_get_cnt_info (&peers_all, &peers_enc);
|
||||
DEBUG("associated peers total=%d, encrypted=%d\n", peers_all, peers_enc);
|
||||
#endif /* ENABLE_DEBUG */
|
||||
|
||||
_esp_now_scan_peers_done = true;
|
||||
|
||||
critical_exit();
|
||||
}
|
||||
|
||||
#endif /* MCU_ESP32 */
|
||||
|
||||
static void esp_now_scan_peers_start(void)
|
||||
{
|
||||
DEBUG("%s\n", __func__);
|
||||
|
||||
/* start the scan */
|
||||
esp_wifi_scan_start(&scan_cfg, false);
|
||||
/* set the time for next scan */
|
||||
xtimer_set(&_esp_now_scan_peers_timer, esp_now_params.scan_period);
|
||||
/* start the scan */
|
||||
#ifdef MCU_ESP32
|
||||
esp_wifi_scan_start(&scan_cfg, false);
|
||||
#else
|
||||
wifi_station_scan((struct scan_config*)&scan_cfg, esp_now_scan_peers_done);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void IRAM_ATTR esp_now_scan_peers_timer_cb(void* arg)
|
||||
@ -287,11 +197,7 @@ static const uint8_t _esp_now_mac[6] = { 0x82, 0x73, 0x79, 0x84, 0x79, 0x83 }; /
|
||||
|
||||
static bool _in_recv_cb = false;
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
static IRAM_ATTR void esp_now_recv_cb(const uint8_t *mac, const uint8_t *data, int len)
|
||||
#else
|
||||
static IRAM_ATTR void esp_now_recv_cb(uint8_t *mac, uint8_t *data, uint8_t len)
|
||||
#endif
|
||||
{
|
||||
#if ESP_NOW_UNICAST
|
||||
if (!_esp_now_scan_peers_done) {
|
||||
@ -349,11 +255,7 @@ static IRAM_ATTR void esp_now_recv_cb(uint8_t *mac, uint8_t *data, uint8_t len)
|
||||
|
||||
static volatile int _esp_now_sending = 0;
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
static void IRAM_ATTR esp_now_send_cb(const uint8_t *mac, esp_now_send_status_t status)
|
||||
#else
|
||||
static void IRAM_ATTR esp_now_send_cb(uint8_t *mac, uint8_t status)
|
||||
#endif
|
||||
{
|
||||
DEBUG("%s: sent to %02x:%02x:%02x:%02x:%02x:%02x with status %d\n",
|
||||
__func__,
|
||||
@ -364,7 +266,6 @@ static void IRAM_ATTR esp_now_send_cb(uint8_t *mac, uint8_t status)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
/*
|
||||
* Event handler for esp system events.
|
||||
*/
|
||||
@ -389,12 +290,6 @@ static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t *
|
||||
extern esp_err_t esp_system_event_add_handler(system_event_cb_t handler,
|
||||
void *arg);
|
||||
|
||||
#else /* MCU_ESP32 */
|
||||
|
||||
#define ESP_IF_WIFI_STA (STATION_IF)
|
||||
|
||||
#endif /* MCU_ESP32 */
|
||||
|
||||
esp_now_netdev_t *netdev_esp_now_setup(void)
|
||||
{
|
||||
esp_now_netdev_t* dev = &_esp_now_dev;
|
||||
@ -406,17 +301,17 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
|
||||
return dev;
|
||||
}
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
|
||||
/* initialize buffer */
|
||||
dev->rx_len = 0;
|
||||
|
||||
/* set the event handler */
|
||||
esp_system_event_add_handler(_esp_system_event_handler, NULL);
|
||||
|
||||
#ifdef MCU_ESP32
|
||||
/* init the WiFi driver */
|
||||
extern portMUX_TYPE g_intr_lock_mux;
|
||||
mutex_init(&g_intr_lock_mux);
|
||||
#endif /* MCU_ESP32 */
|
||||
|
||||
esp_err_t result;
|
||||
|
||||
@ -462,7 +357,7 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
|
||||
}
|
||||
};
|
||||
|
||||
/* get SoftAP interface mac address and store it as device addresss */
|
||||
/* get SoftAP interface mac address and store it as device address */
|
||||
esp_read_mac(dev->addr, ESP_MAC_WIFI_SOFTAP);
|
||||
|
||||
/* prepare the ESP_NOW configuration for SoftAP */
|
||||
@ -513,6 +408,7 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
|
||||
"esp_wifi_start failed with return value %d\n", result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if !ESP_NOW_UNICAST
|
||||
/* all ESP-NOW nodes get the shared mac address on their station interface */
|
||||
esp_wifi_set_mac(ESP_IF_WIFI_STA, (uint8_t*)_esp_now_mac);
|
||||
@ -520,41 +416,6 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
|
||||
|
||||
#endif /* MODULE_ESP_WIFI */
|
||||
|
||||
#else /* MCU_ESP32 */
|
||||
|
||||
int result;
|
||||
|
||||
/* set the WiFi interface to Station + SoftAP mode without DHCP */
|
||||
wifi_set_opmode_current(ESP_NOW_WIFI_STA_SOFTAP);
|
||||
wifi_softap_dhcps_stop();
|
||||
|
||||
/* get SoftAP mac address and store it in device address */
|
||||
wifi_get_macaddr(SOFTAP_IF, dev->addr);
|
||||
|
||||
/* set the SoftAP configuration */
|
||||
struct softap_config ap_conf;
|
||||
|
||||
strcpy((char*)ap_conf.password, esp_now_params.softap_pass);
|
||||
sprintf((char*)ap_conf.ssid, "%s%02x%02x%02x%02x%02x%02x", ESP_NOW_AP_PREFIX,
|
||||
dev->addr[0], dev->addr[1], dev->addr[2],
|
||||
dev->addr[3], dev->addr[4], dev->addr[5]);
|
||||
|
||||
ap_conf.ssid_len = strlen((char*)ap_conf.ssid);
|
||||
ap_conf.channel = esp_now_params.channel; /* support 1 ~ 13 */
|
||||
ap_conf.authmode = AUTH_WPA2_PSK; /* don't support AUTH_WEP in softAP mode. */
|
||||
ap_conf.ssid_hidden = 0; /* default 0 */
|
||||
ap_conf.max_connection = 4; /* default 4, max 4 */
|
||||
ap_conf.beacon_interval = 100; /* support 100 ~ 60000 ms, default 100 */
|
||||
|
||||
wifi_softap_set_config_current(&ap_conf);
|
||||
|
||||
#if !ESP_NOW_UNICAST
|
||||
/* all ESP-NOW nodes get the shared mac address on their station interface */
|
||||
wifi_set_macaddr(ESP_IF_WIFI_STA, (uint8_t*)_esp_now_mac);
|
||||
#endif
|
||||
|
||||
#endif /* MCU_ESP32 */
|
||||
|
||||
/* set the netdev driver */
|
||||
dev->netdev.driver = &_esp_now_driver;
|
||||
|
||||
@ -572,7 +433,6 @@ esp_now_netdev_t *netdev_esp_now_setup(void)
|
||||
}
|
||||
esp_now_register_send_cb(esp_now_send_cb);
|
||||
esp_now_register_recv_cb(esp_now_recv_cb);
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
|
||||
#if ESP_NOW_UNICAST
|
||||
/* timer for peer scan initialization */
|
||||
|
2
cpu/esp_common/vendor/xtensa/portasm.S
vendored
2
cpu/esp_common/vendor/xtensa/portasm.S
vendored
@ -57,6 +57,8 @@ port_IntStack:
|
||||
.space configISR_STACK_SIZE
|
||||
.global port_IntStackTop
|
||||
port_IntStackTop:
|
||||
.global _chip_interrupt_tmp
|
||||
_chip_interrupt_tmp:
|
||||
.word 0
|
||||
|
||||
#ifndef RIOT_VERSION
|
||||
|
6
cpu/esp_common/vendor/xtensa/xtensa_intr.c
vendored
6
cpu/esp_common/vendor/xtensa/xtensa_intr.c
vendored
@ -112,13 +112,7 @@ xt_handler xt_set_interrupt_handler(int n, xt_handler f, void * arg)
|
||||
if( Xthal_intlevel[n] > XCHAL_EXCM_LEVEL )
|
||||
return 0; /* priority level too high to safely handle in C */
|
||||
|
||||
#ifdef MODULE_ESP_SDK
|
||||
/* for compatibility reasons with SDK, we use _xtos_interrupt_table */
|
||||
/* in reverse order */
|
||||
entry = _xt_interrupt_table + (XCHAL_NUM_INTERRUPTS - n);
|
||||
#else
|
||||
entry = _xt_interrupt_table + n;
|
||||
#endif
|
||||
old = entry->handler;
|
||||
|
||||
if (f) {
|
||||
|
@ -66,7 +66,6 @@ _xt_vpri_mask: .word 0xFFFFFFFF /* Virtual priority mask */
|
||||
in SDK we use _xtos_interrupt_table_ which is provided as symbol
|
||||
_xt_interrupt_table_ by ld script
|
||||
*/
|
||||
#ifndef MODULE_ESP_SDK
|
||||
.data
|
||||
.global _xt_interrupt_table
|
||||
.align 8
|
||||
@ -79,7 +78,6 @@ _xt_interrupt_table:
|
||||
.word i /* handler arg (default: intnum) */
|
||||
.set i, i+1
|
||||
.endr
|
||||
#endif
|
||||
|
||||
#endif /* XCHAL_HAVE_INTERRUPTS */
|
||||
|
||||
|
166
cpu/esp_common/vendor/xtensa/xtensa_vectors.S
vendored
166
cpu/esp_common/vendor/xtensa/xtensa_vectors.S
vendored
@ -96,7 +96,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
/* Enable stack backtrace across exception/interrupt - see below */
|
||||
#define XT_DEBUG_BACKTRACE 1
|
||||
|
||||
|
||||
/*
|
||||
--------------------------------------------------------------------------------
|
||||
Defines used to access _xtos_interrupt_table.
|
||||
@ -225,10 +224,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
find_ms_setbit a3, a4, a3, 0 /* a3 = interrupt number */
|
||||
|
||||
#if MODULE_ESP_SDK /* _xtos_interrupt_table is in reverse order */
|
||||
movi a4, XCHAL_NUM_INTERRUPTS /* intnum = XCHAL_NUM_INTERRUPTS - intnum */
|
||||
sub a3, a4, a3
|
||||
#endif
|
||||
movi a4, _xt_interrupt_table
|
||||
addx8 a3, a3, a4 /* a3 = address of interrupt table entry */
|
||||
l32i a4, a3, XIE_HANDLER /* a4 = handler address */
|
||||
@ -302,6 +297,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
.text
|
||||
.literal_position
|
||||
.global _xt_panic
|
||||
.type _xt_panic,@function
|
||||
.align 4
|
||||
@ -315,6 +311,10 @@ _xt_panic:
|
||||
movi a2, SYS_gdb_abort
|
||||
simcall
|
||||
#else
|
||||
#ifdef RIOT_VERSION
|
||||
addi a2, a0, -3
|
||||
call0 _panic_handler
|
||||
#endif
|
||||
rsil a2, XCHAL_EXCM_LEVEL /* disable all low & med ints */
|
||||
1: j 1b /* loop infinitely */
|
||||
#endif
|
||||
@ -388,6 +388,14 @@ Debug Exception.
|
||||
.align 4
|
||||
|
||||
_DebugExceptionVector:
|
||||
/*
|
||||
* Please note that this code will be overwritten with
|
||||
*
|
||||
* xsr a2, excsave2
|
||||
* jx a2
|
||||
*
|
||||
* if module esp_gdbstub is used.
|
||||
*/
|
||||
|
||||
#ifdef XT_SIMULATOR
|
||||
/*
|
||||
@ -401,15 +409,15 @@ _DebugExceptionVector:
|
||||
wsr a3, EXCSAVE+XCHAL_DEBUGLEVEL
|
||||
movi a3, xthal_debugexc_defhndlr_nw /* use default debug handler */
|
||||
jx a3
|
||||
#else
|
||||
#else /* XT_SIMULATOR */
|
||||
wsr a0, EXCSAVE+XCHAL_DEBUGLEVEL /* save original a0 somewhere */
|
||||
call0 _xt_panic /* does not return */
|
||||
rfi XCHAL_DEBUGLEVEL /* make a0 point here not later */
|
||||
#endif
|
||||
#endif /* XT_SIMULATOR */
|
||||
|
||||
.end literal_prefix
|
||||
.end literal_prefix
|
||||
|
||||
#endif
|
||||
#endif /* XCHAL_HAVE_DEBUG */
|
||||
|
||||
/*
|
||||
--------------------------------------------------------------------------------
|
||||
@ -503,6 +511,7 @@ _UserExceptionVector:
|
||||
* "LoadStoreError Handler END" markers was extracted from esp-open-rtos. It is
|
||||
* under the following copyright:
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Original vector contents Copyright (C) 2014-2015 Espressif Systems
|
||||
* Additions Copyright (C) Superhouse Automation Pty Ltd and Angus Gratton
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
@ -573,13 +582,13 @@ _LoadStoreErrorHandler:
|
||||
s32i a2, sp, 0x08
|
||||
s32i a3, sp, 0x0c
|
||||
s32i a4, sp, 0x10
|
||||
rsr a0, sar # Save SAR in a0 to restore later
|
||||
rsr a0, sar # Save SAR in a0 to restore later
|
||||
|
||||
/* Examine the opcode which generated the exception */
|
||||
/* Note: Instructions are in this order to avoid pipeline stalls. */
|
||||
rsr a2, epc1
|
||||
movi a3, ~3
|
||||
ssa8l a2 # sar is now correct shift for aligned read
|
||||
ssa8l a2 # sar is now correct shift for aligned read
|
||||
and a2, a2, a3 # a2 now 4-byte aligned address of instruction
|
||||
l32i a4, a2, 0
|
||||
l32i a2, a2, 4
|
||||
@ -600,8 +609,8 @@ _LoadStoreErrorHandler:
|
||||
and a4, a3, a4 # a4 now word aligned read address
|
||||
|
||||
l32i a4, a4, 0 # perform the actual read
|
||||
ssa8l a3 # sar is now shift to extract a3's byte
|
||||
srl a3, a4 # shift right correct distance
|
||||
ssa8l a3 # sar is now shift to extract a3's byte
|
||||
srl a3, a4 # shift right correct distance
|
||||
extui a4, a3, 0, 8 # mask off bits we need for an l8
|
||||
|
||||
.LSE_post_fetch:
|
||||
@ -678,8 +687,8 @@ _LoadStoreErrorHandler:
|
||||
and a4, a3, a4 # a4 now word aligned read address
|
||||
|
||||
l32i a4, a4, 0 # perform the actual read
|
||||
ssa8l a3 # sar is now shift to extract a3's bytes
|
||||
srl a3, a4 # shift right correct distance
|
||||
ssa8l a3 # sar is now shift to extract a3's bytes
|
||||
srl a3, a4 # shift right correct distance
|
||||
extui a4, a3, 0, 16 # mask off bits we need for an l16
|
||||
|
||||
bbci a2, 15, .LSE_post_fetch # Not a signed op
|
||||
@ -1951,14 +1960,32 @@ _xt_highint6:
|
||||
|
||||
#if XCHAL_HAVE_NMI
|
||||
|
||||
#define NMI_STACK_CANARY 0xABBABABA
|
||||
|
||||
/* Stack space for NMI handler
|
||||
|
||||
NMI handler stack high water mark measured at 0x134 bytes. Any use
|
||||
of the NMI timer callback will add stack overhead as well.
|
||||
|
||||
The NMI handler does a basic check for stack overflow
|
||||
*/
|
||||
|
||||
.section .bss
|
||||
.balign 16
|
||||
|
||||
NMIHandlerStack:
|
||||
.skip 0x200
|
||||
.NMIHandlerStackTop:
|
||||
|
||||
.begin literal_prefix .NMIExceptionVector
|
||||
.section .NMIExceptionVector.text, "ax"
|
||||
.global _NMIExceptionVector
|
||||
.type _NMIExceptionVector,@function
|
||||
.literal_position
|
||||
|
||||
.align 4
|
||||
|
||||
_NMIExceptionVector:
|
||||
|
||||
wsr a0, EXCSAVE + XCHAL_NMILEVEL _ /* preserve a0 */
|
||||
call0 _xt_nmi /* load interrupt handler */
|
||||
/* never returns here - call0 is used as a jump (see note at top) */
|
||||
@ -1983,6 +2010,113 @@ _xt_nmi:
|
||||
/* USER_EDIT:
|
||||
ADD HIGH PRIORITY NON-MASKABLE INTERRUPT (NMI) HANDLER CODE HERE.
|
||||
*/
|
||||
#if defined(RIOT_VERSION) && defined(MCU_ESP8266)
|
||||
|
||||
rsr a0, EXCSAVE + XCHAL_NMILEVEL /* restore a0 as saved in _NMIExceptionHandler */
|
||||
|
||||
/*************************** NMI Handler BEGIN **************************/
|
||||
/*
|
||||
* PLEASE NOTE: The code between "NMI Handler BEGIN" and
|
||||
* "NMI Handler END" markers was extracted from esp-open-rtos.
|
||||
* It is under the following copyright:
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Original vector contents Copyright (C) 2014-2015 Espressif Systems
|
||||
* Additions Copyright (C) Superhouse Automation Pty Ltd and Angus Gratton
|
||||
* BSD Licensed as described in the file LICENSE.
|
||||
*/
|
||||
wsr sp, excsave3 # excsave3 holds user stack
|
||||
movi sp, .NMIHandlerStackTop - 0x40
|
||||
s32i a0, sp, 0x00
|
||||
s32i a2, sp, 0x04
|
||||
s32i a3, sp, 0x08
|
||||
s32i a4, sp, 0x0c
|
||||
s32i a5, sp, 0x10
|
||||
s32i a6, sp, 0x14
|
||||
s32i a7, sp, 0x18
|
||||
s32i a8, sp, 0x1c
|
||||
s32i a9, sp, 0x20
|
||||
s32i a10, sp, 0x24
|
||||
s32i a11, sp, 0x28
|
||||
rsr a0, epc1
|
||||
s32i a0, sp, 0x2c
|
||||
rsr a0, exccause
|
||||
s32i a0, sp, 0x30
|
||||
rsr a0, excsave1
|
||||
s32i a0, sp, 0x34
|
||||
rsr a0, excvaddr
|
||||
s32i a0, sp, 0x38
|
||||
rsr a0, sar
|
||||
s32i a0, sp, 0x3c
|
||||
movi a0, 0x23 # Override PS for NMI handler
|
||||
wsr a0, ps
|
||||
rsync
|
||||
|
||||
/* mark the stack overflow point before we call the actual NMI handler */
|
||||
movi a0, NMIHandlerStack
|
||||
movi a2, NMI_STACK_CANARY
|
||||
s32i a2, a0, 0x00
|
||||
|
||||
call0 wDev_ProcessFiq
|
||||
|
||||
/* verify we didn't overflow */
|
||||
movi a0, NMIHandlerStack
|
||||
l32i a3, a0, 0
|
||||
movi a2, NMI_STACK_CANARY
|
||||
bne a3, a2, _xt_panic /* .NMIFatalStackOverflow */
|
||||
|
||||
l32i a0, sp, 0x3c
|
||||
wsr a0, sar
|
||||
l32i a0, sp, 0x38
|
||||
wsr a0, excvaddr
|
||||
l32i a0, sp, 0x34
|
||||
wsr a0, excsave1
|
||||
l32i a0, sp, 0x30
|
||||
wsr a0, exccause
|
||||
l32i a0, sp, 0x2c
|
||||
wsr a0, epc1
|
||||
l32i a11, sp, 0x28
|
||||
l32i a10, sp, 0x24
|
||||
l32i a9, sp, 0x20
|
||||
l32i a8, sp, 0x1c
|
||||
l32i a7, sp, 0x18
|
||||
l32i a6, sp, 0x14
|
||||
l32i a5, sp, 0x10
|
||||
l32i a4, sp, 0x0c
|
||||
l32i a3, sp, 0x08
|
||||
movi a0, 0x33 # Reset PS
|
||||
wsr a0, ps
|
||||
rsync
|
||||
/* set dport nmi status to 1 (wDev_ProcessFiq clears bit 0 and verifies it
|
||||
* stays cleared, see
|
||||
* http://esp8266-re.foogod.com/wiki/WDev_ProcessFiq_%28IoT_RTOS_SDK_0.9.9%29)
|
||||
*/
|
||||
movi a0, 0x3ff00000
|
||||
movi a2, 0x1
|
||||
s32i a2, a0, 0
|
||||
l32i a2, sp, 0x04
|
||||
l32i a0, sp, 0x00
|
||||
movi a1, 0x0
|
||||
xsr a1, excsave3 # Load stack back from excsave3, clear excsave3
|
||||
rfi XCHAL_NMILEVEL
|
||||
|
||||
.section .rodata
|
||||
.NMIStackOverflowErrorMsg:
|
||||
.string "\nFATAL: NMI Stack Overflow\n"
|
||||
|
||||
.section .NMIExceptionhandler.text, "ax"
|
||||
.literal_position
|
||||
|
||||
.NMIFatalStackOverflow:
|
||||
movi a2, .NMIStackOverflowErrorMsg
|
||||
call0 printf
|
||||
|
||||
.NMIInfiniteLoop:
|
||||
j .NMIInfiniteLoop /* TODO: replace with call to abort() */
|
||||
|
||||
/*************************** NMI Handler END ****************************/
|
||||
|
||||
#endif /* defined(RIOT_VERSION) && defined(MCU_ESP8266) */
|
||||
|
||||
.align 4
|
||||
.L_xt_nmi_exit:
|
||||
|
Loading…
Reference in New Issue
Block a user