6 * \author Adam Lackorznynski <adam@os.inf.tu-dresden.de>
7 * Alexander Warg <alexander.warg@os.inf.tu-dresden.de>
11 * (c) 2008-2009 Author(s)
12 * economic rights: Technische Universität Dresden (Germany)
14 * This file is part of TUD:OS and distributed under the terms of the
15 * GNU General Public License 2.
16 * Please see the COPYING-GPL-2 file for details.
19 #include "uart_sa1000.h"
34 MODE_8N1 = PAR_NONE | DAT_8 | STOP_1,
35 MODE_7E1 = PAR_EVEN | DAT_7 | STOP_1,
37 // these two values are to leave either mode
38 // or baud rate unchanged on a call to change_mode
87 bool Uart_sa1000::startup(Io_register_block const *regs)
90 _regs->write<unsigned int>(UTSR0, ~0UL); // clear pending status bits
91 _regs->write<unsigned int>(UTCR3, UTCR3_RXE | UTCR3_TXE); //enable transmitter and receiver
95 void Uart_sa1000::shutdown()
97 _regs->write<unsigned int>(UTCR3, 0);
100 bool Uart_sa1000::change_mode(Transfer_mode m, Baud_rate baud)
102 unsigned old_utcr3, quot;
105 if (baud == (Baud_rate)-1)
107 if (baud != BAUD_NC && (baud>115200 || baud<96))
109 if (m == (Transfer_mode)-1)
112 //st = proc_cli_save();
113 old_utcr3 = _regs->read<unsigned int>(UTCR3);
114 _regs->write<unsigned int>(UTCR3, (old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE)));
115 //proc_sti_restore(st);
117 while (_regs->read<unsigned int>(UTSR1) & UTSR1_TBY)
121 _regs->write<unsigned int>(UTCR3, 0);
123 /* set parity, data size, and stop bits */
125 _regs->write<unsigned int>(UTCR0, m & 0x0ff);
130 quot = (UARTCLK / (16*baud)) -1;
131 _regs->write<unsigned int>(UTCR1, (quot & 0xf00) >> 8);
132 _regs->write<unsigned int>(UTCR2, quot & 0x0ff);
135 _regs->write<unsigned int>(UTSR0, (unsigned)-1);
136 _regs->write<unsigned int>(UTCR3, old_utcr3);
141 int Uart_sa1000::get_char(bool blocking) const
144 unsigned long old_utcr3 = _regs->read<unsigned int>(UTCR3);
145 _regs->write<unsigned int>(UTCR3, old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE));
147 while (!(_regs->read<unsigned int>(UTSR1) & UTSR1_RNE))
151 ch = _regs->read<unsigned int>(UTDR);
152 _regs->write<unsigned int>(UTCR3, old_utcr3);
157 int Uart_sa1000::char_avail() const
159 return !!(_regs->read<unsigned int>(UTSR1) & UTSR1_RNE);
162 void Uart_sa1000::out_char(char c) const
164 // do UTCR3 thing here as well?
165 while(!(_regs->read<unsigned int>(UTSR1) & UTSR1_TNF))
167 _regs->write<unsigned int>(UTDR, c);
170 int Uart_sa1000::write(char const *s, unsigned long count) const
175 old_utcr3 = _regs->read<unsigned int>(UTCR3);
176 _regs->write<unsigned int>(UTCR3, (old_utcr3 & ~(UTCR3_RIE | UTCR3_TIE)) | UTCR3_TXE );
179 for (i = 0; i < count; i++)
182 /* wait till everything is transmitted */
183 while (_regs->read<unsigned int>(UTSR1) & UTSR1_TBY)
186 _regs->write<unsigned int>(UTCR3, old_utcr3);