| static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE]; | static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE]; | ||||
| static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE]; | static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE]; | ||||
| static volatile uint8_t transmitting = 0; | 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 | #if TX_BUFFER_SIZE > 255 | ||||
| static volatile uint16_t tx_buffer_head = 0; | static volatile uint16_t tx_buffer_head = 0; | ||||
| static volatile uint16_t tx_buffer_tail = 0; | static volatile uint16_t tx_buffer_tail = 0; | ||||
| pinMode(pin, OUTPUT); | pinMode(pin, OUTPUT); | ||||
| digitalWrite(pin, LOW); | digitalWrite(pin, LOW); | ||||
| transmit_pin = portOutputRegister(pin); | transmit_pin = portOutputRegister(pin); | ||||
| #if defined(KINETISL) | |||||
| transmit_mask = digitalPinToBitMask(pin); | |||||
| #endif | |||||
| } | } | ||||
| void serial_putchar(uint32_t c) | void serial_putchar(uint32_t c) | ||||
| uint32_t head, n; | uint32_t head, n; | ||||
| if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return; | if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return; | ||||
| if (transmit_pin) *transmit_pin = 1; | |||||
| if (transmit_pin) transmit_assert(); | |||||
| head = tx_buffer_head; | head = tx_buffer_head; | ||||
| if (++head >= TX_BUFFER_SIZE) head = 0; | if (++head >= TX_BUFFER_SIZE) head = 0; | ||||
| while (tx_buffer_tail == head) { | while (tx_buffer_tail == head) { | ||||
| uint32_t head, n; | uint32_t head, n; | ||||
| if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return; | if (!(SIM_SCGC4 & SIM_SCGC4_UART0)) return; | ||||
| if (transmit_pin) *transmit_pin = 1; | |||||
| if (transmit_pin) transmit_assert(); | |||||
| while (p < end) { | while (p < end) { | ||||
| head = tx_buffer_head; | head = tx_buffer_head; | ||||
| if (++head >= TX_BUFFER_SIZE) head = 0; | if (++head >= TX_BUFFER_SIZE) head = 0; | ||||
| #endif | #endif | ||||
| if ((c & UART_C2_TCIE) && (UART0_S1 & UART_S1_TC)) { | if ((c & UART_C2_TCIE) && (UART0_S1 & UART_S1_TC)) { | ||||
| transmitting = 0; | transmitting = 0; | ||||
| if (transmit_pin) *transmit_pin = 0; | |||||
| if (transmit_pin) transmit_deassert(); | |||||
| UART0_C2 = C2_TX_INACTIVE; | UART0_C2 = C2_TX_INACTIVE; | ||||
| } | } | ||||
| } | } |
| static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE]; | static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE]; | ||||
| static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE]; | static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE]; | ||||
| static volatile uint8_t transmitting = 0; | 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 | #if TX_BUFFER_SIZE > 255 | ||||
| static volatile uint16_t tx_buffer_head = 0; | static volatile uint16_t tx_buffer_head = 0; | ||||
| static volatile uint16_t tx_buffer_tail = 0; | static volatile uint16_t tx_buffer_tail = 0; | ||||
| pinMode(pin, OUTPUT); | pinMode(pin, OUTPUT); | ||||
| digitalWrite(pin, LOW); | digitalWrite(pin, LOW); | ||||
| transmit_pin = portOutputRegister(pin); | transmit_pin = portOutputRegister(pin); | ||||
| #if defined(KINETISL) | |||||
| transmit_mask = digitalPinToBitMask(pin); | |||||
| #endif | |||||
| } | } | ||||
| void serial2_putchar(uint32_t c) | void serial2_putchar(uint32_t c) | ||||
| uint32_t head, n; | uint32_t head, n; | ||||
| if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return; | if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return; | ||||
| if (transmit_pin) *transmit_pin = 1; | |||||
| if (transmit_pin) transmit_assert(); | |||||
| head = tx_buffer_head; | head = tx_buffer_head; | ||||
| if (++head >= TX_BUFFER_SIZE) head = 0; | if (++head >= TX_BUFFER_SIZE) head = 0; | ||||
| while (tx_buffer_tail == head) { | while (tx_buffer_tail == head) { | ||||
| uint32_t head, n; | uint32_t head, n; | ||||
| if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return; | if (!(SIM_SCGC4 & SIM_SCGC4_UART1)) return; | ||||
| if (transmit_pin) *transmit_pin = 1; | |||||
| if (transmit_pin) transmit_assert(); | |||||
| while (p < end) { | while (p < end) { | ||||
| head = tx_buffer_head; | head = tx_buffer_head; | ||||
| if (++head >= TX_BUFFER_SIZE) head = 0; | if (++head >= TX_BUFFER_SIZE) head = 0; | ||||
| #endif | #endif | ||||
| if ((c & UART_C2_TCIE) && (UART1_S1 & UART_S1_TC)) { | if ((c & UART_C2_TCIE) && (UART1_S1 & UART_S1_TC)) { | ||||
| transmitting = 0; | transmitting = 0; | ||||
| if (transmit_pin) *transmit_pin = 0; | |||||
| if (transmit_pin) transmit_deassert(); | |||||
| UART1_C2 = C2_TX_INACTIVE; | UART1_C2 = C2_TX_INACTIVE; | ||||
| } | } | ||||
| } | } |
| static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE]; | static volatile BUFTYPE tx_buffer[TX_BUFFER_SIZE]; | ||||
| static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE]; | static volatile BUFTYPE rx_buffer[RX_BUFFER_SIZE]; | ||||
| static volatile uint8_t transmitting = 0; | 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 | #if TX_BUFFER_SIZE > 255 | ||||
| static volatile uint16_t tx_buffer_head = 0; | static volatile uint16_t tx_buffer_head = 0; | ||||
| static volatile uint16_t tx_buffer_tail = 0; | static volatile uint16_t tx_buffer_tail = 0; | ||||
| pinMode(pin, OUTPUT); | pinMode(pin, OUTPUT); | ||||
| digitalWrite(pin, LOW); | digitalWrite(pin, LOW); | ||||
| transmit_pin = portOutputRegister(pin); | transmit_pin = portOutputRegister(pin); | ||||
| #if defined(KINETISL) | |||||
| transmit_mask = digitalPinToBitMask(pin); | |||||
| #endif | |||||
| } | } | ||||
| void serial3_putchar(uint32_t c) | void serial3_putchar(uint32_t c) | ||||
| uint32_t head, n; | uint32_t head, n; | ||||
| if (!(SIM_SCGC4 & SIM_SCGC4_UART2)) return; | if (!(SIM_SCGC4 & SIM_SCGC4_UART2)) return; | ||||
| if (transmit_pin) *transmit_pin = 1; | |||||
| if (transmit_pin) transmit_assert(); | |||||
| head = tx_buffer_head; | head = tx_buffer_head; | ||||
| if (++head >= TX_BUFFER_SIZE) head = 0; | if (++head >= TX_BUFFER_SIZE) head = 0; | ||||
| while (tx_buffer_tail == head) { | while (tx_buffer_tail == head) { | ||||
| } | } | ||||
| if ((c & UART_C2_TCIE) && (UART2_S1 & UART_S1_TC)) { | if ((c & UART_C2_TCIE) && (UART2_S1 & UART_S1_TC)) { | ||||
| transmitting = 0; | transmitting = 0; | ||||
| if (transmit_pin) *transmit_pin = 0; | |||||
| if (transmit_pin) transmit_deassert(); | |||||
| UART2_C2 = C2_TX_INACTIVE; | UART2_C2 = C2_TX_INACTIVE; | ||||
| } | } | ||||
| } | } |