14 #include "inc/tm4c123gh6pm.h"
15 #include "inc/hw_memmap.h"
17 #include "driverlib/gpio.h"
18 #include "driverlib/uart.h"
19 #include "driverlib/sysctl.h"
20 #include "driverlib/pin_map.h"
24 uint32_t peripheral_gpio;
25 uint32_t peripheral_uart;
28 uint32_t pin_rx_function;
29 uint32_t pin_tx_function;
36 static UART UART_uarts[3] =
72 #define NUMBER_OF_UARTS ( sizeof(UART_uarts) / sizeof(UART) )
74 #define check_uart_num(x, y) if(x >= NUMBER_OF_UARTS) { return y; }
80 check_uart_num(uart_num,);
81 UART *uart = &UART_uarts[uart_num];
84 if(!uart->initialised)
87 if(!SysCtlPeripheralReady(uart->peripheral_uart))
89 SysCtlPeripheralEnable(uart->peripheral_uart);
90 while(!SysCtlPeripheralReady(uart->peripheral_uart)) { };
94 if(!SysCtlPeripheralReady(uart->peripheral_gpio))
96 SysCtlPeripheralEnable(uart->peripheral_gpio);
97 while(!SysCtlPeripheralReady(uart->peripheral_gpio)) { };
100 GPIOPinConfigure(uart->pin_rx_function);
101 GPIOPinConfigure(uart->pin_tx_function);
102 GPIOPinTypeUART(uart->base_gpio, uart->pin_rx | uart->pin_tx);
104 UARTClockSourceSet(uart->base_uart, UART_CLOCK_SYSTEM);
106 uart->initialised =
true;
109 UARTConfigSetExpClk(uart->base_uart, SysCtlClockGet(), baudrate,
110 (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
115 check_uart_num(uart_num,
'\0');
116 UART *uart = &UART_uarts[uart_num];
118 return (
char)UARTCharGet(uart->base_uart);
123 check_uart_num(uart_num,);
124 UART *uart = &UART_uarts[uart_num];
126 UARTCharPut(uart->base_uart, c);
137 void UART_putb(uint8_t uart_num,
char *str, uint32_t len)
147 check_uart_num(uart_num,
false);
148 UART *uart = &UART_uarts[uart_num];
150 int32_t value = UARTCharGetNonBlocking(uart->base_uart);
165 check_uart_num(uart_num,
false);
166 UART *uart = &UART_uarts[uart_num];
168 return UARTCharPutNonBlocking(uart->base_uart, c);
197 check_uart_num(uart_num,
false);
198 UART *uart = &UART_uarts[uart_num];
200 return UARTBusy(uart->base_uart);
205 check_uart_num(uart_num,
false);
206 UART *uart = &UART_uarts[uart_num];
208 return UARTCharsAvail(uart->base_uart);
void UART_init(uint8_t uart_num, uint32_t baudrate)
bool UART_getc_nonblocking(uint8_t uart_num, char *c)
char UART_getc(uint8_t uart_num)
bool UART_putb_nonblocking(uint8_t uart_num, char *str, uint32_t len)
void UART_putb(uint8_t uart_num, char *str, uint32_t len)
bool UART_charsAvail(uint8_t uart_num)
bool UART_putc_nonblocking(uint8_t uart_num, char c)
void UART_puts(uint8_t uart_num, char *str)
bool UART_busy(uint8_t uart_num)
void UART_putc(uint8_t uart_num, char c)
bool UART_puts_nonblocking(uint8_t uart_num, char *str)