Rev 1086 | Rev 1550 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /***************************************************************************** |
2 | * Filename: test_ec.c * |
||
3 | * Author: Marco Ziglioli (Doctor Stein) * |
||
4 | * Date: 20/06/2001 * |
||
5 | * Description: Test program for gated event counting using PCI6025E board * |
||
6 | *----------------------------------------------------------------------------* |
||
7 | * Notes: FOUT are enabled to provide a frequency of 6250 Hz. You could * |
||
8 | * connect PFI3 (pin 41) and PFI6 (pin 45) to this source for counting * |
||
9 | * edges. Gated counting are enabled and PFI4 (pin 42) is gate pin for * |
||
10 | * counter 0 and PFI5 (pin 44) is gate pin for counter 0. DIO 7 and 6 * |
||
11 | * are als configured to switch between 0 and 5 V. Connect DIO 7 to * |
||
12 | * gate 0 and DIO 6 to gate 1. Use 'g' (counter 0) and 'h' (counter 1) * |
||
13 | * to change DIO lines value. On left area of the screen you should * |
||
14 | * see counter while counting and on the right area you should lock * |
||
15 | * counter values by pressing 's' key. * |
||
16 | * Notice that line parameters are enabled and accept inital value * |
||
17 | * for the two counters. If they aren't specified or they are wrong * |
||
18 | * counters start from 0x00FFFFFF (counter 0 which counts down) and * |
||
19 | * 0x00000000 (counter 1 which counts up). * |
||
20 | * Last time addiction: TC Interrupts and Gate interrupts are enabled * |
||
21 | * Bottom squares indicates when an interrupt is * |
||
22 | * raised * |
||
23 | *****************************************************************************/ |
||
24 | |||
25 | /* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it |
||
26 | * |
||
27 | * Copyright (C) 2001 Marco Ziglioli |
||
28 | * |
||
29 | * This program is free software; you can redistribute it and/or modify |
||
30 | * it under the terms of the GNU General Public License as published by |
||
31 | * the Free Software Foundation; either version 2 of the License, or |
||
32 | * (at your option) any later version. |
||
33 | * |
||
34 | * This program is distributed in the hope that it will be useful, |
||
35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
37 | * GNU General Public License for more details. |
||
38 | * |
||
39 | * You should have received a copy of the GNU General Public License |
||
40 | * along with this program; if not, write to the Free Software |
||
41 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
42 | * |
||
43 | */ |
||
44 | |||
45 | #include <kernel/kern.h> |
||
46 | #include <drivers/keyb.h> |
||
47 | #include <drivers/glib.h> |
||
48 | |||
49 | #include <drivers/pci6025e/timer.h> |
||
50 | #include <drivers/pci6025e/dio_ppi.h> |
||
51 | |||
52 | #ifndef INT_NO |
||
53 | #define INT_NO NIDevice_info[0].InterruptLevel |
||
54 | #endif |
||
55 | |||
56 | BYTE sys = 0; |
||
57 | |||
58 | PID show_aper_pid; |
||
59 | BYTE out = 0x00; |
||
60 | |||
61 | int black = rgb16(0, 0, 0), |
||
62 | white = rgb16(255, 255, 255); |
||
63 | |||
64 | void endfun(KEY_EVT *); |
||
65 | void close_event(void *); |
||
66 | void show_evt(KEY_EVT *k); |
||
67 | void gate_change(KEY_EVT *k); |
||
68 | |||
69 | void drawInterface(void); |
||
70 | |||
71 | void int_evt(int intno); |
||
72 | |||
73 | TASK show_per(int); |
||
74 | TASK show_aper(int); |
||
75 | |||
76 | int main(int argc, char **argv) |
||
77 | { |
||
78 | KEY_EVT k; |
||
79 | SOFT_TASK_MODEL show_per_mod, show_aper_mod; |
||
80 | PID show_per_pid; |
||
81 | int result, modenum; |
||
82 | DWORD init_val_c0, init_val_c1; |
||
83 | |||
84 | if(argc >= 3){ |
||
85 | if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1) |
||
86 | init_val_c0 = 0x00FFFFFF; |
||
87 | if( (result = sscanf(argv[2], "%ld", &init_val_c1)) != 1) |
||
88 | init_val_c1 = 0x00000000; |
||
89 | } |
||
90 | if(argc == 2){ |
||
91 | if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1) |
||
92 | init_val_c0 = 0x00FFFFFF; |
||
93 | init_val_c1 = 0x00000000; |
||
94 | } |
||
95 | if(argc == 1){ |
||
96 | init_val_c0 = 0x00FFFFFF; |
||
97 | init_val_c1 = 0x00000000; |
||
98 | } |
||
99 | |||
100 | sys_atrunlevel(close_event, NULL, RUNLEVEL_BEFORE_EXIT); |
||
101 | |||
102 | k.flag = CNTL_BIT; |
||
103 | k.scan = KEY_X; |
||
104 | k.ascii = 'x'; |
||
105 | keyb_hook(k, endfun); |
||
106 | |||
107 | k.flag = CNTR_BIT; |
||
108 | keyb_hook(k, endfun); |
||
109 | |||
110 | soft_task_default_model(show_aper_mod); |
||
111 | soft_task_def_aperiodic(show_aper_mod); |
||
112 | soft_task_def_level(show_aper_mod, 1); |
||
113 | soft_task_def_period(show_aper_mod, 250000); |
||
114 | soft_task_def_met(show_aper_mod, 30000); |
||
115 | soft_task_def_wcet(show_aper_mod, 60000); |
||
116 | if( (show_aper_pid = task_create("Show aperiodic task", show_aper, &show_aper_mod, NULL)) == NIL ){ |
||
117 | sys = 10; |
||
118 | sys_end(); |
||
119 | } |
||
120 | |||
121 | k.flag = 0; |
||
122 | k.scan = KEY_S; |
||
123 | k.ascii = 's'; |
||
124 | keyb_hook(k, show_evt); |
||
125 | |||
126 | k.flag = 0; |
||
127 | k.scan = KEY_G; |
||
128 | k.ascii = 'g'; |
||
129 | keyb_hook(k, gate_change); |
||
130 | |||
131 | k.scan = KEY_H; |
||
132 | k.ascii = 'h'; |
||
133 | keyb_hook(k, gate_change); |
||
134 | |||
135 | soft_task_default_model(show_per_mod); |
||
136 | soft_task_def_level(show_per_mod, 1); |
||
137 | soft_task_def_met(show_per_mod, 1000); |
||
138 | soft_task_def_period(show_per_mod, 10000); |
||
139 | if( (show_per_pid = task_create("Show periodic task", show_per, &show_per_mod, NULL)) == NIL){ |
||
140 | sys = 11; |
||
141 | sys_end(); |
||
142 | } |
||
143 | |||
144 | if(pci_init()==-1){ |
||
145 | sys = 20; |
||
146 | sys_end(); |
||
147 | } |
||
148 | |||
149 | if(!reMap()){ |
||
150 | sys = 21; |
||
151 | sys_end(); |
||
152 | } |
||
153 | |||
154 | if(grx_init()==-1){ |
||
155 | sys = 30; |
||
156 | sys_end(); |
||
157 | } |
||
158 | |||
159 | if( (modenum = grx_getmode(800, 600, 16)) == -1){ |
||
160 | sys = 31; |
||
161 | sys_end(); |
||
162 | } |
||
163 | |||
164 | grx_setmode(modenum); |
||
165 | |||
166 | drawInterface(); |
||
167 | |||
168 | //Init DIO lines used to manage counters gates |
||
169 | DIO_init(); |
||
170 | DIO_setup(0xFF); |
||
171 | DIO_write(out); |
||
172 | |||
173 | //All PFI are configured as input |
||
174 | PFIprogramming(0x0000); |
||
175 | //FOUT enable; Slow TIMEBASE, divided by two; divided by 16 on FOUT pin |
||
176 | setIntClock(1, 1, 0); |
||
177 | |||
178 | TIM_reset(2); //Reset both two counters |
||
179 | |||
180 | //Source PFI3(41); Gate PFI 4(42); Down counting; counts rising edge; |
||
181 | TIM_eventCounting(C0, 0x04, 0x45, 0x03, init_val_c0); |
||
182 | |||
183 | //Source PFI6(45); Gate PFI 5(44); Up counting; counts rising edge; |
||
184 | TIM_eventCounting(C1, 0x87, 0x46, 0x03, init_val_c1); |
||
185 | |||
186 | //Set up interrupt group A and B enabling and programming to assert a request |
||
187 | //both on line 2 and 3 respectively |
||
188 | INT_setup(0x0A, 0x0B); |
||
189 | INT_personalize(0x03); //Interrupt request polarity low; IRQ driven on line 0 and 1 |
||
190 | |||
1340 | giacomo | 191 | handler_set(INT_NO, int_evt, show_aper_pid, FALSE); |
1085 | pj | 192 | |
193 | TIM_arm(2); //Arm both two counters |
||
194 | |||
195 | task_activate(show_per_pid); |
||
196 | |||
197 | return 0; |
||
198 | } |
||
199 | |||
200 | void drawInterface(void) |
||
201 | { |
||
202 | grx_rect(1, 1, 799, 99, rgb16(105, 0, 0)); |
||
203 | grx_rect(2, 2, 798, 98, rgb16(155, 0, 0)); |
||
204 | grx_rect(3, 3, 797, 97, rgb16(205, 0, 0)); |
||
205 | grx_rect(4, 4, 796, 96, rgb16(255, 0, 0)); |
||
206 | |||
207 | grx_text("Test program for Gated Event Counting capacity of PCI6025E timers", |
||
208 | 7, 10, rgb16(50, 255, 50), black); |
||
209 | |||
210 | grx_text("This program counting rise edges on counters source (PFI3 & PFI6) when releted gates", |
||
211 | 7, 25, rgb16(0, 255, 255), black); |
||
212 | grx_text("(PFI 42 & 44) are enabled. Frequency Out (FOUT) is enabled and provides a frequency of 6250 Hz", |
||
213 | 7, 33, rgb16(0, 255, 255), black); |
||
214 | |||
215 | grx_text("Instruction:",7, 43, rgb16(255, 0, 0), black); |
||
216 | grx_text("Use 's' to lock counters value in right squares", |
||
217 | 7, 51, rgb16(0, 255, 255), black); |
||
218 | grx_text("Use 'g' to block or to release alternativly counter 0 (see top-left square)", |
||
219 | 7, 58, rgb16(0, 255, 255), black); |
||
220 | |||
221 | grx_text("Use 'h' to block or to release alternativly counter 1 (see bottom-left square)", |
||
222 | 7, 65, rgb16(0, 255, 255), black); |
||
223 | |||
224 | grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)", |
||
225 | 7, 78, rgb16(0, 255, 0), black); |
||
226 | grx_text("CTRL-X for Exit", 7, 88, rgb16(200, 200, 0), black); |
||
227 | |||
228 | grx_rect(1, 110, 355, 170, rgb16(0, 105, 0)); |
||
229 | grx_rect(2, 111, 354, 169, rgb16(0, 155, 0)); |
||
230 | grx_rect(3, 112, 353, 168, rgb16(0, 205, 0)); |
||
231 | grx_rect(4, 113, 352, 167, rgb16(0, 255, 0)); |
||
232 | grx_text("Counter 0 evolution", 7, 120, rgb16(255, 255, 0), black); |
||
233 | |||
234 | grx_rect(455, 110, 799, 170, rgb16(0, 105, 0)); |
||
235 | grx_rect(456, 111, 798, 169, rgb16(0, 155, 0)); |
||
236 | grx_rect(457, 112, 797, 168, rgb16(0, 205, 0)); |
||
237 | grx_rect(458, 113, 796, 167, rgb16(0, 255, 0)); |
||
238 | grx_text("Counter 0 locked value", 461, 120, rgb16(255, 0, 255), black); |
||
239 | |||
240 | grx_rect(360, 110, 450, 170, rgb16(0, 105, 0)); |
||
241 | grx_rect(361, 111, 449, 169, rgb16(0, 155, 0)); |
||
242 | grx_rect(362, 112, 448, 168, rgb16(0, 205, 0)); |
||
243 | grx_rect(363, 113, 447, 167, rgb16(0, 255, 0)); |
||
244 | grx_text("Gate0", 367, 120, rgb16(200, 255, 200), black); |
||
245 | grx_text("0 V", 367, 145, rgb16(255, 0, 0), black); |
||
246 | |||
247 | grx_rect(1, 190, 355, 260, rgb16(85, 85, 255)); |
||
248 | grx_rect(2, 191, 354, 259, rgb16(135, 135, 255)); |
||
249 | grx_rect(3, 192, 353, 258, rgb16(190, 190, 255)); |
||
250 | grx_rect(4, 193, 352, 257, rgb16(230, 239, 255)); |
||
251 | grx_text("Counter 1 evolution", 7, 200, white, black); |
||
252 | |||
253 | grx_rect(455, 190, 799, 260, rgb16(85, 85, 255)); |
||
254 | grx_rect(456, 191, 798, 259, rgb16(135, 135, 255)); |
||
255 | grx_rect(457, 192, 797, 258, rgb16(190, 190, 255)); |
||
256 | grx_rect(458, 193, 796, 257, rgb16(230, 230, 255)); |
||
257 | grx_text("Counter 1 locked value", 461, 200, white, black); |
||
258 | |||
259 | grx_rect(360, 190, 450, 260, rgb16(85, 85, 255)); |
||
260 | grx_rect(361, 191, 449, 259, rgb16(135, 135, 255)); |
||
261 | grx_rect(362, 192, 448, 258, rgb16(190, 190, 255)); |
||
262 | grx_rect(363, 193, 447, 257, rgb16(230, 230, 255)); |
||
263 | grx_text("Gate1", 367, 200, rgb16(255, 200, 255), black); |
||
264 | grx_text("0 V", 367, 225, rgb16(255, 0, 0), black); |
||
265 | |||
266 | grx_text("Counter 0 Interrupt events", 7, 340, rgb16(255, 200, 100), black); |
||
267 | grx_text("Counter 1 Interrupt events", 461, 340, rgb16(255, 200, 100), black); |
||
268 | grx_rect(1, 350, 355, 400, rgb16(105, 0, 0)); |
||
269 | grx_rect(2, 351, 354, 399, rgb16(155, 0, 0)); |
||
270 | grx_rect(3, 352, 353, 398, rgb16(205, 0, 0)); |
||
271 | grx_rect(4, 353, 352, 397, rgb16(255, 0, 0)); |
||
272 | grx_rect(455, 350, 799, 400, rgb16(105, 0, 0)); |
||
273 | grx_rect(456, 351, 798, 399, rgb16(155, 0, 0)); |
||
274 | grx_rect(457, 352, 797, 398, rgb16(205, 0, 0)); |
||
275 | grx_rect(458, 353, 796, 397, rgb16(255, 0, 0)); |
||
276 | } |
||
277 | |||
278 | |||
279 | TASK show_per(int none) |
||
280 | { |
||
281 | DWORD val; |
||
282 | char buf[30]; |
||
283 | |||
284 | while(1){ |
||
285 | val = TIM_readCounter(C0); //Read counter 0 value |
||
286 | sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val); |
||
287 | grx_text(buf, 7, 145, rgb16(255, 0, 0), black); |
||
288 | |||
289 | val = TIM_readCounter(C1); //Read counter 1 value |
||
290 | sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val); |
||
291 | grx_text(buf, 7, 225, rgb16(255, 0, 0), black); |
||
292 | |||
293 | task_endcycle(); |
||
294 | } |
||
295 | } |
||
296 | |||
297 | TASK show_aper(int dummy) |
||
298 | { |
||
299 | DWORD val; |
||
300 | char buf[30]; |
||
301 | |||
302 | while(1){ |
||
303 | val = TIM_readCounter(C0); |
||
304 | sprintf(buf, "HEX: %08lx DEC: %08ld", val, val); |
||
305 | grx_text(buf, 461, 145, rgb16(80, 80, 255), black); |
||
306 | |||
307 | val = TIM_readCounter(C1); |
||
308 | sprintf(buf, "HEX: %08lx DEC: %08ld", val, val); |
||
309 | grx_text(buf, 461, 225, rgb16(80, 80, 255), black); |
||
310 | |||
311 | task_endcycle(); |
||
312 | } |
||
313 | } |
||
314 | |||
315 | void endfun(KEY_EVT *k) |
||
316 | { |
||
317 | sys_end(); |
||
318 | } |
||
319 | |||
320 | void show_evt(KEY_EVT *k) |
||
321 | { |
||
322 | task_activate(show_aper_pid); |
||
323 | } |
||
324 | |||
325 | void gate_change(KEY_EVT *k) |
||
326 | { |
||
327 | if(k->ascii == 'g'){ |
||
328 | if( (out & 0x80) != 0){ |
||
329 | out &= 0x7F; |
||
330 | grx_text("0 V", 367, 145, rgb16(255, 0, 0), black); |
||
331 | } else { |
||
332 | out |= 0x80; |
||
333 | grx_text("5 V", 367, 145, rgb16(0, 255, 0), black); |
||
334 | } |
||
335 | } else { |
||
336 | if( (out & 0x40) != 0){ |
||
337 | out &= 0xBF; |
||
338 | grx_text("0 V", 367, 225, rgb16(255, 0, 0), black); |
||
339 | } else { |
||
340 | out |= 0x40; |
||
341 | grx_text("5 V", 367, 225, rgb16(0, 255, 0), black); |
||
342 | } |
||
343 | } |
||
344 | |||
345 | DIO_write(out); |
||
346 | } |
||
347 | |||
348 | void close_event(void *arg) |
||
349 | { |
||
350 | TIM_disarm(2); //Disable both two counters |
||
351 | grx_close(); |
||
352 | handler_remove(INT_NO); |
||
353 | |||
354 | |||
355 | switch(sys){ |
||
356 | case 0: cprintf("OK\n"); break; |
||
357 | case 10: cprintf("Task <show aperiodic> down\n"); break; |
||
358 | case 11: cprintf("Task <show periodic> down\n"); break; |
||
359 | case 20: cprintf("No PCI bus\n"); break; |
||
360 | case 21: cprintf("No National board on PCI bus\n"); break; |
||
361 | case 30: cprintf("No graphic can be initialized\n"); break; |
||
362 | case 31: cprintf("This graphic mode cannot be supported\n"); break; |
||
363 | default: cprintf("???????????\n"); break; |
||
364 | } |
||
365 | } |
||
366 | |||
367 | void int_evt(int intno) |
||
368 | { |
||
369 | WORD status; |
||
370 | |||
371 | status = DAQ_STC_Windowed_Mode_Read(AI_STATUS_1); |
||
372 | if( (status & 0x8000) != 0){ |
||
373 | if( (status & 0x0008) != 0){ |
||
374 | grx_text("INT Group A raised! G0 Rolls over", 7, 360, rgb16(0, 255, 0), black); |
||
375 | set(interrupt_a_ack, 14); |
||
376 | DAQ_STC_Windowed_Mode_Write(INTERRUPT_A_ACK, interrupt_a_ack); |
||
377 | clr(interrupt_a_ack, 14); |
||
378 | } |
||
379 | if( (status & 0x0004) != 0){ |
||
380 | grx_text("INT Group A raised! G0 gate pressed", 7, 380, rgb16(0, 255, 0), black); |
||
381 | set(interrupt_a_ack, 15); |
||
382 | DAQ_STC_Windowed_Mode_Write(INTERRUPT_A_ACK, interrupt_a_ack); |
||
383 | clr(interrupt_a_ack, 15); |
||
384 | } |
||
385 | return; |
||
386 | } |
||
387 | |||
388 | status = DAQ_STC_Windowed_Mode_Read(AO_STATUS_1); |
||
389 | if( (status & 0x8000) != 0){ |
||
390 | if( (status & 0x0008) != 0){ |
||
391 | grx_text("INT Group B raised! G1 Rolls over", 461, 360, rgb16(0, 255, 0), black); |
||
392 | set(interrupt_b_ack, 14); |
||
393 | DAQ_STC_Windowed_Mode_Write(INTERRUPT_B_ACK, interrupt_b_ack); |
||
394 | clr(interrupt_b_ack, 14); |
||
395 | } |
||
396 | if( (status & 0x0004) != 0){ |
||
397 | grx_text("INT Group B raised! G1 gate pressed", 461, 380, rgb16(0, 255, 0), black); |
||
398 | set(interrupt_b_ack, 15); |
||
399 | DAQ_STC_Windowed_Mode_Write(INTERRUPT_B_ACK, interrupt_b_ack); |
||
400 | clr(interrupt_b_ack, 15); |
||
401 | } |
||
402 | return; |
||
403 | } |
||
404 | } |
||
405 | /* End of file: Test_ec.c */ |