/* Initialise the serial port with the given baudrate. The settings are always 8 data bits, no parity, 1 stop bit, no start bits.  */
int serial_init(void)
/* Initialise the serial port with the given baudrate. The settings are always 8 data bits, no parity, 1 stop bit, no start bits.  */
int serial_init(void)
{
	__REG(UART_PHYS + UCR1) = 0x0;
	__REG(UART_PHYS + UCR2) = 0x0;
	while (!(__REG(UART_PHYS + UCR2) & UCR2_SRST));
	__REG(UART_PHYS + UCR3) = 0x0704;
	__REG(UART_PHYS + UCR4) = 0x8000;
	__REG(UART_PHYS + UESC) = 0x002b;
	__REG(UART_PHYS + UTIM) = 0x0;
	__REG(UART_PHYS + UTS) = 0x0;
	serial_setbrg();
	__REG(UART_PHYS + UCR2) = UCR2_WS | UCR2_IRTS | UCR2_RXEN | UCR2_TXEN | UCR2_SRST;
	__REG(UART_PHYS + UCR1) = UCR1_UARTEN;
	return 0;
}