diff --git a/cMIPS/tests/mac_uart_rx.c b/cMIPS/tests/mac_uart_rx.c index bc0e2b55ae031470cdcf29e917f4afceb170aa94..235115ae4b8eaaac40f68732128f91ec1f0ef949 100644 --- a/cMIPS/tests/mac_uart_rx.c +++ b/cMIPS/tests/mac_uart_rx.c @@ -1,53 +1,22 @@ //======================================================================== -// UART receive functional test +// UART reception functional test // Linux computer must be connected via USB-serial (/dev/ttyUSB0) -// and must run minicom @ 115.200 bps -// If all is wall, all typed at minicom's terminal are echoed on the LCD +// and must run putty @ 9,600 bps +// 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" -typedef struct control { // control register fields (uses only ls byte) - 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; +#include "uart_defs.c" #if 0 @@ -56,14 +25,13 @@ char s[32]; // = "the quick brown fox jumps over the lazy dog"; // char s[32]; // = " "; #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 volatile Tserial *uart; // tell GCC not to optimize away code volatile Tstatus status; Tcontrol ctrl; - int i,n; - int state; - char c, s[32]; + int i,n, state; + char c; LCDinit(); @@ -74,49 +42,59 @@ int main(void) { // receive a string through the UART serial interface LCDput('I'); LCDput('P'); 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 ctrl.ign = 0; - ctrl.rts = 0; + ctrl.rts = 1; ctrl.ign2 = 0; ctrl.intTX = 0; ctrl.intRX = 0; - ctrl.speed = 3; + ctrl.speed = 7; // 9.600 bps uart->cs.ctl = ctrl; - LCDput(':'); - LCDput(' '); - - n = 0; + LCDgotoxy(1,2); + n = 1; 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; - 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; - if ( n == 16 ){ - LCDbotLine(); - n = 0; + if ( n == 15 ){ + delay_ms(1000); + LCDgotoxy(1,2); + for(i = 1; i < 15; i++) + LCDputc(' '); + LCDgotoxy(1,2); + n = 1; } } while (1 == 1); - return 0; + exit(0); } diff --git a/cMIPS/tests/mac_uart_tx.c b/cMIPS/tests/mac_uart_tx.c index d15226adb790cf6e3f253364b15b34ecd21066a0..3a890f30eeea55879967aaaba9f7b0122e4106dd 100644 --- a/cMIPS/tests/mac_uart_tx.c +++ b/cMIPS/tests/mac_uart_tx.c @@ -1,8 +1,12 @@ //======================================================================== -// UART transmit functional test +// UART transmission functional test // Linux computer must be connected via USB-serial (/dev/ttyUSB0) // 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. //========================================================================