1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2025-04-21 12:27:27 +03:00

Updating examples to Board changes, adding irq driver demo

This commit is contained in:
Carlos Camargo
2010-06-11 08:06:13 -05:00
parent c8b70e5307
commit 5041c0eb60
41 changed files with 2263 additions and 145 deletions

View File

@@ -1,6 +1,7 @@
NET clk LOC = "P38";
NET reset LOC = "P71"; #WARNING change to another pin
NET led LOC = "P44";
NET clk LOC = "P38";
NET reset LOC = "P30"; #WARNING change to another pin
NET led LOC = "P44";
NET irq_pin LOC = "P71";
#ADDRESS BUS
NET "addr<12>" LOC = "P90";

View File

@@ -1,13 +1,14 @@
`timescale 1ns / 1ps
module ADC(clk, sram_data, addr, nwe, ncs, noe, reset, led, ADC_EOC,
ADC_SCLK, ADC_SDIN, ADC_SDOUT, ADC_CS, ADC_CSTART);
ADC_SCLK, ADC_SDIN, ADC_SDOUT, ADC_CS, ADC_CSTART, irq_pin);
parameter B = (7);
parameter B = (7);
input clk, addr, nwe, ncs, noe, reset, ADC_EOC;
inout [B:0] sram_data;
output led, ADC_CS, ADC_CSTART, ADC_SCLK;
inout ADC_SDIN, ADC_SDOUT;
inout ADC_SDIN, ADC_SDOUT;
input irq_pin;
// Internal conection
@@ -32,7 +33,7 @@ module ADC(clk, sram_data, addr, nwe, ncs, noe, reset, led, ADC_EOC,
// Test : LED blinking
always @(posedge clk) begin
if (reset)
if (~reset)
counter <= {25{1'b0}};
else
counter <= counter + 1;
@@ -54,7 +55,7 @@ module ADC(clk, sram_data, addr, nwe, ncs, noe, reset, led, ADC_EOC,
// write access cpu to bram
always @(posedge clk)
if(reset) {w_st, we, wrBus} <= 0;
if(~reset) {w_st, we, wrBus} <= 0;
else begin
wrBus <= buffer_data;
case (w_st)
@@ -89,7 +90,7 @@ module ADC(clk, sram_data, addr, nwe, ncs, noe, reset, led, ADC_EOC,
// Peripheral instantiation
ADC_peripheral P1(
.clk(clk),
.reset(reset),
.reset(~reset),
.cs(csN[0]),
.ADC_EOC(ADC_EOC),
.ADC_CS(ADC_CS),

View File

@@ -1,5 +1,5 @@
NET clk LOC = "P38";
NET reset LOC = "P71";
NET reset LOC = "P30";
NET led LOC = "P44";
#ADDRESS BUS

View File

@@ -5,7 +5,7 @@ module blink(clk, reset, led);
reg [24:0] counter;
always @(posedge clk) begin
if (reset)
if (~reset)
counter <= {25{1'b0}};
else
counter <= counter + 1;

View File

@@ -0,0 +1,23 @@
EXTRA_CFLAGS += -Wall
CC = mipsel-openwrt-linux-gcc
OPENWRT_BASE = /home/cain/Embedded/ingenic/sakc/build/openwrt-xburst
KERNEL_SRC = $(OPENWRT_BASE)/build_dir/linux-xburst_qi_lb60/linux-2.6.32.10/
CROSS_COMPILE = mipsel-openwrt-linux-
obj-m += irq.o
all: driver irq_main
driver:
make -C $(KERNEL_SRC) M=$(PWD) ARCH=mips CROSS_COMPILE=$(CROSS_COMPILE) modules
clean:
make -C $(KERNEL_SRC) M=$(PWD) ARCH=mips CROSS_COMPILE=$(CROSS_COMPILE) clean
rm -rf *.o main.o main irq.ko Modules.symvers irq_main
main: main.o
PREPROCESS.c = $(CC) $(CFLAGS) $(TARGET_ARCH) -E -Wp,-C,-dD,-dI
%.pp : %.c FORCE
$(PREPROCESS.c) $< > $@

175
Examples/drivers/IRQ/irq.c Normal file
View File

@@ -0,0 +1,175 @@
/*
* Interrupt device driver demo
*
* Author: Andres Calderon
* Created: September 16, 2005
* Copyright: (C) 2005 emQbit Ltda
*
* 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.
*
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/ioport.h>
#include <linux/device.h>
#include <linux/interrupt.h> /* We want an interrupt */
#include <linux/irq.h> /* We want an interrupt */
#include <linux/platform_device.h>
#include <linux/fs.h>
#include <asm/delay.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/gpio.h>
#include <asm/mach-jz4740/gpio.h>
#define FPGA_IRQ_PIN JZ_GPIO_PORTC(15)
#define FPGA_BASE 0x15000000 //FPGA_BASE (FPGA) 0x14000000 - 0x17FFFFFF //
#define SUCCESS 0
#define DEVICE_NAME "irq" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
static int irq_enabled = 0;
static int is_device_open = 0; /* Is device open? Used to prevent multiple access to device */
static int Major;
void __iomem *ioaddress;
static unsigned int interrupt_counter = 0;
static DECLARE_WAIT_QUEUE_HEAD(wq);
struct file_operations fops = {
.owner = THIS_MODULE,
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
static irqreturn_t irq_handler(int irq, void *dev_id)
{
if(irq_enabled)
{
interrupt_counter++;
printk(KERN_INFO "interrupt_counter=%d\n",interrupt_counter);
wake_up_interruptible(&wq);
}
return IRQ_HANDLED;
}
static int __init qem_init(void)
{
int res, irq;
printk(KERN_INFO "FPGA module is Up.\n");
interrupt_counter = 0;
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return Major;
}
printk(KERN_ALERT "I was assigned major number %d. To talk to\n", Major);
printk(KERN_ALERT "the driver, create a dev file with\n");
printk(KERN_ALERT "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
/* Set up the FGPA irq line */
irq = gpio_to_irq(FPGA_IRQ_PIN);
res = request_irq(irq, irq_handler, IRQF_DISABLED | IRQF_TRIGGER_RISING, "FPGA - IRQ", NULL); // IRQF_TRIGGER_FALLING
ioaddress = ioremap(FPGA_BASE, 0x4000);
return 0;
}
static void __exit qem_exit(void)
{
// int ret;
/*Tho order for free_irq, iounmap & unregister is very important */
free_irq(FPGA_IRQ_PIN, NULL);
iounmap(ioaddress);
unregister_chrdev(Major, DEVICE_NAME);
printk(KERN_INFO "FPGA driver is down...\n");
}
static int device_open(struct inode *inode, struct file *file)
{
if (is_device_open)
return -EBUSY;
is_device_open = 1;
try_module_get(THIS_MODULE);
return SUCCESS;
}
static int device_release(struct inode *inode, struct file *file)
{
is_device_open = 0;
module_put(THIS_MODULE);
return 0;
}
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t count, /* length of the buffer */
loff_t *offset)
{
wait_event_interruptible(wq, interrupt_counter!=0);
return copy_to_user(buffer, &interrupt_counter, sizeof(interrupt_counter)) ? -EFAULT : 0;
}
static ssize_t
device_write(struct file *filp, const char *buff, size_t count, loff_t * off)
{
const char cmd = buff[0];
if(cmd=='Q')
{
irq_enabled = 1;
printk(KERN_INFO "FPGA irq_enabled...\n");
}
else
if(cmd=='S'){
irq_enabled = 0;
printk(KERN_INFO "FPGA irq disabled.\n");
}
return 1;
}
module_init(qem_init);
module_exit(qem_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andres Calderon <andresn@emqbit.com>");
MODULE_DESCRIPTION("FPGA' IRQ driver");
MODULE_VERSION("1:0.1");

View File

@@ -0,0 +1,53 @@
/*******************************************************************************
*
* Filename: irq_main.c
* Author: Carlos Camargo
* Created: June 10, 2010
*
* 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.
*
******************************************************************************/
#include "stdio.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int fileNum, bytes;
unsigned char buf[40];
size_t nbytes;
ssize_t bytes_read;
if(argc != 2){
fprintf(stderr,"\nUsage: %s enable|disable|read \n",argv[0]);
}
nbytes = sizeof(int);
fileNum = open("/dev/irq", O_RDWR);
if (fileNum < 0) {
printf(" Unable to open device\n");
exit(1);
}
printf("Device opened successfully \n");
if(!strcmp(argv[1], "enable"))
write(fileNum, "Q", 1);
if(!strcmp(argv[1], "disable"))
write(fileNum, "S", 1);
if(!strcmp(argv[1], "read")){
read(fileNum, buf, nbytes);
printf("Interrupts = %d \n", *((int*)(buf)));
}
if( (strcmp(argv[1], "read") != 0 ) & (strcmp(argv[1], "disable") != 0) & (strcmp(argv[1], "enable") != 0) )
fprintf(stderr,"\nUsage: %s enable|disable|read \n",argv[0]);
close(fileNum);
return (0);
}

View File

@@ -1,7 +1,6 @@
OBJS := start.o main.o jz_serial.o
CROSS := mipsel-elf-
CROSS := mipsel-openwrt-linux-
CFLAGS := -O2 -G 0 -mno-abicalls -fno-pic -mips32 -Iinclude
AFLAGS = -D__ASSEMBLY__ $(CFLAGS)

View File

@@ -1,2 +0,0 @@
sudo usbboot -f ./usbboot_2gb_nand.cfg -c "boot"
sudo usbboot -f ./usbboot_2gb_nand.cfg -c "nprog 0 openwrt-xburst-u-boot.bin 0 0 -n"

View File

@@ -1,25 +0,0 @@
OBJS := start.o main.o jz_serial.o
CROSS := mipsel-elf-
CFLAGS := -O2 -G 0 -mno-abicalls -fno-pic -mips32 -Iinclude
AFLAGS = -D__ASSEMBLY__ $(CFLAGS)
LDFLAGS := -T ld.script -nostdlib -EL
.c.o:
$(CROSS)gcc $(CFLAGS) -c $< -o $@
.S.o:
$(CROSS)gcc $(AFLAGS) -c $< -o $@
jz_xloader.bin: jz_xloader
$(CROSS)objdump -D jz_xloader $< > jz_xloader.dump
$(CROSS)objcopy -O binary $< $@
jz_xloader: $(OBJS)
$(CROSS)ld $(LDFLAGS) $^ -o $@
upload:
usbtool 1
clean:
rm -fr *.o jz_xloader jz_xloader.bin jz_xloader.dump

View File

@@ -1,7 +1,7 @@
OBJS := start.o main.o jz_serial.o
CROSS := mipsel-elf-
CROSS := mipsel-openwrt-linux-
CFLAGS := -O2 -G 0 -mno-abicalls -fno-pic -mips32 -Iinclude
AFLAGS = -D__ASSEMBLY__ $(CFLAGS)

View File

@@ -1,6 +1,7 @@
NET clk LOC = "P38";
NET reset LOC = "P71";
NET led LOC = "P44";
NET clk LOC = "P38";
NET reset LOC = "P30";
NET led LOC = "P44";
NET irq_pin LOC = "P71";
#ADDRESS BUS
NET "addr<12>" LOC = "P90";

View File

@@ -1,11 +1,12 @@
`timescale 1ns / 1ps
module sram_bus(clk, sram_data, addr, nwe, ncs, noe, reset, led);
module sram_bus(clk, sram_data, addr, nwe, ncs, noe, reset, led, irq_pin);
parameter B = (7);
input clk, nwe, ncs, noe, reset;
input [12:0] addr;
inout [B:0] sram_data;
output led;
input irq_pin;
// synchronize signals
reg sncs, snwe;
@@ -39,7 +40,7 @@ module sram_bus(clk, sram_data, addr, nwe, ncs, noe, reset, led);
// write access cpu to bram
always @(posedge clk)
if(reset) {w_st, we, wdBus} <= 0;
if(~reset) {w_st, we, wdBus} <= 0;
else begin
wdBus <= buffer_data;
case (w_st)
@@ -71,7 +72,7 @@ RAMB16_S2 ba3( .CLK(~clk), .EN(1'b1), .SSR(1'b0), .ADDR(buffer_addr),
reg [24:0] counter;
always @(posedge clk) begin
if (reset)
if (~reset)
counter <= {25{1'b0}};
else
counter <= counter + 1;

View File

@@ -1,6 +1,6 @@
CC = mipsel-openwrt-linux-gcc
all: jz_init_sram jz_test_gpio enable_rx
all: jz_init_sram jz_test_gpio enable_rx enable_irq
DEBUG = -O3 -g0
@@ -29,6 +29,9 @@ jz_test_gpio: $(COMMON_OBJECTS)
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 $@
@@ -36,7 +39,7 @@ 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} *~
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)

View File

@@ -43,6 +43,14 @@ jz_gpio_as_input (JZ_PIO * pio, unsigned int 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)
{