| 1 |
344 |
markom |
/* UART test using ACV */
|
| 2 |
|
|
|
| 3 |
|
|
#include "spr_defs.h"
|
| 4 |
|
|
#include "support.h"
|
| 5 |
|
|
|
| 6 |
396 |
markom |
/* use this macro to comment out nonworking parts */
|
| 7 |
|
|
#define COMPLETE 0
|
| 8 |
|
|
|
| 9 |
409 |
markom |
/* Whether to do test in more detail */
|
| 10 |
|
|
#define DETAILED 0
|
| 11 |
|
|
|
| 12 |
344 |
markom |
#define UART_ADDR (0x9c000000)
|
| 13 |
|
|
#define UART_RBR (UART_ADDR + 0)
|
| 14 |
|
|
#define UART_THR (UART_ADDR + 0)
|
| 15 |
|
|
#define UART_IER (UART_ADDR + 1)
|
| 16 |
|
|
#define UART_IIR (UART_ADDR + 2)
|
| 17 |
|
|
#define UART_FCR (UART_ADDR + 2)
|
| 18 |
|
|
#define UART_LCR (UART_ADDR + 3)
|
| 19 |
|
|
#define UART_MCR (UART_ADDR + 4)
|
| 20 |
|
|
#define UART_LSR (UART_ADDR + 5)
|
| 21 |
|
|
#define UART_MSR (UART_ADDR + 6)
|
| 22 |
411 |
markom |
#define UART_SCR (UART_ADDR + 7)
|
| 23 |
344 |
markom |
|
| 24 |
|
|
#define UART_DLL (UART_ADDR + 0)
|
| 25 |
|
|
#define UART_DLH (UART_ADDR + 1)
|
| 26 |
|
|
|
| 27 |
355 |
markom |
#define LCR_DIVL (0x80)
|
| 28 |
|
|
#define LCR_BREAK (0x40)
|
| 29 |
|
|
#define LCR_STICK (0x20)
|
| 30 |
|
|
#define LCR_EVENP (0x10)
|
| 31 |
|
|
#define LCR_PAREN (0x08)
|
| 32 |
|
|
#define LCR_NSTOP (0x04)
|
| 33 |
|
|
#define LCR_NBITS (0x03)
|
| 34 |
344 |
markom |
|
| 35 |
355 |
markom |
#define LSR_DR (0x01)
|
| 36 |
|
|
#define LSR_OE (0x02)
|
| 37 |
|
|
#define LSR_PE (0x04)
|
| 38 |
|
|
#define LSR_FE (0x08)
|
| 39 |
|
|
#define LSR_BREAK (0x10)
|
| 40 |
|
|
#define LSR_TXFE (0x20)
|
| 41 |
|
|
#define LSR_TXE (0x40)
|
| 42 |
|
|
#define LSR_ERR (0x80)
|
| 43 |
|
|
|
| 44 |
423 |
markom |
#define UART_INT_LINE 15 /* To which interrupt is uart connected */
|
| 45 |
409 |
markom |
|
| 46 |
344 |
markom |
/* fails if x is false */
|
| 47 |
|
|
#define ASSERT(x) ((x)?1: fail (__FUNCTION__, __LINE__))
|
| 48 |
|
|
/* Waits a few cycles that uart can prepare its data */
|
| 49 |
|
|
#define WAIT() {asm ("l.nop");asm ("l.nop");asm ("l.nop");asm ("l.nop");}
|
| 50 |
|
|
/* fails if there is an error */
|
| 51 |
355 |
markom |
#define NO_ERROR() { unsigned x = getreg (UART_LSR); if ((x & (LSR_BREAK|LSR_FE|LSR_PE|LSR_OE)) && !(x & LSR_ERR)) \
|
| 52 |
411 |
markom |
printf ("LSR7 (0x%02x) ERR @ %i\n", x, __LINE__); ASSERT(!(x & LSR_ERR) && ((x & 0x60) != 0x40));}
|
| 53 |
1024 |
simons |
#define MARK() printf ("Passed line %i\n", __LINE__)
|
| 54 |
344 |
markom |
|
| 55 |
355 |
markom |
#ifndef __LINE__
|
| 56 |
|
|
#define __LINE__ 0
|
| 57 |
|
|
#endif
|
| 58 |
|
|
|
| 59 |
344 |
markom |
void fail (char *func, int line)
|
| 60 |
|
|
{
|
| 61 |
|
|
#ifndef __FUNCTION__
|
| 62 |
|
|
#define __FUNCTION__ "?"
|
| 63 |
|
|
#endif
|
| 64 |
1024 |
simons |
printf ("Test failed in %s:%i\n", func, line);
|
| 65 |
376 |
markom |
report(0xeeeeeeee);
|
| 66 |
344 |
markom |
exit (1);
|
| 67 |
|
|
}
|
| 68 |
|
|
|
| 69 |
|
|
inline void setreg (unsigned long addr, unsigned char value)
|
| 70 |
|
|
{
|
| 71 |
|
|
*((volatile unsigned char *)addr) = value;
|
| 72 |
|
|
}
|
| 73 |
|
|
|
| 74 |
|
|
inline unsigned long getreg (unsigned long addr)
|
| 75 |
|
|
{
|
| 76 |
|
|
return *((volatile unsigned char *)addr);
|
| 77 |
|
|
}
|
| 78 |
|
|
|
| 79 |
409 |
markom |
static volatile int int_cnt = 0;
|
| 80 |
|
|
static volatile unsigned int_iir = 0;
|
| 81 |
|
|
static volatile unsigned int_lsr = 0;
|
| 82 |
|
|
static int int_rbr = 0;
|
| 83 |
|
|
|
| 84 |
344 |
markom |
void interrupt_handler ()
|
| 85 |
|
|
{
|
| 86 |
409 |
markom |
unsigned x;
|
| 87 |
1024 |
simons |
printf ("Int\n");
|
| 88 |
409 |
markom |
report(0xdeaddead);
|
| 89 |
|
|
report(int_iir = getreg (UART_IIR));
|
| 90 |
|
|
report(int_lsr = getreg (UART_LSR));
|
| 91 |
|
|
int_cnt++;
|
| 92 |
|
|
ASSERT (int_iir != 1);
|
| 93 |
|
|
switch (int_iir & 0xf) {
|
| 94 |
1024 |
simons |
case 0x6: printf ("Receiver LS int.\n"); break;
|
| 95 |
|
|
case 0x4: printf ("Received Data available. Expecting %02x, received %02x\n",
|
| 96 |
409 |
markom |
int_rbr, x = getreg(UART_RBR));
|
| 97 |
|
|
ASSERT (x == int_rbr);
|
| 98 |
|
|
report (x);
|
| 99 |
|
|
report (int_rbr);
|
| 100 |
|
|
break;
|
| 101 |
1024 |
simons |
case 0xc: printf ("Character timeout. Expecting %02x, received %02x\n",
|
| 102 |
409 |
markom |
int_rbr, x = getreg(UART_RBR));
|
| 103 |
|
|
ASSERT (x == int_rbr);
|
| 104 |
|
|
report (x);
|
| 105 |
|
|
report (int_rbr);
|
| 106 |
|
|
break;
|
| 107 |
1024 |
simons |
case 0x2: printf ("THR empty.\n"); break;
|
| 108 |
|
|
case 0x0: printf ("Modem Status.\n"); break;
|
| 109 |
409 |
markom |
default:
|
| 110 |
1024 |
simons |
printf ("Invalid iir @ %i\n", __LINE__);
|
| 111 |
409 |
markom |
exit (1);
|
| 112 |
|
|
}
|
| 113 |
|
|
mtspr(SPR_PICSR, 0);
|
| 114 |
344 |
markom |
}
|
| 115 |
|
|
|
| 116 |
409 |
markom |
/* Receives a char and checks for errors */
|
| 117 |
|
|
|
| 118 |
|
|
void recv_char (int ch)
|
| 119 |
|
|
{
|
| 120 |
|
|
unsigned x;
|
| 121 |
|
|
char r;
|
| 122 |
|
|
report (ch);
|
| 123 |
|
|
/* Wait for rx fifo to be */
|
| 124 |
|
|
while (!((x = getreg (UART_LSR)) & LSR_DR));
|
| 125 |
1024 |
simons |
if ((x & (LSR_BREAK|LSR_FE|LSR_PE|LSR_OE)) && !(x & LSR_ERR)) printf ("LSR7 (0x%02x) ERR @ recv_char\n", x);
|
| 126 |
409 |
markom |
ASSERT(!(x & LSR_ERR));
|
| 127 |
|
|
|
| 128 |
1024 |
simons |
printf ("expected %02x, read %02x\n", ch, r = getreg (UART_RBR));
|
| 129 |
409 |
markom |
ASSERT (r == ch); /* compare character */
|
| 130 |
|
|
}
|
| 131 |
|
|
|
| 132 |
|
|
/* Sends a char and checks for errors */
|
| 133 |
|
|
|
| 134 |
493 |
markom |
void send_char_no_wait (int ch)
|
| 135 |
|
|
{
|
| 136 |
|
|
report (ch);
|
| 137 |
|
|
setreg (UART_THR, ch); /* send character */
|
| 138 |
|
|
}
|
| 139 |
|
|
|
| 140 |
409 |
markom |
void send_char (int ch)
|
| 141 |
|
|
{
|
| 142 |
|
|
report (ch);
|
| 143 |
|
|
while (!(getreg (UART_LSR) & LSR_TXFE));
|
| 144 |
|
|
NO_ERROR();
|
| 145 |
|
|
setreg (UART_THR, ch); /* send character */
|
| 146 |
|
|
NO_ERROR();
|
| 147 |
|
|
}
|
| 148 |
|
|
|
| 149 |
|
|
void init_8n1 ()
|
| 150 |
|
|
{
|
| 151 |
|
|
setreg (UART_IER, 0x00); /* disable interrupts */
|
| 152 |
|
|
WAIT();
|
| 153 |
|
|
ASSERT(getreg (UART_IIR) == 0xc1); /* nothing should be happening */
|
| 154 |
|
|
setreg (UART_FCR, 0x07); /* clear RX and TX FIFOs */
|
| 155 |
|
|
setreg (UART_LCR, LCR_DIVL);
|
| 156 |
|
|
setreg (UART_DLH, 2 >> 8);
|
| 157 |
|
|
setreg (UART_DLL, 2 & 0xff);
|
| 158 |
|
|
setreg (UART_LCR, 0x03); /* 8N1 @ 2 */
|
| 159 |
|
|
ASSERT(getreg (UART_LCR) == 0x03);
|
| 160 |
|
|
ASSERT (!(getreg (UART_LSR) & 0x1f));
|
| 161 |
|
|
}
|
| 162 |
|
|
|
| 163 |
344 |
markom |
/* Test reset values and r/w properties of some registers */
|
| 164 |
|
|
|
| 165 |
|
|
void register_test ()
|
| 166 |
|
|
{
|
| 167 |
1024 |
simons |
printf ("register test\n");
|
| 168 |
409 |
markom |
MARK();
|
| 169 |
344 |
markom |
{ /* test reset values */
|
| 170 |
|
|
ASSERT(getreg (UART_RBR) == 0x00); //0
|
| 171 |
|
|
ASSERT(getreg (UART_IER) == 0x00); //1
|
| 172 |
|
|
ASSERT(getreg (UART_IIR) == 0xc1); //2
|
| 173 |
|
|
ASSERT(getreg (UART_LCR) == 0x03); //3
|
| 174 |
|
|
ASSERT(getreg (UART_MCR) == 0x00); //4
|
| 175 |
396 |
markom |
ASSERT(getreg (UART_LSR) == 0x60); //5
|
| 176 |
|
|
ASSERT(getreg (UART_MSR) == 0x00); //6
|
| 177 |
411 |
markom |
ASSERT(getreg (UART_SCR) == 0x00); //7
|
| 178 |
344 |
markom |
|
| 179 |
355 |
markom |
setreg(UART_LCR, LCR_DIVL); //enable latches
|
| 180 |
344 |
markom |
ASSERT(getreg (UART_DLL) == 0x00); //0
|
| 181 |
|
|
ASSERT(getreg (UART_DLH) == 0x00); //1
|
| 182 |
|
|
setreg(UART_LCR, 0x00); //disable latches
|
| 183 |
|
|
}
|
| 184 |
493 |
markom |
setreg(UART_LCR, 0x00); //disable latches igor
|
| 185 |
|
|
setreg(UART_LCR, 0x00); //disable latches
|
| 186 |
|
|
setreg(UART_LCR, 0x00); //disable latches
|
| 187 |
|
|
setreg(UART_LCR, 0x00); //disable latches
|
| 188 |
|
|
setreg(UART_LCR, 0x00); //disable latches
|
| 189 |
344 |
markom |
|
| 190 |
409 |
markom |
MARK();
|
| 191 |
344 |
markom |
{ /* test if status registers are read only */
|
| 192 |
396 |
markom |
unsigned long tmp;
|
| 193 |
344 |
markom |
int i;
|
| 194 |
|
|
tmp = getreg (UART_LSR);
|
| 195 |
|
|
setreg (UART_LSR, ~tmp);
|
| 196 |
|
|
ASSERT(getreg (UART_LSR) == tmp);
|
| 197 |
|
|
|
| 198 |
|
|
for (i = 0; i < 9; i++) {
|
| 199 |
371 |
markom |
setreg (UART_LSR, 1 << i);
|
| 200 |
344 |
markom |
ASSERT(getreg (UART_LSR) == tmp);
|
| 201 |
|
|
}
|
| 202 |
396 |
markom |
|
| 203 |
|
|
tmp = getreg (UART_MSR);
|
| 204 |
344 |
markom |
setreg (UART_MSR, ~tmp);
|
| 205 |
|
|
ASSERT(getreg (UART_MSR) == tmp);
|
| 206 |
|
|
|
| 207 |
|
|
for (i = 0; i < 9; i++) {
|
| 208 |
371 |
markom |
setreg (UART_MSR, 1 << i);
|
| 209 |
344 |
markom |
ASSERT(getreg (UART_MSR) == tmp);
|
| 210 |
396 |
markom |
}
|
| 211 |
344 |
markom |
}
|
| 212 |
396 |
markom |
|
| 213 |
409 |
markom |
MARK();
|
| 214 |
344 |
markom |
{ /* test whether MCR is write only, be careful not to set the loopback bit */
|
| 215 |
396 |
markom |
ASSERT(getreg (UART_MCR) == 0x00);
|
| 216 |
344 |
markom |
setreg (UART_MCR, 0x45);
|
| 217 |
|
|
ASSERT(getreg (UART_MCR) == 0x00);
|
| 218 |
|
|
setreg (UART_MCR, 0xaa);
|
| 219 |
396 |
markom |
ASSERT(getreg (UART_MCR) == 0x00);
|
| 220 |
344 |
markom |
}
|
| 221 |
|
|
ASSERT (!(getreg (UART_LSR) & 0x1f));
|
| 222 |
409 |
markom |
MARK();
|
| 223 |
344 |
markom |
{ /* Test if Divisor latch byte holds the data */
|
| 224 |
|
|
int i;
|
| 225 |
355 |
markom |
setreg(UART_LCR, LCR_DIVL); //enable latches
|
| 226 |
|
|
ASSERT(getreg (UART_LCR) == LCR_DIVL);
|
| 227 |
344 |
markom |
for (i = 0; i < 16; i++) {
|
| 228 |
|
|
unsigned short tmp = 0xdead << i;
|
| 229 |
|
|
setreg (UART_DLH, tmp >> 8);
|
| 230 |
|
|
setreg (UART_DLL, tmp & 0xff);
|
| 231 |
|
|
ASSERT(getreg (UART_DLL) == (tmp & 0xff)); //0
|
| 232 |
|
|
ASSERT(getreg (UART_DLH) == (tmp >> 8)); //1
|
| 233 |
|
|
}
|
| 234 |
493 |
markom |
setreg (UART_DLH, 0xa1); //igor
|
| 235 |
|
|
setreg (UART_DLH, 0xa1); //igor
|
| 236 |
|
|
setreg (UART_DLH, 0xa1); //igor
|
| 237 |
|
|
setreg (UART_DLH, 0xa1); //igor
|
| 238 |
|
|
setreg (UART_DLH, 0xa1); //igor
|
| 239 |
|
|
|
| 240 |
344 |
markom |
ASSERT (!(getreg (UART_LSR) & 0x1f));
|
| 241 |
|
|
for (i = 0; i < 16; i++) {
|
| 242 |
|
|
unsigned short tmp = 0xdead << i;
|
| 243 |
|
|
setreg (UART_DLL, tmp >> 8);
|
| 244 |
|
|
setreg (UART_DLH, tmp & 0xff);
|
| 245 |
|
|
ASSERT(getreg (UART_DLL) == (tmp >> 8)); //1
|
| 246 |
|
|
ASSERT(getreg (UART_DLH) == (tmp & 0xff)); //0
|
| 247 |
|
|
}
|
| 248 |
493 |
markom |
setreg (UART_DLH, 0xa2); //igor
|
| 249 |
|
|
setreg (UART_DLH, 0xa2); //igor
|
| 250 |
|
|
setreg (UART_DLH, 0xa2); //igor
|
| 251 |
|
|
setreg (UART_DLH, 0xa2); //igor
|
| 252 |
|
|
setreg (UART_DLH, 0xa2); //igor
|
| 253 |
|
|
|
| 254 |
344 |
markom |
setreg(UART_LCR, 0x00); //disable latches
|
| 255 |
|
|
ASSERT(getreg (UART_LCR) == 0x00);
|
| 256 |
|
|
ASSERT (!(getreg (UART_LSR) & 0x1f));
|
| 257 |
|
|
}
|
| 258 |
409 |
markom |
MARK();
|
| 259 |
344 |
markom |
{ /* Test LCR, if it holds our data */
|
| 260 |
|
|
int i;
|
| 261 |
|
|
for (i = 0; i < 6; i++) {
|
| 262 |
|
|
unsigned short tmp = (0xde << i) & 0x3f;
|
| 263 |
|
|
setreg (UART_LCR, tmp);
|
| 264 |
|
|
ASSERT(getreg (UART_LCR) == tmp);
|
| 265 |
|
|
}
|
| 266 |
|
|
ASSERT (!(getreg (UART_LSR) & 0x1f));
|
| 267 |
|
|
}
|
| 268 |
493 |
markom |
setreg (UART_LCR, 0xa3); //igor
|
| 269 |
|
|
setreg (UART_LCR, 0xa3); //igor
|
| 270 |
|
|
setreg (UART_LCR, 0xa3); //igor
|
| 271 |
|
|
setreg (UART_LCR, 0xa3); //igor
|
| 272 |
|
|
setreg (UART_LCR, 0xa3); //igor
|
| 273 |
|
|
|
| 274 |
411 |
markom |
MARK ();
|
| 275 |
|
|
|
| 276 |
|
|
{ /* SCR Test :))) */
|
| 277 |
|
|
int i;
|
| 278 |
|
|
setreg (UART_SCR, 0);
|
| 279 |
|
|
ASSERT (getreg (UART_SCR) == 0);
|
| 280 |
|
|
setreg (UART_SCR, 0xff);
|
| 281 |
|
|
ASSERT (getreg (UART_SCR) == 0xff);
|
| 282 |
|
|
for (i = 0; i < 16; i++) {
|
| 283 |
|
|
unsigned char tmp = 0xdead << i;
|
| 284 |
|
|
setreg (UART_SCR, tmp);
|
| 285 |
|
|
ASSERT (getreg (UART_SCR) == tmp);
|
| 286 |
|
|
}
|
| 287 |
|
|
}
|
| 288 |
493 |
markom |
setreg (UART_SCR, 0xa5);//igor
|
| 289 |
|
|
setreg (UART_SCR, 0xa5);//igor
|
| 290 |
|
|
setreg (UART_SCR, 0xa5);//igor
|
| 291 |
|
|
setreg (UART_SCR, 0xa5);//igor
|
| 292 |
|
|
setreg (UART_SCR, 0xa5);//igor
|
| 293 |
|
|
|
| 294 |
409 |
markom |
MARK();
|
| 295 |
344 |
markom |
/* Other registers will be tested later, if they function correctly,
|
| 296 |
|
|
since we cannot test them now, without destroying anything. */
|
| 297 |
|
|
}
|
| 298 |
|
|
|
| 299 |
|
|
/* Initializes uart and sends a few bytes to VAPI. It is then activated and send something back. */
|
| 300 |
|
|
|
| 301 |
|
|
void send_recv_test ()
|
| 302 |
|
|
{
|
| 303 |
|
|
char *s;
|
| 304 |
1024 |
simons |
printf ("send_recv_test\n");
|
| 305 |
344 |
markom |
/* Init */
|
| 306 |
409 |
markom |
MARK();
|
| 307 |
344 |
markom |
|
| 308 |
1024 |
simons |
//printf ("basic\n");
|
| 309 |
355 |
markom |
ASSERT (!(getreg (UART_LSR) & LSR_DR));
|
| 310 |
409 |
markom |
MARK();
|
| 311 |
344 |
markom |
|
| 312 |
|
|
/* Send a string */
|
| 313 |
|
|
s = "send_";
|
| 314 |
|
|
while (*s) {
|
| 315 |
|
|
/* Wait for tx fifo to be empty */
|
| 316 |
409 |
markom |
send_char (*s);
|
| 317 |
371 |
markom |
report((unsigned long)*s);
|
| 318 |
344 |
markom |
s++;
|
| 319 |
|
|
}
|
| 320 |
355 |
markom |
ASSERT (!(getreg (UART_LSR) & LSR_DR));
|
| 321 |
344 |
markom |
s = "test_";
|
| 322 |
|
|
while (*s) {
|
| 323 |
|
|
/* Wait for tx fifo and tx to be empty */
|
| 324 |
355 |
markom |
while (!(getreg (UART_LSR) & LSR_TXE));
|
| 325 |
344 |
markom |
NO_ERROR();
|
| 326 |
|
|
setreg (UART_THR, *s); /* send character */
|
| 327 |
|
|
NO_ERROR();
|
| 328 |
|
|
s++;
|
| 329 |
|
|
}
|
| 330 |
355 |
markom |
ASSERT (!(getreg (UART_LSR) & LSR_DR));
|
| 331 |
409 |
markom |
MARK();
|
| 332 |
344 |
markom |
|
| 333 |
|
|
/* Send characters with delay inbetween */
|
| 334 |
|
|
s = "is_running";
|
| 335 |
|
|
while (*s) {
|
| 336 |
|
|
int i;
|
| 337 |
409 |
markom |
send_char (*s);
|
| 338 |
371 |
markom |
// igor for (i = 0; i < 1600; i++) /* wait at least ten chars before sending next one */
|
| 339 |
396 |
markom |
for (i = 0; i < 16; i++) /* wait at few chars before sending next one */
|
| 340 |
344 |
markom |
asm volatile ("l.nop");
|
| 341 |
|
|
s++;
|
| 342 |
|
|
}
|
| 343 |
|
|
|
| 344 |
409 |
markom |
send_char (0); /* send terminate char */
|
| 345 |
|
|
MARK();
|
| 346 |
355 |
markom |
|
| 347 |
344 |
markom |
/* Receives and compares the string */
|
| 348 |
409 |
markom |
s = "recv";
|
| 349 |
|
|
while (*s) recv_char (*s++);
|
| 350 |
|
|
MARK();
|
| 351 |
1024 |
simons |
printf ("OK\n");
|
| 352 |
344 |
markom |
}
|
| 353 |
|
|
|
| 354 |
355 |
markom |
/* sends break in both directions */
|
| 355 |
|
|
|
| 356 |
|
|
void break_test ()
|
| 357 |
|
|
{
|
| 358 |
409 |
markom |
unsigned x;
|
| 359 |
355 |
markom |
char *s;
|
| 360 |
1024 |
simons |
printf ("break_test\n");
|
| 361 |
355 |
markom |
|
| 362 |
409 |
markom |
MARK();
|
| 363 |
|
|
/* Send a break */
|
| 364 |
355 |
markom |
NO_ERROR();
|
| 365 |
409 |
markom |
MARK();
|
| 366 |
|
|
setreg (UART_LCR, 0x03 | LCR_BREAK); /* 8N1 */
|
| 367 |
|
|
MARK();
|
| 368 |
|
|
send_char ('b'); /* make sure it is recognised as a break */
|
| 369 |
|
|
MARK();
|
| 370 |
|
|
recv_char ('*');
|
| 371 |
|
|
setreg (UART_LCR, 0x03); /* deleting break bit, 8N1 */
|
| 372 |
|
|
MARK();
|
| 373 |
|
|
|
| 374 |
|
|
/* Receive a break */
|
| 375 |
|
|
send_char ('!');
|
| 376 |
|
|
MARK();
|
| 377 |
|
|
while (!((x = getreg (UART_LSR)) & LSR_DR));
|
| 378 |
|
|
/* we should receive zero character with broken frame and break bit should be set */
|
| 379 |
1024 |
simons |
printf("[%x]\n", (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE));
|
| 380 |
423 |
markom |
ASSERT (x == (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE));
|
| 381 |
409 |
markom |
ASSERT (getreg (UART_RBR) == 0);
|
| 382 |
|
|
MARK();
|
| 383 |
|
|
|
| 384 |
|
|
/* Send a # to release break */
|
| 385 |
|
|
setreg (UART_THR, '#');
|
| 386 |
|
|
while (!(getreg (UART_LSR) & LSR_DR));
|
| 387 |
|
|
NO_ERROR(); /* BREAK bit should be cleared now */
|
| 388 |
|
|
ASSERT (getreg (UART_RBR) == '$');
|
| 389 |
|
|
MARK();
|
| 390 |
355 |
markom |
|
| 391 |
|
|
/* Break while sending characters */
|
| 392 |
409 |
markom |
s = "ns";
|
| 393 |
|
|
while (*s) send_char (*s++);
|
| 394 |
355 |
markom |
ASSERT (!(getreg (UART_LSR) & LSR_DR));
|
| 395 |
409 |
markom |
while (!(getreg (UART_LSR) & LSR_TXE)); /* Wait till we send everything */
|
| 396 |
361 |
markom |
/* this should break the * char, so it should not be received */
|
| 397 |
355 |
markom |
setreg (UART_THR, '*');
|
| 398 |
409 |
markom |
setreg (UART_LCR, 0x3 | LCR_BREAK);
|
| 399 |
|
|
MARK();
|
| 400 |
|
|
|
| 401 |
|
|
/* Drop the break, when we get acknowledge */
|
| 402 |
|
|
recv_char ('?');
|
| 403 |
|
|
setreg (UART_LCR, 0x3);
|
| 404 |
355 |
markom |
NO_ERROR();
|
| 405 |
409 |
markom |
MARK();
|
| 406 |
355 |
markom |
|
| 407 |
409 |
markom |
/* Receive a break */
|
| 408 |
|
|
send_char ('#');
|
| 409 |
|
|
while (!((x = getreg (UART_LSR)) & LSR_DR));
|
| 410 |
|
|
/* we should receive zero character with broken frame and break bit
|
| 411 |
|
|
should not be set, because we cleared it */
|
| 412 |
1024 |
simons |
printf("[%x:%x]\n", x, (LSR_DR | LSR_BREAK |LSR_ERR | LSR_TXFE | LSR_TXE));
|
| 413 |
423 |
markom |
ASSERT (x == (LSR_DR | LSR_BREAK |LSR_ERR | LSR_TXFE | LSR_TXE));
|
| 414 |
409 |
markom |
ASSERT (getreg (UART_RBR) == 0);
|
| 415 |
|
|
MARK();
|
| 416 |
|
|
send_char ('?');
|
| 417 |
|
|
MARK();
|
| 418 |
|
|
while (!(getreg (UART_LSR) & LSR_DR));
|
| 419 |
|
|
recv_char ('!');
|
| 420 |
1024 |
simons |
printf ("OK\n");
|
| 421 |
409 |
markom |
}
|
| 422 |
|
|
|
| 423 |
|
|
/* Tries to send data in different modes in both directions */
|
| 424 |
|
|
|
| 425 |
|
|
/* Utility function, that tests current configuration */
|
| 426 |
|
|
void test_mode (int nbits)
|
| 427 |
|
|
{
|
| 428 |
|
|
unsigned mask = (1 << nbits) - 1;
|
| 429 |
|
|
send_char (0x55);
|
| 430 |
|
|
#if DETAILED
|
| 431 |
|
|
send_char (0x55);
|
| 432 |
|
|
recv_char (0x55 & mask);
|
| 433 |
|
|
#endif
|
| 434 |
|
|
recv_char (0x55 & mask);
|
| 435 |
|
|
send_char ('a'); // 0x61
|
| 436 |
|
|
#if DETAILED
|
| 437 |
|
|
send_char ('a'); // 0x61
|
| 438 |
|
|
recv_char ('a' & mask);
|
| 439 |
|
|
#endif
|
| 440 |
|
|
recv_char ('a' & mask);
|
| 441 |
|
|
}
|
| 442 |
|
|
|
| 443 |
|
|
void different_modes_test ()
|
| 444 |
|
|
{
|
| 445 |
|
|
int speed, parity, length;
|
| 446 |
1024 |
simons |
printf ("different modes test\n");
|
| 447 |
409 |
markom |
init_8n1();
|
| 448 |
|
|
|
| 449 |
|
|
/* Init */
|
| 450 |
|
|
MARK();
|
| 451 |
|
|
ASSERT(getreg (UART_IIR) == 0xc1); /* nothing should be happening */
|
| 452 |
|
|
MARK();
|
| 453 |
|
|
|
| 454 |
|
|
/* Test different speeds */
|
| 455 |
|
|
for (speed = 1; speed < 5; speed++) {
|
| 456 |
|
|
setreg (UART_LCR, LCR_DIVL);
|
| 457 |
|
|
setreg (UART_DLH, speed >> 8);
|
| 458 |
|
|
setreg (UART_DLL, speed & 0xff);
|
| 459 |
|
|
setreg (UART_LCR, 0x03); /* 8N1 @ 10 => 160 instructions for one cycle */
|
| 460 |
|
|
test_mode (8);
|
| 461 |
|
|
MARK();
|
| 462 |
355 |
markom |
}
|
| 463 |
409 |
markom |
MARK();
|
| 464 |
|
|
|
| 465 |
|
|
setreg (UART_LCR, LCR_DIVL);
|
| 466 |
|
|
setreg (UART_DLH, 1 >> 8);
|
| 467 |
|
|
setreg (UART_DLL, 1 & 0xff);
|
| 468 |
|
|
MARK();
|
| 469 |
|
|
|
| 470 |
|
|
/* Test all parity modes with different char lengths */
|
| 471 |
|
|
for (parity = 0; parity < 8; parity++)
|
| 472 |
|
|
for (length = 0; length < 4; length++) {
|
| 473 |
|
|
setreg (UART_LCR, length | (0 << 2) | (parity << 3));
|
| 474 |
|
|
test_mode (5 + length);
|
| 475 |
|
|
MARK();
|
| 476 |
|
|
}
|
| 477 |
|
|
MARK();
|
| 478 |
|
|
|
| 479 |
|
|
/* Test configuration, if we have >1 stop bits */
|
| 480 |
|
|
for (length = 0; length < 4; length++) {
|
| 481 |
|
|
setreg (UART_LCR, length | (1 << 2) | (0 << 3));
|
| 482 |
|
|
test_mode (5 + length);
|
| 483 |
|
|
MARK();
|
| 484 |
|
|
}
|
| 485 |
|
|
MARK();
|
| 486 |
|
|
|
| 487 |
|
|
/* Restore normal mode */
|
| 488 |
411 |
markom |
send_char ('T');
|
| 489 |
|
|
while (getreg (UART_LSR) != 0x60); /* Wait for THR to be empty */
|
| 490 |
409 |
markom |
setreg (UART_LCR, LCR_DIVL);
|
| 491 |
|
|
setreg (UART_DLH, 2 >> 8);
|
| 492 |
|
|
setreg (UART_DLL, 2 & 0xff);
|
| 493 |
|
|
setreg (UART_LCR, 0x03); /* 8N1 @ 2 */
|
| 494 |
|
|
MARK();
|
| 495 |
423 |
markom |
while (!(getreg (UART_LSR) & 1)); /* Receive 'x' char */
|
| 496 |
|
|
getreg (UART_RBR);
|
| 497 |
|
|
MARK();
|
| 498 |
411 |
markom |
|
| 499 |
|
|
send_char ('T');
|
| 500 |
|
|
while (getreg (UART_LSR) != 0x60); /* Wait for THR to be empty */
|
| 501 |
|
|
MARK();
|
| 502 |
1024 |
simons |
printf ("OK\n");
|
| 503 |
355 |
markom |
}
|
| 504 |
|
|
|
| 505 |
409 |
markom |
/* Test various FIFO levels, break and framing error interrupt, etc */
|
| 506 |
|
|
|
| 507 |
|
|
void interrupt_test ()
|
| 508 |
344 |
markom |
{
|
| 509 |
409 |
markom |
int i;
|
| 510 |
1024 |
simons |
printf ("interrupt_test\n");
|
| 511 |
409 |
markom |
/* Configure UART for interrupt mode */
|
| 512 |
|
|
ASSERT(getreg (UART_IIR) == 0xc1); /* nothing should be happening */
|
| 513 |
|
|
setreg (UART_LCR, LCR_DIVL);
|
| 514 |
|
|
setreg (UART_DLH, 6 >> 8); /* Set relatively slow speed, so we can hanlde interrupts properly */
|
| 515 |
|
|
setreg (UART_DLL, 6 & 0xff);
|
| 516 |
411 |
markom |
setreg (UART_LCR, 0x03); /* 8N1 @ 6 */
|
| 517 |
409 |
markom |
|
| 518 |
423 |
markom |
ASSERT (int_cnt == 0); /* We should not have got any interrupts before this test */
|
| 519 |
493 |
markom |
setreg (UART_FCR, 0x01); /* Set trigger level = 1 char, fifo should not be reset */
|
| 520 |
409 |
markom |
setreg (UART_IER, 0x07); /* Enable interrupts: line status, THR empty, data ready */
|
| 521 |
423 |
markom |
|
| 522 |
|
|
while (!int_cnt); /* Clear previous THR interrupt */
|
| 523 |
|
|
ASSERT (--int_cnt == 0);
|
| 524 |
|
|
ASSERT (int_iir == 0xc2);
|
| 525 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 526 |
|
|
MARK();
|
| 527 |
|
|
|
| 528 |
409 |
markom |
/* I am configured - start interrupt test */
|
| 529 |
|
|
send_char ('I');
|
| 530 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 531 |
|
|
ASSERT (--int_cnt == 0);
|
| 532 |
|
|
ASSERT (int_iir == 0xc2);
|
| 533 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 534 |
|
|
MARK();
|
| 535 |
|
|
|
| 536 |
|
|
int_rbr = '0';
|
| 537 |
|
|
while (!int_cnt); /* Wait for DR */
|
| 538 |
|
|
ASSERT (--int_cnt == 0);
|
| 539 |
|
|
ASSERT (int_iir == 0xc4);
|
| 540 |
|
|
ASSERT (int_lsr == 0x61);
|
| 541 |
|
|
ASSERT (int_cnt == 0); /* no interrupts should be pending */
|
| 542 |
|
|
MARK();
|
| 543 |
|
|
|
| 544 |
|
|
setreg (UART_FCR, 0x41); /* Set trigger level = 4 chars, fifo should not be reset */
|
| 545 |
|
|
|
| 546 |
|
|
/* Everything ok here, send me 4 more */
|
| 547 |
|
|
send_char ('I');
|
| 548 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 549 |
|
|
ASSERT (--int_cnt == 0);
|
| 550 |
|
|
ASSERT (int_iir == 0xc2);
|
| 551 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 552 |
|
|
MARK();
|
| 553 |
|
|
|
| 554 |
|
|
int_rbr = '1';
|
| 555 |
|
|
while (!int_cnt); /* Wait for DR */
|
| 556 |
|
|
ASSERT (--int_cnt == 0);
|
| 557 |
|
|
ASSERT (int_iir == 0xc4);
|
| 558 |
|
|
ASSERT (int_lsr == 0x61);
|
| 559 |
|
|
MARK();
|
| 560 |
|
|
|
| 561 |
|
|
setreg (UART_FCR, 0x81); /* Set trigger level = 8 chars, fifo should not be reset */
|
| 562 |
|
|
|
| 563 |
|
|
/* Everything ok here, send me 5 more */
|
| 564 |
|
|
send_char ('I');
|
| 565 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 566 |
|
|
ASSERT (--int_cnt == 0);
|
| 567 |
|
|
ASSERT (int_iir == 0xc2);
|
| 568 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 569 |
|
|
MARK();
|
| 570 |
|
|
|
| 571 |
|
|
int_rbr = '2';
|
| 572 |
|
|
while (!int_cnt); /* Wait for DR */
|
| 573 |
|
|
ASSERT (--int_cnt == 0);
|
| 574 |
|
|
ASSERT (int_iir == 0xc4);
|
| 575 |
|
|
ASSERT (int_lsr == 0x61);
|
| 576 |
|
|
MARK();
|
| 577 |
|
|
|
| 578 |
|
|
setreg (UART_FCR, 0xc1); /* Set trigger level = 14 chars, fifo should not be reset */
|
| 579 |
|
|
|
| 580 |
|
|
/* Everything ok here, send me 7 more */
|
| 581 |
|
|
send_char ('I');
|
| 582 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 583 |
|
|
ASSERT (--int_cnt == 0);
|
| 584 |
|
|
ASSERT (int_iir == 0xc2);
|
| 585 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 586 |
|
|
MARK();
|
| 587 |
|
|
|
| 588 |
|
|
int_rbr = '3';
|
| 589 |
|
|
while (!int_cnt); /* Wait for DR */
|
| 590 |
|
|
ASSERT (--int_cnt == 0);
|
| 591 |
|
|
ASSERT (int_iir == 0xc4);
|
| 592 |
|
|
ASSERT (int_lsr == 0x61);
|
| 593 |
|
|
MARK();
|
| 594 |
|
|
|
| 595 |
|
|
/* Everything ok here, send me 4 more - fifo should be full OE should occur */
|
| 596 |
|
|
setreg (UART_IER, 0x06); /* Enable interrupts: line status, THR empty */
|
| 597 |
|
|
send_char ('I');
|
| 598 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 599 |
|
|
ASSERT (--int_cnt == 0);
|
| 600 |
|
|
ASSERT (int_iir == 0xc2);
|
| 601 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 602 |
|
|
MARK();
|
| 603 |
|
|
|
| 604 |
|
|
while (!int_cnt); /* Wait for OE */
|
| 605 |
|
|
ASSERT (--int_cnt == 0);
|
| 606 |
|
|
ASSERT (int_iir == 0xc6);
|
| 607 |
|
|
ASSERT (int_lsr == 0xe3); /* OE flag should be set */
|
| 608 |
|
|
ASSERT (getreg (UART_LSR) == 0x61); /* LSR should be cleared by previous read */
|
| 609 |
|
|
ASSERT (getreg (UART_IIR) == 0xc1); /* No interrupts should be pending */
|
| 610 |
|
|
MARK();
|
| 611 |
|
|
|
| 612 |
|
|
/* Check if we got everything */
|
| 613 |
|
|
ASSERT (int_cnt == 0); /* no interrupts should be pending */
|
| 614 |
|
|
for (i = 0; i < 3; i++) {
|
| 615 |
|
|
recv_char ("456"[i]); /* WARNING: read should not cause interrupt even if we step over trigger */
|
| 616 |
|
|
MARK ();
|
| 617 |
|
|
}
|
| 618 |
|
|
/* It is now safe to enable data ready interrupt */
|
| 619 |
|
|
setreg (UART_IER, 0x07); /* Enable interrupts: line status, THR empty, data ready */
|
| 620 |
|
|
|
| 621 |
|
|
/* Check if we got everything */
|
| 622 |
|
|
for (i = 0; i < 13; i++) {
|
| 623 |
|
|
recv_char ("789abcdefghij"[i]); /* WARNING: read should not cause interrupt even if we step over trigger */
|
| 624 |
|
|
MARK ();
|
| 625 |
|
|
}
|
| 626 |
|
|
|
| 627 |
|
|
ASSERT (int_cnt == 0); /* no interrupts should be pending */
|
| 628 |
|
|
ASSERT (getreg (UART_LSR) == 0x60); /* FIFO should be empty */
|
| 629 |
|
|
|
| 630 |
|
|
getreg (UART_RBR); /* check for FIFO counter overflow - fifo must still be empty */
|
| 631 |
|
|
ASSERT (getreg (UART_LSR) == 0x60); /* FIFO should be empty */
|
| 632 |
|
|
|
| 633 |
|
|
/* check for break interrupt */
|
| 634 |
|
|
send_char ('I');
|
| 635 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 636 |
|
|
ASSERT (--int_cnt == 0);
|
| 637 |
|
|
ASSERT (int_iir == 0xc2);
|
| 638 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 639 |
|
|
MARK();
|
| 640 |
|
|
|
| 641 |
|
|
while (!int_cnt); /* Wait for break interrupt */
|
| 642 |
|
|
ASSERT (--int_cnt == 0);
|
| 643 |
|
|
ASSERT (int_iir == 0xc6);
|
| 644 |
423 |
markom |
ASSERT (int_lsr == 0xf1); /* BE flag should be set */
|
| 645 |
409 |
markom |
ASSERT (getreg (UART_LSR) == 0x61); /* BE flag should be cleared by previous read */
|
| 646 |
411 |
markom |
MARK();
|
| 647 |
409 |
markom |
recv_char (0);
|
| 648 |
|
|
MARK();
|
| 649 |
|
|
|
| 650 |
|
|
send_char ('B'); /* Release break */
|
| 651 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 652 |
|
|
ASSERT (--int_cnt == 0);
|
| 653 |
|
|
ASSERT (int_iir == 0xc2);
|
| 654 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 655 |
|
|
MARK();
|
| 656 |
|
|
/* Wait for acknowledge */
|
| 657 |
|
|
int_rbr = '$';
|
| 658 |
411 |
markom |
while (!int_cnt); /* Wait for timeout */
|
| 659 |
409 |
markom |
ASSERT (--int_cnt == 0);
|
| 660 |
411 |
markom |
ASSERT (int_iir == 0xcc);
|
| 661 |
409 |
markom |
ASSERT (int_lsr == 0x61);
|
| 662 |
|
|
MARK();
|
| 663 |
|
|
|
| 664 |
|
|
/* TODO: Check for parity error */
|
| 665 |
|
|
/* TODO: Check for frame error */
|
| 666 |
|
|
|
| 667 |
|
|
/* Check for timeout */
|
| 668 |
|
|
send_char ('I');
|
| 669 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 670 |
|
|
ASSERT (--int_cnt == 0);
|
| 671 |
|
|
ASSERT (int_iir == 0xc2);
|
| 672 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 673 |
|
|
MARK();
|
| 674 |
|
|
|
| 675 |
|
|
int_rbr = 'T';
|
| 676 |
|
|
while (!int_cnt); /* Wait for timeout */
|
| 677 |
|
|
ASSERT (--int_cnt == 0);
|
| 678 |
|
|
ASSERT (int_iir == 0xcc); /* timeout interrupt occured */
|
| 679 |
|
|
ASSERT (int_lsr == 0x61); /* DR flag should be set */
|
| 680 |
|
|
ASSERT (getreg (UART_LSR) == 0x60); /* DR flag should be cleared - timeout occurred */
|
| 681 |
|
|
MARK();
|
| 682 |
|
|
|
| 683 |
|
|
send_char ('T');
|
| 684 |
411 |
markom |
while (!int_cnt); /* Wait for THR to be empty */
|
| 685 |
|
|
ASSERT (--int_cnt == 0);
|
| 686 |
|
|
ASSERT (int_iir == 0xc2);
|
| 687 |
|
|
ASSERT ((int_lsr & 0xbe) == 0x20);
|
| 688 |
|
|
MARK();
|
| 689 |
409 |
markom |
|
| 690 |
|
|
setreg (UART_IER, 0x00); /* Disable interrupts */
|
| 691 |
|
|
ASSERT (int_cnt == 0); /* no interrupts should be pending */
|
| 692 |
411 |
markom |
NO_ERROR ();
|
| 693 |
409 |
markom |
|
| 694 |
411 |
markom |
while (getreg (UART_LSR) != 0x60); /* wait till we sent everynthing and then change mode */
|
| 695 |
|
|
setreg (UART_LCR, LCR_DIVL);
|
| 696 |
|
|
setreg (UART_DLH, 2 >> 8); /* Set relatively slow speed, so we can hanlde interrupts properly */
|
| 697 |
|
|
setreg (UART_DLL, 2 & 0xff);
|
| 698 |
|
|
setreg (UART_LCR, 0x03); /* 8N1 @ 2 */
|
| 699 |
|
|
send_char ('T');
|
| 700 |
409 |
markom |
|
| 701 |
|
|
MARK ();
|
| 702 |
1024 |
simons |
printf ("OK\n");
|
| 703 |
344 |
markom |
}
|
| 704 |
|
|
|
| 705 |
411 |
markom |
/* Test if all control bits are set correctly. Lot of this was already tested
|
| 706 |
|
|
elsewhere and tests are not duplicated. */
|
| 707 |
|
|
|
| 708 |
|
|
void control_register_test ()
|
| 709 |
|
|
{
|
| 710 |
|
|
/* RBR already tested in send_recv_test() */
|
| 711 |
|
|
/* THR already tested in send_recv_test() */
|
| 712 |
|
|
/* IER already tested in interrupt_test() */
|
| 713 |
|
|
/* IIR already tested in interrupt_test() */
|
| 714 |
|
|
/* FCR0 - uart 16450 specific, not tested */
|
| 715 |
|
|
|
| 716 |
|
|
/* FCR1 - reset rx FIFO */
|
| 717 |
|
|
send_char ('*');
|
| 718 |
|
|
NO_ERROR ();
|
| 719 |
|
|
while (!(getreg (UART_LSR) & 0x01)); /* Wait for data ready */
|
| 720 |
|
|
setreg (UART_FCR, 2); /* Clears rx fifo */
|
| 721 |
|
|
ASSERT (getreg (UART_LSR) == 0x60); /* nothing happening */
|
| 722 |
|
|
send_char ('!');
|
| 723 |
|
|
recv_char ('!');
|
| 724 |
|
|
MARK ();
|
| 725 |
|
|
|
| 726 |
|
|
/* FCR2 - reset tx FIFO */
|
| 727 |
493 |
markom |
send_char_no_wait ('1');
|
| 728 |
|
|
send_char_no_wait ('2');
|
| 729 |
|
|
// send_char ('1');
|
| 730 |
|
|
// send_char ('2');
|
| 731 |
411 |
markom |
setreg (UART_FCR, 4); /* Should clear '2' from fifo, but '1' should be sent OK */
|
| 732 |
|
|
ASSERT (getreg (UART_LSR) == 0x00); /* we should still be sending '1' */
|
| 733 |
|
|
NO_ERROR();
|
| 734 |
|
|
send_char ('*');
|
| 735 |
|
|
recv_char ('*');
|
| 736 |
|
|
MARK ();
|
| 737 |
|
|
|
| 738 |
|
|
/* LCR already tested in different_modes_test () */
|
| 739 |
|
|
/* TODO: MSR */
|
| 740 |
|
|
/* LSR already tested in different_modes_test () and interrupt_test() */
|
| 741 |
|
|
/* SCR already tested in register_test () */
|
| 742 |
|
|
|
| 743 |
|
|
MARK ();
|
| 744 |
1024 |
simons |
printf ("OK\n");
|
| 745 |
411 |
markom |
}
|
| 746 |
|
|
|
| 747 |
|
|
/* Tests parity error and frane error behaviour */
|
| 748 |
|
|
|
| 749 |
|
|
void line_error_test ()
|
| 750 |
|
|
{
|
| 751 |
1024 |
simons |
printf ("line_error_test\n");
|
| 752 |
411 |
markom |
|
| 753 |
|
|
/* Test framing error if we change speed */
|
| 754 |
|
|
setreg (UART_LCR, LCR_DIVL);
|
| 755 |
|
|
setreg (UART_DLH, 2 >> 8);
|
| 756 |
|
|
setreg (UART_DLL, 2 & 0xff);
|
| 757 |
|
|
setreg (UART_LCR, 0x03); /* 8N1 @ 2 */
|
| 758 |
|
|
MARK();
|
| 759 |
|
|
|
| 760 |
|
|
send_char ('c');
|
| 761 |
|
|
ASSERT (int_cnt == 0);
|
| 762 |
|
|
setreg (UART_IER, 0x04); /* Enable interrupts: line status */
|
| 763 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 764 |
|
|
ASSERT (--int_cnt == 0);
|
| 765 |
|
|
ASSERT (int_iir == 0xc6);
|
| 766 |
|
|
ASSERT (int_lsr == 0xe9); /* Framing error and FIFO error */
|
| 767 |
|
|
getreg (UART_RBR); /* Ignore the data */
|
| 768 |
|
|
MARK ();
|
| 769 |
|
|
recv_char ('b');
|
| 770 |
|
|
MARK ();
|
| 771 |
|
|
|
| 772 |
|
|
#if COMPLETE
|
| 773 |
|
|
/* Test framing error if we change stop bits */
|
| 774 |
|
|
send_char ('*');
|
| 775 |
|
|
while (getreg (UART_LSR)); /* wait till we sent everynthing and then change mode */
|
| 776 |
|
|
setreg (UART_LCR, 0x07); /* 8N2 */
|
| 777 |
|
|
send_char ('*');
|
| 778 |
|
|
MARK ();
|
| 779 |
|
|
|
| 780 |
|
|
ASSERT (int_cnt == 0);
|
| 781 |
|
|
setreg (UART_IER, 0x04); /* Enable interrupts: line status */
|
| 782 |
|
|
while (!int_cnt); /* Wait for THR to be empty */
|
| 783 |
|
|
ASSERT (--int_cnt == 0);
|
| 784 |
|
|
ASSERT (int_iir == 0xc6);
|
| 785 |
|
|
ASSERT (int_lsr == 0xe9); /* Framing error and FIFO error */
|
| 786 |
|
|
getreg (UART_RBR); /* Ignore the data */
|
| 787 |
|
|
recv_char ('b');
|
| 788 |
|
|
MARK();
|
| 789 |
|
|
#endif
|
| 790 |
|
|
|
| 791 |
|
|
MARK ();
|
| 792 |
1024 |
simons |
printf ("OK\n");
|
| 793 |
411 |
markom |
}
|
| 794 |
|
|
|
| 795 |
344 |
markom |
int main ()
|
| 796 |
|
|
{
|
| 797 |
|
|
/* Use our low priority interrupt handler */
|
| 798 |
600 |
simons |
excpt_int = (unsigned long)interrupt_handler;
|
| 799 |
344 |
markom |
|
| 800 |
|
|
/* Enable interrupts */
|
| 801 |
600 |
simons |
mtspr (SPR_SR, mfspr(SPR_SR) | SPR_SR_IEE);
|
| 802 |
411 |
markom |
mtspr (SPR_PICMR, mfspr(SPR_PICMR) | (0x00000001L << UART_INT_LINE));
|
| 803 |
409 |
markom |
|
| 804 |
515 |
markom |
register_test ();
|
| 805 |
409 |
markom |
init_8n1 ();
|
| 806 |
515 |
markom |
send_recv_test ();
|
| 807 |
|
|
break_test ();
|
| 808 |
|
|
different_modes_test ();
|
| 809 |
423 |
markom |
interrupt_test ();
|
| 810 |
515 |
markom |
control_register_test ();
|
| 811 |
|
|
line_error_test ();
|
| 812 |
411 |
markom |
|
| 813 |
|
|
/* loopback_test ();
|
| 814 |
344 |
markom |
modem_test ();
|
| 815 |
|
|
modem_error_test ();*/
|
| 816 |
411 |
markom |
recv_char ('@');
|
| 817 |
1024 |
simons |
printf ("ALL TESTS PASSED\n");
|
| 818 |
344 |
markom |
return 0;
|
| 819 |
|
|
}
|