mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-04-21 12:27:27 +03:00
Fixing some examples, adding scripts for compiling xilinx libs with ghdl
This commit is contained in:
45
Examples/sram_gpio/src/Makefile
Normal file
45
Examples/sram_gpio/src/Makefile
Normal file
@@ -0,0 +1,45 @@
|
||||
CC = mipsel-openwrt-linux-gcc
|
||||
|
||||
all: jz_init_sram jz_test_gpio enable_rx enable_irq
|
||||
|
||||
DEBUG = -O3 -g0
|
||||
|
||||
COMMON_SOURCES = jz47xx_gpio.c jz47xx_mmap.c
|
||||
|
||||
H_SOURCES = jz47xx_gpio.h jz47xx_mmap.h
|
||||
|
||||
INCLUDE = -I.
|
||||
|
||||
WARNINGS= -Wcast-align -Wpacked -Wpadded -Wall
|
||||
|
||||
CCFLAGS = ${INCLUDE} ${DEBUG} ${WARNINGS}
|
||||
|
||||
LDFLAGS =
|
||||
|
||||
COMMON_OBJECTS = $(COMMON_SOURCES:.c=.o)
|
||||
|
||||
NANO_IP = 192.168.254.101
|
||||
|
||||
jz_init_sram: $(COMMON_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(COMMON_OBJECTS) jz_init_sram.c -o jz_init_sram
|
||||
|
||||
jz_test_gpio: $(COMMON_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(COMMON_OBJECTS) jz_test_gpio.c -o jz_test_gpio
|
||||
|
||||
enable_rx: $(COMMON_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(COMMON_OBJECTS) enable_rx.c -o enable_rx
|
||||
|
||||
enable_irq: $(COMMON_OBJECTS)
|
||||
$(CC) $(LDFLAGS) $(COMMON_OBJECTS) enable_irq.c -o enable_irq
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CCFLAGS) $< -o $@
|
||||
|
||||
upload: jz_init_sram jz_test_gpio
|
||||
scp jz_test_gpio jz_init_sram root@$(NANO_IP):
|
||||
|
||||
clean:
|
||||
rm -f *.o jz_init_sram jz_test_gpio enable_rx ${EXEC} *~ enable_irq
|
||||
|
||||
indent:
|
||||
indent -bad -bap -nbc -bl -nce -i2 --no-tabs --line-length120 $(COMMON_SOURCES) $(H_SOURCES)
|
||||
40
Examples/sram_gpio/src/enable_irq.c
Normal file
40
Examples/sram_gpio/src/enable_irq.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
JZ47xx test gpio
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
Carlos Camargo cicamargoba@unal.edu.co
|
||||
|
||||
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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jz47xx_gpio.h"
|
||||
|
||||
#define IRQ_PORT JZ_GPIO_PORT_C
|
||||
#define IRQ_PIN 15
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
JZ_PIO *pio = jz_gpio_map (IRQ_PORT);
|
||||
|
||||
if (!pio)
|
||||
return -1;
|
||||
|
||||
jz_gpio_as_irq (pio, IRQ_PIN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
40
Examples/sram_gpio/src/enable_rx.c
Normal file
40
Examples/sram_gpio/src/enable_rx.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
JZ47xx test gpio
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
Carlos Camargo cicamargoba@unal.edu.co
|
||||
|
||||
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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jz47xx_gpio.h"
|
||||
|
||||
#define RXD_PORT JZ_GPIO_PORT_D
|
||||
#define RXD_PIN 26
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
JZ_PIO *pio = jz_gpio_map (RXD_PORT);
|
||||
|
||||
if (!pio)
|
||||
return -1;
|
||||
|
||||
jz_gpio_as_func (pio, RXD_PIN, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
119
Examples/sram_gpio/src/jz47xx_gpio.c
Normal file
119
Examples/sram_gpio/src/jz47xx_gpio.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
JZ47xx GPIO at userspace
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <jz47xx_gpio.h>
|
||||
#include <jz47xx_mmap.h>
|
||||
|
||||
|
||||
#define JZ_GPIO_BASE 0x10010000
|
||||
|
||||
void
|
||||
jz_gpio_as_output (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELC = (1 << (o));
|
||||
pio->PXDIRS = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_as_input (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELC = (1 << (o));
|
||||
pio->PXDIRC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_as_irq (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXFUNC = (1 << (o));
|
||||
pio->PXSELS = (1 << (o));
|
||||
pio->PXDIRC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_set_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXDATS = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
pio->PXDATC = (1 << (o));
|
||||
}
|
||||
|
||||
void
|
||||
jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val)
|
||||
{
|
||||
if (val == 0)
|
||||
pio->PXDATC = (1 << (o));
|
||||
else
|
||||
pio->PXDATS = (1 << (o));
|
||||
}
|
||||
|
||||
unsigned int
|
||||
jz_gpio_get_pin (JZ_PIO * pio, unsigned int o)
|
||||
{
|
||||
return (pio->PXPIN & (1 << o)) ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func)
|
||||
{
|
||||
switch (func)
|
||||
{
|
||||
case 0:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGC = (1 << o);
|
||||
pio->PXSELC = (1 << o);
|
||||
pio->PXPES = (1 << o);
|
||||
return 1;
|
||||
|
||||
case 1:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGC = (1 << o);
|
||||
pio->PXSELS = (1 << o);
|
||||
pio->PXPES = (1 << o);
|
||||
return 1;
|
||||
|
||||
case 2:
|
||||
pio->PXFUNS = (1 << o);
|
||||
pio->PXTRGS = (1 << o);
|
||||
pio->PXSELC = (1 << o);
|
||||
pio->PXPES = (1 << o);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
JZ_PIO *
|
||||
jz_gpio_map (int port)
|
||||
{
|
||||
JZ_PIO *pio;
|
||||
|
||||
pio = (JZ_PIO *) jz_mmap (JZ_GPIO_BASE);
|
||||
pio = (JZ_PIO *) ((unsigned int) pio + port * 0x100);
|
||||
|
||||
return pio;
|
||||
}
|
||||
84
Examples/sram_gpio/src/jz47xx_gpio.h
Normal file
84
Examples/sram_gpio/src/jz47xx_gpio.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
JZ47xx GPIO at userspace
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#ifndef __jz47xx_gpio_h__
|
||||
#define __jz47xx_gpio_h__
|
||||
|
||||
#define JZ_GPIO_PORT_A 0
|
||||
#define JZ_GPIO_PORT_B 1
|
||||
#define JZ_GPIO_PORT_C 2
|
||||
#define JZ_GPIO_PORT_D 3
|
||||
|
||||
typedef volatile unsigned int JZ_REG; /* Hardware register definition */
|
||||
|
||||
typedef struct _JZ_PIO
|
||||
{
|
||||
JZ_REG PXPIN; /* PIN Level Register */
|
||||
JZ_REG Reserved0;
|
||||
JZ_REG Reserved1;
|
||||
JZ_REG Reserved2;
|
||||
JZ_REG PXDAT; /* Port Data Register */
|
||||
JZ_REG PXDATS; /* Port Data Set Register */
|
||||
JZ_REG PXDATC; /* Port Data Clear Register */
|
||||
JZ_REG Reserved3;
|
||||
JZ_REG PXIM; /* Interrupt Mask Register */
|
||||
JZ_REG PXIMS; /* Interrupt Mask Set Reg */
|
||||
JZ_REG PXIMC; /* Interrupt Mask Clear Reg */
|
||||
JZ_REG Reserved4;
|
||||
JZ_REG PXPE; /* Pull Enable Register */
|
||||
JZ_REG PXPES; /* Pull Enable Set Reg. */
|
||||
JZ_REG PXPEC; /* Pull Enable Clear Reg. */
|
||||
JZ_REG Reserved5;
|
||||
JZ_REG PXFUN; /* Function Register */
|
||||
JZ_REG PXFUNS; /* Function Set Register */
|
||||
JZ_REG PXFUNC; /* Function Clear Register */
|
||||
JZ_REG Reserved6;
|
||||
JZ_REG PXSEL; /* Select Register */
|
||||
JZ_REG PXSELS; /* Select Set Register */
|
||||
JZ_REG PXSELC; /* Select Clear Register */
|
||||
JZ_REG Reserved7;
|
||||
JZ_REG PXDIR; /* Direction Register */
|
||||
JZ_REG PXDIRS; /* Direction Set Register */
|
||||
JZ_REG PXDIRC; /* Direction Clear Register */
|
||||
JZ_REG Reserved8;
|
||||
JZ_REG PXTRG; /* Trigger Register */
|
||||
JZ_REG PXTRGS; /* Trigger Set Register */
|
||||
JZ_REG PXTRGC; /* Trigger Set Register */
|
||||
JZ_REG Reserved9;
|
||||
JZ_REG PXFLG; /* Port Flag Register */
|
||||
JZ_REG PXFLGC; /* Port Flag clear Register */
|
||||
} JZ_PIO, *PJZ_PIO;
|
||||
|
||||
void jz_gpio_as_output (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_as_input (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_set_pin (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_clear_pin (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
void jz_gpio_out (JZ_PIO * pio, unsigned int o, unsigned int val);
|
||||
|
||||
unsigned int jz_gpio_get_pin (JZ_PIO * pio, unsigned int o);
|
||||
|
||||
int jz_gpio_as_func (JZ_PIO * pio, unsigned int o, int func);
|
||||
|
||||
JZ_PIO *jz_gpio_map (int port);
|
||||
|
||||
#endif
|
||||
64
Examples/sram_gpio/src/jz47xx_mmap.c
Normal file
64
Examples/sram_gpio/src/jz47xx_mmap.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* JZ47xx GPIO lines
|
||||
*
|
||||
* Written 2010 by Andres Calderon andres.calderon@emqbit.com
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <jz47xx_mmap.h>
|
||||
|
||||
|
||||
void *
|
||||
jz_mmap (off_t address)
|
||||
{
|
||||
int fd;
|
||||
|
||||
void *pio;
|
||||
|
||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot open /dev/mem.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pio = (void *) mmap (0, getpagesize (), PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
|
||||
|
||||
if (pio == (void *) -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot mmap.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pio;
|
||||
}
|
||||
|
||||
void *
|
||||
jz_fpga_map (off_t address)
|
||||
{
|
||||
int fd;
|
||||
|
||||
void *fpga;
|
||||
|
||||
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot open /dev/mem.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fpga = (void *) mmap (0, FPGA_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, address);
|
||||
|
||||
if (fpga == (void *) -1)
|
||||
{
|
||||
fprintf (stderr, "Cannot mmap.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return fpga;
|
||||
}
|
||||
|
||||
17
Examples/sram_gpio/src/jz47xx_mmap.h
Normal file
17
Examples/sram_gpio/src/jz47xx_mmap.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* JZ47xx GPIO lines
|
||||
*
|
||||
* Written 2010 by Andres Calderon andres.calderon@emqbit.com
|
||||
*/
|
||||
|
||||
#ifndef __jz47xx_mmap_h__
|
||||
#define __jz47xx_mmap_h__
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define FPGA_SIZE (1 << 15)
|
||||
|
||||
void *jz_mmap (off_t address);
|
||||
void *jz_fpga_map (off_t address);
|
||||
|
||||
#endif
|
||||
75
Examples/sram_gpio/src/jz_init_sram.c
Normal file
75
Examples/sram_gpio/src/jz_init_sram.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/* SAKC FPGA/SRAM interface test
|
||||
|
||||
Copyright (C) 2010 Carlos Camargo cicamargoba@unal.edu.co
|
||||
Andres Calderon andres.calderon@emqbit.com
|
||||
|
||||
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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jz47xx_gpio.h"
|
||||
#include "jz47xx_mmap.h"
|
||||
|
||||
#define CS2_PORT JZ_GPIO_PORT_B
|
||||
#define CS2_PIN 26
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int i;
|
||||
JZ_PIO *pio;
|
||||
int *virt_addr;
|
||||
|
||||
pio = jz_gpio_map (CS2_PORT);
|
||||
jz_gpio_as_func (pio, CS2_PIN, 0);
|
||||
|
||||
virt_addr = (int *) jz_mmap (0x13010000) + 0x18;
|
||||
|
||||
if (*virt_addr != 0xFFF7700)
|
||||
{ // 0 WS, 8 bits
|
||||
*virt_addr = 0xFFF7700;
|
||||
printf ("Configuring CS2 8 bits \n");
|
||||
}
|
||||
else
|
||||
printf ("CS3, already configured\n");
|
||||
|
||||
virt_addr = (int *) jz_fpga_map (0x15000000);
|
||||
|
||||
printf ("Writing Memory..\n");
|
||||
|
||||
srand48(0x3c);
|
||||
|
||||
for (i = 0; i < FPGA_SIZE/4; i++)
|
||||
virt_addr[i] = (lrand48() & 0x00ff);
|
||||
|
||||
printf ("Reading Memory..\n");
|
||||
|
||||
|
||||
srand48(0x3c);
|
||||
|
||||
for (i = 0; i < FPGA_SIZE/4; i++){
|
||||
printf("%X\n", virt_addr[i]);
|
||||
if (virt_addr[i] != (lrand48() & 0x00ff)){
|
||||
printf ("FPGA - Xburst connection test failed on Address:0x%x\n", i);
|
||||
return 1; /* Error */
|
||||
}
|
||||
}
|
||||
printf ("%d\n", i);
|
||||
printf ("FPGA - Xburst connection test passed\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
59
Examples/sram_gpio/src/jz_test_gpio.c
Normal file
59
Examples/sram_gpio/src/jz_test_gpio.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
JZ47xx test gpio
|
||||
|
||||
Copyright (C) 2010 Andres Calderon andres.calderon@emqbit.com
|
||||
Carlos Camargo cicamargoba@unal.edu.co
|
||||
|
||||
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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jz47xx_gpio.h"
|
||||
|
||||
//#define TEST_PORT JZ_GPIO_PORT_C
|
||||
//#define TEST_PIN 17
|
||||
|
||||
int
|
||||
main (int argc,char *argv[])
|
||||
|
||||
{
|
||||
int TEST_PORT, TEST_PIN;
|
||||
|
||||
if(argc != 3){
|
||||
fprintf(stderr,"\nUsage: %s TEST_PIN_PORT(A=0, B=1, C=2, D=3) TEST_PIN \n",argv[0]);
|
||||
}
|
||||
|
||||
TEST_PORT = ;
|
||||
TEST_PIN = ;
|
||||
JZ_PIO *pio = jz_gpio_map (TEST_PORT);
|
||||
|
||||
if (!pio)
|
||||
return -1;
|
||||
|
||||
jz_gpio_as_output (pio, TEST_PIN);
|
||||
|
||||
int tg = 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
jz_gpio_out (pio, TEST_PIN, tg);
|
||||
printf ("[%d]", jz_gpio_get_pin (pio, TEST_PIN));
|
||||
fflush (stdout);
|
||||
usleep (500 * 1000);
|
||||
tg = !tg;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user