Skip to content

Commit

Permalink
re-fix ESP serial driver bypass #1226
Browse files Browse the repository at this point in the history
  • Loading branch information
phoddie committed Oct 3, 2023
1 parent fd201b4 commit 241bd4b
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions modules/io/serial/esp32/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//#include "soc/uart_caps.h"
#include "soc/uart_struct.h"

#if 0
// local versions of UART register management to avoid issues with uart.c
#define uart_disable_intr_mask(dev, disable_mask) _uart_disable_intr_mask(dev, disable_mask)
#define uart_enable_intr_mask(dev, enable_mask) _uart_enable_intr_mask(dev, enable_mask)
Expand All @@ -55,7 +54,6 @@ static void _uart_enable_rx_intr(uart_dev_t *dev);
static void _uart_disable_rx_intr(uart_dev_t *dev);
static void _uart_disable_tx_intr(uart_dev_t *dev);
static void _uart_enable_tx_intr(uart_dev_t *dev, int enable, int thresh);
#endif

typedef struct SerialRecord SerialRecord;
typedef struct SerialRecord *Serial;
Expand Down Expand Up @@ -151,7 +149,6 @@ void xs_serial_constructor(xsMachine *the)
uartConfig.stop_bits = UART_STOP_BITS_1;
uartConfig.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
uartConfig.rx_flow_ctrl_thresh = 120; // unused. no hardware flow control.
// uartConfig.use_ref_tick = 0; // deprecated in 4.x

err = uart_param_config(uart, &uartConfig);
if (err)
Expand Down Expand Up @@ -197,21 +194,21 @@ void xs_serial_constructor(xsMachine *the)
if (hasReadable) {
serial->onReadable = onReadable;

uart_enable_rx_intr(serial->uart);
uart_enable_rx_intr(serial->uart_reg);
uart_set_rx_timeout(serial->uart, 4);
}
else {
uart_disable_rx_intr(serial->uart);
uart_disable_rx_intr(serial->uart_reg);
serial->onReadable = NULL;
}

if (hasWritable) {
serial->onWritable = onWritable;

uart_enable_tx_intr(serial->uart, 1, kTransmitTreshold);
uart_enable_tx_intr(serial->uart_reg, 1, kTransmitTreshold);
}
else {
uart_disable_tx_intr(serial->uart);
uart_disable_tx_intr(serial->uart_reg);
serial->onWritable = NULL;
}
}
Expand All @@ -229,8 +226,8 @@ void xs_serial_destructor(void *data)
Serial serial = data;
if (!serial) return;

uart_disable_tx_intr(serial->uart);
uart_disable_rx_intr(serial->uart);
uart_disable_tx_intr(serial->uart_reg);
uart_disable_rx_intr(serial->uart_reg);

// uart_isr_free(serial->uart);

Expand Down Expand Up @@ -315,7 +312,7 @@ void xs_serial_read(xsMachine *the)
}

if (serial->onReadable)
uart_enable_rx_intr(serial->uart);
uart_enable_rx_intr(serial->uart_reg);
}

void xs_serial_write(xsMachine *the)
Expand Down Expand Up @@ -345,7 +342,7 @@ void xs_serial_write(xsMachine *the)

if (serial->onWritable && !serial->txInterruptEnabled) {
serial->txInterruptEnabled = 1;
uart_enable_tx_intr(serial->uart, 1, kTransmitTreshold);
uart_enable_tx_intr(serial->uart_reg, 1, kTransmitTreshold);
}
}

Expand All @@ -367,13 +364,13 @@ void ICACHE_RAM_ATTR serial_isr(void * arg)
post |= (0 == serial->isWritable);
serial->isWritable = 1;
serial->txInterruptEnabled = 0;
uart_disable_tx_intr(serial->uart);
uart_disable_tx_intr(serial->uart_reg);
}

if ((status & (UART_INTR_RXFIFO_TOUT | UART_INTR_RXFIFO_FULL)) && serial->onReadable) {
post |= (0 == serial->isReadable);
serial->isReadable = 1;
uart_disable_rx_intr(serial->uart);
uart_disable_rx_intr(serial->uart_reg);
}

if (post) {
Expand Down Expand Up @@ -402,7 +399,7 @@ void serialDeliver(void *theIn, void *refcon, uint8_t *message, uint16_t message
xsCallFunction1(xsReference(serial->onReadable), serial->obj, xsResult);
xsEndHost(the);
}
uart_enable_rx_intr(serial->uart);
uart_enable_rx_intr(serial->uart_reg);
}

if (serial->isWritable) {
Expand Down Expand Up @@ -439,8 +436,6 @@ void xs_serial_mark(xsMachine* the, void* it, xsMarkRoot markRoot)
https://github.com/Moddable-OpenSource/moddable/issues/931
*/

#if 0

static portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;

void _uart_disable_intr_mask(uart_dev_t *dev, uint32_t disable_mask)
Expand Down Expand Up @@ -487,5 +482,3 @@ void _uart_enable_tx_intr(uart_dev_t *dev, int enable, int thresh)
portEXIT_CRITICAL(&spinlock);
}
}

#endif

0 comments on commit 241bd4b

Please sign in to comment.