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/fpga2pc
- from Rev 133 to Rev 211
- ↔ Reverse comparison
Rev 133 → Rev 211
/README
0,0 → 1,4
1. Write ECO32 and one of 'send0' or 'send1' to the on-board Flash ROM. |
2. While holding ECO32 in reset, start 'receive' on the PC. Choose the |
serial port according to the serial line the board is sending on. |
3. Release the reset button. After a while 'receive' shows a report. |
/receive.c
0,0 → 1,126
/* |
* receive.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 prev, curr; |
int count, errors; |
|
if (argc != 2) { |
printf("Usage: %s <serial port>\n", argv[0]); |
exit(1); |
} |
serialPort = argv[1]; |
serialOpen(serialPort); |
count = 0; |
errors = 0; |
while (!serialRcv(&prev)) ; |
count++; |
while (count < 100000) { |
while (!serialRcv(&curr)) ; |
count++; |
if (((prev + 1) & 0xFF) != curr) { |
errors++; |
} |
prev = curr; |
} |
if (sfd != 0) { |
serialClose(); |
sfd = 0; |
} |
printf("count = %d (ok = %d, errors = %d)\n", |
count, count - errors, errors); |
return 0; |
} |
/send1.s
0,0 → 1,27
; |
; send.s -- send stream of bytes |
; |
|
; $8 serial base address |
; $9 temporary value |
; $10 character |
; $11 counter |
; $31 return address |
|
.set tba,0xF0301000 |
|
add $8,$0,tba |
add $11,$0,0 |
loop: |
add $10,$11,0 |
and $10,$10,0xFF |
jal out |
add $11,$11,1 |
j loop |
|
out: |
ldw $9,$8,8 |
and $9,$9,1 |
beq $9,$0,out |
stw $10,$8,12 |
jr $31 |
/Makefile
0,0 → 1,38
# |
# Makefile for serial line test program (FPGA --> PC) |
# |
|
BUILD = ../../../build |
|
.PHONY: all install clean |
|
all: send0.exo send1.exo receive |
|
install: send0.exo send1.exo receive |
|
send0.o: send0.s |
$(BUILD)/bin/as -o send0.o send0.s |
|
send1.o: send1.s |
$(BUILD)/bin/as -o send1.o send1.s |
|
send0.bin: send0.o |
$(BUILD)/bin/ld -h -rc 0xE0000000 -o send0.bin send0.o |
|
send1.bin: send1.o |
$(BUILD)/bin/ld -h -rc 0xE0000000 -o send1.bin send1.o |
|
send0.exo: send0.bin |
$(BUILD)/bin/bin2exo -S2 0 send0.bin send0.exo |
|
send1.exo: send1.bin |
$(BUILD)/bin/bin2exo -S2 0 send1.bin send1.exo |
|
receive: receive.c |
gcc -m32 -g -Wall -o receive receive.c |
|
clean: |
rm -f *~ |
rm -f send0.o send0.bin send0.exo |
rm -f send1.o send1.bin send1.exo |
rm -f receive |
/send0.s
0,0 → 1,27
; |
; send.s -- send stream of bytes |
; |
|
; $8 serial base address |
; $9 temporary value |
; $10 character |
; $11 counter |
; $31 return address |
|
.set tba,0xF0300000 |
|
add $8,$0,tba |
add $11,$0,0 |
loop: |
add $10,$11,0 |
and $10,$10,0xFF |
jal out |
add $11,$11,1 |
j loop |
|
out: |
ldw $9,$8,8 |
and $9,$9,1 |
beq $9,$0,out |
stw $10,$8,12 |
jr $31 |