4#include "uart_msp432.h"
5#include "gpio_msp432.h"
6#include "irq_dispatcher.h"
12uint32_t UART_CLK = SystemCoreClock;
13extern uint32_t SubsystemMasterClock
__attribute__((weak,alias(
"UART_CLK")));
16function<void(
char)> uart_msp432::_intHandler[4] = {
nullptr,
nullptr,
nullptr,
nullptr};
18uart_msp432::uart_msp432(
EUSCI_A_Type * module, uint32_t baud,uart_mode_t mode)
19: _init(false), _EUSCI(module), _baud(baud), _mode(mode),
20 _port(0), _rx_pin(0), _tx_pin(0) {
22 irq_dispatcher::link_in();
25void uart_msp432::init() {
28 if (_EUSCI==EUSCI_A0) { _port = 1; _rx_pin = 2; _tx_pin = 3; }
29 else if (_EUSCI==EUSCI_A1) { _port = 2; _rx_pin = 2; _tx_pin = 3; }
30 else if (_EUSCI==EUSCI_A2) { _port = 3; _rx_pin = 2; _tx_pin = 3; }
31 else if (_EUSCI==EUSCI_A3) { _port = 9; _rx_pin = 6; _tx_pin = 7; }
70uart_msp432::~uart_msp432() {
87bool uart_msp432::available() {
92char uart_msp432::getc() {
97 return _EUSCI->
RXBUF;;
100void uart_msp432::putc(
char c) {
105 _EUSCI->
TXBUF = (uint16_t)c;
108size_t uart_msp432::puts(
const char *s) {
111 for (i=0; i < len; i++) putc(s[i]);
115void uart_msp432::uartMode(uart_mode_t mode) {
121 if (mode & UART::BITS_7) {
124 if (mode & UART::BITS_8) {
125 _EUSCI->
CTLW0 &= ~EUSCI_A_CTLW0_SEVENBIT;
127 if (mode & UART::NO_PARITY) {
128 _EUSCI->
CTLW0 &= ~EUSCI_A_CTLW0_PEN;
130 if (mode & UART::EVEN_PARITY) {
134 if (mode & UART::ODD_PARITY) {
136 _EUSCI->
CTLW0 &= ~EUSCI_A_CTLW0_PAR;
138 if (mode & UART::STOPBITS_1) {
139 _EUSCI->
CTLW0 &= ~EUSCI_A_CTLW0_SPB;
141 if (mode & UART::STOPBITS_2) {
146 _EUSCI->
CTLW0 &= ~EUSCI_A_CTLW0_SWRST;
149void uart_msp432::setBaudrate(uint32_t baud) {
151 _EUSCI->
BRW = (uint16_t)(SubsystemMasterClock / baud);
154void uart_msp432::sendBreak(uint16_t ms) {
156 _EUSCI->
CTLW0 &= ~EUSCI_A_CTLW0_TXBRK;
157 }
else if (ms == 0xffff) {
162 _EUSCI->
CTLW0 &= ~EUSCI_A_CTLW0_TXBRK;
166void uart_msp432::setDTR(
bool) {
167 assert(
false &&
"Not implemented");
170void uart_msp432::setRTS(
bool) {
171 assert(
false &&
"Not implemented");
174void uart_msp432::uartAttachIrq(function<
void(
char)> f) {
176 uint8_t index = (((uint32_t)_EUSCI) >> 10) & 0x3;
177 _intHandler[index] = f;
179 NVIC_EnableIRQ((IRQn_Type)(16 + index));
182void uart_msp432::uartDetachIrq () {
184 uint8_t index = (((uint32_t)_EUSCI) >> 10) & 0x3;
186 NVIC_DisableIRQ((IRQn_Type)(16 + index));
187 _intHandler[index] =
nullptr;
190void uart_msp432::uartEnableIrq () {
194void uart_msp432::uartDisableIrq() {
198void uart_msp432::enableFIFO(
bool val) {
204 char c = uart->
RXBUF;
205 uint8_t index = (((uint32_t)uart) >> 10) & 0x3;
206 if (_intHandler[index])
207 _intHandler[index](c);
214void EUSCIA0_UART_IRQHandler(
void) {
215 uart_msp432::handleIrq(EUSCI_A0);
217void EUSCIA1_UART_IRQHandler(
void) {
218 uart_msp432::handleIrq(EUSCI_A1);
220void EUSCIA2_UART_IRQHandler(
void) {
221 uart_msp432::handleIrq(EUSCI_A2);
223void EUSCIA3_UART_IRQHandler(
void) {
224 uart_msp432::handleIrq(EUSCI_A3);
#define EUSCI_A_CTLW0_PAR
#define EUSCI_A_MCTLW_BRF_MASK
#define EUSCI_A_CTLW0_SPB
#define EUSCI_A_IFG_RXIFG
#define EUSCI_A_STATW_BUSY
#define EUSCI_A_IFG_TXIFG
#define EUSCI_A_CTLW0_TXBRK
#define EUSCI_A_CTLW0_SWRST
#define EUSCI_A_MCTLW_BRS_MASK
#define EUSCI_A_MCTLW_OS16
#define EUSCI_A_CTLW0_SSEL__SMCLK
#define EUSCI_A_CTLW0_PEN
#define EUSCI_A_CTLW0_SEVENBIT
#define EUSCI_A_IE_TXCPTIE
void __attribute__((noreturn))(*rom_reset_usb_boot_fn)(uint32_t
Reboot the device into BOOTSEL mode.