diff options
author | Bert Lange <b.lange@fzd.de> | 2010-11-02 12:30:03 +0100 |
---|---|---|
committer | Bert Lange <b.lange@fzd.de> | 2010-11-02 12:30:03 +0100 |
commit | 5b79e401171e72a9a098aac29e663faa3ee870fa (patch) | |
tree | 7bce1c4d77ad6848b6434d82182e7d3e002a863a /s3estarter | |
parent | 2cd8719a8b41894084948d705622884f717b677f (diff) | |
download | zpu-5b79e401171e72a9a098aac29e663faa3ee870fa.zip zpu-5b79e401171e72a9a098aac29e663faa3ee870fa.tar.gz |
change: software file structure
Diffstat (limited to 's3estarter')
-rw-r--r--[-rwxr-xr-x] | s3estarter/rtl/box.vhd | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | s3estarter/sim/Makefile | 2 | ||||
-rw-r--r-- | s3estarter/software/devel/Makefile | 40 | ||||
-rw-r--r-- | s3estarter/software/ethernet_speed/Makefile | 61 | ||||
-rw-r--r-- | s3estarter/software/ethernet_speed/README.txt | 9 | ||||
-rw-r--r-- | s3estarter/software/ethernet_speed/greth.c | 126 | ||||
-rw-r--r-- | s3estarter/software/ethernet_speed/greth_api.c | 263 | ||||
-rw-r--r-- | s3estarter/software/ethernet_speed/greth_api.h | 120 | ||||
-rw-r--r-- | s3estarter/software/include.mak | 15 | ||||
-rw-r--r--[-rwxr-xr-x] | s3estarter/software/include/peripherie.h | 8 | ||||
-rw-r--r-- | s3estarter/software/libhal/Makefile | 16 | ||||
-rw-r--r--[-rwxr-xr-x] | s3estarter/software/libhal/hw.c (renamed from s3estarter/software/test/hw.c) | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | s3estarter/software/libhal/timer.c (renamed from s3estarter/software/test/timer.c) | 45 | ||||
-rw-r--r-- | s3estarter/software/libhal/timer.h | 34 | ||||
-rw-r--r-- | s3estarter/software/libhal/uart.c | 129 | ||||
-rw-r--r-- | s3estarter/software/libhal/vga.c | 153 | ||||
-rw-r--r--[-rwxr-xr-x] | s3estarter/syn/Makefile | 0 |
17 files changed, 967 insertions, 56 deletions
diff --git a/s3estarter/rtl/box.vhd b/s3estarter/rtl/box.vhd index 21a3745..21a3745 100755..100644 --- a/s3estarter/rtl/box.vhd +++ b/s3estarter/rtl/box.vhd diff --git a/s3estarter/sim/Makefile b/s3estarter/sim/Makefile index 0535859..cd8fe87 100755..100644 --- a/s3estarter/sim/Makefile +++ b/s3estarter/sim/Makefile @@ -13,6 +13,8 @@ vhdlfiles = $(rtl_files) $(rtl_tb_files) all: compile simulate compile_others: + #make --directory ../software/test/ test + make --directory ../software/ethernet_speed make compile --directory ../../rena3/sim compile: lib diff --git a/s3estarter/software/devel/Makefile b/s3estarter/software/devel/Makefile deleted file mode 100644 index 162da5e..0000000 --- a/s3estarter/software/devel/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -COMPILER_OPTIONS=-ffunction-sections -fdata-sections -Wl,--relax -Wl,--gc-sections -OBJCOPY_OPTIONS=--strip-debug --discard-locals - -all: - @echo "romgen - generate zpuromgen tool" - @echo "hello - build example" - @echo "test - build test" - @echo - @echo "clean - clean up" - -romgen: zpuromgen.c - gcc zpuromgen.c -o zpuromgen - - -hello: romgen - zpu-elf-gcc $(COMPILER_OPTIONS) -O3 -phi "`pwd`/hello.c" -o hello.elf -Wl,--relax -Wl,--gc-sections -g - zpu-elf-size hello.elf - - zpu-elf-objcopy $(OBJCOPY_OPTIONS) -O binary hello.elf hello.bin - - cat >../helloworld.vhd helloworld.vhd_header - ./zpuromgen hello.bin >>../helloworld.vhd - cat >>../helloworld.vhd helloworld.vhd_footer - -test_vhdl = ../../../zpu/rtl/dualport_ram.vhd - -test: romgen - zpu-elf-gcc $(COMPILER_OPTIONS) -O3 -phi "`pwd`/test.c" hw.c timer.c lcd-routines.c -o test.elf -Wl,--relax -Wl,--gc-sections -Wa,-adhls=test.lst -g - zpu-elf-size test.elf - zpu-elf-objcopy $(OBJCOPY_OPTIONS) -O binary test.elf test.bin - - cat > $(test_vhdl) dualport_ram.vhd_header - ./zpuromgen test.bin >> $(test_vhdl) - cat >> $(test_vhdl) dualport_ram.vhd_footer - - -clean: - rm -f *.bin - rm -f *.elf - rm -f *.lst diff --git a/s3estarter/software/ethernet_speed/Makefile b/s3estarter/software/ethernet_speed/Makefile new file mode 100644 index 0000000..f9b4150 --- /dev/null +++ b/s3estarter/software/ethernet_speed/Makefile @@ -0,0 +1,61 @@ +DIR=.. +include $(DIR)/include.mak + +OBJECTS=greth_api.o greth.o + +test_vhdl= ../../../zpu/rtl/dualport_ram.vhd + + +all: $(test_vhdl) + +$(test_vhdl): greth.bin $(ROMGEN) + # concat parts + cat > $(test_vhdl) ../support/dualport_ram.vhd_header + $(ROMGEN) greth.bin >> $(test_vhdl) + cat >> $(test_vhdl) ../support/dualport_ram.vhd_footer + +%.bin: %.elf + $(OBJCOPY) $(OBJCOPYFLAGS) -O binary $< $@ + +greth.elf: $(OBJECTS) + $(CC) $(CFLAGS) greth_api.c greth.c -o greth.elf -L$(DIR)/libhal -lhal -Wl,--relax -Wl,--gc-sections -g + #$(LD) $(LDFLAGS) -o $@ -L$(DIR)/libhal --start-group $(OBJECTS) -lhal --end-group + $(SIZE) $@ + +clean: + rm -f *.o + rm -f *.elf + rm -f *.bin + +#COMPILER_OPTIONS=-I../include -ffunction-sections -fdata-sections +#ROMGEN=../support/zpuromgen +# +#all: +# @echo "greth - build greth" +# @echo +# @echo "clean - clean up" +# +# +#test_vhdl = ../../../zpu/rtl/dualport_ram.vhd +#h_files = greth_api.h +#c_files = greth_api.h greth_api.c greth.c +# +# +#greth: $(test_vhdl) +# +# +#greth.bin: $(c_files) $(h_files) +# zpu-elf-gcc $(COMPILER_OPTIONS) -O3 -phi $(c_files) -o greth.elf -Wl,--relax -Wl,--gc-sections -Wa,-adhls=greth.lst -g +# zpu-elf-size greth.elf +# zpu-elf-objcopy $(OBJCOPY_OPTIONS) -O binary greth.elf greth.bin +# +# +# +#clean: +# rm -f *.bin +# rm -f *.elf +# rm -f *.lst +# +## disable implicit rule for c files +#.SUFFIXES: +#%.c: %.w %.ch diff --git a/s3estarter/software/ethernet_speed/README.txt b/s3estarter/software/ethernet_speed/README.txt new file mode 100644 index 0000000..0334142 --- /dev/null +++ b/s3estarter/software/ethernet_speed/README.txt @@ -0,0 +1,9 @@ +This is a simple Bare C Ethernet speed test. + +It transmits 2^20 raw Ethernet packets with 1500 bytes payload +(i.e. 1500 Mbytes of data) and calculates the time and bitrate used. + +Note that no upper layer protocol or any flow control is used. + +Destination and source MAC addresses as well as the APB address of +the GRETH are specified through #define's in greth.c. diff --git a/s3estarter/software/ethernet_speed/greth.c b/s3estarter/software/ethernet_speed/greth.c new file mode 100644 index 0000000..45c8514 --- /dev/null +++ b/s3estarter/software/ethernet_speed/greth.c @@ -0,0 +1,126 @@ +/*****************************************************************************/ +/* This file is a part of the GRLIB VHDL IP LIBRARY */ +/* Copyright (C) 2007 GAISLER RESEARCH */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* See the file COPYING for the full details of the license. */ +/*****************************************************************************/ + +/* Changelog */ +/* 2007-11-13: Simple Ethernet speed test added - Kristoffer Glembo */ +/* 2007-11-13: GRETH BareC API added - Kristoffer Glembo */ + +#include <stdlib.h> +//#include <time.h> // clock +#include <string.h> // memcpy +#include <stdio.h> // printf + +#include <peripherie.h> +#include <../libhal/timer.h> // libhal/timer.c/clocks +#include "greth_api.h" + +/* Set to 1 if using GRETH_GBIT, otherwise 0 */ +#define GRETH_GBIT 0 + +/* Set to 10,100, or 1000 */ +#define GRETH_SPEED 100 + +/* Set to 1 to run full duplex, 0 to run half duplex */ +#define GRETH_FULLDUPLEX 1 + +#define GRETH_ADDR 0x80000b00 + +/* Destination MAC address */ +#define DEST_MAC0 0x00 +#define DEST_MAC1 0x13 +#define DEST_MAC2 0x72 +#define DEST_MAC3 0xAE +#define DEST_MAC4 0x72 +#define DEST_MAC5 0x21 + +/* Source MAC address */ +#define SRC_MAC0 0xDE +#define SRC_MAC1 0xAD +#define SRC_MAC2 0xBE +#define SRC_MAC3 0xEF +#define SRC_MAC4 0x00 +#define SRC_MAC5 0x20 + +struct greth_info greth; + +int main(void) { + + unsigned long long i; + unsigned char buf[1514]; +// uint32_t + clock_t t1, t2; + unsigned long long datasize; + double time, bitrate; + + greth.regs = (greth_regs *) GRETH_ADDR; + + /* Dest. addr */ + buf[0] = DEST_MAC0; + buf[1] = DEST_MAC1; + buf[2] = DEST_MAC2; + buf[3] = DEST_MAC3; + buf[4] = DEST_MAC4; + buf[5] = DEST_MAC5; + + /* Source addr */ + buf[6] = SRC_MAC0; + buf[7] = SRC_MAC1; + buf[8] = SRC_MAC2; + buf[9] = SRC_MAC3; + buf[10] = SRC_MAC4; + buf[11] = SRC_MAC5; + + /* Length 1500 */ + buf[12] = 0x05; + buf[13] = 0xDC; + + memcpy(greth.esa, &buf[6], 6); + + for (i = 14; i < 1514; i++) { + buf[i] = i; + } + + // size: 3459 next block: 4131 + greth_init(&greth); + + // size: 7590 next block: 35868 + + printf("\nSending 1500 Mbyte of data to %.02x:%.02x:%.02x:%.02x:%.02x:%.02x\n", buf[0], buf[1], \ + buf[2], buf[3], \ + buf[4], buf[5]); + + // size: 43458 next block: 337 + t1 = clocks(); //clock(); + + // size: 43795 next block: 179 + i = 0; + while(i < (unsigned long long) 1024*1024) { + + // greth_tx() returns 1 if a free descriptor is found, otherwise 0 + i += greth_tx(1514, buf, &greth); + + } + t2 = clocks(); //clock(); + + // size: 43974 next block: 164 + time = (double)(t2 - t1)/CLOCKS_PER_SECOND; + printf("\nTime: %f\n", time); + + // size: 44138 next block: 408 + datasize = (unsigned long long)1024*1024*1500*8; // In bits + bitrate = (double) datasize/time; + printf("Bitrate: %f Mbps\n", bitrate/(1024*1024)); + + // size: 44546 + + return 0; +} diff --git a/s3estarter/software/ethernet_speed/greth_api.c b/s3estarter/software/ethernet_speed/greth_api.c new file mode 100644 index 0000000..9001173 --- /dev/null +++ b/s3estarter/software/ethernet_speed/greth_api.c @@ -0,0 +1,263 @@ +/*****************************************************************************/ +/* This file is a part of the GRLIB VHDL IP LIBRARY */ +/* Copyright (C) 2007 GAISLER RESEARCH */ +/* */ +/* This program is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 2 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* See the file COPYING for the full details of the license. */ +/*****************************************************************************/ + +/* Changelog */ +/* 2008-02-01: GRETH API separated from test - Marko Isomaki */ + +#include <stdlib.h> // malloc +#include "greth_api.h" + +/* Bypass cache load */ +static inline int load(int addr) +{ + int tmp; +// asm volatile(" lda [%1]1, %0 " +// : "=r"(tmp) +// : "r"(addr) +// ); + return tmp; +} + +static inline int save(unsigned int addr, unsigned int data) +{ + *((volatile unsigned int *)addr) = data; +} + +/* Allocate memory aligned to the size */ +static char *almalloc(int sz) +{ + char *tmp; + int *tmp2; + int i; + tmp = malloc(2*sz); + tmp = (char *) (((int)tmp+sz) & ~(sz -1)); + tmp2 = (int *)tmp; + for (i = 0; i < 128; i++) { + tmp2[i*2] = 0; + } + return(tmp); +} + +int read_mii(int phyaddr, int addr, volatile greth_regs *regs) +{ + unsigned int tmp; + + do { + tmp = load((int)®s->mdio); + } while (tmp & GRETH_MII_BUSY); + + tmp = (phyaddr << 11) | ((addr&0x1F) << 6) | 2; + save((int)®s->mdio, tmp); + + do { + tmp = load((int)®s->mdio); + } while (tmp & GRETH_MII_BUSY); + + if (!(tmp & GRETH_MII_NVALID)) { + tmp = load((int)®s->mdio); + return (tmp>>16)&0xFFFF; + } + else { + /* printf("GRETH: failed to read mii\n"); */ + return -1; + } +} + +void write_mii(int phyaddr, int addr, int data, volatile greth_regs *regs) +{ + unsigned int tmp; + + do { + tmp = load((int)®s->mdio); + } while (tmp & GRETH_MII_BUSY); + + tmp = ((data&0xFFFF)<<16) | (phyaddr << 11) | ((addr&0x1F) << 6) | 1; + + save((int)®s->mdio, tmp); + + do { + tmp = load((int)®s->mdio); + } while (tmp & GRETH_MII_BUSY); + +} + +int greth_set_mac_address(struct greth_info *greth, unsigned char *addr) +{ + greth->esa[0] = addr[0]; + greth->esa[1] = addr[1]; + greth->esa[2] = addr[2]; + greth->esa[3] = addr[3]; + greth->esa[4] = addr[4]; + greth->esa[5] = addr[5]; + save((int)&greth->regs->esa_msb, addr[0] << 8 | addr[1]); + save((int)&greth->regs->esa_lsb, addr[2] << 24 | addr[3] << 16 | addr[4] << 8 | addr[5]); + return 1; +} + +int greth_init(struct greth_info *greth) { + + unsigned int tmp; + int i; + int duplex, speed; + int gbit; + + tmp = load((int)&greth->regs->control); + greth->gbit = (tmp >> 27) & 1; + greth->edcl = (tmp >> 31) & 1; + + if (greth->edcl == 0) { + /* Reset the controller. */ + save((int)&greth->regs->control, GRETH_RESET); + + do { + tmp = load((int)&greth->regs->control); + } while (tmp & GRETH_RESET); + } + + /* Get the phy address which assumed to have been set + * correctly with the reset value in hardware + */ + tmp = load((int)&greth->regs->mdio); + greth->phyaddr = ((tmp >> 11) & 0x1F); + + greth->txd = (struct descriptor *) almalloc(1024); + greth->rxd = (struct descriptor *) almalloc(1024); + save((int)&greth->regs->tx_desc_p, (unsigned int) greth->txd); + save((int)&greth->regs->rx_desc_p, (unsigned int) greth->rxd); + greth->txpnt = 0; + greth->rxpnt = 0; + greth->txchkpnt = 0; + greth->rxchkpnt = 0; + + /* Reset PHY */ + if (greth->edcl == 0) { + write_mii(greth->phyaddr, 0, 0x8000, greth->regs); + while ( (tmp=read_mii(greth->phyaddr,0, greth->regs)) & 0x8000); + i = 0; + if (tmp & 0x1000) { /* auto neg */ + while ( !(read_mii(greth->phyaddr,1, greth->regs) & 0x20 ) ) { + i++; + if (i > 50000) { + /* printf("Auto-negotiation failed\n"); */ + break; + } + } + } + tmp = read_mii(greth->phyaddr, 0, greth->regs); + + if (greth->gbit && !((tmp >> 13) & 1) && ((tmp >> 6) & 1)) { + gbit = 1; speed = 0; + } else if (((tmp >> 13) & 1) && !((tmp >> 6) & 1)) { + gbit = 0; speed = 1; + } else if (!((tmp >> 13) & 1) && !((tmp >> 6) & 1)) { + gbit = 0; speed = 0; + } + duplex = (tmp >> 8) & 1; + + save((int)&greth->regs->control, (duplex << 4) | (speed << 7) | (gbit << 8)); + } else { + /* wait for edcl phy initialisation to finish */ + i = 0; + + while (i < 3) { + tmp = load((int)&greth->regs->mdio); + if ((tmp >> 3) & 1) { + i = 0; + } else { + i++; + } + } + + + } + + + + + /* printf("GRETH(%s) Ethernet MAC at [0x%x]. Running %d Mbps %s duplex\n", greth->gbit?"10/100/1000":"10/100" , \ */ +/* (unsigned int)(greth->regs), \ */ +/* (speed == 0x2000) ? 100:10, duplex ? "full":"half"); */ + + greth_set_mac_address(greth, greth->esa); + +} + +inline int greth_tx(int size, char *buf, struct greth_info *greth) +{ + if ((load((int)&(greth->txd[greth->txpnt].ctrl)) >> 11) & 1) { + return 0; + } + + greth->txd[greth->txpnt].addr = (int) buf; + + if (greth->txpnt == 127) { + greth->txd[greth->txpnt].ctrl = GRETH_BD_WR | GRETH_BD_EN | size; + greth->txpnt = 0; + } else { + greth->txd[greth->txpnt].ctrl = GRETH_BD_EN | size; + greth->txpnt++; + } + + greth->regs->control = load((int)&(greth->regs->control)) | GRETH_TXEN; + + return 1; +} + +inline int greth_rx(char *buf, struct greth_info *greth) +{ + if (((load((int)&(greth->rxd[greth->rxpnt].ctrl)) >> 11) & 1)) { + return 0; + } + greth->rxd[greth->rxpnt].addr = (int)buf; + if (greth->rxpnt == 127) { + greth->rxd[greth->rxpnt].ctrl = GRETH_BD_WR | GRETH_BD_EN; + greth->rxpnt = 0; + } else { + greth->rxd[greth->rxpnt].ctrl = GRETH_BD_EN; + greth->rxpnt++; + } + greth->regs->control = load((int)&(greth->regs->control)) | GRETH_RXEN; + return 1; +} + +inline int greth_checkrx(int *size, struct rxstatus *rxs, struct greth_info *greth) +{ + int tmp; + tmp = load((int)&(greth->rxd[greth->rxchkpnt].ctrl)); + if (!((tmp >> 11) & 1)) { + *size = tmp & GRETH_BD_LEN; + if (greth->rxchkpnt == 127) { + greth->rxchkpnt = 0; + } else { + greth->rxchkpnt++; + } + return 1; + } else { + return 0; + } +} + +inline int greth_checktx(struct greth_info *greth) +{ + int tmp; + tmp = load((int)&(greth->txd[greth->txchkpnt].ctrl)); + if (!((tmp >> 11) & 1)) { + if (greth->txchkpnt == 127) { + greth->txchkpnt = 0; + } else { + greth->txchkpnt++; + } + return 1; + } else { + return 0; + } +} diff --git a/s3estarter/software/ethernet_speed/greth_api.h b/s3estarter/software/ethernet_speed/greth_api.h new file mode 100644 index 0000000..4ad75f9 --- /dev/null +++ b/s3estarter/software/ethernet_speed/greth_api.h @@ -0,0 +1,120 @@ + +#define GRETH_FD 0x10 +#define GRETH_RESET 0x40 +#define GRETH_MII_BUSY 0x8 +#define GRETH_MII_NVALID 0x10 + +/* MII registers */ +#define GRETH_MII_EXTADV_1000FD 0x00000200 +#define GRETH_MII_EXTADV_1000HD 0x00000100 +#define GRETH_MII_EXTPRT_1000FD 0x00000800 +#define GRETH_MII_EXTPRT_1000HD 0x00000400 + +#define GRETH_MII_100T4 0x00000200 +#define GRETH_MII_100TXFD 0x00000100 +#define GRETH_MII_100TXHD 0x00000080 +#define GRETH_MII_10FD 0x00000040 +#define GRETH_MII_10HD 0x00000020 + +#define GRETH_BD_EN 0x800 +#define GRETH_BD_WR 0x1000 +#define GRETH_BD_IE 0x2000 +#define GRETH_BD_LEN 0x7FF + +#define GRETH_TXEN 0x1 +#define GRETH_INT_TX 0x8 +#define GRETH_TXI 0x4 +#define GRETH_TXBD_STATUS 0x0001C000 +#define GRETH_TXBD_MORE 0x20000 +#define GRETH_TXBD_IPCS 0x40000 +#define GRETH_TXBD_TCPCS 0x80000 +#define GRETH_TXBD_UDPCS 0x100000 +#define GRETH_TXBD_ERR_LC 0x10000 +#define GRETH_TXBD_ERR_UE 0x4000 +#define GRETH_TXBD_ERR_AL 0x8000 +#define GRETH_TXBD_NUM 128 +#define GRETH_TXBD_NUM_MASK (GRETH_TXBD_NUM-1) +#define GRETH_TX_BUF_SIZE 2048 + +#define GRETH_INT_RX 0x4 +#define GRETH_RXEN 0x2 +#define GRETH_RXI 0x8 +#define GRETH_RXBD_STATUS 0xFFFFC000 +#define GRETH_RXBD_ERR_AE 0x4000 +#define GRETH_RXBD_ERR_FT 0x8000 +#define GRETH_RXBD_ERR_CRC 0x10000 +#define GRETH_RXBD_ERR_OE 0x20000 +#define GRETH_RXBD_ERR_LE 0x40000 +#define GRETH_RXBD_IP_DEC 0x80000 +#define GRETH_RXBD_IP_CSERR 0x100000 +#define GRETH_RXBD_UDP_DEC 0x200000 +#define GRETH_RXBD_UDP_CSERR 0x400000 +#define GRETH_RXBD_TCP_DEC 0x800000 +#define GRETH_RXBD_TCP_CSERR 0x1000000 + +#define GRETH_RXBD_NUM 128 +#define GRETH_RXBD_NUM_MASK (GRETH_RXBD_NUM-1) +#define GRETH_RX_BUF_SIZE 2048 + +/* Ethernet configuration registers */ +typedef struct _greth_regs { + volatile int control; + volatile int status; + volatile int esa_msb; + volatile int esa_lsb; + volatile int mdio; + volatile int tx_desc_p; + volatile int rx_desc_p; + volatile int edclip; +} greth_regs; + +/* Ethernet buffer descriptor */ +typedef struct _greth_bd { + int stat; + int addr; /* Buffer address */ +} greth_bd; + +struct descriptor +{ + volatile int ctrl; + volatile int addr; +}; + +struct rxstatus +{ + +}; + +struct greth_info { + greth_regs *regs; /* Address of controller registers. */ + + unsigned char esa[6]; + unsigned int gbit; + unsigned int phyaddr; + unsigned int edcl; + + struct descriptor *txd; + struct descriptor *rxd; + unsigned int txpnt; + unsigned int rxpnt; + unsigned int txchkpnt; + unsigned int rxchkpnt; + +}; + +int read_mii(int phyaddr, int addr, volatile greth_regs *regs); + +void write_mii(int phyaddr, int addr, int data, volatile greth_regs *regs); + +int greth_set_mac_address(struct greth_info *greth, unsigned char *addr); + +int greth_init(struct greth_info *greth); + +inline int greth_tx(int size, char *buf, struct greth_info *greth); + +inline int greth_rx(char *buf, struct greth_info *greth); + +inline int greth_checkrx(int *size, struct rxstatus *rxs, struct greth_info *greth); + +inline int greth_checktx(struct greth_info *greth); + diff --git a/s3estarter/software/include.mak b/s3estarter/software/include.mak new file mode 100644 index 0000000..c5abd72 --- /dev/null +++ b/s3estarter/software/include.mak @@ -0,0 +1,15 @@ +AS=zpu-elf-as +CC=zpu-elf-gcc +LD=zpu-elf-ld +OBJCOPY=zpu-elf-objcopy +AR=zpu-elf-ar +RANLIB=zpu-elf-ranlib +SIZE=zpu-elf-size + +ROMGEN=$(DIR)/support/zpuromgen + +INLCUDES=-I$(DIR)/include +ASFLAGS=-adhls -g $(INLCUDES) +CFLAGS=-O3 -phi -Wall -ffunction-sections -fdata-sections $(INLCUDES) +LDFLAGS=--relax --gc-sections +OBJCOPYFLAGS=--strip-debug --discard-locals diff --git a/s3estarter/software/include/peripherie.h b/s3estarter/software/include/peripherie.h index a967090..e7ff507 100755..100644 --- a/s3estarter/software/include/peripherie.h +++ b/s3estarter/software/include/peripherie.h @@ -98,9 +98,11 @@ typedef struct { gptimer_element_t e[8]; } gptimer_t; -void msleep(uint32_t msec); -void nsleep(uint32_t nsec); -void init_timer_prescaler(); +#define CLOCKS_PER_SECOND (1000) +void usleep( uint32_t nsec); +void msleep( uint32_t msec); +void sleep( uint32_t sec); +void timer_init( void); // vga diff --git a/s3estarter/software/libhal/Makefile b/s3estarter/software/libhal/Makefile new file mode 100644 index 0000000..f239d54 --- /dev/null +++ b/s3estarter/software/libhal/Makefile @@ -0,0 +1,16 @@ +DIR=.. +include ../include.mak + +C_FILES=hw.c timer.c uart.c vga.c +OBJECTS=hw.o timer.o uart.o vga.o + +all: libhal.a + +libhal.a: $(OBJECTS) + $(AR) clr libhal.a $(OBJECTS) + $(RANLIB) libhal.a + + +clean: + rm -f *.o + rm -f libhal.a diff --git a/s3estarter/software/test/hw.c b/s3estarter/software/libhal/hw.c index 6d9a639..3f29f84 100755..100644 --- a/s3estarter/software/test/hw.c +++ b/s3estarter/software/libhal/hw.c @@ -1,4 +1,4 @@ -#include "peripherie.h" +#include <peripherie.h> apbuart_t *uart0 = (apbuart_t *) 0x80000100; gptimer_t *timer0 = (gptimer_t *) 0x80000200; diff --git a/s3estarter/software/test/timer.c b/s3estarter/software/libhal/timer.c index e28cafc..8cc1db9 100755..100644 --- a/s3estarter/software/test/timer.c +++ b/s3estarter/software/libhal/timer.c @@ -1,8 +1,26 @@ -#include "peripherie.h" +#include <peripherie.h> //////////////////////////////////////// // timer functions + +// wait for a given time in micro seconds +void usleep(uint32_t usec) +{ + uint32_t tcr; + + // 1 usec = 6 + timer0->e[0].reload = (F_CPU/TIMER_PRESCALER/1000000)*usec; + timer0->e[0].ctrl = TIMER_ENABLE | TIMER_LOAD; + + do + { + tcr = timer0->e[0].ctrl; + } while ( (tcr & TIMER_ENABLE)); +} + + +// wait for given time in milli seconds void msleep(uint32_t msec) { uint32_t tcr; @@ -20,6 +38,8 @@ void msleep(uint32_t msec) } while ( (tcr & TIMER_ENABLE)); } + +// wait for given time in seconds void sleep(uint32_t sec) { uint32_t timer; @@ -35,20 +55,15 @@ void sleep(uint32_t sec) } } -void usleep(uint32_t nsec) -{ - uint32_t tcr; - - // 1 nsec = 6 - timer0->e[0].reload = (F_CPU/TIMER_PRESCALER/1000000)*nsec; - timer0->e[0].ctrl = TIMER_ENABLE | TIMER_LOAD; - do - { - tcr = timer0->e[0].ctrl; - } while ( (tcr & TIMER_ENABLE)); +// deliver the clocks from timer 0.1 +uint32_t clocks( void) +{ + return( timer0->e[1].value); } + +// just a loop void wait( uint32_t value) { uint32_t i; @@ -56,9 +71,15 @@ void wait( uint32_t value) for (i=0; i<value; i++) {} } + +// initialisation for the timer void timer_init( void) { timer0->scaler_reload = TIMER_PRESCALER-1; // set prescaler + + // set timer 0.1 to free running in msec + timer0->e[1].reload = (F_CPU/TIMER_PRESCALER/CLOCKS_PER_SECOND); + timer0->e[1].ctrl = TIMER_ENABLE | TIMER_RESTART | TIMER_LOAD; } diff --git a/s3estarter/software/libhal/timer.h b/s3estarter/software/libhal/timer.h new file mode 100644 index 0000000..368a279 --- /dev/null +++ b/s3estarter/software/libhal/timer.h @@ -0,0 +1,34 @@ +#include <peripherie.h> + +#ifndef TIMER_H +#define TIMER_H + + +//////////////////////////////////////// +// timer functions + + +// wait for a given time in micro seconds +void usleep(uint32_t usec); + +// wait for given time in milli seconds +void msleep(uint32_t msec); + + +// wait for given time in seconds +void sleep(uint32_t sec); + + +// deliver the clocks from timer 0.1 +uint32_t clocks( void); + + +// just a loop +void wait( uint32_t value); + + +// initialisation for the timer +void timer_init( void); + + +#endif // TIMER_H diff --git a/s3estarter/software/libhal/uart.c b/s3estarter/software/libhal/uart.c new file mode 100644 index 0000000..0f7b93b --- /dev/null +++ b/s3estarter/software/libhal/uart.c @@ -0,0 +1,129 @@ +//#include <stdio.h> + +#include <peripherie.h> +#include <lcd-routines.h> + +//////////////////////////////////////// +// common defines + +#define bit_is_set(mem, bv) (mem & bv) +#define bit_is_clear(mem, bv) (!(mem & bv)) +#define loop_until_bit_is_set(mem, bv) do {} while( bit_is_clear(mem, bv)) +#define loop_until_bit_is_clear(mem, bv) do {} while( bit_is_set(mem, bv)) + + +//////////////////////////////////////// +// uart functions + + +void uart_init( void) +{ + uart0->scaler = UART_SCALER; + uart0->ctrl = UART_CONTROL_TX_ENABLE | UART_CONTROL_RX_ENABLE; +} + + +char uart_getchar() +{ + loop_until_bit_is_set(uart0->status, UART_STATUS_DATA_READY); + return uart0->data; +} + + +void uart_putchar_raw( char c) +{ + #if UART_FIFOSIZE==1 || !defined(UART_FIFOSIZE) + loop_until_bit_is_set( uart0->status, UART_STATUS_TX_REG_EMPTY); + #else + loop_until_bit_is_clear( uart0->status, UART_STATUS_TX_FIFO_FULL); + #endif + uart0->data = c; +} + + +void uart_putchar( char c) +{ + if (c == '\n') + uart_putchar_raw( '\r'); + uart_putchar_raw( c); +} + + +void uart_putstr(const char *s) +{ + while (*s) + uart_putchar( *s++); +} + +// http://asalt-vehicle.googlecode.com/svn› trunk› src› uart.c +void uart_hex(unsigned char dataType, unsigned long data) +{ + unsigned char count, i, temp; + char dataString[] = "0x "; + + if (dataType == 8) count = 2; + if (dataType == 16) count = 4; + if (dataType == 32) count = 8; + + for(i=count; i>0; i--) + { + temp = data % 16; + if (temp<10) dataString [i+1] = temp + 0x30; + else dataString [i+1] = (temp - 10) + 0x41; + + data = data/16; + } + + uart_putstr( dataString); +} + + + +//////////////////////////////////////// +// specific stuff + +// http://www.mikrocontroller.net/articles/FAQ#itoa.28.29 +void itoa( int z, char* Buffer ) +{ + int i = 0; + int j; + char tmp; + unsigned u; // In u bearbeiten wir den Absolutbetrag von z. + + // ist die Zahl negativ? + // gleich mal ein - hinterlassen und die Zahl positiv machen + if( z < 0 ) { + Buffer[0] = '-'; + Buffer++; + // -INT_MIN ist idR. größer als INT_MAX und nicht mehr + // als int darstellbar! Man muss daher bei der Bildung + // des Absolutbetrages aufpassen. + u = ( (unsigned)-(z+1) ) + 1; + } + else { + u = (unsigned)z; + } + // die einzelnen Stellen der Zahl berechnen + do { + Buffer[i++] = '0' + u % 10; + u /= 10; + } while( u > 0 ); + + // den String in sich spiegeln + for( j = 0; j < i / 2; ++j ) { + tmp = Buffer[j]; + Buffer[j] = Buffer[i-j-1]; + Buffer[i-j-1] = tmp; + } + Buffer[i] = '\0'; +} + + +void uart_putint(uint32_t data) +{ + char str[20]; + + itoa( data, str); + uart_putstr( str); +} + diff --git a/s3estarter/software/libhal/vga.c b/s3estarter/software/libhal/vga.c new file mode 100644 index 0000000..58e3055 --- /dev/null +++ b/s3estarter/software/libhal/vga.c @@ -0,0 +1,153 @@ +//#include <stdio.h> + +#include <peripherie.h> + + +//////////////////////////////////////// +// common defines + +#define bit_is_set(mem, bv) (mem & bv) +#define bit_is_clear(mem, bv) (!(mem & bv)) +#define loop_until_bit_is_set(mem, bv) do {} while( bit_is_clear(mem, bv)) +#define loop_until_bit_is_clear(mem, bv) do {} while( bit_is_set(mem, bv)) + +//////////////////////////////////////// +// specific stuff + +// http://www.mikrocontroller.net/articles/FAQ#itoa.28.29 +void itoa( int z, char* Buffer ) +{ + int i = 0; + int j; + char tmp; + unsigned u; // In u bearbeiten wir den Absolutbetrag von z. + + // ist die Zahl negativ? + // gleich mal ein - hinterlassen und die Zahl positiv machen + if( z < 0 ) { + Buffer[0] = '-'; + Buffer++; + // -INT_MIN ist idR. größer als INT_MAX und nicht mehr + // als int darstellbar! Man muss daher bei der Bildung + // des Absolutbetrages aufpassen. + u = ( (unsigned)-(z+1) ) + 1; + } + else { + u = (unsigned)z; + } + // die einzelnen Stellen der Zahl berechnen + do { + Buffer[i++] = '0' + u % 10; + u /= 10; + } while( u > 0 ); + + // den String in sich spiegeln + for( j = 0; j < i / 2; ++j ) { + tmp = Buffer[j]; + Buffer[j] = Buffer[i-j-1]; + Buffer[i-j-1] = tmp; + } + Buffer[i] = '\0'; +} + + + +uint8_t vga_line; +uint8_t vga_column; + +void vga_init( void) +{ + vga0->background_color = 0x00000000; + vga0->foreground_color = 0x00ffffff; + vga_line = 0; + vga_column = 0; +} + + + +void vga_clear( void) +{ + uint32_t count; + uint32_t count_max = 37*80; + + for(count = 0; count< count_max; count++) + vga0->data = count<<8; + + vga_line = 0; + vga_column = 0; +} + + +void vga_putchar( char c) +{ + + vga0->data = (( vga_line * 80 + vga_column)<<8) | c; + if ( (c == '\n') || (vga_column == 79) ) + { + if (vga_line<36) + vga_line++; + else + vga_line = 0; + + vga_column = 0; + } + else + { + vga_column++; + } + +} + + +void vga_putstr(char *s) +{ + while (*s) + vga_putchar( *s++); +} + + +void vga_putint(uint32_t data) +{ + char str[20]; + + itoa( data, str); + vga_putstr( str); +} + + +void vga_putbin(unsigned char dataType, unsigned long data) +{ + unsigned char i, temp; + char dataString[] = "0b "; + + for(i=dataType; i>0; i--) + { + temp = data % 2; + dataString [i+1] = temp + 0x30; + data = data/2; + } + vga_putstr( dataString); +} + + +void vga_puthex(unsigned char dataType, unsigned long data) +{ + unsigned char count, i, temp; + char dataString[] = "0x "; + + if (dataType == 8) count = 2; + if (dataType == 16) count = 4; + if (dataType == 32) count = 8; + + for(i=count; i>0; i--) + { + temp = data % 16; + if (temp<10) dataString [i+1] = temp + 0x30; + else dataString [i+1] = (temp - 10) + 0x41; + + data = data/16; + } + vga_putstr( dataString); +} + + diff --git a/s3estarter/syn/Makefile b/s3estarter/syn/Makefile index c45bf1d..c45bf1d 100755..100644 --- a/s3estarter/syn/Makefile +++ b/s3estarter/syn/Makefile |