9 bool startup(Address address, unsigned irq);
22 MODE_8N1 = PAR_NONE | DAT_8 | STOP_1,
23 MODE_7E1 = PAR_EVEN | DAT_7 | STOP_1,
25 // these two values are to leave either mode
26 // or baud rate unchanged on a call to change_mode
71 //---------------------------------------------------------------------------
72 IMPLEMENTATION [sa1100]:
75 #include "processor.h"
77 PRIVATE INLINE static Address Uart::_utcr0(Address a)
80 PRIVATE INLINE static Address Uart::_utcr1(Address a)
83 PRIVATE INLINE static Address Uart::_utcr2(Address a)
86 PRIVATE INLINE static Address Uart::_utcr3(Address a)
89 PRIVATE INLINE static Address Uart::_utcr4(Address a)
92 PRIVATE INLINE static Address Uart::_utdr(Address a)
95 PRIVATE INLINE static Address Uart::_utsr0(Address a)
98 PRIVATE INLINE static Address Uart::_utsr1(Address a)
102 PRIVATE INLINE NEEDS[Uart::_utcr0]
103 unsigned Uart::utcr0() const
104 { return *((volatile unsigned*)(_utcr0(address))); }
106 PRIVATE INLINE NEEDS[Uart::_utcr1]
107 unsigned Uart::utcr1() const
108 { return *((volatile unsigned*)(_utcr1(address))); }
110 PRIVATE INLINE NEEDS[Uart::_utcr2]
111 unsigned Uart::utcr2() const
112 { return *((volatile unsigned*)(_utcr2(address))); }
114 PRIVATE INLINE NEEDS[Uart::_utcr3]
115 unsigned Uart::utcr3() const
116 { return *((volatile unsigned*)(_utcr3(address))); }
118 PRIVATE INLINE NEEDS[Uart::_utcr4]
119 unsigned Uart::utcr4() const
120 { return *((volatile unsigned*)(_utcr4(address))); }
122 PRIVATE INLINE NEEDS[Uart::_utdr]
123 unsigned Uart::utdr() const
124 { return *((volatile unsigned*)(_utdr(address))); }
126 PRIVATE INLINE NEEDS[Uart::_utsr0]
127 unsigned Uart::utsr0() const
128 { return *((volatile unsigned*)(_utsr0(address))); }
130 PRIVATE INLINE NEEDS[Uart::_utsr1]
131 unsigned Uart::utsr1() const
132 { return *((volatile unsigned*)(_utsr1(address))); }
135 PRIVATE INLINE NEEDS[Uart::_utcr0]
136 void Uart::utcr0(unsigned v)
137 { *((volatile unsigned*)(_utcr0(address)))= v; }
139 PRIVATE INLINE NEEDS[Uart::_utcr1]
140 void Uart::utcr1(unsigned v)
141 { *((volatile unsigned*)(_utcr1(address)))= v; }
143 PRIVATE INLINE NEEDS[Uart::_utcr2]
144 void Uart::utcr2(unsigned v)
145 { *((volatile unsigned*)(_utcr2(address)))= v; }
147 PRIVATE INLINE NEEDS[Uart::_utcr3]
148 void Uart::utcr3(unsigned v)
149 { *((volatile unsigned*)(_utcr3(address)))= v; }
151 PRIVATE INLINE NEEDS[Uart::_utcr4]
152 void Uart::utcr4(unsigned v)
153 { *((volatile unsigned*)(_utcr4(address)))= v; }
155 PRIVATE INLINE NEEDS[Uart::_utdr]
156 void Uart::utdr(unsigned v)
157 { *((volatile unsigned*)(_utdr(address)))= v; }
159 PRIVATE INLINE NEEDS[Uart::_utsr0]
160 void Uart::utsr0(unsigned v)
161 { *((volatile unsigned*)(_utsr0(address)))= v; }
163 PRIVATE INLINE NEEDS[Uart::_utsr1]
164 void Uart::utsr1(unsigned v)
165 { *((volatile unsigned*)(_utsr1(address)))= v; }
168 IMPLEMENT Uart::Uart() : Console(DISABLED)
170 address = (unsigned)-1;
174 IMPLEMENT Uart::~Uart()
180 IMPLEMENT bool Uart::startup(Address _address, unsigned irq)
184 utsr0((unsigned)-1); //clear pending status bits
185 utcr3(UTCR3_RXE | UTCR3_TXE); //enable transmitter and receiver
190 IMPLEMENT void Uart::shutdown()
196 IMPLEMENT bool Uart::change_mode(TransferMode m, BaudRate baud)
198 unsigned old_utcr3, quot;
200 if(baud == (BaudRate)-1)
202 if(baud != BAUD_NC && (baud>115200 || baud<96))
204 if(m == (TransferMode)-1)
207 st = Proc::cli_save();
209 utcr3(old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE));
210 Proc::sti_restore(st);
212 while(utsr1() & UTSR1_TBY);
217 /* set parity, data size, and stop bits */
224 quot = (UARTCLK / (16*baud)) -1;
225 utcr1((quot & 0xf00) >> 8);
235 PUBLIC bool Uart::tx_empty()
237 return !(utsr1() & UTSR1_TBY);
242 int Uart::write(const char *s, size_t count)
246 st = Proc::cli_save();
248 utcr3((old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE)) | UTCR3_TXE);
251 for(unsigned i =0; i<count; i++)
253 while(!(utsr1() & UTSR1_TNF))
258 while(!(utsr1() & UTSR1_TNF))
264 /* wait till everything is transmitted */
265 while(utsr1() & UTSR1_TBY)
269 Proc::sti_restore(st);
274 int Uart::getchar(bool blocking)
276 unsigned old_utcr3, ch;
279 utcr3(old_utcr3 & ~(UTCR3_RIE|UTCR3_TIE));
280 while(!(utsr1() & UTSR1_RNE))
285 utsr0(0x04); // clear RID
292 int Uart::char_avail() const
294 if((utsr1() & UTSR1_RNE))
304 int Uart::irq() const
309 IMPLEMENT inline NEEDS[Uart::utcr3]
310 void Uart::enable_rcv_irq()
312 utcr3(utcr3() | UTCR3_RIE);
315 IMPLEMENT inline NEEDS[Uart::utcr3]
316 void Uart::disable_rcv_irq()
318 utcr3(utcr3() & ~UTCR3_RIE);