From e0735185b998f1e0bf61831bb15d802fada4e4ae Mon Sep 17 00:00:00 2001 From: Bert Lange Date: Tue, 25 Oct 2011 23:28:58 +0200 Subject: add: software test for gpio module --- zpu/hdl/zpu4/test/gpiotest/build.sh | 4 ++ zpu/hdl/zpu4/test/gpiotest/gpiotest.c | 72 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100755 zpu/hdl/zpu4/test/gpiotest/build.sh create mode 100644 zpu/hdl/zpu4/test/gpiotest/gpiotest.c 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(); +} -- cgit v1.1