Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /***************************************************************************** |
2 | * Filename: test_mes.c * |
||
3 | * Author: Marco Ziglioli (Doctor Stein) * |
||
4 | * Date: 25/06/2001 * |
||
5 | * Description: Test file for single period and pulsewidth measurement feature* |
||
6 | * of PCI6025E timers/counters * |
||
7 | *----------------------------------------------------------------------------* |
||
8 | * Notes: board is configured to provide a frequency of 1 MHZ through its FOUT* |
||
9 | * pin (50). PFI3 (41) and PFI6 (45) are configured like source pins * |
||
10 | * counter 0 and counter 1. PFI4 (42) and PFI 5(44) are the gates for * |
||
11 | * the two counters. Please connect DIO7(32) to PFI4 and DIO6(30) to * |
||
12 | * PFI 5. * |
||
13 | * With 'g' key a task is started which generate a square wave on DIO7 * |
||
14 | * with a period of 2 secs. With 'h' key the same square wave is * |
||
15 | * generated on DIO6. * |
||
16 | * When measurement is performed data are stored into Hardware Save * |
||
17 | * Registers: use key 's' to show this values * |
||
18 | *****************************************************************************/ |
||
19 | |||
20 | |||
21 | /* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it |
||
22 | * |
||
23 | * Copyright (C) 2001 Marco Ziglioli |
||
24 | * |
||
25 | * This program is free software; you can redistribute it and/or modify |
||
26 | * it under the terms of the GNU General Public License as published by |
||
27 | * the Free Software Foundation; either version 2 of the License, or |
||
28 | * (at your option) any later version. |
||
29 | * |
||
30 | * This program is distributed in the hope that it will be useful, |
||
31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
33 | * GNU General Public License for more details. |
||
34 | * |
||
35 | * You should have received a copy of the GNU General Public License |
||
36 | * along with this program; if not, write to the Free Software |
||
37 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
38 | * |
||
39 | */ |
||
40 | |||
41 | |||
42 | #include <kernel/kern.h> |
||
43 | #include <drivers/keyb.h> |
||
44 | #include <drivers/glib.h> |
||
45 | |||
46 | #include <drivers/pci6025e/timer.h> |
||
47 | #include <drivers/pci6025e/dio_ppi.h> |
||
48 | |||
49 | #define TASK_MET 20000 |
||
50 | #define TASK_WCET 50000 |
||
51 | #define TASK_PERIOD 100000 |
||
52 | |||
53 | #define PERIOD 1000000 |
||
54 | |||
55 | void endFun(KEY_EVT *); |
||
56 | void gateEvent(KEY_EVT *); |
||
57 | |||
58 | void drawInterface(void); |
||
59 | void closeEvent(void *); |
||
60 | |||
61 | TASK show_body(int); |
||
62 | TASK gate_body(int); |
||
63 | |||
64 | BYTE sys = 0; |
||
65 | PID c0_gate_pid, c1_gate_pid, show_pid; |
||
66 | int black = rgb16(0, 0, 0); |
||
67 | |||
68 | int main(int argc, char **argv) |
||
69 | { |
||
70 | KEY_EVT k; |
||
71 | int modenum; |
||
72 | SOFT_TASK_MODEL show_model; |
||
73 | HARD_TASK_MODEL gating; |
||
74 | |||
75 | sys_atrunlevel(closeEvent, NULL, RUNLEVEL_BEFORE_EXIT); |
||
76 | |||
77 | k.flag = CNTL_BIT; |
||
78 | k.scan = KEY_X; |
||
79 | k.ascii = 'x'; |
||
80 | keyb_hook(k, endFun); |
||
81 | |||
82 | k.flag = CNTR_BIT; |
||
83 | keyb_hook(k, endFun); |
||
84 | |||
85 | k.flag = 0; |
||
86 | k.scan = KEY_G; |
||
87 | k.ascii = 'g'; |
||
88 | keyb_hook(k, gateEvent); |
||
89 | |||
90 | k.scan = KEY_H; |
||
91 | k.ascii = 'h'; |
||
92 | keyb_hook(k, gateEvent); |
||
93 | |||
94 | k.scan = KEY_S; |
||
95 | k.ascii = 's'; |
||
96 | keyb_hook(k, gateEvent); |
||
97 | |||
98 | if(pci_init()==-1){ |
||
99 | sys = 10; |
||
100 | sys_end(); |
||
101 | } |
||
102 | |||
103 | if(!reMap()){ |
||
104 | sys = 11; |
||
105 | sys_end(); |
||
106 | } |
||
107 | |||
108 | soft_task_default_model(show_model); |
||
109 | soft_task_def_level(show_model, 1); |
||
110 | soft_task_def_met(show_model, TASK_MET); |
||
111 | soft_task_def_wcet(show_model, TASK_WCET); |
||
112 | soft_task_def_aperiodic(show_model); |
||
113 | soft_task_def_period(show_model, TASK_PERIOD); |
||
114 | if( (show_pid = task_create("Show task", show_body, &show_model, NULL)) |
||
115 | == NIL ){ |
||
116 | sys = 20; |
||
117 | sys_end(); |
||
118 | } |
||
119 | |||
120 | hard_task_default_model(gating); |
||
121 | hard_task_def_mit(gating, PERIOD); |
||
122 | hard_task_def_wcet(gating, 20000); |
||
123 | hard_task_def_arg(gating, C0); |
||
124 | if( (c0_gate_pid = task_create("C0 Gate task", gate_body, &gating, NULL)) == NIL ){ |
||
125 | sys = 21; |
||
126 | sys_end(); |
||
127 | } |
||
128 | |||
129 | hard_task_def_arg(gating, (void *)C1); |
||
130 | if( (c1_gate_pid = task_create("C1 Gate task", gate_body, &gating, NULL)) == NIL ){ |
||
131 | sys = 22; |
||
132 | sys_end(); |
||
133 | } |
||
134 | |||
135 | if(grx_init()==-1){ |
||
136 | sys = 30; |
||
137 | sys_end(); |
||
138 | } |
||
139 | |||
140 | if( (modenum = grx_getmode(800, 600, 16)) == 0 ){ |
||
141 | sys = 31; |
||
142 | sys_end(); |
||
143 | } |
||
144 | |||
145 | grx_setmode(modenum); |
||
146 | drawInterface(); |
||
147 | //Enable DIO to manage gates |
||
148 | DIO_init(); |
||
149 | DIO_setup(0xFF); |
||
150 | DIO_write(0x00); |
||
151 | |||
152 | //All PFI configured as input |
||
153 | PFIprogramming(0x0000); |
||
154 | //Fout provide 1MHz: timebase = 20MHz; divided by 2; on FOUT pin also divided by 10 |
||
155 | setIntClock(0, 1, 10); |
||
156 | |||
157 | //Reset both counters |
||
158 | TIM_reset(2); |
||
159 | |||
160 | //Source PFI3(41); Gate PFI 4(42); Measure period |
||
161 | TIM_timeMeasurement(C0, 0x04, 0x45, 0, 0x00, 0); |
||
162 | |||
163 | //Source PFI6(45); Gate PFI 5(44); Measure pulsewidth |
||
164 | TIM_timeMeasurement(C1, 0x87, 0x46, 1, 0x00, 0); |
||
165 | |||
166 | //Arm both counter |
||
167 | TIM_arm(2); |
||
168 | |||
169 | return 0; |
||
170 | } |
||
171 | |||
172 | TASK show_body(int dummy) |
||
173 | { |
||
174 | DWORD val; |
||
175 | char buf[20]; |
||
176 | |||
177 | while(1){ |
||
178 | val = TIM_readHWSaveReg(C0); |
||
179 | sprintf(buf, "%ld", val); |
||
180 | grx_text(buf, 600, 471, rgb16(0, 255, 0), black); |
||
181 | val = TIM_readHWSaveReg(C1); |
||
182 | sprintf(buf, "%ld", val); |
||
183 | grx_text(buf, 200, 471, rgb16(255, 0, 0), black); |
||
184 | |||
185 | task_endcycle(); |
||
186 | } |
||
187 | } |
||
188 | |||
189 | TASK gate_body(int counter) |
||
190 | { |
||
191 | BYTE out; |
||
192 | |||
193 | if(counter == C0) out = 0x80; |
||
194 | else out = 0x40; |
||
195 | |||
196 | while(1){ |
||
197 | DIO_write(out); |
||
198 | if(counter == C0){ |
||
199 | if(out) out = 0x00; |
||
200 | else out = 0x80; |
||
201 | } else { |
||
202 | if(out) out = 0x40; |
||
203 | else out = 0x00; |
||
204 | } |
||
205 | |||
206 | task_endcycle(); |
||
207 | } |
||
208 | } |
||
209 | |||
210 | void drawInterface(void) |
||
211 | { |
||
212 | grx_rect(1, 1, 799, 120, rgb16(105, 0, 0)); |
||
213 | grx_rect(2, 2, 798, 119, rgb16(155, 0, 0)); |
||
214 | grx_rect(3, 3, 797, 118, rgb16(205, 0, 0)); |
||
215 | grx_rect(4, 4, 796, 117, rgb16(255, 0, 0)); |
||
216 | |||
217 | grx_text("Test program for single period and pulsewidth measurement features", |
||
218 | 7, 10, rgb16(200, 200, 0), black); |
||
219 | |||
220 | grx_text("This program measures single period and pulsewidth of a square wave", |
||
221 | 7, 20, rgb16(0, 255, 0), black); |
||
222 | grx_text("with frequency of 0.5 Hz", 7, 28, rgb16(0, 255, 0), black); |
||
223 | grx_text("Please connect PFI3 & PFI6 (41 & 45) to FOUT pin (50) or to 1Mhz frequency source", |
||
224 | 7, 40, rgb16(255, 0, 0), black); |
||
225 | grx_text("Connect also DIO7 (32) to PFI4 (42) and DIO6 to PFI5 (44)", |
||
226 | 7, 48, rgb16(255, 0, 0), black); |
||
227 | grx_text("Commands:", 7, 60, rgb16(0, 120, 0), black); |
||
228 | grx_text("Use 'g' to start wave generation on DIO7", |
||
229 | 7, 70, rgb16(0, 255, 255), black); |
||
230 | grx_text("Use 'h' to start wave generation on DIO6", |
||
231 | 7, 78, rgb16(0, 255, 255), black); |
||
232 | grx_text("Use 's' to show Hardware Save Registers content", |
||
233 | 7, 86, rgb16(0, 255, 255), black); |
||
234 | grx_text("CTRL-X to exit", 7, 105, rgb16(255, 255, 0), black); |
||
235 | |||
236 | grx_rect(197, 127, 603, 423, rgb16(0, 255, 0)); |
||
237 | grx_rect(198, 128, 602, 422, rgb16(0, 205, 0)); |
||
238 | grx_rect(199, 129, 601, 421, rgb16(0, 155, 0)); |
||
239 | grx_rect(200, 130, 600, 420, rgb16(0, 105, 0)); |
||
240 | grx_line(215, 405, 215, 150, rgb16(255, 255, 255)); |
||
241 | grx_line(210, 400, 580, 400, rgb16(255, 255, 255)); |
||
242 | grx_line(220, 395, 220, 170, rgb16(0, 0, 255)); |
||
243 | grx_line(220, 170, 390, 170, rgb16(0, 0, 255)); |
||
244 | grx_line(390, 170, 390, 395, rgb16(0, 0, 255)); |
||
245 | grx_line(390, 395, 560, 395, rgb16(0, 0, 255)); |
||
246 | grx_line(220, 150, 560, 150, rgb16(0, 255, 0)); |
||
247 | grx_line(220, 155, 390, 155, rgb16(255, 0, 0)); |
||
248 | |||
249 | grx_rect(1, 450, 390, 503, rgb16(105, 0, 0)); |
||
250 | grx_rect(2, 451, 389, 502, rgb16(155, 0, 0)); |
||
251 | grx_rect(3, 452, 388, 501, rgb16(205, 0, 0)); |
||
252 | grx_rect(4, 453, 387, 500, rgb16(255, 0, 0)); |
||
253 | grx_text("Pulsewidth: [us]", 7, 471, rgb16(255, 0, 0), black); |
||
254 | |||
255 | grx_rect(410, 450, 799, 503, rgb16(105, 0, 0)); |
||
256 | grx_rect(411, 451, 798, 502, rgb16(155, 0, 0)); |
||
257 | grx_rect(412, 452, 797, 501, rgb16(205, 0, 0)); |
||
258 | grx_rect(413, 453, 796, 500, rgb16(255, 0, 0)); |
||
259 | grx_text("Period: [us]", 416, 471, rgb16(0, 255, 0), black); |
||
260 | } |
||
261 | |||
262 | void endFun(KEY_EVT *k) |
||
263 | { |
||
264 | sys_end(); |
||
265 | } |
||
266 | |||
267 | void gateEvent(KEY_EVT *k) |
||
268 | { |
||
269 | if(k->scan == KEY_G) task_activate(c0_gate_pid); |
||
270 | if(k->scan == KEY_H) task_activate(c1_gate_pid); |
||
271 | if(k->scan == KEY_S) task_activate(show_pid); |
||
272 | } |
||
273 | |||
274 | void closeEvent(void *arg) |
||
275 | { |
||
276 | TIM_disarm(2); |
||
277 | grx_close(); |
||
278 | |||
279 | switch(sys){ |
||
280 | case 0: cprintf("OK\n"); break; |
||
281 | case 10: cprintf("No PCI bus found\n"); break; |
||
282 | case 11: cprintf("No NATIONAL board found\n"); break; |
||
283 | case 20: cprintf("task <show value> down!!\n"); break; |
||
284 | case 21: cprintf("task <C0 gate manage> down!!!\n"); break; |
||
285 | case 22: cprintf("task <C1 gate manage> down!!!\n"); break; |
||
286 | case 30: cprintf("Cannot init graphic envirorment\n"); break; |
||
287 | case 31: cprintf("graphic mode 800x600x16 not supported\n"); break; |
||
288 | default: cprintf("???????????????\n"); break; |
||
289 | } |
||
290 | } |