deleted
Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@765 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
/************************************************************************/
|
||||
/* Ein Programm zur Berechnung der Bessel-Koeffizienten Jn
|
||||
/* Dateiname : Bessel.cpp
|
||||
/* Autoren : T. Burr, J. Ahrensfeld
|
||||
/* Datum : 28.10.1999
|
||||
/* letzte Änderung : 28.01.2000
|
||||
/* Version : 1.0
|
||||
/************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
#include "math.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
|
||||
#define MAX_SUM 25
|
||||
#define VERSION "1.0"
|
||||
|
||||
/************************************************************************/
|
||||
/* Funktionsdeklarationen */
|
||||
/************************************************************************/
|
||||
// Fakultätsberechnung
|
||||
double fak (int N)
|
||||
{
|
||||
int index;
|
||||
double erg=1;
|
||||
|
||||
for (index = 1; index <= N; index++)
|
||||
erg = erg * index;
|
||||
|
||||
return erg;
|
||||
}
|
||||
|
||||
// Bessel()
|
||||
// Berechnung von Jn von mfm
|
||||
double bessel(int n, double mfm)
|
||||
{
|
||||
int m;
|
||||
double Jn=0;
|
||||
|
||||
for (m=0; m < MAX_SUM; m++)
|
||||
{
|
||||
Jn = Jn + (pow(-1.0,m)/(fak(m)*fak(m+n))*pow(mfm/2.0,(2*m+n)));
|
||||
}
|
||||
return Jn;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* Das Hauptprogramm
|
||||
/************************************************************************/
|
||||
void main()
|
||||
{
|
||||
|
||||
int N, Nmax;
|
||||
double erg;
|
||||
float mfm;
|
||||
|
||||
printf("\n\t Besselfunktion Version %s",VERSION);
|
||||
printf("\n\t ~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
|
||||
printf("\n\tCopyright by J. Ahrensfeld & T. Burr\n\n");
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// Benutzereingaben
|
||||
printf("\nBerechnungen fuer J = 0...");
|
||||
if(scanf("%d",&Nmax)==0)
|
||||
exit (-1);
|
||||
|
||||
printf("Bitte Modulationsindex eingeben : ");
|
||||
if(scanf("%f",&mfm)==0)
|
||||
exit(-1);
|
||||
|
||||
printf("\n");
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// Berechnung
|
||||
for (N=0; N <= Nmax; N++)
|
||||
{
|
||||
erg = bessel(N,(double)mfm);
|
||||
printf("J(%d) = %10.8f\n",N,erg);
|
||||
}
|
||||
|
||||
printf("FERTIG.\n");
|
||||
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
@@ -1,254 +0,0 @@
|
||||
ENDIAN_FLAGS=-EB
|
||||
CFLAGS=$(ENDIAN_FLAGS) -Llibsys -Ilibsys -msoft-float -O2 -march=r3000 -I. -Wl,-M
|
||||
LIBS=-lsys
|
||||
|
||||
AS=mipsel-elf-as
|
||||
AR=mipsel-elf-ar
|
||||
CC=mipsel-elf-gcc
|
||||
LD=mipsel-elf-ld
|
||||
OBJDUMP=mipsel-elf-objdump
|
||||
OBJCOPY=mipsel-elf-objcopy
|
||||
FLASHGEN=flashgen
|
||||
|
||||
PROG = hello.elf testbench.elf test_irq.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf life.elf r3.elf gunzip.elf basic_math.elf jman_patches.elf jman_patchmeshes.elf jman_polys.elf test_hpi.elf test_vga.elf
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
libsys.a:
|
||||
$(MAKE) -C libsys
|
||||
|
||||
hello.elf: hello.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -Os hello.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
testbench.elf: testbench.c libsys.a
|
||||
$(CC) $(CFLAGS) -O3 -o $@ -DHZ=1000 -DNOSIGNAL -DBATCHMODE -DNOMAIN -Os -g testbench.c paranoia.c delay_mips.c bogomips.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
test_irq.elf: test_irq.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ test_irq.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
dhry.elf: dhry_1.c dhry_2.c dhry.h libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -DHZ=1000 dhry_1.c dhry_2.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
queens.elf: queens.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -DUNIX_Old -DHZ=1000 queens.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
stanford.elf: stanford.c libsys.a
|
||||
$(CC) $(CFLAGS) -O3 -o $@ -DHZ=1000 stanford.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
paranoia.elf: paranoia.c libsys.a
|
||||
$(CC) $(CFLAGS) -O3 -o $@ -DNOSIGNAL -DBATCHMODE paranoia.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
rmd160_test.elf: rmd160_test.c rmd160.c rmd160.h libsys.a
|
||||
$(CC) $(CFLAGS) -O2 -o $@ -DNOSIGNAL -DBATCHMODE rmd160.c rmd160_test.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
Bessel.elf: Bessel.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ Bessel.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
whet.elf: whet.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ whet.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
phrasen.elf: phrasen.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ phrasen.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
dttl.elf: dttl.c random.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ dttl.c random.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
richards_benchmark.elf: richards_benchmark.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ richards_benchmark.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
test_exception.elf: test_exception.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -O1 test_exception.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
life.elf: life.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -g life.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
r3.elf: r3.c libsys.a
|
||||
$(CC) $(CFLAGS) -O3 -o $@ -DJMIPS_VGA -O2 r3.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
gunzip.elf: gunzip.c inflate.c crc32.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -o $@ gunzip.c inflate.c crc32.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
basic_math.elf: basicmath_small.c rad2deg.c cubic.c isqrt.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -o $@ basicmath_small.c rad2deg.c cubic.c isqrt.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
JMAN_SRC= \
|
||||
jman/bintree.c \
|
||||
jman/camset.c \
|
||||
jman/engine.c \
|
||||
jman/graph_state.c \
|
||||
jman/grid.c \
|
||||
jman/imageio.c \
|
||||
jman/linklist.c \
|
||||
jman/matrix.c \
|
||||
jman/object.c \
|
||||
jman/render.c \
|
||||
jman/ri.c \
|
||||
jman/ribgen.c \
|
||||
jman/stack.c \
|
||||
jman/vars.c
|
||||
|
||||
jman_patches.elf: $(JMAN_SRC) jman/main_patches.c libsys.a
|
||||
$(CC) $(CFLAGS) -I../ -o $@ -o $@ jman/main_patches.c $(JMAN_SRC) $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
jman_patchmeshes.elf: $(JMAN_SRC) jman/main_patchmeshes.c jman/patches2.c libsys.a
|
||||
$(CC) $(CFLAGS) -I../ -o $@ -o $@ jman/main_patchmeshes.c jman/patches2.c $(JMAN_SRC) $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
jman_polys.elf: $(JMAN_SRC) jman/main_polypin.c jman/polys.c libsys.a
|
||||
$(CC) $(CFLAGS) -I../ -o $@ -o $@ jman/main_polypin.c jman/polys.c $(JMAN_SRC) $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
serdump.elf: serdump.c libsys.a
|
||||
$(CC) $(CFLAGS) -O3 -o $@ -O2 serdump.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
pppi.elf: pppissue/test1.c pppissue/utils.c pppissue/pppd.h libsys.a
|
||||
$(CC) $(CFLAGS) -O2 -o $@ -O2 pppissue/test1.c pppissue/utils.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
lwl.elf: lwl.c libsys.a
|
||||
$(CC) $(CFLAGS) -O2 -o $@ lwl.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
ucb.elf: ucb.c libsys.a
|
||||
$(CC) $(CFLAGS) -O2 -o $@ ucb.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
test_hpi.elf: hpi.c test_hpi.c cfiflash.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ -g hpi.c test_hpi.c cfiflash.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin
|
||||
|
||||
test_vga.elf: test_vga.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ test_vga.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
barcode.elf: barcode.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ barcode.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
lua.elf: lua_init.c libsys.a
|
||||
$(CC) $(CFLAGS) -I./lua-5.1.4/etc -I./lua-5.1.4/src -o $@ lua_init.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
mandelbrot.elf: mandelbrot.c libsys.a
|
||||
$(CC) $(CFLAGS) -o $@ mandelbrot.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
bogomips.elf: bogomips.c delay_mips.c libsys.a
|
||||
$(CC) $(CFLAGS) -DHZ=1000 -o $@ bogomips.c delay_mips.c $(LIBS) >$@.map
|
||||
$(OBJDUMP) -d $@ > $@.dis
|
||||
$(OBJCOPY) $@ -O binary $@.bin
|
||||
$(OBJCOPY) -O srec $@ $@.srec
|
||||
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf *.a *.o *.bin *.map *.dis *.srec *.elf $(PROG) > /dev/null
|
||||
@@ -1,47 +0,0 @@
|
||||
ENDIAN='big'
|
||||
|
||||
ifeq ($(ENDIAN), 'big')
|
||||
ENDIAN_FLAGS=-EB
|
||||
LIB_DIRS=-L $(MIPS_TOOLS_PREFIX)/mipsel-elf/lib/eb -L $(MIPS_TOOLS_PREFIX)/lib/gcc/mipsel-elf/$(MIPS_GCC_VER)/eb
|
||||
else
|
||||
ENDIAN_FLAGS=-EL
|
||||
LIB_DIRS=-L $(MIPS_TOOLS_PREFIX)/mipsel-elf/lib -L $(MIPS_TOOLS_PREFIX)/lib/gcc/mipsel-elf/$(MIPS_GCC_VER)
|
||||
endif
|
||||
|
||||
CFLAGS=$(ENDIAN_FLAGS) -Os -I. -I../ -msoft-float -march=r3000
|
||||
LFLAGS=$(ENDIAN_FLAGS) -M -T bootloader.ld
|
||||
|
||||
LIBS=-lc -lgcc
|
||||
|
||||
CC=mipsel-elf-gcc
|
||||
LD=mipsel-elf-ld
|
||||
OBJDUMP=mipsel-elf-objdump
|
||||
OBJCOPY=mipsel-elf-objcopy
|
||||
|
||||
all: bootloader_flash
|
||||
|
||||
libsys: startup_boot.S init_boot.S kernel_boot.S libsys_boot.c
|
||||
$(CC) $(CFLAGS) -c startup_boot.S -o startup.o
|
||||
$(CC) $(CFLAGS) -c init_boot.S -o init.o
|
||||
$(CC) $(CFLAGS) -c kernel_boot.S -o kernel.o
|
||||
$(CC) $(CFLAGS) -c libsys_boot.c -o libsys.o
|
||||
|
||||
bootloader: libsys bootloader.c
|
||||
$(CC) $(CFLAGS) -g -c bootloader.c
|
||||
$(LD) $(LFLAGS) $(LIB_DIRS) startup.o init.o kernel.o libsys.o bootloader.o -o bootloader.elf $(LIBS) >bootloader.map
|
||||
$(OBJDUMP) -d bootloader.elf > bootloader.dis
|
||||
$(OBJCOPY) bootloader.elf -O binary bootloader.ROM.bin
|
||||
$(OBJCOPY) -O srec bootloader.elf bootloader.srec
|
||||
romgen bootloader.ROM.bin 10 $(ENDIAN_FLAGS)
|
||||
|
||||
bootloader_flash: libsys bootloader_with_flash.c
|
||||
$(CC) $(CFLAGS) -g -c bootloader_with_flash.c
|
||||
$(CC) $(CFLAGS) -g -c ../cfiflash.c
|
||||
$(LD) $(LFLAGS) $(LIB_DIRS) startup.o init.o kernel.o libsys.o cfiflash.o bootloader_with_flash.o -o bootloader.elf $(LIBS) >bootloader.map
|
||||
$(OBJDUMP) -d bootloader.elf > bootloader.dis
|
||||
$(OBJCOPY) bootloader.elf -O binary bootloader.ROM.bin
|
||||
$(OBJCOPY) -O srec bootloader.elf bootloader.srec
|
||||
romgen bootloader.ROM.bin 11 $(ENDIAN_FLAGS)
|
||||
|
||||
clean:
|
||||
rm -rf *.o *.bin *.map *.dis *.srec *.elf *.vhd* *.tcl bootloader > /dev/null
|
||||
@@ -1,247 +0,0 @@
|
||||
#include "libsys_boot.h"
|
||||
|
||||
typedef struct _ssrec_t
|
||||
{
|
||||
UINT32 addr;
|
||||
UINT32 size;
|
||||
UINT32 type;
|
||||
UINT8 *data;
|
||||
|
||||
} srec_t;
|
||||
|
||||
enum srec_type
|
||||
{
|
||||
srec_err, srec_sob, srec_data, srec_rec, srec_eob
|
||||
};
|
||||
|
||||
UINT8 h2i(UINT8 *c)
|
||||
{
|
||||
int i;
|
||||
UINT8 t, b = 0;
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
t = c[i];
|
||||
if (t >= 'A')
|
||||
t = t - 'A' + 10;
|
||||
else
|
||||
t -= '0';
|
||||
|
||||
b = (b << 4) | t;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
int decode_srec(srec_t *pRec, UINT8 *pBuf, int buflen)
|
||||
{
|
||||
UINT8 chksum, byte;
|
||||
int alen, i;
|
||||
|
||||
if (!buflen)
|
||||
return srec_err;
|
||||
|
||||
pRec->type = srec_rec;
|
||||
alen = 0;
|
||||
if ((pBuf[1] > '0') && (pBuf[1] < '4'))
|
||||
{
|
||||
alen = pBuf[1] - '0' + 1;
|
||||
pRec->type = srec_data;
|
||||
}
|
||||
else if ((pBuf[1] >= '7') && (pBuf[1] <= '9'))
|
||||
{
|
||||
alen = 11 - (pBuf[1] - '0');
|
||||
pRec->type = srec_eob;
|
||||
}
|
||||
else if (pBuf[1] == '0')
|
||||
{
|
||||
alen = 2;
|
||||
pRec->type = srec_sob;
|
||||
}
|
||||
|
||||
byte = h2i(&pBuf[2]);
|
||||
pRec->size = byte;
|
||||
chksum = byte;
|
||||
|
||||
pRec->addr = 0;
|
||||
for (i=0; i < alen; i++)
|
||||
{
|
||||
byte = h2i(&pBuf[4+2*i]);
|
||||
pRec->addr = pRec->addr << 8 | byte;
|
||||
chksum += byte;
|
||||
}
|
||||
pRec->size -= (alen+1);
|
||||
|
||||
pRec->data = (UINT8*) &pBuf[4 + 2*alen];
|
||||
for (i=0; i < (int)pRec->size; i++)
|
||||
{
|
||||
byte = h2i(&pRec->data[2*i]);
|
||||
pRec->data[i] = byte;
|
||||
chksum += byte;
|
||||
}
|
||||
chksum = ~chksum;
|
||||
byte = h2i(&pRec->data[2*i]);
|
||||
if (chksum != byte)
|
||||
return 0;
|
||||
|
||||
return pRec->type;
|
||||
}
|
||||
|
||||
int srec_getline(UINT8 *pLine)
|
||||
{
|
||||
char c;
|
||||
int i = 0;
|
||||
|
||||
do
|
||||
{
|
||||
c = readchar();
|
||||
|
||||
} while ((c != 's') && (c != 'S'));
|
||||
|
||||
while(((c != 0x0D) && (c != 0x0A)))
|
||||
{
|
||||
pLine[i++] = c;
|
||||
c = readchar();
|
||||
};
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void Jump_to(void *pEntry)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
);
|
||||
__asm
|
||||
(
|
||||
"jr %[pEntry]\n" // jump entry
|
||||
:
|
||||
: [pEntry] "r" (pEntry)
|
||||
);
|
||||
__asm
|
||||
(
|
||||
"nop\n"
|
||||
);
|
||||
__asm
|
||||
(
|
||||
".set reorder\n"
|
||||
);
|
||||
}
|
||||
|
||||
void Exec_at(void *pEntry)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"mfc0 $26, $12\n" // change exception vector
|
||||
"li $27, 0xFFBFFFFF\n"
|
||||
"and $26, $27\n"
|
||||
"mtc0 $26, $12\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"lw $v0, 16($sp)\n"
|
||||
"nop\n"
|
||||
"jr $v0\n" // jump entry
|
||||
"rfe\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
".set reorder\n"
|
||||
);
|
||||
}
|
||||
void PrintCPUinfo(void)
|
||||
{
|
||||
int result, rev_id;
|
||||
|
||||
char *cpu_type_str[7] = {"invalid", "R2000", "R3000", "R6000", "R4000", "reserved", "R6000A"};
|
||||
|
||||
// Print Status register
|
||||
result = CP0_SR_read();
|
||||
|
||||
sputs("Status : ");
|
||||
print_word(result);
|
||||
sputs("\n");
|
||||
|
||||
// Print Revision
|
||||
result = CP0_PRID_read();
|
||||
rev_id = (result >> 8) & 0xFF;
|
||||
sputs("CPU type: ");
|
||||
if ((rev_id > 0) && (rev_id < 0x07))
|
||||
{
|
||||
sputs(cpu_type_str[rev_id]);
|
||||
sputs(" Rev.");
|
||||
rev_id = result & 0xFF;
|
||||
print_byte((char)rev_id);
|
||||
}
|
||||
else
|
||||
sputs("Unknown");
|
||||
|
||||
sputs("\n");
|
||||
|
||||
}
|
||||
|
||||
#define MAX_IMG_SIZE (1024*1024) // bytes
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
UINT8 buf[256];
|
||||
srec_t srec;
|
||||
int result, srec_state, i;
|
||||
UINT32 haddr;
|
||||
volatile UINT8 *pMem;
|
||||
haddr = 0;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
sputs("\n\n");
|
||||
PrintCPUinfo();
|
||||
sputs("Booting from UART..");
|
||||
|
||||
while(1)
|
||||
{
|
||||
sputs(".");
|
||||
while(1)
|
||||
{
|
||||
result = srec_getline(buf);
|
||||
srec_state = decode_srec(&srec, buf, result);
|
||||
switch (srec_state)
|
||||
{
|
||||
case srec_data:
|
||||
if ((srec.addr + srec.size) > haddr)
|
||||
haddr = srec.addr + srec.size;
|
||||
|
||||
pMem = (UINT8*)srec.addr;
|
||||
for (i=0; i < srec.size; i++)
|
||||
*pMem++ = srec.data[i];
|
||||
|
||||
break;
|
||||
|
||||
case srec_eob:
|
||||
sputs("done\n\n");
|
||||
sputs("Execute program at ");
|
||||
print_word(srec.addr);
|
||||
sputs("\n\n");
|
||||
|
||||
Exec_at((void*)srec.addr);
|
||||
break;
|
||||
|
||||
default:
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
MEMORY
|
||||
{
|
||||
rom : ORIGIN = 0xBFC00000, LENGTH = 0x00002000 /* 8K */
|
||||
ram : ORIGIN = 0x40000000, LENGTH = 0x00002000 /* 8K */
|
||||
}
|
||||
|
||||
OUTPUT_ARCH(mips)
|
||||
SEARCH_DIR(".");
|
||||
SEARCH_DIR("/usr/local/mipsel-elf/lib:/usr/local/mipsel-elf/lib/eb");
|
||||
SEARCH_DIR("/usr/local/lib/gcc/mipsel-elf/4.3.3:/usr/local/lib/gcc/mipsel-elf/4.3.3/eb");
|
||||
|
||||
stack_ptr = 0x7FFFEFF0;
|
||||
baudrate = 0x0D;
|
||||
sys_led_port = 0xA0000000;
|
||||
sys_uart_data = 0xA0010000;
|
||||
sys_uart_stat = 0xA0010004;
|
||||
sys_uart_baud = 0xA0010008;
|
||||
sys_timer_usec = 0xA000008;
|
||||
sys_timer_sec = 0xA000000C;
|
||||
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.init ORIGIN(rom) :
|
||||
{
|
||||
start = ALIGN(4);
|
||||
entry = ALIGN(4);
|
||||
_entry = ALIGN(4);
|
||||
__entry = ALIGN(4);
|
||||
*(.stext)
|
||||
} > rom
|
||||
|
||||
.ktext ORIGIN(rom) + 0x180 :
|
||||
{
|
||||
*(.ktext)
|
||||
} > rom
|
||||
|
||||
.text . :
|
||||
{
|
||||
*(.text)
|
||||
} > rom
|
||||
|
||||
.rodata . :
|
||||
{
|
||||
*(.rodata*)
|
||||
} > rom
|
||||
|
||||
.data ORIGIN(ram) :
|
||||
{
|
||||
*(.*data) *(.*bss) *(.*common)
|
||||
} > ram
|
||||
|
||||
}
|
||||
@@ -1,391 +0,0 @@
|
||||
#include "libsys_boot.h"
|
||||
#include "cfiflash.h"
|
||||
|
||||
#define MAGIC_EB 0x4A464931 // "JFI1" in big-endian;
|
||||
#define MAGIC_EL 0x3149464A // "JFI1" in little-endian;
|
||||
|
||||
typedef struct _ssrec_t
|
||||
{
|
||||
UINT32 addr;
|
||||
UINT32 size;
|
||||
UINT32 type;
|
||||
UINT8 *data;
|
||||
|
||||
} srec_t;
|
||||
typedef struct _sflash_alloc_tbl_t
|
||||
{
|
||||
UINT32 images[16];
|
||||
|
||||
} flash_alloc_tbl_t;
|
||||
|
||||
typedef struct _sflash_img_hdr_t
|
||||
{
|
||||
UINT32 magic;
|
||||
UINT32 target_base;
|
||||
UINT32 img_base;
|
||||
UINT32 img_size;
|
||||
UINT32 hdr_next;
|
||||
UINT8 img_name[128];
|
||||
UINT8 res[108];
|
||||
|
||||
} flash_img_hdr_t;
|
||||
|
||||
enum srec_type
|
||||
{
|
||||
srec_err, srec_sob, srec_data, srec_rec, srec_eob
|
||||
};
|
||||
|
||||
UINT8 h2i(UINT8 *c)
|
||||
{
|
||||
int i;
|
||||
UINT8 t, b = 0;
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
t = c[i];
|
||||
if (t >= 'A')
|
||||
t = t - 'A' + 10;
|
||||
else
|
||||
t -= '0';
|
||||
|
||||
b = (b << 4) | t;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
int decode_srec(srec_t *pRec, UINT8 *pBuf, int buflen)
|
||||
{
|
||||
UINT8 chksum, byte;
|
||||
int alen, i;
|
||||
|
||||
if (!buflen)
|
||||
return srec_err;
|
||||
|
||||
pRec->type = srec_rec;
|
||||
alen = 0;
|
||||
if ((pBuf[1] > '0') && (pBuf[1] < '4'))
|
||||
{
|
||||
alen = pBuf[1] - '0' + 1;
|
||||
pRec->type = srec_data;
|
||||
}
|
||||
else if ((pBuf[1] >= '7') && (pBuf[1] <= '9'))
|
||||
{
|
||||
alen = 11 - (pBuf[1] - '0');
|
||||
pRec->type = srec_eob;
|
||||
}
|
||||
else if (pBuf[1] == '0')
|
||||
{
|
||||
alen = 2;
|
||||
pRec->type = srec_sob;
|
||||
}
|
||||
|
||||
byte = h2i(&pBuf[2]);
|
||||
pRec->size = byte;
|
||||
chksum = byte;
|
||||
|
||||
pRec->addr = 0;
|
||||
for (i=0; i < alen; i++)
|
||||
{
|
||||
byte = h2i(&pBuf[4+2*i]);
|
||||
pRec->addr = pRec->addr << 8 | byte;
|
||||
chksum += byte;
|
||||
}
|
||||
pRec->size -= (alen+1);
|
||||
|
||||
pRec->data = (UINT8*) &pBuf[4 + 2*alen];
|
||||
for (i=0; i < (int)pRec->size; i++)
|
||||
{
|
||||
byte = h2i(&pRec->data[2*i]);
|
||||
pRec->data[i] = byte;
|
||||
chksum += byte;
|
||||
}
|
||||
chksum = ~chksum;
|
||||
byte = h2i(&pRec->data[2*i]);
|
||||
if (chksum != byte)
|
||||
return 0;
|
||||
|
||||
return pRec->type;
|
||||
}
|
||||
|
||||
int srec_getline(UINT8 *pLine)
|
||||
{
|
||||
char c;
|
||||
int i = 0;
|
||||
|
||||
do
|
||||
{
|
||||
c = readchar();
|
||||
|
||||
} while ((c != 's') && (c != 'S'));
|
||||
|
||||
while(((c != 0x0D) && (c != 0x0A)))
|
||||
{
|
||||
pLine[i++] = c;
|
||||
c = readchar();
|
||||
};
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void Jump_to(void *pEntry)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
);
|
||||
__asm
|
||||
(
|
||||
"jr %[pEntry]\n" // jump entry
|
||||
:
|
||||
: [pEntry] "r" (pEntry)
|
||||
);
|
||||
__asm
|
||||
(
|
||||
"nop\n"
|
||||
);
|
||||
__asm
|
||||
(
|
||||
".set reorder\n"
|
||||
);
|
||||
}
|
||||
|
||||
void Exec_at(void *pEntry)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"li $26, 0x10000000\n"
|
||||
"mtc0 $26, $12\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"jr %[pEntry]\n" // jump entry
|
||||
:
|
||||
: [pEntry] "r" (pEntry)
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"rfe\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
".set reorder\n"
|
||||
);
|
||||
}
|
||||
|
||||
void Exec_RE_at(void *pEntry)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"mfc0 $26, $12\n" // change exception vector
|
||||
"li $27, 0xFFBFFFFF\n"
|
||||
"and $26, $27\n"
|
||||
"li $27, 0x02000000\n" // Reverse Endianess
|
||||
"or $26, $27\n"
|
||||
"mtc0 $26, $12\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"jr %[pEntry]\n" // jump entry
|
||||
:
|
||||
: [pEntry] "r" (pEntry)
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
"rfe\n"
|
||||
);
|
||||
|
||||
__asm
|
||||
(
|
||||
".set reorder\n"
|
||||
);
|
||||
}
|
||||
|
||||
#define MAX_IMG_SIZE (1024*1024) // bytes
|
||||
#define SDRAM_BASE 0x40000000
|
||||
#define FLASH_USE_BLOCK 1
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
UINT8 buf[256];
|
||||
srec_t srec;
|
||||
int srec_state, i;
|
||||
UINT32 haddr, result;
|
||||
flash_t flash;
|
||||
flash_img_hdr_t img_hdr = {0};
|
||||
flash_img_hdr_t *pImg_hdr;
|
||||
UINT32 img_size, block_sel;
|
||||
|
||||
volatile UINT32 *pReg = (UINT32*)SYS_LED_PORT;
|
||||
volatile UINT32 *pBtn = (UINT32*)SYS_GPIO0;
|
||||
volatile UINT32 *pDip = (UINT32*)SYS_GPIO1;
|
||||
volatile UINT8 *pMem;
|
||||
volatile UINT32 *pROM32;
|
||||
volatile UINT32 *pMem32;
|
||||
volatile UINT32 *pFlashIO = (UINT32*)SYS_FLASH_IO; // Flash in uncached area
|
||||
volatile UINT32 *pFlashMem = (UINT32*)SYS_FLASH_MEM; // Flash in cached area
|
||||
volatile UINT32 *pUSB = (UINT32*)SYS_USB_DATA;
|
||||
|
||||
volatile UINT8 *ram8 = (UINT8*)SDRAM_BASE;
|
||||
volatile UINT16 *ram16 = (UINT16*)SDRAM_BASE;
|
||||
volatile UINT32 *ram32 = (UINT32*)SDRAM_BASE;
|
||||
UINT32 flash_offset;
|
||||
|
||||
*pReg = 0;
|
||||
haddr = 0;
|
||||
block_sel = 0x7F & (UINT32)*pDip;
|
||||
|
||||
// ----------------------------------------------------------
|
||||
if (IS_ERROR(flash_find(&flash, SYS_FLASH_IO)))
|
||||
{
|
||||
sputs("Cannot find flash device. Exit now!\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get flash offset by value of DIP-switch
|
||||
flash_offset = flash_get_offset_by_blocknum(&flash, block_sel);
|
||||
|
||||
ram32 = (UINT32*)(SDRAM_BASE);
|
||||
pFlashIO = (UINT32*)(SYS_FLASH_IO + flash_offset);
|
||||
|
||||
if (!(*pBtn & 8))
|
||||
{
|
||||
sputs("\n\n");
|
||||
pImg_hdr = (flash_img_hdr_t*)pFlashIO;
|
||||
if ((pImg_hdr->magic != MAGIC_EL) && (pImg_hdr->magic != MAGIC_EB))
|
||||
{
|
||||
sputs("\n\n");
|
||||
sputs("Invalid image found at ");print_word(flash_offset); sputs(". Abort.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sputs("Booting application from flash (");print_word(flash_offset);sputs(")...");
|
||||
|
||||
ram32 = (UINT32*)pImg_hdr->target_base;
|
||||
img_size = pImg_hdr->img_size;
|
||||
|
||||
// It's safe to use cached Flash,
|
||||
// because D-Cache was invalidated during execution of start code
|
||||
// pFlashIO = (UINT32*)(SYS_FLASH_IO + pImg_hdr->img_base);
|
||||
pFlashMem = (UINT32*)(SYS_FLASH_MEM + pImg_hdr->img_base);
|
||||
|
||||
for (i=0; i < img_size/4; i++)
|
||||
// ram32[i] = pFlashIO[i];
|
||||
ram32[i] = pFlashMem[i];
|
||||
|
||||
sputs("done\n");
|
||||
|
||||
sputs("Execute at ");print_word(pImg_hdr->target_base); sputs("\n\n");
|
||||
Exec_at((void*)ram32);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
sputs("\n\n");
|
||||
|
||||
sputs("Reading HEX-Record from UART..");
|
||||
|
||||
// Erase SDRAM
|
||||
for (i=0; i < MAX_IMG_SIZE/4; i++)
|
||||
ram32[i] = 0;
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
sputs(".");
|
||||
while(1)
|
||||
{
|
||||
result = srec_getline(buf);
|
||||
srec_state = decode_srec(&srec, buf, result);
|
||||
*pReg = 0;
|
||||
switch (srec_state)
|
||||
{
|
||||
case srec_data:
|
||||
if ((srec.addr + srec.size) > haddr)
|
||||
haddr = srec.addr + srec.size;
|
||||
|
||||
pMem = (UINT8*)srec.addr;
|
||||
for (i=0; i < srec.size; i++)
|
||||
*pMem++ = srec.data[i];
|
||||
|
||||
break;
|
||||
|
||||
case srec_eob:
|
||||
sputs("done\n\n");
|
||||
img_hdr.magic = MAGIC_EB;
|
||||
img_hdr.target_base = srec.addr;
|
||||
img_hdr.img_size = haddr - srec.addr;
|
||||
img_hdr.img_base = flash_offset + sizeof(flash_img_hdr_t);
|
||||
img_hdr.hdr_next = flash_get_offset_blockaligned(&flash, img_hdr.img_base + img_hdr.img_size);
|
||||
sputs("Size of application : ");print_word(img_hdr.img_size); sputs("\n");
|
||||
sputs("Programming flash at : ");print_word(flash_offset); sputs("\n");
|
||||
sputs("Next free flash offset : ");print_word(img_hdr.hdr_next); sputs("\n");
|
||||
|
||||
sputs("Flash erase...");
|
||||
result = flash_erase(&flash, flash_offset, img_hdr.img_size + sizeof(flash_img_hdr_t));
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
sputs("failed (");print_word(result);sputs(")\n");
|
||||
break;
|
||||
}
|
||||
sputs("done\n");
|
||||
|
||||
sputs("Flash write...");
|
||||
result = flash_program(&flash, flash_offset, (UINT8*)&img_hdr, sizeof(flash_img_hdr_t));
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
sputs("failed (");print_word(result);sputs(")\n");
|
||||
break;
|
||||
}
|
||||
result = flash_program(&flash, img_hdr.img_base, (UINT8*)img_hdr.target_base, img_hdr.img_size);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
sputs("failed (");print_word(result);sputs(")\n");
|
||||
break;
|
||||
}
|
||||
sputs("done\n");
|
||||
|
||||
sputs("Flash verify...");
|
||||
result = flash_verify(&flash, img_hdr.img_base, (UINT8*)img_hdr.target_base, img_hdr.img_size);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
sputs("failed (");print_word(result);sputs(")\n");
|
||||
break;
|
||||
}
|
||||
sputs("passed\n");
|
||||
|
||||
// Jump to reset vector
|
||||
Jump_to((void*)0xBFC00000);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
*pReg = 0x40000000;
|
||||
break;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
.file "init.S"
|
||||
|
||||
.text
|
||||
.section .init,"ax"
|
||||
.align 2
|
||||
.globl _init
|
||||
.extern end
|
||||
|
||||
_init:
|
||||
.set noreorder
|
||||
|
||||
# set uart
|
||||
la $26, sys_uart_baud
|
||||
addiu $27, $0, baudrate
|
||||
sw $27, 0($26)
|
||||
|
||||
jr $ra
|
||||
|
||||
.set reorder
|
||||
@@ -1,46 +0,0 @@
|
||||
.file "kernel.S"
|
||||
|
||||
.section .ktext,"ax"
|
||||
.align 2
|
||||
|
||||
.macro kpush reg
|
||||
addiu $sp, 4
|
||||
sw \reg, 0($sp)
|
||||
.endm
|
||||
|
||||
.macro kpop reg
|
||||
lw \reg, 0($sp)
|
||||
addiu $sp, -4
|
||||
.endm
|
||||
|
||||
_exc_handler:
|
||||
|
||||
.set noreorder
|
||||
|
||||
# Set Error LED and ExcCode LEDs
|
||||
# Get Cause
|
||||
mfc0 $26, $13
|
||||
li $27, 0xC0000000
|
||||
srl $26, 2
|
||||
andi $26, 0x000F
|
||||
or $26, $27
|
||||
la $27, sys_led_port
|
||||
sw $26, 0($27)
|
||||
|
||||
# wait for all interrupts = 0
|
||||
$w4x: mfc0 $26, $13
|
||||
nop
|
||||
srl $26, 8
|
||||
andi $26, 0xFF
|
||||
bnez $26, $w4x
|
||||
nop
|
||||
|
||||
# Get return address
|
||||
mfc0 $26, $14
|
||||
|
||||
# Return
|
||||
nop
|
||||
jr $26
|
||||
rfe
|
||||
.set reorder
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
#include <sys/times.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include "libsys_boot.h"
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// MIPS specific
|
||||
UINT32 CP0_SR_read(void)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
__asm
|
||||
(
|
||||
"mfc0 %[val], $12\n"
|
||||
: [val] "=r" (result)
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CP0_SR_write(UINT32 val)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
"mtc0 %[val], $12\n"
|
||||
: /* no output */
|
||||
: [val] "r" (val)
|
||||
);
|
||||
}
|
||||
|
||||
UINT32 CP0_CR_read(void)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
__asm
|
||||
(
|
||||
"mfc0 %[val], $13\n"
|
||||
: [val] "=r" (result)
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CP0_CR_write(UINT32 val)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
"mtc0 %[val], $13\n"
|
||||
:
|
||||
: [val] "r" (val)
|
||||
);
|
||||
}
|
||||
|
||||
UINT32 CP0_PRID_read(void)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
__asm
|
||||
(
|
||||
"mfc0 %[val], $15\n"
|
||||
: [val] "=r" (result)
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
char readchar(void)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)SYS_UART_STAT;
|
||||
volatile UINT32 *pUART_data = (UINT32*)SYS_UART_DATA;
|
||||
|
||||
while(!(0x10 & *pUART_stat));
|
||||
|
||||
return (char)*pUART_data;
|
||||
}
|
||||
|
||||
void writechar(char c)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)SYS_UART_STAT;
|
||||
volatile UINT32 *pUART_data = (UINT32*)SYS_UART_DATA;
|
||||
|
||||
while((0x02 & *pUART_stat) != 0);
|
||||
|
||||
*pUART_data = (UINT32)c;
|
||||
}
|
||||
|
||||
void _putchar(char c)
|
||||
{
|
||||
if (c == 0x0A)
|
||||
{
|
||||
writechar(0x0D);
|
||||
}
|
||||
writechar(c);
|
||||
}
|
||||
|
||||
int sputs(char *pStr)
|
||||
{
|
||||
char *start;
|
||||
start = pStr;
|
||||
|
||||
while(*pStr)
|
||||
_putchar(*(pStr++));
|
||||
|
||||
return pStr - start;
|
||||
}
|
||||
|
||||
void print_byte(char byte)
|
||||
{
|
||||
int i;
|
||||
unsigned char c, nibble;
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
nibble = (char)((byte >> 4) & 0xF);
|
||||
byte <<= 4;
|
||||
|
||||
if (nibble < 10)
|
||||
c = nibble + '0';
|
||||
else
|
||||
c = nibble + 'A' - 10;
|
||||
|
||||
_putchar(c);
|
||||
}
|
||||
}
|
||||
|
||||
void print_word(int word)
|
||||
{
|
||||
int i;
|
||||
unsigned char c, nibble;
|
||||
|
||||
for (i=0; i < 4; i++)
|
||||
{
|
||||
c = (char) (word >> 24);
|
||||
print_byte(c);
|
||||
word <<= 8;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// PrintBuffer8()
|
||||
// Prints byte buffer as hex and ascii interpretation
|
||||
// ---------------------------------------------------------------------------------
|
||||
// _Parameters :
|
||||
// pBuf: : IN: Buffer to display
|
||||
// nbpr : Number of bytes per row to display
|
||||
// len : Length of input buffer
|
||||
// _Return: none
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
void PrintBuffer8(UINT8 *pBuf, int nbpr, int len)
|
||||
{
|
||||
memdump(pBuf, 1, nbpr, len);
|
||||
}
|
||||
|
||||
void memdump(UINT8 *pBuf, int print_offset_only, int num_bytes_per_row, int len)
|
||||
{
|
||||
int i, j, cnt_hex, cnt_asc, base;
|
||||
unsigned char c;
|
||||
|
||||
i = j = 0;
|
||||
cnt_hex = len;
|
||||
cnt_asc = len;
|
||||
base = 0;
|
||||
if (!print_offset_only)
|
||||
base = (int)pBuf;
|
||||
|
||||
do
|
||||
{
|
||||
print_word(base + i);
|
||||
sputs(": ");
|
||||
for (j=0; j < num_bytes_per_row; j++)
|
||||
{
|
||||
if (cnt_hex)
|
||||
{
|
||||
print_byte(pBuf[i+j]);
|
||||
sputs(" ");
|
||||
cnt_hex--;
|
||||
}
|
||||
else
|
||||
{
|
||||
sputs(" ");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sputs(" ");
|
||||
for (j=0; j < num_bytes_per_row; j++)
|
||||
{
|
||||
if (cnt_asc)
|
||||
{
|
||||
c = pBuf[i+j];
|
||||
if((c < 0x20) || (c > 0x7F))
|
||||
c = '.';
|
||||
|
||||
_putchar(c);
|
||||
cnt_asc--;
|
||||
}
|
||||
else
|
||||
{
|
||||
sputs(" ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sputs("\n");
|
||||
i += num_bytes_per_row;
|
||||
|
||||
} while (cnt_hex);
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef LIBSYS_H
|
||||
#define LIBSYS_H
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Types
|
||||
// ---------------------------------------------------------
|
||||
#define INT8 char
|
||||
#define INT16 short
|
||||
#define INT32 long
|
||||
#define UINT8 unsigned char
|
||||
#define UINT16 unsigned short
|
||||
#define UINT32 unsigned long
|
||||
#define INT int
|
||||
#define UINT unsigned int
|
||||
#define FLOAT32 float
|
||||
#define FLOAT64 double
|
||||
|
||||
#define IS_ERROR(e) ((e & 0x80000000) == 0x80000000)
|
||||
|
||||
#define SYS_GPIO0 0xA0000000
|
||||
#define SYS_GPIO1 0xA0000004
|
||||
#define SYS_LED_PORT SYS_GPIO0
|
||||
#define SYS_USB_CTRL SYS_GPIO1
|
||||
#define SYS_TIMER_USEC 0xA0000008
|
||||
#define SYS_TIMER_SEC 0xA000000C
|
||||
#define SYS_UART_DATA 0xA0010000
|
||||
#define SYS_UART_STAT 0xA0010004
|
||||
#define SYS_UART_BAUD 0xA0010008
|
||||
#define SYS_USB_DATA 0xA0020000
|
||||
#define SYS_USB_MBX 0xA0020004
|
||||
#define SYS_USB_ADDR 0xA0020008
|
||||
#define SYS_USB_STATUS 0xA002000C
|
||||
#define SYS_FLASH_IO 0xA4000000
|
||||
#define SYS_FLASH_MEM 0x00000000
|
||||
|
||||
// MIPS specific
|
||||
UINT32 CP0_SR_read(void);
|
||||
void CP0_SR_write(UINT32 val);
|
||||
UINT32 CP0_CR_read(void);
|
||||
void CP0_CR_write(UINT32 val);
|
||||
UINT32 CP0_PRID_read(void);
|
||||
|
||||
// General
|
||||
char readchar(void);
|
||||
void writechar(char c);
|
||||
int write(int file, char *ptr, int len);
|
||||
int sputs(char *pStr);
|
||||
void print_byte(char byte);
|
||||
void print_word(int word);
|
||||
void PrintBuffer8(UINT8 *pBuf, int nbpr, int len);
|
||||
void memdump(UINT8 *pBuf, int print_offset_only, int num_bytes_per_row, int len);
|
||||
|
||||
#endif // LIBSYS_H
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
.file "startup.S"
|
||||
|
||||
.text
|
||||
.section .init,"ax"
|
||||
.extern _init
|
||||
.align 2
|
||||
|
||||
_start:
|
||||
.set noreorder
|
||||
|
||||
# set stack pointer
|
||||
la $sp, stack_ptr
|
||||
|
||||
# Set Kernel mode
|
||||
li $26, 0x1040000C
|
||||
mtc0 $26, $12
|
||||
li $26, 0x00000000
|
||||
mtc0 $26, $13
|
||||
|
||||
mfc0 $26, $15
|
||||
nop
|
||||
mtc0 $26, $31
|
||||
|
||||
# Invalidate I-Cache
|
||||
cop0 32
|
||||
|
||||
# Invalidate D-Cache
|
||||
cop0 34
|
||||
|
||||
# jump init
|
||||
la $26, _init
|
||||
jalr $26
|
||||
nop
|
||||
|
||||
la $26, main
|
||||
jalr $26
|
||||
nop
|
||||
_terminate:
|
||||
nop
|
||||
j _terminate
|
||||
nop
|
||||
|
||||
.set reorder
|
||||
@@ -1,415 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "libsys.h"
|
||||
#include "cfiflash.h"
|
||||
|
||||
UINT32 cfi_get_status(flash_t *pObj)
|
||||
{
|
||||
volatile UINT32 *pF;
|
||||
UINT32 status;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
|
||||
*pF = 0x00700070;
|
||||
|
||||
status = *pF;
|
||||
|
||||
*pF = 0x00FF00FF;
|
||||
|
||||
return status;
|
||||
|
||||
}
|
||||
|
||||
void cfi_init(flash_t *pObj, UINT32 base_addr)
|
||||
{
|
||||
int i;
|
||||
UINT8 *pInfo;
|
||||
UINT32 endian;
|
||||
UINT8 *pEndian;
|
||||
|
||||
pObj->pBase = (void*)base_addr;
|
||||
|
||||
pInfo = (UINT8*)&pObj->info;
|
||||
for (i=0; i < sizeof(flash_info_t); i++)
|
||||
{
|
||||
pInfo[i] = 0;
|
||||
}
|
||||
pObj->eb = 0;
|
||||
endian = 0x12345678;
|
||||
pEndian = (UINT8*)&endian;
|
||||
if (*pEndian == 0x12)
|
||||
{
|
||||
pObj->eb = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UINT32 cfi_find(flash_t *pObj)
|
||||
{
|
||||
int i;
|
||||
volatile UINT32 *pF;
|
||||
volatile UINT16 *pF16;
|
||||
// UINT8 qry_ref[12] = {0x51, 0x00, 0x51, 0x00, 0x52, 0x00, 0x52, 0x00, 0x59, 0x00, 0x59, 0x00};
|
||||
UINT32 size;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
pF16 = (UINT16*)pObj->pBase;
|
||||
|
||||
// Look for flash
|
||||
*pF = 0x00980098;
|
||||
// for (i=0; i < sizeof(qry_ref); i++)
|
||||
// if (((UINT8*)(&pF[0x10]))[i] != qry_ref[i])
|
||||
// return (UINT32)-1;
|
||||
|
||||
*pF = 0x00FF00FF;
|
||||
*pF = 0x00900090;
|
||||
|
||||
/*
|
||||
printf("ManID : %8.8X\n", (UINT32)pF[0]);
|
||||
printf("Device code : %8.8X\n", (UINT32)pF[1]);
|
||||
printf("Block info : %8.8X\n", (UINT32)pF[2]);
|
||||
|
||||
printf("VCC(min) : %8.8X\n", (UINT32)pF[0x1B]);
|
||||
printf("VCC(max) : %8.8X\n", (UINT32)pF[0x1C]);
|
||||
printf("VPP(min) : %8.8X\n", (UINT32)pF[0x1D]);
|
||||
printf("VPP(max) : %8.8X\n", (UINT32)pF[0x1E]);
|
||||
printf("Device Layout : %8.8X\n", (UINT32)pF[0x27]);
|
||||
printf("Interface type : %8.8X %8.8X\n", (UINT32)pF[0x28], (UINT32)pF[0x29]);
|
||||
printf("Write buffer size : %8.8X %8.8X\n", (UINT32)pF[0x2A], (UINT32)pF[0x2B]);
|
||||
printf("Num. erase blocks : %8.8X\n", (UINT32)pF[0x2C]);
|
||||
printf("Erase block info : %8.8X %8.8X %8.8X %8.8X\n", (UINT32)pF[0x2D], (UINT32)pF[0x2E], (UINT32)pF[0x2F], (UINT32)pF[0x30]);
|
||||
*/
|
||||
pObj->info.num_flash = 2;
|
||||
pObj->info.if_width = 32;
|
||||
size = (UINT32)pF16[2*0x27];
|
||||
pObj->info.flashsize = pObj->info.num_flash;
|
||||
for (i=0; i < size; i++)
|
||||
pObj->info.flashsize *= 2;
|
||||
|
||||
size = (UINT32)(pF16[2*0x2B] << 8 | pF16[2*0x2A]);
|
||||
pObj->info.wbuf_size = pObj->info.num_flash;
|
||||
for (i=0; i < size; i++)
|
||||
pObj->info.wbuf_size *= 2;
|
||||
|
||||
pObj->info.nblocks = (UINT32)(pF16[2*0x2E] << 8 | pF16[2*0x2D]) + 1;
|
||||
pObj->info.blocksize = pObj->info.num_flash * ((UINT32)(pF16[2*0x30] << 8 | pF16[2*0x2F]) * 256);
|
||||
|
||||
*pF = 0x00FF00FF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 cfi_block_is_locked(flash_t *pObj, UINT32 word_index)
|
||||
{
|
||||
volatile UINT32 *pF;
|
||||
UINT32 status, block_index, block_mask;
|
||||
UINT32 error;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
|
||||
if (word_index >= (pObj->info.flashsize/4))
|
||||
return CFI_ERR_INVPARAM;
|
||||
|
||||
block_mask = ((pObj->info.nblocks-1) << 16);
|
||||
block_index = word_index & block_mask;
|
||||
|
||||
*pF = 0x00900090;
|
||||
|
||||
error = ((UINT32)pF[block_index+2] & 0x00010001) != 0;
|
||||
*pF = 0x00FF00FF;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index)
|
||||
{
|
||||
volatile UINT32 *pF;
|
||||
UINT32 status, block_index, block_mask;
|
||||
UINT32 error;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
|
||||
if (word_index >= (pObj->info.flashsize/4))
|
||||
return CFI_ERR_INVPARAM;
|
||||
|
||||
block_mask = ((pObj->info.nblocks-1) << 16);
|
||||
block_index = word_index & block_mask;
|
||||
|
||||
pF[block_index] = 0x00200020;
|
||||
pF[block_index] = 0x00D000D0;
|
||||
|
||||
error = 0;
|
||||
do
|
||||
{
|
||||
status = pF[block_index];
|
||||
|
||||
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
|
||||
|
||||
if (status & (SR_BIT_ECLBS | SR_BIT_VPENS | SR_BIT_DPS))
|
||||
{
|
||||
error = CFI_ERR_DEV_FAIL | status;
|
||||
}
|
||||
|
||||
pF[block_index] = 0x00FF00FF;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
UINT32 cfi_block_lock(flash_t *pObj, UINT32 word_index)
|
||||
{
|
||||
volatile UINT32 *pF;
|
||||
UINT32 status, block_index, block_mask;
|
||||
UINT32 error;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
|
||||
if (word_index >= (pObj->info.flashsize/4))
|
||||
return CFI_ERR_INVPARAM;
|
||||
|
||||
block_mask = ((pObj->info.nblocks-1) << 16);
|
||||
block_index = word_index & block_mask;
|
||||
|
||||
pF[block_index] = 0x00600060;
|
||||
pF[block_index] = 0x00010001;
|
||||
|
||||
error = 0;
|
||||
do
|
||||
{
|
||||
status = pF[block_index];
|
||||
|
||||
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
|
||||
|
||||
if (status & (SR_BIT_PSLBS | SR_BIT_VPENS | SR_BIT_ECLBS))
|
||||
{
|
||||
error = CFI_ERR_DEV_FAIL | status;
|
||||
}
|
||||
|
||||
pF[block_index] = 0x00FF00FF;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
UINT32 cfi_block_unlock(flash_t *pObj, UINT32 word_index)
|
||||
{
|
||||
volatile UINT32 *pF;
|
||||
UINT32 status, block_index, block_mask;
|
||||
UINT32 error;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
|
||||
if (word_index >= (pObj->info.flashsize/4))
|
||||
return CFI_ERR_INVPARAM;
|
||||
|
||||
block_mask = ((pObj->info.nblocks-1) << 16);
|
||||
block_index = word_index & block_mask;
|
||||
|
||||
pF[block_index] = 0x00600060;
|
||||
pF[block_index] = 0x00D000D0;
|
||||
|
||||
error = 0;
|
||||
do
|
||||
{
|
||||
status = pF[block_index];
|
||||
|
||||
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
|
||||
|
||||
if (status & (SR_BIT_PSLBS | SR_BIT_VPENS | SR_BIT_ECLBS))
|
||||
{
|
||||
error = CFI_ERR_DEV_FAIL | status;
|
||||
}
|
||||
|
||||
pF[block_index] = 0x00FF00FF;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word)
|
||||
{
|
||||
volatile UINT32 *pF;
|
||||
UINT32 status, error;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
|
||||
if (word_index >= (pObj->info.flashsize/4))
|
||||
return CFI_ERR_INVPARAM;
|
||||
|
||||
pF[word_index] = 0x00400040;
|
||||
pF[word_index] = word;
|
||||
|
||||
error = 0;
|
||||
do
|
||||
{
|
||||
status = pF[word_index];
|
||||
|
||||
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
|
||||
|
||||
if (status & (SR_BIT_PSLBS | SR_BIT_VPENS | SR_BIT_DPS))
|
||||
{
|
||||
error = CFI_ERR_DEV_FAIL | status;
|
||||
}
|
||||
|
||||
pF[word_index] = 0x00FF00FF;
|
||||
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT32 num_words)
|
||||
{
|
||||
int i, j, k;
|
||||
volatile UINT32 *pF;
|
||||
UINT32 status, bcurr, bnext, block_mask, nblock_write, nbuf_write;
|
||||
UINT32 error;
|
||||
|
||||
pF = (UINT32*)pObj->pBase;
|
||||
|
||||
if (word_index >= (pObj->info.flashsize/4))
|
||||
return CFI_ERR_INVPARAM;
|
||||
|
||||
block_mask = ((pObj->info.nblocks-1) << 16);
|
||||
|
||||
k = 0;
|
||||
while(num_words)
|
||||
{
|
||||
|
||||
bcurr = word_index & block_mask;
|
||||
bnext = bcurr + (1 << 16);
|
||||
nblock_write = bnext - word_index;
|
||||
if (nblock_write > num_words)
|
||||
nblock_write = num_words;
|
||||
|
||||
while(nblock_write)
|
||||
{
|
||||
error = 0;
|
||||
pF[bcurr] = 0x00E800E8;
|
||||
do
|
||||
{
|
||||
status = pF[bcurr];
|
||||
|
||||
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
|
||||
if (status & (SR_BIT_PSLBS | SR_BIT_VPENS | SR_BIT_DPS))
|
||||
{
|
||||
error = CFI_ERR_DEV_FAIL | status;
|
||||
break;
|
||||
}
|
||||
|
||||
nbuf_write = nblock_write;
|
||||
if (nblock_write > pObj->info.wbuf_size/4)
|
||||
nbuf_write = pObj->info.wbuf_size/4;
|
||||
|
||||
pF[bcurr] = (nbuf_write-1) << 16 | (nbuf_write-1);
|
||||
|
||||
for (j=0; j < nbuf_write; j++)
|
||||
pF[word_index+j] = pWords[k++];
|
||||
|
||||
word_index += j;
|
||||
nblock_write -= j;
|
||||
num_words -= j;
|
||||
|
||||
error = 0;
|
||||
pF[bcurr] = 0x00D000D0;
|
||||
do
|
||||
{
|
||||
status = pF[bcurr];
|
||||
|
||||
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
|
||||
if (status & (SR_BIT_PSLBS | SR_BIT_VPENS | SR_BIT_DPS))
|
||||
{
|
||||
error = CFI_ERR_DEV_FAIL | status;
|
||||
break;
|
||||
}
|
||||
|
||||
pF[bcurr] = 0x00FF00FF;
|
||||
}
|
||||
|
||||
if (IS_ERROR(error))
|
||||
{
|
||||
pF[bcurr] = 0x00FF00FF;
|
||||
break;
|
||||
}
|
||||
bcurr = bnext;
|
||||
}
|
||||
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
UINT32 flash_find(flash_t *pObj, UINT32 base_addr)
|
||||
{
|
||||
cfi_init(pObj, base_addr);
|
||||
return cfi_find(pObj);
|
||||
}
|
||||
|
||||
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size)
|
||||
{
|
||||
int i;
|
||||
UINT32 offset_end, error;
|
||||
|
||||
if (size % 4)
|
||||
size = 4*(size/4 + 1);
|
||||
|
||||
offset_end = offset + size;
|
||||
|
||||
for (i=offset; i < offset_end; i += pObj->info.blocksize)
|
||||
{
|
||||
if (cfi_block_is_locked(pObj, i/4))
|
||||
{
|
||||
error = cfi_block_unlock(pObj, i/4);
|
||||
if (IS_ERROR(error))
|
||||
break;
|
||||
}
|
||||
error = cfi_block_erase(pObj, i/4);
|
||||
if (IS_ERROR(error))
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
UINT32 flash_program(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
|
||||
{
|
||||
if (size % 4)
|
||||
size = 4*(size/4 + 1);
|
||||
|
||||
return cfi_program_multi(pObj, offset/4, (UINT32*)pData, size/4);
|
||||
}
|
||||
|
||||
UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
|
||||
{
|
||||
int i;
|
||||
UINT8 *pF;
|
||||
|
||||
pF = (UINT8*)(pObj->pBase + offset);
|
||||
|
||||
for (i=0; i < size; i++)
|
||||
if (pF[i] != pData[i])
|
||||
return CFI_ERR_VFY_FAIL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 flash_get_blocknum_by_offset(flash_t *pObj, UINT32 offset)
|
||||
{
|
||||
UINT32 blocknum;
|
||||
|
||||
blocknum = offset/pObj->info.blocksize;
|
||||
if (offset%pObj->info.blocksize)
|
||||
blocknum++;
|
||||
|
||||
return blocknum;
|
||||
}
|
||||
|
||||
UINT32 flash_get_offset_by_blocknum(flash_t *pObj, UINT32 blocknum)
|
||||
{
|
||||
if (blocknum >= pObj->info.nblocks)
|
||||
blocknum = pObj->info.nblocks - 1;
|
||||
|
||||
return blocknum*pObj->info.blocksize;
|
||||
}
|
||||
|
||||
UINT32 flash_get_offset_blockaligned(flash_t *pObj, UINT32 offset)
|
||||
{
|
||||
return flash_get_blocknum_by_offset(pObj, offset) * pObj->info.blocksize;
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/************************************************************************/
|
||||
#ifndef CFIFLASH_H
|
||||
#define CFIFLASH_H
|
||||
|
||||
#include "libsys.h"
|
||||
|
||||
#define SR_BIT_DPS 0x00020002
|
||||
#define SR_BIT_PSS 0x00040004
|
||||
#define SR_BIT_VPENS 0x00080008
|
||||
#define SR_BIT_PSLBS 0x00100010
|
||||
#define SR_BIT_ECLBS 0x00200020
|
||||
#define SR_BIT_ESS 0x00400040
|
||||
#define SR_BIT_ISMS 0x00800080
|
||||
|
||||
#define CFI_ERR_BASE (LSYS_ERR_BASE + 0x00100000)
|
||||
#define CFI_ERR_GENERAL (CFI_ERR_BASE + 0)
|
||||
#define CFI_ERR_NOTFOUND (CFI_ERR_BASE + 1)
|
||||
#define CFI_ERR_INVPARAM (CFI_ERR_BASE + 2)
|
||||
#define CFI_ERR_VFY_FAIL (CFI_ERR_BASE + 3)
|
||||
#define CFI_ERR_DEV_FAIL (CFI_ERR_BASE + 0x10000000)
|
||||
|
||||
typedef struct _sflash_info_t
|
||||
{
|
||||
UINT32 flashsize;
|
||||
UINT32 blocksize;
|
||||
UINT32 nblocks;
|
||||
UINT32 wbuf_size;
|
||||
UINT32 if_width;
|
||||
UINT32 num_flash;
|
||||
|
||||
} flash_info_t;
|
||||
|
||||
typedef struct _sflash_t
|
||||
{
|
||||
void *pBase;
|
||||
UINT32 eb;
|
||||
flash_info_t info;
|
||||
|
||||
} flash_t;
|
||||
|
||||
void cfi_init(flash_t *pObj, UINT32 base_addr);
|
||||
UINT32 cfi_find(flash_t *pObj);
|
||||
UINT32 cfi_block_is_locked(flash_t *pObj, UINT32 word_index);
|
||||
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index);
|
||||
UINT32 cfi_block_lock(flash_t *pObj, UINT32 word_index);
|
||||
UINT32 cfi_block_unlock(flash_t *pObj, UINT32 word_index);
|
||||
UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word);
|
||||
UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT32 num_words);
|
||||
|
||||
UINT32 flash_get_offset_by_blocknum(flash_t *pObj, UINT32 blocknum);
|
||||
UINT32 flash_get_blocknum_by_offset(flash_t *pObj, UINT32 offset);
|
||||
UINT32 flash_get_offset_blockaligned(flash_t *pObj, UINT32 offset);
|
||||
UINT32 flash_find(flash_t *pObj, UINT32 base_addr);
|
||||
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size);
|
||||
UINT32 flash_program(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);
|
||||
UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);
|
||||
|
||||
#endif // CFIFLASH_H
|
||||
@@ -1,54 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned long MakeCRC32(char *data, unsigned int len, unsigned int CRC)
|
||||
{
|
||||
/* ========================================================================
|
||||
* Table of CRC-32's of all single-byte values (made by makecrc.c)
|
||||
*/
|
||||
unsigned long crc_32_tab[] = {
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
|
||||
0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
|
||||
0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
|
||||
0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
|
||||
0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
|
||||
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
|
||||
0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
|
||||
0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
|
||||
0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
|
||||
0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
|
||||
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
|
||||
0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
|
||||
0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
|
||||
0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
|
||||
0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
|
||||
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
|
||||
0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
|
||||
0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
|
||||
0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
|
||||
0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
|
||||
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
|
||||
0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
|
||||
0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
|
||||
0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
|
||||
0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
|
||||
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
|
||||
0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
|
||||
0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
|
||||
0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
|
||||
0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
|
||||
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
|
||||
0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
|
||||
};
|
||||
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
|
||||
CRC = ~CRC;
|
||||
while (len --)
|
||||
{
|
||||
CRC = crc_32_tab[((unsigned char) CRC ^ *data) & 0xFF] ^ (CRC >> 8);
|
||||
data ++;
|
||||
}
|
||||
|
||||
return ~CRC;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// CRC32 function
|
||||
// To create a CRC from a new buffer, use this:
|
||||
// crc = MakeCRC32(mydata, data_len, 0);
|
||||
// If you need to continue the CRC (e.g. your data is in multiple buffers),
|
||||
// continue like this:
|
||||
// crc = MakeCRC32(moredata, more_len, crc);
|
||||
//
|
||||
// Your desired CRC should be the complement of the CRC generated by
|
||||
// MakeCRC32:
|
||||
// desired = crc
|
||||
// desired - crc = 0
|
||||
|
||||
unsigned long MakeCRC32(char *data, unsigned int len, unsigned long CRC);
|
||||
@@ -1,430 +0,0 @@
|
||||
/*
|
||||
****************************************************************************
|
||||
*
|
||||
* "DHRYSTONE" Benchmark Program
|
||||
* -----------------------------
|
||||
*
|
||||
* Version: C, Version 2.1
|
||||
*
|
||||
* File: dhry.h (part 1 of 3)
|
||||
*
|
||||
* Date: May 25, 1988
|
||||
*
|
||||
* Author: Reinhold P. Weicker
|
||||
* Siemens AG, E STE 35
|
||||
* Postfach 3240
|
||||
* 8520 Erlangen
|
||||
* Germany (West)
|
||||
* Phone: [xxx-49]-9131-7-20330
|
||||
* (8-17 Central European Time)
|
||||
* Usenet: ..!mcvax!unido!estevax!weicker
|
||||
*
|
||||
* Original Version (in Ada) published in
|
||||
* "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
|
||||
* pp. 1013 - 1030, together with the statistics
|
||||
* on which the distribution of statements etc. is based.
|
||||
*
|
||||
* In this C version, the following C library functions are used:
|
||||
* - strcpy, strcmp (inside the measurement loop)
|
||||
* - printf, scanf (outside the measurement loop)
|
||||
* In addition, Berkeley UNIX system calls "times ()" or "time ()"
|
||||
* are used for execution time measurement. For measurements
|
||||
* on other systems, these calls have to be changed.
|
||||
*
|
||||
* Collection of Results:
|
||||
* Reinhold Weicker (address see above) and
|
||||
*
|
||||
* Rick Richardson
|
||||
* PC Research. Inc.
|
||||
* 94 Apple Orchard Drive
|
||||
* Tinton Falls, NJ 07724
|
||||
* Phone: (201) 389-8963 (9-17 EST)
|
||||
* Usenet: ...!uunet!pcrat!rick
|
||||
*
|
||||
* Please send results to Rick Richardson and/or Reinhold Weicker.
|
||||
* Complete information should be given on hardware and software used.
|
||||
* Hardware information includes: Machine type, CPU, type and size
|
||||
* of caches; for microprocessors: clock frequency, memory speed
|
||||
* (number of wait states).
|
||||
* Software information includes: Compiler (and runtime library)
|
||||
* manufacturer and version, compilation switches, OS version.
|
||||
* The Operating System version may give an indication about the
|
||||
* compiler; Dhrystone itself performs no OS calls in the measurement loop.
|
||||
*
|
||||
* The complete output generated by the program should be mailed
|
||||
* such that at least some checks for correctness can be made.
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* History: This version C/2.1 has been made for two reasons:
|
||||
*
|
||||
* 1) There is an obvious need for a common C version of
|
||||
* Dhrystone, since C is at present the most popular system
|
||||
* programming language for the class of processors
|
||||
* (microcomputers, minicomputers) where Dhrystone is used most.
|
||||
* There should be, as far as possible, only one C version of
|
||||
* Dhrystone such that results can be compared without
|
||||
* restrictions. In the past, the C versions distributed
|
||||
* by Rick Richardson (Version 1.1) and by Reinhold Weicker
|
||||
* had small (though not significant) differences.
|
||||
*
|
||||
* 2) As far as it is possible without changes to the Dhrystone
|
||||
* statistics, optimizing compilers should be prevented from
|
||||
* removing significant statements.
|
||||
*
|
||||
* This C version has been developed in cooperation with
|
||||
* Rick Richardson (Tinton Falls, NJ), it incorporates many
|
||||
* ideas from the "Version 1.1" distributed previously by
|
||||
* him over the UNIX network Usenet.
|
||||
* I also thank Chaim Benedelac (National Semiconductor),
|
||||
* David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
|
||||
* Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
|
||||
* for their help with comments on earlier versions of the
|
||||
* benchmark.
|
||||
*
|
||||
* Changes: In the initialization part, this version follows mostly
|
||||
* Rick Richardson's version distributed via Usenet, not the
|
||||
* version distributed earlier via floppy disk by Reinhold Weicker.
|
||||
* As a concession to older compilers, names have been made
|
||||
* unique within the first 8 characters.
|
||||
* Inside the measurement loop, this version follows the
|
||||
* version previously distributed by Reinhold Weicker.
|
||||
*
|
||||
* At several places in the benchmark, code has been added,
|
||||
* but within the measurement loop only in branches that
|
||||
* are not executed. The intention is that optimizing compilers
|
||||
* should be prevented from moving code out of the measurement
|
||||
* loop, or from removing code altogether. Since the statements
|
||||
* that are executed within the measurement loop have NOT been
|
||||
* changed, the numbers defining the "Dhrystone distribution"
|
||||
* (distribution of statements, operand types and locality)
|
||||
* still hold. Except for sophisticated optimizing compilers,
|
||||
* execution times for this version should be the same as
|
||||
* for previous versions.
|
||||
*
|
||||
* Since it has proven difficult to subtract the time for the
|
||||
* measurement loop overhead in a correct way, the loop check
|
||||
* has been made a part of the benchmark. This does have
|
||||
* an impact - though a very minor one - on the distribution
|
||||
* statistics which have been updated for this version.
|
||||
*
|
||||
* All changes within the measurement loop are described
|
||||
* and discussed in the companion paper "Rationale for
|
||||
* Dhrystone version 2".
|
||||
*
|
||||
* Because of the self-imposed limitation that the order and
|
||||
* distribution of the executed statements should not be
|
||||
* changed, there are still cases where optimizing compilers
|
||||
* may not generate code for some statements. To a certain
|
||||
* degree, this is unavoidable for small synthetic benchmarks.
|
||||
* Users of the benchmark are advised to check code listings
|
||||
* whether code is generated for all statements of Dhrystone.
|
||||
*
|
||||
* Version 2.1 is identical to version 2.0 distributed via
|
||||
* the UNIX network Usenet in March 1988 except that it corrects
|
||||
* some minor deficiencies that were found by users of version 2.0.
|
||||
* The only change within the measurement loop is that a
|
||||
* non-executed "else" part was added to the "if" statement in
|
||||
* Func_3, and a non-executed "else" part removed from Proc_3.
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Defines: The following "Defines" are possible:
|
||||
* -DREG=register (default: Not defined)
|
||||
* As an approximation to what an average C programmer
|
||||
* might do, the "register" storage class is applied
|
||||
* (if enabled by -DREG=register)
|
||||
* - for local variables, if they are used (dynamically)
|
||||
* five or more times
|
||||
* - for parameters if they are used (dynamically)
|
||||
* six or more times
|
||||
* Note that an optimal "register" strategy is
|
||||
* compiler-dependent, and that "register" declarations
|
||||
* do not necessarily lead to faster execution.
|
||||
* -DNOSTRUCTASSIGN (default: Not defined)
|
||||
* Define if the C compiler does not support
|
||||
* assignment of structures.
|
||||
* -DNOENUMS (default: Not defined)
|
||||
* Define if the C compiler does not support
|
||||
* enumeration types.
|
||||
* -DTIMES (default)
|
||||
* -DTIME
|
||||
* The "times" function of UNIX (returning process times)
|
||||
* or the "time" function (returning wallclock time)
|
||||
* is used for measurement.
|
||||
* For single user machines, "time ()" is adequate. For
|
||||
* multi-user machines where you cannot get single-user
|
||||
* access, use the "times ()" function. If you have
|
||||
* neither, use a stopwatch in the dead of night.
|
||||
* "printf"s are provided marking the points "Start Timer"
|
||||
* and "Stop Timer". DO NOT use the UNIX "time(1)"
|
||||
* command, as this will measure the total time to
|
||||
* run this program, which will (erroneously) include
|
||||
* the time to allocate storage (malloc) and to perform
|
||||
* the initialization.
|
||||
* -DHZ=nnn
|
||||
* In Berkeley UNIX, the function "times" returns process
|
||||
* time in 1/HZ seconds, with HZ = 60 for most systems.
|
||||
* CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
|
||||
* A VALUE.
|
||||
*
|
||||
***************************************************************************
|
||||
*
|
||||
* Compilation model and measurement (IMPORTANT):
|
||||
*
|
||||
* This C version of Dhrystone consists of three files:
|
||||
* - dhry.h (this file, containing global definitions and comments)
|
||||
* - dhry_1.c (containing the code corresponding to Ada package Pack_1)
|
||||
* - dhry_2.c (containing the code corresponding to Ada package Pack_2)
|
||||
*
|
||||
* The following "ground rules" apply for measurements:
|
||||
* - Separate compilation
|
||||
* - No procedure merging
|
||||
* - Otherwise, compiler optimizations are allowed but should be indicated
|
||||
* - Default results are those without register declarations
|
||||
* See the companion paper "Rationale for Dhrystone Version 2" for a more
|
||||
* detailed discussion of these ground rules.
|
||||
*
|
||||
* For 16-Bit processors (e.g. 80186, 80286), times for all compilation
|
||||
* models ("small", "medium", "large" etc.) should be given if possible,
|
||||
* together with a definition of these models for the compiler system used.
|
||||
*
|
||||
**************************************************************************
|
||||
*
|
||||
* Dhrystone (C version) statistics:
|
||||
*
|
||||
* [Comment from the first distribution, updated for version 2.
|
||||
* Note that because of language differences, the numbers are slightly
|
||||
* different from the Ada version.]
|
||||
*
|
||||
* The following program contains statements of a high level programming
|
||||
* language (here: C) in a distribution considered representative:
|
||||
*
|
||||
* assignments 52 (51.0 %)
|
||||
* control statements 33 (32.4 %)
|
||||
* procedure, function calls 17 (16.7 %)
|
||||
*
|
||||
* 103 statements are dynamically executed. The program is balanced with
|
||||
* respect to the three aspects:
|
||||
*
|
||||
* - statement type
|
||||
* - operand type
|
||||
* - operand locality
|
||||
* operand global, local, parameter, or constant.
|
||||
*
|
||||
* The combination of these three aspects is balanced only approximately.
|
||||
*
|
||||
* 1. Statement Type:
|
||||
* ----------------- number
|
||||
*
|
||||
* V1 = V2 9
|
||||
* (incl. V1 = F(..)
|
||||
* V = Constant 12
|
||||
* Assignment, 7
|
||||
* with array element
|
||||
* Assignment, 6
|
||||
* with record component
|
||||
* --
|
||||
* 34 34
|
||||
*
|
||||
* X = Y +|-|"&&"|"|" Z 5
|
||||
* X = Y +|-|"==" Constant 6
|
||||
* X = X +|- 1 3
|
||||
* X = Y *|/ Z 2
|
||||
* X = Expression, 1
|
||||
* two operators
|
||||
* X = Expression, 1
|
||||
* three operators
|
||||
* --
|
||||
* 18 18
|
||||
*
|
||||
* if .... 14
|
||||
* with "else" 7
|
||||
* without "else" 7
|
||||
* executed 3
|
||||
* not executed 4
|
||||
* for ... 7 | counted every time
|
||||
* while ... 4 | the loop condition
|
||||
* do ... while 1 | is evaluated
|
||||
* switch ... 1
|
||||
* break 1
|
||||
* declaration with 1
|
||||
* initialization
|
||||
* --
|
||||
* 34 34
|
||||
*
|
||||
* P (...) procedure call 11
|
||||
* user procedure 10
|
||||
* library procedure 1
|
||||
* X = F (...)
|
||||
* function call 6
|
||||
* user function 5
|
||||
* library function 1
|
||||
* --
|
||||
* 17 17
|
||||
* ---
|
||||
* 103
|
||||
*
|
||||
* The average number of parameters in procedure or function calls
|
||||
* is 1.82 (not counting the function values aX *
|
||||
*
|
||||
* 2. Operators
|
||||
* ------------
|
||||
* number approximate
|
||||
* percentage
|
||||
*
|
||||
* Arithmetic 32 50.8
|
||||
*
|
||||
* + 21 33.3
|
||||
* - 7 11.1
|
||||
* * 3 4.8
|
||||
* / (int div) 1 1.6
|
||||
*
|
||||
* Comparison 27 42.8
|
||||
*
|
||||
* == 9 14.3
|
||||
* /= 4 6.3
|
||||
* > 1 1.6
|
||||
* < 3 4.8
|
||||
* >= 1 1.6
|
||||
* <= 9 14.3
|
||||
*
|
||||
* Logic 4 6.3
|
||||
*
|
||||
* && (AND-THEN) 1 1.6
|
||||
* | (OR) 1 1.6
|
||||
* ! (NOT) 2 3.2
|
||||
*
|
||||
* -- -----
|
||||
* 63 100.1
|
||||
*
|
||||
*
|
||||
* 3. Operand Type (counted once per operand reference):
|
||||
* ---------------
|
||||
* number approximate
|
||||
* percentage
|
||||
*
|
||||
* Integer 175 72.3 %
|
||||
* Character 45 18.6 %
|
||||
* Pointer 12 5.0 %
|
||||
* String30 6 2.5 %
|
||||
* Array 2 0.8 %
|
||||
* Record 2 0.8 %
|
||||
* --- -------
|
||||
* 242 100.0 %
|
||||
*
|
||||
* When there is an access path leading to the final operand (e.g. a record
|
||||
* component), only the final data type on the access path is counted.
|
||||
*
|
||||
*
|
||||
* 4. Operand Locality:
|
||||
* -------------------
|
||||
* number approximate
|
||||
* percentage
|
||||
*
|
||||
* local variable 114 47.1 %
|
||||
* global variable 22 9.1 %
|
||||
* parameter 45 18.6 %
|
||||
* value 23 9.5 %
|
||||
* reference 22 9.1 %
|
||||
* function result 6 2.5 %
|
||||
* constant 55 22.7 %
|
||||
* --- -------
|
||||
* 242 100.0 %
|
||||
*
|
||||
*
|
||||
* The program does not compute anything meaningful, but it is syntactically
|
||||
* and semantically correct. All variables have a value assigned to them
|
||||
* before they are used as a source operand.
|
||||
*
|
||||
* There has been no explicit effort to account for the effects of a
|
||||
* cache, or to balance the use of long or short displacements for code or
|
||||
* data.
|
||||
*
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
/* Compiler and system dependent definitions: */
|
||||
|
||||
#ifndef TIME
|
||||
#undef TIMES
|
||||
#define TIMES
|
||||
#endif
|
||||
/* Use times(2) time function unless */
|
||||
/* explicitly defined otherwise */
|
||||
#ifdef MSC_CLOCK
|
||||
#undef HZ
|
||||
#undef TIMES
|
||||
#include <time.h>
|
||||
#define HZ CLK_TCK
|
||||
#endif
|
||||
/* Use Microsoft C hi-res clock */
|
||||
|
||||
#ifdef TIMES
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
/* for "times" */
|
||||
#endif
|
||||
|
||||
#define Mic_secs_Per_Second 1000000.0
|
||||
/* Berkeley UNIX C returns process times in seconds/HZ */
|
||||
|
||||
#ifdef NOSTRUCTASSIGN
|
||||
#define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
|
||||
#else
|
||||
#define structassign(d, s) d = s
|
||||
#endif
|
||||
|
||||
#ifdef NOENUM
|
||||
#define Ident_1 0
|
||||
#define Ident_2 1
|
||||
#define Ident_3 2
|
||||
#define Ident_4 3
|
||||
#define Ident_5 4
|
||||
typedef int Enumeration;
|
||||
#else
|
||||
typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
|
||||
Enumeration;
|
||||
#endif
|
||||
/* for boolean and enumeration types in Ada, Pascal */
|
||||
|
||||
/* General definitions: */
|
||||
|
||||
#include <stdio.h>
|
||||
/* for strcpy, strcmp */
|
||||
|
||||
#define Null 0
|
||||
/* Value of a Null pointer */
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
typedef int One_Thirty;
|
||||
typedef int One_Fifty;
|
||||
typedef char Capital_Letter;
|
||||
typedef int Boolean;
|
||||
typedef char Str_30 [31];
|
||||
typedef int Arr_1_Dim [50];
|
||||
typedef int Arr_2_Dim [50] [50];
|
||||
|
||||
typedef struct record
|
||||
{
|
||||
struct record *Ptr_Comp;
|
||||
Enumeration Discr;
|
||||
union {
|
||||
struct {
|
||||
Enumeration Enum_Comp;
|
||||
int Int_Comp;
|
||||
char Str_Comp [31];
|
||||
} var_1;
|
||||
struct {
|
||||
Enumeration E_Comp_2;
|
||||
char Str_2_Comp [31];
|
||||
} var_2;
|
||||
struct {
|
||||
char Ch_1_Comp;
|
||||
char Ch_2_Comp;
|
||||
} var_3;
|
||||
} variant;
|
||||
} Rec_Type, *Rec_Pointer;
|
||||
|
||||
|
||||
@@ -1,402 +0,0 @@
|
||||
/*
|
||||
****************************************************************************
|
||||
*
|
||||
* "DHRYSTONE" Benchmark Program
|
||||
* -----------------------------
|
||||
*
|
||||
* Version: C, Version 2.1
|
||||
*
|
||||
* File: dhry_1.c (part 2 of 3)
|
||||
*
|
||||
* Date: May 25, 1988
|
||||
*
|
||||
* Author: Reinhold P. Weicker
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "dhry.h"
|
||||
|
||||
/* Global Variables: */
|
||||
|
||||
Rec_Pointer Ptr_Glob,
|
||||
Next_Ptr_Glob;
|
||||
int Int_Glob;
|
||||
Boolean Bool_Glob;
|
||||
char Ch_1_Glob,
|
||||
Ch_2_Glob;
|
||||
int Arr_1_Glob [50];
|
||||
int Arr_2_Glob [50] [50];
|
||||
|
||||
extern char *malloc ();
|
||||
Enumeration Func_1 ();
|
||||
/* forward declaration necessary since Enumeration may not simply be int */
|
||||
|
||||
#ifndef REG
|
||||
Boolean Reg = false;
|
||||
#define REG
|
||||
/* REG becomes defined as empty */
|
||||
/* i.e. no register variables */
|
||||
#else
|
||||
Boolean Reg = true;
|
||||
#endif
|
||||
|
||||
/* variables for time measurement: */
|
||||
|
||||
#ifdef TIMES
|
||||
struct tms time_info;
|
||||
/* see library function "times" */
|
||||
#define Too_Small_Time (2*HZ)
|
||||
/* Measurements should last at least about 2 seconds */
|
||||
#endif
|
||||
#ifdef TIME
|
||||
extern long time();
|
||||
/* see library function "time" */
|
||||
#define Too_Small_Time 2
|
||||
/* Measurements should last at least 2 seconds */
|
||||
#endif
|
||||
#ifdef MSC_CLOCK
|
||||
extern clock_t clock();
|
||||
#define Too_Small_Time (2*HZ)
|
||||
#endif
|
||||
|
||||
long Begin_Time,
|
||||
End_Time,
|
||||
User_Time;
|
||||
float Microseconds,
|
||||
Dhrystones_Per_Second;
|
||||
|
||||
/* end of variables for time measurement */
|
||||
|
||||
|
||||
main ()
|
||||
/*****/
|
||||
|
||||
/* main program, corresponds to procedures */
|
||||
/* Main and Proc_0 in the Ada version */
|
||||
{
|
||||
One_Fifty Int_1_Loc;
|
||||
REG One_Fifty Int_2_Loc;
|
||||
One_Fifty Int_3_Loc;
|
||||
REG char Ch_Index;
|
||||
Enumeration Enum_Loc;
|
||||
Str_30 Str_1_Loc;
|
||||
Str_30 Str_2_Loc;
|
||||
REG int Run_Index;
|
||||
REG int Number_Of_Runs;
|
||||
|
||||
/* Initializations */
|
||||
|
||||
Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
|
||||
Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
|
||||
|
||||
Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
|
||||
Ptr_Glob->Discr = Ident_1;
|
||||
Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
|
||||
Ptr_Glob->variant.var_1.Int_Comp = 40;
|
||||
strcpy (Ptr_Glob->variant.var_1.Str_Comp,
|
||||
"DHRYSTONE PROGRAM, SOME STRING");
|
||||
strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
|
||||
|
||||
Arr_2_Glob [8][7] = 10;
|
||||
/* Was missing in published program. Without this statement, */
|
||||
/* Arr_2_Glob [8][7] would have an undefined value. */
|
||||
/* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
|
||||
/* overflow may occur for this array element. */
|
||||
|
||||
/*
|
||||
printf ("\n");
|
||||
printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
|
||||
printf ("\n");
|
||||
if (Reg)
|
||||
{
|
||||
printf ("Program compiled with 'register' attribute\n");
|
||||
printf ("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("Program compiled without 'register' attribute\n");
|
||||
printf ("\n");
|
||||
}
|
||||
printf ("Please give the number of runs through the benchmark: ");
|
||||
{
|
||||
int n;
|
||||
scanf ("%d", &n);
|
||||
Number_Of_Runs = n;
|
||||
}
|
||||
printf ("\n");
|
||||
*/
|
||||
#ifdef NRUNS
|
||||
Number_Of_Runs = NRUNS;
|
||||
#else
|
||||
Number_Of_Runs = 2000000;
|
||||
#endif
|
||||
printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
|
||||
|
||||
/***************/
|
||||
/* Start timer */
|
||||
/***************/
|
||||
|
||||
#ifdef TIMES
|
||||
times (&time_info);
|
||||
Begin_Time = (long) time_info.tms_utime;
|
||||
#endif
|
||||
#ifdef TIME
|
||||
Begin_Time = time ( (long *) 0);
|
||||
#endif
|
||||
#ifdef MSC_CLOCK
|
||||
Begin_Time = clock();
|
||||
#endif
|
||||
|
||||
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
|
||||
{
|
||||
|
||||
Proc_5();
|
||||
Proc_4();
|
||||
/* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
|
||||
Int_1_Loc = 2;
|
||||
Int_2_Loc = 3;
|
||||
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
|
||||
Enum_Loc = Ident_2;
|
||||
Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
|
||||
/* Bool_Glob == 1 */
|
||||
while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
|
||||
{
|
||||
Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
|
||||
/* Int_3_Loc == 7 */
|
||||
Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
|
||||
/* Int_3_Loc == 7 */
|
||||
Int_1_Loc += 1;
|
||||
} /* while */
|
||||
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
|
||||
Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
|
||||
/* Int_Glob == 5 */
|
||||
Proc_1 (Ptr_Glob);
|
||||
for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
|
||||
/* loop body executed twice */
|
||||
{
|
||||
if (Enum_Loc == Func_1 (Ch_Index, 'C'))
|
||||
/* then, not executed */
|
||||
{
|
||||
Proc_6 (Ident_1, &Enum_Loc);
|
||||
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
|
||||
Int_2_Loc = Run_Index;
|
||||
Int_Glob = Run_Index;
|
||||
}
|
||||
}
|
||||
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
|
||||
Int_2_Loc = Int_2_Loc * Int_1_Loc;
|
||||
Int_1_Loc = Int_2_Loc / Int_3_Loc;
|
||||
Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
|
||||
/* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
|
||||
Proc_2 (&Int_1_Loc);
|
||||
/* Int_1_Loc == 5 */
|
||||
|
||||
} /* loop "for Run_Index" */
|
||||
|
||||
/**************/
|
||||
/* Stop timer */
|
||||
/**************/
|
||||
|
||||
#ifdef TIMES
|
||||
times (&time_info);
|
||||
End_Time = (long) time_info.tms_utime;
|
||||
#endif
|
||||
#ifdef TIME
|
||||
End_Time = time ( (long *) 0);
|
||||
#endif
|
||||
#ifdef MSC_CLOCK
|
||||
End_Time = clock();
|
||||
#endif
|
||||
/*
|
||||
printf ("Execution ends\n");
|
||||
printf ("\n");
|
||||
printf ("Final values of the variables used in the benchmark:\n");
|
||||
printf ("\n");
|
||||
printf ("Int_Glob: %d\n", Int_Glob);
|
||||
printf (" should be: %d\n", 5);
|
||||
printf ("Bool_Glob: %d\n", Bool_Glob);
|
||||
printf (" should be: %d\n", 1);
|
||||
printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
|
||||
printf (" should be: %c\n", 'A');
|
||||
printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
|
||||
printf (" should be: %c\n", 'B');
|
||||
printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
|
||||
printf (" should be: %d\n", 7);
|
||||
printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
|
||||
printf (" should be: Number_Of_Runs + 10\n");
|
||||
printf ("Ptr_Glob->\n");
|
||||
printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
|
||||
printf (" should be: (implementation-dependent)\n");
|
||||
printf (" Discr: %d\n", Ptr_Glob->Discr);
|
||||
printf (" should be: %d\n", 0);
|
||||
printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
|
||||
printf (" should be: %d\n", 2);
|
||||
printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
|
||||
printf (" should be: %d\n", 17);
|
||||
printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
|
||||
printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
|
||||
printf ("Next_Ptr_Glob->\n");
|
||||
printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
|
||||
printf (" should be: (implementation-dependent), same as above\n");
|
||||
printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
|
||||
printf (" should be: %d\n", 0);
|
||||
printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
|
||||
printf (" should be: %d\n", 1);
|
||||
printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
|
||||
printf (" should be: %d\n", 18);
|
||||
printf (" Str_Comp: %s\n",
|
||||
Next_Ptr_Glob->variant.var_1.Str_Comp);
|
||||
printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
|
||||
printf ("Int_1_Loc: %d\n", Int_1_Loc);
|
||||
printf (" should be: %d\n", 5);
|
||||
printf ("Int_2_Loc: %d\n", Int_2_Loc);
|
||||
printf (" should be: %d\n", 13);
|
||||
printf ("Int_3_Loc: %d\n", Int_3_Loc);
|
||||
printf (" should be: %d\n", 7);
|
||||
printf ("Enum_Loc: %d\n", Enum_Loc);
|
||||
printf (" should be: %d\n", 1);
|
||||
printf ("Str_1_Loc: %s\n", Str_1_Loc);
|
||||
printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
|
||||
printf ("Str_2_Loc: %s\n", Str_2_Loc);
|
||||
printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
|
||||
printf ("\n");
|
||||
|
||||
*/
|
||||
User_Time = End_Time - Begin_Time;
|
||||
|
||||
if (User_Time < Too_Small_Time)
|
||||
{
|
||||
printf ("Measured time too small to obtain meaningful results\n");
|
||||
printf ("Please increase number of runs\n");
|
||||
printf ("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef TIME
|
||||
Microseconds = (float) User_Time * Mic_secs_Per_Second
|
||||
/ (float) Number_Of_Runs;
|
||||
Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
|
||||
#else
|
||||
Microseconds = (float) User_Time * Mic_secs_Per_Second
|
||||
/ ((float) HZ * ((float) Number_Of_Runs));
|
||||
Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
|
||||
/ (float) User_Time;
|
||||
#endif
|
||||
printf ("Microseconds for one run through Dhrystone: ");
|
||||
printf ("%6.1f \n", Microseconds);
|
||||
printf ("Dhrystones per Second: ");
|
||||
printf ("%6.1f \n", Dhrystones_Per_Second);
|
||||
printf ("\n");
|
||||
printf ("This equals to %6.1f DMIPS\n", Dhrystones_Per_Second/1757);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Proc_1 (Ptr_Val_Par)
|
||||
/******************/
|
||||
|
||||
REG Rec_Pointer Ptr_Val_Par;
|
||||
/* executed once */
|
||||
{
|
||||
REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
|
||||
/* == Ptr_Glob_Next */
|
||||
/* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
|
||||
/* corresponds to "rename" in Ada, "with" in Pascal */
|
||||
|
||||
structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
|
||||
Ptr_Val_Par->variant.var_1.Int_Comp = 5;
|
||||
Next_Record->variant.var_1.Int_Comp
|
||||
= Ptr_Val_Par->variant.var_1.Int_Comp;
|
||||
Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
|
||||
Proc_3 (&Next_Record->Ptr_Comp);
|
||||
/* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
|
||||
== Ptr_Glob->Ptr_Comp */
|
||||
if (Next_Record->Discr == Ident_1)
|
||||
/* then, executed */
|
||||
{
|
||||
Next_Record->variant.var_1.Int_Comp = 6;
|
||||
Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
|
||||
&Next_Record->variant.var_1.Enum_Comp);
|
||||
Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
|
||||
Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
|
||||
&Next_Record->variant.var_1.Int_Comp);
|
||||
}
|
||||
else /* not executed */
|
||||
structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
|
||||
} /* Proc_1 */
|
||||
|
||||
|
||||
Proc_2 (Int_Par_Ref)
|
||||
/******************/
|
||||
/* executed once */
|
||||
/* *Int_Par_Ref == 1, becomes 4 */
|
||||
|
||||
One_Fifty *Int_Par_Ref;
|
||||
{
|
||||
One_Fifty Int_Loc;
|
||||
Enumeration Enum_Loc;
|
||||
|
||||
Int_Loc = *Int_Par_Ref + 10;
|
||||
do /* executed once */
|
||||
if (Ch_1_Glob == 'A')
|
||||
/* then, executed */
|
||||
{
|
||||
Int_Loc -= 1;
|
||||
*Int_Par_Ref = Int_Loc - Int_Glob;
|
||||
Enum_Loc = Ident_1;
|
||||
} /* if */
|
||||
while (Enum_Loc != Ident_1); /* true */
|
||||
} /* Proc_2 */
|
||||
|
||||
|
||||
Proc_3 (Ptr_Ref_Par)
|
||||
/******************/
|
||||
/* executed once */
|
||||
/* Ptr_Ref_Par becomes Ptr_Glob */
|
||||
|
||||
Rec_Pointer *Ptr_Ref_Par;
|
||||
|
||||
{
|
||||
if (Ptr_Glob != Null)
|
||||
/* then, executed */
|
||||
*Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
|
||||
Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
|
||||
} /* Proc_3 */
|
||||
|
||||
|
||||
Proc_4 () /* without parameters */
|
||||
/*******/
|
||||
/* executed once */
|
||||
{
|
||||
Boolean Bool_Loc;
|
||||
|
||||
Bool_Loc = Ch_1_Glob == 'A';
|
||||
Bool_Glob = Bool_Loc | Bool_Glob;
|
||||
Ch_2_Glob = 'B';
|
||||
} /* Proc_4 */
|
||||
|
||||
|
||||
Proc_5 () /* without parameters */
|
||||
/*******/
|
||||
/* executed once */
|
||||
{
|
||||
Ch_1_Glob = 'A';
|
||||
Bool_Glob = false;
|
||||
} /* Proc_5 */
|
||||
|
||||
|
||||
/* Procedure for the assignment of structures, */
|
||||
/* if the C compiler doesn't support this feature */
|
||||
#ifdef NOSTRUCTASSIGN
|
||||
memcpy (d, s, l)
|
||||
register char *d;
|
||||
register char *s;
|
||||
register int l;
|
||||
{
|
||||
while (l--) *d++ = *s++;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
****************************************************************************
|
||||
*
|
||||
* "DHRYSTONE" Benchmark Program
|
||||
* -----------------------------
|
||||
*
|
||||
* Version: C, Version 2.1
|
||||
*
|
||||
* File: dhry_2.c (part 3 of 3)
|
||||
*
|
||||
* Date: May 25, 1988
|
||||
*
|
||||
* Author: Reinhold P. Weicker
|
||||
*
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "dhry.h"
|
||||
|
||||
#ifndef REG
|
||||
#define REG
|
||||
/* REG becomes defined as empty */
|
||||
/* i.e. no register variables */
|
||||
#endif
|
||||
|
||||
extern int Int_Glob;
|
||||
extern char Ch_1_Glob;
|
||||
|
||||
|
||||
Proc_6 (Enum_Val_Par, Enum_Ref_Par)
|
||||
/*********************************/
|
||||
/* executed once */
|
||||
/* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
|
||||
|
||||
Enumeration Enum_Val_Par;
|
||||
Enumeration *Enum_Ref_Par;
|
||||
{
|
||||
*Enum_Ref_Par = Enum_Val_Par;
|
||||
if (! Func_3 (Enum_Val_Par))
|
||||
/* then, not executed */
|
||||
*Enum_Ref_Par = Ident_4;
|
||||
switch (Enum_Val_Par)
|
||||
{
|
||||
case Ident_1:
|
||||
*Enum_Ref_Par = Ident_1;
|
||||
break;
|
||||
case Ident_2:
|
||||
if (Int_Glob > 100)
|
||||
/* then */
|
||||
*Enum_Ref_Par = Ident_1;
|
||||
else *Enum_Ref_Par = Ident_4;
|
||||
break;
|
||||
case Ident_3: /* executed */
|
||||
*Enum_Ref_Par = Ident_2;
|
||||
break;
|
||||
case Ident_4: break;
|
||||
case Ident_5:
|
||||
*Enum_Ref_Par = Ident_3;
|
||||
break;
|
||||
} /* switch */
|
||||
} /* Proc_6 */
|
||||
|
||||
|
||||
Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
|
||||
/**********************************************/
|
||||
/* executed three times */
|
||||
/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
|
||||
/* Int_Par_Ref becomes 7 */
|
||||
/* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
|
||||
/* Int_Par_Ref becomes 17 */
|
||||
/* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
|
||||
/* Int_Par_Ref becomes 18 */
|
||||
One_Fifty Int_1_Par_Val;
|
||||
One_Fifty Int_2_Par_Val;
|
||||
One_Fifty *Int_Par_Ref;
|
||||
{
|
||||
One_Fifty Int_Loc;
|
||||
|
||||
Int_Loc = Int_1_Par_Val + 2;
|
||||
*Int_Par_Ref = Int_2_Par_Val + Int_Loc;
|
||||
} /* Proc_7 */
|
||||
|
||||
|
||||
Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
|
||||
/*********************************************************************/
|
||||
/* executed once */
|
||||
/* Int_Par_Val_1 == 3 */
|
||||
/* Int_Par_Val_2 == 7 */
|
||||
Arr_1_Dim Arr_1_Par_Ref;
|
||||
Arr_2_Dim Arr_2_Par_Ref;
|
||||
int Int_1_Par_Val;
|
||||
int Int_2_Par_Val;
|
||||
{
|
||||
REG One_Fifty Int_Index;
|
||||
REG One_Fifty Int_Loc;
|
||||
|
||||
Int_Loc = Int_1_Par_Val + 5;
|
||||
Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
|
||||
Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
|
||||
Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
|
||||
for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
|
||||
Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
|
||||
Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
|
||||
Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
|
||||
Int_Glob = 5;
|
||||
} /* Proc_8 */
|
||||
|
||||
|
||||
Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
|
||||
/*************************************************/
|
||||
/* executed three times */
|
||||
/* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
|
||||
/* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
|
||||
/* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
|
||||
|
||||
Capital_Letter Ch_1_Par_Val;
|
||||
Capital_Letter Ch_2_Par_Val;
|
||||
{
|
||||
Capital_Letter Ch_1_Loc;
|
||||
Capital_Letter Ch_2_Loc;
|
||||
|
||||
Ch_1_Loc = Ch_1_Par_Val;
|
||||
Ch_2_Loc = Ch_1_Loc;
|
||||
if (Ch_2_Loc != Ch_2_Par_Val)
|
||||
/* then, executed */
|
||||
return (Ident_1);
|
||||
else /* not executed */
|
||||
{
|
||||
Ch_1_Glob = Ch_1_Loc;
|
||||
return (Ident_2);
|
||||
}
|
||||
} /* Func_1 */
|
||||
|
||||
|
||||
Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
|
||||
/*************************************************/
|
||||
/* executed once */
|
||||
/* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
|
||||
/* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
|
||||
|
||||
Str_30 Str_1_Par_Ref;
|
||||
Str_30 Str_2_Par_Ref;
|
||||
{
|
||||
REG One_Thirty Int_Loc;
|
||||
Capital_Letter Ch_Loc;
|
||||
|
||||
Int_Loc = 2;
|
||||
while (Int_Loc <= 2) /* loop body executed once */
|
||||
if (Func_1 (Str_1_Par_Ref[Int_Loc],
|
||||
Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
|
||||
/* then, executed */
|
||||
{
|
||||
Ch_Loc = 'A';
|
||||
Int_Loc += 1;
|
||||
} /* if, while */
|
||||
if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
|
||||
/* then, not executed */
|
||||
Int_Loc = 7;
|
||||
if (Ch_Loc == 'R')
|
||||
/* then, not executed */
|
||||
return (true);
|
||||
else /* executed */
|
||||
{
|
||||
if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
|
||||
/* then, not executed */
|
||||
{
|
||||
Int_Loc += 7;
|
||||
Int_Glob = Int_Loc;
|
||||
return (true);
|
||||
}
|
||||
else /* executed */
|
||||
return (false);
|
||||
} /* if Ch_Loc */
|
||||
} /* Func_2 */
|
||||
|
||||
|
||||
Boolean Func_3 (Enum_Par_Val)
|
||||
/***************************/
|
||||
/* executed once */
|
||||
/* Enum_Par_Val == Ident_3 */
|
||||
Enumeration Enum_Par_Val;
|
||||
{
|
||||
Enumeration Enum_Loc;
|
||||
|
||||
Enum_Loc = Enum_Par_Val;
|
||||
if (Enum_Loc == Ident_3)
|
||||
/* then, executed */
|
||||
return (true);
|
||||
else /* not executed */
|
||||
return (false);
|
||||
} /* Func_3 */
|
||||
|
||||
@@ -1,261 +0,0 @@
|
||||
/* dttl.c -- simulation of Cassini/Huygens symbol synchronizer loop
|
||||
*
|
||||
* Author: Lorenzo Simone's (matlab script)
|
||||
* Modifications by: Jon Hamkins (conversion to C, support routines,
|
||||
* memory requirement reductions)
|
||||
* Last Revised: Wed Jan 31 10:47:52 PST 2001
|
||||
*/
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "random.h"
|
||||
|
||||
/* global variables */
|
||||
int delay,
|
||||
L; /* samples per symbol */
|
||||
double Pt, /* transition density */
|
||||
sigma; /* noise standard deviation */
|
||||
long seed=-123;
|
||||
|
||||
/* This function simulates a large 1-dimensional array without requiring
|
||||
* storage for the whole array. This is possible because the array is
|
||||
* accessed in roughly increasing indices. Thus, we only need to
|
||||
* store a few symbols worth of samples in the array, and we can reuse
|
||||
* the array indices as time goes on. */
|
||||
int drint(double v)
|
||||
{
|
||||
return (int)(v+0.5);
|
||||
}
|
||||
|
||||
double
|
||||
rec(int idx)
|
||||
{
|
||||
static int firsttime = 1,
|
||||
max, /* maximum index containing data */
|
||||
mod, /* length of ring buffer */
|
||||
b; /* value of last transmitted bit */
|
||||
static double r[2000]; /* need several symbols worth of samples */
|
||||
int i,j,k;
|
||||
|
||||
/* First time, store samples for random delay and first few symbols */
|
||||
if (firsttime==1) {
|
||||
firsttime=0;
|
||||
for (i=0; i<delay; i++) r[i] = 0; /* random delay */
|
||||
b = (ran1(&seed)>0.5) ? 1 : -1; /* first random symbol */
|
||||
for (j=0; j<3; j++) { /* 3 binary symbols with transition Pt */
|
||||
b = (ran1(&seed)>Pt) ? b : -b; /* next symbol value */
|
||||
for (k=0; k<L; k++) r[i++] = b + sigma*gaussian(&seed);
|
||||
}
|
||||
max = i-1;
|
||||
mod = i;
|
||||
}
|
||||
if (idx>max) /* check if we need to create another sample */
|
||||
{
|
||||
b = (ran1(&seed)>Pt) ? b : -b; /* next symbol value */
|
||||
/* generate samples for one symbol and store in ring buffer */
|
||||
for (i=1; i<=L; i++) r[(int)(fmod(max+i,mod))] = b+sigma*gaussian(&seed);
|
||||
max += L; /* maximum index for which samples exist */
|
||||
}
|
||||
/* return appropriate sample from ring buffer */
|
||||
return(r[(int)(fmod(idx,mod))]);
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
double
|
||||
detout, /* detector output */
|
||||
I, old_I, /* in-phase accumulations */
|
||||
Q, old_Q, /* quadrature accumulations */
|
||||
T, /* transition detection */
|
||||
theta, /* baseband NCO output (radians) */
|
||||
lambda, /* normalized timing error (symbols) */
|
||||
A, alfa, Ampl, Bl, Df,
|
||||
DR, Es_No, Es_No_lin, Fc1, Fc2, Fvco, Fs, Kd, Kv,
|
||||
lambda_ss_sim = 0., lambda_ss_th, No, P, P_No,
|
||||
sigma_lambda_sim = 0., sigma_lambda_th, SNR_sim, SNR_th, tau, Tc1, Tc2,
|
||||
time, Ts, x1, Y, bit_I, bit_Q, bit;
|
||||
int i, j, k, N, offset, k1, k2, EOB;
|
||||
FILE *p1, *p2, *p3, *p4, *p5;
|
||||
|
||||
/* Data settings */
|
||||
Fc1 = 48000; /* sample rate at DTTL input (F1/2 = 8.215MHz/2) */
|
||||
Tc1 = 1./Fc1;
|
||||
|
||||
DR = 4800; /* data rate (symb/sec) */
|
||||
|
||||
Fc2 = DR; /* sampling rate pre-detection */
|
||||
Tc2 = 1./Fc2;
|
||||
|
||||
L = drint(Tc2/Tc1); /* samples per symbol in the arm filters */
|
||||
offset = drint(L/2.);
|
||||
|
||||
Es_No = 600.; /* dB */
|
||||
P_No = Es_No+10.*log10(DR); /* data power-over-noise spectral density */
|
||||
/* ratio (dBHz) */
|
||||
|
||||
N = 2500; /* number of symbols to simulate */
|
||||
Pt=.5; /* Transition density */
|
||||
|
||||
Bl=0.01*DR; /* loop bandwidth (Hz) */
|
||||
Df=0.001*DR; /* frequency offset */
|
||||
Fvco=DR+Df;
|
||||
|
||||
tau=ran1(&seed)-.5; /* set symbol timing offset, -.5 to .5 */
|
||||
delay=drint(2.*L+tau*L+1); /* channel delay */
|
||||
|
||||
P=1.; /* data power */
|
||||
Ampl=sqrt(P);
|
||||
|
||||
No=10.*log10(P*Tc2)-Es_No; /* noise spectral density (dBW/Hz) */
|
||||
sigma=sqrt(pow(10.,0.1*No)/(2.*Tc1));
|
||||
printf("sigma=%f\n",sigma);
|
||||
|
||||
/* DPLL settings */
|
||||
Fs=DR; /* loop sampling frequency (Hz) */
|
||||
Ts=1./Fs; /* loop sampling time (s) */
|
||||
|
||||
/* Loop gain */
|
||||
Kd=2.*Ampl*Pt; /* phase detector gain (quants/rad) */
|
||||
/* @ high Es/No */
|
||||
Kv=1.; /* VCO gain (rad/quants) */
|
||||
|
||||
/* Analog loop filter components */
|
||||
alfa=4.*Bl/(Kd*Kv);
|
||||
|
||||
/* Digital loop filter components */
|
||||
A=alfa*Ts;
|
||||
|
||||
/* Initial condition */
|
||||
theta = 0;
|
||||
old_I=1;
|
||||
old_Q=1;
|
||||
x1=0;
|
||||
Y=0;
|
||||
|
||||
/* Plot data files */
|
||||
// p1 = fopen("plot1.dat","w"); /* theta */
|
||||
// p2 = fopen("plot2.dat","w"); /* lambda */
|
||||
// p3 = fopen("plot3.dat","w"); /* detout */
|
||||
// p4 = fopen("plot4.dat","w"); /* I-Data */
|
||||
// p5 = fopen("plot5.dat","w"); /* Q-Data */
|
||||
|
||||
k1 = drint(0.5*N);
|
||||
k2 = N;
|
||||
|
||||
printf("Data rate: %.0f symbols/sec\n",DR);
|
||||
printf("Sample rate at DTTL input: %.0f samples/sec\n",Fc1);
|
||||
printf("Samples per symbol: %d\n",L);
|
||||
printf("Random delay set to: %f symbols (%d samples)\n",tau,delay);
|
||||
printf("Transition density used in random bit generation: %f\n",Pt);
|
||||
printf("Es/No: %f dB\n",Es_No);
|
||||
printf("Loop bandwidth: %f Hz\n",Bl);
|
||||
printf("Doppler: %f Hz\n",Df);
|
||||
printf("Simulation length: %d symbols (%d samples)\n\n",N,N*L+delay);
|
||||
|
||||
/* Simulation Loop */
|
||||
for (i=2; i<=N; i++)
|
||||
{
|
||||
/* loop over symbols */
|
||||
/* find start of in-phase integration */
|
||||
for (j=1; j < L; j++)
|
||||
{
|
||||
if (fmod(theta + 2*M_PI * Fvco*(j+1+(i-1)*(Fc1/DR))/Fc1, 2*M_PI)
|
||||
< fmod(theta + 2*M_PI * Fvco*(j +(i-1)*(Fc1/DR))/Fc1, 2*M_PI))
|
||||
break;
|
||||
/* one could replace loop above with a direct calculation such as: */
|
||||
/* j=ceil((1.-modulo(theta/(2*M_PI),1.))/(Fvco*Tc1))-1.; */
|
||||
/* j+1 is the first index in the block */
|
||||
EOB=j+(i-1)*L; /* End of Block */
|
||||
}
|
||||
/* In-phase integrator */
|
||||
bit_I = 0.;
|
||||
printf("Symbol # %d\n", i);
|
||||
printf("I[%d:%d] :\n", EOB-L+1, EOB);
|
||||
for (j=EOB-L+1; j<=EOB; j++)
|
||||
{
|
||||
bit = rec(j);
|
||||
if (bit > 0)
|
||||
printf("-");
|
||||
else
|
||||
printf("_");
|
||||
|
||||
bit_I += bit;
|
||||
}
|
||||
printf("\n");
|
||||
I = bit_I;
|
||||
|
||||
/* Mid-Phase integrator */
|
||||
bit_Q = 0.;
|
||||
printf("Q[%d:%d] :\n", EOB-L+offset+1, EOB+offset);
|
||||
for (j=EOB-L+offset+1; j<=EOB+offset; j++)
|
||||
{
|
||||
bit = rec(j);
|
||||
if (bit > 0)
|
||||
printf("-");
|
||||
else
|
||||
printf("_");
|
||||
|
||||
bit_Q += bit;
|
||||
}
|
||||
printf("\n\n");
|
||||
Q = bit_Q;
|
||||
|
||||
Q *= 2.*M_PI/(Tc2/Tc1);
|
||||
|
||||
/* Transition Detector */
|
||||
I = (I > 0) ? 1. : -1.; /* hard limiter */
|
||||
T = 0.5*(I - old_I);
|
||||
|
||||
/* Detector Output */
|
||||
detout = fmod(old_Q*T,2*M_PI);
|
||||
|
||||
/* Save accumulations for next time through loop */
|
||||
old_I = I;
|
||||
old_Q = Q;
|
||||
if (fabs(detout)>M_PI)
|
||||
detout = -detout+2*M_PI*((detout>0) ? 1. : -1.);
|
||||
|
||||
/* NCO */
|
||||
Y += detout*A; /* Loop filter */
|
||||
theta=Kv*Y; /* phase */
|
||||
// lambda = theta/(2.*M_PI)+(i*Tc2*Df+tau); /* normalized error */
|
||||
lambda = theta/(2.*M_PI)+(i*(Fvco/DR -1) + tau); /* normalized error */
|
||||
|
||||
/* error mean and variance calculation */
|
||||
lambda_ss_sim += lambda; /* partial sum */
|
||||
sigma_lambda_sim += lambda*lambda; /* partial sum of squares */
|
||||
|
||||
/* store phase and normalized error to data files */
|
||||
// fprintf(p1,"%f %f\n",(double)i,theta);
|
||||
// fprintf(p2,"%f %f\n",(double)i,lambda);
|
||||
// fprintf(p3,"%f %f\n",(double)i,detout);
|
||||
// fprintf(p4,"%f %f\n",(double)i,I);
|
||||
// fprintf(p5,"%f %f\n",(double)i,Q);
|
||||
}
|
||||
// fclose(p1);
|
||||
// fclose(p2);
|
||||
// fclose(p3);
|
||||
// fclose(p4);
|
||||
// fclose(p5);
|
||||
|
||||
/* Statistics Analysis */
|
||||
/* ------------------- */
|
||||
/* complete the mean and variance calculation */
|
||||
lambda_ss_sim /= N;
|
||||
sigma_lambda_sim = sigma_lambda_sim/N - lambda_ss_sim*lambda_ss_sim;
|
||||
Es_No_lin = pow(10.,0.1*Es_No);
|
||||
// sigma_lambda_th = Bl*Tc2/(4.*Pt*Es_No_lin*pow(erf(sqrt(Es_No_lin)),2.));
|
||||
sigma_lambda_th = Bl*Tc2/(4.*Pt*Es_No_lin*Es_No_lin);
|
||||
SNR_sim = -10*log10(sigma_lambda_sim);
|
||||
SNR_th = -10*log10(sigma_lambda_th);
|
||||
/* Steady-State error */
|
||||
lambda_ss_th=Df/(4.*Bl);
|
||||
printf("Simulation: var: %f rad^2 loop SNR: %f dB ss error: %f%%\n",
|
||||
sigma_lambda_sim, SNR_sim, 100.*lambda_ss_sim);
|
||||
printf("Theory: var: %f rad^2 loop SNR: %f dB ss error: %f%%\n",
|
||||
sigma_lambda_th, SNR_th, 100.*lambda_ss_th);
|
||||
// system("gnuplot < plot1.gp");
|
||||
// system("gnuplot < plot2.gp");
|
||||
printf("Done.\n");
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#define CPU_FREQ_HZ 100000000
|
||||
#include "libsys.h"
|
||||
|
||||
#include "crc32.h"
|
||||
#include "inflate.h"
|
||||
|
||||
char buffer[1024*1024];
|
||||
char * volatile pPtr_r;
|
||||
char * volatile pPtr_w;
|
||||
volatile int timeout_cnt;
|
||||
volatile int file_len;
|
||||
|
||||
void handler3(void)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)SYS_UART0_STAT;
|
||||
volatile UINT32 *pUART_data = (UINT32*)SYS_UART0_DATA;
|
||||
|
||||
while(0x200 & *pUART_stat)
|
||||
{
|
||||
// sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
||||
if (pPtr_w == &buffer[sizeof(buffer)-1])
|
||||
pPtr_w = buffer;
|
||||
*(pPtr_w++) = *pUART_data;
|
||||
timeout_cnt = 100;
|
||||
file_len++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int READBYTE(z_stream *zs) {
|
||||
if (zs->avail_in <= 0)
|
||||
return -1;
|
||||
|
||||
zs->avail_in --;
|
||||
return *(zs->next_in ++);
|
||||
}
|
||||
|
||||
#define MAX_BUFOUT 16*1024*1024
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)SYS_UART0_STAT;
|
||||
unsigned char outData[MAX_BUFOUT];
|
||||
FILE *infp;
|
||||
int i, gpflags, tmp[4];
|
||||
unsigned long size, crc;
|
||||
unsigned char *fileData;
|
||||
unsigned long bytes, InflatedSize, InflatedCRC, speed_count;
|
||||
z_stream zs;
|
||||
time_t start_time, work_time;
|
||||
|
||||
UART0_setbaud(460800);
|
||||
|
||||
printf("Reading gzipped stream..\n");
|
||||
|
||||
pPtr_r = buffer;
|
||||
pPtr_w = buffer;
|
||||
*pUART_stat = (1 << 6);
|
||||
interrupt_register(3, handler3);
|
||||
interrupt_enable(3);
|
||||
|
||||
file_len = 0;
|
||||
timeout_cnt = 1000000;
|
||||
while(timeout_cnt--)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("file_len: %d\n", file_len);
|
||||
bytes = file_len;
|
||||
fileData = pPtr_r;
|
||||
|
||||
zs.next_in = fileData;
|
||||
zs.avail_in = (unsigned int) bytes;
|
||||
zs.next_out = outData;
|
||||
zs.avail_out = MAX_BUFOUT;
|
||||
|
||||
tmp[0] = READBYTE(&zs);
|
||||
if (tmp[0] == -1)
|
||||
{
|
||||
// error reading from file
|
||||
printf("error reading data from file\n");
|
||||
return 0;
|
||||
}
|
||||
tmp[1] = READBYTE(&zs);
|
||||
|
||||
if (tmp[0] != 0x1f || tmp[1] != 0x8b) {
|
||||
// fprintf(stderr, "Magic number mismatch 0x%02x%02x\n",
|
||||
// tmp[0], tmp[1]);
|
||||
return 20;
|
||||
}
|
||||
|
||||
tmp[0] = READBYTE(&zs);
|
||||
if(tmp[0] != 8) {
|
||||
// fprintf(stderr, "Unknown compression method: 0x%02x\n", tmp[0]);
|
||||
return 20;
|
||||
}
|
||||
|
||||
gpflags = READBYTE(&zs);
|
||||
if ((gpflags & ~0x1f)) {
|
||||
printf("Unknown flags set!\n");
|
||||
}
|
||||
|
||||
/* Skip file modification time (4 bytes) */
|
||||
READBYTE(&zs);
|
||||
READBYTE(&zs);
|
||||
READBYTE(&zs);
|
||||
READBYTE(&zs);
|
||||
/* Skip extra flags and operating system fields (2 bytes) */
|
||||
READBYTE(&zs);
|
||||
READBYTE(&zs);
|
||||
|
||||
if ((gpflags & 4)) {
|
||||
/* Skip extra field */
|
||||
tmp[0] = READBYTE(&zs);
|
||||
tmp[1] = READBYTE(&zs);
|
||||
i = tmp[0] + 256*tmp[1];
|
||||
while (i--)
|
||||
{
|
||||
READBYTE(&zs);
|
||||
}
|
||||
}
|
||||
if((gpflags & 8)) {
|
||||
while((READBYTE(&zs))) {
|
||||
}
|
||||
}
|
||||
if((gpflags & 16)) {
|
||||
while((READBYTE(&zs))) {
|
||||
}
|
||||
}
|
||||
if((gpflags & 2)) {
|
||||
/* Skip CRC16 */
|
||||
READBYTE(&zs);
|
||||
READBYTE(&zs);
|
||||
}
|
||||
|
||||
printf("Go\n");
|
||||
// normal test
|
||||
start_time = clock();
|
||||
if (InflateData(&zs))
|
||||
{
|
||||
printf("Problem during decompression!\n");
|
||||
return 0;
|
||||
}
|
||||
work_time = clock() - start_time;
|
||||
|
||||
|
||||
/*
|
||||
// speed test
|
||||
fprintf(stdout, "SPEED TEST!\n");
|
||||
speed_count = 0;
|
||||
while (time(NULL) - start_time < 20)
|
||||
{
|
||||
zs_speed.next_in = zs.next_in;
|
||||
zs_speed.next_out = zs.next_out;
|
||||
zs_speed.avail_in = zs.avail_in;
|
||||
zs_speed.avail_out = zs.avail_out;
|
||||
if (InflateData(&zs_speed))
|
||||
{
|
||||
fprintf(stdout, "Problem during decompression!\n");
|
||||
return 0;
|
||||
}
|
||||
speed_count ++;
|
||||
}
|
||||
fprintf(stdout, "speed count %ld\n", speed_count);
|
||||
zs.next_in = zs_speed.next_in;
|
||||
zs.next_out = zs_speed.next_out;
|
||||
zs.avail_in = zs_speed.avail_in;
|
||||
zs.avail_out = zs_speed.avail_out;
|
||||
*/
|
||||
|
||||
crc = READBYTE(&zs);
|
||||
crc |= (READBYTE(&zs)<<8);
|
||||
crc |= (READBYTE(&zs)<<16);
|
||||
crc |= (READBYTE(&zs)<<24);
|
||||
|
||||
size = READBYTE(&zs);
|
||||
size |= (READBYTE(&zs)<<8);
|
||||
size |= (READBYTE(&zs)<<16);
|
||||
size |= (READBYTE(&zs)<<24);
|
||||
|
||||
InflatedSize = MAX_BUFOUT - zs.avail_out;
|
||||
InflatedCRC = MakeCRC32(outData, InflatedSize, 0);
|
||||
|
||||
// write(1, outData, InflatedSize);
|
||||
fprintf(stdout, "CRC: %08lx %08lx %s\n", crc, InflatedCRC, (crc != InflatedCRC)?"**error**":"");
|
||||
fprintf(stdout, "Size: %08lx %08lx %s\n", size, InflatedSize, (size != InflatedSize)?"**error**":"");
|
||||
fprintf(stdout, "Time for decompression was %.2f seconds\n", (float)work_time/1000);
|
||||
fprintf(stdout, "Throughput is %d kByte/s\n", InflatedSize/work_time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#define A 0.5
|
||||
#define B 0.55
|
||||
|
||||
_Sat long _Fract sat_add3 (_Sat long _Fract a, _Sat long _Fract b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
long _Fract mul3 (long _Fract a, long _Fract b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("hello %X + %X = %X\n", (_Sat long _Fract)A, (_Sat long _Fract)B, sat_add3(A, B));
|
||||
printf("hello %X * %X = %X\n", (_Sat long _Fract)A, (_Sat long _Fract)B, mul3(A, B));
|
||||
}
|
||||
@@ -1,949 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "libsys.h"
|
||||
#include "hpi.h"
|
||||
|
||||
static volatile UINT32 _g_int_active;
|
||||
static volatile UINT32 _g_mbx_return;
|
||||
static volatile UINT32 _g_mbx_in_flag;
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Globals
|
||||
// ---------------------------------------------------------
|
||||
typedef struct _susb_t
|
||||
{
|
||||
fp_t fptr_ept[USB_MAX_NUM_EPT];
|
||||
void *aptr_ept[USB_MAX_NUM_EPT];
|
||||
|
||||
fp_t fptr_rst;
|
||||
void *aptr_rst;
|
||||
|
||||
fp_t fptr_sof;
|
||||
void *aptr_sof;
|
||||
|
||||
fp_t fptr_cfg;
|
||||
void *aptr_cfg;
|
||||
|
||||
fp_t fptr_sus;
|
||||
void *aptr_sus;
|
||||
|
||||
fp_t fptr_id;
|
||||
void *aptr_id;
|
||||
|
||||
fp_t fptr_vbus;
|
||||
void *aptr_vbus;
|
||||
|
||||
} usb_t;
|
||||
|
||||
static usb_t _g_usb[USB_MAX_NUM_PORTS];
|
||||
//static usb_irp_t *_g_usb_irp_ptr[USB_MAX_NUM_PORTS][USB_MAX_NUM_EPT];
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// HPI ISR
|
||||
// ---------------------------------------------------------
|
||||
void cy67k3_isr(void)
|
||||
{
|
||||
INT32 i;
|
||||
UINT16 sie_msg, hpi_status;
|
||||
UINT32 port, siemsg_handled, int_handled;
|
||||
_g_int_active = 1;
|
||||
// sputs("--------------------------------------------------------\n");
|
||||
// sputs("USB-Interrupt(4)\n");
|
||||
// sputs("HPI Status : ");
|
||||
hpi_status = cy67k3_read_HPI_STATUS();
|
||||
// print_word(hpi_status);
|
||||
// sputs("\n");
|
||||
|
||||
// sputs("MAILBOX (REG): ");
|
||||
|
||||
// cy67k3_write(HPI_ADDRESS, HPI_REG_MAILBOX);
|
||||
// print_word(cy67k3_read_HPI_DATA());
|
||||
// sputs("\n");
|
||||
|
||||
int_handled = 0;
|
||||
if (hpi_status & HPI_STATUS_MBX_IN)
|
||||
{
|
||||
int_handled = 1;
|
||||
// sputs("MAILBOX (HPI): ");
|
||||
_g_mbx_return = cy67k3_read_HPI_MAILBOX();
|
||||
_g_mbx_in_flag = 1;
|
||||
// print_word(_g_mbx_return);
|
||||
// sputs("\n");
|
||||
}
|
||||
|
||||
if (hpi_status & HPI_STATUS_RESET1)
|
||||
{
|
||||
int_handled = 1;
|
||||
hpi_read_reg(SUSB1_REG_STATUS);
|
||||
hpi_comm_exec_int(SUSB_INIT_INT, 2, R1, 0, R2, 1);
|
||||
// sputs("RESET 1\n");
|
||||
}
|
||||
|
||||
if (hpi_status & HPI_STATUS_RESET2)
|
||||
{
|
||||
int_handled = 1;
|
||||
hpi_read_reg(SUSB2_REG_STATUS);
|
||||
hpi_comm_exec_int(SUSB_INIT_INT, 2, R1, 0, R2, 2);
|
||||
// sputs("RESET 2\n");
|
||||
}
|
||||
|
||||
if (hpi_status & HPI_STATUS_DONE1)
|
||||
{
|
||||
int_handled = 1;
|
||||
// sputs("DONE 1\n");
|
||||
}
|
||||
|
||||
if (hpi_status & HPI_STATUS_DONE2)
|
||||
{
|
||||
int_handled = 1;
|
||||
// sputs("DONE 2\n");
|
||||
}
|
||||
|
||||
if (hpi_status & HPI_STATUS_SOFEOP1)
|
||||
{
|
||||
int_handled = 1;
|
||||
hpi_read_reg(SUSB1_REG_STATUS);
|
||||
// sputs("SOF/EOP 1\n");
|
||||
}
|
||||
|
||||
if (hpi_status & HPI_STATUS_SOFEOP2)
|
||||
{
|
||||
int_handled = 1;
|
||||
hpi_read_reg(SUSB2_REG_STATUS);
|
||||
// sputs("SOF/EOP 2\n");
|
||||
}
|
||||
|
||||
port = 0;
|
||||
siemsg_handled = 0;
|
||||
if (hpi_status & HPI_STATUS_SIEMSG1)
|
||||
{
|
||||
int_handled = 1;
|
||||
sie_msg = hpi_read_reg(HPI_REG_SIE1MSG);
|
||||
|
||||
// Reset message register
|
||||
hpi_write_reg(HPI_REG_SIE1MSG, 0x0000);
|
||||
|
||||
if (sie_msg & SUSB_RST_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_rst)
|
||||
(_g_usb[port].fptr_rst)(_g_usb[port].aptr_rst);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_SOF_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_sof)
|
||||
(_g_usb[port].fptr_sof)(_g_usb[port].aptr_sof);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_CFG_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_cfg)
|
||||
(_g_usb[port].fptr_cfg)(_g_usb[port].aptr_cfg);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_SUS_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_sus)
|
||||
(_g_usb[port].fptr_sus)(_g_usb[port].aptr_sus);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_ID_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_id)
|
||||
(_g_usb[port].fptr_id)(_g_usb[port].aptr_id);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_VBUS_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_vbus)
|
||||
(_g_usb[port].fptr_vbus)(_g_usb[port].aptr_vbus);
|
||||
}
|
||||
|
||||
for (i=0; i < 8; i++)
|
||||
{
|
||||
if (sie_msg & (SUSB_EP0_MSG << i))
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_ept[i])
|
||||
(_g_usb[port].fptr_ept[i])(_g_usb[port].aptr_ept[i]);
|
||||
}
|
||||
}
|
||||
if (!siemsg_handled)
|
||||
{
|
||||
sputs("Unhandled SIE1 message ");
|
||||
print_word(sie_msg);
|
||||
sputs("!\n");
|
||||
}
|
||||
|
||||
}
|
||||
port = 1;
|
||||
siemsg_handled = 0;
|
||||
if (hpi_status & HPI_STATUS_SIEMSG2)
|
||||
{
|
||||
int_handled = 1;
|
||||
sie_msg = hpi_read_reg(HPI_REG_SIE2MSG);
|
||||
|
||||
// Reset message register
|
||||
hpi_write_reg(HPI_REG_SIE2MSG, 0x0000);
|
||||
|
||||
if (sie_msg & SUSB_RST_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_rst)
|
||||
(_g_usb[port].fptr_rst)(_g_usb[port].aptr_rst);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_SOF_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_sof)
|
||||
(_g_usb[port].fptr_sof)(_g_usb[port].aptr_sof);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_CFG_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_cfg)
|
||||
(_g_usb[port].fptr_cfg)(_g_usb[port].aptr_cfg);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_SUS_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_sus)
|
||||
(_g_usb[port].fptr_sus)(_g_usb[port].aptr_sus);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_ID_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_id)
|
||||
(_g_usb[port].fptr_id)(_g_usb[port].aptr_id);
|
||||
}
|
||||
|
||||
if (sie_msg & SUSB_VBUS_MSG)
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_vbus)
|
||||
(_g_usb[port].fptr_vbus)(_g_usb[port].aptr_vbus);
|
||||
}
|
||||
|
||||
for (i=0; i < 8; i++)
|
||||
{
|
||||
if (sie_msg & (SUSB_EP0_MSG << i))
|
||||
{
|
||||
siemsg_handled = 1;
|
||||
if (_g_usb[port].fptr_ept[i])
|
||||
(_g_usb[port].fptr_ept[i])(_g_usb[port].aptr_ept[i]);
|
||||
}
|
||||
}
|
||||
if (!siemsg_handled)
|
||||
{
|
||||
sputs("Unhandled SIE2 message ");
|
||||
print_word(sie_msg);
|
||||
sputs("!\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (!int_handled)
|
||||
{
|
||||
sputs("Unhandled interrupt (status = ");
|
||||
print_word(hpi_status);
|
||||
sputs(")!\n");
|
||||
}
|
||||
|
||||
// sputs("--------------------------------------------------------\n");
|
||||
_g_int_active = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// CY7C67300 low-level routines
|
||||
// ---------------------------------------------------------
|
||||
void cy67k3_reset(void)
|
||||
{
|
||||
int i;
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_CTRL;
|
||||
|
||||
*pHpi = 3;
|
||||
for (i=0; i <160; i++)
|
||||
{
|
||||
__asm __volatile
|
||||
(
|
||||
".set noreorder\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
);
|
||||
}
|
||||
|
||||
*pHpi = 2;
|
||||
|
||||
}
|
||||
|
||||
UINT16 cy67k3_read_HPI_DATA(void)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_DATA;
|
||||
|
||||
return (UINT16)*pHpi;
|
||||
}
|
||||
|
||||
UINT16 cy67k3_read_HPI_MAILBOX(void)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_MBX;
|
||||
|
||||
return (UINT16)*pHpi;
|
||||
}
|
||||
|
||||
UINT16 cy67k3_read_HPI_ADDRESS(void)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_ADDR;
|
||||
|
||||
return (UINT16)*pHpi;
|
||||
}
|
||||
|
||||
UINT16 cy67k3_read_HPI_STATUS(void)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_STATUS;
|
||||
|
||||
return (UINT16)*pHpi;
|
||||
}
|
||||
|
||||
void cy67k3_write_HPI_DATA(UINT16 data)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_DATA;
|
||||
|
||||
*pHpi = (UINT32)data;
|
||||
}
|
||||
|
||||
void cy67k3_write_HPI_MAILBOX(UINT16 data)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_MBX;
|
||||
|
||||
*pHpi = (UINT32)data;
|
||||
}
|
||||
|
||||
void cy67k3_write_HPI_ADDRESS(UINT16 data)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_ADDR;
|
||||
|
||||
*pHpi = (UINT32)data;
|
||||
}
|
||||
|
||||
void cy67k3_write_HPI_STATUS(UINT16 data)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_STATUS;
|
||||
|
||||
*pHpi = (UINT32)data;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// HPI API
|
||||
// ---------------------------------------------------------
|
||||
UINT32 hpi_init(void)
|
||||
{
|
||||
volatile UINT32 *pHpi = (UINT32*)SYS_USB_CTRL;
|
||||
int i;
|
||||
UINT16 reg;
|
||||
|
||||
// ToDo: Enable HPI interrupt
|
||||
_g_int_active = 0;
|
||||
|
||||
hpi_write_reg(HPI_REG_SIE1MSG, 0x0000);
|
||||
hpi_write_reg(HPI_REG_SIE2MSG, 0x0000);
|
||||
hpi_write_reg(SUSB1_REG_STATUS, 0xFFFF);
|
||||
hpi_write_reg(SUSB2_REG_STATUS, 0xFFFF);
|
||||
|
||||
// Init 1
|
||||
for(i=0; i < USB_MAX_NUM_EPT; i++)
|
||||
{
|
||||
hpi_write_reg(SUSB1_REG_EP_ADDR0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB1_REG_EP_CNTRES0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB1_REG_EP_COUNT0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB1_REG_EP_CTRL0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB1_REG_EP_STATUS0 + 16*i, 0);
|
||||
}
|
||||
// Init 2
|
||||
for(i=0; i < USB_MAX_NUM_EPT; i++)
|
||||
{
|
||||
hpi_write_reg(SUSB2_REG_EP_ADDR0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB2_REG_EP_CNTRES0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB2_REG_EP_COUNT0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB2_REG_EP_CTRL0 + 16*i, 0);
|
||||
hpi_write_reg(SUSB2_REG_EP_STATUS0 + 16*i, 0);
|
||||
}
|
||||
|
||||
hpi_write_reg(HPI_REG_INTROUTE, 0x0000);
|
||||
reg = hpi_read_reg(HPI_REG_INTROUTE);
|
||||
// hpi_write_reg(HPI_REG_INTROUTE, reg | 0x0202); // Route reset {1,2} to HPI only
|
||||
// hpi_write_reg(HPI_REG_INTROUTE, reg | 0x2800); // Route SOF/EOP {1,2} to HPI only
|
||||
// hpi_write_reg(HPI_REG_INTROUTE, reg | 0x1400); // Route SOF/EOP {1,2} to CY16 only
|
||||
hpi_write_reg(HPI_REG_INTROUTE, reg | 0x3C00); // Route SOF/EOP {1,2} to HPI and CY16
|
||||
|
||||
|
||||
interrupt_register(4, cy67k3_isr);
|
||||
interrupt_enable(4);
|
||||
*pHpi = 0x02;
|
||||
|
||||
return HPI_NOERROR;
|
||||
}
|
||||
|
||||
void hpi_mbx_write(UINT16 msgcode)
|
||||
{
|
||||
_g_mbx_in_flag = 0;
|
||||
cy67k3_write_HPI_MAILBOX(msgcode);
|
||||
}
|
||||
|
||||
UINT32 hpi_mbx_read(void)
|
||||
{
|
||||
UINT32 err;
|
||||
UINT16 cy_return;
|
||||
|
||||
if (_g_int_active)
|
||||
{
|
||||
while (!(cy67k3_read_HPI_STATUS() & HPI_STATUS_MBX_IN));
|
||||
cy_return = cy67k3_read_HPI_MAILBOX();
|
||||
}
|
||||
else
|
||||
{
|
||||
while(!_g_mbx_in_flag);
|
||||
cy_return = _g_mbx_return;
|
||||
}
|
||||
|
||||
switch (cy_return)
|
||||
{
|
||||
case COMM_ACK:
|
||||
err = cy_return;
|
||||
break;
|
||||
|
||||
case COMM_NAK:
|
||||
case COMM_ASYNC:
|
||||
err = HPI_ERR_PREFIX_MBX | cy_return;
|
||||
break;
|
||||
|
||||
default:
|
||||
err = HPI_ERR_PREFIX_MBX | cy_return;
|
||||
break;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
UINT32 hpi_check_addr(UINT16 addr)
|
||||
{
|
||||
if ((addr >= 0x0000) && (addr < 0x4000))
|
||||
return 0;
|
||||
|
||||
if ((addr >= 0xC080) && (addr < 0xC0BC))
|
||||
return 0;
|
||||
|
||||
if (addr >= 0xE000)
|
||||
return 0;
|
||||
|
||||
sputs("Invalid address for HPI direct access! Use LCP-command instead!\n");
|
||||
return HPI_ERR_INVPARAM;
|
||||
}
|
||||
|
||||
UINT32 hpi_read_reg(UINT16 addr)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
result = hpi_check_addr(addr);
|
||||
if (IS_ERROR(result))
|
||||
return result;
|
||||
|
||||
cy67k3_write_HPI_ADDRESS(addr);
|
||||
return cy67k3_read_HPI_DATA();
|
||||
}
|
||||
|
||||
UINT32 hpi_write_reg(UINT16 addr, UINT16 data)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
result = hpi_check_addr(addr);
|
||||
if (IS_ERROR(result))
|
||||
return result;
|
||||
|
||||
cy67k3_write_HPI_ADDRESS(addr);
|
||||
cy67k3_write_HPI_DATA(data);
|
||||
}
|
||||
|
||||
UINT32 hpi_write_ram(UINT16 addr, UINT16 *pData, UINT32 len)
|
||||
{
|
||||
int i, num_words;
|
||||
|
||||
if (addr > 0x3FFE)
|
||||
return HPI_ERR_INVPARAM;
|
||||
|
||||
if (addr & 1) // Not 16bit aligned?
|
||||
return HPI_ERR_INVPARAM;
|
||||
|
||||
cy67k3_write_HPI_ADDRESS(addr);
|
||||
|
||||
num_words = len/2;
|
||||
if (len % 2)
|
||||
num_words++;
|
||||
|
||||
for (i=0; i < num_words; i++)
|
||||
cy67k3_write_HPI_DATA(pData[i]);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
UINT32 hpi_read_ram(UINT16 addr, UINT16 *pData, UINT32 len)
|
||||
{
|
||||
int i, num_words;
|
||||
|
||||
if (addr > 0x3FFE)
|
||||
return HPI_ERR_INVPARAM;
|
||||
|
||||
if (addr & 1) // Not 16bit aligned?
|
||||
return HPI_ERR_INVPARAM;
|
||||
|
||||
cy67k3_write_HPI_ADDRESS(addr);
|
||||
|
||||
num_words = len/2;
|
||||
if (len % 2)
|
||||
num_words++;
|
||||
|
||||
for (i=0; i < num_words; i++)
|
||||
pData[i] = cy67k3_read_HPI_DATA();
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
UINT32 hpi_comm_reset(void)
|
||||
{
|
||||
hpi_mbx_write(COMM_RESET);
|
||||
|
||||
return hpi_mbx_read();
|
||||
}
|
||||
|
||||
UINT32 hpi_comm_jump2code(UINT16 addr)
|
||||
{
|
||||
cy67k3_write_HPI_ADDRESS(addr);
|
||||
hpi_mbx_write(COMM_JUMP2CODE);
|
||||
|
||||
return hpi_mbx_read();
|
||||
}
|
||||
|
||||
UINT32 hpi_comm_callcode(UINT16 addr)
|
||||
{
|
||||
hpi_write_reg(COMM_CODE_ADDR, addr);
|
||||
|
||||
hpi_mbx_write(COMM_CALL_CODE);
|
||||
|
||||
return hpi_mbx_read();
|
||||
}
|
||||
|
||||
UINT32 hpi_comm_write_ctrl_reg(UINT16 addr, UINT16 data, UINT16 logic)
|
||||
{
|
||||
|
||||
hpi_write_reg(COMM_CTRL_REG_ADDR, addr);
|
||||
hpi_write_reg(COMM_CTRL_REG_DATA, data);
|
||||
hpi_write_reg(COMM_CTRL_REG_LOGIC, logic);
|
||||
|
||||
hpi_mbx_write(COMM_WRITE_CTRL_REG);
|
||||
|
||||
return hpi_mbx_read();
|
||||
}
|
||||
|
||||
UINT32 hpi_comm_read_ctrl_reg(UINT16 addr)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
hpi_write_reg(COMM_CTRL_REG_ADDR, addr);
|
||||
|
||||
hpi_mbx_write(COMM_READ_CTRL_REG);
|
||||
|
||||
result = hpi_mbx_read();
|
||||
if (IS_ERROR(result))
|
||||
return result;
|
||||
|
||||
cy67k3_write_HPI_ADDRESS(COMM_CTRL_REG_DATA);
|
||||
return (UINT32)cy67k3_read_HPI_DATA();
|
||||
|
||||
}
|
||||
|
||||
UINT32 hpi_comm_write_xmem(UINT16 addr, UINT8 *pData, UINT16 len)
|
||||
{
|
||||
return HPI_ERR_NOTIMPL;
|
||||
|
||||
}
|
||||
|
||||
UINT32 hpi_comm_read_xmem(UINT16 addr, UINT8 *pData, UINT16 len)
|
||||
{
|
||||
return HPI_ERR_NOTIMPL;
|
||||
|
||||
}
|
||||
|
||||
typedef struct _sreg_param_t
|
||||
{
|
||||
UINT32 id;
|
||||
UINT16 val;
|
||||
|
||||
} reg_param_t;
|
||||
|
||||
UINT32 hpi_comm_exec_int(UINT16 intnum, UINT32 nargs, ...)
|
||||
{
|
||||
int i;
|
||||
UINT32 result;
|
||||
va_list args;
|
||||
reg_param_t reg_param[MAX_NUM_REGS];
|
||||
|
||||
va_start(args, nargs);
|
||||
|
||||
if (nargs > MAX_NUM_REGS)
|
||||
{
|
||||
fprintf(stderr, "hpi_comm_exec_int(): Number (%d), of arguments exceeds %d!\n", nargs, MAX_NUM_REGS);
|
||||
return HPI_ERR_INVPARAM;
|
||||
}
|
||||
|
||||
for (i=0; i < nargs; i++)
|
||||
{
|
||||
reg_param[i].id = va_arg(args, UINT32);
|
||||
if (reg_param[i].id > MAX_NUM_REGS)
|
||||
{
|
||||
fprintf(stderr, "hpi_comm_exec_int(): Invalid register R%d!\n", reg_param[i].id);
|
||||
return HPI_ERR_INVPARAM;
|
||||
}
|
||||
|
||||
reg_param[i].val = (UINT16)va_arg(args, UINT32);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
hpi_write_reg(COMM_INT_NUM, intnum);
|
||||
|
||||
for (i=0; i < nargs; i++)
|
||||
{
|
||||
hpi_write_reg(COMM_R0 + 2*reg_param[i].id, reg_param[i].val);
|
||||
}
|
||||
|
||||
hpi_mbx_write(COMM_EXEC_INT);
|
||||
|
||||
result = hpi_mbx_read();
|
||||
if (IS_ERROR(result))
|
||||
return result;
|
||||
|
||||
return (UINT32)hpi_read_reg(COMM_R0);
|
||||
}
|
||||
|
||||
UINT32 usb_init(void)
|
||||
{
|
||||
INT32 i;
|
||||
|
||||
for (i=0; i < USB_MAX_NUM_PORTS; i++)
|
||||
{
|
||||
memset(&_g_usb[i], 0, sizeof(usb_t));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 usb_callback_register(UINT32 port, UINT32 type, fp_t pFunc, void *pArg)
|
||||
{
|
||||
UINT32 result;
|
||||
if (port >= USB_MAX_NUM_PORTS)
|
||||
return -1;
|
||||
|
||||
result = 0;
|
||||
switch (type)
|
||||
{
|
||||
case SUSB_EP0_MSG:
|
||||
_g_usb[port].fptr_ept[0] = pFunc;
|
||||
_g_usb[port].aptr_ept[0] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_EP1_MSG:
|
||||
_g_usb[port].fptr_ept[1] = pFunc;
|
||||
_g_usb[port].aptr_ept[1] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_EP2_MSG:
|
||||
_g_usb[port].fptr_ept[2] = pFunc;
|
||||
_g_usb[port].aptr_ept[2] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_EP3_MSG:
|
||||
_g_usb[port].fptr_ept[3] = pFunc;
|
||||
_g_usb[port].aptr_ept[3] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_EP4_MSG:
|
||||
_g_usb[port].fptr_ept[4] = pFunc;
|
||||
_g_usb[port].aptr_ept[4] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_EP5_MSG:
|
||||
_g_usb[port].fptr_ept[5] = pFunc;
|
||||
_g_usb[port].aptr_ept[5] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_EP6_MSG:
|
||||
_g_usb[port].fptr_ept[6] = pFunc;
|
||||
_g_usb[port].aptr_ept[6] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_EP7_MSG:
|
||||
_g_usb[port].fptr_ept[7] = pFunc;
|
||||
_g_usb[port].aptr_ept[7] = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_RST_MSG:
|
||||
_g_usb[port].fptr_rst = pFunc;
|
||||
_g_usb[port].aptr_rst = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_SOF_MSG:
|
||||
_g_usb[port].fptr_sof = pFunc;
|
||||
_g_usb[port].aptr_sof = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_CFG_MSG:
|
||||
_g_usb[port].fptr_cfg = pFunc;
|
||||
_g_usb[port].aptr_cfg = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_SUS_MSG:
|
||||
_g_usb[port].fptr_sus = pFunc;
|
||||
_g_usb[port].aptr_sus = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_ID_MSG:
|
||||
_g_usb[port].fptr_id = pFunc;
|
||||
_g_usb[port].aptr_id = pArg;
|
||||
break;
|
||||
|
||||
case SUSB_VBUS_MSG:
|
||||
_g_usb[port].fptr_vbus = pFunc;
|
||||
_g_usb[port].aptr_vbus = pArg;
|
||||
break;
|
||||
|
||||
default:
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UINT32 usb_irp_register(usb_irp_t *pIRP, UINT32 port, UINT32 ept, UINT32 size, UINT32 is_out)
|
||||
{
|
||||
|
||||
if (!pIRP)
|
||||
return -1;
|
||||
|
||||
if (port >= USB_MAX_NUM_PORTS)
|
||||
return -1;
|
||||
|
||||
if (ept >= USB_MAX_NUM_EPT)
|
||||
return -1;
|
||||
|
||||
if (size >= USB_MAX_IMG_SIZE)
|
||||
return -1;
|
||||
|
||||
memset(pIRP, 0, sizeof(usb_irp_t));
|
||||
pIRP->is_out = is_out;
|
||||
pIRP->is_in = !is_out;
|
||||
pIRP->tsize = size;
|
||||
pIRP->port = port;
|
||||
pIRP->ept = ept;
|
||||
pIRP->cy_irp_addr = USB_IRP_BASE + port*USB_MAX_NUM_EPT*sizeof(cy_req_t) + ept*sizeof(cy_req_t);
|
||||
pIRP->cy_req.next = 0;
|
||||
pIRP->cy_req.addr = USB_IMG_BASE + port*USB_MAX_NUM_EPT*USB_MAX_IMG_SIZE + ept*USB_MAX_IMG_SIZE;
|
||||
pIRP->cy_req.size = size;
|
||||
pIRP->cy_req.callback = 0;
|
||||
fifo_alloc(&pIRP->fifo, 8*USB_MAX_IMG_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 usb_irp_enqueue(usb_irp_t *pIRP)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
if (!pIRP)
|
||||
{
|
||||
// sputs ("usb_irp_enqueue(): Invalid IRP!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// printf("cy_addr: %4.4X, Next: %4.4X, Addr: %4.4X, Size: %4.4X, CB: %4.4X\n", pIRP->cy_irp_addr, pIRP->cy_req.next, pIRP->cy_req.addr, pIRP->cy_req.size, pIRP->cy_req.callback);
|
||||
|
||||
if (pIRP->is_out)
|
||||
{
|
||||
hpi_write_ram(pIRP->cy_irp_addr, (UINT16*)&pIRP->cy_req, sizeof(cy_req_t));
|
||||
if (pIRP->port == 0)
|
||||
result = hpi_comm_exec_int(SUSB1_RECEIVE_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
|
||||
|
||||
if (pIRP->port == 1)
|
||||
result = hpi_comm_exec_int(SUSB2_RECEIVE_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
|
||||
}
|
||||
if (pIRP->is_in)
|
||||
{
|
||||
pIRP->tx_in_progress = 1;
|
||||
hpi_write_ram(pIRP->cy_irp_addr, (UINT16*)&pIRP->cy_req, sizeof(cy_req_t));
|
||||
if (pIRP->port == 0)
|
||||
result = hpi_comm_exec_int(SUSB1_SEND_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
|
||||
|
||||
if (pIRP->port == 1)
|
||||
result = hpi_comm_exec_int(SUSB2_SEND_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
|
||||
}
|
||||
|
||||
// if (result)
|
||||
// printf ("usb_irp_enqueue(): Result = %8.8X\n", result);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
UINT32 fifo_alloc(fifo_t *pObj, UINT32 size)
|
||||
{
|
||||
pObj->pBuf = (UINT8*)malloc(size);
|
||||
if (!pObj->pBuf)
|
||||
{
|
||||
// printf ("fifo_alloc(): Error allocating memory!\n");
|
||||
return -1;
|
||||
}
|
||||
// printf ("fifo_alloc(): pBuf at %8.8X\n", (UINT32)pObj->pBuf);
|
||||
pObj->size = size;
|
||||
pObj->pPtr_wr = pObj->pBuf;
|
||||
pObj->pPtr_rd = pObj->pBuf;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 fifo_free(fifo_t *pObj)
|
||||
{
|
||||
if (pObj->pBuf)
|
||||
free(pObj->pBuf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 fifo_flush(fifo_t *pObj)
|
||||
{
|
||||
pObj->pPtr_wr = pObj->pBuf;
|
||||
pObj->pPtr_rd = pObj->pBuf;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 fifo_is_empty(fifo_t *pObj)
|
||||
{
|
||||
return (pObj->pPtr_wr == pObj->pPtr_rd);
|
||||
}
|
||||
|
||||
UINT32 fifo_is_full(fifo_t *pObj)
|
||||
{
|
||||
UINT8 *pNext, *pEnd;
|
||||
|
||||
pEnd = pObj->pBuf + pObj->size;
|
||||
pNext = pObj->pPtr_wr + 1;
|
||||
if (pNext == pEnd)
|
||||
pNext = pObj->pBuf;
|
||||
|
||||
return (pNext == pObj->pPtr_rd);
|
||||
}
|
||||
|
||||
UINT32 fifo_read(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block)
|
||||
{
|
||||
UINT32 i;
|
||||
UINT32 wait_4ever, timeout_cnt, cnt;
|
||||
UINT8 *pEnd;
|
||||
|
||||
pEnd = pObj->pBuf + pObj->size;
|
||||
wait_4ever = (timeout == 0);
|
||||
|
||||
cnt = 0;
|
||||
while(size)
|
||||
{
|
||||
timeout_cnt = timeout;
|
||||
|
||||
while(fifo_is_empty(pObj))
|
||||
{
|
||||
if (!do_block)
|
||||
return cnt;
|
||||
|
||||
if (!wait_4ever)
|
||||
{
|
||||
if (timeout_cnt)
|
||||
{
|
||||
timeout_cnt--;
|
||||
sleep(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pData)
|
||||
pData[cnt] = *(pObj->pPtr_rd);
|
||||
|
||||
cnt++;
|
||||
pObj->pPtr_rd++;
|
||||
if (pObj->pPtr_rd == pEnd)
|
||||
pObj->pPtr_rd = pObj->pBuf;
|
||||
|
||||
size--;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
UINT32 fifo_write(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block)
|
||||
{
|
||||
UINT32 wait_4ever, timeout_cnt, cnt;
|
||||
UINT8 *pEnd;
|
||||
|
||||
pEnd = pObj->pBuf + pObj->size;
|
||||
wait_4ever = (timeout == 0);
|
||||
|
||||
cnt = 0;
|
||||
while(size)
|
||||
{
|
||||
timeout_cnt = timeout;
|
||||
|
||||
while(fifo_is_full(pObj))
|
||||
{
|
||||
if (!do_block)
|
||||
return cnt;
|
||||
|
||||
if (!wait_4ever)
|
||||
{
|
||||
if (timeout_cnt)
|
||||
{
|
||||
timeout_cnt--;
|
||||
sleep(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pData)
|
||||
*(pObj->pPtr_wr) = pData[cnt];
|
||||
|
||||
cnt++;
|
||||
pObj->pPtr_wr++;
|
||||
if (pObj->pPtr_wr == pEnd)
|
||||
pObj->pPtr_wr = pObj->pBuf;
|
||||
|
||||
size--;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
@@ -1,384 +0,0 @@
|
||||
#ifndef HPI_H
|
||||
#define HPI_H
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// API related
|
||||
// ---------------------------------------------------------
|
||||
//#define IS_ERROR(e) (0 != (e & HPI_ERROR))
|
||||
#define HPI_NOERROR 0
|
||||
#define HPI_ERROR 0x80000000
|
||||
#define HPI_ERR_NOTIMPL (HPI_ERROR + 1)
|
||||
#define HPI_ERR_INVPARAM (HPI_ERROR + 2)
|
||||
#define HPI_ERR_TIMEOUT (HPI_ERROR + 3)
|
||||
#define HPI_ERR_PREFIX_MBX (HPI_ERROR + 0x00010000)
|
||||
|
||||
#define MAX_NUM_REGS 14
|
||||
#define R0 0
|
||||
#define R1 1
|
||||
#define R2 2
|
||||
#define R3 3
|
||||
#define R4 4
|
||||
#define R5 5
|
||||
#define R6 6
|
||||
#define R7 7
|
||||
#define R8 8
|
||||
#define R9 9
|
||||
#define R10 10
|
||||
#define R11 11
|
||||
#define R12 12
|
||||
#define R13 13
|
||||
|
||||
#define USB_MAX_NUM_PORTS 2
|
||||
#define USB_MAX_NUM_EPT 8
|
||||
#define USB_MAX_IMG_SIZE 512
|
||||
#define USB_IRP_BASE 0x0F80
|
||||
#define USB_IMG_BASE 0x1000
|
||||
|
||||
typedef void (*fp_t)(void*);
|
||||
|
||||
// Receive buffer on EP
|
||||
typedef struct _scy_req_t
|
||||
{
|
||||
UINT16 next;
|
||||
UINT16 addr;
|
||||
UINT16 size;
|
||||
UINT16 callback;
|
||||
} cy_req_t;
|
||||
|
||||
typedef struct _sfifo_t
|
||||
{
|
||||
UINT32 size;
|
||||
UINT8 *pBuf;
|
||||
UINT8 * volatile pPtr_wr, * volatile pPtr_rd;
|
||||
|
||||
} fifo_t;
|
||||
|
||||
typedef struct _susb_irp_t
|
||||
{
|
||||
UINT16 tsize;
|
||||
UINT32 is_in, is_out;
|
||||
UINT32 port, ept;
|
||||
UINT16 cy_irp_addr;
|
||||
fifo_t fifo;
|
||||
UINT32 tx_in_progress;
|
||||
cy_req_t cy_req;
|
||||
} usb_irp_t;
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// CY7C67300 related
|
||||
// ---------------------------------------------------------
|
||||
#define HPI_WAITACK 1
|
||||
#define HPI_NOWAIT 0
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// HPI status flags
|
||||
#define HPI_STATUS_MBX_IN 0x0001
|
||||
#define HPI_STATUS_RESET1 0x0002
|
||||
#define HPI_STATUS_DONE1 0x0004
|
||||
#define HPI_STATUS_DONE2 0x0008
|
||||
#define HPI_STATUS_SIEMSG1 0x0010
|
||||
#define HPI_STATUS_SIEMSG2 0x0020
|
||||
#define HPI_STATUS_RESUME1 0x0040
|
||||
#define HPI_STATUS_RESUME2 0x0080
|
||||
#define HPI_STATUS_MBX_OUT 0x0100
|
||||
#define HPI_STATUS_RESET2 0x0200
|
||||
#define HPI_STATUS_SOFEOP1 0x0400
|
||||
#define HPI_STATUS_SOFEOP2 0x1000
|
||||
#define HPI_STATUS_ID 0x4000
|
||||
#define HPI_STATUS_VBUS 0x8000
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// LCP command codes
|
||||
#define COMM_RESET 0xFA50
|
||||
#define COMM_JUMP2CODE 0xCE00
|
||||
#define COMM_EXEC_INT 0xCE01
|
||||
#define COMM_READ_CTRL_REG 0xCE02
|
||||
#define COMM_WRITE_CTRL_REG 0xCE03
|
||||
#define COMM_CALL_CODE 0xCE04
|
||||
#define COMM_READ_XMEM 0xCE05
|
||||
#define COMM_WRITE_XMEM 0xCE06
|
||||
#define C0MM_CONFIG 0xCE07
|
||||
#define COMM_READ_MEM 0xCE08
|
||||
#define COMM_WRITE_MEM 0xCE09
|
||||
// LCP response codes
|
||||
#define COMM_ACK 0x0FED
|
||||
#define COMM_NAK 0xDEAD
|
||||
#define COMM_ASYNC 0xF00D
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// LCP memory addresses
|
||||
#define COMM_PORT_CMD 0x01BA // For PORT Command
|
||||
#define COMM_MEM_ADDR 0x01BC // Address for COMM_RD/WR_MEM
|
||||
#define COMM_MEM_LEN 0x01BE // Address for COMM_RD/WR_MEM
|
||||
#define COMM_LAST_DATA 0x01C0 // memory pointer for xmem
|
||||
#define COMM_CTRL_REG_ADDR 0x01BC // Address for COMM_RD/WR_CTRL_REG
|
||||
#define COMM_CTRL_REG_DATA 0x01BE // Address for COMM_RD/WR_CTRL_REG
|
||||
#define COMM_CTRL_REG_LOGIC 0x01C0 // Address used for AND/OR
|
||||
#define REG_WRITE_FLG 0x0000 // Value for COMM_CTRL_REG_LOGIC
|
||||
#define REG_AND_FLG 0x0001 // Value for COMM_CTRL_REG_LOGIC
|
||||
#define REG_OR_FLG 0x0002 // Value for COMM_CTRL_REG_LOGIC
|
||||
#define COMM_TIMEOUT 0x01BE // Address setting Timeout for sending response to host
|
||||
#define COMM_CODE_ADDR 0x01BC // Address for COMM_CALL_CODE and COMM_JUMP2CODE
|
||||
#define COMM_INT_NUM 0x01C2 // Address used for COMM_EXEC_INT
|
||||
#define COMM_R0 0x01C4 // CY16-R0 register
|
||||
#define COMM_R1 0x01C6 // CY16-R1 register
|
||||
#define COMM_R2 0x01C8 // CY16-R2 register
|
||||
#define COMM_R3 0x01CA // CY16-R3 register
|
||||
#define COMM_R4 0x01CC // CY16-R4 register
|
||||
#define COMM_R5 0x01CE // CY16-R5 register
|
||||
#define COMM_R6 0x01D0 // CY16-R6 register
|
||||
#define COMM_R7 0x01D2 // CY16-R7 register
|
||||
#define COMM_R8 0x01D4 // CY16-R8 register
|
||||
#define COMM_R9 0x01D6 // CY16-R9 register
|
||||
#define COMM_R10 0x01D8 // CY16-R10 register
|
||||
#define COMM_R11 0x01DA // CY16-R11 register
|
||||
#define COMM_R12 0x01DC // CY16-R12 register
|
||||
#define COMM_R13 0x01DE // CY16-R13 register
|
||||
|
||||
// for COMM_CTRL_REG_LOGIC
|
||||
#define LOGIC_DIRECT 0
|
||||
#define LOGIC_AND 1
|
||||
#define LOGIC_OR 2
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Software interrupts
|
||||
#define SUSB_INIT_INT 113
|
||||
// USB 1
|
||||
#define SUSB1_DEVICE_DESCRIPTOR_VEC 90
|
||||
#define SUSB1_CONFIGURATION_DESCRIPTOR_VEC 91
|
||||
#define SUSB1_STRING_DESCRIPTOR_VEC 92
|
||||
#define SUSB1_FINISH_INT 89
|
||||
#define SUSB1_STALL_INT 82
|
||||
#define SUSB1_STANDARD_INT 83
|
||||
#define SUSB1_SEND_INT 80
|
||||
#define SUSB1_RECEIVE_INT 81
|
||||
#define SUSB1_VENDOR_INT 85
|
||||
#define SUSB1_CLASS_INT 87
|
||||
#define SUSB1_LOADER_INT 94
|
||||
#define SUSB1_DELTA_CONFIG_INT 95
|
||||
|
||||
// USB 2
|
||||
#define SUSB2_DEVICE_DESCRIPTOR_VEC 106
|
||||
#define SUSB2_CONFIGURATION_DESCRIPTOR_VEC 107
|
||||
#define SUSB2_STRING_DESCRIPTOR_VEC 108
|
||||
#define SUSB2_FINISH_INT 105
|
||||
#define SUSB2_STALL_INT 98
|
||||
#define SUSB2_STANDARD_INT 99
|
||||
#define SUSB2_SEND_INT 96
|
||||
#define SUSB2_RECEIVE_INT 97
|
||||
#define SUSB2_VENDOR_INT 101
|
||||
#define SUSB2_CLASS_INT 103
|
||||
#define SUSB2_LOADER_INT 110
|
||||
#define SUSB2_DELTA_CONFIG_INT 111
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// General USB Registers
|
||||
#define USB_REG_FLAGS 0xC000 // CPU Flags
|
||||
#define USB_REG_BANK 0xC002 // Register Bank
|
||||
#define USB_REG_REVISON 0xC004 // Hardware Revision
|
||||
#define USB_REG_SPEED 0xC008 // CPU Speed
|
||||
#define USB_REG_PWRCTRL 0xC00A // Power Control
|
||||
#define USB_REG_INTEN 0xC00E // Interrupt Enable
|
||||
#define USB_REG_BP 0xC014 // Breakpoint
|
||||
#define USB_REG_USBDIAG 0xC03C // USB Diagnostic
|
||||
#define USB_REG_MEMDIAG 0xC03E // Memory Diagnostic
|
||||
|
||||
// HPI registers
|
||||
#define HPI_REG_BP 0x0140 // HPI Breakpoint
|
||||
#define HPI_REG_INTROUTE 0x0142 // Interrupt Routing
|
||||
#define HPI_REG_SIE1MSG 0x0144 // SIE1msg
|
||||
#define HPI_REG_SIE2MSG 0x0148 // SIE2msg
|
||||
#define HPI_REG_MAILBOX 0xC0C6 // HPI Mailbox
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// General Device Registers
|
||||
// Device 1
|
||||
#define SUSB1_REG_PORTSEL 0xC084 // Port select
|
||||
#define SUSB1_REG_USBCTRL 0xC08A // USB control
|
||||
#define SUSB1_REG_INTEN 0xC08C // Interrupt enable
|
||||
#define SUSB1_REG_ADDR 0xC08E // Address
|
||||
#define SUSB1_REG_STATUS 0xC090 // Status
|
||||
#define SUSB1_REG_FRAMENUM 0xC092 // Frame number
|
||||
#define SUSB1_REG_SOFEOPCNT 0xC094 // SOF/EOP count
|
||||
|
||||
// Device 2
|
||||
#define SUSB2_REG_PORTSEL 0xC0A4 // Port select
|
||||
#define SUSB2_REG_USBCTRL 0xC0AA // USB control
|
||||
#define SUSB2_REG_INTEN 0xC0AC // Interrupt enable
|
||||
#define SUSB2_REG_ADDR 0xC0AE // Address
|
||||
#define SUSB2_REG_STATUS 0xC0B0 // Status
|
||||
#define SUSB2_REG_FRAMENUM 0xC0B2 // Frame number
|
||||
#define SUSB2_REG_SOFEOPCNT 0xC0B4 // SOF/EOP count
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Endpoint Registers
|
||||
// Device 1 Control
|
||||
#define SUSB1_REG_EP_CTRL0 0x0200
|
||||
#define SUSB1_REG_EP_CTRL1 0x0210
|
||||
#define SUSB1_REG_EP_CTRL2 0x0220
|
||||
#define SUSB1_REG_EP_CTRL3 0x0230
|
||||
#define SUSB1_REG_EP_CTRL4 0x0240
|
||||
#define SUSB1_REG_EP_CTRL5 0x0250
|
||||
#define SUSB1_REG_EP_CTRL6 0x0260
|
||||
#define SUSB1_REG_EP_CTRL7 0x0270
|
||||
// Device 1 Address
|
||||
#define SUSB1_REG_EP_ADDR0 0x0202
|
||||
#define SUSB1_REG_EP_ADDR1 0x0212
|
||||
#define SUSB1_REG_EP_ADDR2 0x0222
|
||||
#define SUSB1_REG_EP_ADDR3 0x0232
|
||||
#define SUSB1_REG_EP_ADDR4 0x0242
|
||||
#define SUSB1_REG_EP_ADDR5 0x0252
|
||||
#define SUSB1_REG_EP_ADDR6 0x0262
|
||||
#define SUSB1_REG_EP_ADDR7 0x0272
|
||||
// Device 1 Count
|
||||
#define SUSB1_REG_EP_COUNT0 0x0204
|
||||
#define SUSB1_REG_EP_COUNT1 0x0214
|
||||
#define SUSB1_REG_EP_COUNT2 0x0224
|
||||
#define SUSB1_REG_EP_COUNT3 0x0234
|
||||
#define SUSB1_REG_EP_COUNT4 0x0244
|
||||
#define SUSB1_REG_EP_COUNT5 0x0254
|
||||
#define SUSB1_REG_EP_COUNT6 0x0264
|
||||
#define SUSB1_REG_EP_COUNT7 0x0274
|
||||
// Device 1 Status
|
||||
#define SUSB1_REG_EP_STATUS0 0x0206
|
||||
#define SUSB1_REG_EP_STATUS1 0x0216
|
||||
#define SUSB1_REG_EP_STATUS2 0x0226
|
||||
#define SUSB1_REG_EP_STATUS3 0x0236
|
||||
#define SUSB1_REG_EP_STATUS4 0x0246
|
||||
#define SUSB1_REG_EP_STATUS5 0x0256
|
||||
#define SUSB1_REG_EP_STATUS6 0x0266
|
||||
#define SUSB1_REG_EP_STATUS7 0x0276
|
||||
// Device 1 Count result
|
||||
#define SUSB1_REG_EP_CNTRES0 0x0208
|
||||
#define SUSB1_REG_EP_CNTRES1 0x0218
|
||||
#define SUSB1_REG_EP_CNTRES2 0x0228
|
||||
#define SUSB1_REG_EP_CNTRES3 0x0238
|
||||
#define SUSB1_REG_EP_CNTRES4 0x0248
|
||||
#define SUSB1_REG_EP_CNTRES5 0x0258
|
||||
#define SUSB1_REG_EP_CNTRES6 0x0268
|
||||
#define SUSB1_REG_EP_CNTRES7 0x0278
|
||||
|
||||
// Device 2 Control
|
||||
#define SUSB2_REG_EP_CTRL0 0x0280
|
||||
#define SUSB2_REG_EP_CTRL1 0x0290
|
||||
#define SUSB2_REG_EP_CTRL2 0x02A0
|
||||
#define SUSB2_REG_EP_CTRL3 0x02B0
|
||||
#define SUSB2_REG_EP_CTRL4 0x02C0
|
||||
#define SUSB2_REG_EP_CTRL5 0x02D0
|
||||
#define SUSB2_REG_EP_CTRL6 0x02E0
|
||||
#define SUSB2_REG_EP_CTRL7 0x02F0
|
||||
// Device 2 Address
|
||||
#define SUSB2_REG_EP_ADDR0 0x0282
|
||||
#define SUSB2_REG_EP_ADDR1 0x0292
|
||||
#define SUSB2_REG_EP_ADDR2 0x02A2
|
||||
#define SUSB2_REG_EP_ADDR3 0x02B2
|
||||
#define SUSB2_REG_EP_ADDR4 0x02C2
|
||||
#define SUSB2_REG_EP_ADDR5 0x02D2
|
||||
#define SUSB2_REG_EP_ADDR6 0x02E2
|
||||
#define SUSB2_REG_EP_ADDR7 0x02F2
|
||||
// Device 2 Count
|
||||
#define SUSB2_REG_EP_COUNT0 0x0284
|
||||
#define SUSB2_REG_EP_COUNT1 0x0294
|
||||
#define SUSB2_REG_EP_COUNT2 0x02A4
|
||||
#define SUSB2_REG_EP_COUNT3 0x02B4
|
||||
#define SUSB2_REG_EP_COUNT4 0x02C4
|
||||
#define SUSB2_REG_EP_COUNT5 0x02D4
|
||||
#define SUSB2_REG_EP_COUNT6 0x02E4
|
||||
#define SUSB2_REG_EP_COUNT7 0x02F4
|
||||
// Device 2 Status
|
||||
#define SUSB2_REG_EP_STATUS0 0x0286
|
||||
#define SUSB2_REG_EP_STATUS1 0x0296
|
||||
#define SUSB2_REG_EP_STATUS2 0x02A6
|
||||
#define SUSB2_REG_EP_STATUS3 0x02B6
|
||||
#define SUSB2_REG_EP_STATUS4 0x02C6
|
||||
#define SUSB2_REG_EP_STATUS5 0x02D6
|
||||
#define SUSB2_REG_EP_STATUS6 0x02E6
|
||||
#define SUSB2_REG_EP_STATUS7 0x02F6
|
||||
// Device 2 Count result
|
||||
#define SUSB2_REG_EP_CNTRES0 0x0288
|
||||
#define SUSB2_REG_EP_CNTRES1 0x0298
|
||||
#define SUSB2_REG_EP_CNTRES2 0x02A8
|
||||
#define SUSB2_REG_EP_CNTRES3 0x02B8
|
||||
#define SUSB2_REG_EP_CNTRES4 0x02C8
|
||||
#define SUSB2_REG_EP_CNTRES5 0x02D8
|
||||
#define SUSB2_REG_EP_CNTRES6 0x02E8
|
||||
#define SUSB2_REG_EP_CNTRES7 0x02F8
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// others
|
||||
#define HUSB_TDLISTDONE 0x1000
|
||||
#define HUSB_SOF 0x2000
|
||||
#define HUSB_ARMV 0x0001
|
||||
#define HUSB_AINS_FS 0x0002
|
||||
#define HUSB_AINS_LS 0x0004
|
||||
#define HUSB_AWAKEUP 0x0008
|
||||
#define HUSB_BRMV 0x0010
|
||||
#define HUSB_BINS_FS 0x0020
|
||||
#define HUSB_BINS_LS 0x0040
|
||||
#define HUSB_BWAKEUP 0x0080
|
||||
|
||||
#define SUSB_EP0_MSG 0x0001
|
||||
#define SUSB_EP1_MSG 0x0002
|
||||
#define SUSB_EP2_MSG 0x0004
|
||||
#define SUSB_EP3_MSG 0x0008
|
||||
#define SUSB_EP4_MSG 0x0010
|
||||
#define SUSB_EP5_MSG 0x0020
|
||||
#define SUSB_EP6_MSG 0x0040
|
||||
#define SUSB_EP7_MSG 0x0080
|
||||
#define SUSB_RST_MSG 0x0100
|
||||
#define SUSB_SOF_MSG 0x0200
|
||||
#define SUSB_CFG_MSG 0x0400
|
||||
#define SUSB_SUS_MSG 0x0800
|
||||
#define SUSB_ID_MSG 0x4000
|
||||
#define SUSB_VBUS_MSG 0x8000
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// Functions
|
||||
// ---------------------------------------------------------
|
||||
|
||||
// HPI low-level routines
|
||||
void cy67k3_isr(void);
|
||||
void cy67k3_reset(void);
|
||||
UINT16 cy67k3_read_HPI_DATA(void);
|
||||
UINT16 cy67k3_read_HPI_MAILBOX(void);
|
||||
UINT16 cy67k3_read_HPI_ADDRESS(void);
|
||||
UINT16 cy67k3_read_HPI_STATUS(void);
|
||||
void cy67k3_write_HPI_DATA(UINT16 data);
|
||||
void cy67k3_write_HPI_MAILBOX(UINT16 data);
|
||||
void cy67k3_write_HPI_ADDRESS(UINT16 data);
|
||||
void cy67k3_write_HPI_STATUS(UINT16 data);
|
||||
|
||||
// HPI API
|
||||
UINT32 hpi_init(void);
|
||||
void hpi_mbx_write(UINT16 msgcode);
|
||||
UINT32 hpi_mbx_read(void);
|
||||
UINT32 hpi_read_reg(UINT16 addr);
|
||||
UINT32 hpi_write_reg(UINT16 addr, UINT16 data);
|
||||
UINT32 hpi_write_ram(UINT16 addr, UINT16 *pData, UINT32 num_words);
|
||||
UINT32 hpi_read_ram(UINT16 addr, UINT16 *pData, UINT32 num_words);
|
||||
UINT32 hpi_comm_reset(void);
|
||||
UINT32 hpi_comm_jump2code(UINT16 addr);
|
||||
UINT32 hpi_comm_callcode(UINT16 addr);
|
||||
UINT32 hpi_comm_write_ctrl_reg(UINT16 addr, UINT16 data, UINT16 logic);
|
||||
UINT32 hpi_comm_read_ctrl_reg(UINT16 addr);
|
||||
UINT32 hpi_comm_write_xmem(UINT16 addr, UINT8 *pData, UINT16 len);
|
||||
UINT32 hpi_comm_read_xmem(UINT16 addr, UINT8 *pData, UINT16 len);
|
||||
UINT32 hpi_comm_exec_int(UINT16 intnum, UINT32 nargs, ...);
|
||||
|
||||
// USB API
|
||||
UINT32 usb_init(void);
|
||||
UINT32 usb_irp_register(usb_irp_t *pIRP, UINT32 port, UINT32 ept, UINT32 size, UINT32 is_out);
|
||||
UINT32 usb_irp_enqueue(usb_irp_t *pIRP);
|
||||
UINT32 usb_callback_register(UINT32 port, UINT32 type, fp_t pFunc, void *pArg);
|
||||
|
||||
#define FIFO_BLOCK 1
|
||||
#define FIFO_NONBLOCK 0
|
||||
UINT32 fifo_alloc(fifo_t *pObj, UINT32 size);
|
||||
UINT32 fifo_free(fifo_t *pObj);
|
||||
UINT32 fifo_flush(fifo_t *pObj);
|
||||
UINT32 fifo_is_full(fifo_t *pObj);
|
||||
UINT32 fifo_is_empty(fifo_t *pObj);
|
||||
UINT32 fifo_read(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block);
|
||||
UINT32 fifo_write(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block);
|
||||
|
||||
#endif // HPI_H
|
||||
@@ -1,504 +0,0 @@
|
||||
/* inflate routines for Palm OS (to inflate a deflated stream)
|
||||
*
|
||||
* Based heavily upon gunzip.c by Pasi Ojala <albert@cs.tut.fi>
|
||||
* http://www.cs.tut.fi/~albert/Dev/gunzip/
|
||||
* Many, many thanks for that code!
|
||||
*
|
||||
* Changes:
|
||||
* 2002-12-30 - Added #defines to use zlib's struct instead of mine, just
|
||||
* in case you want to compile it that way.
|
||||
* 2002-12-29 - Found out that this is VERY slow. ZLib is 3x faster.
|
||||
* Worked on speeding it up. Partially successful. Profiled
|
||||
* code and marked critical areas. 1932 bytes added to a
|
||||
* Palm program by linking in the .o file. Schweet!
|
||||
* 2002-12-21 - Finished surgery. Only one function to inflate dynamic and
|
||||
* fixed data. Rewrote table generation to be iterative.
|
||||
* Hacked and slashed my way through unnecessary code.
|
||||
* The size is now down to 3512 bytes.
|
||||
* 2002-12-20 - Started major surgery
|
||||
* 2002-12-19 - Looked at the code a bit more
|
||||
* 2002-12-17 - Continued work. Down to about 6k for the .o file
|
||||
* 2002-12-09 - Continued work, added z_stream_fid instead of globals
|
||||
* 2002-12-08 - Started work so that it decompresses up to 64k (one memory
|
||||
* chunk on the Palm.
|
||||
* 2002-12-07 - Removed bit reverse table. Removed unzip code.
|
||||
*/
|
||||
#include "libsys.h"
|
||||
#include "inflate.h"
|
||||
#ifdef VERBOSE
|
||||
#include <stdio.h> // Just in case you put a printf() function back in
|
||||
#endif
|
||||
|
||||
void Status(char *, int);
|
||||
|
||||
typedef struct HufNode_struct {
|
||||
// b0 and b1 are either values in the tree array to jump to (branches)
|
||||
// or are literal values.
|
||||
// if (bX & 0x8000)
|
||||
// value = bX ^ 0x8000;
|
||||
// else
|
||||
// link_to_array_element = bX;
|
||||
unsigned int b0; // Bigger than 1 byte (2 is ideal)
|
||||
unsigned int b1; // Bigger than 1 byte (2 is ideal)
|
||||
} HufNode;
|
||||
|
||||
|
||||
// Not that rhobust anymore -- If out of data, this will
|
||||
// return a whole lot of 1 bits.
|
||||
//
|
||||
// This function consumes a large percentage of time (#1)
|
||||
char READBIT(z_stream *zs)
|
||||
{
|
||||
char carry;
|
||||
|
||||
if (zs->reserved == 1)
|
||||
{
|
||||
if (zs->avail_in == 0)
|
||||
return 1;
|
||||
zs->reserved = *(zs->next_in ++) | 0x0100;
|
||||
zs->avail_in --;
|
||||
}
|
||||
|
||||
carry = zs->reserved & 1;
|
||||
zs->reserved >>= 1;
|
||||
|
||||
return carry;
|
||||
}
|
||||
|
||||
|
||||
// Make sure that [a] is <= 16
|
||||
// If there are endian problems, force [a] to be <= 8
|
||||
// Might be faster if all (up to [a] bits) of zs->reserved was read into res
|
||||
// right away.
|
||||
//
|
||||
// This function consumes a large percentage of time (#4)
|
||||
int READBITS(z_stream *zs, int a)
|
||||
{
|
||||
int res = 0, pos = 0;
|
||||
|
||||
while (a --)
|
||||
{
|
||||
if (zs->reserved == 1)
|
||||
{
|
||||
if (zs->avail_in == 0)
|
||||
return 1;
|
||||
zs->reserved = *(zs->next_in ++) | 0x0100;
|
||||
zs->avail_in --;
|
||||
}
|
||||
|
||||
res += (zs->reserved & 1) << pos;
|
||||
zs->reserved >>= 1;
|
||||
pos ++;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// Huffman tree structures, variables and related routines
|
||||
//
|
||||
// These routines are one-bit-at-a-time decode routines. They
|
||||
// are not as fast as multi-bit routines, but maybe a bit easier
|
||||
// to understand and use a lot less memory.
|
||||
//
|
||||
// The tree is created in an array
|
||||
//
|
||||
// currentTree = where to put the tree (in an array)
|
||||
// numval = Number of elements in the lengths array
|
||||
// lengths = array of lengths
|
||||
//
|
||||
//
|
||||
// This function consumes a large percentage of time (#5)
|
||||
int CreateTree(HufNode *currentTree, int numval, unsigned char *lengths) {
|
||||
int i, j, len; // basically scratch values
|
||||
int BlankNode; // Where is the next blank array index
|
||||
int this_code, mask, *bitData; // used in tree generation
|
||||
int bl_count[16] = { 0, }; // Counter of code lengths
|
||||
int next_code[16] = { 0, }; // Code for a specific length
|
||||
// 16 = (15 is max length of a code when inflating) + (1 for zero)
|
||||
|
||||
// Step 1: Count the code lengths
|
||||
for (i = 0; i < numval; i ++)
|
||||
{
|
||||
j = lengths[i];
|
||||
if (j > 15)
|
||||
return 1;
|
||||
bl_count[j] ++;
|
||||
}
|
||||
|
||||
// Step 2: Find numerical value of the smallest code of each length
|
||||
// Also note that I've inserted some weak validation code here. I'm
|
||||
// not 100% sure that it is up to RFC specs, but it seems to work fine
|
||||
// in my tests
|
||||
//
|
||||
// The validation theory is that at the root node, you have 2 branches or
|
||||
// values possible. If you branch, you get 2 more potentials. If you
|
||||
// get a value, you lose one potential. So, if the root node has one of
|
||||
// each, the number of potentials at the next level is still two. If that
|
||||
// node just has branches, the number of potentials is four. If both of
|
||||
// the nodes on the following level just have values, the number of
|
||||
// potentials is 0, leaving us with a complete tree.
|
||||
//
|
||||
// If I don't validate and if an invalid tree gets generated, an
|
||||
// infinite loop is possible
|
||||
bl_count[0] = 0;
|
||||
j = 0;
|
||||
len = 2;
|
||||
for (i = 1; i < 16; i ++)
|
||||
{
|
||||
len -= bl_count[i];
|
||||
len *= 2;
|
||||
j = (j + bl_count[i - 1]) << 1;
|
||||
next_code[i] = j;
|
||||
}
|
||||
if (len)
|
||||
return 1;
|
||||
|
||||
// Step 3: Assign numerical values to all codes
|
||||
BlankNode = 1;
|
||||
currentTree[0].b0 = 0x0000;
|
||||
currentTree[0].b1 = 0x0000;
|
||||
for (i = 0; i < numval; i ++)
|
||||
{
|
||||
len = lengths[i];
|
||||
if (len != 0)
|
||||
{
|
||||
this_code = next_code[len];
|
||||
next_code[len] ++;
|
||||
mask = 1 << (len - 1);
|
||||
j = 0;
|
||||
while (mask > 1)
|
||||
{
|
||||
if (this_code & mask)
|
||||
bitData = &(currentTree[j].b1);
|
||||
else
|
||||
bitData = &(currentTree[j].b0);
|
||||
|
||||
if (*bitData == 0x0000)
|
||||
{
|
||||
*bitData = BlankNode;
|
||||
j = BlankNode;
|
||||
BlankNode ++;
|
||||
currentTree[j].b0 = 0x0000;
|
||||
currentTree[j].b1 = 0x0000;
|
||||
}
|
||||
else
|
||||
j = *bitData;
|
||||
|
||||
mask >>= 1;
|
||||
}
|
||||
if (this_code & 0x01)
|
||||
currentTree[j].b1 = 0x8000 | i;
|
||||
else
|
||||
currentTree[j].b0 = 0x8000 | i;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
fprintf(stderr, "%d table entries used\n",
|
||||
BlankNode);
|
||||
if (numval < 20) {
|
||||
for (i = 0; i < BlankNode; i ++)
|
||||
{
|
||||
fprintf(stderr, "0x%03x - ", i);
|
||||
if (currentTree[i].b0 & 0x8000)
|
||||
fprintf(stderr, "value: 0x%03x ", currentTree[i].b0 ^ 0x8000);
|
||||
else
|
||||
fprintf(stderr, " link: 0x%03x ", currentTree[i].b0);
|
||||
|
||||
if (currentTree[i].b1 & 0x8000)
|
||||
fprintf(stderr, "value: 0x%03x\n", currentTree[i].b1 ^ 0x8000);
|
||||
else
|
||||
fprintf(stderr, " link: 0x%03x\n", currentTree[i].b1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Using the tree passed in, read bits from the data stream until we arrive
|
||||
// at the proper value
|
||||
//
|
||||
// This function consumes a large percentage of time (#2)
|
||||
int DecodeValue(z_stream *zs, HufNode *currentTree)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
// decode one symbol of the data per iteration
|
||||
// Infinite loop detection code could go here. Maximum
|
||||
// bits to read is 15.
|
||||
while (i < 0x8000)
|
||||
{
|
||||
if (READBIT(zs))
|
||||
i = currentTree[i].b1;
|
||||
else
|
||||
i = currentTree[i].b0;
|
||||
}
|
||||
return i & 0x7FFF;
|
||||
}
|
||||
|
||||
|
||||
int Decompress_Stored(z_stream *zs)
|
||||
{
|
||||
int blockLen, cSum;
|
||||
|
||||
#ifdef VERBOSE
|
||||
fprintf(stderr, "Stored\n");
|
||||
#endif
|
||||
|
||||
zs->reserved = 1;;
|
||||
if (zs->avail_in < 4)
|
||||
return -1;
|
||||
|
||||
zs->avail_in -= 4;
|
||||
blockLen = *(zs->next_in ++);
|
||||
blockLen |= *(zs->next_in ++) << 8;
|
||||
|
||||
cSum = *(zs->next_in ++);
|
||||
cSum |= (*(zs->next_in ++) << 8);
|
||||
|
||||
if ((blockLen + cSum) ^ 0xFFFF)
|
||||
return 1;
|
||||
if (zs->avail_in < blockLen || zs->avail_out < blockLen)
|
||||
return -1;
|
||||
zs->avail_in -= blockLen;
|
||||
zs->avail_out -= blockLen;
|
||||
|
||||
while (blockLen --)
|
||||
{
|
||||
*(zs->next_out) = *(zs->next_in);
|
||||
zs->next_out ++;
|
||||
zs->next_in ++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int MakeTrees(z_stream *zs, char is_fixed, HufNode *literalTree,
|
||||
HufNode *distanceTree)
|
||||
{
|
||||
// Order of the bit length code lengths
|
||||
static const unsigned border[] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
|
||||
unsigned char ll[288+32];
|
||||
int i, j, n, l, literalCodes, distCodes;
|
||||
|
||||
if (is_fixed)
|
||||
{
|
||||
literalCodes = 288;
|
||||
|
||||
// Set a large range to 8
|
||||
for (i = 0; i < 288; i ++)
|
||||
ll[i] = 8;
|
||||
// In that range, set some to 9 and others to 7
|
||||
// (smaller code, but slightly slower table generation)
|
||||
for (i = 144; i < 256; i ++)
|
||||
ll[i] = 9;
|
||||
for (; i < 280; i ++)
|
||||
ll[i] = 7;
|
||||
|
||||
distCodes = 32;
|
||||
|
||||
for (i = 288; i < 320; i ++)
|
||||
ll[i] = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
literalCodes = 257 + READBITS(zs, 5);
|
||||
distCodes = 1 + READBITS(zs, 5);
|
||||
l = 4 + READBITS(zs, 4);
|
||||
|
||||
for (j = 0; j < 19; j ++)
|
||||
ll[j] = 0;
|
||||
|
||||
// Get the decode tree code lengths
|
||||
// The decode tree is Huffman encoded
|
||||
|
||||
for (j = 0; j < l; j++)
|
||||
{
|
||||
ll[border[j]] = READBITS(zs, 3);
|
||||
}
|
||||
if (CreateTree(distanceTree, 19, ll))
|
||||
return 1;
|
||||
|
||||
// read in literal and distance code lengths
|
||||
n = literalCodes + distCodes;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
j = DecodeValue(zs, distanceTree);
|
||||
if (j < 16) // length of code in bits (0..15)
|
||||
ll[i++] = j;
|
||||
else if (j == 16)
|
||||
{ // repeat last length 3 to 6 times
|
||||
j = 3 + READBITS(zs, 2);
|
||||
|
||||
if (i + j > n)
|
||||
return 1;
|
||||
|
||||
l = i ? ll[i-1] : 0;
|
||||
while (j --)
|
||||
ll[i++] = l;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j == 17) // 3 to 10 zero length codes
|
||||
j = 3 + READBITS(zs, 3);
|
||||
else // j == 18: 11 to 138 zero length codes
|
||||
j = 11 + READBITS(zs, 7);
|
||||
|
||||
if (i + j > n)
|
||||
return 1;
|
||||
|
||||
while (j --)
|
||||
ll[i++] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Can overwrite tree decode tree as it is not used anymore
|
||||
if (CreateTree(literalTree, literalCodes, &ll[0]))
|
||||
return 1;
|
||||
|
||||
if(CreateTree(distanceTree, distCodes, &ll[literalCodes]))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// This function consumes a large percentage of time (#3)
|
||||
// Most output produced by gzip/zlib/etc is dynamic.
|
||||
int Decompress_DynamicOrFixed(z_stream *zs, char is_fixed)
|
||||
{
|
||||
// Copy lengths for literal codes 257..285
|
||||
static const unsigned short cplens[] = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 };
|
||||
// Extra bits for literal codes 257..285
|
||||
static const unsigned short cplext[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 }; // 99==invalid
|
||||
// Copy offsets for distance codes 0..29
|
||||
static const unsigned short cpdist[] = {
|
||||
0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d,
|
||||
0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1,
|
||||
0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01,
|
||||
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001 };
|
||||
// Extra bits for distance codes
|
||||
static const unsigned short cpdext[] = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2,
|
||||
3, 3, 4, 4, 5, 5, 6, 6,
|
||||
7, 7, 8, 8, 9, 9, 10, 10,
|
||||
11, 11, 12, 12, 13, 13 };
|
||||
HufNode literalTree[288];
|
||||
HufNode distanceTree[32];
|
||||
int j, l, dist;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (is_fixed)
|
||||
fprintf(stderr, "Fixed Huffman codes\n");
|
||||
else
|
||||
fprintf(stderr, "Dynamic Huffman codes\n");
|
||||
#endif
|
||||
|
||||
if (MakeTrees(zs, is_fixed, literalTree, distanceTree))
|
||||
return 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
j = DecodeValue(zs, literalTree);
|
||||
if (j >= 256)
|
||||
{
|
||||
if (j == 256) // EOF
|
||||
break;
|
||||
|
||||
//printf("%04x ", j);
|
||||
j -= 256 + 1; // bytes + EOF
|
||||
|
||||
l = READBITS(zs, cplext[j]) + cplens[j];
|
||||
//printf("%04x ", l);
|
||||
|
||||
j = DecodeValue(zs, distanceTree);
|
||||
//printf("%02x ", j);
|
||||
|
||||
dist = READBITS(zs, cpdext[j]) + cpdist[j];
|
||||
//printf("%04x ", dist);
|
||||
|
||||
//printf("LZ77 len %d dist %d @%04x\n", l, dist, bIdx);
|
||||
while(l--)
|
||||
{
|
||||
//printf("%02x ", c);
|
||||
if (! zs->avail_out --)
|
||||
return -1;
|
||||
|
||||
*(zs->next_out ++) = *(zs->next_out - dist);
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("%02x\n", j);
|
||||
if (! zs->avail_out --)
|
||||
return -1;
|
||||
*(zs->next_out ++) = (unsigned char) j;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Returns 0 if success
|
||||
int InflateData(z_stream *zs) {
|
||||
int last, type;
|
||||
|
||||
zs->reserved = 1;;
|
||||
|
||||
do
|
||||
{
|
||||
last = READBIT(zs);
|
||||
#ifdef VERBOSE
|
||||
if (last)
|
||||
fprintf(stderr, "Last Block: ");
|
||||
else
|
||||
fprintf(stderr, "Not Last Block: ");
|
||||
#endif
|
||||
|
||||
type = READBITS(zs, 2);
|
||||
|
||||
if (type == 0)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
fprintf(stderr, "Decompress_Stored..");
|
||||
#endif
|
||||
if (Decompress_Stored(zs))
|
||||
return 1;
|
||||
}
|
||||
else if (type > 2)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
if (type == 3)
|
||||
fprintf(stderr, "Reserved block type!!\n");
|
||||
else // the "else" should never happen
|
||||
fprintf(stderr, "Unexpected value %d!\n", type);
|
||||
#endif
|
||||
zs->reserved = 1;;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
fprintf(stderr, "Decompress_DynamicOrFixed..");
|
||||
#endif
|
||||
if (Decompress_DynamicOrFixed(zs, type & 0x01))
|
||||
return 1;
|
||||
}
|
||||
} while(!last);
|
||||
|
||||
zs->reserved = 1;;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifdef USE_ZLIB_STRUCT
|
||||
#include "SysZLib.h" // For PalmOS. Change to your liking.
|
||||
#else
|
||||
typedef struct z_stream_s
|
||||
{
|
||||
unsigned char *next_in; // Next input byte (CHANGES)
|
||||
unsigned int avail_in; // number of bytes left at next_in
|
||||
unsigned char *next_out; // Next output byte goes here (CHANGES)
|
||||
unsigned int avail_out; // number of bytes left at next_out
|
||||
unsigned int reserved; // For the readbit() and readbits() functions
|
||||
// Bigger than 1 byte
|
||||
} z_stream;
|
||||
#endif
|
||||
|
||||
int InflateData(z_stream *zs);
|
||||
@@ -1,260 +0,0 @@
|
||||
.file "kernel.s"
|
||||
|
||||
.equ stack_ptr, 0x7FFFEFFC
|
||||
.equ baudrate, 0x0D
|
||||
.equ sys_led_port, 0xA0000000
|
||||
.equ sys_uart_baud, 0xA0000009
|
||||
.equ sys_uart_stat, 0xA0000008
|
||||
.equ sys_uart_data, 0xA0000004
|
||||
.equ sys_timer_sec, 0xA0000014
|
||||
.equ sys_timer_usec, 0xA0000010
|
||||
|
||||
.section .kdata,"a"
|
||||
.align 2
|
||||
_k_stack: .space 256, 0
|
||||
_k_msg1: .asciiz "Exception at "
|
||||
_k_msg2: .asciiz "EPC : "
|
||||
_k_msg3: .asciiz "Cause : "
|
||||
_k_msg4: .asciiz "Status : "
|
||||
_k_msg5: .asciiz "BadVAddr : "
|
||||
_k_crlf: .asciiz "\r\n"
|
||||
_k_hextbl: .ascii "0123456789ABCDEF"
|
||||
|
||||
.section .ktext,"ax"
|
||||
.align 2
|
||||
.globl _kputs
|
||||
|
||||
.macro kpush reg
|
||||
addiu $sp, 4
|
||||
sw \reg, 0($sp)
|
||||
.endm
|
||||
|
||||
.macro kpop reg
|
||||
lw \reg, 0($sp)
|
||||
addiu $sp, -4
|
||||
.endm
|
||||
|
||||
_exc_handler:
|
||||
|
||||
sw $sp, _k_stack
|
||||
la $sp, _k_stack
|
||||
kpush $8
|
||||
kpush $9
|
||||
kpush $10
|
||||
kpush $11
|
||||
kpush $12
|
||||
kpush $31
|
||||
|
||||
.set noreorder
|
||||
# # Get BadVAddr
|
||||
# mfc0 $10, $8
|
||||
# kpush $10
|
||||
# # Get Status
|
||||
# mfc0 $10, $12
|
||||
# kpush $10
|
||||
# # Get Cause
|
||||
# mfc0 $10, $13
|
||||
# kpush $10
|
||||
# srl $10, 29
|
||||
# andi $11, $10, 4
|
||||
# # Get EPC
|
||||
# mfc0 $10, $14
|
||||
# kpush $10
|
||||
#
|
||||
# # Get real EPC
|
||||
# addu $10, $11
|
||||
# kpush $10
|
||||
#
|
||||
# # set uart
|
||||
# la $26, sys_uart_baud
|
||||
# addiu $27, $0, baudrate
|
||||
# sb $27, 0($26)
|
||||
#
|
||||
# # Print CRLF
|
||||
# la $11, _k_crlf
|
||||
# jal _kputs
|
||||
# nop
|
||||
#
|
||||
# # Print real EPC
|
||||
# la $11, _k_msg1
|
||||
# jal _kputs
|
||||
# nop
|
||||
# kpop $10
|
||||
# jal _kprint_word
|
||||
# nop
|
||||
# la $11, _k_crlf
|
||||
# jal _kputs
|
||||
# nop
|
||||
#
|
||||
# # Print EPC
|
||||
# la $11, _k_msg2
|
||||
# jal _kputs
|
||||
# nop
|
||||
# kpop $10
|
||||
# jal _kprint_word
|
||||
# nop
|
||||
# la $11, _k_crlf
|
||||
# jal _kputs
|
||||
# nop
|
||||
#
|
||||
# # Print Cause
|
||||
# la $11, _k_msg3
|
||||
# jal _kputs
|
||||
# nop
|
||||
# kpop $10
|
||||
# jal _kprint_word
|
||||
# nop
|
||||
# la $11, _k_crlf
|
||||
# jal _kputs
|
||||
# nop
|
||||
#
|
||||
# # Print Status
|
||||
# la $11, _k_msg4
|
||||
# jal _kputs
|
||||
# nop
|
||||
# kpop $10
|
||||
# jal _kprint_word
|
||||
# nop
|
||||
# la $11, _k_crlf
|
||||
# jal _kputs
|
||||
# nop
|
||||
#
|
||||
# # Print BadVAddr
|
||||
# la $11, _k_msg5
|
||||
# jal _kputs
|
||||
# nop
|
||||
# kpop $10
|
||||
# jal _kprint_word
|
||||
# nop
|
||||
# la $11, _k_crlf
|
||||
# jal _kputs
|
||||
# nop
|
||||
#
|
||||
# Set Error LED and ExcCode LEDs
|
||||
# Get Cause
|
||||
# mfc0 $26, $13
|
||||
# la $27, sys_led_port
|
||||
# srl $26, 2
|
||||
# andi $26, 0x000F
|
||||
# or $26, $27
|
||||
# sw $26, 0($27)
|
||||
|
||||
# wait for all interrupts = 0
|
||||
#$w4x: mfc0 $26, $13
|
||||
# mfc0 $27, $12
|
||||
# srl $26, 8
|
||||
# srl $27, 8
|
||||
# and $26, $27
|
||||
# bnez $26, $w4x
|
||||
|
||||
# Get return address
|
||||
mfc0 $26, $14
|
||||
|
||||
$no_int: kpop $31
|
||||
kpop $12
|
||||
kpop $11
|
||||
kpop $10
|
||||
kpop $9
|
||||
kpop $8
|
||||
lw $sp, _k_stack
|
||||
|
||||
# Return
|
||||
jr $26
|
||||
rfe
|
||||
.set reorder
|
||||
|
||||
# word = $10
|
||||
_kprint_word:
|
||||
.set noreorder
|
||||
kpush $31
|
||||
kpush $10
|
||||
srl $10, 16
|
||||
jal _kprint_halfword
|
||||
nop
|
||||
kpop $10
|
||||
jal _kprint_halfword
|
||||
nop
|
||||
kpop $31
|
||||
jr $31
|
||||
nop
|
||||
.set noreorder
|
||||
|
||||
# halfword = $10
|
||||
_kprint_halfword:
|
||||
.set noreorder
|
||||
kpush $31
|
||||
kpush $10
|
||||
srl $10, 8
|
||||
jal _kprint_byte
|
||||
nop
|
||||
kpop $10
|
||||
jal _kprint_byte
|
||||
nop
|
||||
kpop $31
|
||||
jr $31
|
||||
nop
|
||||
.set noreorder
|
||||
|
||||
# byte = $10
|
||||
_kprint_byte:
|
||||
.set noreorder
|
||||
kpush $31
|
||||
kpush $10
|
||||
srl $10, 4
|
||||
jal _kprint_nibble
|
||||
nop
|
||||
kpop $10
|
||||
jal _kprint_nibble
|
||||
nop
|
||||
kpop $31
|
||||
jr $31
|
||||
nop
|
||||
.set noreorder
|
||||
|
||||
_kprint_nibble:
|
||||
.set noreorder
|
||||
kpush $31
|
||||
kpush $10
|
||||
la $12, _k_hextbl
|
||||
andi $10, 0xF
|
||||
addu $12, $10
|
||||
lbu $10, 0($12)
|
||||
jal _ksaus
|
||||
nop
|
||||
kpop $10
|
||||
kpop $31
|
||||
jr $31
|
||||
nop
|
||||
.set noreorder
|
||||
|
||||
# char = $10
|
||||
_ksaus:
|
||||
.set noreorder
|
||||
la $8, sys_uart_stat
|
||||
lbu $8, 0($8)
|
||||
la $9, sys_uart_data
|
||||
andi $8, 0x02
|
||||
bnez $8, _ksaus
|
||||
nop
|
||||
j $31
|
||||
sb $10, 0($9)
|
||||
.set reorder
|
||||
|
||||
_kputs:
|
||||
.set noreorder
|
||||
kpush $11
|
||||
kpush $31
|
||||
$kpl: lbu $10, 0($11)
|
||||
addiu $11, 1
|
||||
blez $10, $kpex
|
||||
nop
|
||||
jal _ksaus
|
||||
nop
|
||||
j $kpl
|
||||
nop
|
||||
$kpex: kpop $31
|
||||
kpop $11
|
||||
jr $31
|
||||
nop
|
||||
.set reorder
|
||||
|
||||
@@ -1,251 +0,0 @@
|
||||
/* life.c - demonstrator for later Mips+LCD game of life
|
||||
*
|
||||
* 23.03.06 - MACRO-based version
|
||||
* 22.02.06 - new file
|
||||
*/
|
||||
|
||||
//#include "ks0108.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libsys.h"
|
||||
|
||||
|
||||
#define NX 200 // 70 // 128 // 48 // 128
|
||||
#define NY 150 // 31 // 64 // 27 // 64
|
||||
|
||||
#define SCREEN_X 800
|
||||
#define SCREEN_Y 600
|
||||
|
||||
#define SCALE_X (4)
|
||||
#define SCALE_Y (4)
|
||||
#define OFFSET_X ((SCREEN_X-(SCALE_X*NX))/2)
|
||||
#define OFFSET_Y ((SCREEN_Y-(SCALE_Y*NY))/2)
|
||||
|
||||
// OCCUPIED must be uneven, EMPTY even.
|
||||
#define OCCUPIED 0x77771111
|
||||
#define EMPTY 0xeeee0000
|
||||
|
||||
#define MATRIX( row, col ) (*(matrix + (NX*col) + row ))
|
||||
#define FUTURE( row, col ) (*(future + (NX*col) + row ))
|
||||
|
||||
UINT32 *g_gx_buff;
|
||||
|
||||
int clock_lfsr32()
|
||||
{
|
||||
return rand();
|
||||
}
|
||||
|
||||
|
||||
/* return a pseudo-random integer in the range 0..1023 */
|
||||
int random1023() {
|
||||
int tmp;
|
||||
|
||||
tmp = clock_lfsr32();
|
||||
return tmp & 0x000003ff;
|
||||
}
|
||||
|
||||
typedef struct _scolor_t
|
||||
{
|
||||
UINT8 r, g, b, a;
|
||||
} __attribute__ ((__packed__)) color_t;
|
||||
|
||||
|
||||
void DrawPixel(UINT32 x, UINT32 y, color_t *pColor)
|
||||
{
|
||||
int i, j;
|
||||
for (i=0; i < SCALE_Y; i++)
|
||||
for (j=0; j < SCALE_X; j++)
|
||||
g_gx_buff[(OFFSET_X+SCALE_X*x+j) + SCREEN_X*(OFFSET_Y+SCALE_Y*y+i)] = *((UINT32*)pColor);
|
||||
}
|
||||
|
||||
|
||||
/* MSB/LSB in y-Richtung vertauscht */
|
||||
void displayBoard1( int* matrix )
|
||||
{
|
||||
int x, y;
|
||||
int mask, accu;
|
||||
UINT32 color;
|
||||
|
||||
for( x=0; x < NX; x++ )
|
||||
{
|
||||
mask = 0x80;
|
||||
accu = 0x00;
|
||||
for( y=0; y < NY; y++ )
|
||||
{
|
||||
color = (UINT32)-(MATRIX(x,y) & 0x1);
|
||||
DrawPixel(x, y, (color_t*)&color);
|
||||
// if (MATRIX( x, y ) != OCCUPIED)
|
||||
// {
|
||||
// accu |= mask;
|
||||
// }
|
||||
// mask = mask >> 1;
|
||||
|
||||
// color = 0;
|
||||
// DrawPixel(x, (y>>3), (color_t*)&color);
|
||||
// if (mask == 0)
|
||||
// {
|
||||
// color = accu;
|
||||
// DrawPixel(x, (y>>3), (color_t*)&color);
|
||||
// mask = 0x80;
|
||||
// accu = 0x00;
|
||||
// }
|
||||
}
|
||||
// color = accu;
|
||||
// DrawPixel(x, (y>>3), (color_t*)&color);
|
||||
|
||||
}
|
||||
// *(matrix-15) = 0xdead0000;
|
||||
// *(matrix-16) = *(matrix-16) + 1;
|
||||
}
|
||||
|
||||
void initializeBoard( int* matrix ) {
|
||||
int x, y;
|
||||
for( x=0; x < NX; x++ ) {
|
||||
for( y=0; y < NY; y++ ) {
|
||||
int d = random1023();
|
||||
if (d > 920) MATRIX( x, y ) = OCCUPIED;
|
||||
else MATRIX( x, y ) = EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int countNeighbors( int* matrix, int i, int j ) {
|
||||
int im = i-1;
|
||||
int ip = i+1;
|
||||
|
||||
int jm = j-1;
|
||||
int jp = j+1;
|
||||
|
||||
int n = 0;
|
||||
// wrap-around
|
||||
if (ip >= NX) ip = 0;
|
||||
if (jp >= NY) jp = 0;
|
||||
|
||||
if (im < 0) im = NX-1;
|
||||
if (jm < 0) jm = NY-1;
|
||||
|
||||
// check eight neighbors
|
||||
n += MATRIX(im, jm ) & 0x1; // nw
|
||||
n += MATRIX(im, j ) & 0x1; // west
|
||||
n += MATRIX(im, jp ) & 0x1; // sw
|
||||
|
||||
n += MATRIX(i, jm ) & 0x1; // north
|
||||
// n += MATRIX(i, j ) & 0x1; // center
|
||||
n += MATRIX(i, jp ) & 0x1; // south
|
||||
|
||||
n += MATRIX(ip, jm ) & 0x1; // ne
|
||||
n += MATRIX(ip, j ) & 0x1; // east
|
||||
n += MATRIX(ip, jp ) & 0x1; // se
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* the actual game of life algorithm: cell is born when three neighbors,
|
||||
* survives when exactly two live neighbors, dies otherwise.
|
||||
*/
|
||||
void nextGeneration( int* matrix, int* future ) {
|
||||
int i, j;
|
||||
int lifes = 0;
|
||||
|
||||
for( i=0; i < NX; i++ ) {
|
||||
for( j=0; j < NY; j++ ) {
|
||||
// count neighbors
|
||||
int n = countNeighbors( matrix, i, j );
|
||||
|
||||
//if ((n != 0) && (random1023() > 990)) { // some slight random offset
|
||||
// if (random1023() > 500) FUTURE(i,j) = OCCUPIED;
|
||||
// else FUTURE(i,j) = EMPTY;
|
||||
//}
|
||||
// else if (n == 3) FUTURE(i,j) = OCCUPIED;
|
||||
|
||||
if (n == 3) FUTURE(i,j) = OCCUPIED;
|
||||
else if ((n == 2) && (MATRIX(i,j) == OCCUPIED)) FUTURE(i,j) = OCCUPIED;
|
||||
else FUTURE(i,j) = EMPTY;
|
||||
|
||||
if (FUTURE(i,j) == OCCUPIED) lifes++;
|
||||
}
|
||||
}
|
||||
// generation ++;
|
||||
|
||||
// avoid extinction :-)
|
||||
if (lifes < 10) {
|
||||
// printf( "CREATING A NEW POPULATION\n\n\n" );
|
||||
initializeBoard( matrix );
|
||||
}
|
||||
else { // swap buffers: C PROHIBITS ASSIGNING TO ARRAY TYPES
|
||||
for( i=0; i < NX; i++ ) {
|
||||
for( j=0; j < NY; j++ ) {
|
||||
MATRIX(i,j) = FUTURE(i,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gx_init(void)
|
||||
{
|
||||
volatile UINT32 *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
|
||||
volatile UINT32 *pVGA_front = (UINT32*)SYS_VGA_FB_FRONT;
|
||||
volatile UINT32 *pVGA_back = (UINT32*)SYS_VGA_FB_BACK;
|
||||
|
||||
sleep(500);
|
||||
|
||||
g_gx_buff = (UINT32*)malloc(SCREEN_X*SCREEN_Y*sizeof(UINT32));
|
||||
memset(g_gx_buff, 0, SCREEN_X*SCREEN_Y*sizeof(UINT32));
|
||||
printf("g_gx_buff : %8.8X\n", (UINT32)g_gx_buff);
|
||||
|
||||
*pVGA_ctrl |= SYS_VGA_BIT_MSTEN;
|
||||
*pVGA_front = (UINT32)g_gx_buff;
|
||||
*pVGA_back = (UINT32)g_gx_buff;
|
||||
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
|
||||
int* ptr, cnt = 0;
|
||||
|
||||
int* matrix;
|
||||
int* future;
|
||||
volatile UINT32 *pBtn = (UINT32*)SYS_GPIO0;
|
||||
|
||||
// lcdEnableDisplay( 1 );
|
||||
// lcdSetColor( 1 );
|
||||
// lcdSetPixel( 0, 0 );
|
||||
// lcdSetPixel( 3, 5 );
|
||||
|
||||
// if we have stdlib:
|
||||
matrix = (void*) malloc( NX*NY*sizeof(int) );
|
||||
future = (void*) malloc( NX*NY*sizeof(int) );
|
||||
|
||||
|
||||
gx_init();
|
||||
|
||||
// matrix = (void *) 0x00004000;
|
||||
// future = (void *) 0x00014000;
|
||||
|
||||
// init_lfsr32( 0xcafebabe );
|
||||
// init_lfsr32( 0x13 );
|
||||
|
||||
srand(clock());
|
||||
initializeBoard( matrix );
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
|
||||
if (*pBtn)
|
||||
{
|
||||
srand(clock());
|
||||
initializeBoard( matrix );
|
||||
cnt = 0;
|
||||
}
|
||||
sputs("Generation #"); print_word(cnt++); sputs("\n");
|
||||
displayBoard1( matrix );
|
||||
nextGeneration( matrix, future );
|
||||
}
|
||||
|
||||
// return 0
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
/* Script for -z combreloc: combine and sort reloc sections */
|
||||
OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips",
|
||||
"elf32-littlemips")
|
||||
OUTPUT_ARCH(mips)
|
||||
ENTRY(_start)
|
||||
SEARCH_DIR(".");
|
||||
SEARCH_DIR("/usr/local/mipsel-elf/lib:/usr/local/mipsel-elf/lib/eb");
|
||||
SEARCH_DIR("/usr/local/lib/gcc/mipsel-elf/4.3.3:/usr/local/lib/gcc/mipsel-elf/4.3.3/eb");
|
||||
|
||||
stack_ptr = 0x7FFFEFF0;
|
||||
baudrate = 0x0D;
|
||||
sys_led_port = 0xA0000000;
|
||||
sys_uart_data = 0xA0010000;
|
||||
sys_uart_stat = 0xA0010004;
|
||||
sys_uart_baud = 0xA0010008;
|
||||
sys_timer_usec = 0xA000008;
|
||||
sys_timer_sec = 0xA000000C;
|
||||
|
||||
STARTUP(startup.o)
|
||||
INPUT(kernel.o)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* Read-only sections, merged into text segment: */
|
||||
PROVIDE (__executable_start = 0x40000000); . = 0x40000000;
|
||||
.start __executable_start :
|
||||
{
|
||||
start = ALIGN(2);
|
||||
entry = ALIGN(2);
|
||||
_entry = ALIGN(2);
|
||||
__entry = ALIGN(2);
|
||||
*(.start)
|
||||
}
|
||||
/* Kernel text with low-level exception handler */
|
||||
.exc_vector __executable_start + 0x080 :
|
||||
{
|
||||
_exc_vect_start = .;
|
||||
*(.exc_vect)
|
||||
_exc_vect_end = .;
|
||||
}
|
||||
.init :
|
||||
{
|
||||
KEEP (*(.init))
|
||||
} =0
|
||||
.plt : { *(.plt) }
|
||||
.text :
|
||||
{
|
||||
_ftext = . ;
|
||||
*(.text .stub .text.* .gnu.linkonce.t.*)
|
||||
/* .gnu.warning sections are handled specially by elf32.em. */
|
||||
*(.gnu.warning)
|
||||
*(.mips16.fn.*) *(.mips16.call.*)
|
||||
} =0
|
||||
.fini :
|
||||
{
|
||||
KEEP (*(.fini))
|
||||
} =0
|
||||
PROVIDE (__etext = .);
|
||||
PROVIDE (_etext = .);
|
||||
PROVIDE (etext = .);
|
||||
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
|
||||
.rodata1 : { *(.rodata1) }
|
||||
.sdata2 :
|
||||
{
|
||||
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
|
||||
}
|
||||
.sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
|
||||
.eh_frame_hdr : { *(.eh_frame_hdr) }
|
||||
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
|
||||
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
|
||||
/* Adjust the address for the data segment. We want to adjust up to
|
||||
the same address within the page on the next page up. */
|
||||
. = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
|
||||
/* Exception handling */
|
||||
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
|
||||
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
|
||||
/* Thread Local Storage sections */
|
||||
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
|
||||
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
}
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
}
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
}
|
||||
.ctors :
|
||||
{
|
||||
/* gcc uses crtbegin.o to find the start of
|
||||
the constructors, so we make sure it is
|
||||
first. Because this is a wildcard, it
|
||||
doesn't matter if the user does not
|
||||
actually link against crtbegin.o; the
|
||||
linker won't look for a file to match a
|
||||
wildcard. The wildcard also means that it
|
||||
doesn't matter which directory crtbegin.o
|
||||
is in. */
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*crtbegin?.o(.ctors))
|
||||
/* We don't want to include the .ctor section from
|
||||
the crtend.o file until after the sorted ctors.
|
||||
The .ctor section from the crtend file contains the
|
||||
end of ctors marker and it must be last */
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
}
|
||||
.dtors :
|
||||
{
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*crtbegin?.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
}
|
||||
.jcr : { KEEP (*(.jcr)) }
|
||||
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
|
||||
. = DATA_SEGMENT_RELRO_END (0, .);
|
||||
.data :
|
||||
{
|
||||
_fdata = . ;
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
SORT(CONSTRUCTORS)
|
||||
}
|
||||
.data1 : { *(.data1) }
|
||||
.got.plt : { *(.got.plt) }
|
||||
. = .;
|
||||
_gp = ALIGN(16) + 0x7ff0;
|
||||
.got : { *(.got) }
|
||||
/* We want the small data sections together, so single-instruction offsets
|
||||
can access them all, and initialized data all before uninitialized, so
|
||||
we can shorten the on-disk segment size. */
|
||||
.sdata :
|
||||
{
|
||||
*(.sdata .sdata.* .gnu.linkonce.s.*)
|
||||
}
|
||||
.lit8 : { *(.lit8) }
|
||||
.lit4 : { *(.lit4) }
|
||||
_edata = .; PROVIDE (edata = .);
|
||||
__bss_start = .;
|
||||
_fbss = .;
|
||||
.sbss :
|
||||
{
|
||||
*(.dynsbss)
|
||||
*(.sbss .sbss.* .gnu.linkonce.sb.*)
|
||||
*(.scommon)
|
||||
}
|
||||
.bss :
|
||||
{
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
/* Align here to ensure that the .bss section occupies space up to
|
||||
_end. Align after .bss to ensure correct alignment even if the
|
||||
.bss section disappears because there are no input sections.
|
||||
FIXME: Why do we need it? When there is no .bss section, we don't
|
||||
pad the .data section. */
|
||||
. = ALIGN(. != 0 ? 32 / 8 : 1);
|
||||
}
|
||||
. = ALIGN(32 / 8);
|
||||
. = ALIGN(32 / 8);
|
||||
_end = .; PROVIDE (end = .);
|
||||
. = DATA_SEGMENT_END (.);
|
||||
/* Stabs debugging sections. */
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.comment 0 : { *(.comment) }
|
||||
/* DWARF debug sections.
|
||||
Symbols in the DWARF debugging sections are relative to the beginning
|
||||
of the section so we begin them at 0. */
|
||||
/* DWARF 1 */
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
/* GNU DWARF 1 extensions */
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
/* DWARF 1.1 and DWARF 2 */
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
/* DWARF 2 */
|
||||
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
/* SGI/MIPS DWARF 2 extensions */
|
||||
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
/* DWARF 3 */
|
||||
.debug_pubtypes 0 : { *(.debug_pubtypes) }
|
||||
.debug_ranges 0 : { *(.debug_ranges) }
|
||||
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
|
||||
.gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
|
||||
.gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
|
||||
.mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }
|
||||
.mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }
|
||||
.mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }
|
||||
.mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }
|
||||
.mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }
|
||||
.mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }
|
||||
.gcc_compiled_long32 : { KEEP(*(.gcc_compiled_long32)) }
|
||||
.gcc_compiled_long64 : { KEEP(*(.gcc_compiled_long64)) }
|
||||
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,298 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "libsys.h"
|
||||
|
||||
struct substantive
|
||||
{
|
||||
char *subst;
|
||||
int sex;
|
||||
};
|
||||
|
||||
struct verben
|
||||
{
|
||||
char *verb_k;
|
||||
char *verb_gr;
|
||||
int art;
|
||||
};
|
||||
|
||||
struct adjektive
|
||||
{
|
||||
char *adj;
|
||||
};
|
||||
|
||||
char *art[4]={"er","ie","as","en"};
|
||||
|
||||
char getch(void)
|
||||
{
|
||||
return _getchar();
|
||||
}
|
||||
|
||||
void randomize(void)
|
||||
{
|
||||
srand(clock());
|
||||
}
|
||||
|
||||
struct substantive namen[]=
|
||||
{
|
||||
{"Gerhard Schröder",1},{"Helmut Kohl",1},{"Rudolf Scharping",1},
|
||||
{"Claudia Nolte",2}, {"Johannes Rau",1},{"Wolfgang Schäuble",1},
|
||||
{"Joschka Fischer",1},{"Toni Blair",1},{"Kleopatra",2},
|
||||
{"Claudia Schiffer",2},{"Hannelore Kohl",2},{"Konrad Adenauer",1},
|
||||
{"Michael Jackson",1},{"Karl Marx",1}, {"Helmut Kohl",1},{"Heino",1},
|
||||
{"Gerhard Schröder",1},{"Donald Duck",1},{"Madonna",2},{"Jesus",1},
|
||||
{"Gott",1},{"Sheryl Crow",2},{"Verona Feldbusch",2},{"Pipi Langstrumpf",2},
|
||||
{"Bill Gates",1},{"Bill Clinton",1},{"Cleopatra",2},{"Winnetou",1},
|
||||
{"Käpt'n Blaubär",1},{"Rita Süssmuth",2},{"Boris Becker",1},
|
||||
{"Lilo Wanders",2},{"Queen Elizabeth",2},{"Lady Di",2},{"Steffi Graf",2},
|
||||
{"Frank Zappa",1},{"Dolly Buster",2},{"Mao Tse Tung",1},{"Ghandi",1},
|
||||
{"Dalai Lama",1},{"Teufel",1},{"Lenin",1},{"Edmund Stoiber",1},
|
||||
{"Ludwig van Beethoven",1},{"Wolfgang Amadeus Mozart",1},
|
||||
{"Richard Wagner",1},{"Erich Honecker",1},{"Adam Riese",1},
|
||||
{"Bill Clinton",1},{"Josef Stalin",1},{"Willy Brandt",1},
|
||||
{"John F. Kennedy",1},{"E.T.",1},{"Donald Duck",1},{"Lothar Matthäus",1},
|
||||
{"Hans Dietrich Genscher",1},{"Franz Josef Strauss",1},{"Sting",1},
|
||||
{"Hermann Hesse",1},{"Albert Einstein",1},{"Max Planck",1},
|
||||
{"Tom Jones",1},{"Heidi Kabel",2},{"Homer Simpson",1},{"Zeus",1},
|
||||
{"Helmut Schmidt",1},{"Antje Vollmer",2},{"Politiker",1},{"Papst",1},
|
||||
{"Bundeskanzler",1},{"Arzt",1},{"Friseuse",2},{"Teufel",1},
|
||||
{"Sandmännchen",3},{"Mutter",2},{"Vater",1},{"Säufer",1},{"Student",1},
|
||||
{"Bauer",1},{"Leiche",2},{"Polizist",1},{"Patientin",2},{"Bäcker",1},
|
||||
{"Wirt",1}, {"Schlachter",1},{"Baby",3},{"Reporter",1},{"Politiker",1},
|
||||
{"Beamtin",2},{"Oma",2},{"Putzfrau",2},{"Blinde",2},{"Wahnsinnige",2},
|
||||
{"Mörder",1},{"Psychiater",1},{"Prinz Charles",1},{"Onkel",1},{"Tante",2}
|
||||
};
|
||||
|
||||
struct substantive sachen[]=
|
||||
{
|
||||
{"Haus",3},{"Buch",3},{"Fahrrad",3},{"Schule",2},{"Auto",3},{"Nase",2},
|
||||
{"Mund",1},{"Kopf",1},{"Kaffee",1},{"Telephon",3},{"Tasse",2},{"Katze",2},
|
||||
{"Hund",1},{"Maus",2},{"Stuhl",1},{"Mann",1},{"Frau",2},{"Kind",3},
|
||||
{"Idiotin",2},{"Lampe",2},{"Panzer",1},{"Klavier",3},{"Gitarre",2},
|
||||
{"Straße",2},{"Wasser",3},{"Luft",2},{"Feuer",3},{"Erde",2},{"Mond",1},
|
||||
{"Sonne",2},{"Bild",3},{"Stadt",2},{"Land",3},{"Fluss",1},
|
||||
{"Bundeskanzler",1},{"Ball",1},{"Hut",1},{"Hose",2},{"Hemd",3},{"Tod",1},
|
||||
{"Geld",3},{"Tisch",1},{"Hand",2},{"Baum",1},{"Bier",3},{"Ratte",2},
|
||||
{"Esel",1},{"Musik",2},{"Blech",3},{"Dose",2},{"Zahn",1},{"Humor",1},
|
||||
{"Unterhose",2},{"Gift",3},{"Gesicht",3},{"Fuß",1},{"Auge",3},{"Warze",2},
|
||||
{"Ohr",3},{"Kanone",2},{"Milch",2},{"Messer",3},{"Papier",3},{"Haar",3},
|
||||
{"Welt",2},{"Motor",1},{"Langeweile",2},{"Grab",3},{"Schnaps",1},
|
||||
{"Vogel",1},{"Fisch",1},{"Meer",3},{"Banane",2},{"Brot",3},
|
||||
{"Sitzung",2},{"Labor",3},{"Kurzschluß",1},{"Lüge",2},{"Axt",2},
|
||||
{"Abstimmung",2},{"Toilette",2},{"Zigarette",2},{"Winter",1},
|
||||
{"Torte",2},{"Bahnhof",1},{"Sarg",1},{"Imbiss",1},{"Mund",1},{"Seife",2},
|
||||
{"Fernseher",1},{"Flasche",2},{"Eimer",1},{"Uhr",2},{"Irrenhaus",3},
|
||||
{"Wüste",2},{"Klumpen",1},{"Glück",3},{"Schiff",3},{"Käse",1},{"Quark",1},
|
||||
{"Sommer",1},{"Witz",1},{"Idee",2},{"Nacht",2},{"Dreck",1},{"Meer",3},
|
||||
{"Blut",3},{"Herz",3},{"Apfel",1},{"Banane",2},{"Mist",1},{"Atom",3},
|
||||
{"Note",2},{"Gehirn",3},{"Gefühl",3},{"Bombe",2},{"Vakuum",3},
|
||||
{"Zahl",2},{"Wort",3},{"Programm",3},{"Computer",1},{"Orient",1},
|
||||
{"Gabelstapler",1}
|
||||
};
|
||||
|
||||
struct adjektive ad[]=
|
||||
{
|
||||
{"schön"},{"doof"},{"gut"},{"schlecht"},{"gelb"},{"grün"},{"rot"},
|
||||
{"blau"},{"schnell"},{"lang"},{"kurz"},{"hell"},{"düster"},{"sanft"},
|
||||
{"hart"},{"langsam"},{"bitter"},{"süß"},{"kaputt"},{"nett"},{"groß"},
|
||||
{"klein"},{"leicht"},{"schwer"},{"dick"},{"dünn"},{"rund"},{"eckig"},
|
||||
{"heiß"},{"kalt"},{"schlau"},{"elektrisch"},{"nass"},{"trocken"},{"ratlos"},
|
||||
{"abartig"},{"genial"},{"bestechlich"},{"irr"},{"steif"},{"angespannt"},
|
||||
{"laut"},{"leis"},{"warm"},{"wütend"},{"sauber"},{"schmutzig"},{"arm"},
|
||||
{"ätzend"},{"langweilig"},{"interessant"},{"erfahren"},{"abgewählt"},
|
||||
{"durchgeknallt"},{"angenehm"},{"widerwärtig"},{"willig"},{"mutig"},
|
||||
{"schwach"},{"stark"},{"nervend"},{"spießig"},{"alt"},{"neu"},{"spitz"},
|
||||
{"stumpf"},{"teuflisch"},{"scharf"},{"lecker"},{"übelriechend"},{"halb"},
|
||||
{"ganz"},{"bleich"},{"peinlich"},{"taktlos"},{"gewieft"},{"windig"},
|
||||
{"größenwahnsinnig"},{"verrückt"},{"uralt"},{"aalglatt"},{"korrekt"},
|
||||
{"kompetent"},{"einfühlsam"},{"tot"},{"schleimig"},{"gestört"},{"hohl"},
|
||||
{"beknackt"},{"nackt"},{"barfüßig"},{"schwitzend"},{"laufend"},{"knackig"},
|
||||
{"unverschämt"},{"schläfrig"},{"wohlgeformt"},{"kugelförmig"},{"rauh"},
|
||||
{"degeneriert"},{"ekelhaft"},{"brutal"},{"gemein"},{"aggressiv"},
|
||||
{"aufdringlich"},{"betroffen"},{"geliebt"},{"gehasst"},{"beharrlich"},
|
||||
{"unmenschlich"},{"verblödet"},{"wichtig"},{"gigantisch"},{"winzig"},
|
||||
{"witzig"},{"komisch"},{"pervers"},{"fett"},{"stinkend"},{"lausig"},
|
||||
{"wendig"},{"breit"},{"locker"},{"einzigartig"},{"sterbend"},{"munter"},
|
||||
{"ungepflegt"},{"eisern"},{"echt"},{"besser"},{"wild"},{"ächzend"},
|
||||
{"frohlockend"},{"unscheinbar"},{"nebulös"},{"skandalös"},{"obzön"},
|
||||
{"beschränkt"},{"genervt"},{"hilflos"},{"unwürdig"},{"geleckt"},
|
||||
{"betrunken"},{"unwürdig"},{"bissig"},{"verkalkt"},{"senil"},
|
||||
{"jungfräulich"},{"ausgeleiert"},{"beleibt"},{"nachtragend"},{"errötend"},
|
||||
{"kahl"},{"würgend"},{"abwesend"},{"ruhig"},{"albern"},{"trostlos"},
|
||||
{"salzig"},{"lachend"},{"merkwürdig"},{"behaart"},{"leblos"},{"aufgeblasen"},
|
||||
{"frech"},{"kopflos"},{"schmierig"}
|
||||
};
|
||||
|
||||
struct verben verb[]=
|
||||
{
|
||||
{"geht","gehen",6},{"steht","stehen",2},{"sitzt","sitzen",2},
|
||||
{"spielt","spielen",7},{"singt","singen",2},{"trinkt","trinken",3},
|
||||
{"redet","reden",2}, {"liebt","lieben",7},{"schläft","schlafen",2},
|
||||
{"ißt","essen",3},{"lacht","lachen",2},{"tötet","töten",7},
|
||||
{"lügt","lügen",2},{"fliegt","fliegen",2},{"überfährt","überfahren",7},
|
||||
{"sieht","sehen",3},{"hört","hören",3},{"spricht","sprechen",2},
|
||||
{"berechnet","rechnen",3},{"schwimmt","schwimmen",2},
|
||||
{"zerschneidet","zerschnitten werden",3},{"raucht","rauchen",3},
|
||||
{"spaltet","spalten",3},{"verbrennt","verbrennen",2},{"ist","sein",2},
|
||||
{"hat","haben",1},{"zerbricht","zerbrechen",3},{"muss","müssen",4},
|
||||
{"kann","können",4},{"darf","dürfen",4},{"will","wollen",5},
|
||||
{"klaut","klauen",1},{"soll","sollen",4},{"studiert","studieren",3},
|
||||
{"reibt","reiben",3},{"liest","lesen",2},{"irrt","irren",2},
|
||||
{"spendiert","spendieren",1},{"schlägt","schlagen",3},{"fragt","fragen",7},
|
||||
{"zerstört","zerstören",1},{"erschießt","sich erschießen",1},
|
||||
{"überlegt","überlegen",2},{"trifft","treffen",7},{"leckt","lecken",1},
|
||||
{"wirft","werfen",1},{"vergiftet","vergiftet werden",1},
|
||||
{"öffnet","öffnen",1},{"schreit","schreien",2},{"sprengt","explodieren",3},
|
||||
{"erwürgt","würgen",7},{"arbeitet","arbeiten",2},{"erlegt","erlegen",1},
|
||||
{"putzt","putzen",1},{"stirbt","sterben",2}, {"kauft","kaufen",1},
|
||||
{"brüllt","brüllen",2},{"versteht","es verstehen",7},
|
||||
{"zertritt","zertreten werden",1},{"verendet","verenden",2},
|
||||
{"labert","labern",2},{"kratzt","kratzen",1},{"wird","nichts werden",2},
|
||||
{"entkleidet","sich entkleiden",7},{"verbiegt","sich verbiegen",1},
|
||||
{"verschenkt","es verschenken",7},{"vergisst","es vergessen",1},
|
||||
{"ergreift","greifen",1},{"baut","bauen",1},{"betet","beten",},
|
||||
{"rollt","rollen",3},{"bleibt","bleiben",2},{"wäscht","sich waschen",1},
|
||||
{"heiratet","heiraten",7},{"hebt","heben",1},{"denkt","nachdenken",2}
|
||||
};
|
||||
|
||||
void end_sach_aus(void);
|
||||
void nam_aus(void);
|
||||
void end_nam_aus(void);
|
||||
void adj_aus(void);
|
||||
int verb_aus_k(void);
|
||||
int verb_aus_gr(void);
|
||||
int zufall(int);
|
||||
|
||||
int main()
|
||||
{
|
||||
int vindx;
|
||||
int rem=0;
|
||||
char end;
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
randomize();
|
||||
printf("\n\t\t************************");
|
||||
printf("\n\t\t* DER ELEKTRISCHE POET *");
|
||||
printf("\n\t\t************************\n");
|
||||
printf("\n\tCopyright by J. Ahrensfeld & T. Burr");
|
||||
printf("\n\n\tFür die Texte ist Ihr Computer verantwortlich :-)\n");
|
||||
printf("\n\tZum beenden des Programmes 'x' eingeben!\n");
|
||||
printf("\n\tWeiter mit beliebiger Taste!\n");
|
||||
end = getch();
|
||||
|
||||
while(end != 'x')
|
||||
{
|
||||
if(rem >= 10)
|
||||
{
|
||||
printf("\n\n\tZum beenden des Programmes 'x' eingeben!\n");
|
||||
rem = 0;
|
||||
if(getch() == 'x')
|
||||
break;
|
||||
}
|
||||
printf("\n\n");
|
||||
nam_aus();
|
||||
|
||||
vindx=verb_aus_k();
|
||||
|
||||
switch (vindx)
|
||||
{
|
||||
case 1: end_sach_aus(); break;
|
||||
|
||||
case 2: adj_aus(); break;
|
||||
|
||||
case 3: end_sach_aus(); break;
|
||||
|
||||
case 4: verb_aus_gr(); break;
|
||||
|
||||
case 5: verb_aus_gr(); break;
|
||||
|
||||
case 6: adj_aus(); break;
|
||||
|
||||
case 7: end_nam_aus(); break;
|
||||
}
|
||||
|
||||
printf(".");
|
||||
end = getch();
|
||||
rem++;
|
||||
|
||||
}
|
||||
printf("\n\n\tDas ist das Ende!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zufall(int max)
|
||||
{
|
||||
|
||||
return (rand()%max);
|
||||
}
|
||||
|
||||
void adj_aus(void)
|
||||
{
|
||||
printf("%s", ad[zufall((sizeof(ad)/sizeof(*ad)))].adj);
|
||||
return;
|
||||
}
|
||||
|
||||
void end_sach_aus(void)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = zufall(sizeof(sachen)/sizeof(*sachen));
|
||||
if (sachen[index].sex==1)
|
||||
printf("d%s", art[3]);
|
||||
else
|
||||
printf("d%s", art[(sachen[index].sex)-1]);
|
||||
printf(" ");
|
||||
adj_aus();
|
||||
if (sachen[index].sex==1)
|
||||
printf("en %s", sachen[index].subst);
|
||||
else
|
||||
printf("e %s", sachen[index].subst);
|
||||
return;
|
||||
}
|
||||
|
||||
void nam_aus(void)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = zufall(sizeof(namen)/sizeof(*namen));
|
||||
printf("D%s", art[(namen[index].sex)-1]);
|
||||
printf(" ");
|
||||
adj_aus();
|
||||
printf("e %s " ,namen[index].subst);
|
||||
return;
|
||||
}
|
||||
|
||||
void end_nam_aus(void)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = zufall(sizeof(namen)/sizeof(*namen));
|
||||
if (namen[index].sex==1)
|
||||
printf("d%s", art[3]);
|
||||
else
|
||||
printf("d%s", art[(namen[index].sex)-1]);
|
||||
printf(" ");
|
||||
adj_aus();
|
||||
if (namen[index].sex==1)
|
||||
printf("en %s", namen[index].subst);
|
||||
else
|
||||
printf("e %s", namen[index].subst);
|
||||
return;
|
||||
}
|
||||
|
||||
int verb_aus_k(void)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = zufall(sizeof(verb)/sizeof(*verb));
|
||||
printf("%s ", verb[index].verb_k);
|
||||
return (verb[index].art);
|
||||
}
|
||||
|
||||
int verb_aus_gr(void)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = zufall(sizeof(verb)/sizeof(*verb));
|
||||
printf("%s", verb[index].verb_gr);
|
||||
return index;
|
||||
}
|
||||
@@ -1,856 +0,0 @@
|
||||
/*
|
||||
** Queens.c -- Find solutions to the Eight-Queens chess problem.
|
||||
** Roberto Sierra 7/25/93 Version 1.1
|
||||
** 3/19/84 Version 1.0
|
||||
**
|
||||
** Description:
|
||||
** This program finds all the possible ways that N queens can
|
||||
** be placed on an NxN chessboard so that the queens cannot
|
||||
** capture one another -- that is, so that no rank, file or
|
||||
** diagonal is occupied by more than one queen. By default,
|
||||
** the program prints the first solution it finds. You can
|
||||
** use the -a option to print all solutions, or the -c option
|
||||
** just to count them. The program allows the chess board
|
||||
** to be from 1x1 (trivial case) to 100x100. Warning: the
|
||||
** larger the chess board, the longer it typically takes to
|
||||
** find each solution, even though there may be more of them.
|
||||
**
|
||||
** This is a terrific example of the utility of recursion. The
|
||||
** algorithm uses recursion to drastically limit the number
|
||||
** of board positions that are tested. The program is able
|
||||
** to find all 8x8 queen solutions in a fraction of a second
|
||||
** (not counting print time). The code makes no attempt to
|
||||
** eliminate symmetrical solutions, so the number of solutions
|
||||
** reported will always be higher than the actual number of
|
||||
** distinct solutions.
|
||||
**
|
||||
**
|
||||
** Usage:
|
||||
** Queens [-ac] n
|
||||
**
|
||||
** n number of queens (rows and columns).
|
||||
** An integer from 1 to 100.
|
||||
** -a Find (and print) all solutions.
|
||||
** -c Count all solutions, but do not print them.
|
||||
**
|
||||
** The output is sent to stdout. All errors messages are
|
||||
** sent to stderr. If a problem arises, the return code is -1.
|
||||
**
|
||||
**
|
||||
** Examples:
|
||||
**
|
||||
** Queens 8 ## Show an 8x8 solution
|
||||
** 8 queens on a 8x8 board...
|
||||
** Q - - - - - - -
|
||||
** - - - - Q - - -
|
||||
** - - - - - - - Q
|
||||
** - - - - - Q - -
|
||||
** - - Q - - - - -
|
||||
** - - - - - - Q -
|
||||
** - Q - - - - - -
|
||||
** - - - Q - - - -
|
||||
**
|
||||
** Queens -c 8 ## Count all 8x8 solutions
|
||||
** 8 queens on a 8x8 board...
|
||||
** ...there are 92 solutions.
|
||||
**
|
||||
** Queens -a 4 ## Show all 4x4 solutions
|
||||
** 4 queens on a 4x4 board...
|
||||
**
|
||||
** Solution #1:
|
||||
** - Q - -
|
||||
** - - - Q
|
||||
** Q - - -
|
||||
** - - Q -
|
||||
**
|
||||
** Solution #2:
|
||||
** - - Q -
|
||||
** Q - - -
|
||||
** - - - Q
|
||||
** - Q - -
|
||||
**
|
||||
** ...there are 2 solutions.
|
||||
**
|
||||
**
|
||||
** Build Instructions:
|
||||
** You'll need an ANSI C compiler (or the willingness to edit
|
||||
** the program a bit). If you've got Gnu C, then you can
|
||||
** compile and load the program as follows:
|
||||
**
|
||||
** gcc Queens.c -ansi -o Queens
|
||||
**
|
||||
** [If you're using MPW on the Mac, define '-d MPW' on the
|
||||
** compile line so that background processing will occur.]
|
||||
**
|
||||
**
|
||||
** Algorithm:
|
||||
** In a 1984 Byte article, I ran across an interesting letter
|
||||
** from a high school student who was attempting to solve the
|
||||
** Eight Queens problem using a BASIC interpreter. He had
|
||||
** developed a program which placed eight queens successively
|
||||
** on all sixty-four squares, testing for conflicts at each
|
||||
** iteration. Of course, such a program would require 64^8
|
||||
** iterations (about 2.8x10^14 iterations). Even in C on a,
|
||||
** fast CPU, this could take months or years. Byte's answer was
|
||||
** to alter the loops so that the queens resided on separate
|
||||
** ranks, thereby reducing the number of iterations required
|
||||
** to find all solutions to 8^8 iterations (about 16 million).
|
||||
** More reasonable, but still requiring a chunk of CPU time.
|
||||
**
|
||||
** I puzzled about this problem a bit, and came to realize that
|
||||
** this was still wasting a lot of CPU cycles. Though I'm sure
|
||||
** others have come up with good algorithms, I decided to come
|
||||
** up with my own, with a particular eye on efficiency. The
|
||||
** resulting algorithm finds all 8x8 solutions in a fraction
|
||||
** of a second (there are 92 solutions, including rotations).
|
||||
** On a Sun 4, it'll find all 365,596 solutions on a 14x14 board
|
||||
** in a bit over 2 minutes (printing them out requires extra
|
||||
** time, of course). Even Byte's solution would require 14^14
|
||||
** iterations (about 10^16) which would take aeons.
|
||||
**
|
||||
** My algorithm works as follows:
|
||||
** (1) Place a queen in the top left corner.
|
||||
** (2) Place another queen immediately below.
|
||||
** (3) Test for conflicts. If the second queen conflicts (it
|
||||
** does at first), then move it one square to the right.
|
||||
** (4) Loop step 3 until there are no conflicts. Place
|
||||
** the next queen on the board and recurse.
|
||||
** (5) If any queen reaches the right edge of the board,
|
||||
** remove it and 'pop' to the previous recursion level.
|
||||
** (6) Now repeat these steps recursively until all eight
|
||||
** queens (or however many) have been placed without
|
||||
** conflict -- the result is a solution to the problem,
|
||||
** which is counted and optionally printed.
|
||||
**
|
||||
** Because conflicts are tested as the recursion proceeds,
|
||||
** this has the effect of 'pruning' the recursion so that
|
||||
** a large number of board positions are not even attempted.
|
||||
** The result is that the algorithm runs in reasonable time.
|
||||
**
|
||||
** I used a few tricks to make the test-for-conflict code
|
||||
** extremely efficient -- there is no 'inner' loop to search
|
||||
** along ranks, files, or diagonals. A series of arrays are
|
||||
** maintained instead which indicate which queen currently
|
||||
** 'owns' each rank, file or diagonal. This makes the
|
||||
** algorithm really fly, though the code is a little hard to
|
||||
** read. Lastly, pointer arithmetic is used to reduce the
|
||||
** number of implicit multiplications used in array addressing.
|
||||
**
|
||||
**
|
||||
** Contact:
|
||||
** For queries regarding this program, contact Roberto Sierra
|
||||
** at any of the following addresses:
|
||||
**
|
||||
** Roberto Sierra
|
||||
** bert@netcom.com (preferred address)
|
||||
** 73557.2101@compuserve.com
|
||||
**
|
||||
** Tempered MicroDesigns
|
||||
** P.O. Box 170638
|
||||
** San Francisco, CA 94117
|
||||
**
|
||||
**
|
||||
** Fine Print:
|
||||
** This program is in the public domain and can be used for
|
||||
** any purpose whatsoever, including commercial application.
|
||||
** [I'd like to hear what you do with it, though.]
|
||||
** Absolutely no warranty or liability is implied or extended
|
||||
** by the author.
|
||||
**
|
||||
**
|
||||
** Modification History:
|
||||
** PRS 3/19/84 v1.0 -- Original version.
|
||||
** PRS 7/25/93 v1.1 -- ANSIfied the code. More efficient pointers.
|
||||
**
|
||||
*/
|
||||
|
||||
/***************************************************************/
|
||||
/* Timer options. You MUST uncomment one of the options below */
|
||||
/* or compile, for example, with the '-DUNIX' option. */
|
||||
/***************************************************************/
|
||||
/* #define Amiga */
|
||||
/* #define UNIX */
|
||||
/* #define UNIX_Old */
|
||||
/* #define VMS */
|
||||
/* #define BORLAND_C */
|
||||
/* #define MSC */
|
||||
/* #define MAC */
|
||||
/* #define IPSC */
|
||||
/* #define FORTRAN_SEC */
|
||||
/* #define GTODay */
|
||||
/* #define CTimer */
|
||||
/* #define UXPM */
|
||||
/* #define MAC_TMgr */
|
||||
/* #define PARIX */
|
||||
/* #define POSIX */
|
||||
/* #define WIN32 */
|
||||
/* #define POSIX1 */
|
||||
/***********************/
|
||||
|
||||
#include <stdio.h> /* Need standard I/O functions */
|
||||
#include <stdlib.h> /* Need exit() routine interface */
|
||||
#include <string.h> /* Need strcmp() interface */
|
||||
#ifdef MPW /* Macintosh MPW ONLY */
|
||||
#include <CursorCtl.h> /* Need cursor control interfaces */
|
||||
#endif
|
||||
|
||||
#define MAXQUEENS 100 /* Maximum number of queens */
|
||||
#define MAXRANKS MAXQUEENS /* Maximum number of ranks (rows) */
|
||||
#define MAXFILES MAXQUEENS /* Maximum number of files (columns) */
|
||||
#define MAXDIAGS (MAXRANKS+MAXFILES-1) /* Maximum number of diagonals */
|
||||
#define EMPTY (MAXQUEENS+1) /* Marks unoccupied file or diagonal */
|
||||
|
||||
/* GLOBAL VARIABLES */
|
||||
|
||||
int queens; /* Number of queens to place */
|
||||
int ranks; /* Number of ranks (rows) */
|
||||
int files; /* Number of files (columns) */
|
||||
int printing = 1; /* TRUE if printing positions */
|
||||
int findall = 0; /* TRUE if finding all solutions */
|
||||
|
||||
unsigned long solutions = 0; /* Number of solutions found */
|
||||
int queen[MAXRANKS]; /* File on which each queen is located */
|
||||
int file[MAXFILES]; /* Which queen 'owns' each file */
|
||||
int fordiag[MAXDIAGS]; /* Which queen 'owns' forward diagonals */
|
||||
int bakdiag[MAXDIAGS]; /* Which queen 'owns' reverse diagonals */
|
||||
char *progname = 0; /* The name of this program */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***********************/
|
||||
/**** ROUTINES ****/
|
||||
/***********************/
|
||||
|
||||
/* Internal prototypes */
|
||||
//void main(int argc,char **argv); /* Main program */
|
||||
void find(int level); /* Algorithm to find solutions */
|
||||
void pboard(void); /* Print a solution */
|
||||
void run_queens(int argc,char **argv);
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------- main() ---------------------------
|
||||
** MAIN program. The main purpose of this routine is
|
||||
** to deal with decoding the command line arguments,
|
||||
** initializing the various arrays, and starting the
|
||||
** recursive search routine.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
char *args[] = {"queens", "-c", "12"};
|
||||
run_queens(3, args);
|
||||
}
|
||||
|
||||
void run_queens(int argc,char **argv)
|
||||
{
|
||||
register int i; /* Loop variable */
|
||||
register char *p; /* Pointer to argument */
|
||||
double starttime, benchtime, dtime();
|
||||
|
||||
#ifdef MPW /* Macintosh MPW ONLY */
|
||||
InitCursorCtl(0); /* Enable cursor control */
|
||||
#endif
|
||||
|
||||
progname = argv[0]; /* The name of the program */
|
||||
|
||||
/**** DECODE COMMAND LINE ARGUMENTS ****/
|
||||
|
||||
for (i=1; i<argc; ++i) { /* Scan through arguments */
|
||||
p = argv[i]; /* Pointer to base of argument */
|
||||
if (*p == '-') { /* Command line option? */
|
||||
while (*++p) { /* Loop through characters */
|
||||
switch (*p) { /* What is the character */
|
||||
case 'a': /* '-a' option */
|
||||
findall = 1; /* Set flag to find all solutions */
|
||||
break;
|
||||
case 'c': /* '-c' option */
|
||||
printing = 0; /* Counting, not printing */
|
||||
findall = 1; /* Also forces findall option */
|
||||
break;
|
||||
default: /* Illegal option */
|
||||
fprintf(stderr,"%s: Illegal option '%s'\n",progname,argv[i]);
|
||||
fprintf(stderr,"usage: %s [-ac] queens\n",progname);
|
||||
exit(-1);
|
||||
} /* End of switch */
|
||||
} /* End of loop */
|
||||
} else { /* End of option test */
|
||||
if (sscanf(p,"%d",&queens) != 1) { /* Read integer argument */
|
||||
fprintf(stderr,"%s: non-integer argument '%s'\n",progname,p);
|
||||
exit(-1);
|
||||
}
|
||||
if (queens <= 0) { /* N must be positive */
|
||||
fprintf(stderr,"%s: queens must be positive integer\n",progname);
|
||||
exit(-1);
|
||||
}
|
||||
if (queens > MAXQUEENS) { /* N can't be too large */
|
||||
fprintf(stderr,"%s: can't have more than %d queens\n",
|
||||
progname, MAXQUEENS);
|
||||
exit(-1);
|
||||
}
|
||||
} /* End of argument test */
|
||||
} /* End of argument scan loop */
|
||||
if (queens == 0) {
|
||||
fprintf(stderr,"%s: missing queens argument\n",progname);
|
||||
fprintf(stderr,"usage: %s [-ac] queens\n",progname);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
ranks = files = queens; /* NxN board for N queens */
|
||||
printf("%d queen%s on a %dx%d board...\n",
|
||||
queens, queens>1? "s" : "", ranks, files);
|
||||
fflush(stdout);
|
||||
|
||||
starttime = dtime();
|
||||
|
||||
/* Initialization */
|
||||
solutions = 0; /* No solutions yet */
|
||||
for (i=0; i<MAXFILES; ++i) file[i] = EMPTY;
|
||||
for (i=0; i<MAXDIAGS; ++i) fordiag[i] = bakdiag[i] = EMPTY;
|
||||
|
||||
/* Find all solutions (begin recursion) */
|
||||
find(0);
|
||||
if (printing && solutions) putchar('\n');
|
||||
|
||||
/* Report results */
|
||||
if (solutions == 1) {
|
||||
printf("...there is 1 solution\n");
|
||||
} else {
|
||||
printf("...there are %ld solutions\n", solutions);
|
||||
}
|
||||
|
||||
benchtime = dtime() - starttime;
|
||||
printf("Run Time (sec) = %9.3lf\n\n",benchtime);
|
||||
|
||||
|
||||
exit(0); /* No errors */
|
||||
} /* End of main() */
|
||||
|
||||
|
||||
|
||||
/*-------------------------- find() ----------------------------
|
||||
** FIND is the recursive heart of the program, and finds all
|
||||
** solutions given a set of level-1 fixed queen positions.
|
||||
** The routine moves a single queen through all files (columns)
|
||||
** at the current rank (recursion level). As the queen is moved,
|
||||
** conflict tests are made. If the queen can be placed without
|
||||
** conflict, then the routine recurses to the next level. When
|
||||
** all queens have been placed without conflict, a solution is
|
||||
** counted and reported.
|
||||
*/
|
||||
|
||||
void find(register int level)
|
||||
{
|
||||
register int f; /* Indexes through files */
|
||||
register int *fp,*fdp,*bdp; /* Ptrs to file/diagonal entries */
|
||||
|
||||
#ifdef MPW /* Macintosh MPW ONLY */
|
||||
if (level & 7 == 0) { /* Periodically break for... */
|
||||
SpinCursor(1); /* background processing */
|
||||
}
|
||||
#endif
|
||||
|
||||
if (level == queens) { /* Placed all queens? Stop. */
|
||||
++solutions; /* Congrats, this is a solution! */
|
||||
if (printing) pboard(); /* Print board if printing */
|
||||
if (!findall) exit(0); /* May stop after first solution */
|
||||
#ifdef MPW /* Macintosh MPW ONLY */
|
||||
SpinCursor(1); /* Allow background processing */
|
||||
#endif
|
||||
} else { /* Not at final level yet */
|
||||
|
||||
for ( /* MOVE QUEEN THROUGH ALL FILES */
|
||||
f = 0, /* Queen starts at left (file 0) */
|
||||
fp = file, /* Ptr to base of file array */
|
||||
fdp = &fordiag[level], /* Ptr to first fwd diag entry */
|
||||
bdp = &bakdiag[level+files-1] /* Ptr to first bak diag entry */
|
||||
;
|
||||
f < files /* Loop through all files */
|
||||
;
|
||||
++f, /* Advance index */
|
||||
++fp, ++fdp, --bdp /* Advance pointers */
|
||||
) {
|
||||
if (*fp >= level && /* No queen on the file? */
|
||||
*fdp >= level && *bdp >= level /* No queens on diagonals? */
|
||||
) {
|
||||
queen[level] = f; /* Note new position of queen */
|
||||
*fp = *fdp = *bdp = level; /* Place queen on file & diags */
|
||||
find(level+1); /* This level OK, recurse to next */
|
||||
*fp = *fdp = *bdp = EMPTY; /* Remove queen from file & diags */
|
||||
} /* End of conflict test */
|
||||
} /* End of file loop */
|
||||
} /* End if (level == queens) */
|
||||
} /* End of find() */
|
||||
|
||||
|
||||
|
||||
|
||||
/*------------------------- pboard() -----------------------
|
||||
** This routines prints the board for a particular solution.
|
||||
** The output is sent to stdout.
|
||||
*/
|
||||
|
||||
void pboard(void)
|
||||
{
|
||||
register int i,j; /* Rank/File indices */
|
||||
|
||||
if (findall) { /* Only if searching for all */
|
||||
printf("\nSolution #%lu:\n",solutions); /* Print solution number */
|
||||
}
|
||||
for (i=0; i<ranks; ++i) { /* Loop through all ranks */
|
||||
for (j=0; j<files; ++j) { /* Loop through all files */
|
||||
putchar(' '); /* Output a space */
|
||||
if (j==queen[i]) putchar('Q'); /* Output Q for queen... */
|
||||
else putchar('-'); /* or '-' if empty */
|
||||
}
|
||||
putchar('\n'); /* Break line */
|
||||
}
|
||||
fflush(stdout); /* Flush solution to output */
|
||||
} /* End of pboard() */
|
||||
|
||||
/*****************************************************/
|
||||
/* Various timer routines. */
|
||||
/* Al Aburto, aburto@nosc.mil, 18 Feb 1997 */
|
||||
/* */
|
||||
/* t = dtime() outputs the current time in seconds. */
|
||||
/* Use CAUTION as some of these routines will mess */
|
||||
/* up when timing across the hour mark!!! */
|
||||
/* */
|
||||
/* For timing I use the 'user' time whenever */
|
||||
/* possible. Using 'user+sys' time is a separate */
|
||||
/* issue. */
|
||||
/* */
|
||||
/* Example Usage: */
|
||||
/* [timer options added here] */
|
||||
/* main() */
|
||||
/* { */
|
||||
/* double starttime,benchtime,dtime(); */
|
||||
/* */
|
||||
/* starttime = dtime(); */
|
||||
/* [routine to time] */
|
||||
/* benchtime = dtime() - starttime; */
|
||||
/* } */
|
||||
/* */
|
||||
/* [timer code below added here] */
|
||||
/*****************************************************/
|
||||
|
||||
/*********************************/
|
||||
/* Timer code. */
|
||||
/*********************************/
|
||||
/*******************/
|
||||
/* Amiga dtime() */
|
||||
/*******************/
|
||||
#ifdef Amiga
|
||||
#include <ctype.h>
|
||||
#define HZ 50
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
struct tt
|
||||
{
|
||||
long days;
|
||||
long minutes;
|
||||
long ticks;
|
||||
} tt;
|
||||
|
||||
DateStamp(&tt);
|
||||
|
||||
q = ((double)(tt.ticks + (tt.minutes * 60L * 50L))) / (double)HZ;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************/
|
||||
/* UNIX dtime(). This is the preferred UNIX timer. */
|
||||
/* Provided by: Markku Kolkka, mk59200@cc.tut.fi */
|
||||
/* HP-UX Addition by: Bo Thide', bt@irfu.se */
|
||||
/*****************************************************/
|
||||
#ifdef UNIX
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#ifdef hpux
|
||||
#include <sys/syscall.h>
|
||||
#define getrusage(a,b) syscall(SYS_getrusage,a,b)
|
||||
#endif
|
||||
|
||||
struct rusage rusage;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
getrusage(RUSAGE_SELF,&rusage);
|
||||
|
||||
q = (double)(rusage.ru_utime.tv_sec);
|
||||
q = q + (double)(rusage.ru_utime.tv_usec) * 1.0e-06;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************/
|
||||
/* UNIX_Old dtime(). This is the old UNIX timer. */
|
||||
/* Make sure HZ is properly defined in param.h !! */
|
||||
/***************************************************/
|
||||
#ifdef UNIX_Old
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifndef HZ
|
||||
#define HZ 60
|
||||
#endif
|
||||
|
||||
struct tms tms;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
times(&tms);
|
||||
|
||||
q = (double)(tms.tms_utime) / (double)HZ;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************************************/
|
||||
/* VMS dtime() for VMS systems. */
|
||||
/* Provided by: RAMO@uvphys.phys.UVic.CA */
|
||||
/* Some people have run into problems with this timer. */
|
||||
/*********************************************************/
|
||||
#ifdef VMS
|
||||
#include time
|
||||
|
||||
#ifndef HZ
|
||||
#define HZ 100
|
||||
#endif
|
||||
|
||||
struct tbuffer_t
|
||||
{
|
||||
int proc_user_time;
|
||||
int proc_system_time;
|
||||
int child_user_time;
|
||||
int child_system_time;
|
||||
};
|
||||
|
||||
struct tbuffer_t tms;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
times(&tms);
|
||||
|
||||
q = (double)(tms.proc_user_time) / (double)HZ;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************/
|
||||
/* BORLAND C dtime() for DOS */
|
||||
/******************************/
|
||||
#ifdef BORLAND_C
|
||||
#include <ctype.h>
|
||||
#include <dos.h>
|
||||
#include <time.h>
|
||||
|
||||
#define HZ 100
|
||||
struct time tnow;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
gettime(&tnow);
|
||||
|
||||
q = 60.0 * (double)(tnow.ti_min);
|
||||
q = q + (double)(tnow.ti_sec);
|
||||
q = q + (double)(tnow.ti_hund)/(double)HZ;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**************************************/
|
||||
/* Microsoft C (MSC) dtime() for DOS */
|
||||
/**************************************/
|
||||
#ifdef MSC
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define HZ CLOCKS_PER_SEC
|
||||
clock_t tnow;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
tnow = clock();
|
||||
|
||||
q = (double)tnow / (double)HZ;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************************************/
|
||||
/* Macintosh (MAC) Think C dtime() */
|
||||
/*************************************/
|
||||
#ifdef MAC
|
||||
#include <time.h>
|
||||
|
||||
#define HZ 60
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
q = (double)clock() / (double)HZ;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************/
|
||||
/* iPSC/860 (IPSC) dtime() for i860. */
|
||||
/* Provided by: Dan Yergeau, yergeau@gloworm.Stanford.EDU */
|
||||
/************************************************************/
|
||||
#ifdef IPSC
|
||||
extern double dclock();
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
q = dclock();
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**************************************************/
|
||||
/* FORTRAN dtime() for Cray type systems. */
|
||||
/* This is the preferred timer for Cray systems. */
|
||||
/**************************************************/
|
||||
#ifdef FORTRAN_SEC
|
||||
|
||||
fortran double second();
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
second(&q);
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***********************************************************/
|
||||
/* UNICOS C dtime() for Cray UNICOS systems. Don't use */
|
||||
/* unless absolutely necessary as returned time includes */
|
||||
/* 'user+system' time. Provided by: R. Mike Dority, */
|
||||
/* dority@craysea.cray.com */
|
||||
/***********************************************************/
|
||||
#ifdef CTimer
|
||||
#include <time.h>
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
clock_t clock(void);
|
||||
|
||||
q = (double)clock() / (double)CLOCKS_PER_SEC;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/********************************************/
|
||||
/* Another UNIX timer using gettimeofday(). */
|
||||
/* However, getrusage() is preferred. */
|
||||
/********************************************/
|
||||
#ifdef GTODay
|
||||
#include <sys/time.h>
|
||||
|
||||
struct timeval tnow;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
gettimeofday(&tnow,NULL);
|
||||
q = (double)tnow.tv_sec + (double)tnow.tv_usec * 1.0e-6;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************/
|
||||
/* Fujitsu UXP/M timer. */
|
||||
/* Provided by: Mathew Lim, ANUSF, M.Lim@anu.edu.au */
|
||||
/*****************************************************/
|
||||
#ifdef UXPM
|
||||
#include <sys/types.h>
|
||||
#include <sys/timesu.h>
|
||||
struct tmsu rusage;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
timesu(&rusage);
|
||||
|
||||
q = (double)(rusage.tms_utime) * 1.0e-06;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************************************/
|
||||
/* Macintosh (MAC_TMgr) Think C dtime() */
|
||||
/* requires Think C Language Extensions or */
|
||||
/* #include <MacHeaders> in the prefix */
|
||||
/* provided by Francis H Schiffer 3rd (fhs) */
|
||||
/* skipschiffer@genie.geis.com */
|
||||
/**********************************************/
|
||||
#ifdef MAC_TMgr
|
||||
#include <Timer.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static TMTask mgrTimer;
|
||||
static Boolean mgrInited = false;
|
||||
static double mgrClock;
|
||||
|
||||
#define RMV_TIMER RmvTime( (QElemPtr)&mgrTimer )
|
||||
#define MAX_TIME 1800000000L
|
||||
/* MAX_TIME limits time between calls to */
|
||||
/* dtime( ) to no more than 30 minutes */
|
||||
/* this limitation could be removed by */
|
||||
/* creating a completion routine to sum */
|
||||
/* 30 minute segments (fhs 1994 feb 9) */
|
||||
|
||||
static void Remove_timer( )
|
||||
{
|
||||
RMV_TIMER;
|
||||
mgrInited = false;
|
||||
}
|
||||
|
||||
double dtime( )
|
||||
{
|
||||
if( mgrInited ) {
|
||||
RMV_TIMER;
|
||||
mgrClock += (MAX_TIME + mgrTimer.tmCount)*1.0e-6;
|
||||
} else {
|
||||
if( _atexit( &Remove_timer ) == 0 ) mgrInited = true;
|
||||
mgrClock = 0.0;
|
||||
}
|
||||
|
||||
if ( mgrInited )
|
||||
{
|
||||
mgrTimer.tmAddr = NULL;
|
||||
mgrTimer.tmCount = 0;
|
||||
mgrTimer.tmWakeUp = 0;
|
||||
mgrTimer.tmReserved = 0;
|
||||
InsTime( (QElemPtr)&mgrTimer );
|
||||
PrimeTime( (QElemPtr)&mgrTimer, -MAX_TIME );
|
||||
}
|
||||
return( mgrClock );
|
||||
}
|
||||
#endif
|
||||
|
||||
/***********************************************************/
|
||||
/* Parsytec GCel timer. */
|
||||
/* Provided by: Georg Wambach, gw@informatik.uni-koeln.de */
|
||||
/***********************************************************/
|
||||
#ifdef PARIX
|
||||
#include <sys/time.h>
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
q = (double) (TimeNowHigh()) / (double) CLK_TCK_HIGH;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************/
|
||||
/* Sun Solaris POSIX dtime() routine */
|
||||
/* Provided by: Case Larsen, CTLarsen.lbl.gov */
|
||||
/************************************************/
|
||||
#ifdef POSIX
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/rusage.h>
|
||||
|
||||
#ifdef __hpux
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
struct rusage rusage;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
|
||||
getrusage(RUSAGE_SELF,&rusage);
|
||||
|
||||
q = (double)(rusage.ru_utime.tv_sec);
|
||||
q = q + (double)(rusage.ru_utime.tv_nsec) * 1.0e-09;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************/
|
||||
/* Windows NT (32 bit) dtime() routine */
|
||||
/* Provided by: Piers Haken, piersh@microsoft.com */
|
||||
/****************************************************/
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
|
||||
double dtime(void)
|
||||
{
|
||||
double q;
|
||||
|
||||
q = (double)GetTickCount() * 1.0e-03;
|
||||
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************/
|
||||
/* Time according to POSIX.1 - <J.Pelan@qub.ac.uk> */
|
||||
/* Ref: "POSIX Programmer's Guide" O'Reilly & Assoc.*/
|
||||
/*****************************************************/
|
||||
#ifdef POSIX1
|
||||
#define _POSIX_SOURCE 1
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
struct tms tms;
|
||||
|
||||
double dtime()
|
||||
{
|
||||
double q;
|
||||
times(&tms);
|
||||
q = (double)tms.tms_utime / (double)CLK_TCK;
|
||||
return q;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-------- End of queens.c, Say goodnight Linda! --------*/
|
||||
@@ -1,471 +0,0 @@
|
||||
/*
|
||||
* IOCCC Raytracer by Anders Gavare.
|
||||
*
|
||||
* The raytracer was one of the winners of the 17th IOCCC.
|
||||
*
|
||||
* NOTE: This is the UNOBFUSCATED version of the raytracer I used
|
||||
* during development, not the actual entry sent to the contest.
|
||||
*
|
||||
*
|
||||
* How to build:
|
||||
* cc r3.c -o r3 (plus optimization flags)
|
||||
*
|
||||
* How to run:
|
||||
* ./r3 > ray.ppm
|
||||
* or
|
||||
* ./r3 | xv -
|
||||
*/
|
||||
#include "libsys.h"
|
||||
UINT32 *pP;
|
||||
|
||||
xsize = 800;
|
||||
ysize = 600;
|
||||
An = 3;
|
||||
|
||||
camera_X = 0;
|
||||
camera_Y = -10;
|
||||
camera_Z = -7;
|
||||
|
||||
scale = 1296;
|
||||
RootOfScale = 36;
|
||||
maxcolor = 255;
|
||||
|
||||
MaxDepth=9;
|
||||
_=1<<15;
|
||||
|
||||
/*
|
||||
double sphere_x[44] = {
|
||||
-15,-15,-15,-15, // I
|
||||
-8,-8,-10,-6,-10,-6, // O
|
||||
-1,-1, 1,1, // C
|
||||
6, 6, 8,8, // C
|
||||
13,13,15,15, // C
|
||||
-11,-11,-11,-11,-9,-9,-7,-7, // r
|
||||
0,0,-2,-2,-2,2,2,2, // a
|
||||
7,7,9,9,11,11, // y
|
||||
};
|
||||
double sphere_z[44] = {
|
||||
3,0,-3,-6, // I
|
||||
-6, 3,0,0,-3,-3, // O
|
||||
0,-3,-6, 3, // C
|
||||
0,-3,-6, 3, // C
|
||||
0,-3,-6, 3, // C
|
||||
-11,-13,-15,-17,-11,-15,-13,-17, // r
|
||||
-11,-15,-13,-15,-17,-13,-15,-17, // a
|
||||
-11,-13,-15,-17,-11,-13, // y
|
||||
};
|
||||
*/
|
||||
|
||||
/* Common return variable: */
|
||||
return_var;
|
||||
return_var2;
|
||||
return_var3;
|
||||
return_var4;
|
||||
|
||||
|
||||
get_sphere_coordinates(b)
|
||||
{
|
||||
return_var = "1111886:6:??AAFFHHMMOO55557799@@>>>BBBGGIIKK"[b]-64;
|
||||
return_var3 = "C@=::C@@==@=:C@=:C@=:C531/513/5131/31/531/53"[b]-64;
|
||||
|
||||
/* return_var = sphere_x[b]; */
|
||||
return_var2 = b<22? 9 : 0;
|
||||
/* return_var3 = sphere_z[b]; */
|
||||
return_var4 = 2;
|
||||
}
|
||||
|
||||
|
||||
/* sqroot(x) returns the square root of x in return_var */
|
||||
sqroot_sub(x, mask, guess)
|
||||
{
|
||||
mask?
|
||||
(
|
||||
guess ^= mask,
|
||||
guess*guess > x ?
|
||||
( guess ^= mask )
|
||||
:
|
||||
0,
|
||||
sqroot_sub(x, mask/2, guess)
|
||||
)
|
||||
:
|
||||
( return_var = guess );
|
||||
}
|
||||
|
||||
|
||||
sqroot(x)
|
||||
{
|
||||
sqroot_sub(x, _, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* hit_sphere():
|
||||
*
|
||||
* returns where on a sphere we hit
|
||||
* Returns distance in hit_sphere_q. (Negative return
|
||||
* value if we didn't hit anything.)
|
||||
*/
|
||||
hit_sphere_q;
|
||||
hit_sphere(objnr, x, y, z,
|
||||
dx, dy, dz,
|
||||
a, b)
|
||||
{
|
||||
get_sphere_coordinates(objnr);
|
||||
x -= return_var*scale;
|
||||
y -= return_var2*scale;
|
||||
z -= return_var3*scale;
|
||||
|
||||
/*
|
||||
* Solve the following equation:
|
||||
*
|
||||
* q^2 (dx^2+dy^2+dz^2) + q * 2(x*dx+y*dy+z*dz)
|
||||
* + x^2+y^2+z^2 - r^2 = 0
|
||||
*
|
||||
* We assume that |dx,dy,dz| is 1.
|
||||
*
|
||||
* q^2 + a q + b = 0
|
||||
*
|
||||
* The solution is (of course)
|
||||
*
|
||||
* q = -a/2 +- sqrt(a^2/4 - b)
|
||||
*/
|
||||
|
||||
b = x*x/scale+y*y/scale+z*z/scale-return_var4*return_var4*scale;
|
||||
|
||||
/* a = 2*(...), and then divide by -2 */
|
||||
a = -x*dx/scale-y*dy/scale-z*dz/scale;
|
||||
|
||||
hit_sphere_q =
|
||||
(
|
||||
(b = a*a/scale - b) >= 0 ?
|
||||
(
|
||||
/* b = scale*sqrt((double)b/(double)scale), */
|
||||
/* sqroot(b*scale), */
|
||||
|
||||
/* sqroot_sub(b, _, 0),
|
||||
b = return_var * RootOfScale,
|
||||
*/
|
||||
sqroot_sub(b*scale, _, 0),
|
||||
b = return_var,
|
||||
|
||||
/*
|
||||
* Return the lowest q (a+b or a-b) which is more
|
||||
* than 0. Return negative if neither
|
||||
* a+b or a-b is more than 0.
|
||||
*/
|
||||
|
||||
a + (a>b? -b : b)
|
||||
)
|
||||
:
|
||||
-1.0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* find_closest():
|
||||
*
|
||||
* find_closest() scans objects and returns an index
|
||||
* to the object which was closest (has the lowest 'q').
|
||||
* x,y,z,dx,dy,dz are scaled.
|
||||
* find_closest_i is the index number of the found object,
|
||||
* -1 if none was found. find_closest_q is the distance
|
||||
* (scaled).
|
||||
*/
|
||||
find_closest_i; /* index ("sphere number") */
|
||||
find_closest_q; /* distance (scaled) */
|
||||
find_closest(objnr, x, y, z,
|
||||
dx, dy, dz, notindex)
|
||||
{
|
||||
/* Initialize find_closest_i on first call: */
|
||||
find_closest_i =
|
||||
!objnr ? -1 : find_closest_i;
|
||||
|
||||
objnr < 44 ?
|
||||
(
|
||||
hit_sphere(objnr, x,y,z, dx,dy,dz, 0,0),
|
||||
(hit_sphere_q > 0 && objnr!=notindex &&
|
||||
(hit_sphere_q<find_closest_q || find_closest_i<0)) ?
|
||||
(
|
||||
find_closest_q = hit_sphere_q,
|
||||
find_closest_i = objnr
|
||||
) : 0,
|
||||
find_closest(objnr+1, x,y,z,dx,dy,dz, notindex)
|
||||
)
|
||||
: 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* trace_ray():
|
||||
*
|
||||
* Traces one ray. orig_xyz and dir_xyz are scaled.
|
||||
* Return value in trace_ray_R, G, and B.
|
||||
*/
|
||||
trace_ray_R;
|
||||
trace_ray_G;
|
||||
trace_ray_B;
|
||||
nX;
|
||||
nY;
|
||||
nZ; /* tmp normal, and tmp
|
||||
sphere_light calculation */
|
||||
trace_ray(orig_x, orig_y, orig_z,
|
||||
dir_x, dir_y, dir_z,
|
||||
depth, notindex,
|
||||
tmpcol, closest_i_saved)
|
||||
{
|
||||
/*
|
||||
* "Scan" through the list of all objects
|
||||
* to see which one is closest:
|
||||
*/
|
||||
|
||||
find_closest(0, orig_x, orig_y, orig_z,
|
||||
dir_x, dir_y, dir_z, notindex);
|
||||
|
||||
depth>0 && find_closest_i >= 0?
|
||||
(
|
||||
/* find_closest_i and _q are the object
|
||||
number and distance of the object we
|
||||
hit. */
|
||||
|
||||
orig_x += dir_x*find_closest_q/scale,
|
||||
orig_y += dir_y*find_closest_q/scale,
|
||||
orig_z += dir_z*find_closest_q/scale,
|
||||
|
||||
/*
|
||||
* Calculate color (diffuse light):
|
||||
* (Note: use nZ as a temp variable while
|
||||
* calculating nY)
|
||||
*/
|
||||
get_sphere_coordinates(find_closest_i),
|
||||
nX = orig_x - return_var*scale,
|
||||
nY = orig_y - return_var2*scale,
|
||||
nZ = orig_z - return_var3*scale,
|
||||
|
||||
tmpcol = (-2*nX -2*nY + nZ) / 3, /* sqrt(9), */
|
||||
/* Set return_var to the length of the normal
|
||||
vector (in this case the sphere radius) */
|
||||
/* return_var = sqrt(nX*nX + nY*nY +nZ*nZ), */
|
||||
sqroot(nX*nX + nY*nY +nZ*nZ),
|
||||
// return_var = return_var4*scale,
|
||||
/* divide by return_var to get the color */
|
||||
// tmpcol = return_var!=0? tmpcol*scale/return_var : 0,
|
||||
tmpcol /= return_var4,
|
||||
|
||||
/* color is now -1..1 */
|
||||
tmpcol *= tmpcol, /* square the color 1..-1 => 1..1 */
|
||||
tmpcol *= 200,
|
||||
tmpcol /= (scale*scale),
|
||||
/* tmpcol += 5, */
|
||||
|
||||
closest_i_saved = find_closest_i,
|
||||
|
||||
/* Mirror: out = in - 2*(-normal)*cos v
|
||||
where v is the angle between in and
|
||||
-normal */
|
||||
|
||||
/* -normal: (normalized to len=1.0) */
|
||||
/* return_var = sqrt(nX*nX + nY*nY + nZ*nZ), */
|
||||
return_var!=0?
|
||||
(
|
||||
nX = -nX * scale / return_var,
|
||||
nY = -nY * scale / return_var,
|
||||
nZ = -nZ * scale / return_var
|
||||
) : 0,
|
||||
|
||||
/* use return_var as a temp variable,
|
||||
calculate cosinus between the vectors */
|
||||
return_var = (dir_x*nX + dir_y*nY + dir_z*nZ)/scale,
|
||||
/*
|
||||
dir_x -= 2 * nX * return_var / scale,
|
||||
dir_y -= 2 * nY * return_var / scale,
|
||||
dir_z -= 2 * nZ * return_var / scale,
|
||||
*/
|
||||
dir_x -= nX * return_var / (scale/2),
|
||||
dir_y -= nY * return_var / (scale/2),
|
||||
dir_z -= nZ * return_var / (scale/2),
|
||||
|
||||
trace_ray(orig_x, orig_y, orig_z,
|
||||
dir_x, dir_y, dir_z,
|
||||
depth-1, find_closest_i, 0,0),
|
||||
|
||||
trace_ray_R /= 2,
|
||||
trace_ray_G /= 2,
|
||||
trace_ray_B /= 2,
|
||||
/*
|
||||
closest_i_saved &= 7,
|
||||
!closest_i_saved? (closest_i_saved++) : 0,
|
||||
*/
|
||||
/*
|
||||
closest_i_saved = closest_i_saved<4? closest_i_saved+1 : 7,
|
||||
*/
|
||||
/*
|
||||
tvinga gråskalor: closest_i_saved = 7,
|
||||
*/
|
||||
closest_i_saved = closest_i_saved<22? 7 :
|
||||
(
|
||||
closest_i_saved<30 ? 1 :
|
||||
(
|
||||
closest_i_saved<38 ? 2 :
|
||||
(
|
||||
closest_i_saved<44 ? 4 :
|
||||
(
|
||||
closest_i_saved == 44 ? 6 :
|
||||
3
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
trace_ray_R += closest_i_saved & 1 ? tmpcol : 0,
|
||||
trace_ray_G += closest_i_saved & 2 ? tmpcol : 0,
|
||||
trace_ray_B += closest_i_saved & 4 ? tmpcol : 0
|
||||
)
|
||||
:
|
||||
(
|
||||
/* If we didn't hit anything, set the color anyway: */
|
||||
|
||||
depth==MaxDepth? /* True if this is a ray originating
|
||||
from the camera */
|
||||
(
|
||||
orig_z += 2,
|
||||
dir_z = orig_z > 0? orig_z / 8 : orig_z / 20
|
||||
)
|
||||
: 0,
|
||||
|
||||
/*
|
||||
* Colors according to Horizon_1 in gimp:
|
||||
* At top of sky: 13,92,146 (light blue)
|
||||
* At bottom sky: 255,255,255 (white)
|
||||
* Top of ground: 213,168,111 (light brown)
|
||||
* Bottom of ground: 103, 55, 26 (brown)
|
||||
*/
|
||||
|
||||
dir_z > 0?
|
||||
(
|
||||
trace_ray_B = dir_z * dir_z / scale,
|
||||
trace_ray_R = 255 - 250 * trace_ray_B / scale,
|
||||
trace_ray_G = 255 - 150 * trace_ray_B / scale,
|
||||
trace_ray_B = 255 - 100 * trace_ray_B / scale
|
||||
)
|
||||
:
|
||||
(
|
||||
trace_ray_B = dir_z * dir_z / scale,
|
||||
trace_ray_B < scale/5?
|
||||
(
|
||||
trace_ray_R = 255 - 210 * trace_ray_B / scale,
|
||||
trace_ray_G = 255 - 435 * trace_ray_B / scale,
|
||||
trace_ray_B = 255 - 720 * trace_ray_B / scale
|
||||
)
|
||||
:
|
||||
(
|
||||
trace_ray_B -= scale/5,
|
||||
trace_ray_R = 213 - 110 * trace_ray_B / scale,
|
||||
trace_ray_G = 168 - 113 * trace_ray_B / scale,
|
||||
trace_ray_B = 111 - 85 * trace_ray_B / scale
|
||||
)
|
||||
),
|
||||
|
||||
depth!=MaxDepth?
|
||||
(
|
||||
trace_ray_R /= 2,
|
||||
trace_ray_G /= 2,
|
||||
trace_ray_B /= 2
|
||||
)
|
||||
: 0
|
||||
);
|
||||
|
||||
trace_ray_R = trace_ray_R<0? 0 : trace_ray_R>maxcolor? maxcolor: trace_ray_R;
|
||||
trace_ray_G = trace_ray_G<0? 0 : trace_ray_G>maxcolor? maxcolor : trace_ray_G;
|
||||
trace_ray_B = trace_ray_B<0? 0 : trace_ray_B>maxcolor? maxcolor : trace_ray_B;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* do_pixels_in_line():
|
||||
*
|
||||
* the horizontal "for loop"
|
||||
*/
|
||||
R; G; B;
|
||||
dpil_helper(x,y, a,b)
|
||||
{
|
||||
trace_ray(
|
||||
scale*camera_X + scale*40*(An*x+a)/xsize/An - scale*20,
|
||||
scale*camera_Y,
|
||||
scale*camera_Z - scale*30*(An*y+b)/ysize/An + scale*15,
|
||||
0, scale, 0, MaxDepth, -1, 0,0);
|
||||
|
||||
R += trace_ray_R;
|
||||
G += trace_ray_G;
|
||||
B += trace_ray_B;
|
||||
|
||||
++a<An?
|
||||
dpil_helper(x,y,a,b)
|
||||
: (
|
||||
++b<An?
|
||||
dpil_helper(x,y,0,b)
|
||||
: 0
|
||||
);
|
||||
}
|
||||
do_pixels_in_line(x, y)
|
||||
{
|
||||
R = G = B = 0;
|
||||
dpil_helper(x,y,0,0);
|
||||
|
||||
x < xsize ?
|
||||
(
|
||||
/* output the pixel to stdout, */
|
||||
|
||||
#ifndef JMIPS_VGA
|
||||
printf("%c%c%c", R/An/An, G/An/An, B/An/An),
|
||||
#else
|
||||
pP[x+xsize*y] = (R/An/An & 0xFF) | ((G/An/An & 0xFF) << 8) | ((B/An/An & 0xFF) << 16),
|
||||
#endif
|
||||
/* and then do the next pixel in this line: */
|
||||
do_pixels_in_line(x+1, y)
|
||||
) : 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* do_line():
|
||||
*
|
||||
* the vertical "for loop"
|
||||
*/
|
||||
do_line(y)
|
||||
{
|
||||
/* Do all lines: */
|
||||
do_pixels_in_line(0, --y? do_line(y),y:y);
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
#ifdef JMIPS_VGA
|
||||
volatile UINT32 *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
|
||||
volatile UINT32 *pVGA_front = (UINT32*)SYS_VGA_FB_FRONT;
|
||||
volatile UINT32 *pVGA_back = (UINT32*)SYS_VGA_FB_BACK;
|
||||
UINT64 *pPixelBuf;
|
||||
|
||||
xsize = Screen_get_resx();
|
||||
ysize = Screen_get_resy();
|
||||
|
||||
pPixelBuf = (UINT64*)malloc(xsize*ysize*sizeof(UINT32));
|
||||
pP = (UINT32*)pPixelBuf;
|
||||
printf("pPixelBuf : %8.8X\n", (UINT32)pPixelBuf);
|
||||
|
||||
*pVGA_front = (UINT32)pPixelBuf;
|
||||
*pVGA_back = (UINT32)pPixelBuf;
|
||||
*pVGA_ctrl |= SYS_VGA_BIT_MSTEN;
|
||||
|
||||
memset(pPixelBuf, 0, xsize*ysize*sizeof(UINT32));
|
||||
#else
|
||||
|
||||
/* Output PPM file header ... */
|
||||
printf("P6\n%i %i\n255\n", xsize, ysize);
|
||||
|
||||
#endif
|
||||
|
||||
/* and do all lines: */
|
||||
do_line(ysize);
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/* random.c
|
||||
|
||||
Author: Numerical recipes (ran1, gaussian), Jon Hamkins (others)
|
||||
Revised by: Jon Hamkins
|
||||
Date: 4-16-98
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#define IA 16807
|
||||
#define IM 2147483647
|
||||
#define AM (1.0/IM)
|
||||
#define IQ 127773
|
||||
#define IR 2836
|
||||
#define NTAB 32
|
||||
#define NDIV (1+(IM-1)/NTAB)
|
||||
#define EPS 1.2e-14
|
||||
#define RNMX (1.0-EPS)
|
||||
/* From Numerical Recipes, p. 280, modified from float to double */
|
||||
/* returns a uniform deviate in (0,1) */
|
||||
double ran1(long *idum)
|
||||
{
|
||||
int j;
|
||||
long k;
|
||||
static long iy=0;
|
||||
static long iv[NTAB];
|
||||
double temp;
|
||||
|
||||
if (*idum <=0 || !iy) {
|
||||
if (-(*idum) < 1) *idum=1;
|
||||
else *idum = -(*idum);
|
||||
for (j=NTAB+7; j>=0; j--) {
|
||||
k=(*idum)/IQ;
|
||||
*idum=IA*(*idum-k*IQ)-IR*k;
|
||||
if (*idum < 0) *idum += IM;
|
||||
if (j < NTAB) iv[j] = *idum;
|
||||
}
|
||||
iy = iv[0];
|
||||
}
|
||||
k=(*idum)/IQ;
|
||||
*idum=IA*(*idum-k*IQ)-IR*k;
|
||||
if (*idum < 0) *idum += IM;
|
||||
j=iy/NDIV;
|
||||
iy=iv[j];
|
||||
iv[j] = *idum;
|
||||
if ((temp=AM*iy) > RNMX) return RNMX;
|
||||
else return temp;
|
||||
}
|
||||
#undef IA
|
||||
#undef IM
|
||||
#undef AM
|
||||
#undef IQ
|
||||
#undef IR
|
||||
#undef NTAB
|
||||
#undef NDIV
|
||||
#undef EPS
|
||||
#undef RNMX
|
||||
|
||||
/* Generate a N(0,1) r.v. */
|
||||
double gaussian(long *idum)
|
||||
{
|
||||
static int iset=0;
|
||||
static double gset;
|
||||
double fac,r,v1,v2;
|
||||
double ran1();
|
||||
if (iset == 0) {
|
||||
do {
|
||||
v1=2.0*ran1(idum)-1.0;
|
||||
v2=2.0*ran1(idum)-1.0;
|
||||
r=v1*v1+v2*v2;
|
||||
} while (r >= 1.0 || r == 0.0);
|
||||
fac=sqrt(-2.0*log(r)/r);
|
||||
gset=v1*fac;
|
||||
iset=1;
|
||||
return v2*fac;
|
||||
} else {
|
||||
iset=0;
|
||||
return gset;
|
||||
}
|
||||
}
|
||||
|
||||
/* generate a random bit */
|
||||
int random_bit(long *idum)
|
||||
{
|
||||
return((ran1(idum)<0.5) ? 0 : 1);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
/* random.h */
|
||||
|
||||
/* functions provided by random.c */
|
||||
extern double ran1(long *idum);
|
||||
extern double gaussian(long *idum);
|
||||
extern int random_bit(long *idum);
|
||||
@@ -1,408 +0,0 @@
|
||||
|
||||
/* C version of the systems programming language benchmark
|
||||
** Author: M. J. Jordan Cambridge Computer Laboratory.
|
||||
**
|
||||
** Modified by: M. Richards, Nov 1996
|
||||
** to be ANSI C and runnable on 64 bit machines + other minor changes
|
||||
** Modified by: M. Richards, 20 Oct 1998
|
||||
** made minor corrections to improve ANSI compliance (suggested
|
||||
** by David Levine)
|
||||
**
|
||||
** Compile with, say
|
||||
**
|
||||
** gcc -o bench bench.c
|
||||
**
|
||||
** or
|
||||
**
|
||||
** gcc -o bench100 -Dbench100 bench.c (for a version that obeys
|
||||
** the main loop 100x more often)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef SMALL_PROBLEM_SIZE
|
||||
#define Count 1000*1000
|
||||
#define Qpktcountval 2326389
|
||||
#define Holdcountval 930555
|
||||
#else
|
||||
#define Count 10000*1000
|
||||
#define Qpktcountval 23263894
|
||||
#define Holdcountval 9305557
|
||||
#endif
|
||||
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define MAXINT 32767
|
||||
|
||||
#define BUFSIZE 3
|
||||
#define I_IDLE 1
|
||||
#define I_WORK 2
|
||||
#define I_HANDLERA 3
|
||||
#define I_HANDLERB 4
|
||||
#define I_DEVA 5
|
||||
#define I_DEVB 6
|
||||
#define PKTBIT 1
|
||||
#define WAITBIT 2
|
||||
#define HOLDBIT 4
|
||||
#define NOTPKTBIT !1
|
||||
#define NOTWAITBIT !2
|
||||
#define NOTHOLDBIT 0XFFFB
|
||||
|
||||
#define S_RUN 0
|
||||
#define S_RUNPKT 1
|
||||
#define S_WAIT 2
|
||||
#define S_WAITPKT 3
|
||||
#define S_HOLD 4
|
||||
#define S_HOLDPKT 5
|
||||
#define S_HOLDWAIT 6
|
||||
#define S_HOLDWAITPKT 7
|
||||
|
||||
#define K_DEV 1000
|
||||
#define K_WORK 1001
|
||||
|
||||
struct packet
|
||||
{
|
||||
struct packet *p_link;
|
||||
int p_id;
|
||||
int p_kind;
|
||||
int p_a1;
|
||||
char p_a2[4];
|
||||
};
|
||||
|
||||
struct task
|
||||
{
|
||||
struct task *t_link;
|
||||
int t_id;
|
||||
int t_pri;
|
||||
struct packet *t_wkq;
|
||||
int t_state;
|
||||
struct task *(*t_fn)(struct packet *);
|
||||
long t_v1;
|
||||
long t_v2;
|
||||
};
|
||||
|
||||
char alphabet[28] = "0ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
struct task *tasktab[11] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
struct task *tasklist = 0;
|
||||
struct task *tcb;
|
||||
long taskid;
|
||||
long v1;
|
||||
long v2;
|
||||
int qpktcount = 0;
|
||||
int holdcount = 0;
|
||||
int tracing = 1;
|
||||
int layout = 0;
|
||||
|
||||
void append(struct packet *pkt, struct packet *ptr);
|
||||
|
||||
void createtask(int id,
|
||||
int pri,
|
||||
struct packet *wkq,
|
||||
int state,
|
||||
struct task *(*fn)(struct packet *),
|
||||
long v1,
|
||||
long v2)
|
||||
{
|
||||
struct task *t = (struct task *)malloc(sizeof(struct task));
|
||||
|
||||
tasktab[id] = t;
|
||||
t->t_link = tasklist;
|
||||
t->t_id = id;
|
||||
t->t_pri = pri;
|
||||
t->t_wkq = wkq;
|
||||
t->t_state = state;
|
||||
t->t_fn = fn;
|
||||
t->t_v1 = v1;
|
||||
t->t_v2 = v2;
|
||||
tasklist = t;
|
||||
}
|
||||
|
||||
struct packet *pkt(struct packet *link, int id, int kind)
|
||||
{
|
||||
int i;
|
||||
struct packet *p = (struct packet *)malloc(sizeof(struct packet));
|
||||
|
||||
for (i=0; i<=BUFSIZE; i++)
|
||||
p->p_a2[i] = 0;
|
||||
|
||||
p->p_link = link;
|
||||
p->p_id = id;
|
||||
p->p_kind = kind;
|
||||
p->p_a1 = 0;
|
||||
|
||||
return (p);
|
||||
}
|
||||
|
||||
void trace(char a)
|
||||
{
|
||||
if ( --layout <= 0 )
|
||||
{
|
||||
printf("\n");
|
||||
layout = 50;
|
||||
}
|
||||
|
||||
printf("%c", a);
|
||||
}
|
||||
|
||||
void schedule()
|
||||
{
|
||||
while ( tcb != 0 )
|
||||
{
|
||||
struct packet *pkt;
|
||||
struct task *newtcb;
|
||||
|
||||
pkt=0;
|
||||
|
||||
switch ( tcb->t_state )
|
||||
{
|
||||
case S_WAITPKT:
|
||||
pkt = tcb->t_wkq;
|
||||
tcb->t_wkq = pkt->p_link;
|
||||
tcb->t_state = tcb->t_wkq == 0 ? S_RUN : S_RUNPKT;
|
||||
|
||||
case S_RUN:
|
||||
case S_RUNPKT:
|
||||
taskid = tcb->t_id;
|
||||
v1 = tcb->t_v1;
|
||||
v2 = tcb->t_v2;
|
||||
if (tracing==TRUE) trace(taskid+'0');
|
||||
|
||||
newtcb = (*(tcb->t_fn))(pkt);
|
||||
tcb->t_v1 = v1;
|
||||
tcb->t_v2 = v2;
|
||||
tcb = newtcb;
|
||||
break;
|
||||
|
||||
case S_WAIT:
|
||||
case S_HOLD:
|
||||
case S_HOLDPKT:
|
||||
case S_HOLDWAIT:
|
||||
case S_HOLDWAITPKT:
|
||||
tcb = tcb->t_link;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct task *Wait(void)
|
||||
{
|
||||
tcb->t_state |= WAITBIT;
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
struct task *holdself(void)
|
||||
{
|
||||
++holdcount;
|
||||
tcb->t_state |= HOLDBIT;
|
||||
return (tcb->t_link) ;
|
||||
}
|
||||
|
||||
struct task *findtcb(int id)
|
||||
{
|
||||
struct task *t = 0;
|
||||
|
||||
if (1<=id && id<=(long)10)
|
||||
t = tasktab[id];
|
||||
if (t==0) printf("\nBad task id %d\n", id);
|
||||
return(t);
|
||||
}
|
||||
|
||||
struct task *release(int id)
|
||||
{
|
||||
struct task *t;
|
||||
|
||||
t = findtcb(id);
|
||||
if ( t==0 ) return (0);
|
||||
|
||||
t->t_state &= NOTHOLDBIT;
|
||||
if ( t->t_pri > tcb->t_pri ) return (t);
|
||||
|
||||
return (tcb) ;
|
||||
}
|
||||
|
||||
|
||||
struct task *qpkt(struct packet *pkt)
|
||||
{
|
||||
struct task *t;
|
||||
|
||||
t = findtcb(pkt->p_id);
|
||||
if (t==0) return (t);
|
||||
|
||||
qpktcount++;
|
||||
|
||||
pkt->p_link = 0;
|
||||
pkt->p_id = taskid;
|
||||
|
||||
if (t->t_wkq==0)
|
||||
{
|
||||
t->t_wkq = pkt;
|
||||
t->t_state |= PKTBIT;
|
||||
if (t->t_pri > tcb->t_pri) return (t);
|
||||
}
|
||||
else
|
||||
{
|
||||
append(pkt, (struct packet *)&(t->t_wkq));
|
||||
}
|
||||
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
struct task *idlefn(struct packet *pkt)
|
||||
{
|
||||
--v2;
|
||||
if ( v2==0 ) return ( holdself() );
|
||||
|
||||
if ( (v1&1) == 0 )
|
||||
{
|
||||
v1 = ( v1>>1) & MAXINT;
|
||||
return ( release(I_DEVA) );
|
||||
}
|
||||
else
|
||||
{
|
||||
v1 = ( (v1>>1) & MAXINT) ^ 0XD008;
|
||||
return ( release(I_DEVB) );
|
||||
}
|
||||
}
|
||||
|
||||
struct task *workfn(struct packet *pkt)
|
||||
{
|
||||
if ( pkt==0 ) return ( Wait() );
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
v1 = I_HANDLERA + I_HANDLERB - v1;
|
||||
pkt->p_id = v1;
|
||||
|
||||
pkt->p_a1 = 0;
|
||||
for (i=0; i<=BUFSIZE; i++)
|
||||
{
|
||||
v2++;
|
||||
if ( v2 > 26 ) v2 = 1;
|
||||
(pkt->p_a2)[i] = alphabet[v2];
|
||||
}
|
||||
return ( qpkt(pkt) );
|
||||
}
|
||||
}
|
||||
|
||||
struct task *handlerfn(struct packet *pkt)
|
||||
{
|
||||
if ( pkt!=0) append(pkt,
|
||||
(struct packet *)(pkt->p_kind==K_WORK ? &v1 : &v2));
|
||||
|
||||
if ( v1!=0 )
|
||||
{
|
||||
int count;
|
||||
struct packet *workpkt = (struct packet *)v1;
|
||||
count = workpkt->p_a1;
|
||||
|
||||
if ( count > BUFSIZE )
|
||||
{
|
||||
v1 = (long)(((struct packet *)v1)->p_link);
|
||||
return ( qpkt(workpkt) );
|
||||
}
|
||||
|
||||
if ( v2!=0 )
|
||||
{
|
||||
struct packet *devpkt;
|
||||
|
||||
devpkt = (struct packet *)v2;
|
||||
v2 = (long)(((struct packet *)v2)->p_link);
|
||||
devpkt->p_a1 = workpkt->p_a2[count];
|
||||
workpkt->p_a1 = count+1;
|
||||
return( qpkt(devpkt) );
|
||||
}
|
||||
}
|
||||
return ( Wait() );
|
||||
}
|
||||
|
||||
struct task *devfn(struct packet *pkt)
|
||||
{
|
||||
if ( pkt==0 )
|
||||
{
|
||||
if ( v1==0 ) return ( Wait() );
|
||||
pkt = (struct packet *)v1;
|
||||
v1 = 0;
|
||||
return ( qpkt(pkt) );
|
||||
}
|
||||
else
|
||||
{
|
||||
v1 = (long)pkt;
|
||||
if (tracing==TRUE) trace(pkt->p_a1);
|
||||
return ( holdself() );
|
||||
}
|
||||
}
|
||||
|
||||
void append(struct packet *pkt, struct packet *ptr)
|
||||
{
|
||||
pkt->p_link = 0;
|
||||
|
||||
while ( ptr->p_link ) ptr = ptr->p_link;
|
||||
|
||||
ptr->p_link = pkt;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct packet *wkq = 0;
|
||||
int retval;
|
||||
|
||||
printf("Bench mark starting\n");
|
||||
|
||||
createtask(I_IDLE, 0, wkq, S_RUN, idlefn, 1, Count);
|
||||
|
||||
wkq = pkt(0, 0, K_WORK);
|
||||
wkq = pkt(wkq, 0, K_WORK);
|
||||
|
||||
createtask(I_WORK, 1000, wkq, S_WAITPKT, workfn, I_HANDLERA, 0);
|
||||
|
||||
wkq = pkt(0, I_DEVA, K_DEV);
|
||||
wkq = pkt(wkq, I_DEVA, K_DEV);
|
||||
wkq = pkt(wkq, I_DEVA, K_DEV);
|
||||
|
||||
createtask(I_HANDLERA, 2000, wkq, S_WAITPKT, handlerfn, 0, 0);
|
||||
|
||||
wkq = pkt(0, I_DEVB, K_DEV);
|
||||
wkq = pkt(wkq, I_DEVB, K_DEV);
|
||||
wkq = pkt(wkq, I_DEVB, K_DEV);
|
||||
|
||||
createtask(I_HANDLERB, 3000, wkq, S_WAITPKT, handlerfn, 0, 0);
|
||||
|
||||
wkq = 0;
|
||||
createtask(I_DEVA, 4000, wkq, S_WAIT, devfn, 0, 0);
|
||||
createtask(I_DEVB, 5000, wkq, S_WAIT, devfn, 0, 0);
|
||||
|
||||
tcb = tasklist;
|
||||
|
||||
qpktcount = holdcount = 0;
|
||||
|
||||
printf("Starting\n");
|
||||
|
||||
tracing = FALSE;
|
||||
layout = 0;
|
||||
|
||||
schedule();
|
||||
|
||||
printf("finished\n");
|
||||
|
||||
printf("qpkt count = %d holdcount = %d\n",
|
||||
qpktcount, holdcount);
|
||||
|
||||
printf("These results are ");
|
||||
if (qpktcount == Qpktcountval && holdcount == Holdcountval) {
|
||||
printf("correct");
|
||||
retval = 0;
|
||||
} else {
|
||||
printf("incorrect");
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
printf("\nend of run\n");
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -1,294 +0,0 @@
|
||||
/********************************************************************\
|
||||
*
|
||||
* FILE: rmd160.c
|
||||
*
|
||||
* CONTENTS: A sample C-implementation of the RIPEMD-160
|
||||
* hash-function.
|
||||
* TARGET: any computer with an ANSI C compiler
|
||||
*
|
||||
* AUTHOR: Antoon Bosselaers, ESAT-COSIC
|
||||
* DATE: 1 March 1996
|
||||
* VERSION: 1.0
|
||||
*
|
||||
* Copyright (c) Katholieke Universiteit Leuven
|
||||
* 1996, All Rights Reserved
|
||||
*
|
||||
* Conditions for use of the RIPEMD-160 Software
|
||||
*
|
||||
* The RIPEMD-160 software is freely available for use under the terms and
|
||||
* conditions described hereunder, which shall be deemed to be accepted by
|
||||
* any user of the software and applicable on any use of the software:
|
||||
*
|
||||
* 1. K.U.Leuven Department of Electrical Engineering-ESAT/COSIC shall for
|
||||
* all purposes be considered the owner of the RIPEMD-160 software and of
|
||||
* all copyright, trade secret, patent or other intellectual property
|
||||
* rights therein.
|
||||
* 2. The RIPEMD-160 software is provided on an "as is" basis without
|
||||
* warranty of any sort, express or implied. K.U.Leuven makes no
|
||||
* representation that the use of the software will not infringe any
|
||||
* patent or proprietary right of third parties. User will indemnify
|
||||
* K.U.Leuven and hold K.U.Leuven harmless from any claims or liabilities
|
||||
* which may arise as a result of its use of the software. In no
|
||||
* circumstances K.U.Leuven R&D will be held liable for any deficiency,
|
||||
* fault or other mishappening with regard to the use or performance of
|
||||
* the software.
|
||||
* 3. User agrees to give due credit to K.U.Leuven in scientific publications
|
||||
* or communications in relation with the use of the RIPEMD-160 software
|
||||
* as follows: RIPEMD-160 software written by Antoon Bosselaers,
|
||||
* available at http://www.esat.kuleuven.be/~cosicart/ps/AB-9601/.
|
||||
*
|
||||
\********************************************************************/
|
||||
|
||||
/* header files */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "rmd160.h"
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void MDinit(dword *MDbuf)
|
||||
{
|
||||
MDbuf[0] = 0x67452301UL;
|
||||
MDbuf[1] = 0xefcdab89UL;
|
||||
MDbuf[2] = 0x98badcfeUL;
|
||||
MDbuf[3] = 0x10325476UL;
|
||||
MDbuf[4] = 0xc3d2e1f0UL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void compress(dword *MDbuf, dword *X)
|
||||
{
|
||||
dword aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2],
|
||||
dd = MDbuf[3], ee = MDbuf[4];
|
||||
dword aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2],
|
||||
ddd = MDbuf[3], eee = MDbuf[4];
|
||||
|
||||
/* round 1 */
|
||||
FF(aa, bb, cc, dd, ee, X[ 0], 11);
|
||||
FF(ee, aa, bb, cc, dd, X[ 1], 14);
|
||||
FF(dd, ee, aa, bb, cc, X[ 2], 15);
|
||||
FF(cc, dd, ee, aa, bb, X[ 3], 12);
|
||||
FF(bb, cc, dd, ee, aa, X[ 4], 5);
|
||||
FF(aa, bb, cc, dd, ee, X[ 5], 8);
|
||||
FF(ee, aa, bb, cc, dd, X[ 6], 7);
|
||||
FF(dd, ee, aa, bb, cc, X[ 7], 9);
|
||||
FF(cc, dd, ee, aa, bb, X[ 8], 11);
|
||||
FF(bb, cc, dd, ee, aa, X[ 9], 13);
|
||||
FF(aa, bb, cc, dd, ee, X[10], 14);
|
||||
FF(ee, aa, bb, cc, dd, X[11], 15);
|
||||
FF(dd, ee, aa, bb, cc, X[12], 6);
|
||||
FF(cc, dd, ee, aa, bb, X[13], 7);
|
||||
FF(bb, cc, dd, ee, aa, X[14], 9);
|
||||
FF(aa, bb, cc, dd, ee, X[15], 8);
|
||||
|
||||
/* round 2 */
|
||||
GG(ee, aa, bb, cc, dd, X[ 7], 7);
|
||||
GG(dd, ee, aa, bb, cc, X[ 4], 6);
|
||||
GG(cc, dd, ee, aa, bb, X[13], 8);
|
||||
GG(bb, cc, dd, ee, aa, X[ 1], 13);
|
||||
GG(aa, bb, cc, dd, ee, X[10], 11);
|
||||
GG(ee, aa, bb, cc, dd, X[ 6], 9);
|
||||
GG(dd, ee, aa, bb, cc, X[15], 7);
|
||||
GG(cc, dd, ee, aa, bb, X[ 3], 15);
|
||||
GG(bb, cc, dd, ee, aa, X[12], 7);
|
||||
GG(aa, bb, cc, dd, ee, X[ 0], 12);
|
||||
GG(ee, aa, bb, cc, dd, X[ 9], 15);
|
||||
GG(dd, ee, aa, bb, cc, X[ 5], 9);
|
||||
GG(cc, dd, ee, aa, bb, X[ 2], 11);
|
||||
GG(bb, cc, dd, ee, aa, X[14], 7);
|
||||
GG(aa, bb, cc, dd, ee, X[11], 13);
|
||||
GG(ee, aa, bb, cc, dd, X[ 8], 12);
|
||||
|
||||
/* round 3 */
|
||||
HH(dd, ee, aa, bb, cc, X[ 3], 11);
|
||||
HH(cc, dd, ee, aa, bb, X[10], 13);
|
||||
HH(bb, cc, dd, ee, aa, X[14], 6);
|
||||
HH(aa, bb, cc, dd, ee, X[ 4], 7);
|
||||
HH(ee, aa, bb, cc, dd, X[ 9], 14);
|
||||
HH(dd, ee, aa, bb, cc, X[15], 9);
|
||||
HH(cc, dd, ee, aa, bb, X[ 8], 13);
|
||||
HH(bb, cc, dd, ee, aa, X[ 1], 15);
|
||||
HH(aa, bb, cc, dd, ee, X[ 2], 14);
|
||||
HH(ee, aa, bb, cc, dd, X[ 7], 8);
|
||||
HH(dd, ee, aa, bb, cc, X[ 0], 13);
|
||||
HH(cc, dd, ee, aa, bb, X[ 6], 6);
|
||||
HH(bb, cc, dd, ee, aa, X[13], 5);
|
||||
HH(aa, bb, cc, dd, ee, X[11], 12);
|
||||
HH(ee, aa, bb, cc, dd, X[ 5], 7);
|
||||
HH(dd, ee, aa, bb, cc, X[12], 5);
|
||||
|
||||
/* round 4 */
|
||||
II(cc, dd, ee, aa, bb, X[ 1], 11);
|
||||
II(bb, cc, dd, ee, aa, X[ 9], 12);
|
||||
II(aa, bb, cc, dd, ee, X[11], 14);
|
||||
II(ee, aa, bb, cc, dd, X[10], 15);
|
||||
II(dd, ee, aa, bb, cc, X[ 0], 14);
|
||||
II(cc, dd, ee, aa, bb, X[ 8], 15);
|
||||
II(bb, cc, dd, ee, aa, X[12], 9);
|
||||
II(aa, bb, cc, dd, ee, X[ 4], 8);
|
||||
II(ee, aa, bb, cc, dd, X[13], 9);
|
||||
II(dd, ee, aa, bb, cc, X[ 3], 14);
|
||||
II(cc, dd, ee, aa, bb, X[ 7], 5);
|
||||
II(bb, cc, dd, ee, aa, X[15], 6);
|
||||
II(aa, bb, cc, dd, ee, X[14], 8);
|
||||
II(ee, aa, bb, cc, dd, X[ 5], 6);
|
||||
II(dd, ee, aa, bb, cc, X[ 6], 5);
|
||||
II(cc, dd, ee, aa, bb, X[ 2], 12);
|
||||
|
||||
/* round 5 */
|
||||
JJ(bb, cc, dd, ee, aa, X[ 4], 9);
|
||||
JJ(aa, bb, cc, dd, ee, X[ 0], 15);
|
||||
JJ(ee, aa, bb, cc, dd, X[ 5], 5);
|
||||
JJ(dd, ee, aa, bb, cc, X[ 9], 11);
|
||||
JJ(cc, dd, ee, aa, bb, X[ 7], 6);
|
||||
JJ(bb, cc, dd, ee, aa, X[12], 8);
|
||||
JJ(aa, bb, cc, dd, ee, X[ 2], 13);
|
||||
JJ(ee, aa, bb, cc, dd, X[10], 12);
|
||||
JJ(dd, ee, aa, bb, cc, X[14], 5);
|
||||
JJ(cc, dd, ee, aa, bb, X[ 1], 12);
|
||||
JJ(bb, cc, dd, ee, aa, X[ 3], 13);
|
||||
JJ(aa, bb, cc, dd, ee, X[ 8], 14);
|
||||
JJ(ee, aa, bb, cc, dd, X[11], 11);
|
||||
JJ(dd, ee, aa, bb, cc, X[ 6], 8);
|
||||
JJ(cc, dd, ee, aa, bb, X[15], 5);
|
||||
JJ(bb, cc, dd, ee, aa, X[13], 6);
|
||||
|
||||
/* parallel round 1 */
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8);
|
||||
JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11);
|
||||
JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14);
|
||||
JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14);
|
||||
JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12);
|
||||
JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6);
|
||||
|
||||
/* parallel round 2 */
|
||||
III(eee, aaa, bbb, ccc, ddd, X[ 6], 9);
|
||||
III(ddd, eee, aaa, bbb, ccc, X[11], 13);
|
||||
III(ccc, ddd, eee, aaa, bbb, X[ 3], 15);
|
||||
III(bbb, ccc, ddd, eee, aaa, X[ 7], 7);
|
||||
III(aaa, bbb, ccc, ddd, eee, X[ 0], 12);
|
||||
III(eee, aaa, bbb, ccc, ddd, X[13], 8);
|
||||
III(ddd, eee, aaa, bbb, ccc, X[ 5], 9);
|
||||
III(ccc, ddd, eee, aaa, bbb, X[10], 11);
|
||||
III(bbb, ccc, ddd, eee, aaa, X[14], 7);
|
||||
III(aaa, bbb, ccc, ddd, eee, X[15], 7);
|
||||
III(eee, aaa, bbb, ccc, ddd, X[ 8], 12);
|
||||
III(ddd, eee, aaa, bbb, ccc, X[12], 7);
|
||||
III(ccc, ddd, eee, aaa, bbb, X[ 4], 6);
|
||||
III(bbb, ccc, ddd, eee, aaa, X[ 9], 15);
|
||||
III(aaa, bbb, ccc, ddd, eee, X[ 1], 13);
|
||||
III(eee, aaa, bbb, ccc, ddd, X[ 2], 11);
|
||||
|
||||
/* parallel round 3 */
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[15], 9);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[14], 6);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, X[11], 12);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[12], 5);
|
||||
HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14);
|
||||
HHH(bbb, ccc, ddd, eee, aaa, X[10], 13);
|
||||
HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13);
|
||||
HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7);
|
||||
HHH(ddd, eee, aaa, bbb, ccc, X[13], 5);
|
||||
|
||||
/* parallel round 4 */
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[11], 14);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, X[15], 6);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, X[12], 9);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12);
|
||||
GGG(bbb, ccc, ddd, eee, aaa, X[13], 9);
|
||||
GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12);
|
||||
GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5);
|
||||
GGG(ddd, eee, aaa, bbb, ccc, X[10], 15);
|
||||
GGG(ccc, ddd, eee, aaa, bbb, X[14], 8);
|
||||
|
||||
/* parallel round 5 */
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6);
|
||||
FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5);
|
||||
FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15);
|
||||
FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13);
|
||||
FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11);
|
||||
FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11);
|
||||
|
||||
/* combine results */
|
||||
ddd += cc + MDbuf[1]; /* final result for MDbuf[0] */
|
||||
MDbuf[1] = MDbuf[2] + dd + eee;
|
||||
MDbuf[2] = MDbuf[3] + ee + aaa;
|
||||
MDbuf[3] = MDbuf[4] + aa + bbb;
|
||||
MDbuf[4] = MDbuf[0] + bb + ccc;
|
||||
MDbuf[0] = ddd;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void MDfinish(dword *MDbuf, byte *strptr, dword lswlen, dword mswlen)
|
||||
{
|
||||
unsigned int i; /* counter */
|
||||
dword X[16]; /* message words */
|
||||
|
||||
memset(X, 0, 16*sizeof(dword));
|
||||
|
||||
/* put bytes from strptr into X */
|
||||
for (i=0; i<(lswlen&63); i++) {
|
||||
/* byte i goes into word X[i div 4] at pos. 8*(i mod 4) */
|
||||
X[i>>2] ^= (dword) *strptr++ << (8 * (i&3));
|
||||
}
|
||||
|
||||
/* append the bit m_n == 1 */
|
||||
X[(lswlen>>2)&15] ^= (dword)1 << (8*(lswlen&3) + 7);
|
||||
|
||||
if ((lswlen & 63) > 55) {
|
||||
/* length goes to next block */
|
||||
compress(MDbuf, X);
|
||||
memset(X, 0, 16*sizeof(dword));
|
||||
}
|
||||
|
||||
/* append length in bits*/
|
||||
X[14] = lswlen << 3;
|
||||
X[15] = (lswlen >> 29) | (mswlen << 3);
|
||||
compress(MDbuf, X);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/************************ end of file rmd160.c **********************/
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/********************************************************************\
|
||||
*
|
||||
* FILE: rmd160.h
|
||||
*
|
||||
* CONTENTS: Header file for a sample C-implementation of the
|
||||
* RIPEMD-160 hash-function.
|
||||
* TARGET: any computer with an ANSI C compiler
|
||||
*
|
||||
* AUTHOR: Antoon Bosselaers, ESAT-COSIC
|
||||
* DATE: 1 March 1996
|
||||
* VERSION: 1.0
|
||||
*
|
||||
* Copyright (c) Katholieke Universiteit Leuven
|
||||
* 1996, All Rights Reserved
|
||||
*
|
||||
* Conditions for use of the RIPEMD-160 Software
|
||||
*
|
||||
* The RIPEMD-160 software is freely available for use under the terms and
|
||||
* conditions described hereunder, which shall be deemed to be accepted by
|
||||
* any user of the software and applicable on any use of the software:
|
||||
*
|
||||
* 1. K.U.Leuven Department of Electrical Engineering-ESAT/COSIC shall for
|
||||
* all purposes be considered the owner of the RIPEMD-160 software and of
|
||||
* all copyright, trade secret, patent or other intellectual property
|
||||
* rights therein.
|
||||
* 2. The RIPEMD-160 software is provided on an "as is" basis without
|
||||
* warranty of any sort, express or implied. K.U.Leuven makes no
|
||||
* representation that the use of the software will not infringe any
|
||||
* patent or proprietary right of third parties. User will indemnify
|
||||
* K.U.Leuven and hold K.U.Leuven harmless from any claims or liabilities
|
||||
* which may arise as a result of its use of the software. In no
|
||||
* circumstances K.U.Leuven R&D will be held liable for any deficiency,
|
||||
* fault or other mishappening with regard to the use or performance of
|
||||
* the software.
|
||||
* 3. User agrees to give due credit to K.U.Leuven in scientific publications
|
||||
* or communications in relation with the use of the RIPEMD-160 software
|
||||
* as follows: RIPEMD-160 software written by Antoon Bosselaers,
|
||||
* available at http://www.esat.kuleuven.be/~cosicart/ps/AB-9601/.
|
||||
*
|
||||
\********************************************************************/
|
||||
|
||||
#ifndef RMD160H /* make sure this file is read only once */
|
||||
#define RMD160H
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
/* typedef 8 and 32 bit types, resp. */
|
||||
/* adapt these, if necessary,
|
||||
for your operating system and compiler */
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned long dword;
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
/* macro definitions */
|
||||
|
||||
/* collect four bytes into one word: */
|
||||
#define BYTES_TO_DWORD(strptr) \
|
||||
(((dword) *((strptr)+3) << 24) | \
|
||||
((dword) *((strptr)+2) << 16) | \
|
||||
((dword) *((strptr)+1) << 8) | \
|
||||
((dword) *(strptr)))
|
||||
|
||||
/* ROL(x, n) cyclically rotates x over n bits to the left */
|
||||
/* x must be of an unsigned 32 bits type and 0 <= n < 32. */
|
||||
#define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* the five basic functions F(), G() and H() */
|
||||
#define F(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define G(x, y, z) (((x) & (y)) | (~(x) & (z)))
|
||||
#define H(x, y, z) (((x) | ~(y)) ^ (z))
|
||||
#define I(x, y, z) (((x) & (z)) | ((y) & ~(z)))
|
||||
#define J(x, y, z) ((x) ^ ((y) | ~(z)))
|
||||
|
||||
/* the ten basic operations FF() through III() */
|
||||
#define FF(a, b, c, d, e, x, s) {\
|
||||
(a) += F((b), (c), (d)) + (x);\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define GG(a, b, c, d, e, x, s) {\
|
||||
(a) += G((b), (c), (d)) + (x) + 0x5a827999UL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define HH(a, b, c, d, e, x, s) {\
|
||||
(a) += H((b), (c), (d)) + (x) + 0x6ed9eba1UL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define II(a, b, c, d, e, x, s) {\
|
||||
(a) += I((b), (c), (d)) + (x) + 0x8f1bbcdcUL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define JJ(a, b, c, d, e, x, s) {\
|
||||
(a) += J((b), (c), (d)) + (x) + 0xa953fd4eUL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define FFF(a, b, c, d, e, x, s) {\
|
||||
(a) += F((b), (c), (d)) + (x);\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define GGG(a, b, c, d, e, x, s) {\
|
||||
(a) += G((b), (c), (d)) + (x) + 0x7a6d76e9UL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define HHH(a, b, c, d, e, x, s) {\
|
||||
(a) += H((b), (c), (d)) + (x) + 0x6d703ef3UL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define III(a, b, c, d, e, x, s) {\
|
||||
(a) += I((b), (c), (d)) + (x) + 0x5c4dd124UL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
#define JJJ(a, b, c, d, e, x, s) {\
|
||||
(a) += J((b), (c), (d)) + (x) + 0x50a28be6UL;\
|
||||
(a) = ROL((a), (s)) + (e);\
|
||||
(c) = ROL((c), 10);\
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
void MDinit(dword *MDbuf);
|
||||
/*
|
||||
* initializes MDbuffer to "magic constants"
|
||||
*/
|
||||
|
||||
void compress(dword *MDbuf, dword *X);
|
||||
/*
|
||||
* the compression function.
|
||||
* transforms MDbuf using message bytes X[0] through X[15]
|
||||
*/
|
||||
|
||||
void MDfinish(dword *MDbuf, byte *strptr, dword lswlen, dword mswlen);
|
||||
/*
|
||||
* puts bytes from strptr into X and pad out; appends length
|
||||
* and finally, compresses the last block(s)
|
||||
* note: length in bits == 8 * (lswlen + 2^32 mswlen).
|
||||
* note: there are (lswlen mod 64) bytes left in strptr.
|
||||
*/
|
||||
|
||||
#endif /* RMD160H */
|
||||
|
||||
/*********************** end of file rmd160.h ***********************/
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libsys.h"
|
||||
|
||||
#include "rmd160.h"
|
||||
|
||||
#ifndef RMDsize
|
||||
#define RMDsize 160
|
||||
#endif
|
||||
|
||||
byte *RMD(byte *message)
|
||||
/*
|
||||
* returns RMD(message)
|
||||
* message should be a string terminated by '\0'
|
||||
*/
|
||||
{
|
||||
dword MDbuf[RMDsize/32]; /* contains (A, B, C, D(, E)) */
|
||||
static byte hashcode[RMDsize/8]; /* for final hash-value */
|
||||
dword X[16]; /* current 16-word chunk */
|
||||
unsigned int i; /* counter */
|
||||
dword length; /* length in bytes of message */
|
||||
dword nbytes; /* # of bytes not yet processed */
|
||||
|
||||
/* initialize */
|
||||
MDinit(MDbuf);
|
||||
length = (dword)strlen((char *)message);
|
||||
|
||||
/* process message in 16-word chunks */
|
||||
for (nbytes=length; nbytes > 63; nbytes-=64) {
|
||||
for (i=0; i<16; i++) {
|
||||
X[i] = BYTES_TO_DWORD(message);
|
||||
message += 4;
|
||||
}
|
||||
compress(MDbuf, X);
|
||||
} /* length mod 64 bytes left */
|
||||
|
||||
/* finish: */
|
||||
MDfinish(MDbuf, message, length, 0);
|
||||
|
||||
for (i=0; i<RMDsize/8; i+=4) {
|
||||
hashcode[i] = MDbuf[i>>2]; /* implicit cast to byte */
|
||||
hashcode[i+1] = (MDbuf[i>>2] >> 8); /* extracts the 8 least */
|
||||
hashcode[i+2] = (MDbuf[i>>2] >> 16); /* significant bits. */
|
||||
hashcode[i+3] = (MDbuf[i>>2] >> 24);
|
||||
}
|
||||
|
||||
return (byte *)hashcode;
|
||||
}
|
||||
|
||||
#define MSG_SIZE 1024*1024 // Bit
|
||||
int main (void)
|
||||
{
|
||||
int result, i, j, cnt;
|
||||
byte *hashcode;
|
||||
byte hashref[] = {0xFC,0x20,0x7B,0x84,0x40,0x1C,0x49,0x0B,0x8D,0x69,0x88,0xD2,0x49,0x20,0x01,0x90,0x41,0x77,0x72,0x59};
|
||||
char msg[MSG_SIZE/8+1];
|
||||
char crlf[] = "\n";
|
||||
UINT32 start, stop;
|
||||
|
||||
for (i=0; i < MSG_SIZE/8; i++)
|
||||
msg[i] = 0x55;
|
||||
|
||||
msg[i] = 0;
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
cnt = 0;
|
||||
start = time(NULL);
|
||||
stop = start + 1;
|
||||
while(1)
|
||||
{
|
||||
hashcode = RMD((byte *)msg);
|
||||
start = time(NULL);
|
||||
if (memcmp(hashcode, hashref, sizeof(hashref)))
|
||||
{
|
||||
printf("Error RipeMD-160!\n");
|
||||
printf("Hash expected: ");
|
||||
for (i=0; i<sizeof(hashref); i++)
|
||||
printf("%2.2X", hashref[i]);
|
||||
|
||||
printf("\n");
|
||||
printf("Hash computed: ");
|
||||
for (i=0; i<sizeof(hashref); i++)
|
||||
printf("%2.2X", hashcode[i]);
|
||||
|
||||
printf("\n");
|
||||
return 1;
|
||||
}
|
||||
if (start >= stop)
|
||||
{
|
||||
for (i=0; i<sizeof(hashref); i++)
|
||||
printf("%2.2X", hashcode[i]);
|
||||
printf("\n%d Hashes/s of %d Mbit message => %d Mbit/s\n\n", cnt, MSG_SIZE/(1024*1024), cnt*MSG_SIZE/(1024*1024));
|
||||
start = time(NULL);
|
||||
stop = start + 1;
|
||||
cnt = 0;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,282 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "libsys.h"
|
||||
|
||||
void _exc_break(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
"break 0x9\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
void _exc_syscall(UINT32 code, UINT32 arg)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
"move $v0, %[code]\n"
|
||||
"move $a0, %[arg]\n"
|
||||
"syscall\n"
|
||||
:
|
||||
: [code] "r" (code), [arg] "r" (arg)
|
||||
: "v0", "a0"
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
void _exc_arith(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t0, 0x7FFFFFFF\n"
|
||||
" addi $t1, $t0, 2\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
void _exc_store_err(void)
|
||||
{
|
||||
volatile int *pSrc = (int*)SYS_TIMER_SEC;
|
||||
volatile int *pDst = (int*)0x40000001;
|
||||
|
||||
*pDst = *pSrc;
|
||||
|
||||
}
|
||||
|
||||
void _exc_load_err(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t0, 0x40000000\n"
|
||||
" li $t1, 0x40000000\n"
|
||||
" lw $t1, 0($t1)\n"
|
||||
" lw $t0, 2($t0)\n"
|
||||
" lw $t1, 4($t0)\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void _exc_kaddr_err(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t0, 0x80000000\n"
|
||||
" jr $t0\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void _exc_iaddr_daddr_err(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t0, 0x40000003\n"
|
||||
" li $t1, 0x40000002\n"
|
||||
" jr $t0\n"
|
||||
" lw $t1, 0($t1)\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void _exc_daddr_iaddr_err(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t0, 0x40000003\n"
|
||||
" li $t1, 0x40000002\n"
|
||||
" lw $t1, 0($t1)\n"
|
||||
" jr $t0\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void _exc_iaddr_err(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t0, 0x40000003\n"
|
||||
" jr $t0\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void _exc_ri(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t0, 0x40010000\n"
|
||||
" li $t1, 0x9c563442\n"
|
||||
" sw $t1, 0($t0)\n"
|
||||
" jr $t0\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void _exc_ibe(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t1, 0x10000000\n"
|
||||
" jr $t1\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void _exc_dbe(void)
|
||||
{
|
||||
__asm
|
||||
(
|
||||
".set noreorder\n"
|
||||
" li $t1, 0x10000000\n"
|
||||
" lw $t0, 0($t1)\n"
|
||||
"nop\n"
|
||||
" jr $t0\n"
|
||||
"nop\n"
|
||||
".set reorder\n"
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
void handler0(void)
|
||||
{
|
||||
printf("Interrupt 0\n");
|
||||
interrupt_clr(0);
|
||||
}
|
||||
|
||||
void handler1(void)
|
||||
{
|
||||
printf("Interrupt 1\n");
|
||||
interrupt_clr(1);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int buf[256];
|
||||
int i, sel;
|
||||
|
||||
interrupt_register(0, handler0);
|
||||
interrupt_enable(0);
|
||||
interrupt_register(1, handler1);
|
||||
interrupt_enable(1);
|
||||
|
||||
while(1)
|
||||
{
|
||||
printf("Welche exception möchten Sie testen?\n");
|
||||
printf(" 1 : Reserved instruction\n");
|
||||
printf(" 2 : Privileged address (BadVAddr = 0x80000000)\n");
|
||||
printf(" 3 : Arithmetic overflow\n");
|
||||
printf(" 4 : Syscall\n");
|
||||
printf(" 5 : Breakpoint\n");
|
||||
printf(" 6 : Load error on instruction (BadVAddr = 0x40000003)\n");
|
||||
printf(" 7 : Load error on data (BadVAddr = 0x40000002)\n");
|
||||
printf(" 8 : Store error on data (BadVAddr = 0x40000001)\n");
|
||||
printf(" 9 : Bus error on instruction\n");
|
||||
printf("10 : Bus error on data\n");
|
||||
printf("11 : SW-interrupt 0\n");
|
||||
printf("12 : SW-interrupt 1\n");
|
||||
printf("13 : Load error on instruction and Load error on data (BadVAddr = 0x40000003)\n");
|
||||
printf("14 : Load error on data and Load error on instruction (BadVAddr = 0x40000002)\n");
|
||||
|
||||
scanf("%d", &sel);
|
||||
printf("Jetzt kommt die exception (%d)!\n", sel);
|
||||
|
||||
switch(sel)
|
||||
{
|
||||
case 1:
|
||||
_exc_ri();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
_exc_kaddr_err();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
_exc_arith();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
_exc_syscall(4, (UINT32)((char*)"Hallo Syscall ("));
|
||||
_exc_syscall(1, 12345678);
|
||||
_exc_syscall(4, (UINT32)((char*)")\n"));
|
||||
break;
|
||||
|
||||
case 5:
|
||||
_exc_break();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
_exc_iaddr_err();
|
||||
break;
|
||||
|
||||
case 7:
|
||||
_exc_load_err();
|
||||
break;
|
||||
|
||||
case 8:
|
||||
_exc_store_err();
|
||||
break;
|
||||
|
||||
case 9:
|
||||
printf("IBE: Exception not implemented in current CPU!\nPush reset to restart!\n");
|
||||
_exc_ibe();
|
||||
break;
|
||||
|
||||
case 10:
|
||||
printf("DBE: Exception not implemented in current CPU!\nPush reset to restart!\n");
|
||||
_exc_dbe();
|
||||
break;
|
||||
|
||||
case 11:
|
||||
case 12:
|
||||
interrupt_set(sel-11);
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_exc_iaddr_daddr_err();
|
||||
break;
|
||||
|
||||
case 14:
|
||||
_exc_daddr_iaddr_err();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
sel = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/* AMD CFI Enabled Flash Memory Drivers */
|
||||
/* File name: CFIDRIVE.C */
|
||||
/* Revision: 1.0 5/07/98 */
|
||||
/* */
|
||||
/* Copyright (c) 1998 ADVANCED MICRO DEVICES, INC. All Rights Reserved. */
|
||||
/* This software is unpublished and contains the trade secrets and */
|
||||
/* confidential proprietary information of AMD. Unless otherwise */
|
||||
/* provided in the Software Agreement associated herewith, it is */
|
||||
/* licensed in confidence "AS IS" and is not to be reproduced in whole */
|
||||
/* or part by any means except for backup. Use, duplication, or */
|
||||
/* disclosure by the Government is subject to the restrictions in */
|
||||
/* paragraph (b) (3) (B) of the Rights in Technical Data and Computer */
|
||||
/* Software clause in DFAR 52.227-7013 (a) (Oct 1988). */
|
||||
/* Software owned by */
|
||||
/* Advanced Micro Devices, Inc., */
|
||||
/* One AMD Place, */
|
||||
/* P.O. Box 3453 */
|
||||
/* Sunnyvale, CA 94088-3453. */
|
||||
/************************************************************************/
|
||||
/* This software constitutes a basic shell of source code for */
|
||||
/* programming all AMD Flash components. AMD */
|
||||
/* will not be responsible for misuse or illegal use of this */
|
||||
/* software for devices not supported herein. AMD is providing */
|
||||
/* this source code "AS IS" and will not be responsible for */
|
||||
/* issues arising from incorrect user implementation of the */
|
||||
/* source code herein. It is the user's responsibility to */
|
||||
/* properly design-in this source code. */
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "cfiflash.h"
|
||||
#include "libsys.h"
|
||||
|
||||
#define TEST_SIZE (1024*1024)
|
||||
#define FLASH_OFFSET 0x700000
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
flash_t flash;
|
||||
UINT8 *pFlash = (UINT8*)0xA4000000;
|
||||
UINT32 result;
|
||||
UINT8 *pBuf;
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
result = flash_find(&flash, 0xA4000000);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
printf("flash_find() error!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Found Flash at %8.8X\n", (UINT32)flash.pBase);
|
||||
|
||||
pBuf = (UINT8*)malloc(TEST_SIZE);
|
||||
|
||||
for (i=0; i < TEST_SIZE; i++)
|
||||
pBuf[i] = i;
|
||||
|
||||
printf("Flash erase from %8.8X to %8.8X...", FLASH_OFFSET, FLASH_OFFSET+TEST_SIZE);
|
||||
result = flash_erase(&flash, FLASH_OFFSET, TEST_SIZE);
|
||||
if (result < 0)
|
||||
{
|
||||
printf("error!\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
printf("Flash program from %8.8X to %8.8X...", FLASH_OFFSET, FLASH_OFFSET+TEST_SIZE);
|
||||
result = flash_program(&flash, FLASH_OFFSET, pBuf, TEST_SIZE);
|
||||
if (result < 0)
|
||||
{
|
||||
printf("error!\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
printf("Flash verify from %8.8X to %8.8X...", FLASH_OFFSET, FLASH_OFFSET+TEST_SIZE);
|
||||
result = flash_verify(&flash, FLASH_OFFSET, pBuf, TEST_SIZE);
|
||||
if (result < 0)
|
||||
{
|
||||
printf("error!\n");
|
||||
return 1;
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
// PrintBuffer8((UINT8*)pFlash, 16, TEST_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,848 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "libsys.h"
|
||||
#include "cfiflash.h"
|
||||
#include "hpi.h"
|
||||
|
||||
static volatile UINT32 _g_uart_msg;
|
||||
static volatile UINT32 _g_rst;
|
||||
static volatile UINT32 _g_sus;
|
||||
static volatile UINT32 _g_cfg;
|
||||
|
||||
void uart_handler(void)
|
||||
{
|
||||
volatile UINT32 *pUART_stat = (UINT32*)SYS_UART_STAT;
|
||||
volatile UINT32 *pUART_data = (UINT32*)SYS_UART_DATA;
|
||||
|
||||
while((SYS_PS2_BIT_RX_AVAIL & *pUART_stat))
|
||||
{
|
||||
_g_uart_msg = *pUART_data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrintDevRegs(UINT devid)
|
||||
{
|
||||
int i;
|
||||
UINT32 reg_base1, reg_base2, reg_addr;
|
||||
|
||||
if ((devid < 1) || (devid > 2))
|
||||
return;
|
||||
|
||||
printf("********************************************************\n");
|
||||
printf("Device %d status\n", devid);
|
||||
printf("********************************************************\n");
|
||||
reg_base1 = 0x0200 + (devid-1)*0x80;
|
||||
reg_base2 = 0xC080 + (devid-1)*0x20;
|
||||
reg_addr = reg_base2 + 4;
|
||||
printf("Port select (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base2 + 10;
|
||||
printf("USB control (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base2 + 12;
|
||||
printf("Int. enable (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base2 + 14;
|
||||
printf("Address (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base2 + 16;
|
||||
printf("Status (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base2 + 18;
|
||||
printf("Frame # reg (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base2 + 20;
|
||||
printf("SOF/EOP cnt (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
for (i=0; i < 8; i++)
|
||||
{
|
||||
printf("EP# %d\n", i);
|
||||
reg_addr = reg_base1 + 16*i + 0;
|
||||
printf("Control (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base1 + 16*i + 2;
|
||||
printf("Address (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base1 + 16*i + 4;
|
||||
printf("Count (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base1 + 16*i + 6;
|
||||
printf("Status (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
reg_addr = reg_base1 + 16*i + 8;
|
||||
printf("Count result (%4.4X) : %4.4X\n", reg_addr, hpi_read_reg(reg_addr));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct _sdev_descr_t
|
||||
{
|
||||
UINT8 size; // length
|
||||
UINT8 type; // desc type
|
||||
UINT16 usb_spec; // USB spec
|
||||
UINT8 devclass; // device class
|
||||
UINT8 subclass; // sub class
|
||||
UINT8 protocol; // protocol
|
||||
UINT8 max_packet_size; // max packet size for endpoint 0
|
||||
UINT16 vendor_id; // Vendor ID
|
||||
UINT16 product_id; // Product ID
|
||||
UINT16 device_id; // device release number
|
||||
UINT8 man_str_index; // index of manufacture string
|
||||
UINT8 prod_str_index; // index of product string
|
||||
UINT8 sn_str_index; // index of serial number string
|
||||
UINT8 nconfs; // number of configurations
|
||||
} __attribute__ ((__packed__)) dev_descr_t;
|
||||
|
||||
typedef struct _sconf_descr_t
|
||||
{
|
||||
UINT8 size; // length of this config
|
||||
UINT8 type; // desc type
|
||||
UINT16 total_size; // Total configuration desc length including this config and following descriptions
|
||||
UINT8 nifaces; // Number of interface descriptions following this
|
||||
UINT8 conf_id; // config number
|
||||
UINT8 conf_str_index; // index of string describing config
|
||||
UINT8 attr; // attributes (e.g. bus powered)
|
||||
UINT8 current; // 2mA x <current> (max. 250 => 500mA)
|
||||
} __attribute__ ((__packed__)) conf_descr_t;
|
||||
|
||||
typedef struct _siface_descr_t
|
||||
{
|
||||
UINT8 size; // length of this config
|
||||
UINT8 type; // desc type
|
||||
UINT8 base; // base number
|
||||
UINT8 alt; // alt
|
||||
UINT8 neps; // number of endpoint description following this
|
||||
UINT8 iface_class; // interface class (vendor)
|
||||
UINT8 subclass; // subclass
|
||||
UINT8 iface_proto; // interface proto (vendor)
|
||||
UINT8 iface_str_index;
|
||||
} __attribute__ ((__packed__)) iface_descr_t;
|
||||
|
||||
typedef struct _sep_descr_t
|
||||
{
|
||||
UINT8 size; // length of this config
|
||||
UINT8 type; // type (endpoint)
|
||||
UINT8 type_num; // type/number (Host use WriteFile)
|
||||
UINT8 bulk; // Bulk
|
||||
UINT16 pkt_size; // packet size
|
||||
UINT8 interval; // interval
|
||||
} __attribute__ ((__packed__)) ep_descr_t;
|
||||
|
||||
typedef struct _sotg_descr_t
|
||||
{
|
||||
UINT8 size; // length of this config
|
||||
UINT8 type; // type (OTG)
|
||||
UINT8 hnp_srp; // HNP|SRP support
|
||||
} __attribute__ ((__packed__)) otg_descr_t;
|
||||
|
||||
typedef struct _sstr_descr_hdr_t
|
||||
{
|
||||
UINT8 size; // length of this config
|
||||
UINT8 type; // type
|
||||
} __attribute__ ((__packed__)) str_descr_hdr_t;
|
||||
|
||||
typedef struct _scfg_inst_t
|
||||
{
|
||||
usb_irp_t *pIRP_rx;
|
||||
usb_irp_t *pIRP_tx;
|
||||
} cfg_inst_t;
|
||||
|
||||
UINT32 conf_write(UINT8 *pConfDescr, UINT32 neps, ep_descr_t *pEP)
|
||||
{
|
||||
UINT32 pos, size;
|
||||
conf_descr_t cfg;
|
||||
iface_descr_t iface;
|
||||
otg_descr_t otg_descr;
|
||||
|
||||
// Fill config description
|
||||
cfg.size = sizeof(conf_descr_t);
|
||||
cfg.type = 2;
|
||||
cfg.total_size = sizeof(conf_descr_t) + sizeof(iface_descr_t) + neps*sizeof(ep_descr_t) + sizeof(otg_descr_t);
|
||||
cfg.nifaces = 1; // can handle only one interface per config
|
||||
cfg.conf_id = 1;
|
||||
cfg.conf_str_index = 0;
|
||||
cfg.attr = 0x80;
|
||||
cfg.current = 50;
|
||||
|
||||
// Copy config description
|
||||
pos = 0;
|
||||
size = sizeof(conf_descr_t);
|
||||
memcpy(&pConfDescr[pos], &cfg, size);
|
||||
|
||||
// Fill interface description
|
||||
iface.size = sizeof(iface_descr_t);
|
||||
iface.type = 4;
|
||||
iface.base = 0;
|
||||
iface.alt = 0;
|
||||
iface.neps = neps;
|
||||
iface.iface_class = 0;
|
||||
iface.subclass = 0;
|
||||
iface.iface_proto = 0;
|
||||
iface.iface_str_index = 0;
|
||||
|
||||
// Copy interface description
|
||||
pos += size;
|
||||
size = sizeof(iface_descr_t);
|
||||
memcpy(&pConfDescr[pos], &iface, size);
|
||||
|
||||
// Copy N end point descriptions
|
||||
pos += size;
|
||||
size = neps*sizeof(ep_descr_t);
|
||||
memcpy(&pConfDescr[pos], pEP, size);
|
||||
|
||||
// Fill OTG description
|
||||
otg_descr.size = sizeof(otg_descr_t);
|
||||
otg_descr.type = 9; // OTG
|
||||
otg_descr.hnp_srp = 3; // HNP|SRP supported
|
||||
|
||||
// Copy OTG description
|
||||
pos += size;
|
||||
size = sizeof(ep_descr_t);
|
||||
memcpy(&pConfDescr[pos], &otg_descr, size);
|
||||
|
||||
pos += size;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
UINT32 str_write(UINT8 *pStrDescr, UINT8 *pStr0, UINT8 *pStr1, UINT8 *pStr2)
|
||||
{
|
||||
int i;
|
||||
UINT32 pos, size, strsize;
|
||||
str_descr_hdr_t *pStrHdr;
|
||||
UINT16 *pStr;
|
||||
|
||||
pos = 0;
|
||||
size = sizeof(str_descr_hdr_t);
|
||||
strsize = 2;
|
||||
pStrHdr = (str_descr_hdr_t*)&pStrDescr[pos];
|
||||
pStrHdr->size = size + strsize;
|
||||
pStrHdr->type = 3;
|
||||
|
||||
pos += size;
|
||||
pStr = (UINT16*)&pStrDescr[pos];
|
||||
|
||||
*pStr = 0x0409;
|
||||
|
||||
// String 0
|
||||
pos += size;
|
||||
size = sizeof(str_descr_hdr_t);
|
||||
strsize = strlen(pStr0);
|
||||
|
||||
pStrHdr = (str_descr_hdr_t*)&pStrDescr[pos];
|
||||
pStrHdr->size = sizeof(str_descr_hdr_t) + 2*strsize;
|
||||
pStrHdr->type = 3;
|
||||
|
||||
pos += size;
|
||||
size = 2*strsize;
|
||||
pStr = (UINT16*)&pStrDescr[pos];
|
||||
|
||||
for (i=0; i < strsize; i++)
|
||||
pStr[i] = (UINT16)pStr0[i];
|
||||
|
||||
// String 1
|
||||
pos += size;
|
||||
size = sizeof(str_descr_hdr_t);
|
||||
strsize = strlen(pStr1);
|
||||
|
||||
pStrHdr = (str_descr_hdr_t*)&pStrDescr[pos];
|
||||
pStrHdr->size = sizeof(str_descr_hdr_t) + 2*strsize;
|
||||
pStrHdr->type = 3;
|
||||
|
||||
pos += size;
|
||||
size = 2*strsize;
|
||||
pStr = (UINT16*)&pStrDescr[pos];
|
||||
|
||||
for (i=0; i < strsize; i++)
|
||||
pStr[i] = (UINT16)pStr1[i];
|
||||
|
||||
// String 2
|
||||
pos += size;
|
||||
size = sizeof(str_descr_hdr_t);
|
||||
strsize = strlen(pStr2);
|
||||
|
||||
pStrHdr = (str_descr_hdr_t*)&pStrDescr[pos];
|
||||
pStrHdr->size = sizeof(str_descr_hdr_t) + 2*strsize;
|
||||
pStrHdr->type = 3;
|
||||
|
||||
pos += size;
|
||||
size = 2*strsize;
|
||||
pStr = (UINT16*)&pStrDescr[pos];
|
||||
|
||||
for (i=0; i < strsize; i++)
|
||||
pStr[i] = (UINT16)pStr2[i];
|
||||
|
||||
pos += size;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
void ep0_func(void *pArg)
|
||||
{
|
||||
UINT32 result;
|
||||
UINT16 buf[USB_MAX_IMG_SIZE/2], ep_cntres, ep_status, ep_count, tsize;
|
||||
usb_irp_t *pIRP = (usb_irp_t*)pArg;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
ep_status = hpi_read_reg (SUSB2_REG_EP_STATUS0);
|
||||
ep_cntres = hpi_read_reg (SUSB2_REG_EP_CNTRES0);
|
||||
ep_count = hpi_read_reg (SUSB2_REG_EP_COUNT0);
|
||||
|
||||
if (ep_status & 0x10)
|
||||
{
|
||||
printf("Setup-flag detected. Status = %4.4X\n", ep_status);
|
||||
}
|
||||
}
|
||||
|
||||
void ep1_func(void *pArg)
|
||||
{
|
||||
UINT32 result;
|
||||
UINT16 buf[USB_MAX_IMG_SIZE/2], ep_cntres, ep_status, ep_count, tsize;
|
||||
usb_irp_t *pIRP = (usb_irp_t*)pArg;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
ep_status = hpi_read_reg (SUSB2_REG_EP_STATUS1);
|
||||
ep_cntres = hpi_read_reg (SUSB2_REG_EP_CNTRES1);
|
||||
ep_count = hpi_read_reg (SUSB2_REG_EP_COUNT1);
|
||||
|
||||
tsize = pIRP->tsize;
|
||||
if (ep_status & 0x0020)
|
||||
{
|
||||
printf("Length exception result %4.4X with count = %d\n", ep_status, (INT16)ep_cntres);
|
||||
if (ep_status & 0x0400)
|
||||
tsize = (UINT16)((INT16)tsize - (INT16)ep_cntres);
|
||||
if (ep_status & 0x0800)
|
||||
tsize = (UINT16)((INT16)tsize - (INT16)ep_cntres);
|
||||
|
||||
}
|
||||
result = hpi_read_ram(pIRP->cy_req.addr, buf, tsize);
|
||||
usb_irp_enqueue(pIRP);
|
||||
fifo_write(&pIRP->fifo, (UINT8*)buf, result, 0, FIFO_BLOCK);
|
||||
|
||||
// printf("Read %d bytes\n", result);
|
||||
|
||||
}
|
||||
|
||||
void ep2_func(void *pArg)
|
||||
{
|
||||
UINT32 result;
|
||||
UINT16 buf[USB_MAX_IMG_SIZE/2], ep_cntres, ep_status, ep_count, tsize;
|
||||
usb_irp_t *pIRP = (usb_irp_t*)pArg;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
ep_status = hpi_read_reg (SUSB2_REG_EP_STATUS2);
|
||||
ep_cntres = hpi_read_reg (SUSB2_REG_EP_CNTRES2);
|
||||
ep_count = hpi_read_reg (SUSB2_REG_EP_COUNT2);
|
||||
|
||||
tsize = pIRP->tsize;
|
||||
if (ep_status & 0x0020)
|
||||
{
|
||||
printf("Length exception result %4.4X with count = %d\n", ep_status, (INT16)ep_cntres);
|
||||
if (ep_status & 0x0400)
|
||||
tsize = (UINT16)((INT16)tsize - (INT16)ep_cntres);
|
||||
if (ep_status & 0x0800)
|
||||
tsize = (UINT16)((INT16)tsize - (INT16)ep_cntres);
|
||||
}
|
||||
|
||||
pIRP->tx_in_progress = 0;
|
||||
result = fifo_read(&pIRP->fifo, (UINT8*)buf, pIRP->tsize, 0, FIFO_NONBLOCK);
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
pIRP->cy_req.size = result;
|
||||
hpi_write_ram(pIRP->cy_req.addr, (UINT16*)buf, result);
|
||||
|
||||
usb_irp_enqueue(pIRP);
|
||||
|
||||
// printf("Wrote %d bytes\n", result);
|
||||
|
||||
}
|
||||
|
||||
void rst_func(void *pArg)
|
||||
{
|
||||
volatile int *pLED = (int*)SYS_LED_PORT;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
sputs("SUSB_RST_MSG\n");
|
||||
/// hpi_comm_reset();
|
||||
|
||||
_g_rst = 1;
|
||||
|
||||
*pLED = 0x40000000 + 1;
|
||||
|
||||
}
|
||||
|
||||
void sof_func(void *pArg)
|
||||
{
|
||||
volatile int *pLED = (int*)SYS_LED_PORT;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
sputs("SUSB_SOF_MSG\n");
|
||||
|
||||
*pLED = 0x40000000 + 2;
|
||||
|
||||
}
|
||||
|
||||
void cfg_func(void *pArg)
|
||||
{
|
||||
volatile int *pLED = (int*)SYS_LED_PORT;
|
||||
cfg_inst_t *pCFG = (cfg_inst_t*)pArg;
|
||||
usb_irp_t *pIRP_rx = (usb_irp_t*)pCFG->pIRP_rx;
|
||||
usb_irp_t *pIRP_tx = (usb_irp_t*)pCFG->pIRP_tx;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
sputs("SUSB_CFG_MSG\n");
|
||||
_g_cfg = 1;
|
||||
usb_irp_enqueue(pIRP_rx);
|
||||
fifo_flush(&pIRP_rx->fifo);
|
||||
fifo_flush(&pIRP_tx->fifo);
|
||||
pIRP_tx->tx_in_progress = 0;
|
||||
*pLED = 0;
|
||||
|
||||
}
|
||||
|
||||
void sus_func(void *pArg)
|
||||
{
|
||||
volatile int *pLED = (int*)SYS_LED_PORT;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
sputs("SUSB_SUS_MSG\n");
|
||||
|
||||
*pLED = 0x40000000 + 3;
|
||||
|
||||
_g_sus = 1;
|
||||
|
||||
}
|
||||
|
||||
void id_func(void *pArg)
|
||||
{
|
||||
volatile int *pLED = (int*)SYS_LED_PORT;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
sputs("SUSB_ID_MSG\n");
|
||||
|
||||
*pLED = 0x40000000 + 4;
|
||||
|
||||
}
|
||||
|
||||
void vbus_func(void *pArg)
|
||||
{
|
||||
volatile int *pLED = (int*)SYS_LED_PORT;
|
||||
|
||||
// printf("Callback with pArg = %8.8X\n", (UINT32)pArg);
|
||||
sputs("SUSB_VBUS_MSG\n");
|
||||
|
||||
*pLED = 0x40000000 + 5;
|
||||
|
||||
}
|
||||
|
||||
UINT32 usb_init_descr(void)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
UINT16 buffer16[0x100];
|
||||
UINT16 addr;
|
||||
dev_descr_t dev_descr = {sizeof(dev_descr_t), 1, 0x0200, 0xFF, 0, 0, 8, 0x04B4, 0x7200, 0x0099, 1, 2, 3, 1};
|
||||
ep_descr_t ep_descr[2] = {{sizeof(ep_descr_t), 5, 1, 2, 64, 0}, {sizeof(ep_descr_t), 5, 0x82, 2, 64, 0}};
|
||||
|
||||
// Set device descriptor
|
||||
addr = 0xf516; // default
|
||||
addr = 0xA00;
|
||||
hpi_write_ram(addr, (UINT16*)&dev_descr, sizeof(dev_descr_t));
|
||||
hpi_write_reg(2*SUSB2_DEVICE_DESCRIPTOR_VEC, addr);
|
||||
|
||||
// Set new configuration descriptor
|
||||
|
||||
// Write config and interface descriptor
|
||||
result = conf_write((UINT8*)buffer16, sizeof(ep_descr)/sizeof(ep_descr_t), ep_descr);
|
||||
|
||||
addr = 0xf528; // default
|
||||
addr = 0xB00;
|
||||
hpi_write_ram(addr, (UINT16*)buffer16, result);
|
||||
hpi_write_reg(2*SUSB2_CONFIGURATION_DESCRIPTOR_VEC, addr);
|
||||
|
||||
// Set string description
|
||||
result = str_write((UINT8*)buffer16, "JDI Inc.", "JDI-USB (MIPS)", "311070");
|
||||
addr = 0xf528; // default
|
||||
addr = 0xC00;
|
||||
hpi_write_ram(addr, (UINT16*)buffer16, result);
|
||||
hpi_write_reg(2*SUSB2_STRING_DESCRIPTOR_VEC, addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT32 usb_force_reconnect(UINT32 port)
|
||||
{
|
||||
UINT32 result;
|
||||
UINT16 addr;
|
||||
|
||||
if (port >= USB_MAX_NUM_PORTS)
|
||||
return -1;
|
||||
|
||||
if (port == 0)
|
||||
{
|
||||
// R1 = 0 : Full speed
|
||||
// R2 = 1 : SIE1
|
||||
addr = hpi_read_reg(SUSB1_REG_USBCTRL);
|
||||
hpi_write_reg(SUSB1_REG_USBCTRL, addr | 0x0010);
|
||||
result = hpi_comm_exec_int(SUSB_INIT_INT, 2, R1, 0, R2, 1);
|
||||
hpi_write_reg(SUSB1_REG_USBCTRL, addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// R1 = 0 : Full speed
|
||||
// R2 = 2 : SIE2
|
||||
addr = hpi_read_reg(SUSB2_REG_USBCTRL);
|
||||
hpi_write_reg(SUSB2_REG_USBCTRL, addr | 0x0010);
|
||||
result = hpi_comm_exec_int(SUSB_INIT_INT, 2, R1, 0, R2, 2);
|
||||
hpi_write_reg(SUSB2_REG_USBCTRL, addr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
UINT32 usb_recv(usb_irp_t *pObj, UINT8 *pData, UINT32 len, UINT32 timeout)
|
||||
{
|
||||
UINT32 result;
|
||||
|
||||
result = fifo_read(&pObj->fifo, pData, len, timeout, FIFO_BLOCK);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UINT32 usb_send(usb_irp_t *pObj, UINT8 *pData, UINT32 len, UINT32 timeout)
|
||||
{
|
||||
UINT32 result;
|
||||
UINT8 buf[USB_MAX_IMG_SIZE];
|
||||
|
||||
// Fill-up FIFO
|
||||
result = fifo_write(&pObj->fifo, pData, len, 0, FIFO_NONBLOCK);
|
||||
if (!result)
|
||||
return 0;
|
||||
|
||||
// Trigger TX
|
||||
if (!pObj->tx_in_progress)
|
||||
{
|
||||
pObj->cy_req.size = fifo_read(&pObj->fifo, (UINT8*)buf, pObj->tsize, 0, FIFO_NONBLOCK);
|
||||
hpi_write_ram(pObj->cy_req.addr, (UINT16*)buf, pObj->cy_req.size);
|
||||
usb_irp_enqueue(pObj);
|
||||
}
|
||||
|
||||
// If necessary, write rest to FIFO
|
||||
result += fifo_write(&pObj->fifo, &pData[result], len - result, timeout, FIFO_BLOCK);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
#define TEST_SIZE (2*1024*1024)
|
||||
#define TRANSFER_SIZE 64
|
||||
#define FLASH_IMAGE_SIZE (2*1024*1024)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
UINT32 result, sync, cmd, len, buf_count, led_count, remain, tx_cnt, flash_offset;
|
||||
UINT8 buffer8[2048];
|
||||
UINT16 buffer16[0x2000];
|
||||
UINT16 addr;
|
||||
volatile UINT32 *pLED = (UINT32*)SYS_LED_PORT;
|
||||
volatile UINT32 *pUART0_stat = (UINT32*)SYS_UART0_STAT;
|
||||
UINT32 start, end;
|
||||
UINT32 *pFlash32;
|
||||
UINT8 *pFlash8;
|
||||
UINT32 buffer32[16], *pBuf;
|
||||
UINT64 *pBuf64;
|
||||
usb_irp_t irp_rx, irp_tx;
|
||||
fifo_t fifo_rx, fifo_tx;
|
||||
cfg_inst_t cfg_inst;
|
||||
flash_t flash;
|
||||
volatile UINT32 *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
|
||||
volatile UINT32 *pVGA_front = (UINT32*)SYS_VGA_FB_FRONT;
|
||||
volatile UINT32 *pVGA_back = (UINT32*)SYS_VGA_FB_BACK;
|
||||
|
||||
_g_rst = 0;
|
||||
_g_sus = 0;
|
||||
_g_cfg = 0;
|
||||
|
||||
usb_init();
|
||||
|
||||
// enable EP#0 callback
|
||||
usb_callback_register(1, SUSB_EP0_MSG, ep0_func, NULL);
|
||||
|
||||
// enable EP#1 callback
|
||||
usb_irp_register(&irp_rx, 1, 1, TRANSFER_SIZE, 1);
|
||||
usb_callback_register(1, SUSB_EP1_MSG, ep1_func, &irp_rx);
|
||||
|
||||
// enable EP#2 callback
|
||||
usb_irp_register(&irp_tx, 1, 2, TRANSFER_SIZE, 0);
|
||||
usb_callback_register(1, SUSB_EP2_MSG, ep2_func, &irp_tx);
|
||||
|
||||
usb_callback_register(1, SUSB_RST_MSG, rst_func, NULL);
|
||||
usb_callback_register(1, SUSB_SOF_MSG, sof_func, NULL);
|
||||
cfg_inst.pIRP_rx = &irp_rx;
|
||||
cfg_inst.pIRP_tx = &irp_tx;
|
||||
usb_callback_register(1, SUSB_CFG_MSG, cfg_func, &cfg_inst);
|
||||
usb_callback_register(1, SUSB_SUS_MSG, sus_func, NULL);
|
||||
usb_callback_register(1, SUSB_ID_MSG, id_func, NULL);
|
||||
usb_callback_register(1, SUSB_VBUS_MSG, vbus_func, NULL);
|
||||
|
||||
printf("HPI-Test\n\n");
|
||||
|
||||
if (IS_ERROR(hpi_init()))
|
||||
{
|
||||
sputs("hpi_init(): error\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("cy67k3_reset\n");
|
||||
cy67k3_reset();
|
||||
|
||||
while(!_g_rst);
|
||||
|
||||
printf("hpi_comm_reset\n");
|
||||
hpi_comm_reset();
|
||||
|
||||
while(!_g_sus);
|
||||
|
||||
printf("usb_init_descr\n");
|
||||
usb_init_descr();
|
||||
printf("hpi_comm_exec_int\n");
|
||||
hpi_comm_exec_int(SUSB_INIT_INT, 2, R1, 0, R2, 2);
|
||||
printf("usb_force_reconnect\n");
|
||||
usb_force_reconnect(1);
|
||||
|
||||
while(!_g_cfg);
|
||||
|
||||
printf("USB-Ready\n");
|
||||
|
||||
printf("CY-Read..");
|
||||
start = clock();
|
||||
for (i=0; i < TEST_SIZE; i+=0x2000)
|
||||
hpi_read_ram(0x2000, buffer16, 0x2000);
|
||||
|
||||
end = clock();
|
||||
printf("done (%.2f Mbyte/s)\n", (double)TEST_SIZE/(1000*(end-start)));
|
||||
|
||||
printf("CY-Write..");
|
||||
start = clock();
|
||||
for (i=0; i < TEST_SIZE; i+=0x2000)
|
||||
hpi_write_ram(0x2000, buffer16, 0x2000);
|
||||
|
||||
end = clock();
|
||||
printf("done (%.2f Mbyte/s)\n", (double)TEST_SIZE/(1000*(end-start)));
|
||||
|
||||
sputs("HPI-Status : ");
|
||||
print_word(cy67k3_read_HPI_STATUS());
|
||||
sputs("\n");
|
||||
|
||||
sputs("HPI BP : ");
|
||||
print_word(hpi_read_reg(HPI_REG_BP));
|
||||
sputs("\n");
|
||||
|
||||
sputs("HPI IRR : ");
|
||||
print_word(hpi_read_reg(HPI_REG_INTROUTE));
|
||||
sputs("\n");
|
||||
|
||||
sputs("CPU Revision : ");
|
||||
print_word(hpi_comm_read_ctrl_reg(USB_REG_REVISON));
|
||||
sputs("\n");
|
||||
|
||||
hpi_comm_write_ctrl_reg(USB_REG_SPEED, 0x0000, LOGIC_DIRECT);
|
||||
sputs("CPU Speed : ");
|
||||
print_word(hpi_comm_read_ctrl_reg(USB_REG_SPEED));
|
||||
sputs("\n");
|
||||
|
||||
// usb_init_descr();
|
||||
// usb_force_reconnect(1);
|
||||
|
||||
// enable RX interrupt
|
||||
*pUART0_stat |= (1 << 6);
|
||||
interrupt_register(3, uart_handler);
|
||||
interrupt_enable(3);
|
||||
|
||||
// Enable EP#1
|
||||
hpi_write_reg(SUSB2_REG_EP_COUNT1, TRANSFER_SIZE);
|
||||
hpi_write_reg(SUSB2_REG_EP_CTRL1, 2);
|
||||
hpi_write_reg(SUSB2_REG_EP_CNTRES1, 0);
|
||||
hpi_write_reg(SUSB2_REG_EP_STATUS1, 0);
|
||||
|
||||
// Enable EP#2
|
||||
hpi_write_reg(SUSB2_REG_EP_COUNT2, TRANSFER_SIZE);
|
||||
hpi_write_reg(SUSB2_REG_EP_CTRL2, 2);
|
||||
hpi_write_reg(SUSB2_REG_EP_CNTRES2, 0);
|
||||
hpi_write_reg(SUSB2_REG_EP_STATUS2, 0);
|
||||
|
||||
led_count = 0;
|
||||
buf_count = 0;
|
||||
|
||||
pBuf64 = (UINT64*)malloc(FLASH_IMAGE_SIZE);
|
||||
pBuf = (UINT32*)pBuf64;
|
||||
|
||||
*pVGA_front = (UINT32)pBuf64;
|
||||
*pVGA_back = (UINT32)pBuf64;
|
||||
*pVGA_ctrl |= SYS_VGA_BIT_MSTEN;
|
||||
|
||||
if (IS_ERROR(flash_find(&flash, SYS_FLASH_IO)))
|
||||
{
|
||||
printf("Cannot find flash device. Exit now!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get flash offset by value of DIP-switch
|
||||
flash_offset = flash_get_offset_by_blocknum(&flash, flash.info.nblocks-FLASH_IMAGE_SIZE/flash.info.blocksize);
|
||||
printf("flash_offset: %08X\n", flash_offset);
|
||||
pFlash32 = (UINT32*)(SYS_FLASH_IO + flash_offset);
|
||||
pFlash8 = (UINT8*)pFlash32;
|
||||
|
||||
while(1)
|
||||
{
|
||||
switch (_g_uart_msg)
|
||||
{
|
||||
case '1':
|
||||
_g_uart_msg = 0;
|
||||
PrintDevRegs(1);
|
||||
printf("\nSIEmsg1: %4.4X\n", hpi_read_reg(HPI_REG_SIE1MSG));
|
||||
break;
|
||||
|
||||
case '2':
|
||||
_g_uart_msg = 0;
|
||||
PrintDevRegs(2);
|
||||
printf("\nSIEmsg2: %4.4X\n", hpi_read_reg(HPI_REG_SIE2MSG));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
result = usb_recv(&irp_rx, (UINT8*)&sync, 4, 100);
|
||||
if (!result)
|
||||
continue;
|
||||
|
||||
*pLED = led_count++;
|
||||
|
||||
if (sync == 0xC24755AA)
|
||||
{
|
||||
printf("Sync found\n");
|
||||
result = usb_recv(&irp_rx, (UINT8*)&cmd, 4, 1000);
|
||||
if (!result)
|
||||
continue;
|
||||
|
||||
result = usb_recv(&irp_rx, (UINT8*)&len, 4, 1000);
|
||||
if (!result)
|
||||
continue;
|
||||
|
||||
printf("Command %d with len %d found\n",cmd, len);
|
||||
switch(cmd)
|
||||
{
|
||||
case 0x00000001:
|
||||
result = usb_recv(&irp_rx, NULL, len, 1000);
|
||||
if (result)
|
||||
{
|
||||
printf("Read %d bytes\n", result);
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00000002:
|
||||
remain = len;
|
||||
tx_cnt = 0;
|
||||
while(remain)
|
||||
{
|
||||
len = sizeof(buffer8);
|
||||
if (remain < len)
|
||||
len = remain;
|
||||
|
||||
for (i=0; i < len; i++)
|
||||
buffer8[i] = buf_count+i;
|
||||
|
||||
result = usb_send(&irp_tx, buffer8, len, 1000);
|
||||
if (!result)
|
||||
break;
|
||||
tx_cnt += result;
|
||||
remain -= result;
|
||||
buf_count++;
|
||||
}
|
||||
printf("Wrote %d bytes\n", tx_cnt);
|
||||
break;
|
||||
|
||||
case 0x00000003:
|
||||
remain = len;
|
||||
tx_cnt = 0;
|
||||
while(remain)
|
||||
{
|
||||
len = 256;
|
||||
if (remain < len)
|
||||
len = remain;
|
||||
|
||||
result = usb_send(&irp_tx, (UINT8*)&pFlash8[tx_cnt], len, 1000);
|
||||
if (!result)
|
||||
break;
|
||||
tx_cnt += result;
|
||||
remain -= result;
|
||||
buf_count++;
|
||||
}
|
||||
printf("Wrote %d bytes\n", tx_cnt);
|
||||
break;
|
||||
|
||||
case 0x00000004:
|
||||
*pVGA_ctrl &= ~SYS_VGA_BIT_MSTEN;
|
||||
result = usb_recv(&irp_rx, (UINT8*)pBuf, len, 1000);
|
||||
if (result)
|
||||
{
|
||||
printf("Read %d bytes\n", result);
|
||||
}
|
||||
|
||||
len = result;
|
||||
if (len > FLASH_IMAGE_SIZE)
|
||||
{
|
||||
printf("Cannot write flash: image to large!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Flash erase...");
|
||||
result = flash_erase(&flash, flash_offset, len);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf("failed (%08X)\n", result);
|
||||
break;
|
||||
}
|
||||
printf("done\n");
|
||||
|
||||
printf("Flash write...");
|
||||
result = flash_program(&flash, flash_offset, (UINT8*)pBuf, len);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf("failed (%08X)\n", result);
|
||||
break;
|
||||
}
|
||||
printf("done\n");
|
||||
|
||||
printf("Flash verify...");
|
||||
result = flash_verify(&flash, flash_offset, (UINT8*)pBuf, len);
|
||||
if (IS_ERROR(result))
|
||||
{
|
||||
printf("failed (%08X)\n", result);
|
||||
break;
|
||||
}
|
||||
printf("passed\n");
|
||||
*pVGA_ctrl |= SYS_VGA_BIT_MSTEN;
|
||||
break;
|
||||
|
||||
case 0x000000FF:
|
||||
usb_force_reconnect(1);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// pMem = (UINT8*)0x40000000;
|
||||
// result = fifo_write(&fifo_tx, pMem, 640, 0, FIFO_NONBLOCK);
|
||||
// pMem += result;
|
||||
// usb_irp_enqueue(&irp_tx);
|
||||
@@ -1,335 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define CPU_FREQ_HZ 100000000
|
||||
#include "libsys.h"
|
||||
#include "irq.h"
|
||||
#include "mips_gfx.h"
|
||||
#include "mips_ps2.h"
|
||||
|
||||
char buffer[16384];
|
||||
char * volatile pPtr_r;
|
||||
char * volatile pPtr_w;
|
||||
static volatile INT32 mouse_x;
|
||||
static volatile INT32 mouse_y;
|
||||
static box_t box;
|
||||
static gfx_t gfx;
|
||||
static volatile int _g_posx, _g_posy;
|
||||
static volatile g_btn_l, g_btn_r;
|
||||
static volatile UINT32 g_color;
|
||||
|
||||
// -------------------------------------------------------------
|
||||
void handler0(void)
|
||||
{
|
||||
printf("Interrupt 0\n");
|
||||
interrupt_clr(0);
|
||||
}
|
||||
|
||||
void handler1(void)
|
||||
{
|
||||
printf("Interrupt 1\n");
|
||||
interrupt_clr(1);
|
||||
}
|
||||
|
||||
void handler2(void)
|
||||
{
|
||||
printf("Interrupt 2\n");
|
||||
}
|
||||
|
||||
void handler3(void)
|
||||
{
|
||||
volatile UINT32 *pUART0_stat = (UINT32*)SYS_UART0_STAT;
|
||||
volatile UINT32 *pUART0_data = (UINT32*)SYS_UART0_DATA;
|
||||
volatile UINT32 *pUART1_stat = (UINT32*)SYS_UART1_STAT;
|
||||
volatile UINT32 *pUART1_data = (UINT32*)SYS_UART1_DATA;
|
||||
|
||||
while(0x200 & *pUART0_stat)
|
||||
{
|
||||
// sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
||||
if (pPtr_w == &buffer[16383])
|
||||
pPtr_w = buffer;
|
||||
*(pPtr_w++) = *pUART0_data;
|
||||
}
|
||||
|
||||
while(0x200 & *pUART1_stat)
|
||||
{
|
||||
// sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
||||
if (pPtr_w == &buffer[16383])
|
||||
pPtr_w = buffer;
|
||||
*(pPtr_w++) = *pUART1_data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void handler4(void)
|
||||
{
|
||||
printf("Interrupt 4\n");
|
||||
}
|
||||
|
||||
void handler5(void)
|
||||
{
|
||||
UINT32 volatile *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
|
||||
|
||||
// Ack
|
||||
*pVGA_ctrl |= SYS_VGA_BIT_BUFCHG_FLAG;
|
||||
|
||||
}
|
||||
|
||||
void handler6(void)
|
||||
{
|
||||
int p, i;
|
||||
ps2_if_t *pIF;
|
||||
UINT8 mouse_rsp[3];
|
||||
UINT32 timeout_count, key;
|
||||
|
||||
INT32 dx, dy;
|
||||
|
||||
for (p=0; p < PS2_get_num_if(); p++)
|
||||
{
|
||||
pIF = PS2_get_if(p);
|
||||
if (SYS_PS2_BIT_RX_ERR_FLAG & *pIF->pCTRL)
|
||||
fprintf(stderr, "PS2[%d]: Status = 0x%08X\n", p, *pIF->pCTRL);
|
||||
|
||||
if (pIF->type == ps2_type_keyb)
|
||||
{
|
||||
while(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL)
|
||||
{
|
||||
key = *pIF->pDATA;
|
||||
printf("Keyboard scan code = 0x%02X\n", key);
|
||||
}
|
||||
}
|
||||
if (pIF->type == ps2_type_mouse)
|
||||
{
|
||||
if(!(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL))
|
||||
continue;
|
||||
|
||||
for (i=0; i < 3; i++)
|
||||
{
|
||||
timeout_count = 100;
|
||||
while(!(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL))
|
||||
{
|
||||
timeout_count--;
|
||||
if (!timeout_count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
if (!timeout_count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
mouse_rsp[i] = (UINT8)*pIF->pDATA;
|
||||
}
|
||||
if (!timeout_count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
dx = mouse_rsp[1];
|
||||
if (mouse_rsp[0] & 0x10)
|
||||
dx |= 0xFFFFFF00;
|
||||
dy = mouse_rsp[2];
|
||||
if (mouse_rsp[0] & 0x20)
|
||||
dy |= 0xFFFFFF00;
|
||||
|
||||
// printf("dx = %5d, dy = %5d\n", dx, dy);
|
||||
|
||||
mouse_x += dx;
|
||||
mouse_y -= dy;
|
||||
g_btn_l = 0;
|
||||
if (mouse_rsp[0] & 0x01)
|
||||
g_btn_l = 1;
|
||||
|
||||
if (mouse_rsp[0] & 0x02)
|
||||
{
|
||||
if (g_btn_r == 0)
|
||||
{
|
||||
g_color = (UINT32)rand();
|
||||
}
|
||||
g_btn_r = 1;
|
||||
}
|
||||
else
|
||||
g_btn_r = 0;
|
||||
|
||||
|
||||
if (mouse_x < 0)
|
||||
mouse_x = 0;
|
||||
if (mouse_y < 0)
|
||||
mouse_y = 0;
|
||||
if (mouse_x > (gfx.w-1))
|
||||
mouse_x = gfx.w-1;
|
||||
if (mouse_y >= (gfx.h-1))
|
||||
mouse_y = gfx.h-1;
|
||||
|
||||
// Screen_csr_set_x(mouse_x);
|
||||
// Screen_csr_set_y(mouse_y);
|
||||
|
||||
// printf("x = %5d, y = %5d\n", mouse_x, mouse_y);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handler7(void)
|
||||
{
|
||||
printf("Interrupt 7\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
int i;
|
||||
volatile UINT32 *pUART0_stat = (UINT32*)SYS_UART0_STAT;
|
||||
volatile UINT32 *pUART1_stat = (UINT32*)SYS_UART1_STAT;
|
||||
volatile UINT32 *pUART0_baud = (UINT32*)SYS_UART0_BAUD;
|
||||
volatile UINT32 *pUART1_baud = (UINT32*)SYS_UART1_BAUD;
|
||||
UINT32 volatile *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
|
||||
UINT32 volatile *pVGA_moffs_0 = (UINT32*)SYS_VGA_FB_FRONT;
|
||||
UINT32 volatile *pVGA_moffs_1 = (UINT32*)SYS_VGA_FB_BACK;
|
||||
UINT32 volatile *pVGA_cgcol = (UINT32*)SYS_VGA_CGCOL;
|
||||
UINT32 volatile *pFlashPicture = (UINT32*)(SYS_FLASH_MEM + 0x00600000);
|
||||
UINT32 framecount;
|
||||
UINT32 start, end;
|
||||
char string[65];
|
||||
|
||||
interrupt_register(0, (void*)handler0);
|
||||
interrupt_register(1, (void*)handler1);
|
||||
// interrupt_register(2, (void*)handler2);
|
||||
interrupt_register(3, (void*)handler3);
|
||||
// interrupt_register(4, (void*)handler4);
|
||||
// interrupt_register(5, (void*)handler5);
|
||||
interrupt_register(6, (void*)handler6);
|
||||
interrupt_register(7, (void*)handler7);
|
||||
|
||||
srand(clock());
|
||||
UART1_setbaud(460800);
|
||||
printf("Hello\n");
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
*pVGA_cgcol = 0x00FFFFFF;
|
||||
_g_posx = _g_posy = 0;
|
||||
g_color = 0xFFFFFFFF;
|
||||
GFX_init(&gfx);
|
||||
|
||||
GFX_set_background(&gfx, pFlashPicture, 800, 600, 1, 1);
|
||||
box_create(&box, 256, 256);
|
||||
GFX_box_draw(&gfx, &box, _g_posx, _g_posy, g_color);
|
||||
GFX_show(&gfx);
|
||||
printf("VGA status = %08X\n", *pVGA_ctrl);
|
||||
|
||||
pPtr_r = buffer;
|
||||
pPtr_w = buffer;
|
||||
|
||||
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
||||
printf("UART0 Baud = 0x%8.8X\n", *pUART0_baud);
|
||||
printf("UART1 Status = 0x%8.8X\n", *pUART1_stat);
|
||||
printf("UART1 Baud = 0x%8.8X\n", *pUART1_baud);
|
||||
|
||||
// UART: enable RX interrupt
|
||||
*pUART0_stat |= (1 << 6);
|
||||
*pUART1_stat |= (1 << 6);
|
||||
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
||||
printf("UART1 Status = 0x%8.8X\n", *pUART1_stat);
|
||||
|
||||
PS2_init(0);
|
||||
PS2_init(1);
|
||||
|
||||
sputs("r: "); print_word((int)pPtr_r); sputs("\n");
|
||||
sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
||||
|
||||
// Print Status register
|
||||
sputs("Status : ");
|
||||
print_word(CP0_SR_read());
|
||||
sputs("\n");
|
||||
sputs("\n");
|
||||
|
||||
interrupt_disable(6);
|
||||
printf("Bitte gebe ein: ");
|
||||
scanf("%s", string);
|
||||
printf("Du schriebst: %s\n", string);
|
||||
|
||||
// Flush buffer
|
||||
PS2_flush(0);
|
||||
PS2_flush(1);
|
||||
|
||||
printf("Start:\n");
|
||||
|
||||
interrupt_enable(0);
|
||||
interrupt_enable(1);
|
||||
// interrupt_enable(2);
|
||||
interrupt_enable(3);
|
||||
// interrupt_enable(4);
|
||||
// interrupt_enable(5);
|
||||
interrupt_enable(6);
|
||||
interrupt_enable(7);
|
||||
|
||||
interrupt_set(0);
|
||||
interrupt_set(1);
|
||||
interrupt_set(2);
|
||||
interrupt_set(3);
|
||||
interrupt_set(4);
|
||||
interrupt_set(5);
|
||||
interrupt_set(6);
|
||||
interrupt_set(7);
|
||||
|
||||
// while(1)
|
||||
// {
|
||||
// printf("PS2-Status : 0x%08X\n", *(ps2_if[0].pCTRL));
|
||||
// printf("PS2-Data : 0x%08X\n", *(ps2_if[0].pDATA));
|
||||
// sleep(1000);
|
||||
// }
|
||||
|
||||
interrupt_enable(6);
|
||||
framecount = Screen_get_fps();
|
||||
start = clock();
|
||||
|
||||
while(1)
|
||||
{
|
||||
if (!framecount)
|
||||
{
|
||||
end = clock();
|
||||
framecount = Screen_get_fps();
|
||||
printf("%f FPS\n", (float)framecount/((float)(end-start)/CLOCKS_PER_SEC));
|
||||
start = clock();
|
||||
}
|
||||
|
||||
GFX_frame(&gfx, GFX_FRAME_SYNC);
|
||||
framecount--;
|
||||
|
||||
while ((_g_posx != (UINT32)mouse_x) || (_g_posy != (UINT32)mouse_y) || g_btn_r || g_btn_l)
|
||||
{
|
||||
|
||||
GFX_restore(&gfx, &box, _g_posx, _g_posy);
|
||||
|
||||
_g_posx = (UINT32)mouse_x;
|
||||
_g_posy = (UINT32)mouse_y;
|
||||
|
||||
if (g_btn_l && !g_btn_r)
|
||||
{
|
||||
GFX_box_draw_bg(&gfx, &box, _g_posx, _g_posy, g_color);
|
||||
}
|
||||
|
||||
if (g_btn_l && g_btn_r)
|
||||
{
|
||||
GFX_set_background(&gfx, pFlashPicture, 800, 600, 1, 1);
|
||||
}
|
||||
|
||||
GFX_box_draw(&gfx, &box, _g_posx, _g_posy, g_color);
|
||||
break;
|
||||
}
|
||||
GFX_show(&gfx);
|
||||
|
||||
if(pPtr_w != pPtr_r)
|
||||
{
|
||||
// sputs("r: "); print_word((int)pPtr_r); sputs("\n");
|
||||
if (pPtr_r == &buffer[16383])
|
||||
pPtr_r = buffer;
|
||||
writechar(0, *(pPtr_r++));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,265 +0,0 @@
|
||||
/*
|
||||
* @(#)whet.c 1.1
|
||||
*/
|
||||
|
||||
/*
|
||||
* Whetstone benchmark in C. This program is a translation of the
|
||||
* original Algol version in "A Synthetic Benchmark" by H.J. Curnow
|
||||
* and B.A. Wichman in Computer Journal, Vol 19 #1, February 1976.
|
||||
*
|
||||
* Used to test compiler optimization and floating point performance.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compile with -DMEASURE_TIME for time measurement.
|
||||
*
|
||||
* Compile with -DPOUT to print intermediate results.
|
||||
* Running this benchmark without printing the intermediate results is
|
||||
* contrary to the authors' intentions! But using serial I/O can draw back
|
||||
* the performance extremely when low baud rate communication is used.
|
||||
*/
|
||||
#define MEASURE_TIME 1
|
||||
//#define POUT 1
|
||||
|
||||
#define ITERATIONS 10 /* 10 Million Whetstone instructions */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef MEASURE_TIME
|
||||
#include <time.h>
|
||||
unsigned long Begin_Time,End_Time,Total_Time;
|
||||
double whetstones;
|
||||
#endif
|
||||
|
||||
#define Pout(n, j, k, x1, x2, x3, x4) pout(n, j, k, x1, x2, x3, x4);
|
||||
|
||||
double xx1, xx2, xx3, xx4, x, y, z, t, t1, t2;
|
||||
double e1[4];
|
||||
unsigned int i, j, k, l, n1, n2, n3, n4, n6, n7, n8, n9, n10, n11;
|
||||
|
||||
main()
|
||||
{
|
||||
printf("\nWhetstone Benchmark\n\n");
|
||||
|
||||
printf( "%d iterations\n", ITERATIONS );
|
||||
|
||||
#ifdef MEASURE_TIME
|
||||
Begin_Time = clock();
|
||||
#endif
|
||||
|
||||
/* initialize constants */
|
||||
|
||||
t = 0.499975;
|
||||
t1 = 0.50025;
|
||||
t2 = 2.0;
|
||||
|
||||
/* set values of module weights */
|
||||
|
||||
n1 = 0 * ITERATIONS;
|
||||
n2 = 12 * ITERATIONS;
|
||||
n3 = 14 * ITERATIONS;
|
||||
n4 = 345 * ITERATIONS;
|
||||
n6 = 210 * ITERATIONS;
|
||||
n7 = 32 * ITERATIONS;
|
||||
n8 = 899 * ITERATIONS;
|
||||
n9 = 616 * ITERATIONS;
|
||||
n10 = 0 * ITERATIONS;
|
||||
n11 = 93 * ITERATIONS;
|
||||
|
||||
/* MODULE 1: simple identifiers */
|
||||
|
||||
xx1 = 1.0;
|
||||
xx2 = xx3 = xx4 = -1.0;
|
||||
|
||||
for(i = 1; i <= n1; i += 1) {
|
||||
xx1 = ( xx1 + xx2 + xx3 - xx4 ) * t;
|
||||
xx2 = ( xx1 + xx2 - xx3 + xx4 ) * t;
|
||||
xx3 = ( xx1 - xx2 + xx3 + xx4 ) * t;
|
||||
xx4 = (-xx1 + xx2 + xx3 + xx4 ) * t;
|
||||
}
|
||||
#ifdef POUT
|
||||
Pout(n1, n1, n1, xx1, xx2, xx3, xx4);
|
||||
#endif
|
||||
|
||||
|
||||
/* MODULE 2: array elements */
|
||||
|
||||
e1[0] = 1.0;
|
||||
e1[1] = e1[2] = e1[3] = -1.0;
|
||||
|
||||
for (i = 1; i <= n2; i +=1) {
|
||||
e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
|
||||
e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
|
||||
e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
|
||||
e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
|
||||
}
|
||||
#ifdef POUT
|
||||
Pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
|
||||
#endif
|
||||
|
||||
/* MODULE 3: array as parameter */
|
||||
|
||||
for (i = 1; i <= n3; i += 1)
|
||||
pa(e1);
|
||||
#ifdef POUT
|
||||
Pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
|
||||
#endif
|
||||
|
||||
/* MODULE 4: conditional jumps */
|
||||
|
||||
j = 1;
|
||||
for (i = 1; i <= n4; i += 1) {
|
||||
if (j == 1)
|
||||
j = 2;
|
||||
else
|
||||
j = 3;
|
||||
|
||||
if (j > 2)
|
||||
j = 0;
|
||||
else
|
||||
j = 1;
|
||||
|
||||
if (j < 1 )
|
||||
j = 1;
|
||||
else
|
||||
j = 0;
|
||||
}
|
||||
#ifdef POUT
|
||||
Pout(n4, j, j, xx1, xx2, xx3, xx4);
|
||||
#endif
|
||||
|
||||
/* MODULE 5: omitted */
|
||||
|
||||
/* MODULE 6: integer arithmetic */
|
||||
|
||||
j = 1;
|
||||
k = 2;
|
||||
l = 3;
|
||||
|
||||
for (i = 1; i <= n6; i += 1) {
|
||||
j = j * (k - j) * (l -k);
|
||||
k = l * k - (l - j) * k;
|
||||
l = (l - k) * (k + j);
|
||||
|
||||
e1[l - 2] = j + k + l; /* C arrays are zero based */
|
||||
e1[k - 2] = j * k * l;
|
||||
}
|
||||
#ifdef POUT
|
||||
Pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
|
||||
#endif
|
||||
|
||||
/* MODULE 7: trig. functions */
|
||||
|
||||
x = y = 0.5;
|
||||
|
||||
for(i = 1; i <= n7; i +=1) {
|
||||
x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
|
||||
y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
|
||||
}
|
||||
#ifdef POUT
|
||||
Pout(n7, j, k, x, x, y, y);
|
||||
#endif
|
||||
|
||||
/* MODULE 8: procedure calls */
|
||||
|
||||
x = y = z = 1.0;
|
||||
|
||||
for (i = 1; i <= n8; i +=1)
|
||||
p3(x, y, &z);
|
||||
#ifdef POUT
|
||||
Pout(n8, j, k, x, y, z, z);
|
||||
#endif
|
||||
|
||||
/* MODULE9: array references */
|
||||
|
||||
j = 1;
|
||||
k = 2;
|
||||
l = 3;
|
||||
|
||||
e1[0] = 1.0;
|
||||
e1[1] = 2.0;
|
||||
e1[2] = 3.0;
|
||||
|
||||
for(i = 1; i <= n9; i += 1)
|
||||
p0();
|
||||
#ifdef POUT
|
||||
Pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
|
||||
#endif
|
||||
|
||||
/* MODULE10: integer arithmetic */
|
||||
|
||||
j = 2;
|
||||
k = 3;
|
||||
|
||||
for(i = 1; i <= n10; i +=1) {
|
||||
j = j + k;
|
||||
k = j + k;
|
||||
j = k - j;
|
||||
k = k - j - j;
|
||||
}
|
||||
#ifdef POUT
|
||||
Pout(n10, j, k, xx1, xx2, xx3, xx4);
|
||||
#endif
|
||||
|
||||
/* MODULE11: standard functions */
|
||||
|
||||
x = 0.75;
|
||||
for(i = 1; i <= n11; i +=1)
|
||||
x = sqrt( exp( log(x) / t1));
|
||||
|
||||
#ifdef POUT
|
||||
Pout(n11, j, k, x, x, x, x);
|
||||
#endif
|
||||
|
||||
#ifdef MEASURE_TIME
|
||||
End_Time = clock();
|
||||
|
||||
Total_Time = End_Time - Begin_Time; /* in 1/ seconds */
|
||||
|
||||
whetstones = (1e5 * ITERATIONS * CLOCKS_PER_SEC) / Total_Time;
|
||||
printf("\nWhetstone runs in %ld clock ticks (%d). %ld Kwhets/second\n",
|
||||
Total_Time, CLOCKS_PER_SEC, (long) whetstones / 1000 );
|
||||
#endif
|
||||
}
|
||||
|
||||
pa(e)
|
||||
double e[4];
|
||||
{
|
||||
register int j;
|
||||
|
||||
j = 0;
|
||||
lab:
|
||||
e[0] = ( e[0] + e[1] + e[2] - e[3] ) * t;
|
||||
e[1] = ( e[0] + e[1] - e[2] + e[3] ) * t;
|
||||
e[2] = ( e[0] - e[1] + e[2] + e[3] ) * t;
|
||||
e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
|
||||
j += 1;
|
||||
if (j < 6)
|
||||
goto lab;
|
||||
}
|
||||
|
||||
p3(x, y, z)
|
||||
double x, y, *z;
|
||||
{
|
||||
x = t * (x + y);
|
||||
y = t * (x + y);
|
||||
*z = (x + y) /t2;
|
||||
}
|
||||
|
||||
p0()
|
||||
{
|
||||
e1[j] = e1[k];
|
||||
e1[k] = e1[l];
|
||||
e1[l] = e1[j];
|
||||
}
|
||||
|
||||
#ifdef POUT
|
||||
pout(n, j, k, x1, x2, x3, x4)
|
||||
unsigned int n, j, k;
|
||||
double x1, x2, x3, x4;
|
||||
{
|
||||
printf("%5u %5u %5u %11.3e %11.3e %11.3e %11.3e\n",
|
||||
n, j, k, x1, x2, x3, x4);
|
||||
}
|
||||
#endif
|
||||
@@ -1,46 +0,0 @@
|
||||
# ---------------------------------------------------------------
|
||||
# 1. Binutils bauen und installieren
|
||||
# ---------------------------------------------------------------
|
||||
> tar -xzf binutils-2.19.tar.gz
|
||||
> mkdir binutils-2.19_build
|
||||
> cd binutils-2.19_build
|
||||
|
||||
> ../binutils-2.19/configure --target=mipsel-elf --prefix=/usr/local
|
||||
> make
|
||||
> make install
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# 2. GCC bootstrapping
|
||||
# ---------------------------------------------------------------
|
||||
> tar -xzf gcc-4.3.2.tar.gz
|
||||
> mkdir gcc-4.3.2_build
|
||||
> cd gcc-4.3.2_build
|
||||
> ../gcc-4.3.2/configure --target=mipsel-elf --prefix=/usr/local --enable-languages="c,c++" --without-headers --with-newlib --with-float=soft --disable-multilib
|
||||
> CFLAGS_FOR_TARGET="-mno-gpopt" make all-gcc
|
||||
> make info-gcc
|
||||
> make install-gcc
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# 3. Newlib bauen und installieren
|
||||
# ---------------------------------------------------------------
|
||||
> tar -xzf newlib-1.16.0.tar.gz
|
||||
! Bug in newlib-1.16.0/newlib/libc/machine/mips/strlen.c.
|
||||
Newlib von Hand patchen (32-bit MIPS targets):
|
||||
"lbu $3,0($4)\n"
|
||||
"nop\n" <= nop einfügen
|
||||
"bnez $3,1b\n"
|
||||
|
||||
> mkdir newlib-1.16.0_build
|
||||
> cd newlib-1.16.0_build
|
||||
> ../newlib-1.16.0/configure --target=mipsel-elf --prefix=/usr/local --with-float=soft --disable-multilib
|
||||
> TARGET_CFLAGS="-mno-gpopt" make all
|
||||
> make install
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# 4. GCC bauen und installieren
|
||||
# ---------------------------------------------------------------
|
||||
> cd gcc-4.3.2_build
|
||||
> ../gcc-4.3.2/configure --target=mipsel-elf --prefix=/usr/local --enable-languages="c,c++" --disable-shared --with-newlib --with-float=soft --disable-multilib
|
||||
> CFLAGS_FOR_TARGET="-mno-gpopt" make all
|
||||
> make info
|
||||
> make install
|
||||
@@ -1,151 +0,0 @@
|
||||
#!/bin/sh
|
||||
TARGET=mipsel-elf
|
||||
PREFIX=/usr/local
|
||||
|
||||
SRC_BINUTILS=binutils-2.19
|
||||
SRC_GCC=gcc-4.3.3
|
||||
SRC_NEWLIB=newlib-1.16.0
|
||||
SRC_GMP=gmp-4.2.4
|
||||
SRC_MPFR=mpfr-2.4.0
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# 1. Binutils bauen und installieren
|
||||
# ---------------------------------------------------------------
|
||||
if [ ! -e $SRC_BINUTILS.tar.bz2 ]; then
|
||||
echo Downloading $SRC_BINUTILS
|
||||
wget ftp://ftp-stud.fht-esslingen.de/pub/Mirrors/ftp.gnu.org/binutils/$SRC_BINUTILS.tar.bz2 || exit 1
|
||||
else
|
||||
echo Skipped downloading $SRC_BINUTILS
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_BINUTILS ]; then
|
||||
echo Unpacking $SRC_BINUTILS
|
||||
tar -xjf $SRC_BINUTILS.tar.bz2 || exit 1
|
||||
else
|
||||
echo Skipped unpacking $SRC_BINUTILS
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_BINUTILS-build ]; then
|
||||
echo Building $SRC_BINUTILS
|
||||
mkdir -p $SRC_BINUTILS-build
|
||||
cd $SRC_BINUTILS-build
|
||||
../$SRC_BINUTILS/configure --target=$TARGET --prefix=$PREFIX || exit 1
|
||||
make || exit 1
|
||||
make install || exit 1
|
||||
cd ..
|
||||
else
|
||||
echo $SRC_BINUTILS is already built.
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# 2. GMP bauen und installieren
|
||||
# ---------------------------------------------------------------
|
||||
if [ ! -e $SRC_GMP.tar.bz2 ]; then
|
||||
echo Downloading $SRC_GMP
|
||||
wget http://ftp.sunet.se/pub/gnu/gmp/$SRC_GMP.tar.bz2 || exit 1
|
||||
else
|
||||
echo Skipped downloading $SRC_GMP
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_GMP ]; then
|
||||
echo Unpacking $SRC_GMP
|
||||
tar -xjf $SRC_GMP.tar.bz2 || exit 1
|
||||
else
|
||||
echo Skipped unpacking $SRC_GMP
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_GMP-build ]; then
|
||||
echo Building $SRC_GMP
|
||||
mkdir -p $SRC_GMP-build
|
||||
cd $SRC_GMP-build
|
||||
../$SRC_GMP/configure --prefix=$PREFIX || exit 1
|
||||
make || exit 1
|
||||
make check || exit 1
|
||||
make install || exit 1
|
||||
cd ..
|
||||
else
|
||||
echo $SRC_GMP is already built.
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# 3. MPFR bauen und installieren
|
||||
# ---------------------------------------------------------------
|
||||
if [ ! -e $SRC_MPFR.tar.bz2 ]; then
|
||||
echo Downloading $SRC_MPFR
|
||||
wget http://www.mpfr.org/mpfr-current/$SRC_MPFR.tar.bz2 || exit 1
|
||||
else
|
||||
echo Skipped downloading $SRC_MPFR
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_MPFR ]; then
|
||||
echo Unpacking $SRC_MPFR
|
||||
tar -xjf $SRC_MPFR.tar.bz2 || exit 1
|
||||
else
|
||||
echo Skipped unpacking $SRC_MPFR
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_MPFR-build ]; then
|
||||
echo Building $SRC_MPFR
|
||||
mkdir -p $SRC_MPFR-build
|
||||
cd $SRC_MPFR-build
|
||||
../$SRC_MPFR/configure --prefix=$PREFIX || exit 1
|
||||
make || exit 1
|
||||
make check || exit 1
|
||||
make install || exit 1
|
||||
cd ..
|
||||
else
|
||||
echo $SRC_MPFR is already built.
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# 4. GCC & newlib bauen und installieren
|
||||
# ---------------------------------------------------------------
|
||||
if [ ! -e $SRC_NEWLIB.tar.gz ]; then
|
||||
echo Downloading $SRC_NEWLIB
|
||||
wget ftp://sources.redhat.com/pub/newlib/$SRC_NEWLIB.tar.gz || exit 1
|
||||
else
|
||||
echo Skipped downloading $SRC_NEWLIB
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_NEWLIB ]; then
|
||||
echo Unpacking $SRC_NEWLIB
|
||||
tar -xzf $SRC_NEWLIB.tar.gz || exit 1
|
||||
if [ -e $SRC_NEWLIB-jens.patch ]; then
|
||||
echo Patching $SRC_NEWLIB
|
||||
patch -p0 < $SRC_NEWLIB-jens.patch || exit 1
|
||||
fi
|
||||
else
|
||||
echo Skipped unpacking $SRC_NEWLIB
|
||||
fi
|
||||
|
||||
if [ ! -e $SRC_GCC.tar.bz2 ]; then
|
||||
echo Downloading $SRC_GCC
|
||||
wget ftp://ftp-stud.fht-esslingen.de/pub/Mirrors/ftp.gnu.org/gcc/$SRC_GCC/$SRC_GCC.tar.bz2 || exit 1
|
||||
else
|
||||
echo Skipped downloading $SRC_GCC
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_GCC ]; then
|
||||
echo Unpacking $SRC_GCC
|
||||
tar -xjf $SRC_GCC.tar.bz2 || exit 1
|
||||
cd ./$SRC_GCC
|
||||
ln -sf ../$SRC_NEWLIB/newlib/ .
|
||||
cd ..
|
||||
else
|
||||
echo Skipped unpacking $SRC_GCC
|
||||
fi
|
||||
|
||||
if [ ! -e ./$SRC_GCC-build ]; then
|
||||
echo Building $SRC_GCC
|
||||
mkdir -p $SRC_GCC-build
|
||||
cd $SRC_GCC-build
|
||||
../$SRC_GCC/configure --target=$TARGET --prefix=$PREFIX --with-float=soft --with-newlib --verbose --enable-languages="c,c++" || exit 1
|
||||
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PREFIX/lib make all || exit 1
|
||||
make info || exit 1
|
||||
make install || exit 1
|
||||
cd ..
|
||||
echo $PREFIX/lib >/etc/ld.so.conf.d/local.conf
|
||||
ldconfig
|
||||
else
|
||||
echo $SRC_GCC is already built.
|
||||
fi
|
||||
@@ -1,11 +0,0 @@
|
||||
diff -Naur newlib-1.16.0/newlib/libc/machine/mips/strlen.c newlib-1.16.0-fixed/newlib/libc/machine/mips/strlen.c
|
||||
--- newlib-1.16.0/newlib/libc/machine/mips/strlen.c 2002-03-14 03:41:43.000000000 +0100
|
||||
+++ newlib-1.16.0-fixed/newlib/libc/machine/mips/strlen.c 2009-02-14 15:52:58.000000000 +0100
|
||||
@@ -60,6 +60,7 @@
|
||||
" addiu $2,$4,1\n"
|
||||
"\n"
|
||||
"1: lbu $3,0($4)\n"
|
||||
+ " nop\n"
|
||||
" bnez $3,1b\n"
|
||||
" addiu $4,$4,1\n"
|
||||
"\n"
|
||||
@@ -1,11 +0,0 @@
|
||||
diff -Naur newlib-1.17.0/newlib/libc/machine/mips/strlen.c newlib-1.17.0-fixed/newlib/libc/machine/mips/strlen.c
|
||||
--- newlib-1.17.0/newlib/libc/machine/mips/strlen.c 2002-03-14 03:41:43.000000000 +0100
|
||||
+++ newlib-1.17.0-fixed/newlib/libc/machine/mips/strlen.c 2009-02-14 15:45:19.000000000 +0100
|
||||
@@ -60,6 +60,7 @@
|
||||
" addiu $2,$4,1\n"
|
||||
"\n"
|
||||
"1: lbu $3,0($4)\n"
|
||||
+ " nop\n"
|
||||
" bnez $3,1b\n"
|
||||
" addiu $4,$4,1\n"
|
||||
"\n"
|
||||
Reference in New Issue
Block a user