Просмотр исходного кода

Fix Hardware Serial transmitterEnable() on Teensy-LC

teensy4-core
PaulStoffregen 9 лет назад
Родитель
Сommit
6ed0c5f01f
3 измененных файлов: 47 добавлений и 11 удалений
  1. +16
    -4
      teensy3/serial1.c
  2. +16
    -4
      teensy3/serial2.c
  3. +15
    -3
      teensy3/serial3.c

+ 16
- 4
teensy3/serial1.c Просмотреть файл

@@ -56,7 +56,16 @@ static uint8_t use9Bits = 0;
static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE];
static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE];
static volatile uint8_t transmitting = 0;
static volatile uint8_t *transmit_pin=NULL;
#if defined(KINETISK)
static volatile uint8_t *transmit_pin=NULL;
#define transmit_assert() *transmit_pin = 1
#define transmit_deassert() *transmit_pin = 0
#elif defined(KINETISL)
static volatile uint8_t *transmit_pin=NULL;
static uint8_t transmit_mask=0;
#define transmit_assert() *(transmit_pin+4) = transmit_mask;
#define transmit_deassert() *(transmit_pin+8) = transmit_mask;
#endif
#if TX_BUFFER_SIZE > 255
static volatile uint16_t tx_buffer_head = 0;
static volatile uint16_t tx_buffer_tail = 0;
@@ -158,6 +167,9 @@ void serial_set_transmit_pin(uint8_t pin)
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
transmit_pin = portOutputRegister(pin);
#if defined(KINETISL)
transmit_mask = digitalPinToBitMask(pin);
#endif
}

void serial_putchar(uint32_t c)
@@ -165,7 +177,7 @@ void serial_putchar(uint32_t c)
uint32_t head, n;

if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return;
if (transmit_pin) *transmit_pin = 1;
if (transmit_pin) transmit_assert();
head = tx_buffer_head;
if (++head >= TX_BUFFER_SIZE) head = 0;
while (tx_buffer_tail == head) {
@@ -197,7 +209,7 @@ void serial_write(const void *buf, unsigned int count)
uint32_t head, n;

if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return;
if (transmit_pin) *transmit_pin = 1;
if (transmit_pin) transmit_assert();
while (p < end) {
head = tx_buffer_head;
if (++head >= TX_BUFFER_SIZE) head = 0;
@@ -395,7 +407,7 @@ void uart0_status_isr(void)
#endif
if ((c & UART_C2_TCIE) && (UART0_S1 & UART_S1_TC)) {
transmitting = 0;
if (transmit_pin) *transmit_pin = 0;
if (transmit_pin) transmit_deassert();
UART0_C2 = C2_TX_INACTIVE;
}
}

+ 16
- 4
teensy3/serial2.c Просмотреть файл

@@ -55,7 +55,16 @@ static uint8_t use9Bits = 0;
static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE];
static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE];
static volatile uint8_t transmitting = 0;
static volatile uint8_t *transmit_pin=NULL;
#if defined(KINETISK)
static volatile uint8_t *transmit_pin=NULL;
#define transmit_assert() *transmit_pin = 1
#define transmit_deassert() *transmit_pin = 0
#elif defined(KINETISL)
static volatile uint8_t *transmit_pin=NULL;
static uint8_t transmit_mask=0;
#define transmit_assert() *(transmit_pin+4) = transmit_mask;
#define transmit_deassert() *(transmit_pin+8) = transmit_mask;
#endif
#if TX_BUFFER_SIZE > 255
static volatile uint16_t tx_buffer_head = 0;
static volatile uint16_t tx_buffer_tail = 0;
@@ -163,6 +172,9 @@ void serial2_set_transmit_pin(uint8_t pin)
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
transmit_pin = portOutputRegister(pin);
#if defined(KINETISL)
transmit_mask = digitalPinToBitMask(pin);
#endif
}

void serial2_putchar(uint32_t c)
@@ -170,7 +182,7 @@ void serial2_putchar(uint32_t c)
uint32_t head, n;

if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return;
if (transmit_pin) *transmit_pin = 1;
if (transmit_pin) transmit_assert();
head = tx_buffer_head;
if (++head >= TX_BUFFER_SIZE) head = 0;
while (tx_buffer_tail == head) {
@@ -202,7 +214,7 @@ void serial2_write(const void *buf, unsigned int count)
uint32_t head, n;

if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return;
if (transmit_pin) *transmit_pin = 1;
if (transmit_pin) transmit_assert();
while (p < end) {
head = tx_buffer_head;
if (++head >= TX_BUFFER_SIZE) head = 0;
@@ -400,7 +412,7 @@ void uart1_status_isr(void)
#endif
if ((c & UART_C2_TCIE) && (UART1_S1 & UART_S1_TC)) {
transmitting = 0;
if (transmit_pin) *transmit_pin = 0;
if (transmit_pin) transmit_deassert();
UART1_C2 = C2_TX_INACTIVE;
}
}

+ 15
- 3
teensy3/serial3.c Просмотреть файл

@@ -56,7 +56,16 @@ static uint8_t use9Bits = 0;
static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE];
static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE];
static volatile uint8_t transmitting = 0;
static volatile uint8_t *transmit_pin=NULL;
#if defined(KINETISK)
static volatile uint8_t *transmit_pin=NULL;
#define transmit_assert() *transmit_pin = 1
#define transmit_deassert() *transmit_pin = 0
#elif defined(KINETISL)
static volatile uint8_t *transmit_pin=NULL;
static uint8_t transmit_mask=0;
#define transmit_assert() *(transmit_pin+4) = transmit_mask;
#define transmit_deassert() *(transmit_pin+8) = transmit_mask;
#endif
#if TX_BUFFER_SIZE > 255
static volatile uint16_t tx_buffer_head = 0;
static volatile uint16_t tx_buffer_tail = 0;
@@ -147,6 +156,9 @@ void serial3_set_transmit_pin(uint8_t pin)
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
transmit_pin = portOutputRegister(pin);
#if defined(KINETISL)
transmit_mask = digitalPinToBitMask(pin);
#endif
}

void serial3_putchar(uint32_t c)
@@ -154,7 +166,7 @@ void serial3_putchar(uint32_t c)
uint32_t head, n;

if (!(SIM_SCGC4 & SIM_SCGC4_UART2)) return;
if (transmit_pin) *transmit_pin = 1;
if (transmit_pin) transmit_assert();
head = tx_buffer_head;
if (++head >= TX_BUFFER_SIZE) head = 0;
while (tx_buffer_tail == head) {
@@ -281,7 +293,7 @@ void uart2_status_isr(void)
}
if ((c & UART_C2_TCIE) && (UART2_S1 & UART_S1_TC)) {
transmitting = 0;
if (transmit_pin) *transmit_pin = 0;
if (transmit_pin) transmit_deassert();
UART2_C2 = C2_TX_INACTIVE;
}
}

Загрузка…
Отмена
Сохранить