11 #include <sys/ioctl.h>
14 #include <linux/mcst/msps_io.h>
15 #include <linux/mcst/mcst_selftest.h>
19 #define myprintf(fmt, args...) printf("* msps_test:\t" fmt, ## args)
21 #define DEV_NAME "/dev/msps0"
24 char dev_name
[1024] = DEV_NAME
;
26 int selftest_flag
= 0;
28 int data_size
= 64; /* bytes */
30 int testmode_flag
= 0; /* plug at PLIS 1 -> 0, 3 -> 2, 5 -> 4 */
33 static time_t test_time
= 60;
34 static time_t print_time
= 5;
36 void print_first_dma()
38 myprintf("first dma bytes: 0x%lx 0x%lx\n",
39 *(dma
[0] + 0), *(dma
[1] + 0));
40 myprintf("second dma bytes: 0x%lx 0x%lx\n",
41 *(dma
[0] + 1), *(dma
[1] + 1));
46 test_opt(int ac
, char **av
)
49 while ((i
= getopt(ac
, av
, "?hnTi:t:Ss:p:aA:")) != EOF
) {
52 instance
= atol(optarg
);
53 if (instance
== 1 || instance
== 3 || instance
== 5)
55 sprintf(dev_name
, "/dev/msps%d", instance
);
61 active_work
= atol(optarg
);
65 case 'd': /* temporary off */
66 sprintf(dev_name
, "%s", optarg
);
69 test_time
= atol(optarg
);
80 data_size
= atol(optarg
);
85 print_time
= atol(optarg
);
92 printf("Parameters:\n"
93 "\t[-d path to device (temporary off)]\n"
94 "\t[-i instance number/dev/msps?]\n"
97 "\t[-S run internal test]\n"
98 "\t[-p period output print]\n"
99 "\t[-T test exchange mode]\n"
100 "\t[-n do nothing, only open/close (-S working)]\n"
101 "\t[-a active wait on cpu (not interrupt) 10 microsec]\n"
102 "\t[-A active wait on cpu - arg - time waiting]\n");
109 int main(int ac
, char **av
)
113 msps_status_t status
;
114 msps_setup_a_t activetask
;
115 msps_setup_t
*task
= &activetask
.s
;
121 fd
= open(dev_name
, O_RDWR
);
123 myprintf("Cant open device (%s): %s\n",
124 dev_name
, strerror(errno
));
131 res
= ioctl(fd
, MCST_SELFTEST_MAGIC
, &test
);
133 myprintf("selfttest ioctl get error\n");
136 printf("selftest: %d %d (0x%x 0x%x 0x%x) [%d %d] (0x%x 0x%x 0x%x) \"%s\"\n",
139 test
.info
.pci
.vendor
,
140 test
.info
.pci
.device
,
155 dma
[0] = (u_long
*)mmap(0, MSPS_DMA_SIZE
, PROT_READ
| PROT_WRITE
,
158 if (dma
[0] == (u_long
*)-1) {
159 myprintf("Error mmap dma[0]: %s\n", strerror(errno
));
163 dma
[1] = (u_long
*)mmap(0, MSPS_DMA_SIZE
, PROT_READ
| PROT_WRITE
,
166 if (dma
[1] == (u_long
*)-1) {
167 myprintf("Error mmap dma[1]: %s\n", strerror(errno
));
170 myprintf("mmap - ok\n");
172 for (i
= 0; i
< (data_size
/sizeof(u_long
)); i
++) {
173 (*(dma
[0] + i
)) = 0x0;
174 (*(dma
[1] + i
)) = 0x0;
183 printf("Device test mode - are on\n");
184 ioctl(fd
, MSPS_TEST_MODE_ON
, NULL
);
187 res
= ioctl(fd
, MSPS_GET_STATUS
, &status
);
189 myprintf("ioctl get status error\n");
193 task
->size
= data_size
;
194 activetask
.time
= active_work
* 1000; /* mili or micro seconds!? 0_o */
199 for (i
= 0; i
< (data_size
/sizeof(u_long
)); i
++) {
200 (*(dma
[0] + i
)) = mask
;
201 (*(dma
[1] + i
)) = mask
;
204 printf("%s with msps %s (%s):\n",
205 write_flag
? "Write" : "Read",
207 active_work
? "active" : "interrupt");
210 res
= ioctl(fd
, MSPS_EXCH_DATA_ACTIVE
, &activetask
);
212 res
= ioctl(fd
, MSPS_EXCH_DATA
, task
);
215 myprintf("ioctl exch_data error\n");
217 myprintf("%d -> state: 0x%x, size: %d, buf: %d\n",
229 typedef struct msps_status {
230 msps_exch_stat_t input;
231 msps_exch_stat_t output;
234 typedef struct msps_exch_stat {
235 u_int state; // if == 0 - then finished
236 u_int size; // size of last exchange
237 u_int buffer; // which buffer used for last exchange
242 myprintf("status:\n\tstate\t0x%x\n\tsize\t0x%x\n\tbuffer\t0x%x\n\n",
248 printf("Device test mode - are off\n");
249 ioctl(fd
, MSPS_TEST_MODE_OFF
, NULL
);
252 munmap(dma
[0], MSPS_DMA_SIZE
);
253 munmap(dma
[1], MSPS_DMA_SIZE
);