#include "../include/io.h" // UART0 enum { ARM_UART0_BASE = PERIPHERAL_BASE + 0x201000, ARM_UART0_DR = ARM_UART0_BASE + 0x00, ARM_UART0_FR = ARM_UART0_BASE + 0x18, ARM_UART0_IBRD = ARM_UART0_BASE + 0x24, ARM_UART0_FBRD = ARM_UART0_BASE + 0x28, ARM_UART0_LCRH = ARM_UART0_BASE + 0x2C, ARM_UART0_CR = ARM_UART0_BASE + 0x30, ARM_UART0_IFLS = ARM_UART0_BASE + 0x34, ARM_UART0_IMSC = ARM_UART0_BASE + 0x38, ARM_UART0_RIS = ARM_UART0_BASE + 0x3C, ARM_UART0_MIS = ARM_UART0_BASE + 0x40, ARM_UART0_ICR = ARM_UART0_BASE + 0x44 }; unsigned char lo(unsigned int val) { return (unsigned char)(val & 0xff); } unsigned char hi(unsigned int val) { return (unsigned char)((val & 0xff00) >> 8); } unsigned int bt_isReadByteReady() { return (!(mmio_read(ARM_UART0_FR) & 0x10)); } unsigned char bt_readByte() { unsigned char ch = lo(mmio_read(ARM_UART0_DR)); return ch; } unsigned char bt_waitReadByte() { while (!bt_isReadByteReady()); return bt_readByte(); } void bt_writeByte(char byte) { while ((mmio_read(ARM_UART0_FR) & 0x20) != 0); mmio_write(ARM_UART0_DR, (unsigned int)byte); } void bt_flushrx() { while (bt_isReadByteReady()) bt_readByte(); } void wait_msec(unsigned int n) { register unsigned long f, t, r; // Get the current counter frequency asm volatile ("mrs %0, cntfrq_el0" : "=r"(f)); // Read the current counter asm volatile ("mrs %0, cntpct_el0" : "=r"(t)); // Calculate expire value for counter t+=((f/1000)*n)/1000; do{asm volatile ("mrs %0, cntpct_el0" : "=r"(r));}while(r