|
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 <stdlib.h> |
|
29 #include "me8100.h" |
|
30 |
|
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 oflags = 0; |
|
47 |
|
48 unsigned short mask_a; |
|
49 unsigned short ctrl_a; |
|
50 |
|
51 unsigned char icsr; |
|
52 |
|
53 printf("IRQ Test %d\n", getpid()); |
|
54 |
|
55 file_handle = open("/dev/me8100_0", O_RDWR, 0); |
|
56 |
|
57 if(file_handle < 0){ |
|
58 printf("Cannot open path !\n"); |
|
59 return 1; |
|
60 } |
|
61 |
|
62 /*---------------------- general setup ------------------------------------*/ |
|
63 |
|
64 /* install the signal handler */ |
|
65 signal(SIGIO, signal_handler); |
|
66 |
|
67 /* set current process as owner of the path */ |
|
68 fcntl(file_handle, F_SETOWN, getpid()); |
|
69 |
|
70 /* read the flags of the path */ |
|
71 oflags = fcntl(file_handle, F_GETFL); |
|
72 |
|
73 /* Inform the driver to put the current process on the fasync queue */ |
|
74 fcntl(file_handle, F_SETFL, oflags | FASYNC); |
|
75 |
|
76 /* enable both interrupts on the plx, set interrupts to high active */ |
|
77 icsr = |
|
78 LOCAL_INT1_EN | |
|
79 LOCAL_INT1_POL | |
|
80 PCI_INT_EN; |
|
81 |
|
82 err = ioctl(file_handle, ME8100_SETUP_ICSR, &icsr); |
|
83 if(err){ |
|
84 printf("Cannot setup PLX\n"); |
|
85 return 1; |
|
86 } |
|
87 |
|
88 /*-------------------- Interrupt caused by bit mask -----------------*/ |
|
89 |
|
90 /* Set the proper bit mask for port a */ |
|
91 mask_a = 0xffff; |
|
92 err = ioctl(file_handle, ME8100_WRITE_MASK_A, &mask_a); |
|
93 if(err){ |
|
94 printf("Cannot write mask a\n"); |
|
95 return 1; |
|
96 } |
|
97 |
|
98 /* Enable interrupt signalling by bit mask for port a */ |
|
99 ctrl_a = ME8100_CTL_ENIO | ME8100_CTL_SOURCE | ME8100_CTL_IRQ_MASK; |
|
100 err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a); |
|
101 if(err){ |
|
102 printf("Cannot write ctrl a\n"); |
|
103 return 1; |
|
104 } |
|
105 |
|
106 printf("<<<--- WAITING FOR INTERRUPTS BY BIT MASK --->>>\n\n"); |
|
107 |
|
108 i = 0; |
|
109 while(i < 10) { |
|
110 select(0, NULL, NULL, NULL, NULL); |
|
111 } |
|
112 |
|
113 printf("Close path to me8100_0\n"); |
|
114 err = close(file_handle); |
|
115 if(err){ |
|
116 printf("Kann Pfad nicht schliessen\n"); |
|
117 return 1; |
|
118 } |
|
119 |
|
120 return 1; |
|
121 } |
|
122 |
|
123 |
|
124 |
|
125 void signal_handler(int sig){ |
|
126 int err = 0; |
|
127 i++; |
|
128 err = ioctl(file_handle, ME8100_GET_INT_COUNT, &intcounts); |
|
129 if(err) |
|
130 return; |
|
131 |
|
132 fprintf(stderr, "<<<--- ME8100 SIGNAL HANDLER CALLED --->>>\n" |
|
133 "Execution = %04d\n" |
|
134 "int_count_1 = %04d\n" |
|
135 "int_count_2 = %04d\n\n", i, intcounts.int1, intcounts.int2); |
|
136 return; |
|
137 } |
|
138 |
|
139 /* |
|
140 vim:sts=2 sw=2 aw ai sm: |
|
141 */ |