|
1 /* |
|
2 * Source File : me8100_test_counter.c |
|
3 * Destination : me8100_test_counter |
|
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 use of the driver and the counter part |
|
15 * of the me8100 board. It configures the counters in mode 3 (symetric |
|
16 * devisor) with a counter value of 4. So each frequency of a signal |
|
17 * put in at CLK is devided by 4. |
|
18 */ |
|
19 #include <stdio.h> |
|
20 #include <fcntl.h> |
|
21 #include <unistd.h> |
|
22 #include <sys/ioctl.h> |
|
23 #include <signal.h> |
|
24 #include <linux/spinlock.h> |
|
25 |
|
26 #include "../me8100.h" |
|
27 |
|
28 |
|
29 int main(void){ |
|
30 int err = 0; |
|
31 int minor = 0; |
|
32 int count = 0; |
|
33 static int file_handle = -1; |
|
34 |
|
35 unsigned char cctrl_0; |
|
36 unsigned char cctrl_1; |
|
37 unsigned char cctrl_2; |
|
38 unsigned char clvalue_0; |
|
39 unsigned char chvalue_0; |
|
40 unsigned char clvalue_1; |
|
41 unsigned char chvalue_1; |
|
42 unsigned char clvalue_2; |
|
43 unsigned char chvalue_2; |
|
44 |
|
45 printf("%c%3s", 27, "[2J"); |
|
46 printf("<<<--- ME8100 TESTPROGRAM FOR COUNTER --->>>\n\n"); |
|
47 |
|
48 /* |
|
49 * You can select up to four me8100 baords, if installed. |
|
50 * 0 is the first board. |
|
51 */ |
|
52 printf("Please type in the Minor Device Number of Board to open : "); |
|
53 count = scanf("%d", &minor); |
|
54 if(!count){ |
|
55 printf("Invalid Input !\n"); |
|
56 return 1; |
|
57 } |
|
58 printf("Open path /dev/me8100_%d !\n\n", minor); |
|
59 |
|
60 switch(minor){ |
|
61 case 0: |
|
62 file_handle = open("/dev/me8100_0", O_RDWR, 0); |
|
63 break; |
|
64 case 1: |
|
65 file_handle = open("/dev/me8100_1", O_RDWR, 0); |
|
66 break; |
|
67 case 2: |
|
68 file_handle = open("/dev/me8100_2", O_RDWR, 0); |
|
69 break; |
|
70 case 3: |
|
71 file_handle = open("/dev/me8100_3", O_RDWR, 0); |
|
72 break; |
|
73 default: |
|
74 printf("Invalid Input !\n"); |
|
75 return 1; |
|
76 } |
|
77 |
|
78 if(file_handle < 0){ |
|
79 printf("Cannot open path !\n"); |
|
80 return 1; |
|
81 } |
|
82 |
|
83 /* |
|
84 * Counter |
|
85 * |
|
86 * Now that you have access to the me8100 you have to configurate |
|
87 * the board according to your needs. |
|
88 * The ME8100 has got 3 counters with 16 bit each. First you have |
|
89 * to configure the counters control register according to your needs. |
|
90 * Then you can write the proper value to the counter. |
|
91 */ |
|
92 |
|
93 |
|
94 /*--------------- ALL COUNTER IN MODE 3 AND BINARY ------------------------*/ |
|
95 |
|
96 printf("Please press return to test counter in mode 3/binary :\n"); |
|
97 getchar(); |
|
98 getchar(); |
|
99 |
|
100 /* |
|
101 * Configure COUNTER_0 as asynchronous devisor, |
|
102 * as binary counter and LSB/MSB. |
|
103 */ |
|
104 cctrl_0 = 0x36; |
|
105 err = ioctl(file_handle , ME8100_SETUP_COUNTER, &cctrl_0); |
|
106 if(err){ |
|
107 printf("Cannot setup counter 0\n"); |
|
108 return 1; |
|
109 } |
|
110 |
|
111 /* |
|
112 * Configure COUNTER_1 as asynchronous devisor, |
|
113 * as binary counter and LSB/MSB. |
|
114 */ |
|
115 cctrl_1 = 0x76; |
|
116 err = ioctl(file_handle , ME8100_SETUP_COUNTER, &cctrl_1); |
|
117 if(err){ |
|
118 printf("Cannot setup counter 1\n"); |
|
119 return 1; |
|
120 } |
|
121 |
|
122 /* |
|
123 * Configure COUNTER_2 as asynchronous devisor, |
|
124 * as binary counter and LSB/MSB. |
|
125 */ |
|
126 cctrl_2 = 0xB6; |
|
127 err = ioctl(file_handle , ME8100_SETUP_COUNTER, &cctrl_2); |
|
128 if(err){ |
|
129 printf("Cannot setup counter 2\n"); |
|
130 return 1; |
|
131 } |
|
132 |
|
133 |
|
134 /*---------------------------- LOAD COUNTER -------------------------------*/ |
|
135 |
|
136 /* Counter 0 */ |
|
137 clvalue_0 = 0x4; |
|
138 chvalue_0 = 0x0; |
|
139 /* Write lower byte */ |
|
140 err = ioctl(file_handle , ME8100_WRITE_COUNTER_0, &clvalue_0); |
|
141 if(err){ |
|
142 printf("Cannot write to counter 0\n"); |
|
143 return 1; |
|
144 } |
|
145 /* Write higher byte */ |
|
146 err = ioctl(file_handle , ME8100_WRITE_COUNTER_0, &chvalue_0); |
|
147 if(err){ |
|
148 printf("Cannot write to counter 0\n"); |
|
149 return 1; |
|
150 } |
|
151 |
|
152 /* Counter 1 */ |
|
153 clvalue_1 = 0x4; |
|
154 chvalue_1 = 0x0; |
|
155 /* Write lower byte */ |
|
156 err = ioctl(file_handle , ME8100_WRITE_COUNTER_1, &clvalue_1); |
|
157 if(err){ |
|
158 printf("Cannot write to counter 1\n"); |
|
159 return 1; |
|
160 } |
|
161 /* Write higher byte */ |
|
162 err = ioctl(file_handle , ME8100_WRITE_COUNTER_1, &chvalue_1); |
|
163 if(err){ |
|
164 printf("Cannot write to counter 1\n"); |
|
165 return 1; |
|
166 } |
|
167 |
|
168 /* Counter 2 */ |
|
169 clvalue_2 = 0x4; |
|
170 chvalue_2 = 0x0; |
|
171 /* Write lower byte */ |
|
172 err = ioctl(file_handle , ME8100_WRITE_COUNTER_2, &clvalue_2); |
|
173 if(err){ |
|
174 printf("Cannot write to counter 2\n"); |
|
175 return 1; |
|
176 } |
|
177 /* Write higher byte */ |
|
178 err = ioctl(file_handle , ME8100_WRITE_COUNTER_2, &chvalue_2); |
|
179 if(err){ |
|
180 printf("Cannot write to counter 2\n"); |
|
181 return 1; |
|
182 } |
|
183 |
|
184 |
|
185 |
|
186 /*-------------------------------- END ------------------------------------*/ |
|
187 |
|
188 printf("Please press return to terminate program :\n"); |
|
189 getchar(); |
|
190 |
|
191 printf("Close path to me8100_%d\n", minor); |
|
192 err = close(file_handle); |
|
193 if(err){ |
|
194 printf("Kann Pfad nicht schliessen\n"); |
|
195 return 1; |
|
196 } |
|
197 |
|
198 return 0; |
|
199 } |