瀏覽代碼

T4 HardwareSerial - Fix SerialEventX code

I forgot to remove the default eventhandlers from some of the HardwareSerial files as such the ones in the serialEventX files was not used and why my flags were not set properly.

Could have done simple fix, but decide to make it more consistent with what I did in T3.x/LC code and not look through all the NULLS, but simply have list of active ones and count of active.

Appears to fix the issue so far.
main
Kurt Eckhardt 4 年之前
父節點
當前提交
0bf9e0f55c
共有 11 個文件被更改,包括 34 次插入118 次删除
  1. +10
    -33
      teensy4/HardwareSerial.cpp
  2. +14
    -8
      teensy4/HardwareSerial.h
  3. +1
    -5
      teensy4/HardwareSerial1.cpp
  4. +2
    -10
      teensy4/HardwareSerial2.cpp
  5. +1
    -9
      teensy4/HardwareSerial3.cpp
  6. +1
    -10
      teensy4/HardwareSerial4.cpp
  7. +1
    -12
      teensy4/HardwareSerial5.cpp
  8. +1
    -9
      teensy4/HardwareSerial6.cpp
  9. +1
    -11
      teensy4/HardwareSerial7.cpp
  10. +1
    -10
      teensy4/HardwareSerial8.cpp
  11. +1
    -1
      teensy4/yield.cpp

+ 10
- 33
teensy4/HardwareSerial.cpp 查看文件

@@ -67,11 +67,14 @@ extern "C" {
}

#if defined(ARDUINO_TEENSY41)
SerialEventCheckingFunctionPointer HardwareSerial::serial_event_handler_checks[8] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
HardwareSerial *HardwareSerial::s_serials_with_serial_events[8];
#else
SerialEventCheckingFunctionPointer HardwareSerial::serial_event_handler_checks[7] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
HardwareSerial *HardwareSerial::s_serials_with_serial_events[7];
#endif
uint8_t HardwareSerial::serial_event_handlers_active = 0;

// define our static objects
uint8_t HardwareSerial::s_count_serials_with_serial_events = 0;



#define CTRL_ENABLE (LPUART_CTRL_TE | LPUART_CTRL_RE | LPUART_CTRL_RIE | LPUART_CTRL_ILIE)
@@ -198,7 +201,7 @@ void HardwareSerial::begin(uint32_t baud, uint16_t format)

//Serial.printf(" stat:%x ctrl:%x fifo:%x water:%x\n", port->STAT, port->CTRL, port->FIFO, port->WATER );
// Only if the user implemented their own...
if (!(*hardware->serial_event_handler_default)) enableSerialEvents(); // Enable the processing of serialEvent for this object
if (!(*hardware->serial_event_handler_default)) addToSerialEventsList(); // Enable the processing of serialEvent for this object
};

inline void HardwareSerial::rts_assert()
@@ -228,7 +231,6 @@ void HardwareSerial::end(void)
rx_buffer_tail_ = 0;
if (rts_pin_baseReg_) rts_deassert();
//
disableSerialEvents(); // disable the processing of serialEvent for this object
}

void HardwareSerial::transmitterEnable(uint8_t pin)
@@ -602,34 +604,9 @@ void HardwareSerial::IRQHandler()
}


void HardwareSerial::processSerialEvents()
{
if (!serial_event_handlers_active) return; // bail quick if no one processing SerialEvents.
uint8_t handlers_still_to_process = serial_event_handlers_active;
for (uint8_t i = 0; i < 8; i++) {
if (serial_event_handler_checks[i]) {
(*serial_event_handler_checks[i])();
if (--handlers_still_to_process == 0) return;
}
}
}

void HardwareSerial::enableSerialEvents()
{
if (!serial_event_handler_checks[hardware->serial_index]) {
serial_event_handler_checks[hardware->serial_index] = hardware->serial_event_handler_check; // clear it out
serial_event_handlers_active++;
yield_active_check_flags |= YIELD_CHECK_HARDWARE_SERIAL;
}
}

void HardwareSerial::disableSerialEvents()
{
if (serial_event_handler_checks[hardware->serial_index]) {
serial_event_handler_checks[hardware->serial_index] = nullptr; // clear it out
serial_event_handlers_active--;
if (!serial_event_handlers_active) yield_active_check_flags &= ~YIELD_CHECK_HARDWARE_SERIAL;
}
void HardwareSerial::addToSerialEventsList() {
s_serials_with_serial_events[s_count_serials_with_serial_events++] = this;
yield_active_check_flags |= YIELD_CHECK_HARDWARE_SERIAL;
}



+ 14
- 8
teensy4/HardwareSerial.h 查看文件

@@ -142,8 +142,6 @@ extern const pin_to_xbar_info_t pin_to_xbar_info[];
extern const uint8_t count_pin_to_xbar_info;


typedef void(*SerialEventCheckingFunctionPointer)();

class HardwareSerial : public Stream
{
public:
@@ -160,7 +158,7 @@ public:
uint8_t serial_index; // which object are we? 0 based
IRQ_NUMBER_t irq;
void (*irq_handler)(void);
void (*serial_event_handler_check)(void);
void (* _serialEvent)(void);
const uint8_t *serial_event_handler_default;
volatile uint32_t &ccm_register;
const uint32_t ccm_value;
@@ -202,9 +200,6 @@ public:
size_t write9bit(uint32_t c);
// Event Handler functions and data
void enableSerialEvents();
void disableSerialEvents();
static void processSerialEvents();
static uint8_t serial_event_handlers_active;

using Print::write;
@@ -223,6 +218,12 @@ public:
*/

operator bool() { return true; }

static inline void processSerialEventsList() {
for (uint8_t i = 0; i < s_count_serials_with_serial_events; i++) {
s_serials_with_serial_events[i]->doYieldCode();
}
}
private:
IMXRT_LPUART_t * const port;
const hardware_t * const hardware;
@@ -264,10 +265,15 @@ private:
friend void IRQHandler_Serial7();
#if defined(ARDUINO_TEENSY41)
friend void IRQHandler_Serial8();
static SerialEventCheckingFunctionPointer serial_event_handler_checks[8];
static HardwareSerial *s_serials_with_serial_events[8];
#else
static SerialEventCheckingFunctionPointer serial_event_handler_checks[7];
static HardwareSerial *s_serials_with_serial_events[7];
#endif
static uint8_t s_count_serials_with_serial_events;
void addToSerialEventsList();
inline void doYieldCode() {
if (available()) (*hardware->_serialEvent)();
}




+ 1
- 5
teensy4/HardwareSerial1.cpp 查看文件

@@ -45,10 +45,6 @@ void IRQHandler_Serial1()
Serial1.IRQHandler();
}

void serial_event_check_serial1()
{
if (Serial1.available()) serialEvent1();
}

// Serial1
static BUFTYPE tx_buffer1[SERIAL1_TX_BUFFER_SIZE];
@@ -57,7 +53,7 @@ uint8_t _serialEvent1_default __attribute__((weak)) PROGMEM = 0 ;

const HardwareSerial::hardware_t UART6_Hardware = {
0, IRQ_LPUART6, &IRQHandler_Serial1,
&serial_event_check_serial1, &_serialEvent1_default,
&serialEvent1, &_serialEvent1_default,
CCM_CCGR3, CCM_CCGR3_LPUART6(CCM_CCGR_ON),
#if defined(ARDUINO_TEENSY41)
{{0,2, &IOMUXC_LPUART6_RX_SELECT_INPUT, 1}, {52, 2, &IOMUXC_LPUART6_RX_SELECT_INPUT, 0}},

+ 2
- 10
teensy4/HardwareSerial2.cpp 查看文件

@@ -45,20 +45,16 @@ void IRQHandler_Serial2()
Serial2.IRQHandler();
}

void serial_event_check_serial2()
{
if (Serial2.available()) serialEvent2();
}


// Serial2
static BUFTYPE tx_buffer2[SERIAL2_TX_BUFFER_SIZE];
static BUFTYPE rx_buffer2[SERIAL2_RX_BUFFER_SIZE];

uint8_t _serialEvent2_default __attribute__((weak)) PROGMEM = 0 ;

static HardwareSerial::hardware_t UART4_Hardware = {
1, IRQ_LPUART4, &IRQHandler_Serial2,
&serial_event_check_serial2, &_serialEvent2_default,
&serialEvent2, &_serialEvent2_default,
CCM_CCGR1, CCM_CCGR1_LPUART4(CCM_CCGR_ON),
#if defined(__IMXRT1052__)
{{6,2, &IOMUXC_LPUART4_RX_SELECT_INPUT, 2}, {0xff, 0xff, nullptr, 0}},
@@ -74,7 +70,3 @@ static HardwareSerial::hardware_t UART4_Hardware = {
};
HardwareSerial Serial2(&IMXRT_LPUART4, &UART4_Hardware, tx_buffer2, SERIAL2_TX_BUFFER_SIZE,
rx_buffer2, SERIAL2_RX_BUFFER_SIZE);


void serialEvent2() __attribute__((weak));
void serialEvent2() {Serial2.disableSerialEvents(); } // No use calling this so disable if called...

+ 1
- 9
teensy4/HardwareSerial3.cpp 查看文件

@@ -44,11 +44,6 @@ void IRQHandler_Serial3()
Serial3.IRQHandler();
}

void serial_event_check_serial3()
{
if (Serial3.available()) serialEvent3();
}

// Serial3
static BUFTYPE tx_buffer3[SERIAL3_TX_BUFFER_SIZE];
static BUFTYPE rx_buffer3[SERIAL3_RX_BUFFER_SIZE];
@@ -56,7 +51,7 @@ uint8_t _serialEvent3_default __attribute__((weak)) PROGMEM = 0 ;

static HardwareSerial::hardware_t UART2_Hardware = {
2, IRQ_LPUART2, &IRQHandler_Serial3,
&serial_event_check_serial3, &_serialEvent3_default,
&serialEvent3, &_serialEvent3_default,
CCM_CCGR0, CCM_CCGR0_LPUART2(CCM_CCGR_ON),
{{15,2, &IOMUXC_LPUART2_RX_SELECT_INPUT, 1}, {0xff, 0xff, nullptr, 0}},
{{14,2, &IOMUXC_LPUART2_TX_SELECT_INPUT, 1}, {0xff, 0xff, nullptr, 0}},
@@ -68,6 +63,3 @@ static HardwareSerial::hardware_t UART2_Hardware = {
HardwareSerial Serial3(&IMXRT_LPUART2, &UART2_Hardware,tx_buffer3, SERIAL3_TX_BUFFER_SIZE,
rx_buffer3, SERIAL3_RX_BUFFER_SIZE);

void serialEvent3() __attribute__((weak));
void serialEvent3() {Serial3.disableSerialEvents(); } // No use calling this so disable if called...


+ 1
- 10
teensy4/HardwareSerial4.cpp 查看文件

@@ -45,11 +45,6 @@ void IRQHandler_Serial4()
Serial4.IRQHandler();
}

void serial_event_check_serial4()
{
if (Serial4.available()) serialEvent4();
}

// Serial4
static BUFTYPE tx_buffer4[SERIAL4_TX_BUFFER_SIZE];
static BUFTYPE rx_buffer4[SERIAL4_RX_BUFFER_SIZE];
@@ -57,7 +52,7 @@ uint8_t _serialEvent4_default __attribute__((weak)) PROGMEM = 0 ;

static HardwareSerial::hardware_t UART3_Hardware = {
3, IRQ_LPUART3, &IRQHandler_Serial4,
&serial_event_check_serial4, &_serialEvent4_default,
&serialEvent4, &_serialEvent4_default,
CCM_CCGR0, CCM_CCGR0_LPUART3(CCM_CCGR_ON),
{{16,2, &IOMUXC_LPUART3_RX_SELECT_INPUT, 0}, {0xff, 0xff, nullptr, 0}},
{{17,2, &IOMUXC_LPUART3_TX_SELECT_INPUT, 0}, {0xff, 0xff, nullptr, 0}},
@@ -68,7 +63,3 @@ static HardwareSerial::hardware_t UART3_Hardware = {
};
HardwareSerial Serial4(&IMXRT_LPUART3, &UART3_Hardware, tx_buffer4, SERIAL4_TX_BUFFER_SIZE,
rx_buffer4, SERIAL4_RX_BUFFER_SIZE);


void serialEvent4() __attribute__((weak));
void serialEvent4() {Serial4.disableSerialEvents(); } // No use calling this so disable if called...

+ 1
- 12
teensy4/HardwareSerial5.cpp 查看文件

@@ -44,12 +44,6 @@ void IRQHandler_Serial5()
{
Serial5.IRQHandler();
}

void serial_event_check_serial5()
{
if (Serial5.available()) serialEvent5();
}

// Serial5
static BUFTYPE tx_buffer5[SERIAL5_TX_BUFFER_SIZE];
static BUFTYPE rx_buffer5[SERIAL5_RX_BUFFER_SIZE];
@@ -57,7 +51,7 @@ uint8_t _serialEvent5_default __attribute__((weak)) PROGMEM = 0 ;

static HardwareSerial::hardware_t UART8_Hardware = {
4, IRQ_LPUART8, &IRQHandler_Serial5,
&serial_event_check_serial5, &_serialEvent5_default,
&serialEvent5, &_serialEvent5_default,
CCM_CCGR6, CCM_CCGR6_LPUART8(CCM_CCGR_ON),
#if defined(ARDUINO_TEENSY41)
{{21,2, &IOMUXC_LPUART8_RX_SELECT_INPUT, 1}, {46, 2, &IOMUXC_LPUART8_RX_SELECT_INPUT, 0}},
@@ -75,8 +69,3 @@ static HardwareSerial::hardware_t UART8_Hardware = {
};
HardwareSerial Serial5(&IMXRT_LPUART8, &UART8_Hardware, tx_buffer5, SERIAL5_TX_BUFFER_SIZE,
rx_buffer5, SERIAL5_RX_BUFFER_SIZE);



void serialEvent5() __attribute__((weak));
void serialEvent5() {Serial5.disableSerialEvents(); } // No use calling this so disable if called...

+ 1
- 9
teensy4/HardwareSerial6.cpp 查看文件

@@ -44,11 +44,6 @@ void IRQHandler_Serial6()
Serial6.IRQHandler();
}

void serial_event_check_serial6()
{
if (Serial6.available()) serialEvent6();
}


// Serial6
static BUFTYPE tx_buffer6[SERIAL6_TX_BUFFER_SIZE];
@@ -57,7 +52,7 @@ uint8_t _serialEvent6_default __attribute__((weak)) PROGMEM = 0 ;

static HardwareSerial::hardware_t UART1_Hardware = {
5, IRQ_LPUART1, &IRQHandler_Serial6,
&serial_event_check_serial6, &_serialEvent6_default,
&serialEvent6, &_serialEvent6_default,
CCM_CCGR5, CCM_CCGR5_LPUART1(CCM_CCGR_ON),
{{25,2, nullptr, 0}, {0xff, 0xff, nullptr, 0}},
{{24,2, nullptr, 0}, {0xff, 0xff, nullptr, 0}},
@@ -69,6 +64,3 @@ static HardwareSerial::hardware_t UART1_Hardware = {

HardwareSerial Serial6(&IMXRT_LPUART1, &UART1_Hardware, tx_buffer6, SERIAL6_TX_BUFFER_SIZE,
rx_buffer6, SERIAL6_RX_BUFFER_SIZE);

void serialEvent6() __attribute__((weak));
void serialEvent6() {Serial6.disableSerialEvents(); } // No use calling this so disable if called...

+ 1
- 11
teensy4/HardwareSerial7.cpp 查看文件

@@ -44,12 +44,6 @@ void IRQHandler_Serial7()
Serial7.IRQHandler();
}

void serial_event_check_serial7()
{
if (Serial7.available()) serialEvent7();
}


// Serial7
static BUFTYPE tx_buffer7[SERIAL7_TX_BUFFER_SIZE];
static BUFTYPE rx_buffer7[SERIAL7_RX_BUFFER_SIZE];
@@ -57,7 +51,7 @@ uint8_t _serialEvent7_default __attribute__((weak)) PROGMEM = 0 ;

static HardwareSerial::hardware_t UART7_Hardware = {
6, IRQ_LPUART7, &IRQHandler_Serial7,
&serial_event_check_serial7, &_serialEvent7_default,
&serialEvent7, &_serialEvent7_default,
CCM_CCGR5, CCM_CCGR5_LPUART7(CCM_CCGR_ON),
{{28,2, &IOMUXC_LPUART7_RX_SELECT_INPUT, 1}, {0xff, 0xff, nullptr, 0}},
{{29,2, &IOMUXC_LPUART7_TX_SELECT_INPUT, 1}, {0xff, 0xff, nullptr, 0}},
@@ -68,7 +62,3 @@ static HardwareSerial::hardware_t UART7_Hardware = {
};
HardwareSerial Serial7(&IMXRT_LPUART7, &UART7_Hardware, tx_buffer7, SERIAL7_TX_BUFFER_SIZE,
rx_buffer7, SERIAL7_RX_BUFFER_SIZE);


void serialEvent7() __attribute__((weak));
void serialEvent7() {Serial7.disableSerialEvents(); } // No use calling this so disable if called...

+ 1
- 10
teensy4/HardwareSerial8.cpp 查看文件

@@ -45,12 +45,6 @@ void IRQHandler_Serial8()
Serial8.IRQHandler();
}

void serial_event_check_serial8()
{
if (Serial8.available()) serialEvent8();
}



// Serial8
static BUFTYPE tx_buffer8[SERIAL8_TX_BUFFER_SIZE];
@@ -59,7 +53,7 @@ uint8_t _serialEvent8_default __attribute__((weak)) PROGMEM = 0 ;

static HardwareSerial::hardware_t UART5_Hardware = {
7, IRQ_LPUART5, &IRQHandler_Serial8,
&serial_event_check_serial8, &_serialEvent8_default,
&serialEvent8, &_serialEvent8_default,
CCM_CCGR3, CCM_CCGR3_LPUART5(CCM_CCGR_ON),
{{34,1, &IOMUXC_LPUART5_RX_SELECT_INPUT, 1}, {48, 2, &IOMUXC_LPUART5_RX_SELECT_INPUT, 0}},
{{35,1, &IOMUXC_LPUART5_TX_SELECT_INPUT, 1}, {0xff, 0xff, nullptr, 0}},
@@ -71,7 +65,4 @@ static HardwareSerial::hardware_t UART5_Hardware = {
};
HardwareSerial Serial8(&IMXRT_LPUART5, &UART5_Hardware, tx_buffer8, SERIAL8_TX_BUFFER_SIZE,
rx_buffer8, SERIAL8_RX_BUFFER_SIZE);

void serialEvent8() __attribute__((weak));
void serialEvent8() {Serial8.disableSerialEvents(); } // No use calling this so disable if called...
#endif

+ 1
- 1
teensy4/yield.cpp 查看文件

@@ -50,7 +50,7 @@ void yield(void)
}

// Current workaround until integrate with EventResponder.
if (yield_active_check_flags & YIELD_CHECK_HARDWARE_SERIAL) HardwareSerial::processSerialEvents();
if (yield_active_check_flags & YIELD_CHECK_HARDWARE_SERIAL) HardwareSerial::processSerialEventsList();

running = 0;
if (yield_active_check_flags & YIELD_CHECK_EVENT_RESPONDER) EventResponder::runFromYield();

Loading…
取消
儲存