Subversion Repositories shark

Rev

Rev 1085 | 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
#include <drivers/keyb.h>
45
#include <drivers/glib.h>
46
 
47
#include <drivers/pci6025e/timer.h>
48
#include <drivers/pci6025e/dio_ppi.h>
49
 
50
BYTE sys = 0;
51
 
52
PID show_aper_pid;
53
BYTE out = 0x00;
54
 
55
int black = rgb16(0, 0, 0),
56
    white = rgb16(255, 255, 255);
57
 
58
void endfun(KEY_EVT *);
59
void close_event(void *);
60
void show_evt(KEY_EVT *k);
61
void gate_change(KEY_EVT *k);
62
 
63
void drawInterface(void);
64
 
65
TASK show_per(int);
66
TASK show_aper(int);
67
 
68
int main(int argc, char **argv)
69
{
70
   KEY_EVT k;
71
   SOFT_TASK_MODEL show_per_mod, show_aper_mod;
72
   PID show_per_pid;
73
   int result, modenum;
74
   DWORD init_val_c0, init_val_c1;
75
 
76
   if(argc >= 3){
77
      if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
78
         init_val_c0 = 0x00FFFFFF;
79
      if( (result = sscanf(argv[2], "%ld", &init_val_c1)) != 1)
80
         init_val_c1 = 0x00000000;
81
   }
82
   if(argc == 2){
83
      if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
84
         init_val_c0 = 0x00FFFFFF;
85
      init_val_c1 = 0x00000000;
86
   }
87
   if(argc == 1){
88
      init_val_c0 = 0x00FFFFFF;
89
      init_val_c1 = 0x00000000;
90
   }
91
 
92
   sys_atrunlevel(close_event, NULL, RUNLEVEL_BEFORE_EXIT);
93
 
94
   k.flag = CNTL_BIT;
95
   k.scan = KEY_X;
96
   k.ascii = 'x';
97
   keyb_hook(k, endfun);
98
 
99
   k.flag = CNTR_BIT;
100
   keyb_hook(k, endfun);
101
 
102
   soft_task_default_model(show_aper_mod);
103
   soft_task_def_aperiodic(show_aper_mod);
104
   soft_task_def_level(show_aper_mod, 1);
105
   soft_task_def_period(show_aper_mod, 250000);
106
   soft_task_def_met(show_aper_mod, 30000);
107
   soft_task_def_wcet(show_aper_mod, 60000);
108
   if( (show_aper_pid = task_create("Show aperiodic task", show_aper, &show_aper_mod, NULL)) == NIL ){
109
      sys = 10;
110
      sys_end();
111
   }
112
 
113
   k.flag = 0;
114
   k.scan = KEY_S;
115
   k.ascii = 's';
116
   keyb_hook(k, show_evt);
117
 
118
   k.flag = 0;
119
   k.scan = KEY_G;
120
   k.ascii = 'g';
121
   keyb_hook(k, gate_change);
122
 
123
   k.scan = KEY_H;
124
   k.ascii = 'h';
125
   keyb_hook(k, gate_change);
126
 
127
   soft_task_default_model(show_per_mod);
128
   soft_task_def_level(show_per_mod, 1);
129
   soft_task_def_met(show_per_mod, 1000);
130
   soft_task_def_period(show_per_mod, 10000);
131
   if( (show_per_pid = task_create("Show periodic task", show_per, &show_per_mod, NULL)) == NIL){
132
      sys = 11;
133
      sys_end();
134
   }
135
 
136
   if(pci_init()==-1){
137
      sys = 20;
138
      sys_end();
139
   }
140
 
141
   if(!reMap()){
142
      sys = 21;
143
      sys_end();
144
   }
145
 
146
   if(grx_init()==-1){
147
      sys = 30;
148
      sys_end();
149
   }
150
 
151
   if( (modenum = grx_getmode(800, 600, 16)) == -1){
152
      sys = 31;
153
      sys_end();
154
   }
155
 
156
   grx_setmode(modenum);
157
 
158
   drawInterface();
159
 
160
   DIO_init();
161
   DIO_setup(0xFF);
162
   DIO_write(out);
163
 
164
   PFIprogramming(0x0000);
165
   setIntClock(1, 1, 0);
166
   TIM_reset(2); //Reset both two counters
167
 
168
 
169
   //Source PFI3(41); Gate PFI 4(42); Down counting; counts rising edge;
170
   TIM_bufferedEventCounting(C0, 0x04, 0x45, 0x01, init_val_c0);
171
 
172
   //Source PFI6(45); Gate PFI 5(44); Up counting; counts rising edge;
173
   TIM_bufferedEventCounting(C1, 0x87, 0x46, 0x00, init_val_c1);
174
 
175
   TIM_arm(2); //Arm both two counters
176
 
177
   task_activate(show_per_pid);
178
 
179
   return 0;
180
}
181
 
182
void drawInterface(void)
183
{
184
   grx_rect(1, 1, 799, 99, rgb16(105, 0, 0));
185
   grx_rect(2, 2, 798, 98, rgb16(155, 0, 0));
186
   grx_rect(3, 3, 797, 97, rgb16(205, 0, 0));
187
   grx_rect(4, 4, 796, 96, rgb16(255, 0, 0));
188
 
189
   grx_text("Test program for Buffered Event Counting capacity of PCI6025E timers",
190
            7, 10, rgb16(50, 255, 50), black);
191
 
192
   grx_text("This program counting rise edges on counters source (PFI3 & PFI6)",
193
             7, 18, rgb16(0, 255, 255), black);
194
   grx_text("Counter 1 will be resetted every gate falling edge",
195
             7, 26, rgb16(0, 255, 255), black);
196
   grx_text("(PFI 42 & 44) are enabled. Frequency Out (FOUT) is enabled and provides a frequency of 6250 Hz",
197
             7, 34, rgb16(0, 255, 255), black);
198
 
199
   grx_text("Instruction:",7, 43, rgb16(255, 0, 0), black);
200
   grx_text("Use 's' to watch contents of Hardware save registers updated every time gate goes down",
201
            7, 51, rgb16(0, 255, 255), black);
202
   grx_text("Use 'g' to generate an event on counter 0 gate (see top-left square)",
203
             7, 58, rgb16(0, 255, 255), black);
204
 
205
   grx_text("Use 'h' to generate an event on counter 1 gate (see bottom-left square)",
206
             7, 65, rgb16(0, 255, 255), black);
207
 
208
   grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)",
209
             7, 78, rgb16(0, 255, 0), black);
210
   grx_text("CTRL-X for Exit", 7, 88, rgb16(200, 200, 0), black);
211
 
212
   grx_rect(1, 110, 355, 170, rgb16(0, 105, 0));
213
   grx_rect(2, 111, 354, 169, rgb16(0, 155, 0));
214
   grx_rect(3, 112, 353, 168, rgb16(0, 205, 0));
215
   grx_rect(4, 113, 352, 167, rgb16(0, 255, 0));
216
   grx_text("Counter 0 evolution", 7, 120, rgb16(255, 255, 0), black);
217
 
218
   grx_rect(455, 110, 799, 170, rgb16(0, 105, 0));
219
   grx_rect(456, 111, 798, 169, rgb16(0, 155, 0));
220
   grx_rect(457, 112, 797, 168, rgb16(0, 205, 0));
221
   grx_rect(458, 113, 796, 167, rgb16(0, 255, 0));
222
   grx_text("Counter 0 locked value", 461, 120, rgb16(255, 0, 255), black);
223
 
224
   grx_rect(360, 110, 450, 170, rgb16(0, 105, 0));
225
   grx_rect(361, 111, 449, 169, rgb16(0, 155, 0));
226
   grx_rect(362, 112, 448, 168, rgb16(0, 205, 0));
227
   grx_rect(363, 113, 447, 167, rgb16(0, 255, 0));
228
   grx_text("Gate0", 367, 120, rgb16(200, 255, 200), black);
229
   grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
230
 
231
   grx_rect(1, 190, 355, 260, rgb16(85, 85, 255));
232
   grx_rect(2, 191, 354, 259, rgb16(135, 135, 255));
233
   grx_rect(3, 192, 353, 258, rgb16(190, 190, 255));
234
   grx_rect(4, 193, 352, 257, rgb16(230, 239, 255));
235
   grx_text("Counter 1 evolution", 7, 200, white, black);
236
 
237
   grx_rect(455, 190, 799, 260, rgb16(85, 85, 255));
238
   grx_rect(456, 191, 798, 259, rgb16(135, 135, 255));
239
   grx_rect(457, 192, 797, 258, rgb16(190, 190, 255));
240
   grx_rect(458, 193, 796, 257, rgb16(230, 230, 255));
241
   grx_text("Counter 1 locked value", 461, 200, white, black);
242
 
243
   grx_rect(360, 190, 450, 260, rgb16(85, 85, 255));
244
   grx_rect(361, 191, 449, 259, rgb16(135, 135, 255));
245
   grx_rect(362, 192, 448, 258, rgb16(190, 190, 255));
246
   grx_rect(363, 193, 447, 257, rgb16(230, 230, 255));
247
   grx_text("Gate1", 367, 200, rgb16(255, 200, 255), black);
248
   grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
249
}
250
 
251
TASK show_per(int none)
252
{
253
   DWORD val;
254
   char buf[30];
255
 
256
   while(1){
257
      val = TIM_readCounter(C0); //Read from Hardware Save Register
258
      sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
259
      grx_text(buf, 7, 145, rgb16(255, 0, 0), black);
260
 
261
      val = TIM_readCounter(C1); //Read from Hardware Save Register
262
      sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
263
      grx_text(buf, 7, 225, rgb16(255, 0, 0), black);
264
 
265
      task_endcycle();
266
   }
267
}
268
 
269
TASK show_aper(int dummy)
270
{
271
   DWORD val;
272
   char buf[30];
273
 
274
   while(1){
275
      val = TIM_readHWSaveReg(C0); //Read from Hardware Save Register
276
      sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
277
      grx_text(buf, 461, 145, rgb16(80, 80, 255), black);
278
 
279
      val = TIM_readHWSaveReg(C1); //Read from Hardware Save Register
280
      sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
281
      grx_text(buf, 461, 225, rgb16(80, 80, 255), black);
282
 
283
      task_endcycle();
284
   }
285
}
286
 
287
void endfun(KEY_EVT *k)
288
{
289
   sys_end();
290
}
291
 
292
void show_evt(KEY_EVT *k)
293
{
294
   task_activate(show_aper_pid);
295
}
296
 
297
void gate_change(KEY_EVT *k)
298
{
299
   if(k->ascii == 'g'){
300
      if( (out & 0x80) != 0){
301
         out &= 0x7F;
302
         grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
303
      } else {
304
         out |= 0x80;
305
         grx_text("5 V", 367, 145, rgb16(0, 255, 0), black);
306
      }
307
   } else {
308
      if( (out & 0x40) != 0){
309
         out &= 0xBF;
310
         grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
311
      } else {
312
         out |= 0x40;
313
         grx_text("5 V", 367, 225, rgb16(0, 255, 0), black);
314
      }
315
   }
316
 
317
   DIO_write(out);
318
}
319
 
320
void close_event(void *arg)
321
{
322
   TIM_disarm(2); //Disable both two counters
323
   grx_close();
324
 
325
   switch(sys){
326
      case 0:     cprintf("OK\n"); break;
327
      case 10:    cprintf("Task <show aperiodic> down\n"); break;
328
      case 11:    cprintf("Task <show periodic> down\n"); break;
329
      case 20:    cprintf("No PCI bus\n"); break;
330
      case 21:    cprintf("No National board on PCI bus\n"); break;
331
      case 30:    cprintf("No graphic can be initialized\n"); break;
332
      case 31:    cprintf("This graphic mode cannot be supported\n"); break;
333
      default:    cprintf("???????????\n"); break;
334
   }
335
}
336
/* End of file: Test_bec.c */