Browse Source

Try using BITBAND to turn on/off TIE and TCIE

Make update of these flags be hopefully interrupt safe
teensy4-core
Kurt Eckhardt 8 years ago
parent
commit
d2f9acc78c
1 changed files with 17 additions and 4 deletions
  1. +17
    -4
      teensy3/serial6_lpuart.c

+ 17
- 4
teensy3/serial6_lpuart.c View File



#ifdef HAS_KINETISK_LPUART0 #ifdef HAS_KINETISK_LPUART0


#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
#define GPIO_BITBAND_PTR(reg, bit) ((uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
#define BITBAND_SET_BIT(reg, bit) (*GPIO_BITBAND_PTR((reg), (bit)) = 1)
#define BITBAND_CLR_BIT(reg, bit) (*GPIO_BITBAND_PTR((reg), (bit)) = 0)
#define TCIE_BIT 22
#define TIE_BIT 23



//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Tunable parameters (relatively safe to edit these numbers) // Tunable parameters (relatively safe to edit these numbers)
tx_buffer[head] = c; tx_buffer[head] = c;
transmitting = 1; transmitting = 1;
tx_buffer_head = head; tx_buffer_head = head;
LPUART0_CTRL |= LPUART_CTRL_TIE; // enable the transmit interrupt

//LPUART0_CTRL |= LPUART_CTRL_TIE; // enable the transmit interrupt
BITBAND_SET_BIT(LPUART0_CTRL, TIE_BIT);

} }


void serial6_write(const void *buf, unsigned int count) void serial6_write(const void *buf, unsigned int count)
head = tx_buffer_head; head = tx_buffer_head;
tail = tx_buffer_tail; tail = tx_buffer_tail;
if (head == tail) { if (head == tail) {
LPUART0_CTRL &= ~LPUART_CTRL_TIE;
LPUART0_CTRL |= LPUART_CTRL_TCIE; // Actually wondering if we can just leave this one on...
BITBAND_CLR_BIT(LPUART0_CTRL, TIE_BIT);
BITBAND_SET_BIT(LPUART0_CTRL, TCIE_BIT);
//LPUART0_CTRL &= ~LPUART_CTRL_TIE;
//LPUART0_CTRL |= LPUART_CTRL_TCIE; // Actually wondering if we can just leave this one on...
} else { } else {
if (++tail >= TX_BUFFER_SIZE) tail = 0; if (++tail >= TX_BUFFER_SIZE) tail = 0;
n = tx_buffer[tail]; n = tx_buffer[tail];
if ((c & LPUART_CTRL_TCIE) && (LPUART0_STAT & LPUART_STAT_TC)) { if ((c & LPUART_CTRL_TCIE) && (LPUART0_STAT & LPUART_STAT_TC)) {
transmitting = 0; transmitting = 0;
if (transmit_pin) transmit_deassert(); if (transmit_pin) transmit_deassert();
LPUART0_CTRL &= ~LPUART_CTRL_TCIE; // Actually wondering if we can just leave this one on...
BITBAND_CLR_BIT(LPUART0_CTRL, TCIE_BIT);
// LPUART0_CTRL &= ~LPUART_CTRL_TCIE; // Actually wondering if we can just leave this one on...
} }
} }



Loading…
Cancel
Save