fine-tuned upload system
This commit is contained in:
+30
-1
@@ -7,6 +7,7 @@
|
||||
#include "uart_buffer.h"
|
||||
#include "ansi_parser.h"
|
||||
#include "jstring.h"
|
||||
#include "uart_driver.h"
|
||||
|
||||
// Heartbeat interval in ms
|
||||
#define HB_TIME 1000
|
||||
@@ -18,6 +19,8 @@
|
||||
volatile bool notify_available = true;
|
||||
volatile bool notify_cooldown = false;
|
||||
|
||||
volatile bool browser_wants_xon = false;
|
||||
|
||||
static ETSTimer notifyContentTim;
|
||||
static ETSTimer notifyLabelsTim;
|
||||
static ETSTimer notifyCooldownTim;
|
||||
@@ -224,11 +227,20 @@ void ICACHE_FLASH_ATTR updateSockRx(Websock *ws, char *data, int len, int flags)
|
||||
case 's':
|
||||
// pass string verbatim
|
||||
if (termconf_scratch.loopback) {
|
||||
for (int i = 1; i < strlen(data); i++) {
|
||||
for (int i = 1; i < len; i++) {
|
||||
ansi_parser(data[i]);
|
||||
}
|
||||
}
|
||||
UART_SendAsync(data+1, -1);
|
||||
|
||||
// TODO base this on the actual buffer empty space, not rx chunk size
|
||||
if ((UART_AsyncTxGetEmptySpace() < 256) && !browser_wants_xon) {
|
||||
UART_WriteChar(UART1, '-', 100);
|
||||
cgiWebsockBroadcast(URL_WS_UPDATE, "-", 1, 0);
|
||||
browser_wants_xon = true;
|
||||
|
||||
system_soft_wdt_feed();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
@@ -276,3 +288,20 @@ void ICACHE_FLASH_ATTR updateSockConnect(Websock *ws)
|
||||
|
||||
TIMER_START(&heartbeatTim, heartbeatTimCb, HB_TIME, 1);
|
||||
}
|
||||
|
||||
ETSTimer xonTim;
|
||||
|
||||
void ICACHE_FLASH_ATTR notify_empty_txbuf_cb(void *unused)
|
||||
{
|
||||
UART_WriteChar(UART1, '+', 100);
|
||||
cgiWebsockBroadcast(URL_WS_UPDATE, "+", 1, 0);
|
||||
browser_wants_xon = false;
|
||||
}
|
||||
|
||||
|
||||
void notify_empty_txbuf(void)
|
||||
{
|
||||
if (browser_wants_xon) {
|
||||
TIMER_START(&xonTim, notify_empty_txbuf_cb, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
/** Update websocket connect callback */
|
||||
void updateSockConnect(Websock *ws);
|
||||
|
||||
void notify_empty_txbuf(void);
|
||||
|
||||
void send_beep(void);
|
||||
|
||||
// defined in the makefile
|
||||
|
||||
+28
-11
@@ -8,8 +8,8 @@
|
||||
#include <esp8266.h>
|
||||
#include <uart_register.h>
|
||||
|
||||
#define UART_TX_BUFFER_SIZE 256 //Ring buffer length of tx buffer
|
||||
#define UART_RX_BUFFER_SIZE 512 //Ring buffer length of rx buffer
|
||||
#define UART_TX_BUFFER_SIZE 1024 //Ring buffer length of tx buffer
|
||||
#define UART_RX_BUFFER_SIZE 1024 //Ring buffer length of rx buffer
|
||||
|
||||
struct UartBuffer {
|
||||
uint32 UartBuffSize;
|
||||
@@ -177,6 +177,11 @@ void UART_RxFifoCollect(void)
|
||||
}
|
||||
}
|
||||
|
||||
u16 ICACHE_FLASH_ATTR UART_AsyncTxGetEmptySpace(void)
|
||||
{
|
||||
return pTxBuffer->Space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule data to be sent
|
||||
* @param pdata
|
||||
@@ -227,7 +232,7 @@ static void UART_TxFifoEnq(struct UartBuffer *pTxBuff, uint8 data_len, uint8 uar
|
||||
pTxBuff->Space += data_len;
|
||||
}
|
||||
|
||||
|
||||
volatile bool next_empty_it_only_for_notify = false;
|
||||
/******************************************************************************
|
||||
* FunctionName : TxFromBuffer
|
||||
* Description : get data from the tx buffer and fill the uart tx fifo, co-work with the uart fifo empty interrupt
|
||||
@@ -242,16 +247,28 @@ void UART_DispatchFromTxBuffer(uint8 uart_no)
|
||||
uint16 data_len;
|
||||
|
||||
// if (pTxBuffer) {
|
||||
data_len = (uint8) (pTxBuffer->UartBuffSize - pTxBuffer->Space);
|
||||
if (data_len > fifo_remain) {
|
||||
len_tmp = fifo_remain;
|
||||
UART_TxFifoEnq(pTxBuffer, len_tmp, uart_no);
|
||||
data_len = (uint8) (pTxBuffer->UartBuffSize - pTxBuffer->Space);
|
||||
if (data_len > fifo_remain) {
|
||||
len_tmp = fifo_remain;
|
||||
UART_TxFifoEnq(pTxBuffer, len_tmp, uart_no);
|
||||
SET_PERI_REG_MASK(UART_INT_ENA(UART0), UART_TXFIFO_EMPTY_INT_ENA);
|
||||
}
|
||||
else {
|
||||
len_tmp = (uint8) data_len;
|
||||
UART_TxFifoEnq(pTxBuffer, len_tmp, uart_no);
|
||||
|
||||
// we get one more IT after fifo ends even if we have 0 more bytes
|
||||
// for notify
|
||||
if (next_empty_it_only_for_notify) {
|
||||
notify_empty_txbuf();
|
||||
next_empty_it_only_for_notify = 0;
|
||||
} else {
|
||||
// Done sending
|
||||
next_empty_it_only_for_notify = 1;
|
||||
SET_PERI_REG_MASK(UART_INT_ENA(UART0), UART_TXFIFO_EMPTY_INT_ENA);
|
||||
}
|
||||
else {
|
||||
len_tmp = (uint8) data_len;
|
||||
UART_TxFifoEnq(pTxBuffer, len_tmp, uart_no);
|
||||
}
|
||||
}
|
||||
|
||||
// }
|
||||
// else {
|
||||
// error("pTxBuff null \n\r");
|
||||
|
||||
@@ -23,4 +23,8 @@ void UART_DispatchFromTxBuffer(uint8 uart_no);
|
||||
|
||||
u16 UART_AsyncRxCount(void);
|
||||
|
||||
u16 UART_AsyncTxGetEmptySpace(void);
|
||||
|
||||
extern void __attribute__((weak)) notify_empty_txbuf(void);
|
||||
|
||||
#endif //ESP_VT100_FIRMWARE_UART_BUFFER_H
|
||||
|
||||
Reference in New Issue
Block a user