URL
https://opencores.org/ocsvn/eco32/eco32/trunk
Subversion Repositories eco32
Compare Revisions
- This comparison shows the changes necessary to convert path
/eco32/tags/eco32-0.24/hwtests/serial/pc2fpga
- from Rev 134 to Rev 211
- ↔ Reverse comparison
Rev 134 → Rev 211
/README
0,0 → 1,5
1. Write ECO32 and one of 'receive0' or 'receive1' to the on-board Flash ROM. |
2. Press and release the ECO32 reset button. |
3. Start 'send' on the PC. Choose the serial port according to the serial |
line the board is listening on. After a while 'send' shows either a |
dot ('.') indicating success, or a question mark ('?') for failure. |
/receive1.s
0,0 → 1,54
; |
; receive.s -- receive & check a stream of bytes |
; |
|
; $8 serial base address |
; $9 temporary value |
; $10 current character |
; $11 previous character |
; $12 counter |
; $13 error |
; $31 return address |
|
.set tba,0xF0301000 |
|
add $8,$0,tba |
add $12,$0,100000 |
add $13,$0,0 |
jal in |
add $11,$10,0 |
sub $12,$12,1 |
loop: |
add $11,$11,1 |
and $11,$11,0xFF |
jal in |
beq $10,$11,chrok |
add $13,$13,1 |
chrok: |
sub $12,$12,1 |
bne $12,$0,loop |
bne $13,$0,error |
add $13,$0,'.' |
jal out |
j halt |
error: |
add $13,$0,'?' |
jal out |
j halt |
|
halt: |
j halt |
|
in: |
ldw $9,$8,0 |
and $9,$9,1 |
beq $9,$0,in |
ldw $10,$8,4 |
jr $31 |
|
out: |
ldw $9,$8,8 |
and $9,$9,1 |
beq $9,$0,out |
stw $13,$8,12 |
jr $31 |
/send.c
0,0 → 1,122
/* |
* send.c -- serial line test program |
*/ |
|
|
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdarg.h> |
#include <fcntl.h> |
#include <unistd.h> |
#include <termios.h> |
|
|
#define NUM_TRIES 10 |
|
#define SYN 0x16 |
#define ACK 0x06 |
|
|
static FILE *diskFile = NULL; |
static int sfd = 0; |
static struct termios origOptions; |
static struct termios currOptions; |
|
|
void serialClose(void); |
|
|
void error(char *fmt, ...) { |
va_list ap; |
|
va_start(ap, fmt); |
printf("Error: "); |
vprintf(fmt, ap); |
printf("\n"); |
va_end(ap); |
if (diskFile != NULL) { |
fclose(diskFile); |
diskFile = NULL; |
} |
if (sfd != 0) { |
serialClose(); |
sfd = 0; |
} |
exit(1); |
} |
|
|
void serialOpen(char *serialPort) { |
sfd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY); |
if (sfd == -1) { |
error("cannot open serial port '%s'", serialPort); |
} |
tcgetattr(sfd, &origOptions); |
currOptions = origOptions; |
cfsetispeed(&currOptions, B38400); |
cfsetospeed(&currOptions, B38400); |
currOptions.c_cflag |= (CLOCAL | CREAD); |
currOptions.c_cflag &= ~PARENB; |
currOptions.c_cflag &= ~CSTOPB; |
currOptions.c_cflag &= ~CSIZE; |
currOptions.c_cflag |= CS8; |
currOptions.c_cflag &= ~CRTSCTS; |
currOptions.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG | IEXTEN); |
currOptions.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK); |
currOptions.c_iflag &= ~(INPCK | ISTRIP | INLCR | IGNCR | ICRNL); |
currOptions.c_iflag &= ~(IXON | IXOFF | IXANY); |
currOptions.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONOCR | ONLRET); |
tcsetattr(sfd, TCSANOW, &currOptions); |
} |
|
|
void serialClose(void) { |
tcsetattr(sfd, TCSANOW, &origOptions); |
close(sfd); |
} |
|
|
int serialSnd(unsigned char b) { |
int n; |
|
n = write(sfd, &b, 1); |
return n == 1; |
} |
|
|
int serialRcv(unsigned char *bp) { |
int n; |
|
n = read(sfd, bp, 1); |
return n == 1; |
} |
|
|
int main(int argc, char *argv[]) { |
char *serialPort; |
unsigned char curr; |
int count; |
|
if (argc != 2) { |
printf("Usage: %s <serial port>\n", argv[0]); |
exit(1); |
} |
serialPort = argv[1]; |
serialOpen(serialPort); |
curr = 0; |
count = 0; |
while (count < 100000) { |
while (!serialSnd(curr)) ; |
curr = (curr + 1) & 0xFF; |
count++; |
} |
printf("count = %d\n", count); |
while (!serialRcv(&curr)) ; |
printf("answer = %c\n", curr); |
if (sfd != 0) { |
serialClose(); |
sfd = 0; |
} |
return 0; |
} |
/Makefile
0,0 → 1,38
# |
# Makefile for serial line test program (PC --> FPGA) |
# |
|
BUILD = ../../../build |
|
.PHONY: all install clean |
|
all: receive0.exo receive1.exo send |
|
install: receive0.exo receive1.exo send |
|
receive0.o: receive0.s |
$(BUILD)/bin/as -o receive0.o receive0.s |
|
receive1.o: receive1.s |
$(BUILD)/bin/as -o receive1.o receive1.s |
|
receive0.bin: receive0.o |
$(BUILD)/bin/ld -h -rc 0xE0000000 -o receive0.bin receive0.o |
|
receive1.bin: receive1.o |
$(BUILD)/bin/ld -h -rc 0xE0000000 -o receive1.bin receive1.o |
|
receive0.exo: receive0.bin |
$(BUILD)/bin/bin2exo -S2 0 receive0.bin receive0.exo |
|
receive1.exo: receive1.bin |
$(BUILD)/bin/bin2exo -S2 0 receive1.bin receive1.exo |
|
send: send.c |
gcc -m32 -g -Wall -o send send.c |
|
clean: |
rm -f *~ |
rm -f receive0.o receive0.bin receive0.exo |
rm -f receive1.o receive1.bin receive1.exo |
rm -f send |
/receive0.s
0,0 → 1,54
; |
; receive.s -- receive & check a stream of bytes |
; |
|
; $8 serial base address |
; $9 temporary value |
; $10 current character |
; $11 previous character |
; $12 counter |
; $13 error |
; $31 return address |
|
.set tba,0xF0300000 |
|
add $8,$0,tba |
add $12,$0,100000 |
add $13,$0,0 |
jal in |
add $11,$10,0 |
sub $12,$12,1 |
loop: |
add $11,$11,1 |
and $11,$11,0xFF |
jal in |
beq $10,$11,chrok |
add $13,$13,1 |
chrok: |
sub $12,$12,1 |
bne $12,$0,loop |
bne $13,$0,error |
add $13,$0,'.' |
jal out |
j halt |
error: |
add $13,$0,'?' |
jal out |
j halt |
|
halt: |
j halt |
|
in: |
ldw $9,$8,0 |
and $9,$9,1 |
beq $9,$0,in |
ldw $10,$8,4 |
jr $31 |
|
out: |
ldw $9,$8,8 |
and $9,$9,1 |
beq $9,$0,out |
stw $13,$8,12 |
jr $31 |