Bladeren bron

T4 - SerialX Support for Transmitter Enable

Used macros from OneWIre to fast set/clear the optional Transmitter Enable support.

Also fixed bug in ISR where was not properly looking for TC.  This will help make SerialX->flush() to work
teensy4-core
Kurt Eckhardt 6 jaren geleden
bovenliggende
commit
2209a9f01b
2 gewijzigde bestanden met toevoegingen van 23 en 9 verwijderingen
  1. +19
    -6
      teensy4/HardwareSerial.cpp
  2. +4
    -3
      teensy4/HardwareSerial.h

+ 19
- 6
teensy4/HardwareSerial.cpp Bestand weergeven

@@ -19,6 +19,18 @@
volatile uint32_t WATER;
} IMXRT_LPUART_t; */

//. From Onewire utility files
#define PIN_TO_BASEREG(pin) (portOutputRegister(pin))
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_BASE_ATTR
#define IO_REG_MASK_ATTR
#define DIRECT_READ(base, mask) ((*((base)+2) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask) (*((base)+1) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask) (*((base)+1) |= (mask))
#define DIRECT_WRITE_LOW(base, mask) (*((base)+34) = (mask))
#define DIRECT_WRITE_HIGH(base, mask) (*((base)+33) = (mask))

#define UART_CLOCK 24000000

#ifndef SERIAL1_TX_BUFFER_SIZE
@@ -150,9 +162,9 @@ void HardwareSerial::transmitterEnable(uint8_t pin)
{
while (transmitting_) ;
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
transmit_pin_ = pin; // BUGBUG - Faster way?
transmit_pin_baseReg_ = PIN_TO_BASEREG(pin);
transmit_pin_bitmask_ = PIN_TO_BITMASK(pin);
DIRECT_WRITE_LOW(transmit_pin_baseReg_, transmit_pin_bitmask_);
}

void HardwareSerial::setRX(uint8_t pin)
@@ -265,7 +277,7 @@ size_t HardwareSerial::write(uint8_t c)
uint32_t head, n;
//digitalWrite(3, HIGH);
//digitalWrite(5, HIGH);
// if (transmit_pin_) transmit_assert();
if (transmit_pin_baseReg_) DIRECT_WRITE_HIGH(transmit_pin_baseReg_, transmit_pin_bitmask_);
head = tx_buffer_head_;
if (++head >= tx_buffer_total_size_) head = 0;
while (tx_buffer_tail_ == head) {
@@ -359,10 +371,11 @@ void HardwareSerial::IRQHandler()
//digitalWrite(3, LOW);
}

if ((ctrl & LPUART_CTRL_TCIE) && (port->STAT & LPUART_STAT_TDRE))
if ((ctrl & LPUART_CTRL_TCIE) && (port->STAT & LPUART_STAT_TC))
{
transmitting_ = 0;
//if (transmit_pin_) transmit_deassert();
if (transmit_pin_baseReg_) DIRECT_WRITE_LOW(transmit_pin_baseReg_, transmit_pin_bitmask_);

port->CTRL = CTRL_TX_INACTIVE;
}
//digitalWrite(4, LOW);

+ 4
- 3
teensy4/HardwareSerial.h Bestand weergeven

@@ -127,11 +127,12 @@ private:
volatile uint16_t rx_buffer_tail_ = 0;

// Currently using digitalWWrite...
int transmit_pin_=-1;
volatile uint32_t *transmit_pin_baseReg_ = 0;
uint32_t transmit_pin_bitmask_ = 0;

//int transmit_pin_=-1;
int rts_pin_=-1;

inline void transmit_assert() {digitalWrite(transmit_pin_, 1);}
inline void transmit_deassert() {digitalWrite(transmit_pin_, 0);}
inline void rts_assert() {digitalWrite(rts_pin_ , 0); }
inline void rts_deassert() {digitalWrite(rts_pin_ , 1); }


Laden…
Annuleren
Opslaan