The Pedigree Project  0.1
au1500/Serial.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "Serial.h"
21 
22 Au1500Serial::Au1500Serial() : m_pRegs(0)
23 {
24 }
25 Au1500Serial::~Au1500Serial()
26 {
27 }
28 void Au1500Serial::setBase(uintptr_t nBaseAddr)
29 {
30  // We use KSEG1 (uncached physical) for our IO accesses.
31  m_pRegs = reinterpret_cast<serial *>(KSEG1(nBaseAddr));
32 }
33 char Au1500Serial::read()
34 {
35  while (!(m_pRegs->autoflow & 0x1))
36  ;
37  return static_cast<char>(m_pRegs->rxdata);
38 }
39 char Au1500Serial::readNonBlock()
40 {
41  if (m_pRegs->autoflow & 0x1)
42  return m_pRegs->rxdata;
43  else
44  return '\0';
45 }
46 void Au1500Serial::write(char c)
47 {
48  while (!(m_pRegs->autoflow & 0x20))
49  ;
50  m_pRegs->txdata = static_cast<uint8_t>(c);
51 }
virtual void setBase(uintptr_t nBaseAddr)