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 unsigned long Uart_sa1000::rd(unsigned long reg) const
89 volatile unsigned long *r = (unsigned long*)(_base + reg);
93 void Uart_sa1000::wr(unsigned long reg, unsigned long val) const
95 volatile unsigned long *r = (unsigned long*)(_base + reg);
99 bool Uart_sa1000::startup(unsigned long base)
102 wr(UTSR0, ~0UL); // clear pending status bits
103 wr(UTCR3, UTCR3_RXE | UTCR3_TXE); //enable transmitter and receiver
107 void Uart_sa1000::shutdown()
112 bool Uart_sa1000::enable_rx_irq(bool /*enable*/)
116 bool Uart_sa1000::enable_tx_irq(bool /*enable*/) { return false; }
117 bool Uart_sa1000::change_mode(Transfer_mode m, Baud_rate baud)
119 unsigned old_utcr3, quot;
122 if (baud == (Baud_rate)-1)
124 if (baud != BAUD_NC && (baud>115200 || baud<96))
126 if (m == (Transfer_mode)-1)
129 //st = proc_cli_save();
130 old_utcr3 = rd(UTCR3);
131 wr(UTCR3, (old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE)));
132 //proc_sti_restore(st);
134 while (rd(UTSR1) & UTSR1_TBY)
140 /* set parity, data size, and stop bits */
142 wr(UTCR0, m & 0x0ff);
147 quot = (UARTCLK / (16*baud)) -1;
148 wr(UTCR1, (quot & 0xf00) >> 8);
149 wr(UTCR2, quot & 0x0ff);
152 wr(UTSR0, (unsigned)-1);
153 wr(UTCR3, old_utcr3);
158 int Uart_sa1000::get_char(bool blocking) const
161 unsigned long old_utcr3 = rd(UTCR3);
162 wr(UTCR3, old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE));
164 while (!(rd(UTSR1) & UTSR1_RNE))
169 wr(UTCR3, old_utcr3);
174 int Uart_sa1000::char_avail() const
176 return !!(rd(UTSR1) & UTSR1_RNE);
179 void Uart_sa1000::out_char(char c) const
181 // do UTCR3 thing here as well?
182 while(!(rd(UTSR1) & UTSR1_TNF))
187 int Uart_sa1000::write(char const *s, unsigned long count) const
193 //st = proc_cli_save();
194 old_utcr3 = rd(UTCR3);
195 wr(UTCR3, (old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE)) | UTCR3_TXE );
198 for(i = 0; i < count; i++)
205 /* wait till everything is transmitted */
206 while (rd(UTSR1) & UTSR1_TBY)
209 wr(UTCR3, old_utcr3);
210 //proc_sti_restore(st);