| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include "sleep.h" |
| 6 |
#include "xil_cache.h" |
| 7 |
#include "xil_io.h" |
| 8 |
#include "xparameters.h" |
| 9 |
#include "xstatus.h" |
| 10 |
|
| 11 |
#define GPIO_WAIT_TIME 5000 |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
|
| 15 |
void gpio_write(u32 value) { |
| 16 |
Xil_Out32((XPAR_AXI_GPREG_BASEADDR + (0x101 * 0x4)), value); |
| 17 |
Xil_Out32((XPAR_AXI_GPREG_BASEADDR + (0x111 * 0x4)), value); |
| 18 |
Xil_Out32((XPAR_AXI_GPREG_BASEADDR + (0x121 * 0x4)), value); |
| 19 |
} |
| 20 |
|
| 21 |
int gpio_read(u32 pin, u32 expected) { |
| 22 |
int ret = XST_SUCCESS; |
| 23 |
u32 rdata; |
| 24 |
|
| 25 |
rdata = Xil_In32(XPAR_AXI_GPREG_BASEADDR + (0x102 * 0x4)); |
| 26 |
if (rdata != expected) { |
| 27 |
xil_printf("Loopback error on pin %d: " |
| 28 |
"wrote 0x%08x, read 0x%08x\r\n", pin, expected, rdata); |
| 29 |
ret = XST_FAILURE; |
| 30 |
} |
| 31 |
|
| 32 |
rdata = Xil_In32(XPAR_AXI_GPREG_BASEADDR + (0x112 * 0x4)); |
| 33 |
if (rdata != expected) { |
| 34 |
xil_printf("Loopback error on pin %d: " |
| 35 |
"wrote 0x%08x, read 0x%08x\r\n", (pin + 32), expected, rdata); |
| 36 |
ret = XST_FAILURE; |
| 37 |
} |
| 38 |
|
| 39 |
if (pin < 24) { |
| 40 |
rdata = Xil_In32(XPAR_AXI_GPREG_BASEADDR + (0x122 * 0x4)); |
| 41 |
if ((rdata & 0xffffff) != ((expected & 0xffffff) | 0x2)) { |
| 42 |
xil_printf("Loopback error on pin %d: " |
| 43 |
"wrote 0x%08x, read 0x%08x\r\n", (pin + 64), |
| 44 |
expected, rdata); |
| 45 |
ret = XST_FAILURE; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
return ret; |
| 50 |
} |
| 51 |
|
| 52 |
void gpio_wait() |
| 53 |
{ |
| 54 |
u32 i; |
| 55 |
|
| 56 |
for(i = 0; i < GPIO_WAIT_TIME; i++) { |
| 57 |
asm("nop"); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
int main() |
| 62 |
{ |
| 63 |
int ret = XST_SUCCESS; |
| 64 |
u32 n, wdata; |
| 65 |
|
| 66 |
Xil_DCacheDisable(); |
| 67 |
Xil_ICacheDisable(); |
| 68 |
|
| 69 |
|
| 70 |
for(n = 0; n < 32; n++) { |
| 71 |
wdata = 1 << n; |
| 72 |
gpio_write(wdata); |
| 73 |
gpio_wait(); |
| 74 |
if (gpio_read(n, wdata) != XST_SUCCESS) |
| 75 |
ret = XST_FAILURE; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
for(n = 0; n < 32; n++) { |
| 80 |
wdata = 1 << n; |
| 81 |
wdata = ~wdata; |
| 82 |
gpio_write(wdata); |
| 83 |
gpio_wait(); |
| 84 |
if (gpio_read(n, wdata) != XST_SUCCESS) |
| 85 |
ret = XST_FAILURE; |
| 86 |
} |
| 87 |
|
| 88 |
return ret; |
| 89 |
} |