Browse Source

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 years ago
parent
commit
2209a9f01b
2 changed files with 23 additions and 9 deletions
  1. +19
    -6
      teensy4/HardwareSerial.cpp
  2. +4
    -3
      teensy4/HardwareSerial.h

+ 19
- 6
teensy4/HardwareSerial.cpp View File

volatile uint32_t WATER; volatile uint32_t WATER;
} IMXRT_LPUART_t; */ } 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 #define UART_CLOCK 24000000


#ifndef SERIAL1_TX_BUFFER_SIZE #ifndef SERIAL1_TX_BUFFER_SIZE
{ {
while (transmitting_) ; while (transmitting_) ;
pinMode(pin, OUTPUT); 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) void HardwareSerial::setRX(uint8_t pin)
uint32_t head, n; uint32_t head, n;
//digitalWrite(3, HIGH); //digitalWrite(3, HIGH);
//digitalWrite(5, 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_; head = tx_buffer_head_;
if (++head >= tx_buffer_total_size_) head = 0; if (++head >= tx_buffer_total_size_) head = 0;
while (tx_buffer_tail_ == head) { while (tx_buffer_tail_ == head) {
//digitalWrite(3, LOW); //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; 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; port->CTRL = CTRL_TX_INACTIVE;
} }
//digitalWrite(4, LOW); //digitalWrite(4, LOW);

+ 4
- 3
teensy4/HardwareSerial.h View File

volatile uint16_t rx_buffer_tail_ = 0; volatile uint16_t rx_buffer_tail_ = 0;


// Currently using digitalWWrite... // 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; 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_assert() {digitalWrite(rts_pin_ , 0); }
inline void rts_deassert() {digitalWrite(rts_pin_ , 1); } inline void rts_deassert() {digitalWrite(rts_pin_ , 1); }



Loading…
Cancel
Save