From 83f727f76add578ff6c8e4e949d1e3268b9fba09 Mon Sep 17 00:00:00 2001 From: Carlos Camargo Date: Fri, 24 Sep 2010 10:27:12 -0500 Subject: [PATCH] Adding sram_gpio_QT example --- Examples/sram_gpio/QT_src/compile-mips | 5 + Examples/sram_gpio/QT_src/jz47xx_gpio.cpp | 108 +++++++++++++++++++++ Examples/sram_gpio/QT_src/jz47xx_gpio.h | 84 ++++++++++++++++ Examples/sram_gpio/QT_src/jz47xx_mmap.cpp | 39 ++++++++ Examples/sram_gpio/QT_src/jz47xx_mmap.h | 14 +++ Examples/sram_gpio/QT_src/main.cpp | 10 ++ Examples/sram_gpio/QT_src/mainwindow.cpp | 86 ++++++++++++++++ Examples/sram_gpio/QT_src/mainwindow.h | 39 ++++++++ Examples/sram_gpio/QT_src/mainwindow.ui | 87 +++++++++++++++++ Examples/sram_gpio/QT_src/sram_gpio_QT.pro | 13 +++ lm32/logic/sakc/system_tb.v | 4 +- 11 files changed, 487 insertions(+), 2 deletions(-) create mode 100755 Examples/sram_gpio/QT_src/compile-mips create mode 100644 Examples/sram_gpio/QT_src/jz47xx_gpio.cpp create mode 100644 Examples/sram_gpio/QT_src/jz47xx_gpio.h create mode 100644 Examples/sram_gpio/QT_src/jz47xx_mmap.cpp create mode 100644 Examples/sram_gpio/QT_src/jz47xx_mmap.h create mode 100644 Examples/sram_gpio/QT_src/main.cpp create mode 100644 Examples/sram_gpio/QT_src/mainwindow.cpp create mode 100644 Examples/sram_gpio/QT_src/mainwindow.h create mode 100644 Examples/sram_gpio/QT_src/mainwindow.ui create mode 100644 Examples/sram_gpio/QT_src/sram_gpio_QT.pro diff --git a/Examples/sram_gpio/QT_src/compile-mips b/Examples/sram_gpio/QT_src/compile-mips new file mode 100755 index 0000000..6cdc0dc --- /dev/null +++ b/Examples/sram_gpio/QT_src/compile-mips @@ -0,0 +1,5 @@ +#!/bin/sh +QT_BASE_DIR="/home/cain/Embedded/ingenic/sakc/build/openwrt-xburst/build_dir/target-mipsel_uClibc-0.9.32/qt-everywhere-opensource-src-4.7.0-beta2" +${QT_BASE_DIR}/bin/qmake -spec ${QT_BASE_DIR}/mkspecs/qws/linux-openwrt-g++ -o Makefile +make + diff --git a/Examples/sram_gpio/QT_src/jz47xx_gpio.cpp b/Examples/sram_gpio/QT_src/jz47xx_gpio.cpp new file mode 100644 index 0000000..affa85e --- /dev/null +++ b/Examples/sram_gpio/QT_src/jz47xx_gpio.cpp @@ -0,0 +1,108 @@ +/* + 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 +#include +#include + +#include +#include + + +#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_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); + return 1; + + case 1: + pio->PXFUNS = (1 << o); + pio->PXTRGC = (1 << o); + pio->PXSELS = (1 << o); + return 1; + + case 2: + pio->PXFUNS = (1 << o); + pio->PXTRGS = (1 << o); + pio->PXSELC = (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; +} diff --git a/Examples/sram_gpio/QT_src/jz47xx_gpio.h b/Examples/sram_gpio/QT_src/jz47xx_gpio.h new file mode 100644 index 0000000..d8b0113 --- /dev/null +++ b/Examples/sram_gpio/QT_src/jz47xx_gpio.h @@ -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 diff --git a/Examples/sram_gpio/QT_src/jz47xx_mmap.cpp b/Examples/sram_gpio/QT_src/jz47xx_mmap.cpp new file mode 100644 index 0000000..52266bb --- /dev/null +++ b/Examples/sram_gpio/QT_src/jz47xx_mmap.cpp @@ -0,0 +1,39 @@ +/* + * JZ47xx GPIO lines + * + * Written 2010 by Andres Calderon andres.calderon@emqbit.com + */ + +#include +#include +#include +#include +#include +#include + +#include + + +unsigned int * +jz_mmap (off_t address) +{ + int fd; + + unsigned int *pio; + + if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1) + { + fprintf (stderr, "Cannot open /dev/mem.\n"); + return 0; + } + + pio = (unsigned int *) mmap (0, getpagesize (), PROT_READ | PROT_WRITE, MAP_SHARED, fd, address); + + if (pio == (unsigned int *) -1) + { + fprintf (stderr, "Cannot mmap.\n"); + return 0; + } + + return pio; +} diff --git a/Examples/sram_gpio/QT_src/jz47xx_mmap.h b/Examples/sram_gpio/QT_src/jz47xx_mmap.h new file mode 100644 index 0000000..7380eb6 --- /dev/null +++ b/Examples/sram_gpio/QT_src/jz47xx_mmap.h @@ -0,0 +1,14 @@ +/* + * JZ47xx GPIO lines + * + * Written 2010 by Andres Calderon andres.calderon@emqbit.com + */ + +#ifndef __jz47xx_mmap_h__ +#define __jz47xx_mmap_h__ + +#include + +unsigned int * jz_mmap (off_t address); + +#endif diff --git a/Examples/sram_gpio/QT_src/main.cpp b/Examples/sram_gpio/QT_src/main.cpp new file mode 100644 index 0000000..6e7efd9 --- /dev/null +++ b/Examples/sram_gpio/QT_src/main.cpp @@ -0,0 +1,10 @@ +#include +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/Examples/sram_gpio/QT_src/mainwindow.cpp b/Examples/sram_gpio/QT_src/mainwindow.cpp new file mode 100644 index 0000000..5b44378 --- /dev/null +++ b/Examples/sram_gpio/QT_src/mainwindow.cpp @@ -0,0 +1,86 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + RAM=initFPGA_RAM(); + LED=initGPIO_LED(); + iter=0; + + startTimer(1000); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +JZ_PIO * +MainWindow::initGPIO_LED() +{ + JZ_PIO *pio; + + pio = jz_gpio_map (LED_PORT); + jz_gpio_as_output (pio, LED_PIN); + jz_gpio_clear_pin (pio, LED_PIN); + + return pio; +} + +JZ_REG * +MainWindow::initFPGA_RAM() +{ + JZ_PIO *pio; + JZ_REG *virt_addr; + + pio = jz_gpio_map (CS2_PORT); + jz_gpio_as_func (pio, CS2_PIN, 0); + + virt_addr = (JZ_REG *) (jz_mmap(0x13010000) + 0x18); + + if (*virt_addr != 0x0FFF7700) + { + *virt_addr = 0x0FFF7700; + printf ("ADC: Configuring CS2 8 bits and 0 WS: %08X\n", *virt_addr); + } + else + printf ("ADC: CS2, already configured: %08X\n", *virt_addr); + + virt_addr = (JZ_REG *) jz_mmap (0x14000000); + + return virt_addr; +} + + +void +MainWindow::timerEvent(QTimerEvent*) +{ + QString plain_text; + + jz_gpio_out (LED, LED_PIN, iter&0b1); + + if(iter&0b1) plain_text = "[ON]"; else plain_text = "[OFF]"; + ui->label_2->setText("LED is " + plain_text); + iter++; + + /* Escribiendo en RAM */ + plain_text="\t**Iteration: "+QString::number(iter)+"**\nW:"; + for(int i = 0; i<14; i++) + { + RAM[i]= i & 0xFF; + plain_text+="["+QString::number(i&0xFF)+"]"; + } + + /* Leyendo de RAM */ + int temp; + plain_text+="\nR:"; + for(int i = 0; i<14; i++) + { + temp=RAM[i]; + plain_text+="["+QString::number(temp)+"]"; + } + ui->plainTextEdit->appendPlainText(plain_text); +} diff --git a/Examples/sram_gpio/QT_src/mainwindow.h b/Examples/sram_gpio/QT_src/mainwindow.h new file mode 100644 index 0000000..e4ba565 --- /dev/null +++ b/Examples/sram_gpio/QT_src/mainwindow.h @@ -0,0 +1,39 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + + + +#include +#include "jz47xx_mmap.h" +#include "jz47xx_gpio.h" + +#define CS2_PORT JZ_GPIO_PORT_B +#define CS2_PIN 26 +#define LED_PORT JZ_GPIO_PORT_C +#define LED_PIN 17 + + + + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow { + Q_OBJECT +public: + MainWindow(QWidget *parent = 0); + ~MainWindow(); + JZ_PIO *initGPIO_LED(); + JZ_REG *initFPGA_RAM(); + +private: + Ui::MainWindow *ui; + JZ_PIO *LED; + JZ_REG *RAM; + int iter; +protected: + void timerEvent(QTimerEvent*); +}; + +#endif // MAINWINDOW_H diff --git a/Examples/sram_gpio/QT_src/mainwindow.ui b/Examples/sram_gpio/QT_src/mainwindow.ui new file mode 100644 index 0000000..cc75877 --- /dev/null +++ b/Examples/sram_gpio/QT_src/mainwindow.ui @@ -0,0 +1,87 @@ + + + MainWindow + + + + 0 + 0 + 320 + 240 + + + + MainWindow + + + + + + 10 + 0 + 261 + 151 + + + + + + + 90 + 160 + 62 + 17 + + + + TextLabel + + + + + + 210 + 160 + 62 + 17 + + + + TextLabel + + + + + + false + + + + 0 + 0 + 320 + 23 + + + + + + false + + + TopToolBarArea + + + false + + + + + false + + + + + + + diff --git a/Examples/sram_gpio/QT_src/sram_gpio_QT.pro b/Examples/sram_gpio/QT_src/sram_gpio_QT.pro new file mode 100644 index 0000000..577acea --- /dev/null +++ b/Examples/sram_gpio/QT_src/sram_gpio_QT.pro @@ -0,0 +1,13 @@ +# ------------------------------------------------- +# Project created by QtCreator 2010-09-24T09:17:13 +# ------------------------------------------------- +TARGET = sram_gpio_QT +TEMPLATE = app +SOURCES += main.cpp \ + mainwindow.cpp \ + jz47xx_mmap.cpp \ + jz47xx_gpio.cpp +HEADERS += mainwindow.h \ + jz47xx_mmap.h \ + jz47xx_gpio.h +FORMS += mainwindow.ui diff --git a/lm32/logic/sakc/system_tb.v b/lm32/logic/sakc/system_tb.v index 9ea8c06..b1234b0 100644 --- a/lm32/logic/sakc/system_tb.v +++ b/lm32/logic/sakc/system_tb.v @@ -52,8 +52,8 @@ initial begin $dumpfile("system_tb.vcd"); //$monitor("%b,%b,%b,%b",clk,rst,uart_txd,uart_rxd); - $dumpvars(-1, dut); -// $dumpvars(-1,clk,rst,uart_txd,uart_rxd); +// $dumpvars(-1, dut); + $dumpvars(-1,clk,rst,uart_txd,uart_rxd); // reset #0 rst <= 0; #80 rst <= 1;