summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBert Lange <b.lange@hzdr.de>2011-10-25 23:28:58 +0200
committerBert Lange <b.lange@hzdr.de>2011-10-25 23:28:58 +0200
commite0735185b998f1e0bf61831bb15d802fada4e4ae (patch)
treeb40564d5a2fbd46594909874c1a1119d3ec28f5d
parentc883cd4a4e4fa1974e5d7d72a79240de88bd26da (diff)
downloadzpu-e0735185b998f1e0bf61831bb15d802fada4e4ae.zip
zpu-e0735185b998f1e0bf61831bb15d802fada4e4ae.tar.gz
add: software test for gpio module
-rwxr-xr-xzpu/hdl/zpu4/test/gpiotest/build.sh4
-rw-r--r--zpu/hdl/zpu4/test/gpiotest/gpiotest.c72
2 files changed, 76 insertions, 0 deletions
diff --git a/zpu/hdl/zpu4/test/gpiotest/build.sh b/zpu/hdl/zpu4/test/gpiotest/build.sh
new file mode 100755
index 0000000..c0385ad
--- /dev/null
+++ b/zpu/hdl/zpu4/test/gpiotest/build.sh
@@ -0,0 +1,4 @@
+zpu-elf-gcc -O3 -phi `pwd`/gpiotest.c -o gpiotest.elf -Wl,--relax -Wl,--gc-sections -g
+zpu-elf-objdump --disassemble-all >gpiotest.dis gpiotest.elf
+zpu-elf-objcopy -O binary gpiotest.elf gpiotest.bin
+java -classpath ../../../../sw/simulator/zpusim.jar com.zylin.zpu.simulator.tools.MakeRam gpiotest.bin >gpiotest.ram
diff --git a/zpu/hdl/zpu4/test/gpiotest/gpiotest.c b/zpu/hdl/zpu4/test/gpiotest/gpiotest.c
new file mode 100644
index 0000000..393ab9f
--- /dev/null
+++ b/zpu/hdl/zpu4/test/gpiotest/gpiotest.c
@@ -0,0 +1,72 @@
+/*
+ * Small test program to check GPIOs
+ *
+ * LED chaser until keypress
+ *
+ */
+
+// addresses refer to Phi memory layout
+#define GPIO_DATA *((volatile unsigned int *) 0x080a0004)
+#define GPIO_DIR *((volatile unsigned int *) 0x080a0008)
+
+
+#define BUTTON_EAST (3)
+#define BUTTON_NORTH (2)
+#define BUTTON_SOUTH (1)
+#define BUTTON_WEST (0)
+
+
+#define bit_is_set(var, bit) ((var) & (1 << (bit)))
+#define bit_is_clear(var, bit) ((!(var)) & (1 << (bit)))
+#define loop_until_bit_is_set(var, bit) do { } while (bit_is_clear(var, bit))
+#define loop_until_bit_is_clear(var, bit) do { } while (bit_is_set(var, bit))
+
+
+void led_test( void)
+{
+ unsigned char runs;
+ unsigned char leds;
+
+ runs = 1;
+ leds = 0x01;
+
+ while( runs)
+ {
+ // output
+ GPIO_DATA = leds;
+
+ // read button status
+ if bit_is_set(GPIO_DATA, BUTTON_NORTH)
+ {
+ runs = 0;
+ }
+
+ // LED chaser
+ leds = leds << 1;
+ if (leds == 0)
+ {
+ leds = 0x01;
+ }
+ }
+}
+
+
+void header_test( void)
+{
+ // this test is special for the SP601 header connector
+ // check the output in simulation
+ GPIO_DATA = 0x00550000;
+ GPIO_DIR = 0xff00ffff;
+ GPIO_DATA = 0x00aa0000;
+ GPIO_DIR = 0xffffffff;
+}
+
+
+int main(int argc, char **argv)
+{
+
+ led_test();
+ header_test();
+
+ abort();
+}
OpenPOWER on IntegriCloud