summaryrefslogtreecommitdiffstats
path: root/zpu/hdl/zpu4/test/gpiotest/gpiotest.c
diff options
context:
space:
mode:
authorBert Lange <b.lange@hzdr.de>2015-04-15 13:36:55 +0200
committerBert Lange <b.lange@hzdr.de>2015-04-15 13:36:55 +0200
commita1c964908b51599bf624bd2d253419c7e629f195 (patch)
tree06125d59e83b7dde82d1bb57bc0e09ca83451b98 /zpu/hdl/zpu4/test/gpiotest/gpiotest.c
parentbbfe29a15f11548eb7c9fa71dcb4d2d18c164a53 (diff)
parent8679e4f91dcae05aef40f96629f33f0f4161f14a (diff)
downloadzpu-a1c964908b51599bf624bd2d253419c7e629f195.zip
zpu-a1c964908b51599bf624bd2d253419c7e629f195.tar.gz
Merge branch 'master' of https://github.com/zylin/zpu
Diffstat (limited to 'zpu/hdl/zpu4/test/gpiotest/gpiotest.c')
-rw-r--r--zpu/hdl/zpu4/test/gpiotest/gpiotest.c72
1 files changed, 72 insertions, 0 deletions
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