Skip to content
Snippets Groups Projects
Commit f7177d35 authored by Strozzi's avatar Strozzi
Browse files

nice job

parent 30f9ab24
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -2,14 +2,49 @@
#include "vetorFib.h"
#include "structUart.h"
#define OBOUND_MESG "Out of bounds\n"
#define OVERUN_MESG "Overun\n"
#define MAXPOW 7
#define SPEED 3
#define COUNT ((SPEED+1)*100)
// ----------------------- begin driver?
extern UARTdriver Ud;
Tcontrol ctrl;
volatile Tserial *uart;
int proberx () {
return Ud.nrx;
}
int probetx () {
return Ud.ntx;
}
void ioctl (int c) {
uart->cs.ctl = (unsigned char)c;
}
int ioctl () {
return uart->cs.stat;
}
int Putc (char c) {
int ntx = probetx();
if (ntx == 0)
return 0;
if (ntx == 16 && uart->cs.stat.txEmpty) // Empty Q && Tx
uart->d.tx = (int) c; // 32-bits
else { // Sending smthng
disableInterr();
ud.ntx--;
Ud.tx_q[Ud.tx_tl] = c;
Ud.tx_tl = (Ud.tx_tl + 1)&0xF; // modulo 16
enableInterr();
}
return 1;
}
// ------------------------- end driver?
// ------------------------- begin main()
int Strlen (char *c) {
int i= 0;
while(c[i++]-10);
......@@ -26,6 +61,25 @@ int pow16 (int ex) {
int hex2int (char *hex) {
int s= Strlen(hex), i, ans= 0;
#if 0
Test Signal...
switch (hex[0]) {
case 'F':
case 'f':
case 'E':
case 'e':
case 'D':
case 'd':
case 'C':
case 'c':
case 'B':
case 'b':
case 'A':
case 'a':
case '9':
ans = hex[0]*pow16(s-1);
}
#endif
for (i= 0; i< s; i++) {
hex[i]-= 48;
if (hex[i] > 9)
......@@ -58,69 +112,37 @@ int int2hex (char *c, int i) {
return j-1;
}
int Putc (char c) {
if (Ud.ntx == 0)
return 0;
if (Ud.ntx == 16 && uart->cs.stat.txEmpty) // Empty Q && Tx
uart->d.tx = (int) c; // 32-bits
else { // Sending smthng
disableInterr();
ud.ntx--;
Ud.tx_q[Ud.tx_tl] = c;
Ud.tx_tl = (Ud.tx_tl + 1)&0xF; // modulo 16
enableInterr();
}
return 1;
}
int main () {
uart= IO_UART_ADDR;
Tcontrol ctrl;
char n[16], f[16], c;
int fib, j, s, val;
uart= IO_UART_ADDR;
// initialize UART control
ctrl.rts= 1;
ctrl.intTX= 1; // Both interruption
ctrl.intRX= 1;
ctrl.speed= SPEED;
uart->cs.ctl = ctrl;
ioctl((int)ctrl);
while (1) {
j= 0;
while ((n[j++]= getFila()) != '\n');
n[j] = '\n'
if (n[0] == 10) // critério de fim de transmissão
break;
/***************************
** Reception with tests **
***************************/
fib= hex2int(n);
if (fib < BUF_SZ) {
fib = buf[fib];
s= int2hex(f, fib); // retorna strlen de f
for (j= 0; j< s; j++)
Putc(f[j]);
} else {
to_stdout('v');
to_stdout('a');
to_stdout('l');
to_stdout('o');
to_stdout('r');
to_stdout(' ');
to_stdout('m');
to_stdout('u');
to_stdout('i');
to_stdout('t');
to_stdout('o');
to_stdout(' ');
to_stdout('g');
to_stdout('r');
to_stdout('a');
to_stdout('n');
to_stdout('d');
to_stdout('e');
to_stdout('\n');
}
while(!Putc(f[j])); // enquanto fila de tranmissão está cheia
} else
for (j= 0; j<sizeof(BOUND_MESG); j++)
to_stdout(BOUND_MESG[j]);
}
startCounter (COUNT , 0);
while ((val= (readCounter() && 0x3FFFFFFF)) < COUNT);
// sleep??
// yes, baby!
return val;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment