OpenCores
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.23/hwtests/serial
    from Rev 142 to Rev 157
    Reverse comparison

Rev 142 → Rev 157

/README
0,0 → 1,3
Here are tests for unidirectional serial communication from the FPGA board
to the PC and vice versa, as well as for bidirectional serial communication.
See the individual README files for instructions.
/sertest/README
0,0 → 1,5
1. Write ECO32 and one of 'echo0' or 'echo1' to the on-board Flash ROM.
2. Press and release the ECO32 reset button.
3. Start 'sertest' on the PC. Choose the serial port according to the
serial line the board is responding on. Every 10000 bytes 'sertest'
shows a report.
/sertest/echo1.s
0,0 → 1,20
;
; echo.s -- test the serial interface
;
 
.set sba,0xF0301000 ; serial base address
 
add $8,$0,sba ; set serial base address
L1:
ldw $9,$8,0 ; load receiver status into $9
and $9,$9,1 ; check receiver ready
beq $9,$0,L1 ; loop while not ready
ldw $10,$8,4 ; load receiver data into $10
add $10,$10,0x5C
and $10,$10,0xFF
L2:
ldw $9,$8,8 ; load transmitter status into $9
and $9,$9,1 ; check transmitter ready
beq $9,$0,L2 ; loop while not ready
stw $10,$8,12 ; load char into transmitter data
j L1 ; all over again
/sertest/sertest.c
0,0 → 1,149
/*
* sertest.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;
static int errors;
 
 
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;
}
 
 
void block(void) {
unsigned char src[1000];
unsigned char dst[1000];
unsigned char *p, *q;
int i;
 
for (i = 0; i < 1000; i++) {
src[i] = rand();
}
p = src;
q = dst;
while (1) {
if (p != &src[1000] && serialSnd(*p)) {
p++;
}
if (q != &dst[1000] && serialRcv(q)) {
q++;
}
if (q == &dst[1000]) {
break;
}
}
for (i = 0; i < 1000; i++) {
if (((src[i] + 0x5C) & 0xFF) != dst[i]) {
errors++;
}
}
}
 
 
int main(int argc, char *argv[]) {
char *serialPort;
int i;
 
if (argc != 2) {
printf("Usage: %s <serial port>\n", argv[0]);
exit(1);
}
serialPort = argv[1];
serialOpen(serialPort);
errors = 0;
for (i = 1; i <= 100; i++) {
block();
if (i % 10 == 0) {
printf("%d bytes, errors = %d\n", i * 1000, errors);
}
}
if (sfd != 0) {
serialClose();
sfd = 0;
}
return 0;
}
/sertest/Makefile
0,0 → 1,38
#
# Makefile for serial line test program (FPGA <--> PC)
#
 
BUILD = ../../../build
 
.PHONY: all install clean
 
all: echo0.exo echo1.exo sertest
 
install: echo0.exo echo1.exo sertest
 
echo0.o: echo0.s
$(BUILD)/bin/as -o echo0.o echo0.s
 
echo1.o: echo1.s
$(BUILD)/bin/as -o echo1.o echo1.s
 
echo0.bin: echo0.o
$(BUILD)/bin/ld -h -rc 0xE0000000 -o echo0.bin echo0.o
 
echo1.bin: echo1.o
$(BUILD)/bin/ld -h -rc 0xE0000000 -o echo1.bin echo1.o
 
echo0.exo: echo0.bin
$(BUILD)/bin/bin2exo -S2 0 echo0.bin echo0.exo
 
echo1.exo: echo1.bin
$(BUILD)/bin/bin2exo -S2 0 echo1.bin echo1.exo
 
sertest: sertest.c
gcc -m32 -g -Wall -o sertest sertest.c
 
clean:
rm -f *~
rm -f echo0.o echo0.bin echo0.exo
rm -f echo1.o echo1.bin echo1.exo
rm -f sertest
/sertest/echo0.s
0,0 → 1,20
;
; echo.s -- test the serial interface
;
 
.set sba,0xF0300000 ; serial base address
 
add $8,$0,sba ; set serial base address
L1:
ldw $9,$8,0 ; load receiver status into $9
and $9,$9,1 ; check receiver ready
beq $9,$0,L1 ; loop while not ready
ldw $10,$8,4 ; load receiver data into $10
add $10,$10,0x5C
and $10,$10,0xFF
L2:
ldw $9,$8,8 ; load transmitter status into $9
and $9,$9,1 ; check transmitter ready
beq $9,$0,L2 ; loop while not ready
stw $10,$8,12 ; load char into transmitter data
j L1 ; all over again
/pc2fpga/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.
/pc2fpga/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
/pc2fpga/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;
}
/pc2fpga/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
/pc2fpga/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
/fpga2pc/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.
/fpga2pc/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;
}
/fpga2pc/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
/fpga2pc/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
/fpga2pc/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
/Makefile
0,0 → 1,25
#
# Makefile for serial interface tests
#
 
BUILD = ../../build
 
DIRS = fpga2pc pc2fpga sertest
 
.PHONY: all install clean
 
all:
for i in $(DIRS) ; do \
$(MAKE) -C $$i all ; \
done
 
install:
for i in $(DIRS) ; do \
$(MAKE) -C $$i install ; \
done
 
clean:
for i in $(DIRS) ; do \
$(MAKE) -C $$i clean ; \
done
rm -f *~

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.