MNRS-BM-BSP/include/ehrenberg/devices/uart.h

29 lines
705 B
C

#ifndef _BSP_UART_H
#define _BSP_UART_H
#include <stdint.h>
#include "gen/Apb3Uart.h"
#define uart_t apb3uart_t
static inline uint32_t uart_get_tx_free(volatile uart_t *reg){
return (reg->STATUS_REG >> 16) & 0xFF;
}
static inline uint32_t uart_get_rx_avail(volatile uart_t *reg){
return reg->STATUS_REG >> 24;
}
static inline void uart_write(volatile uart_t *reg, uint8_t data){
while(get_uart_rx_tx_reg_tx_free(reg) == 0);
set_uart_rx_tx_reg_data(reg, data);
}
static inline inline uint8_t uart_read(volatile uart_t *reg){
uint32_t res = get_uart_rx_tx_reg_data(reg);
while((res&0x10000) == 0) res = get_uart_rx_tx_reg_data(reg);
return res;
}
#endif /* _BSP_UART_H */