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

Subversion Repositories tv80

[/] [tv80/] [trunk/] [tests/] [basic_uart.c] - Blame information for rev 90

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 70 ghutchis
//
2
// Copyright (c) 2004 Guy Hutchison (ghutchis@opencores.org)
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a 
5
// copy of this software and associated documentation files (the "Software"), 
6
// to deal in the Software without restriction, including without limitation 
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
8
// and/or sell copies of the Software, and to permit persons to whom the 
9
// Software is furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included 
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
15
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
17
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 
18
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
19
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
20
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
//
22
 
23
sfr at 0x18 uart_dm0;
24
sfr at 0x19 uart_dm1;
25
sfr at 0x1a uart_iir;
26
sfr at 0x1b uart_lcr;
27
sfr at 0x1c uart_mcr;
28
sfr at 0x1d uart_lsr;
29
sfr at 0x1e uart_msr;
30
sfr at 0x1f uart_scr;
31
 
32
sfr at 0x80 sim_ctl_port;
33
sfr at 0x81 msg_port;
34
sfr at 0x82 timeout_port;
35
 
36
// THR (transmit holding register) is DM0
37
// RBR (receive buffer register) is also DM0
38
 
39
void print (char *string)
40
{
41
  char *iter;
42
 
43
  iter = string;
44
  while (*iter != 0) {
45
    msg_port = *iter++;
46
  }
47
}
48
 
49
char rxbuf[128];
50
 
51
void test_byte (unsigned char pattern) {
52
  unsigned char status, data;
53
 
54
  // send a byte through the UART
55
  uart_dm0 = pattern;
56
 
57
  // wait for byte to be received
58
  do {
59
    status = uart_lsr;
60
  } while ((status & 0x01) == 0);
61
 
62
  // fail if status byte indicates anything other
63
  // than data ready and transmitter empty
64
  if (status != 0x61) {
65 77 ghutchis
    print ("Incorrect status byte\n");
66 70 ghutchis
    sim_ctl_port = 0x02;
67
  }
68
 
69
  // read the sent byte and fail if it's not what we sent
70
  data = uart_dm0;
71
  if (data != pattern) {
72 77 ghutchis
    print ("Data miscompare\n");
73 70 ghutchis
    sim_ctl_port = 0x02;
74
  }
75
}
76
 
77
int main ()
78
{
79
  //print ("Hello, world!\n");
80
 
81
  int i, rx_count;
82
 
83
  // set divisor to 100
84
  uart_lcr = 0x8b;
85
  uart_dm0 = 0x02;
86
  uart_dm1 = 0x00;
87
 
88
  // line settings:
89
  // 8 bits, 1 stop bit, even parity
90
  uart_lcr = 0x0b;
91
 
92
  // turn on internal loopback in UART
93
  uart_mcr = 0x10;
94
  test_byte (0x55);
95
  test_byte (0x1F);
96
 
97
  // turn off loopback and use external loop
98
  uart_mcr = 0x00;
99
  test_byte (0xAA);
100
  test_byte (0xBD);
101
 
102
  // maybe do a checksum here
103
  sim_ctl_port = 0x01;
104
 
105
  return 0;
106
}
107
 

powered by: WebSVN 2.1.0

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