Rev 1550 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /***************************************************************************** |
2 | * Filename: test_bms.c * |
||
3 | * Author: Marco Ziglioli (Doctor Stein) * |
||
4 | * Date: 27/06/2001 * |
||
5 | * Description: Test program for buffered period and semiperiod measurement * |
||
6 | * capacity of National PCI6025E board * |
||
7 | *----------------------------------------------------------------------------* |
||
8 | * Notes: FOUT are enable and avaiable on pin 50 to provide 1 Mhz frequency * |
||
9 | * You should connect source 0 (PIN 41) and source 1 (pin 45) to this * |
||
10 | * freq source. Gate 0 (pin 42) and gate 1 (pin 44) must be connected * |
||
11 | * rispectivly to DIO7 (pin 32) and DIO6 (pin 30). * |
||
12 | * Use 'g' button to activate gate_action_task which generate a square * |
||
13 | * wave with a freq of 0.5 Hz and Duty cycle of 75%. * |
||
14 | * 's' button should show counters countent but gate_action_task * |
||
15 | * when active shows counters content automatically so 's' button isn't* |
||
16 | * useful. * |
||
17 | *****************************************************************************/ |
||
18 | |||
19 | /* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it |
||
20 | * |
||
21 | * Copyright (C) 2001 Marco Ziglioli |
||
22 | * |
||
23 | * This program is free software; you can redistribute it and/or modify |
||
24 | * it under the terms of the GNU General Public License as published by |
||
25 | * the Free Software Foundation; either version 2 of the License, or |
||
26 | * (at your option) any later version. |
||
27 | * |
||
28 | * This program is distributed in the hope that it will be useful, |
||
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
31 | * GNU General Public License for more details. |
||
32 | * |
||
33 | * You should have received a copy of the GNU General Public License |
||
34 | * along with this program; if not, write to the Free Software |
||
35 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
36 | * |
||
37 | */ |
||
38 | |||
39 | #include <kernel/kern.h> |
||
40 | |||
1436 | giacomo | 41 | #include <drivers/shark_keyb26.h> |
42 | #include <drivers/shark_fb26.h> |
||
43 | |||
1085 | pj | 44 | #include <drivers/pci6025e/timer.h> |
45 | #include <drivers/pci6025e/dio_ppi.h> |
||
46 | |||
47 | #define SHOW_MET 30000 |
||
48 | #define SHOW_WCET 50000 |
||
49 | #define SHOW_PERIOD 1000000 |
||
50 | |||
51 | #define GATE_MET 2000 |
||
52 | #define GATE_WCET 5000 |
||
53 | #define GATE_PERIOD 2000000 |
||
54 | |||
55 | #define GATE_ACTION_P 500000 |
||
56 | #define GATE_ACTION_W 10000 |
||
57 | |||
58 | #define black rgb16(0, 0, 0) |
||
59 | |||
60 | void endFun(KEY_EVT *); |
||
61 | void gateEvent(KEY_EVT *); |
||
62 | void showEvent(KEY_EVT *); |
||
63 | |||
64 | void closeEvent(void *); |
||
65 | |||
66 | void drawInterface(void); |
||
67 | |||
68 | TASK show_val_body(int); |
||
69 | TASK gate_action_body(int); |
||
70 | |||
71 | BYTE sys = 0; |
||
72 | PID show_val_pid, gate_action_pid; |
||
73 | |||
74 | int main(int argc, char **argv) |
||
75 | { |
||
76 | KEY_EVT k; |
||
77 | SOFT_TASK_MODEL show_val_mod; |
||
78 | HARD_TASK_MODEL gate_action_model; |
||
79 | |||
80 | k.flag = CNTL_BIT; |
||
1599 | tullio | 81 | k.scan = KEY_C; |
82 | k.ascii = 'c'; |
||
1436 | giacomo | 83 | k.status = KEY_PRESSED; |
84 | keyb_hook(k, endFun, FALSE); |
||
1085 | pj | 85 | |
86 | k.flag = CNTR_BIT; |
||
1436 | giacomo | 87 | k.status = KEY_PRESSED; |
88 | keyb_hook(k, endFun, FALSE); |
||
1085 | pj | 89 | |
90 | k.flag = 0; |
||
91 | k.scan = KEY_G; |
||
92 | k.ascii = 'g'; |
||
1436 | giacomo | 93 | k.status = KEY_PRESSED; |
94 | keyb_hook(k, gateEvent, FALSE); |
||
1085 | pj | 95 | |
96 | k.scan = KEY_S; |
||
97 | k.ascii = 's'; |
||
1436 | giacomo | 98 | k.status = KEY_PRESSED; |
99 | keyb_hook(k, showEvent, FALSE); |
||
1085 | pj | 100 | |
101 | if(!reMap()){ |
||
102 | sys = 11; |
||
1550 | pj | 103 | exit(1); |
1085 | pj | 104 | } |
105 | |||
106 | soft_task_default_model(show_val_mod); |
||
107 | soft_task_def_aperiodic(show_val_mod); |
||
1436 | giacomo | 108 | soft_task_def_level(show_val_mod, 2); |
1085 | pj | 109 | soft_task_def_met(show_val_mod, SHOW_MET); |
110 | soft_task_def_wcet(show_val_mod, SHOW_WCET); |
||
111 | soft_task_def_period(show_val_mod, SHOW_PERIOD); |
||
112 | if( (show_val_pid = task_create("Show task", show_val_body, &show_val_mod, NULL)) |
||
113 | == NIL ){ |
||
114 | sys = 20; |
||
1550 | pj | 115 | exit(1); |
1085 | pj | 116 | } |
117 | |||
118 | hard_task_default_model(gate_action_model); |
||
119 | hard_task_def_mit(gate_action_model, GATE_ACTION_P); |
||
120 | hard_task_def_wcet(gate_action_model, GATE_ACTION_W); |
||
121 | if( (gate_action_pid = task_create("Gate Action", gate_action_body, &gate_action_model, NULL)) |
||
122 | == NIL ){ |
||
123 | sys = 22; |
||
1550 | pj | 124 | exit(1); |
1085 | pj | 125 | } |
126 | |||
127 | drawInterface(); |
||
128 | |||
129 | DIO_init(); |
||
130 | DIO_setup(0xFF); |
||
131 | DIO_write(0x00); |
||
132 | |||
133 | //All PFI configured as input |
||
134 | PFIprogramming(0x0000); |
||
135 | |||
136 | //Fout provide 1MHz: timebase = 20MHz; divided by 2; on FOUT pin also divided by 10 |
||
137 | setIntClock(0, 1, 10); |
||
138 | |||
139 | //Reset both counters |
||
140 | TIM_reset(2); |
||
141 | |||
142 | //C0 measures period on PFI3 with gate from PFI 4 driven by DIO7 |
||
143 | TIM_bufferedTimeMeasurement(C0, 0x04, 0x45, 0, 0); |
||
144 | |||
145 | //C1 measures semiperiod on PFI 6 with gate from PFI 5 driven by FIO6 |
||
146 | TIM_bufferedTimeMeasurement(C1, 0x87, 0x46, 1, 0); |
||
147 | |||
148 | //arm both counters |
||
149 | TIM_arm(2); |
||
150 | |||
151 | return 0; |
||
152 | } |
||
153 | |||
154 | void endFun(KEY_EVT *k) |
||
155 | { |
||
1436 | giacomo | 156 | closeEvent(NULL); |
157 | |||
1550 | pj | 158 | exit(1); |
1085 | pj | 159 | } |
160 | |||
161 | void showEvent(KEY_EVT *k) |
||
162 | { |
||
163 | task_activate(show_val_pid); |
||
164 | } |
||
165 | |||
166 | void gateEvent(KEY_EVT *k) |
||
167 | { |
||
168 | task_activate(gate_action_pid); |
||
169 | } |
||
170 | |||
171 | void drawInterface(void) |
||
172 | { |
||
173 | grx_rect(1, 1, 799, 129, rgb16(105, 0, 0)); |
||
174 | grx_rect(2, 2, 798, 128, rgb16(155, 0, 0)); |
||
175 | grx_rect(3, 3, 797, 127, rgb16(205, 0, 0)); |
||
176 | grx_rect(4, 4, 796, 126, rgb16(255, 0, 0)); |
||
177 | |||
178 | grx_text("Test program for Buffered Period and Semiperiod measure through PCI6025E timers", |
||
179 | 7, 10, rgb16(50, 255, 50), black); |
||
180 | |||
181 | grx_text("This program counting rise edges on counters source (PFI3 & PFI6) between two rising", |
||
182 | 7, 25, rgb16(0, 255, 255), black); |
||
183 | grx_text("edges on gate (PFI 42) and beetwen each gate edge (PFI44).FOUT is enabled and", |
||
184 | 7, 33, rgb16(0, 255, 255), black); |
||
185 | grx_text("provides a frequency of 1 MHz", 7, 41, rgb16(0, 255, 255), black); |
||
186 | grx_text("Instruction:",7, 53, rgb16(255, 0, 0), black); |
||
187 | grx_text("Use 's' to see counters value", |
||
188 | 7, 61, rgb16(0, 255, 255), black); |
||
189 | grx_text("Use 'g' to enbale automatic tasks which generate square wave with freq of 0.5Hz", |
||
190 | 7, 68, rgb16(0, 255, 255), black); |
||
191 | |||
192 | grx_text("And duty cycle of 75%. Counter 0 must be loaded with about 2E6 ticks and counter 1", |
||
193 | 7, 75, rgb16(0, 255, 255), black); |
||
194 | grx_text("must be loaded alternativly with about 1.5E6 and 0.5E6 ticks", |
||
195 | 7, 83, rgb16(0, 255, 255), black); |
||
196 | |||
197 | grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)", |
||
198 | 7, 95, rgb16(0, 255, 0), black); |
||
1599 | tullio | 199 | grx_text("CTRL-C for Exit", 7, 110, rgb16(200, 200, 0), black); |
1085 | pj | 200 | |
201 | grx_rect(1, 147, 355, 183, rgb16(0, 105, 0)); |
||
202 | grx_rect(2, 148, 354, 182, rgb16(0, 155, 0)); |
||
203 | grx_rect(3, 149, 353, 181, rgb16(0, 205, 0)); |
||
204 | grx_rect(4, 150, 352, 180, rgb16(0, 255, 0)); |
||
205 | grx_text("Period", 7, 155, rgb16(255, 255, 0), black); |
||
206 | |||
207 | grx_rect(455, 147, 799, 183, rgb16(0, 105, 0)); |
||
208 | grx_rect(456, 148, 798, 182, rgb16(0, 155, 0)); |
||
209 | grx_rect(457, 149, 797, 181, rgb16(0, 205, 0)); |
||
210 | grx_rect(458, 150, 796, 180, rgb16(0, 255, 0)); |
||
211 | grx_text("Semiperiod", 461, 155, rgb16(255, 0, 255), black); |
||
212 | } |
||
213 | |||
214 | TASK show_val_body(int dummy) |
||
215 | { |
||
216 | DWORD val; |
||
217 | char buf[40]; |
||
218 | |||
219 | while(1){ |
||
220 | val = TIM_readHWSaveReg(C0); |
||
221 | sprintf(buf,"C0 %07ld", val); |
||
222 | grx_text(buf, 7, 165, rgb16(255, 0, 0), rgb16(0, 0, 0)); |
||
223 | val = TIM_readHWSaveReg(C1); |
||
224 | sprintf(buf,"C1 %07ld", val); |
||
225 | grx_text(buf, 461, 165, rgb16(0, 255, 0), rgb16(0, 0, 0)); |
||
226 | |||
227 | task_endcycle(); |
||
228 | } |
||
229 | } |
||
230 | |||
231 | TASK gate_action_body(int dummy) |
||
232 | { |
||
233 | int i; |
||
234 | i = 0; |
||
235 | |||
236 | while(1){ |
||
237 | if( (i%4)==0 ) DIO_write(0xC0); |
||
238 | if( (i%4)==3 ) DIO_write(0x00); |
||
239 | |||
240 | i++; |
||
241 | |||
242 | task_activate(show_val_pid); |
||
243 | |||
244 | task_endcycle(); |
||
245 | } |
||
246 | } |
||
247 | |||
248 | void closeEvent(void *arg) |
||
249 | { |
||
250 | TIM_disarm(2); |
||
251 | switch(sys){ |
||
1436 | giacomo | 252 | case 0: sys_shutdown_message("Ok\n"); break; |
253 | case 10: sys_shutdown_message("No PCI\n"); break; |
||
254 | case 11: sys_shutdown_message("No National Board\n"); break; |
||
255 | case 20: sys_shutdown_message("task <show val> down\n"); break; |
||
256 | case 22: sys_shutdown_message("task <gate action> down\n"); break; |
||
257 | case 30: sys_shutdown_message("Cannot initialize grx\n"); break; |
||
258 | case 31: sys_shutdown_message("Resolution 800x600x16 not supported\n"); break; |
||
259 | case 32: sys_shutdown_message("Cannot sets up graphic envirorment\n"); break; |
||
260 | default: sys_shutdown_message("????????????\n"); break; |
||
1085 | pj | 261 | } |
262 | } |