diff --git a/cMIPS/tests/uart_defs.c b/cMIPS/tests/uart_defs.c index 249cc4c651e4ab8c013682ccd1b969ca183b9a9a..348451f511a943508e16bf38ac5c5c60c7c01f7c 100644 --- a/cMIPS/tests/uart_defs.c +++ b/cMIPS/tests/uart_defs.c @@ -8,6 +8,15 @@ typedef struct control { // control register fields (uses only ls byte) speed : 3; // 4,8,16... {tx,rx}clock data rates (bits 0..2) } Tcontrol; +typedef struct interr { // interrupt clear bits (uses only ls byte) + unsigned int ign : 24, // ignore uppermost 3 bytes + rts : 1, // Request to Send output (bit 7) + ign2 : 2, // bits 6,5 ignored + clrTX : 1, // interrupt on TX buffer empty (bit 4) + clrRX : 1, // interrupt on RX buffer full (bit 3) + ign3 : 3; // bits 2..0 ignored +} Tinterr; + typedef struct status { // status register fields (uses only ls byte) unsigned int ign : 24, // ignore uppermost 3 bytes cts : 1, // Clear To Send input=1 (bit 7) @@ -20,19 +29,16 @@ typedef struct status { // status register fields (uses only ls byte) overun : 1; // overun error (bit 0) } Tstatus; -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; // address is (int *)IO_UART_ADDR - Tdata d; // address is (int *)(IO_UART_ADDR+1) + Tcontrol ctl; // read-writ, address is (int *)IO_UART_ADDR + Tstatus stat; // read-only, address is (int *)(IO_UART_ADDR+1) + Tinterr interr; // write-only, address is (int *)(IO_UART_ADDR+2) + Tdata d; // read-write, address is (int *)(IO_UART_ADDR+3) } Tserial; diff --git a/cMIPS/tests/uart_irx.c b/cMIPS/tests/uart_irx.c index a2b2bc4633fb558742d5fbf7d4b886707e594418..b5f473f2f40bce0524793a20c5306810c587a40f 100644 --- a/cMIPS/tests/uart_irx.c +++ b/cMIPS/tests/uart_irx.c @@ -39,7 +39,7 @@ int main(void) { // receive a string through the UART serial interface ctrl.intTX = 0; ctrl.intRX = 0; ctrl.speed = SPEED; - uart->cs.ctl = ctrl; // initizlize UART + uart->ctl = ctrl; // initizlize UART // handler sets flag=[U_FLAg] to 1 after new character is received; // this program resets the flag on fetching a new character from buffer @@ -50,7 +50,7 @@ int main(void) { // receive a string through the UART serial interface ctrl.intTX = 0; ctrl.intRX = 1; // do generate interrupts on RXbuffer full ctrl.speed = SPEED; // operate at 1/4 of the highest data rate - uart->cs.ctl = ctrl; + uart->ctl = ctrl; do { while ( (c = (char)bfr[U_FLAG]) == 0 ) // check flag in Ud[] diff --git a/cMIPS/tests/uartrx.c b/cMIPS/tests/uartrx.c index a783effa7a4e52b04b403a6bc5bc354520a6cbd4..016e7b6443da267855ac0e176ef00b3ce8ae6dd2 100644 --- a/cMIPS/tests/uartrx.c +++ b/cMIPS/tests/uartrx.c @@ -35,7 +35,7 @@ int main(void) { // receive a string through the UART serial interface ctrl.intTX = 0; ctrl.intRX = 0; ctrl.speed = SPEED; // operate at the second highest data rate - uart->cs.ctl = ctrl; + uart->ctl = ctrl; i = -1; @@ -45,19 +45,20 @@ int main(void) { // receive a string through the UART serial interface ctrl.intTX = 0; ctrl.intRX = 0; ctrl.speed = SPEED; // operate at the second highest data rate - uart->cs.ctl = ctrl; + uart->ctl = ctrl; do { i = i+1; - while ( (state = (int)uart->cs.stat.rxFull) == 0 ) - delay_cycle(1); // just do something + while ( (state = (int)uart->stat.rxFull) == 0 ) + delay_cycle(1); // just do something s[i] = (char)uart->d.rx; - if (s[i] != EOT) + if (s[i] != EOT) { to_stdout( s[i] ); // and print new char - else - to_stdout( '\n' ); // and print new-line - + } else { + to_stdout( '\n' ); // print new-line + to_stdout( EOT ); // and signal End Of Transmission + } } while (s[i] != EOT); return(state); diff --git a/cMIPS/tests/uarttx.c b/cMIPS/tests/uarttx.c index f3fa1733341964871be528ce0bf0903316aa407c..cf3fe50f8140a126934a8e562d03e9ad7ca64c52 100644 --- a/cMIPS/tests/uarttx.c +++ b/cMIPS/tests/uarttx.c @@ -62,13 +62,13 @@ int main(void) { // send a string through the UART serial interface ctrl.ign2 = 0; ctrl.ign = 0; ctrl.rts = 0; // make RTS=0 so RemoteUnit won't transmit, just receive - uart->cs.ctl = ctrl; + uart->ctl = ctrl; i = -1; do { i = i+1; - while ( (state = (int)uart->cs.stat.txEmpty) == 0 ) + while ( (state = (int)uart->stat.txEmpty) == 0 ) delay_cycle(1); // do something uart->d.tx = (int)s[i];