38 #include <aducrf101-include.h>
40 static int (*uart_input_handler)(
unsigned char c);
41 static int stdout_enabled;
47 pADI_GP1->GPCON &= ~(GP1CON_CON0_MSK | GP1CON_CON1_MSK);
48 pADI_GP1->GPCON |= GP1CON_CON0_UART0RXD | GP1CON_CON1_UART0TXD;
54 int div = (
F_CPU / 32) / baud;
55 pADI_UART->COMDIV = div;
56 pADI_UART->COMFBR = 0x8800 | ((((64 *
F_CPU) / div) / baud) - 2048);
57 pADI_UART->COMIEN = 0;
58 pADI_UART->COMLCR = 3;
61 pADI_UART->COMIEN = COMIEN_ERBFI_EN;
65 uart_input_handler =
NULL;
70 uart_put(
unsigned char x)
72 while(!(pADI_UART->COMLSR & COMLSR_THRE))
78 UART_Int_Handler(
void)
80 if(pADI_UART->COMIIR & COMIIR_STA_RXBUFFULL) {
81 unsigned char x = pADI_UART->COMRX;
82 if(uart_input_handler) {
83 uart_input_handler(x);
91 uart_input_handler = input;
94 uart_enable_stdout(
int enabled)
96 stdout_enabled = enabled;
101 _write(
int fd,
const void *buf,
size_t len)
103 if(stdout_enabled == 0) {
107 if(fd == 1 || fd == 2) {
109 const unsigned char *p = buf;
120 __write(
int fd,
const unsigned char *buf,
size_t count)
122 return _write(fd, buf, count);
#define F_CPU
CPU core frequency resulting from the chosen divisors and multipliers.
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
Enable External Interrupt.
void uart_set_input(uint8_t uart, int(*input)(unsigned char c))
Assigns a callback to be called when the UART receives a byte.
void uart_init(const unsigned int uart_num, uint32_t module_clk_hz, const uint32_t baud)
Initialize UART.
#define NULL
The null pointer.