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_bec.c * |
||
3 | * Author: Marco Ziglioli (Doctor Stein) * |
||
4 | * Date: 20/06/2001 * |
||
5 | * Description: Test program for buffered gated event counting using PCI6025E * |
||
6 | * board * |
||
7 | *----------------------------------------------------------------------------* |
||
8 | * Notes: FOUT are enabled to provide a frequency of 6250 Hz. You could * |
||
9 | * connect PFI3 (pin 41) and PFI6 (pin 45) to this source for counting * |
||
10 | * edges. Gated counting are enabled and PFI4 (pin 42) is gate pin for * |
||
11 | * counter 0 and PFI5 (pin 44) is gate pin for counter 0. DIO 7 and 6 * |
||
12 | * are als configured to switch between 0 and 5 V. Connect DIO 7 to * |
||
13 | * gate 0 and DIO 6 to gate 1. Use 'g' (counter 0) and 'h' (counter 1) * |
||
14 | * to change DIO lines value. On left area of the screen you should * |
||
15 | * see counter while counting and on the right area you should lock * |
||
16 | * counter values by pressing 's' key. * |
||
17 | * Notice that line parameters are enabled and accept inital value * |
||
18 | * for the two counters. If they aren't specified or they are wrong * |
||
19 | * counters start from 0x00FFFFFF (counter 0 which counts down) and * |
||
20 | * 0x00000000 (counter 1 which counts up). * |
||
21 | *****************************************************************************/ |
||
22 | |||
23 | /* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it |
||
24 | * |
||
25 | * Copyright (C) 2001 Marco Ziglioli |
||
26 | * |
||
27 | * This program is free software; you can redistribute it and/or modify |
||
28 | * it under the terms of the GNU General Public License as published by |
||
29 | * the Free Software Foundation; either version 2 of the License, or |
||
30 | * (at your option) any later version. |
||
31 | * |
||
32 | * This program is distributed in the hope that it will be useful, |
||
33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
35 | * GNU General Public License for more details. |
||
36 | * |
||
37 | * You should have received a copy of the GNU General Public License |
||
38 | * along with this program; if not, write to the Free Software |
||
39 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
40 | * |
||
41 | */ |
||
42 | |||
43 | #include <kernel/kern.h> |
||
44 | |||
1436 | giacomo | 45 | #include <drivers/shark_keyb26.h> |
46 | #include <drivers/shark_fb26.h> |
||
47 | |||
1085 | pj | 48 | #include <drivers/pci6025e/timer.h> |
49 | #include <drivers/pci6025e/dio_ppi.h> |
||
50 | |||
51 | BYTE sys = 0; |
||
52 | |||
53 | PID show_aper_pid; |
||
54 | BYTE out = 0x00; |
||
55 | |||
56 | int black = rgb16(0, 0, 0), |
||
57 | white = rgb16(255, 255, 255); |
||
58 | |||
59 | void endfun(KEY_EVT *); |
||
60 | void close_event(void *); |
||
61 | void show_evt(KEY_EVT *k); |
||
62 | void gate_change(KEY_EVT *k); |
||
63 | |||
64 | void drawInterface(void); |
||
65 | |||
66 | TASK show_per(int); |
||
67 | TASK show_aper(int); |
||
68 | |||
69 | int main(int argc, char **argv) |
||
70 | { |
||
71 | KEY_EVT k; |
||
72 | SOFT_TASK_MODEL show_per_mod, show_aper_mod; |
||
73 | PID show_per_pid; |
||
1436 | giacomo | 74 | int result; |
1085 | pj | 75 | DWORD init_val_c0, init_val_c1; |
76 | |||
77 | if(argc >= 3){ |
||
78 | if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1) |
||
79 | init_val_c0 = 0x00FFFFFF; |
||
80 | if( (result = sscanf(argv[2], "%ld", &init_val_c1)) != 1) |
||
81 | init_val_c1 = 0x00000000; |
||
82 | } |
||
83 | if(argc == 2){ |
||
84 | if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1) |
||
85 | init_val_c0 = 0x00FFFFFF; |
||
86 | init_val_c1 = 0x00000000; |
||
87 | } |
||
88 | if(argc == 1){ |
||
89 | init_val_c0 = 0x00FFFFFF; |
||
90 | init_val_c1 = 0x00000000; |
||
91 | } |
||
92 | |||
93 | k.flag = CNTL_BIT; |
||
94 | k.scan = KEY_X; |
||
95 | k.ascii = 'x'; |
||
1436 | giacomo | 96 | k.status = KEY_PRESSED; |
97 | keyb_hook(k, endfun, FALSE); |
||
1085 | pj | 98 | |
99 | k.flag = CNTR_BIT; |
||
1436 | giacomo | 100 | k.status = KEY_PRESSED; |
101 | keyb_hook(k, endfun, FALSE); |
||
1085 | pj | 102 | |
103 | soft_task_default_model(show_aper_mod); |
||
104 | soft_task_def_aperiodic(show_aper_mod); |
||
1436 | giacomo | 105 | soft_task_def_level(show_aper_mod, 2); |
1085 | pj | 106 | soft_task_def_period(show_aper_mod, 250000); |
107 | soft_task_def_met(show_aper_mod, 30000); |
||
108 | soft_task_def_wcet(show_aper_mod, 60000); |
||
109 | if( (show_aper_pid = task_create("Show aperiodic task", show_aper, &show_aper_mod, NULL)) == NIL ){ |
||
110 | sys = 10; |
||
111 | sys_end(); |
||
112 | } |
||
113 | |||
114 | k.flag = 0; |
||
115 | k.scan = KEY_S; |
||
116 | k.ascii = 's'; |
||
1436 | giacomo | 117 | k.status = KEY_PRESSED; |
118 | keyb_hook(k, show_evt, FALSE); |
||
1085 | pj | 119 | |
120 | k.flag = 0; |
||
121 | k.scan = KEY_G; |
||
122 | k.ascii = 'g'; |
||
1436 | giacomo | 123 | k.status = KEY_PRESSED; |
124 | keyb_hook(k, gate_change, FALSE); |
||
1085 | pj | 125 | |
126 | k.scan = KEY_H; |
||
127 | k.ascii = 'h'; |
||
1436 | giacomo | 128 | k.status = KEY_PRESSED; |
129 | keyb_hook(k, gate_change, FALSE); |
||
1085 | pj | 130 | |
131 | soft_task_default_model(show_per_mod); |
||
1436 | giacomo | 132 | soft_task_def_level(show_per_mod, 2); |
1085 | pj | 133 | soft_task_def_met(show_per_mod, 1000); |
134 | soft_task_def_period(show_per_mod, 10000); |
||
135 | if( (show_per_pid = task_create("Show periodic task", show_per, &show_per_mod, NULL)) == NIL){ |
||
136 | sys = 11; |
||
137 | sys_end(); |
||
138 | } |
||
139 | |||
140 | if(!reMap()){ |
||
141 | sys = 21; |
||
142 | sys_end(); |
||
143 | } |
||
144 | |||
145 | drawInterface(); |
||
146 | |||
147 | DIO_init(); |
||
148 | DIO_setup(0xFF); |
||
149 | DIO_write(out); |
||
150 | |||
151 | PFIprogramming(0x0000); |
||
152 | setIntClock(1, 1, 0); |
||
153 | TIM_reset(2); //Reset both two counters |
||
154 | |||
155 | |||
156 | //Source PFI3(41); Gate PFI 4(42); Down counting; counts rising edge; |
||
157 | TIM_bufferedEventCounting(C0, 0x04, 0x45, 0x01, init_val_c0); |
||
158 | |||
159 | //Source PFI6(45); Gate PFI 5(44); Up counting; counts rising edge; |
||
160 | TIM_bufferedEventCounting(C1, 0x87, 0x46, 0x00, init_val_c1); |
||
161 | |||
162 | TIM_arm(2); //Arm both two counters |
||
163 | |||
164 | task_activate(show_per_pid); |
||
165 | |||
166 | return 0; |
||
167 | } |
||
168 | |||
169 | void drawInterface(void) |
||
170 | { |
||
171 | grx_rect(1, 1, 799, 99, rgb16(105, 0, 0)); |
||
172 | grx_rect(2, 2, 798, 98, rgb16(155, 0, 0)); |
||
173 | grx_rect(3, 3, 797, 97, rgb16(205, 0, 0)); |
||
174 | grx_rect(4, 4, 796, 96, rgb16(255, 0, 0)); |
||
175 | |||
176 | grx_text("Test program for Buffered Event Counting capacity of PCI6025E timers", |
||
177 | 7, 10, rgb16(50, 255, 50), black); |
||
178 | |||
179 | grx_text("This program counting rise edges on counters source (PFI3 & PFI6)", |
||
180 | 7, 18, rgb16(0, 255, 255), black); |
||
181 | grx_text("Counter 1 will be resetted every gate falling edge", |
||
182 | 7, 26, rgb16(0, 255, 255), black); |
||
183 | grx_text("(PFI 42 & 44) are enabled. Frequency Out (FOUT) is enabled and provides a frequency of 6250 Hz", |
||
184 | 7, 34, rgb16(0, 255, 255), black); |
||
185 | |||
186 | grx_text("Instruction:",7, 43, rgb16(255, 0, 0), black); |
||
187 | grx_text("Use 's' to watch contents of Hardware save registers updated every time gate goes down", |
||
188 | 7, 51, rgb16(0, 255, 255), black); |
||
189 | grx_text("Use 'g' to generate an event on counter 0 gate (see top-left square)", |
||
190 | 7, 58, rgb16(0, 255, 255), black); |
||
191 | |||
192 | grx_text("Use 'h' to generate an event on counter 1 gate (see bottom-left square)", |
||
193 | 7, 65, rgb16(0, 255, 255), black); |
||
194 | |||
195 | grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)", |
||
196 | 7, 78, rgb16(0, 255, 0), black); |
||
197 | grx_text("CTRL-X for Exit", 7, 88, rgb16(200, 200, 0), black); |
||
198 | |||
199 | grx_rect(1, 110, 355, 170, rgb16(0, 105, 0)); |
||
200 | grx_rect(2, 111, 354, 169, rgb16(0, 155, 0)); |
||
201 | grx_rect(3, 112, 353, 168, rgb16(0, 205, 0)); |
||
202 | grx_rect(4, 113, 352, 167, rgb16(0, 255, 0)); |
||
203 | grx_text("Counter 0 evolution", 7, 120, rgb16(255, 255, 0), black); |
||
204 | |||
205 | grx_rect(455, 110, 799, 170, rgb16(0, 105, 0)); |
||
206 | grx_rect(456, 111, 798, 169, rgb16(0, 155, 0)); |
||
207 | grx_rect(457, 112, 797, 168, rgb16(0, 205, 0)); |
||
208 | grx_rect(458, 113, 796, 167, rgb16(0, 255, 0)); |
||
209 | grx_text("Counter 0 locked value", 461, 120, rgb16(255, 0, 255), black); |
||
210 | |||
211 | grx_rect(360, 110, 450, 170, rgb16(0, 105, 0)); |
||
212 | grx_rect(361, 111, 449, 169, rgb16(0, 155, 0)); |
||
213 | grx_rect(362, 112, 448, 168, rgb16(0, 205, 0)); |
||
214 | grx_rect(363, 113, 447, 167, rgb16(0, 255, 0)); |
||
215 | grx_text("Gate0", 367, 120, rgb16(200, 255, 200), black); |
||
216 | grx_text("0 V", 367, 145, rgb16(255, 0, 0), black); |
||
217 | |||
218 | grx_rect(1, 190, 355, 260, rgb16(85, 85, 255)); |
||
219 | grx_rect(2, 191, 354, 259, rgb16(135, 135, 255)); |
||
220 | grx_rect(3, 192, 353, 258, rgb16(190, 190, 255)); |
||
221 | grx_rect(4, 193, 352, 257, rgb16(230, 239, 255)); |
||
222 | grx_text("Counter 1 evolution", 7, 200, white, black); |
||
223 | |||
224 | grx_rect(455, 190, 799, 260, rgb16(85, 85, 255)); |
||
225 | grx_rect(456, 191, 798, 259, rgb16(135, 135, 255)); |
||
226 | grx_rect(457, 192, 797, 258, rgb16(190, 190, 255)); |
||
227 | grx_rect(458, 193, 796, 257, rgb16(230, 230, 255)); |
||
228 | grx_text("Counter 1 locked value", 461, 200, white, black); |
||
229 | |||
230 | grx_rect(360, 190, 450, 260, rgb16(85, 85, 255)); |
||
231 | grx_rect(361, 191, 449, 259, rgb16(135, 135, 255)); |
||
232 | grx_rect(362, 192, 448, 258, rgb16(190, 190, 255)); |
||
233 | grx_rect(363, 193, 447, 257, rgb16(230, 230, 255)); |
||
234 | grx_text("Gate1", 367, 200, rgb16(255, 200, 255), black); |
||
235 | grx_text("0 V", 367, 225, rgb16(255, 0, 0), black); |
||
236 | } |
||
237 | |||
238 | TASK show_per(int none) |
||
239 | { |
||
240 | DWORD val; |
||
241 | char buf[30]; |
||
242 | |||
243 | while(1){ |
||
244 | val = TIM_readCounter(C0); //Read from Hardware Save Register |
||
245 | sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val); |
||
246 | grx_text(buf, 7, 145, rgb16(255, 0, 0), black); |
||
247 | |||
248 | val = TIM_readCounter(C1); //Read from Hardware Save Register |
||
249 | sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val); |
||
250 | grx_text(buf, 7, 225, rgb16(255, 0, 0), black); |
||
251 | |||
252 | task_endcycle(); |
||
253 | } |
||
254 | } |
||
255 | |||
256 | TASK show_aper(int dummy) |
||
257 | { |
||
258 | DWORD val; |
||
259 | char buf[30]; |
||
260 | |||
261 | while(1){ |
||
262 | val = TIM_readHWSaveReg(C0); //Read from Hardware Save Register |
||
263 | sprintf(buf, "HEX: %08lx DEC: %08ld", val, val); |
||
264 | grx_text(buf, 461, 145, rgb16(80, 80, 255), black); |
||
265 | |||
266 | val = TIM_readHWSaveReg(C1); //Read from Hardware Save Register |
||
267 | sprintf(buf, "HEX: %08lx DEC: %08ld", val, val); |
||
268 | grx_text(buf, 461, 225, rgb16(80, 80, 255), black); |
||
269 | |||
270 | task_endcycle(); |
||
271 | } |
||
272 | } |
||
273 | |||
274 | void endfun(KEY_EVT *k) |
||
275 | { |
||
1436 | giacomo | 276 | close_event(NULL); |
277 | |||
1085 | pj | 278 | sys_end(); |
279 | } |
||
280 | |||
281 | void show_evt(KEY_EVT *k) |
||
282 | { |
||
283 | task_activate(show_aper_pid); |
||
284 | } |
||
285 | |||
286 | void gate_change(KEY_EVT *k) |
||
287 | { |
||
288 | if(k->ascii == 'g'){ |
||
289 | if( (out & 0x80) != 0){ |
||
290 | out &= 0x7F; |
||
291 | grx_text("0 V", 367, 145, rgb16(255, 0, 0), black); |
||
292 | } else { |
||
293 | out |= 0x80; |
||
294 | grx_text("5 V", 367, 145, rgb16(0, 255, 0), black); |
||
295 | } |
||
296 | } else { |
||
297 | if( (out & 0x40) != 0){ |
||
298 | out &= 0xBF; |
||
299 | grx_text("0 V", 367, 225, rgb16(255, 0, 0), black); |
||
300 | } else { |
||
301 | out |= 0x40; |
||
302 | grx_text("5 V", 367, 225, rgb16(0, 255, 0), black); |
||
303 | } |
||
304 | } |
||
305 | |||
306 | DIO_write(out); |
||
307 | } |
||
308 | |||
309 | void close_event(void *arg) |
||
310 | { |
||
311 | TIM_disarm(2); //Disable both two counters |
||
312 | |||
313 | switch(sys){ |
||
1436 | giacomo | 314 | case 0: sys_shutdown_message("OK\n"); break; |
315 | case 10: sys_shutdown_message("Task <show aperiodic> down\n"); break; |
||
316 | case 11: sys_shutdown_message("Task <show periodic> down\n"); break; |
||
317 | case 20: sys_shutdown_message("No PCI bus\n"); break; |
||
318 | case 21: sys_shutdown_message("No National board on PCI bus\n"); break; |
||
319 | case 30: sys_shutdown_message("No graphic can be initialized\n"); break; |
||
320 | case 31: sys_shutdown_message("This graphic mode cannot be supported\n"); break; |
||
321 | default: sys_shutdown_message("???????????\n"); break; |
||
1085 | pj | 322 | } |
323 | } |
||
324 | /* End of file: Test_bec.c */ |