Select Git revision
-
Roberto Hexsel authoredRoberto Hexsel authored
uart_irx.c 1.73 KiB
//
// Test interrupts caused by UART's reception circuit.
//
// Remote unit reads string from serial.inp and sends it over the
// serial line.
//
// UARTinterr, in include/handlers.s, reads newly arrived character,
// sets a flag and puts character in a buffer. main() reads from the
// buffer and prints it to the simulator's standard output.
#include "cMIPS.h"
#include "uart_defs.c"
#define U_DATA 0
#define U_FLAG 1
#define SPEED 2 // operate at 1/4 of the highest data rate
int main(void) { // receive a string through the UART serial interface
volatile Tserial *uart; // tell GCC not to optimize away code
Tcontrol ctrl;
extern int Ud[2]; // declared in include/handlers.s
volatile int *bfr;
volatile char c;
bfr = (int *)Ud;
uart = (void *)IO_UART_ADDR; // bottom of UART address range
ctrl.ign = 0;
ctrl.rts = 0; // make RTS=0 to hold remote unit inactive
ctrl.intTX = 0;
ctrl.intRX = 0;
ctrl.speed = SPEED;
uart->cs.ctl = ctrl; // initizlize UART
// handler sets flag=bfr[3] to 1 after new character is received;
// this program resets the flag on fetching a new character from buffer
bfr[U_FLAG] = 0; // reset flag
ctrl.ign = 0;
ctrl.rts = 1; // make RTS=1 to activate remote unit
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;
do {
while ( (c = (char)bfr[U_FLAG]) == 0 ) // check flag in Ud[1]
{}; // nothing new
c = (char)bfr[U_DATA]; // get new character
bfr[U_FLAG] = 0; // and reset flag
to_stdout( (int)c ); // and print new char
} while (c != '\0'); // end of string?
return c;
}