Skip to content
Snippets Groups Projects
Commit eee0c716 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Transmission kind of working (on a very weird way)

parent 2a1c0925
No related branches found
No related tags found
1 merge request!1Transmission
0 0
00 11
ffffffff ffffffff
7C2 7C2
...@@ -31,9 +31,9 @@ RX: ...@@ -31,9 +31,9 @@ RX:
nop nop
sb $k1, 0($a0) # Put data on RX_queue tail sb $k1, 0($a0) # Put data on RX_queue tail
# lui $a0, %hi(x_IO_BASE_ADDR) lui $a0, %hi(x_IO_BASE_ADDR)
# ori $a0, $a0, %lo(x_IO_BASE_ADDR) ori $a0, $a0, %lo(x_IO_BASE_ADDR)
# sw $k1, 0($a0) # Print for debug sw $k1, 0($a0) # Print for debug
...@@ -46,6 +46,10 @@ TX: ...@@ -46,6 +46,10 @@ TX:
lw $a1, 52($a0) # Read ntx lw $a1, 52($a0) # Read ntx
# lui $k1, %hi(x_IO_BASE_ADDR)
# ori $k1, $k1, %lo(x_IO_BASE_ADDR)
# sw $a1, 0($k1) # Print for debug
addiu $k1, $zero, 16 addiu $k1, $zero, 16
slt $k1, $a1, $k1 # If ntx < 16 there's something on the queue slt $k1, $a1, $k1 # If ntx < 16 there's something on the queue
beq $k1, $zero, END beq $k1, $zero, END
...@@ -59,13 +63,17 @@ TX: ...@@ -59,13 +63,17 @@ TX:
andi $k1, $k1, 15 # It's a circular queue so: (tx_hd+1)%16 andi $k1, $k1, 15 # It's a circular queue so: (tx_hd+1)%16
sw $k1, 40($a0) # Save tx_hd sw $k1, 40($a0) # Save tx_hd
addiu $a1, $a1, 24 # tx_hd position on tx_queue # addiu $a1, $a1, 24 # tx_hd position on tx_queue
add $a0, $a1, $a0 # tx_queue head address add $a0, $a1, $a0 # tx_queue head address
lbu $a1, 0($a0) # Read TX_queue head lbu $a1, 24($a0) # Read TX_queue head
lui $a0, %hi(HW_uart_addr) lui $a0, %hi(HW_uart_addr)
ori $a0, $a0, %lo(HW_uart_addr) ori $a0, $a0, %lo(HW_uart_addr)
sb $a1, 4($a0) # Put data on UART sb $a1, 4($a0) # Put data on UART
# lui $a0, %hi(x_IO_BASE_ADDR)
# ori $a0, $a0, %lo(x_IO_BASE_ADDR)
# sw $a1, 0($a0) # Print for debug
END: END:
...@@ -74,32 +74,55 @@ int main(){ ...@@ -74,32 +74,55 @@ int main(){
ctrl.ign = 0; ctrl.ign = 0;
ctrl.intTX = 0; ctrl.intTX = 1;
ctrl.intRX = 1; ctrl.intRX = 1;
ctrl.speed = 2; // operate at 1/2 of the highest data rate ctrl.speed = 1; // operate at 1/2 of the highest data rate
uart->cs.ctl = ctrl; uart->cs.ctl = ctrl;
initUd(); initUd();
int lol;
c = getc(); char last = EOF;
while(c != '\0') { char first = EOF;
while(!((c = getc()) == '\n' && c == last)) {
last = c;
print(c);
if(c != EOF) { if(c != EOF) {
int n = 0; if(!Putc(c)){
while(c != '\n' && c != '\0') { print(0);
int h = ctoi(c); while(!(TXempty&uart->cs.stat.s));
if(h != EOF) { disableInterr();
n = n*16 + h; first = Ud.tx_q[Ud.tx_hd];
} Ud.tx_hd = (Ud.tx_hd+1)%16;
c = getc(); Ud.ntx++;
} enableInterr();
//If it's a negative hex make it a negative integer as well uart->d.tx = first;
n = 0x8000&n ? (int)(0x7FFF&n)-0x8000 : n; Putc(c);
print(n); }
//while(!Putc(c)); // Wait till there's space on queue }
} }
c = getc(); // for(i=0;i<Ud.ntx;i++){
} // print(Ud.tx_q[i]);
Putc(c); // Sends EOF // }
// to_stdout('\n');
//uart->d.tx = '\n'; //Send STX (Start of Text)
// while((c = getc()) != '\0') {
// if(c != EOF) {
// // while(!Putc(c)); // Wait till there's space on queue
// int n = 0;
// while(c != '\n' && c != '\0') {
// int h = ctoi(c);
// if(h != EOF) {
// n = n*16 + h;
// }
// c = getc();
// }
// //If it's a negative hex make it a negative integer as well
// n = 0x8000&n ? (int)(0x7FFF&n)-0x8000 : n;
// // print(n);
// }
// }
// Putc(c); // Sends EOF
return 0; return 0;
} }
...@@ -114,37 +137,27 @@ void initUd(){ ...@@ -114,37 +137,27 @@ void initUd(){
} }
char getc(){ char getc(){
char c; char c = EOF;
if(Ud.nrx > 0){ if(Ud.nrx > 0){
disableInterr(); disableInterr();
c = Ud.rx_q[Ud.rx_hd]; c = Ud.rx_q[Ud.rx_hd];
Ud.rx_hd = (Ud.rx_hd+1)%16; Ud.rx_hd = (Ud.rx_hd+1)%16;
Ud.nrx--; Ud.nrx--;
enableInterr(); enableInterr();
}else{
c = EOF;
} }
return c; return c;
} }
int Putc(char c){ int Putc(char c){
int sent;
if(Ud.ntx == 16) {
uart->d.tx = c;
return 1;
}
if(Ud.ntx > 0){ if(Ud.ntx > 0){
disableInterr(); disableInterr();
Ud.tx_q[Ud.tx_tl] = c; Ud.tx_q[Ud.tx_tl] = c;
Ud.tx_tl = (Ud.tx_tl+1)%16; Ud.tx_tl = (Ud.tx_tl+1)%16;
Ud.ntx--; Ud.ntx--;
enableInterr(); enableInterr();
sent = 1; return 1;
}else{
sent = 0;
} }
return sent; return 0;
} }
int proberx(){ int proberx(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment