gpio_test.c
5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "pi_util.h"
#include <PR/bbsim.h>
#define __GPIO_OUT_MASK(val) ((val)&0xff)
/*
* GPIO, 1 (GPIO board-id)
*/
void gpioBoardId()
{
u32 val,initId;
int i;
int result = FAIL;
/* record initial value of board id */
initId = IO_READ(PI_GPIO_REG);
initId = ((initId&PI_GPIO_ID_MASK)>>PI_GPIO_ID_SHIFT)&0xffff;
for(i=6; i<16; i++){
/* take ide bus out of reset */
val = IO_READ(PI_IDE_CONFIG_REG);
IO_WRITE(PI_IDE_CONFIG_REG,val&(~PI_IDE_CONFIG_RESET));
IDE_WRITE(PI_IDE3_SET_BOARDID,(1<<i));
pin_reset();
/* enter secure mode again after pin reset */
IO_READ(MI_SEC_MODE_REG);
IO_READ(BOOT_RAM_LO_START);
val = IO_READ(PI_GPIO_REG);
if((((val&PI_GPIO_ID_MASK)>>PI_GPIO_ID_SHIFT)&0xffff) != (1<<i)){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: board id bit %d.\n",i));
goto printresult;
}
}
result = PASS;
printresult:
/* reset ide bus */
val = IO_READ(PI_IDE_CONFIG_REG);
IO_WRITE(PI_IDE_CONFIG_REG,val&(~PI_IDE_CONFIG_RESET));
/* restore initial board id */
IDE_WRITE(PI_IDE3_SET_BOARDID,initId);
pin_reset();
/* enter secure mode again after pin reset */
IO_READ(MI_SEC_MODE_REG);
IO_READ(BOOT_RAM_LO_START);
val = IO_READ(PI_GPIO_REG);
printf("gpioBoardId ");
OUTPUT_TEST_PASSFAIL(result);
fflush(NULL);
}
/*
* GPIO, 2 (GPIO signals)
*/
void gpioSignals()
{
u32 val,gpioIoMask,ideIoMask,ideWriteNibble,gpioWriteNibble;
int i;
int result = FAIL;
/* reset ide bus */
val = IO_READ(PI_IDE_CONFIG_REG);
IO_WRITE(PI_IDE_CONFIG_REG,val&(~PI_IDE_CONFIG_RESET));
/* all gpio pins for read */
IO_WRITE(PI_GPIO_REG,
(0x0<<PI_GPIO_ENABLE_SHIFT) | (0x0<<PI_GPIO_DATA_SHIFT));
IDE_WRITE(PI_IDE3_GPIO_LOOPBACK,
(0xf<<PI_GPIO_ENABLE_SHIFT) | (0xf<<PI_GPIO_DATA_SHIFT) );
val = IO_READ(PI_GPIO_REG);
if( ((val & PI_GPIO_DATA_MASK)>>PI_GPIO_DATA_SHIFT) != 0xf ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: all gpio read 1.\n"));
goto printresult;
}
IDE_WRITE(PI_IDE3_GPIO_LOOPBACK,
(0xf<<PI_GPIO_ENABLE_SHIFT) | (0x0<<PI_GPIO_DATA_SHIFT) );
val = IO_READ(PI_GPIO_REG);
if( ((val & PI_GPIO_DATA_MASK)>>PI_GPIO_DATA_SHIFT) != 0x0 ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: all gpio read 0.\n"));
goto printresult;
}
/* all gpio pins for write */
IO_WRITE(PI_GPIO_REG,
(0xf<<PI_GPIO_ENABLE_SHIFT) | (0xf<<PI_GPIO_DATA_SHIFT));
IDE_WRITE(PI_IDE3_GPIO_LOOPBACK,
(0x0<<PI_GPIO_ENABLE_SHIFT) | (0x0<<PI_GPIO_DATA_SHIFT) );
val = (u32)IDE_READ(PI_IDE3_GPIO_LOOPBACK);
if( ((val & PI_GPIO_DATA_MASK)>>PI_GPIO_DATA_SHIFT) != 0xf ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: all gpio write 1.\n"));
goto printresult;
}
IO_WRITE(PI_GPIO_REG,
(0xf<<PI_GPIO_ENABLE_SHIFT) | (0x0<<PI_GPIO_DATA_SHIFT));
val = (u32)IDE_READ(PI_IDE3_GPIO_LOOPBACK);
if( ((val & PI_GPIO_DATA_MASK)>>PI_GPIO_DATA_SHIFT) != 0x0 ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: all gpio write 0.\n"));
goto printresult;
}
/* one gpio pin enabled for read at a time */
for(i=0; i<4; i++){
ideIoMask = 1<<(PI_GPIO_ENABLE_SHIFT+i);
gpioIoMask = (~ideIoMask)&PI_GPIO_ENABLE_MASK;
ideWriteNibble = 0xf<<PI_GPIO_DATA_SHIFT;
gpioWriteNibble = 0x0<<PI_GPIO_DATA_SHIFT;
IO_WRITE(PI_GPIO_REG,gpioIoMask+gpioWriteNibble);
IDE_WRITE(PI_IDE3_GPIO_LOOPBACK,ideIoMask+ideWriteNibble);
/* insure read values are correct */
val = IO_READ(PI_GPIO_REG);
if( (val & (ideIoMask>>PI_GPIO_ENABLE_SHIFT)) !=
(ideWriteNibble&(ideIoMask>>PI_GPIO_ENABLE_SHIFT)) ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: gpio read pin %d, read 1.\n",i));
goto printresult;
}
/* insure write values are correct */
val = (u32)IDE_READ(PI_IDE3_GPIO_LOOPBACK);
if( (val & (gpioIoMask>>PI_GPIO_ENABLE_SHIFT)) !=
(gpioWriteNibble&(gpioIoMask>>PI_GPIO_ENABLE_SHIFT)) ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: gpio read pin %d, write 0.\n",i));
goto printresult;
}
ideWriteNibble = 0x0<<PI_GPIO_DATA_SHIFT;
gpioWriteNibble = 0xf<<PI_GPIO_DATA_SHIFT;
IO_WRITE(PI_GPIO_REG,gpioIoMask+gpioWriteNibble);
IDE_WRITE(PI_IDE3_GPIO_LOOPBACK,ideIoMask+ideWriteNibble);
/* insure read values are correct */
val = IO_READ(PI_GPIO_REG);
if( (val & (ideIoMask>>PI_GPIO_ENABLE_SHIFT)) !=
(ideWriteNibble&(ideIoMask>>PI_GPIO_ENABLE_SHIFT)) ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: gpio read pin %d, read 0.\n",i));
goto printresult;
}
/* insure write values are correct */
val = (u32)IDE_READ(PI_IDE3_GPIO_LOOPBACK);
if( (val & (gpioIoMask>>PI_GPIO_ENABLE_SHIFT)) !=
(gpioWriteNibble&(gpioIoMask>>PI_GPIO_ENABLE_SHIFT)) ){
_TRACE(DERROR, fprintf(LogFp,
" ERROR: gpio read pin %d, write 1.\n",i));
goto printresult;
}
}
result = PASS;
printresult:
printf("gpioSignals ");
OUTPUT_TEST_PASSFAIL(result);
fflush(NULL);
}