|
1 /* |
|
2 * Source File : me8100_test_int.c |
|
3 * Destination : me8100_test_int.out |
|
4 * Author : GG (Guenter Gebhardt) |
|
5 * |
|
6 * |
|
7 * File History: Version Date Editor Action |
|
8 *--------------------------------------------------------------------- |
|
9 * 1.00.00 01.07.12 GG first release |
|
10 * |
|
11 *--------------------------------------------------------------------- |
|
12 * |
|
13 * Description: |
|
14 * This program shows the usage of the driver and the interrupt |
|
15 * facility of the me8100. First the board is configured, in order to |
|
16 * generate an interrupt when a bit pattern of 0x0001 on port a and a bit |
|
17 * pattern of 0x0100 an port b is pending. Then the board is configured, |
|
18 * in order to generate an interrupt with a bit mask of 0x0001 on port a |
|
19 * and a bit mask of 0x0100 on port b. |
|
20 * We install a signal handler, which is informed by the interrupt routine |
|
21 * by signalling of the driver, when a interrupt occures. |
|
22 */ |
|
23 #include <stdio.h> |
|
24 #include <fcntl.h> |
|
25 #include <unistd.h> |
|
26 #include <sys/ioctl.h> |
|
27 #include <signal.h> |
|
28 #include <linux/spinlock.h> |
|
29 |
|
30 #include "../me8100.h" |
|
31 |
|
32 /* Prototypes */ |
|
33 static void signal_handler(int); |
|
34 |
|
35 /* Counts the interrupts */ |
|
36 static me8100_int_occur_type intcounts; |
|
37 |
|
38 /* Count of signal handler execution */ |
|
39 static int i = 0; |
|
40 |
|
41 /* Path to the ME8100 board */ |
|
42 static int file_handle = -1; |
|
43 |
|
44 int main(void){ |
|
45 int err = 0; |
|
46 int minor = 0; |
|
47 int oflags = 0; |
|
48 |
|
49 unsigned short pattern_a; |
|
50 unsigned short pattern_b; |
|
51 unsigned short mask_a; |
|
52 unsigned short mask_b; |
|
53 unsigned short ctrl_a; |
|
54 unsigned short ctrl_b; |
|
55 |
|
56 unsigned char icsr; |
|
57 |
|
58 printf("%c%3s", 27, "[2J"); |
|
59 printf("<<<--- ME8100 TESTPROGRAM FOR INT --->>>\n\n"); |
|
60 |
|
61 /* |
|
62 * You can select up to four me8100 baords, if installed. |
|
63 * 0 is the first board. |
|
64 */ |
|
65 printf("Please type in the minor device number of the board to open : "); |
|
66 scanf("%d", &minor); |
|
67 printf("Open path /dev/me8100_%d !\n\n", minor); |
|
68 |
|
69 switch(minor){ |
|
70 case 0: |
|
71 file_handle = open("/dev/me8100_0", O_RDWR, 0); |
|
72 break; |
|
73 case 1: |
|
74 file_handle = open("/dev/me8100_1", O_RDWR, 0); |
|
75 break; |
|
76 case 2: |
|
77 file_handle = open("/dev/me8100_2", O_RDWR, 0); |
|
78 break; |
|
79 case 3: |
|
80 file_handle = open("/dev/me8100_3", O_RDWR, 0); |
|
81 break; |
|
82 default: |
|
83 printf("Invalid input !\n"); |
|
84 return 1; |
|
85 } |
|
86 |
|
87 if(file_handle < 0){ |
|
88 printf("Cannot open path !\n"); |
|
89 return 1; |
|
90 } |
|
91 |
|
92 /*---------------------- general setup ------------------------------------*/ |
|
93 |
|
94 /* install the signal handler */ |
|
95 signal(SIGIO, signal_handler); |
|
96 |
|
97 /* set current process as owner of the path */ |
|
98 fcntl(file_handle, F_SETOWN, getpid()); |
|
99 |
|
100 /* read the flags of the path */ |
|
101 oflags = fcntl(file_handle, F_GETFL); |
|
102 |
|
103 /* Inform the driver to put the current process on the fasync queue */ |
|
104 fcntl(file_handle, F_SETFL, oflags | FASYNC); |
|
105 |
|
106 /* enable both interrupts on the plx, set interrupts to high active */ |
|
107 icsr = |
|
108 LOCAL_INT1_EN | |
|
109 LOCAL_INT1_POL | |
|
110 LOCAL_INT2_EN | |
|
111 LOCAL_INT2_POL | |
|
112 PCI_INT_EN; |
|
113 |
|
114 err = ioctl(file_handle, ME8100_SETUP_ICSR, &icsr); |
|
115 if(err){ |
|
116 printf("Cannot setup PLX\n"); |
|
117 return 1; |
|
118 } |
|
119 |
|
120 |
|
121 |
|
122 /*-------------------- Interrupt caused by bit pattern -----------------*/ |
|
123 |
|
124 /* Set the proper bit pattern for port a */ |
|
125 pattern_a = 0x1; |
|
126 err = ioctl(file_handle, ME8100_WRITE_PATTERN_A, &pattern_a); |
|
127 if(err){ |
|
128 printf("Cannot write pattern a\n"); |
|
129 return 1; |
|
130 } |
|
131 |
|
132 /* Set the proper bit pattern for port b */ |
|
133 pattern_b = 0x100; |
|
134 err = ioctl(file_handle, ME8100_WRITE_PATTERN_B, &pattern_b); |
|
135 if(err){ |
|
136 printf("Cannot write pattern b\n"); |
|
137 return 1; |
|
138 } |
|
139 |
|
140 /* Enable interrupt signalling by bit pattern for port a */ |
|
141 ctrl_a = 0x40; |
|
142 err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a); |
|
143 if(err){ |
|
144 printf("Cannot write ctrl a\n"); |
|
145 return 1; |
|
146 } |
|
147 |
|
148 /* Enable interrupt signalling by bit pattern for port b */ |
|
149 ctrl_b = 0x40; |
|
150 err = ioctl(file_handle, ME8100_WRITE_CTRL_B, &ctrl_b); |
|
151 if(err){ |
|
152 printf("Cannot write ctrl b\n"); |
|
153 return 1; |
|
154 } |
|
155 |
|
156 printf("<<<--- WAITING FOR INTERRUPTS BY BIT PATTERN --->>>\n\n"); |
|
157 |
|
158 i = 0; |
|
159 /* execute until 0x8 interrupt will be occured */ |
|
160 while(i < 0x4){ |
|
161 } |
|
162 |
|
163 |
|
164 /*-------------------- Interrupt caused by bit mask -----------------*/ |
|
165 |
|
166 /* Set the proper bit mask for port a */ |
|
167 mask_a = 0x1; |
|
168 err = ioctl(file_handle, ME8100_WRITE_MASK_A, &mask_a); |
|
169 if(err){ |
|
170 printf("Cannot write mask a\n"); |
|
171 return 1; |
|
172 } |
|
173 |
|
174 /* Set the proper bit mask for port b */ |
|
175 mask_b = 0x100; |
|
176 err = ioctl(file_handle, ME8100_WRITE_MASK_B, &mask_b); |
|
177 if(err){ |
|
178 printf("Cannot write mask b\n"); |
|
179 return 1; |
|
180 } |
|
181 |
|
182 /* Enable interrupt signalling by bit mask for port a */ |
|
183 ctrl_a = 0x60; |
|
184 err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a); |
|
185 if(err){ |
|
186 printf("Cannot write ctrl a\n"); |
|
187 return 1; |
|
188 } |
|
189 |
|
190 /* Enable interrupt signalling by bit mask for port b */ |
|
191 ctrl_b = 0x60; |
|
192 err = ioctl(file_handle, ME8100_WRITE_CTRL_B, &ctrl_b); |
|
193 if(err){ |
|
194 printf("Cannot write ctrl b\n"); |
|
195 return 1; |
|
196 } |
|
197 |
|
198 printf("<<<--- WAITING FOR INTERRUPTS BY BIT MASK --->>>\n\n"); |
|
199 |
|
200 i = 0; |
|
201 /* execute until 0x8 interrupt will be occured */ |
|
202 while(i < 0x4){ |
|
203 } |
|
204 |
|
205 |
|
206 /*-------------------------------- END ------------------------------------*/ |
|
207 |
|
208 printf("Close path to me8100_%d\n", minor); |
|
209 err = close(file_handle); |
|
210 if(err){ |
|
211 printf("Kann Pfad nicht schliessen\n"); |
|
212 return 1; |
|
213 } |
|
214 |
|
215 return 1; |
|
216 } |
|
217 |
|
218 |
|
219 |
|
220 void signal_handler(int sig){ |
|
221 int err = 0; |
|
222 i++; |
|
223 err = ioctl(file_handle, ME8100_GET_INT_COUNT, &intcounts); |
|
224 if(err) |
|
225 return; |
|
226 |
|
227 printf("<<<--- ME8100 SIGNAL HANDLER CALLED --->>>\n" |
|
228 "Execution = %04d\n" |
|
229 "int_count_1 = %04d\n" |
|
230 "int_count_2 = %04d\n\n", i, intcounts.int1, intcounts.int2); |
|
231 return; |
|
232 } |