1/* 2 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#ifndef DRIVER_H_ 8#define DRIVER_H_ 9 10#include <camkes.h> 11#include <stdint.h> 12 13#define KZM_IO_BASE_ADDR (unsigned int)regs 14#define KZM_UART1_RX_ADDR (KZM_IO_BASE_ADDR + 0x00) 15#define KZM_UART1_TX_ADDR (KZM_IO_BASE_ADDR + 0x40) 16#define KZM_UART1_STAT_ADDR (KZM_IO_BASE_ADDR + 0x94) 17 18#define KZM_UART1_RX_RDY (1UL << 9) 19#define KZM_UART1_TX_RDY (1UL << 13) 20#define KZM_UART1_RX_MASK 0xFF 21 22#define UART_VAL(x) *((volatile uint32_t *)(x)) 23 24static inline int uart_received() 25{ 26 return UART_VAL(KZM_UART1_STAT_ADDR) & KZM_UART1_RX_RDY; 27} 28 29static inline int is_transmit_empty() { 30 return UART_VAL(KZM_UART1_STAT_ADDR) & KZM_UART1_TX_RDY; 31} 32 33static inline void uart_put_char(char c) 34{ 35 while(is_transmit_empty() == 0); 36 UART_VAL(KZM_UART1_TX_ADDR) = c; 37} 38 39static inline void uart_put(const char *s) { 40 while (*s != '\0') { 41 uart_put_char(*s); 42 s++; 43 } 44} 45 46#endif 47