1 /* 2 * Copyright 2012 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * François Revol, revol@free.fr 7 */ 8 #ifndef _KERNEL_ARCH_DEBUG_UART_H 9 #define _KERNEL_ARCH_DEBUG_UART_H 10 11 12 #include <sys/types.h> 13 14 #include <SupportDefs.h> 15 16 17 class DebugUART { 18 public: 19 DebugUART(addr_t base, int64 clock) 20 : fBase(base), 21 fClock(clock), 22 fEnabled(true) {}; 23 ~DebugUART() {}; 24 25 virtual void InitEarly() {}; 26 virtual void Init() {}; 27 virtual void InitPort(uint32 baud) {}; 28 29 virtual void Enable() { fEnabled = true; } 30 virtual void Disable() { fEnabled = false; } 31 32 virtual int PutChar(char c) = 0; 33 virtual int GetChar(bool wait) = 0; 34 35 virtual void FlushTx() = 0; 36 virtual void FlushRx() = 0; 37 38 addr_t Base() const { return fBase; } 39 int64 Clock() const { return fClock; } 40 bool Enabled() const { return fEnabled; } 41 42 protected: 43 // default MMIO 44 virtual void Out8(int reg, uint8 value) 45 { *((uint8 *)Base() + reg) = value; } 46 virtual uint8 In8(int reg) 47 { return *((uint8 *)Base() + reg); } 48 virtual void Barrier() {} 49 50 private: 51 addr_t fBase; 52 int64 fClock; 53 bool fEnabled; 54 }; 55 56 57 #endif /* _KERNEL_ARCH_DEBUG_UART_H */ 58