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

Subversion Repositories tv80

[/] [tv80/] [trunk/] [tests/] [basic_uart.c] - Diff between revs 77 and 84

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

Rev 77 Rev 84
Line 38... Line 38...
 
 
void print (char *string)
void print (char *string)
{
{
  char *iter;
  char *iter;
 
 
 
  iter = string;
 
  while (*iter != 0) {
 
    msg_port = *iter++;
 
  }
 
}
 
 
 
char rxbuf[128];
 
 
 
void test_byte (unsigned char pattern) {
 
  unsigned char status, data;
 
 
 
  // send a byte through the UART
 
  uart_dm0 = pattern;
 
 
 
  // wait for byte to be received
 
  do {
 
    status = uart_lsr;
 
  } while ((status & 0x01) == 0);
 
 
 
  // fail if status byte indicates anything other
 
  // than data ready and transmitter empty
 
  if (status != 0x61) {
 
    print ("Incorrect status byte\n");
 
    sim_ctl_port = 0x02;
 
  }
 
 
 
  // read the sent byte and fail if it's not what we sent
 
  data = uart_dm0;
 
  if (data != pattern) {
 
    print ("Data miscompare\n");
 
    sim_ctl_port = 0x02;
 
  }
 
}
 
 
 
int main ()
 
{
 
  //print ("Hello, world!\n");
 
 
 
  int i, rx_count;
 
 
 
  // set divisor to 100
 
  uart_lcr = 0x8b;
 
  uart_dm0 = 0x02;
 
  uart_dm1 = 0x00;
 
 
 
  // line settings:
 
  // 8 bits, 1 stop bit, even parity
 
  uart_lcr = 0x0b;
 
 
 
  // turn on internal loopback in UART
 
  uart_mcr = 0x10;
 
  test_byte (0x55);
 
  test_byte (0x1F);
 
 
 
  // turn off loopback and use external loop
 
  uart_mcr = 0x00;
 
  test_byte (0xAA);
 
  test_byte (0xBD);
 
 
 
  // maybe do a checksum here
 
  sim_ctl_port = 0x01;
 
 
 
  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.