1/** 2 * \file 3 * \brief Architecture-independent interface to the kernel serial port 4 * subsystem. 5 */ 6/* 7 * Copyright (c) 2007-2012 ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, CAB F.78, Universitaestr. 6, CH-8092 Zurich. 13 * Attn: Systems Group. 14 */ 15 16#ifndef __SERIAL_H 17#define __SERIAL_H 18 19/* Need to include this for errval_t */ 20#include <errors/errno.h> 21 22/* 23 * What kind of serial ports do we have? 24 */ 25extern unsigned serial_num_physical_ports; 26 27/* 28 * Initialize a physical serial port 29 */ 30extern errval_t serial_init(unsigned port, bool initialize_hw); 31extern errval_t serial_early_init(unsigned port); 32extern errval_t serial_early_init_mmu_enabled(unsigned port); 33 34/* 35 * Polled, blocking input/output. No buffering. 36 */ 37extern void serial_putchar(unsigned port, char c); 38extern char serial_getchar(unsigned port); 39 40/* 41 * Console logical port. Putchar will replace LF with CRLF, unlike 42 * the above calls. 43 */ 44extern unsigned serial_console_port; 45 46static inline errval_t serial_console_init(bool hwinit) 47{ 48 return serial_init(serial_console_port, hwinit); 49} 50 51static inline void serial_console_putchar(char c) 52{ 53 if (c == '\n') { 54 serial_putchar(serial_console_port, '\r'); 55 } 56 serial_putchar(serial_console_port, c); 57} 58 59static inline char serial_console_getchar(void) 60{ 61 return serial_getchar(serial_console_port); 62} 63 64/* 65 * Debug logical port. Putchar will replace LF with CRLF, unlike 66 * the above calls. 67 */ 68extern unsigned serial_debug_port; 69 70 71static inline errval_t serial_debug_init(void) 72{ 73 return serial_init(serial_debug_port, true); 74} 75 76static inline void serial_debug_putchar(char c) 77{ 78 if (c == '\n') { 79 serial_putchar(serial_debug_port, '\r'); 80 } 81 serial_putchar(serial_debug_port, c); 82} 83 84static inline char serial_debug_getchar(void) 85{ 86 return serial_getchar(serial_debug_port); 87} 88 89#endif //__SERIAL_H 90