mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
change idle loop prio to 0
This commit is contained in:
parent
ef378a625b
commit
fecd8c6175
@ -1,17 +1,19 @@
|
||||
/*
|
||||
* ESP8266_board.h
|
||||
*
|
||||
* Created on: Aug 25, 2015
|
||||
* Author: kolban
|
||||
*/
|
||||
|
||||
#ifndef TARGETS_ESP8266_ESP8266_BOARD_H_
|
||||
#define TARGETS_ESP8266_ESP8266_BOARD_H_
|
||||
#include <user_interface.h>
|
||||
// Define the task ids for the APP event handler
|
||||
#define TASK_APP_MAINLOOP ((os_signal_t)1)
|
||||
#define TASK_APP_RX_DATA ((os_signal_t)2)
|
||||
#define TASK_APP_QUEUE USER_TASK_PRIO_1
|
||||
|
||||
|
||||
#endif /* TARGETS_ESP8266_ESP8266_BOARD_H_ */
|
||||
/*
|
||||
* ESP8266_board.h
|
||||
*
|
||||
* Created on: Aug 25, 2015
|
||||
* Author: kolban
|
||||
*/
|
||||
|
||||
#ifndef TARGETS_ESP8266_ESP8266_BOARD_H_
|
||||
#define TARGETS_ESP8266_ESP8266_BOARD_H_
|
||||
#include <user_interface.h>
|
||||
|
||||
// Define the task ids for the APP event handler
|
||||
#define TASK_APP_MAINLOOP ((os_signal_t)1)
|
||||
#define TASK_APP_RX_DATA ((os_signal_t)2)
|
||||
|
||||
// Task priority for main loop
|
||||
#define TASK_APP_QUEUE USER_TASK_PRIO_0
|
||||
|
||||
#endif /* TARGETS_ESP8266_ESP8266_BOARD_H_ */
|
||||
|
||||
@ -86,16 +86,16 @@ uart_config(uint8 uart_no)
|
||||
#endif
|
||||
}
|
||||
uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));//SET BAUDRATE
|
||||
|
||||
|
||||
WRITE_PERI_REG(UART_CONF0(uart_no), ((UartDev.exist_parity & UART_PARITY_EN_M) << UART_PARITY_EN_S) //SET BIT AND PARITY MODE
|
||||
| ((UartDev.parity & UART_PARITY_M) <<UART_PARITY_S )
|
||||
| ((UartDev.stop_bits & UART_STOP_BIT_NUM) << UART_STOP_BIT_NUM_S)
|
||||
| ((UartDev.data_bits & UART_BIT_NUM) << UART_BIT_NUM_S));
|
||||
|
||||
|
||||
//clear rx and tx fifo,not ready
|
||||
SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); //RESET FIFO
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
|
||||
|
||||
|
||||
if (uart_no == UART0){
|
||||
//set rx fifo trigger
|
||||
WRITE_PERI_REG(UART_CONF1(uart_no),
|
||||
@ -106,7 +106,7 @@ uart_config(uint8 uart_no)
|
||||
#endif
|
||||
(0x02 & UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S |
|
||||
UART_RX_TOUT_EN|
|
||||
((0x10 & UART_TXFIFO_EMPTY_THRHD)<<UART_TXFIFO_EMPTY_THRHD_S));//wjl
|
||||
((0x10 & UART_TXFIFO_EMPTY_THRHD)<<UART_TXFIFO_EMPTY_THRHD_S));//wjl
|
||||
#if UART_HW_CTS
|
||||
SET_PERI_REG_MASK( UART_CONF0(uart_no),UART_TX_FLOW_EN); //add this sentense to add a tx flow control via MTCK( CTS )
|
||||
#endif
|
||||
@ -153,7 +153,7 @@ uart1_write_char(char c)
|
||||
uart_tx_one_char(UART1, '\r');
|
||||
uart_tx_one_char(UART1, '\n');
|
||||
}else if (c == '\r'){
|
||||
|
||||
|
||||
}else{
|
||||
uart_tx_one_char(UART1, c);
|
||||
}
|
||||
@ -163,7 +163,7 @@ uart1_write_char(char c)
|
||||
LOCAL void ICACHE_FLASH_ATTR
|
||||
uart0_write_char_no_wait(char c)
|
||||
{
|
||||
#if UART_BUFF_EN //send to uart0 fifo but do not wait
|
||||
#if UART_BUFF_EN //send to uart0 fifo but do not wait
|
||||
uint8 chr;
|
||||
if (c == '\n'){
|
||||
chr = '\r';
|
||||
@ -171,7 +171,7 @@ uart0_write_char_no_wait(char c)
|
||||
chr = '\n';
|
||||
tx_buff_enq(&chr, 1);
|
||||
}else if (c == '\r'){
|
||||
|
||||
|
||||
}else{
|
||||
tx_buff_enq(&c,1);
|
||||
}
|
||||
@ -180,7 +180,7 @@ uart0_write_char_no_wait(char c)
|
||||
uart_tx_one_char_no_wait(UART0, '\r');
|
||||
uart_tx_one_char_no_wait(UART0, '\n');
|
||||
}else if (c == '\r'){
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
uart_tx_one_char_no_wait(UART0, c);
|
||||
@ -239,7 +239,7 @@ uart0_rx_intr_handler(void *para)
|
||||
uint8 buf_idx = 0;
|
||||
uint8 temp,cnt;
|
||||
//RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para;
|
||||
|
||||
|
||||
/*ATTENTION:*/
|
||||
/*IN NON-OS VERSION SDK, DO NOT USE "ICACHE_FLASH_ATTR" FUNCTIONS IN THE WHOLE HANDLER PROCESS*/
|
||||
/*ALL THE FUNCTIONS CALLED IN INTERRUPT HANDLER MUST BE DECLARED IN RAM */
|
||||
@ -270,7 +270,7 @@ uart0_rx_intr_handler(void *para)
|
||||
#endif
|
||||
//system_os_post(uart_recvTaskPrio, 1, 0);
|
||||
WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_TXFIFO_EMPTY_INT_CLR);
|
||||
|
||||
|
||||
}else if(UART_RXFIFO_OVF_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_OVF_INT_ST)){
|
||||
WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_RXFIFO_OVF_INT_CLR);
|
||||
DBG1("RX OVF!!\r\n");
|
||||
@ -301,7 +301,7 @@ LOCAL void ICACHE_FLASH_ATTR ///////
|
||||
uart_recvTask(os_event_t *events)
|
||||
{
|
||||
if(events->sig == 0){
|
||||
#if UART_BUFF_EN
|
||||
#if UART_BUFF_EN
|
||||
Uart_rx_buff_enq();
|
||||
#else
|
||||
uint8 fifo_len = (READ_PERI_REG(UART_STATUS(UART0))>>UART_RXFIFO_CNT_S)&UART_RXFIFO_CNT;
|
||||
@ -317,7 +317,7 @@ uart_recvTask(os_event_t *events)
|
||||
}
|
||||
}
|
||||
if (fifo_len > 0) {
|
||||
system_os_post(1, 2, 0);
|
||||
system_os_post(0, 2, 0);
|
||||
}
|
||||
WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR|UART_RXFIFO_TOUT_INT_CLR);
|
||||
uart_rx_intr_enable(UART0);
|
||||
@ -326,8 +326,8 @@ uart_recvTask(os_event_t *events)
|
||||
#if UART_BUFF_EN
|
||||
//already move uart buffer output to uart empty interrupt
|
||||
//tx_start_uart_buffer(UART0);
|
||||
#else
|
||||
|
||||
#else
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -337,13 +337,13 @@ uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
|
||||
{
|
||||
/*this is a example to process uart data from task,please change the priority to fit your application task if exists*/
|
||||
system_os_task(uart_recvTask, uart_recvTaskPrio, uart_recvTaskQueue, uart_recvTaskQueueLen); //demo with a task to process the uart data
|
||||
|
||||
|
||||
UartDev.baut_rate = uart0_br;
|
||||
uart_config(UART0);
|
||||
UartDev.baut_rate = uart1_br;
|
||||
uart_config(UART1);
|
||||
ETS_UART_INTR_ENABLE();
|
||||
|
||||
|
||||
#if UART_BUFF_EN
|
||||
pTxBuffer = Uart_Buf_Init(UART_TX_BUFFER_SIZE);
|
||||
pRxBuffer = Uart_Buf_Init(UART_RX_BUFFER_SIZE);
|
||||
@ -361,7 +361,7 @@ uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
|
||||
/*see uart0_write_char_no_wait:you can output via a buffer or output directly */
|
||||
/*os_printf output uart data via uart0 or uart buffer*/
|
||||
//os_install_putc1((void *)uart0_write_char_no_wait); //use this to print via uart0
|
||||
|
||||
|
||||
#if UART_SELFTEST&UART_BUFF_EN
|
||||
os_timer_disarm(&buff_timer_t);
|
||||
os_timer_setfn(&buff_timer_t, uart_test_rx , NULL); //a demo to process the data in uart rx buffer
|
||||
@ -377,7 +377,7 @@ uart_reattach()
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : uart_tx_one_char_no_wait
|
||||
* Description : uart tx a single char without waiting for fifo
|
||||
* Description : uart tx a single char without waiting for fifo
|
||||
* Parameters : uint8 uart - uart port
|
||||
* uint8 TxChar - char to tx
|
||||
* Returns : STATUS
|
||||
@ -418,7 +418,7 @@ void uart1_sendStr_no_wait(const char *str)
|
||||
#if UART_BUFF_EN
|
||||
/******************************************************************************
|
||||
* FunctionName : Uart_Buf_Init
|
||||
* Description : tx buffer enqueue: fill a first linked buffer
|
||||
* Description : tx buffer enqueue: fill a first linked buffer
|
||||
* Parameters : char *pdata - data point to be enqueue
|
||||
* Returns : NONE
|
||||
*******************************************************************************/
|
||||
@ -449,7 +449,7 @@ Uart_Buf_Init(uint32 buf_size)
|
||||
LOCAL void Uart_Buf_Cpy(struct UartBuffer* pCur, char* pdata , uint16 data_len)
|
||||
{
|
||||
if(data_len == 0) return ;
|
||||
|
||||
|
||||
uint16 tail_len = pCur->pUartBuff + pCur->UartBuffSize - pCur->pInPos ;
|
||||
if(tail_len >= data_len){ //do not need to loop back the queue
|
||||
os_memcpy(pCur->pInPos , pdata , data_len );
|
||||
@ -466,7 +466,7 @@ LOCAL void Uart_Buf_Cpy(struct UartBuffer* pCur, char* pdata , uint16 data_len)
|
||||
pCur->pInPos = (pCur->pUartBuff + (pCur->pInPos - pCur->pUartBuff) % pCur->UartBuffSize );
|
||||
pCur->Space -=( data_len-tail_len);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@ -501,11 +501,11 @@ rx_buff_deq(char* pdata, uint16 data_len )
|
||||
pRxBuffer->pOutPos += tail_len;
|
||||
pRxBuffer->pOutPos = (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos- pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize );
|
||||
pRxBuffer->Space += tail_len;
|
||||
|
||||
|
||||
os_memcpy(pdata+tail_len , pRxBuffer->pOutPos, len_tmp-tail_len);
|
||||
pRxBuffer->pOutPos+= ( len_tmp-tail_len );
|
||||
pRxBuffer->pOutPos= (pRxBuffer->pUartBuff + (pRxBuffer->pOutPos- pRxBuffer->pUartBuff) % pRxBuffer->UartBuffSize );
|
||||
pRxBuffer->Space +=( len_tmp-tail_len);
|
||||
pRxBuffer->Space +=( len_tmp-tail_len);
|
||||
}else{
|
||||
//os_printf("case 3 in rx deq\n\r");
|
||||
os_memcpy(pdata, pRxBuffer->pOutPos, len_tmp);
|
||||
@ -517,7 +517,7 @@ rx_buff_deq(char* pdata, uint16 data_len )
|
||||
if(pRxBuffer->Space >= UART_FIFO_LEN){
|
||||
uart_rx_intr_enable(UART0);
|
||||
}
|
||||
return len_tmp;
|
||||
return len_tmp;
|
||||
}
|
||||
|
||||
|
||||
@ -529,7 +529,7 @@ void Uart_rx_buff_enq()
|
||||
#if 1
|
||||
fifo_len = (READ_PERI_REG(UART_STATUS(UART0))>>UART_RXFIFO_CNT_S)&UART_RXFIFO_CNT;
|
||||
if(fifo_len >= pRxBuffer->Space){
|
||||
os_printf("buf full!!!\n\r");
|
||||
os_printf("buf full!!!\n\r");
|
||||
}else{
|
||||
buf_idx=0;
|
||||
while(buf_idx < fifo_len){
|
||||
@ -538,7 +538,7 @@ void Uart_rx_buff_enq()
|
||||
*(pRxBuffer->pInPos++) = fifo_data;
|
||||
if(pRxBuffer->pInPos == (pRxBuffer->pUartBuff + pRxBuffer->UartBuffSize)){
|
||||
pRxBuffer->pInPos = pRxBuffer->pUartBuff;
|
||||
}
|
||||
}
|
||||
}
|
||||
pRxBuffer->Space -= fifo_len ;
|
||||
if(pRxBuffer->Space >= UART_FIFO_LEN){
|
||||
@ -573,7 +573,7 @@ tx_buff_enq(char* pdata, uint16 data_len )
|
||||
}
|
||||
#if 0
|
||||
if(pTxBuffer->Space <= URAT_TX_LOWER_SIZE){
|
||||
set_tcp_block();
|
||||
set_tcp_block();
|
||||
}
|
||||
#endif
|
||||
SET_PERI_REG_MASK(UART_CONF1(UART0), (UART_TX_EMPTY_THRESH_VAL & UART_TXFIFO_EMPTY_THRHD)<<UART_TXFIFO_EMPTY_THRHD_S);
|
||||
@ -610,8 +610,8 @@ void tx_start_uart_buffer(uint8 uart_no)
|
||||
uint8 len_tmp;
|
||||
uint16 tail_ptx_len,head_ptx_len,data_len;
|
||||
//struct UartBuffer* pTxBuff = *get_buff_prt();
|
||||
|
||||
if(pTxBuffer){
|
||||
|
||||
if(pTxBuffer){
|
||||
data_len = (pTxBuffer->UartBuffSize - pTxBuffer->Space);
|
||||
if(data_len > fifo_remain){
|
||||
len_tmp = fifo_remain;
|
||||
@ -662,26 +662,26 @@ uart0_write_char(char c)
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len)
|
||||
UART_SetWordLength(uint8 uart_no, UartBitsNum4Char len)
|
||||
{
|
||||
SET_PERI_REG_BITS(UART_CONF0(uart_no),UART_BIT_NUM,len,UART_BIT_NUM_S);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num)
|
||||
UART_SetStopBits(uint8 uart_no, UartStopBitsNum bit_num)
|
||||
{
|
||||
SET_PERI_REG_BITS(UART_CONF0(uart_no),UART_STOP_BIT_NUM,bit_num,UART_STOP_BIT_NUM_S);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask)
|
||||
UART_SetLineInverse(uint8 uart_no, UART_LineLevelInverse inverse_mask)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_LINE_INV_MASK);
|
||||
SET_PERI_REG_MASK(UART_CONF0(uart_no), inverse_mask);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
UART_SetParity(uint8 uart_no, UartParityMode Parity_mode)
|
||||
UART_SetParity(uint8 uart_no, UartParityMode Parity_mode)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_PARITY |UART_PARITY_EN);
|
||||
if(Parity_mode==NONE_BITS){
|
||||
@ -719,7 +719,7 @@ UART_WaitTxFifoEmpty(uint8 uart_no , uint32 time_out_us) //do not use if tx flow
|
||||
{
|
||||
uint32 t_s = system_get_time();
|
||||
while (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S)){
|
||||
|
||||
|
||||
if(( system_get_time() - t_s )> time_out_us){
|
||||
break;
|
||||
}
|
||||
@ -742,7 +742,7 @@ UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us)
|
||||
}else{
|
||||
tx_buff_len = 0;
|
||||
}
|
||||
|
||||
|
||||
if( tx_fifo_len==0 && tx_buff_len==0){
|
||||
return TRUE;
|
||||
}
|
||||
@ -750,7 +750,7 @@ UART_CheckOutputFinished(uint8 uart_no, uint32 time_out_us)
|
||||
return FALSE;
|
||||
}
|
||||
WRITE_PERI_REG(0X60000914, 0X73);//WTD
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -801,7 +801,7 @@ uart_init_2(UartBautRate uart0_br, UartBautRate uart1_br)
|
||||
UartDev.parity = EVEN_BITS;
|
||||
UartDev.stop_bits = ONE_STOP_BIT;
|
||||
UartDev.data_bits = EIGHT_BITS;
|
||||
|
||||
|
||||
uart_config(UART0);
|
||||
UartDev.baut_rate = uart1_br;
|
||||
uart_config(UART1);
|
||||
|
||||
@ -1,241 +1,243 @@
|
||||
/*
|
||||
* This file is part of Espruino/ESP8266, a JavaScript interpreter for ESP8266
|
||||
*
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <user_interface.h>
|
||||
#include <osapi.h>
|
||||
#include <driver/uart.h>
|
||||
#include <telnet.h>
|
||||
#include <espmissingincludes.h>
|
||||
|
||||
//#define FAKE_STDLIB
|
||||
#define _GCC_WRAP_STDINT_H
|
||||
typedef long long int64_t;
|
||||
|
||||
#include <jsdevices.h>
|
||||
#include <jsinteractive.h>
|
||||
#include <jswrap_esp8266.h>
|
||||
#include "ESP8266_board.h"
|
||||
|
||||
// --- Constants
|
||||
// The size of the task queue
|
||||
#define TASK_QUEUE_LENGTH 10
|
||||
|
||||
// Should we introduce a ticker to say we are still alive?
|
||||
#define EPS8266_BOARD_HEARTBEAT
|
||||
|
||||
// --- Forward definitions
|
||||
static void mainLoop();
|
||||
|
||||
// --- File local variables
|
||||
|
||||
// The task queue for the app
|
||||
static os_event_t taskAppQueue[TASK_QUEUE_LENGTH];
|
||||
|
||||
// Flag indicating whether or not main loop processing is suspended.
|
||||
static bool suspendMainLoopFlag = false;
|
||||
|
||||
// Time structure for main loop time suspension.
|
||||
static os_timer_t mainLoopSuspendTimer;
|
||||
|
||||
// --- Functions
|
||||
/**
|
||||
* \brief Dump the ESP8266 restart information.
|
||||
* This is purely for debugging.
|
||||
* When an ESP8266 crashes, before it ends, it records its exception information.
|
||||
* This function retrieves that data and logs it.
|
||||
*/
|
||||
static void dumpRestart() {
|
||||
struct rst_info *rstInfo = system_get_rst_info();
|
||||
os_printf("Restart info:\n");
|
||||
os_printf(" reason: %d\n", rstInfo->reason);
|
||||
os_printf(" exccause: %x\n", rstInfo->exccause);
|
||||
os_printf(" epc1: %x\n", rstInfo->epc1);
|
||||
os_printf(" epc2: %x\n", rstInfo->epc2);
|
||||
os_printf(" epc3: %x\n", rstInfo->epc3);
|
||||
os_printf(" excvaddr: %x\n", rstInfo->excvaddr);
|
||||
os_printf(" depc: %x\n", rstInfo->depc);
|
||||
} // End of dump_restart
|
||||
|
||||
|
||||
/**
|
||||
* \brief Queue a task for the main loop.
|
||||
*/
|
||||
static void queueTaskMainLoop() {
|
||||
system_os_post(TASK_APP_QUEUE, TASK_APP_MAINLOOP, 0);
|
||||
} // End of queueMainLoop
|
||||
|
||||
|
||||
/**
|
||||
* \brief Suspend processing the main loop for a period of time.
|
||||
*/
|
||||
void suspendMainLoop(
|
||||
uint32 interval //!<
|
||||
) {
|
||||
suspendMainLoopFlag = true;
|
||||
os_timer_arm(&mainLoopSuspendTimer, interval, 0 /* No repeat */);
|
||||
} // End of suspendMainLoop
|
||||
|
||||
|
||||
/**
|
||||
* \brief Enable main loop processing.
|
||||
*/
|
||||
static void enableMainLoop() {
|
||||
suspendMainLoopFlag = false;
|
||||
queueTaskMainLoop();
|
||||
} // End of enableMainLoop
|
||||
|
||||
|
||||
/**
|
||||
* \brief The event handler for ESP8266 tasks as created by system_os_post() on the TASK_APP_QUEUE.
|
||||
*/
|
||||
static void eventHandler(
|
||||
os_event_t *pEvent //!<
|
||||
) {
|
||||
|
||||
switch (pEvent->sig) {
|
||||
// Handle the main loop event.
|
||||
case TASK_APP_MAINLOOP:
|
||||
mainLoop();
|
||||
break;
|
||||
// Handle the event to process received data.
|
||||
case TASK_APP_RX_DATA:
|
||||
{
|
||||
// Get the data from the UART RX buffer. If the size of the returned data is
|
||||
// not zero, then push it onto the Espruino processing queue for characters.
|
||||
char pBuffer[100];
|
||||
int size = getRXBuffer(pBuffer, sizeof(pBuffer));
|
||||
if (size > 0) {
|
||||
jshPushIOCharEvents(jsiGetConsoleDevice(), pBuffer, size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Handle the unknown event type.
|
||||
default:
|
||||
os_printf("user_main: eventHandler: Unknown task type: %d",
|
||||
pEvent->sig);
|
||||
break;
|
||||
}
|
||||
} // End of eventHandler
|
||||
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* \brief A callback function to be invoked when a line has been entered on the telnet client.
|
||||
* Here we want to pass that line to the JS parser for processing.
|
||||
*/
|
||||
static void telnetLineCB(char *line) {
|
||||
jsiConsolePrintf("LineCB: %s", line);
|
||||
// Pass the line to the interactive module ...
|
||||
|
||||
jshPushIOCharEvents(jsiGetConsoleDevice(), line, strlen(line));
|
||||
//jspEvaluate(line, true);
|
||||
//jsiDumpState();
|
||||
telnet_send("JS> ");
|
||||
} // End of lineCB
|
||||
|
||||
|
||||
/**
|
||||
* When we have been allocated a TCP/IP address, this function is called back. Obviously
|
||||
* there is little we can do at the network level until we have an IP.
|
||||
*/
|
||||
static void gotIpCallback() {
|
||||
telnet_startListening(telnetLineCB);
|
||||
} // End of gotIpCallback
|
||||
#endif
|
||||
|
||||
static uint32 lastTime = 0;
|
||||
|
||||
/**
|
||||
* \brief Perform the main loop processing.
|
||||
* This is where work is performed
|
||||
* as often as possible.
|
||||
*/
|
||||
static void mainLoop() {
|
||||
if (suspendMainLoopFlag == true) {
|
||||
return;
|
||||
}
|
||||
jsiLoop();
|
||||
|
||||
#ifdef EPS8266_BOARD_HEARTBEAT
|
||||
if (system_get_time() - lastTime > 1000 * 1000 * 5) {
|
||||
lastTime = system_get_time();
|
||||
os_printf("tick: %ld, heap: %ld\n",
|
||||
(uint32)(jshGetSystemTime()), system_get_free_heap_size());
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup for another callback
|
||||
queueTaskMainLoop();
|
||||
} // End of mainLoop
|
||||
|
||||
|
||||
/**
|
||||
* The ESP8266 provides a mechanism to register a callback that is invoked when initialization
|
||||
* of the ESP8266 is complete. This is the implementation of that callback. At this point
|
||||
* we can assume that the ESP8266 is fully ready to do work for us.
|
||||
*/
|
||||
static void initDone() {
|
||||
os_printf("initDone invoked\n");
|
||||
os_printf("Heap: %d\n", system_get_free_heap_size());
|
||||
|
||||
// Discard any junk data in the input as this is a boot.
|
||||
//uart_rx_discard();
|
||||
|
||||
jshInit(); // Initialize the hardware
|
||||
jsvInit(); // Initialize the variables
|
||||
jsiInit(false); // Initialize the interactive subsystem
|
||||
|
||||
// Register the event handlers.
|
||||
system_os_task(eventHandler, TASK_APP_QUEUE, taskAppQueue, TASK_QUEUE_LENGTH);
|
||||
|
||||
// At this point, our JavaScript environment should be up and running.
|
||||
|
||||
// Initialize the networking subsystem.
|
||||
jswrap_ESP8266WiFi_init();
|
||||
|
||||
// Post the first event to get us going.
|
||||
queueTaskMainLoop();
|
||||
|
||||
os_printf("Heap: %d\n", system_get_free_heap_size());
|
||||
return;
|
||||
} // End of initDone
|
||||
|
||||
|
||||
/**
|
||||
* This is a required function needed for ESP8266 SDK. In 99.999% of the instances, this function
|
||||
* needs to be present but have no body. It isn't 100% known what this function does other than
|
||||
* provide an architected callback during initializations. However, its purpose is unknown.
|
||||
*/
|
||||
void user_rf_pre_init() {
|
||||
} // End of user_rf_pre_init
|
||||
|
||||
|
||||
/**
|
||||
* \brief The main entry point in an ESP8266 application.
|
||||
* It is where the logic of ESP8266 starts.
|
||||
*/
|
||||
void user_init() {
|
||||
// Initialize the UART devices
|
||||
uart_init(BIT_RATE_115200, BIT_RATE_115200);
|
||||
os_delay_us(10000); // give the uart a break
|
||||
UART_SetPrintPort(1);
|
||||
system_set_os_print(1);
|
||||
os_printf("Heap: %d\n", system_get_free_heap_size());
|
||||
|
||||
// Dump the restart exception information.
|
||||
dumpRestart();
|
||||
|
||||
// Register the ESP8266 initialization callback.
|
||||
system_init_done_cb(initDone);
|
||||
|
||||
// Do NOT attempt to auto connect to an access point.
|
||||
//wifi_station_set_auto_connect(0);
|
||||
os_timer_setfn(&mainLoopSuspendTimer, enableMainLoop, NULL);
|
||||
} // End of user_init
|
||||
// End of file
|
||||
/*
|
||||
* This file is part of Espruino/ESP8266, a JavaScript interpreter for ESP8266
|
||||
*
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <user_interface.h>
|
||||
#include <osapi.h>
|
||||
#include <driver/uart.h>
|
||||
#include <telnet.h>
|
||||
#include <espmissingincludes.h>
|
||||
|
||||
//#define FAKE_STDLIB
|
||||
#define _GCC_WRAP_STDINT_H
|
||||
typedef long long int64_t;
|
||||
|
||||
#include <jsdevices.h>
|
||||
#include <jsinteractive.h>
|
||||
#include <jswrap_esp8266.h>
|
||||
#include "ESP8266_board.h"
|
||||
|
||||
// --- Constants
|
||||
// The size of the task queue
|
||||
#define TASK_QUEUE_LENGTH 10
|
||||
|
||||
// Should we introduce a ticker to say we are still alive?
|
||||
#define EPS8266_BOARD_HEARTBEAT
|
||||
|
||||
// --- Forward definitions
|
||||
static void mainLoop();
|
||||
|
||||
// --- File local variables
|
||||
|
||||
// The task queue for the app
|
||||
static os_event_t taskAppQueue[TASK_QUEUE_LENGTH];
|
||||
|
||||
// Flag indicating whether or not main loop processing is suspended.
|
||||
static bool suspendMainLoopFlag = false;
|
||||
|
||||
// Time structure for main loop time suspension.
|
||||
static os_timer_t mainLoopSuspendTimer;
|
||||
|
||||
// --- Functions
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* \brief A callback function to be invoked when a line has been entered on the telnet client.
|
||||
* Here we want to pass that line to the JS parser for processing.
|
||||
*/
|
||||
static void telnetLineCB(char *line) {
|
||||
jsiConsolePrintf("LineCB: %s", line);
|
||||
// Pass the line to the interactive module ...
|
||||
|
||||
jshPushIOCharEvents(jsiGetConsoleDevice(), line, strlen(line));
|
||||
//jspEvaluate(line, true);
|
||||
//jsiDumpState();
|
||||
telnet_send("JS> ");
|
||||
} // End of lineCB
|
||||
|
||||
|
||||
/**
|
||||
* When we have been allocated a TCP/IP address, this function is called back. Obviously
|
||||
* there is little we can do at the network level until we have an IP.
|
||||
*/
|
||||
static void gotIpCallback() {
|
||||
telnet_startListening(telnetLineCB);
|
||||
} // End of gotIpCallback
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Dump the ESP8266 restart information.
|
||||
* This is purely for debugging.
|
||||
* When an ESP8266 crashes, before it ends, it records its exception information.
|
||||
* This function retrieves that data and logs it.
|
||||
*/
|
||||
static void dumpRestart() {
|
||||
struct rst_info *rstInfo = system_get_rst_info();
|
||||
os_printf("Restart info:\n");
|
||||
os_printf(" reason: %d\n", rstInfo->reason);
|
||||
os_printf(" exccause: %x\n", rstInfo->exccause);
|
||||
os_printf(" epc1: %x\n", rstInfo->epc1);
|
||||
os_printf(" epc2: %x\n", rstInfo->epc2);
|
||||
os_printf(" epc3: %x\n", rstInfo->epc3);
|
||||
os_printf(" excvaddr: %x\n", rstInfo->excvaddr);
|
||||
os_printf(" depc: %x\n", rstInfo->depc);
|
||||
} // End of dump_restart
|
||||
|
||||
|
||||
/**
|
||||
* \brief Queue a task for the main loop.
|
||||
*/
|
||||
static void queueTaskMainLoop() {
|
||||
system_os_post(TASK_APP_QUEUE, TASK_APP_MAINLOOP, 0);
|
||||
} // End of queueMainLoop
|
||||
|
||||
|
||||
/**
|
||||
* \brief Suspend processing the main loop for a period of time.
|
||||
*/
|
||||
void suspendMainLoop(
|
||||
uint32 interval //!< suspension interval in milliseconds
|
||||
) {
|
||||
suspendMainLoopFlag = true;
|
||||
os_timer_arm(&mainLoopSuspendTimer, interval, 0 /* No repeat */);
|
||||
} // End of suspendMainLoop
|
||||
|
||||
|
||||
/**
|
||||
* \brief Enable main loop processing.
|
||||
*/
|
||||
static void enableMainLoop() {
|
||||
suspendMainLoopFlag = false;
|
||||
queueTaskMainLoop();
|
||||
} // End of enableMainLoop
|
||||
|
||||
|
||||
/**
|
||||
* \brief The event handler for ESP8266 tasks as created by system_os_post() on the TASK_APP_QUEUE.
|
||||
*/
|
||||
static void eventHandler(
|
||||
os_event_t *pEvent //!<
|
||||
) {
|
||||
|
||||
switch (pEvent->sig) {
|
||||
// Handle the main loop event.
|
||||
case TASK_APP_MAINLOOP:
|
||||
mainLoop();
|
||||
break;
|
||||
// Handle the event to process received data.
|
||||
case TASK_APP_RX_DATA:
|
||||
{
|
||||
// Get the data from the UART RX buffer. If the size of the returned data is
|
||||
// not zero, then push it onto the Espruino processing queue for characters.
|
||||
char pBuffer[100];
|
||||
int size = getRXBuffer(pBuffer, sizeof(pBuffer));
|
||||
if (size > 0) {
|
||||
jshPushIOCharEvents(jsiGetConsoleDevice(), pBuffer, size);
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Handle the unknown event type.
|
||||
default:
|
||||
os_printf("user_main: eventHandler: Unknown task type: %d",
|
||||
pEvent->sig);
|
||||
break;
|
||||
}
|
||||
} // End of eventHandler
|
||||
|
||||
|
||||
static uint32 lastTime = 0;
|
||||
|
||||
/**
|
||||
* \brief Perform the main loop processing.
|
||||
* This is where work is performed
|
||||
* as often as possible.
|
||||
*/
|
||||
static void mainLoop() {
|
||||
if (suspendMainLoopFlag == true) {
|
||||
return;
|
||||
}
|
||||
jsiLoop();
|
||||
|
||||
#ifdef EPS8266_BOARD_HEARTBEAT
|
||||
if (system_get_time() - lastTime > 1000 * 1000 * 5) {
|
||||
lastTime = system_get_time();
|
||||
os_printf("tick: %ld, heap: %ld\n",
|
||||
(uint32)(jshGetSystemTime()), system_get_free_heap_size());
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup for another callback
|
||||
//queueTaskMainLoop();
|
||||
suspendMainLoop(0); // HACK to get around SDK 1.4 bug
|
||||
} // End of mainLoop
|
||||
|
||||
|
||||
/**
|
||||
* The ESP8266 provides a mechanism to register a callback that is invoked when initialization
|
||||
* of the ESP8266 is complete. This is the implementation of that callback. At this point
|
||||
* we can assume that the ESP8266 is fully ready to do work for us.
|
||||
*/
|
||||
static void initDone() {
|
||||
os_printf("initDone invoked\n");
|
||||
|
||||
// Discard any junk data in the input as this is a boot.
|
||||
//uart_rx_discard();
|
||||
|
||||
jshInit(); // Initialize the hardware
|
||||
jsvInit(); // Initialize the variables
|
||||
jsiInit(false); // Initialize the interactive subsystem
|
||||
|
||||
// Register the event handlers.
|
||||
system_os_task(eventHandler, TASK_APP_QUEUE, taskAppQueue, TASK_QUEUE_LENGTH);
|
||||
|
||||
// At this point, our JavaScript environment should be up and running.
|
||||
|
||||
// Initialize the networking subsystem.
|
||||
jswrap_ESP8266WiFi_init();
|
||||
|
||||
// Post the first event to get us going.
|
||||
queueTaskMainLoop();
|
||||
|
||||
return;
|
||||
} // End of initDone
|
||||
|
||||
|
||||
/**
|
||||
* This is a required function needed for ESP8266 SDK. It allows RF parameters, in particular
|
||||
* whether to calibrate the RF, to be set before the SDK does the calibration, which happens
|
||||
* before user_init() is called.
|
||||
*/
|
||||
void user_rf_pre_init() {
|
||||
} // End of user_rf_pre_init
|
||||
|
||||
|
||||
/**
|
||||
* \brief The main entry point in an ESP8266 application.
|
||||
* It is where the logic of ESP8266 starts.
|
||||
*/
|
||||
void user_init() {
|
||||
// Initialize the UART devices
|
||||
uart_init(BIT_RATE_115200, BIT_RATE_115200);
|
||||
os_delay_us(10000); // give the uart a break
|
||||
UART_SetPrintPort(1);
|
||||
system_set_os_print(1);
|
||||
|
||||
// Dump the restart exception information.
|
||||
dumpRestart();
|
||||
os_printf("Heap: %d\n", system_get_free_heap_size());
|
||||
os_printf("Variables: %d @%dea = %ldbytes\n", JSVAR_CACHE_SIZE, sizeof(JsVar),
|
||||
JSVAR_CACHE_SIZE * sizeof(JsVar));
|
||||
|
||||
// Register the ESP8266 initialization callback.
|
||||
system_init_done_cb(initDone);
|
||||
|
||||
// Do NOT attempt to auto connect to an access point.
|
||||
//wifi_station_set_auto_connect(0);
|
||||
os_timer_setfn(&mainLoopSuspendTimer, enableMainLoop, NULL);
|
||||
} // End of user_init
|
||||
// End of file
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user