Skip to content
Snippets Groups Projects
Commit af6daa88 authored by Roberto Hexsel's avatar Roberto Hexsel
Browse files

added test for UART RX on macnica board

parent 319e530d
No related branches found
No related tags found
No related merge requests found
//======================================================================== //========================================================================
// UART receive functional test // UART reception functional test
// Linux computer must be connected via USB-serial (/dev/ttyUSB0) // Linux computer must be connected via USB-serial (/dev/ttyUSB0)
// and must run minicom @ 115.200 bps // and must run putty @ 9,600 bps
// If all is wall, all typed at minicom's terminal are echoed on the LCD // If all is well, LCD's line 2 shows text typed into putty's terminal.
// LCD screen shows on line 1 "cMIPS UART_status UART_error" and on line 2
// the last 15 chars typed on putty.
// If all is well, UART_status=0x60="open single quote"
// in case of error,
// UART_error=0x61='a'=overun or 0x62='b'=framing or 0x63='c'=ovr+fram
// 7-segment leds show status.TXempty and status.RXfull,
// left dot=framing error, right dot=overun error
// This test runs forever.
//======================================================================== //========================================================================
#include "cMIPS.h" #include "cMIPS.h"
typedef struct control { // control register fields (uses only ls byte) #include "uart_defs.c"
int ign : 24, // ignore uppermost bits
rts : 1, // Request to Send
ign2 : 2, // bits 6,5 ignored
intTX : 1, // interrupt on TX buffer empty (bit 4)
intRX : 1, // interrupt on RX buffer full (bit 3)
speed : 3; // 4,8,16..256 tx-rx clock data rates (bits 0..2)
} Tcontrol;
typedef struct status { // status register fields (uses only ls byte)
int s;
// int ign : 24, // ignore uppermost bits
// ign7 : 1, // ignored (bit 7)
// txEmpty : 1, // TX register is empty (bit 6)
// rxFull : 1, // octet available from RX register (bit 5)
// int_TX_empt: 1, // interrupt pending on TX empty (bit 4)
// int_RX_full: 1, // interrupt pending on RX full (bit 3)
// ign2 : 1, // ignored (bit 2)
// framing : 1, // framing error (bit 1)
// overun : 1; // overun error (bit 0)
} Tstatus;
#define RXfull 0x00000020
#define TXempty 0x00000040
typedef union ctlStat { // control + status on same address
Tcontrol ctl; // write-only
Tstatus stat; // read-only
} TctlStat;
typedef union data { // data registers on same address
int tx; // write-only
int rx; // read-only
} Tdata;
typedef struct serial {
TctlStat cs;
Tdata d;
} Tserial;
#if 0 #if 0
...@@ -56,14 +25,13 @@ char s[32]; // = "the quick brown fox jumps over the lazy dog"; ...@@ -56,14 +25,13 @@ char s[32]; // = "the quick brown fox jumps over the lazy dog";
// char s[32]; // = " "; // char s[32]; // = " ";
#endif #endif
int main(void) { // receive a string through the UART serial interface void main(void) { // receive a string through the UART serial interface
// and write it to the LCD display // and write it to the LCD display
volatile Tserial *uart; // tell GCC not to optimize away code volatile Tserial *uart; // tell GCC not to optimize away code
volatile Tstatus status; volatile Tstatus status;
Tcontrol ctrl; Tcontrol ctrl;
int i,n; int i,n, state;
int state; char c;
char c, s[32];
LCDinit(); LCDinit();
...@@ -74,49 +42,59 @@ int main(void) { // receive a string through the UART serial interface ...@@ -74,49 +42,59 @@ int main(void) { // receive a string through the UART serial interface
LCDput('I'); LCDput('I');
LCDput('P'); LCDput('P');
LCDput('S'); LCDput('S');
LCDput(' ');
LCDput('s');
LCDput('a');
LCDput('y');
LCDput('s');
LCDput(' ');
LCDput('H');
LCDput('I');
LCDput('!');
LCDbotLine();
uart = (void *)IO_UART_ADDR; // bottom of UART address range uart = (void *)IO_UART_ADDR; // bottom of UART address range
ctrl.ign = 0; ctrl.ign = 0;
ctrl.rts = 0; ctrl.rts = 1;
ctrl.ign2 = 0; ctrl.ign2 = 0;
ctrl.intTX = 0; ctrl.intTX = 0;
ctrl.intRX = 0; ctrl.intRX = 0;
ctrl.speed = 3; ctrl.speed = 7; // 9.600 bps
uart->cs.ctl = ctrl; uart->cs.ctl = ctrl;
LCDput(':'); LCDgotoxy(1,2);
LCDput(' '); n = 1;
n = 0;
do { do {
while ( ( (state = uart->cs.stat.s) & RXfull ) == 0 ) do {
; delay_us(1); // just do something so gcc won't optimize this away
status = uart->cs.stat;
} while ( status.rxFull == 0 );
c = (char)uart->d.rx; c = (char)uart->d.rx;
DSP7SEGput( state>>4 , 0, state & 0xf, 0);
LCDput(c);
// cmips_delay(12500000); state = ((status.cts <<7) |
(status.txEmpty <<6) | (status.rxFull <<5) |
// (status.int_TX_empt <<4) | (status.int_RX_full <<3) |
(status.framing <<1) | status.overun) & 0xff;
LCDgotoxy(8,1);
LCDput((unsigned char)state);
if (status.framing != 0 || status.overun != 0) {
LCDgotoxy(11,1);
LCDput((unsigned char)state);
DSP7SEGput( (int)status.txEmpty,
(int)status.framing,
(int)status.rxFull,
(int)status.overun, 0 );
}
LCDgotoxy(n,2);
LCDputc(c);
n = n + 1; n = n + 1;
if ( n == 16 ){ if ( n == 15 ){
LCDbotLine(); delay_ms(1000);
n = 0; LCDgotoxy(1,2);
for(i = 1; i < 15; i++)
LCDputc(' ');
LCDgotoxy(1,2);
n = 1;
} }
} while (1 == 1); } while (1 == 1);
return 0; exit(0);
} }
//======================================================================== //========================================================================
// UART transmit functional test // UART transmission functional test
// Linux computer must be connected via USB-serial (/dev/ttyUSB0) // Linux computer must be connected via USB-serial (/dev/ttyUSB0)
// and must run putty @ 9.600 bps // and must run putty @ 9.600 bps
// If all is well, minicom's screen shows, forever, '0'..'9''\n'... // If all is well, putty's screen shows,
// ten times '0'..'9''\n' then ten times 'a'...'j''\n'.
// LCD screen shows on line 1 "cMIPS UART_status" and on line 2
// {0123456789|abcedfghij}
// Test ends with RED led shining.
//======================================================================== //========================================================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment