OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [testbench/] [acv_uart.c] - Diff between revs 997 and 1024

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 997 Rev 1024
Line 48... Line 48...
/* Waits a few cycles that uart can prepare its data */
/* Waits a few cycles that uart can prepare its data */
#define WAIT() {asm ("l.nop");asm ("l.nop");asm ("l.nop");asm ("l.nop");}
#define WAIT() {asm ("l.nop");asm ("l.nop");asm ("l.nop");asm ("l.nop");}
/* fails if there is an error */
/* fails if there is an error */
#define NO_ERROR() { unsigned x = getreg (UART_LSR); if ((x & (LSR_BREAK|LSR_FE|LSR_PE|LSR_OE)) && !(x & LSR_ERR)) \
#define NO_ERROR() { unsigned x = getreg (UART_LSR); if ((x & (LSR_BREAK|LSR_FE|LSR_PE|LSR_OE)) && !(x & LSR_ERR)) \
printf ("LSR7 (0x%02x) ERR @ %i\n", x, __LINE__); ASSERT(!(x & LSR_ERR) && ((x & 0x60) != 0x40));}
printf ("LSR7 (0x%02x) ERR @ %i\n", x, __LINE__); ASSERT(!(x & LSR_ERR) && ((x & 0x60) != 0x40));}
#define MARK() PRINTF ("Passed line %i\n", __LINE__)
#define MARK() printf ("Passed line %i\n", __LINE__)
 
 
#ifndef __LINE__
#ifndef __LINE__
#define __LINE__  0
#define __LINE__  0
#endif
#endif
 
 
void fail (char *func, int line)
void fail (char *func, int line)
{
{
#ifndef __FUNCTION__
#ifndef __FUNCTION__
#define __FUNCTION__ "?"
#define __FUNCTION__ "?"
#endif
#endif
  PRINTF ("Test failed in %s:%i\n", func, line);
  printf ("Test failed in %s:%i\n", func, line);
  report(0xeeeeeeee);
  report(0xeeeeeeee);
  exit (1);
  exit (1);
}
}
 
 
inline void setreg (unsigned long addr, unsigned char value)
inline void setreg (unsigned long addr, unsigned char value)
Line 82... Line 82...
static int int_rbr = 0;
static int int_rbr = 0;
 
 
void interrupt_handler ()
void interrupt_handler ()
{
{
  unsigned x;
  unsigned x;
  PRINTF ("Int\n");
  printf ("Int\n");
  report(0xdeaddead);
  report(0xdeaddead);
  report(int_iir = getreg (UART_IIR));
  report(int_iir = getreg (UART_IIR));
  report(int_lsr = getreg (UART_LSR));
  report(int_lsr = getreg (UART_LSR));
  int_cnt++;
  int_cnt++;
  ASSERT (int_iir != 1);
  ASSERT (int_iir != 1);
  switch (int_iir & 0xf) {
  switch (int_iir & 0xf) {
    case 0x6: PRINTF ("Receiver LS int.\n"); break;
    case 0x6: printf ("Receiver LS int.\n"); break;
    case 0x4: PRINTF ("Received Data available. Expecting %02x, received %02x\n",
    case 0x4: printf ("Received Data available. Expecting %02x, received %02x\n",
                        int_rbr, x = getreg(UART_RBR));
                        int_rbr, x = getreg(UART_RBR));
              ASSERT (x == int_rbr);
              ASSERT (x == int_rbr);
              report (x);
              report (x);
              report (int_rbr);
              report (int_rbr);
              break;
              break;
    case 0xc: PRINTF ("Character timeout. Expecting %02x, received %02x\n",
    case 0xc: printf ("Character timeout. Expecting %02x, received %02x\n",
                        int_rbr, x = getreg(UART_RBR));
                        int_rbr, x = getreg(UART_RBR));
              ASSERT (x == int_rbr);
              ASSERT (x == int_rbr);
              report (x);
              report (x);
              report (int_rbr);
              report (int_rbr);
              break;
              break;
    case 0x2: PRINTF ("THR empty.\n"); break;
    case 0x2: printf ("THR empty.\n"); break;
    case 0x0: PRINTF ("Modem Status.\n"); break;
    case 0x0: printf ("Modem Status.\n"); break;
    default:
    default:
      PRINTF ("Invalid iir @ %i\n", __LINE__);
      printf ("Invalid iir @ %i\n", __LINE__);
      exit (1);
      exit (1);
  }
  }
  mtspr(SPR_PICSR, 0);
  mtspr(SPR_PICSR, 0);
}
}
 
 
Line 120... Line 120...
  unsigned x;
  unsigned x;
  char r;
  char r;
  report (ch);
  report (ch);
  /* Wait for rx fifo to be  */
  /* Wait for rx fifo to be  */
  while (!((x = getreg (UART_LSR)) & LSR_DR));
  while (!((x = getreg (UART_LSR)) & LSR_DR));
  if ((x & (LSR_BREAK|LSR_FE|LSR_PE|LSR_OE)) && !(x & LSR_ERR)) PRINTF ("LSR7 (0x%02x) ERR @ recv_char\n", x);
  if ((x & (LSR_BREAK|LSR_FE|LSR_PE|LSR_OE)) && !(x & LSR_ERR)) printf ("LSR7 (0x%02x) ERR @ recv_char\n", x);
  ASSERT(!(x & LSR_ERR));
  ASSERT(!(x & LSR_ERR));
 
 
  PRINTF ("expected %02x, read %02x\n", ch, r = getreg (UART_RBR));
  printf ("expected %02x, read %02x\n", ch, r = getreg (UART_RBR));
  ASSERT (r == ch); /* compare character */
  ASSERT (r == ch); /* compare character */
}
}
 
 
/* Sends a char and checks for errors */
/* Sends a char and checks for errors */
 
 
Line 162... Line 162...
 
 
/* Test reset values and r/w properties of some registers */
/* Test reset values and r/w properties of some registers */
 
 
void register_test ()
void register_test ()
{
{
  PRINTF ("register test\n");
  printf ("register test\n");
  MARK();
  MARK();
  { /* test reset values */
  { /* test reset values */
    ASSERT(getreg (UART_RBR) == 0x00); //0
    ASSERT(getreg (UART_RBR) == 0x00); //0
    ASSERT(getreg (UART_IER) == 0x00); //1
    ASSERT(getreg (UART_IER) == 0x00); //1
    ASSERT(getreg (UART_IIR) == 0xc1); //2
    ASSERT(getreg (UART_IIR) == 0xc1); //2
Line 299... Line 299...
/* Initializes uart and sends a few bytes to VAPI. It is then activated and send something back. */
/* Initializes uart and sends a few bytes to VAPI. It is then activated and send something back. */
 
 
void send_recv_test ()
void send_recv_test ()
{
{
  char *s;
  char *s;
  PRINTF ("send_recv_test\n");
  printf ("send_recv_test\n");
  /* Init */
  /* Init */
  MARK();
  MARK();
 
 
  //PRINTF ("basic\n");
  //printf ("basic\n");
  ASSERT (!(getreg (UART_LSR) & LSR_DR));
  ASSERT (!(getreg (UART_LSR) & LSR_DR));
  MARK();
  MARK();
 
 
  /* Send a string */
  /* Send a string */
  s = "send_";
  s = "send_";
Line 346... Line 346...
 
 
  /* Receives and compares the string */
  /* Receives and compares the string */
  s = "recv";
  s = "recv";
  while (*s) recv_char (*s++);
  while (*s) recv_char (*s++);
  MARK();
  MARK();
  PRINTF ("OK\n");
  printf ("OK\n");
}
}
 
 
/* sends break in both directions */
/* sends break in both directions */
 
 
void break_test ()
void break_test ()
{
{
  unsigned x;
  unsigned x;
  char *s;
  char *s;
  PRINTF ("break_test\n");
  printf ("break_test\n");
 
 
  MARK();
  MARK();
  /* Send a break */
  /* Send a break */
  NO_ERROR();
  NO_ERROR();
  MARK();
  MARK();
Line 374... Line 374...
  /* Receive a break */
  /* Receive a break */
  send_char ('!');
  send_char ('!');
  MARK();
  MARK();
  while (!((x = getreg (UART_LSR)) & LSR_DR));
  while (!((x = getreg (UART_LSR)) & LSR_DR));
  /* we should receive zero character with broken frame and break bit should be set */
  /* we should receive zero character with broken frame and break bit should be set */
  PRINTF("[%x]\n", (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE));
  printf("[%x]\n", (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE));
  ASSERT (x == (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE));
  ASSERT (x == (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE));
  ASSERT (getreg (UART_RBR) == 0);
  ASSERT (getreg (UART_RBR) == 0);
  MARK();
  MARK();
 
 
  /* Send a # to release break */
  /* Send a # to release break */
Line 407... Line 407...
  /* Receive a break */
  /* Receive a break */
  send_char ('#');
  send_char ('#');
  while (!((x = getreg (UART_LSR)) & LSR_DR));
  while (!((x = getreg (UART_LSR)) & LSR_DR));
  /* we should receive zero character with broken frame and break bit
  /* we should receive zero character with broken frame and break bit
     should not be set, because we cleared it */
     should not be set, because we cleared it */
  PRINTF("[%x:%x]\n", x, (LSR_DR | LSR_BREAK |LSR_ERR | LSR_TXFE | LSR_TXE));
  printf("[%x:%x]\n", x, (LSR_DR | LSR_BREAK |LSR_ERR | LSR_TXFE | LSR_TXE));
  ASSERT (x == (LSR_DR | LSR_BREAK |LSR_ERR | LSR_TXFE | LSR_TXE));
  ASSERT (x == (LSR_DR | LSR_BREAK |LSR_ERR | LSR_TXFE | LSR_TXE));
  ASSERT (getreg (UART_RBR) == 0);
  ASSERT (getreg (UART_RBR) == 0);
  MARK();
  MARK();
  send_char ('?');
  send_char ('?');
  MARK();
  MARK();
  while (!(getreg (UART_LSR) & LSR_DR));
  while (!(getreg (UART_LSR) & LSR_DR));
  recv_char ('!');
  recv_char ('!');
  PRINTF ("OK\n");
  printf ("OK\n");
}
}
 
 
/* Tries to send data in different modes in both directions */
/* Tries to send data in different modes in both directions */
 
 
/* Utility function, that tests current configuration */
/* Utility function, that tests current configuration */
Line 441... Line 441...
}
}
 
 
void different_modes_test ()
void different_modes_test ()
{
{
  int speed, parity, length;
  int speed, parity, length;
  PRINTF ("different modes test\n");
  printf ("different modes test\n");
  init_8n1();
  init_8n1();
 
 
  /* Init */
  /* Init */
  MARK();
  MARK();
  ASSERT(getreg (UART_IIR) == 0xc1); /* nothing should be happening */
  ASSERT(getreg (UART_IIR) == 0xc1); /* nothing should be happening */
Line 497... Line 497...
  MARK();
  MARK();
 
 
  send_char ('T');
  send_char ('T');
  while (getreg (UART_LSR) != 0x60); /* Wait for THR to be empty */
  while (getreg (UART_LSR) != 0x60); /* Wait for THR to be empty */
  MARK();
  MARK();
  PRINTF ("OK\n");
  printf ("OK\n");
}
}
 
 
/* Test various FIFO levels, break and framing error interrupt, etc */
/* Test various FIFO levels, break and framing error interrupt, etc */
 
 
void interrupt_test ()
void interrupt_test ()
{
{
  int i;
  int i;
  PRINTF ("interrupt_test\n");
  printf ("interrupt_test\n");
  /* Configure UART for interrupt mode */
  /* Configure UART for interrupt mode */
  ASSERT(getreg (UART_IIR) == 0xc1); /* nothing should be happening */
  ASSERT(getreg (UART_IIR) == 0xc1); /* nothing should be happening */
  setreg (UART_LCR, LCR_DIVL);
  setreg (UART_LCR, LCR_DIVL);
  setreg (UART_DLH, 6 >> 8);            /* Set relatively slow speed, so we can hanlde interrupts properly */
  setreg (UART_DLH, 6 >> 8);            /* Set relatively slow speed, so we can hanlde interrupts properly */
  setreg (UART_DLL, 6 & 0xff);
  setreg (UART_DLL, 6 & 0xff);
Line 697... Line 697...
  setreg (UART_DLL, 2 & 0xff);
  setreg (UART_DLL, 2 & 0xff);
  setreg (UART_LCR, 0x03);    /* 8N1 @ 2 */
  setreg (UART_LCR, 0x03);    /* 8N1 @ 2 */
  send_char ('T');
  send_char ('T');
 
 
  MARK ();
  MARK ();
  PRINTF ("OK\n");
  printf ("OK\n");
}
}
 
 
/* Test if all control bits are set correctly.  Lot of this was already tested
/* Test if all control bits are set correctly.  Lot of this was already tested
   elsewhere and tests are not duplicated.  */
   elsewhere and tests are not duplicated.  */
 
 
Line 739... Line 739...
  /* TODO: MSR */
  /* TODO: MSR */
  /* LSR already tested in different_modes_test () and interrupt_test() */
  /* LSR already tested in different_modes_test () and interrupt_test() */
  /* SCR already tested in register_test () */
  /* SCR already tested in register_test () */
 
 
  MARK ();
  MARK ();
  PRINTF ("OK\n");
  printf ("OK\n");
}
}
 
 
/* Tests parity error and frane error behaviour */
/* Tests parity error and frane error behaviour */
 
 
void line_error_test ()
void line_error_test ()
{
{
  PRINTF ("line_error_test\n");
  printf ("line_error_test\n");
 
 
  /* Test framing error if we change speed */
  /* Test framing error if we change speed */
  setreg (UART_LCR, LCR_DIVL);
  setreg (UART_LCR, LCR_DIVL);
  setreg (UART_DLH, 2 >> 8);
  setreg (UART_DLH, 2 >> 8);
  setreg (UART_DLL, 2 & 0xff);
  setreg (UART_DLL, 2 & 0xff);
Line 787... Line 787...
  recv_char ('b');
  recv_char ('b');
  MARK();
  MARK();
#endif
#endif
 
 
  MARK ();
  MARK ();
  PRINTF ("OK\n");
  printf ("OK\n");
}
}
 
 
int main ()
int main ()
{
{
  /* Use our low priority interrupt handler */
  /* Use our low priority interrupt handler */
Line 812... Line 812...
 
 
  /* loopback_test ();
  /* loopback_test ();
  modem_test ();
  modem_test ();
  modem_error_test ();*/
  modem_error_test ();*/
  recv_char ('@');
  recv_char ('@');
  PRINTF ("ALL TESTS PASSED\n");
  printf ("ALL TESTS PASSED\n");
  return 0;
  return 0;
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.