Subversion Repositories shark

Rev

Rev 1599 | 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
 
1436 giacomo 47
#include <drivers/shark_keyb26.h>
48
#include <drivers/shark_fb26.h>
49
 
1085 pj 50
#include <drivers/pci6025e/timer.h>
51
#include <drivers/pci6025e/dio_ppi.h>
52
 
53
#ifndef INT_NO
54
   #define INT_NO NIDevice_info[0].InterruptLevel
55
#endif
56
 
57
BYTE sys = 0;
58
 
59
PID show_aper_pid;
60
BYTE out = 0x00;
61
 
62
int black = rgb16(0, 0, 0),
63
    white = rgb16(255, 255, 255);
64
 
65
void endfun(KEY_EVT *);
66
void close_event(void *);
67
void show_evt(KEY_EVT *k);
68
void gate_change(KEY_EVT *k);
69
 
70
void drawInterface(void);
71
 
72
void int_evt(int intno);
73
 
74
TASK show_per(int);
75
TASK show_aper(int);
76
 
77
int main(int argc, char **argv)
78
{
79
   KEY_EVT k;
80
   SOFT_TASK_MODEL show_per_mod, show_aper_mod;
81
   PID show_per_pid;
1436 giacomo 82
   int result;
1085 pj 83
   DWORD init_val_c0, init_val_c1;
84
 
85
   if(argc >= 3){
86
      if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
87
         init_val_c0 = 0x00FFFFFF;
88
      if( (result = sscanf(argv[2], "%ld", &init_val_c1)) != 1)
89
         init_val_c1 = 0x00000000;
90
   }
91
   if(argc == 2){
92
      if( (result = sscanf(argv[1], "%ld", &init_val_c0)) != 1)
93
         init_val_c0 = 0x00FFFFFF;
94
      init_val_c1 = 0x00000000;
95
   }
96
   if(argc == 1){
97
      init_val_c0 = 0x00FFFFFF;
98
      init_val_c1 = 0x00000000;
99
   }
100
 
101
   k.flag = CNTL_BIT;
1599 tullio 102
   k.scan = KEY_C;
103
   k.ascii = 'c';
1436 giacomo 104
   k.status = KEY_PRESSED;
105
   keyb_hook(k, endfun, FALSE);
1085 pj 106
 
107
   k.flag = CNTR_BIT;
1436 giacomo 108
   k.status = KEY_PRESSED;
109
   keyb_hook(k, endfun, FALSE);
1085 pj 110
 
111
   soft_task_default_model(show_aper_mod);
112
   soft_task_def_aperiodic(show_aper_mod);
1436 giacomo 113
   soft_task_def_level(show_aper_mod, 2);
1085 pj 114
   soft_task_def_period(show_aper_mod, 250000);
115
   soft_task_def_met(show_aper_mod, 30000);
116
   soft_task_def_wcet(show_aper_mod, 60000);
117
   if( (show_aper_pid = task_create("Show aperiodic task", show_aper, &show_aper_mod, NULL)) == NIL ){
118
      sys = 10;
1550 pj 119
      exit(1);
1085 pj 120
   }
121
 
122
   k.flag = 0;
123
   k.scan = KEY_S;
124
   k.ascii = 's';
1436 giacomo 125
   k.status = KEY_PRESSED;
126
   keyb_hook(k, show_evt, FALSE);
1085 pj 127
 
128
   k.flag = 0;
129
   k.scan = KEY_G;
130
   k.ascii = 'g';
1436 giacomo 131
   k.status = KEY_PRESSED;
132
   keyb_hook(k, gate_change, FALSE);
1085 pj 133
 
134
   k.scan = KEY_H;
135
   k.ascii = 'h';
1436 giacomo 136
   k.status = KEY_PRESSED;
137
   keyb_hook(k, gate_change, FALSE);
1085 pj 138
 
139
   soft_task_default_model(show_per_mod);
1436 giacomo 140
   soft_task_def_level(show_per_mod, 2);
1085 pj 141
   soft_task_def_met(show_per_mod, 1000);
142
   soft_task_def_period(show_per_mod, 10000);
143
   if( (show_per_pid = task_create("Show periodic task", show_per, &show_per_mod, NULL)) == NIL){
144
      sys = 11;
1550 pj 145
      exit(1);
1085 pj 146
   }
147
 
148
   if(!reMap()){
149
      sys = 21;
1550 pj 150
      exit(1);
1085 pj 151
   }
152
 
153
   drawInterface();
154
 
155
        //Init DIO lines used to manage counters gates
156
   DIO_init();
157
   DIO_setup(0xFF);
158
   DIO_write(out);
159
 
160
        //All PFI are configured as input
161
   PFIprogramming(0x0000);
162
        //FOUT enable; Slow TIMEBASE, divided by two; divided by 16 on FOUT pin
163
   setIntClock(1, 1, 0);
164
 
165
   TIM_reset(2); //Reset both two counters
166
 
167
   //Source PFI3(41); Gate PFI 4(42); Down counting; counts rising edge;
168
   TIM_eventCounting(C0, 0x04, 0x45, 0x03, init_val_c0);
169
 
170
   //Source PFI6(45); Gate PFI 5(44); Up counting; counts rising edge;
171
   TIM_eventCounting(C1, 0x87, 0x46, 0x03, init_val_c1);
172
 
173
        //Set up interrupt group A and B enabling and programming to assert a request
174
        //both on line 2 and 3 respectively
175
   INT_setup(0x0A, 0x0B);
176
   INT_personalize(0x03);       //Interrupt request polarity low; IRQ driven on line 0 and 1 
177
 
1567 mauro 178
   handler_set(INT_NO, int_evt, FALSE, show_aper_pid, NULL);
1085 pj 179
 
180
   TIM_arm(2); //Arm both two counters
181
 
182
   task_activate(show_per_pid);
183
 
184
   return 0;
185
}
186
 
187
void drawInterface(void)
188
{
189
   grx_rect(1, 1, 799, 99, rgb16(105, 0, 0));
190
   grx_rect(2, 2, 798, 98, rgb16(155, 0, 0));
191
   grx_rect(3, 3, 797, 97, rgb16(205, 0, 0));
192
   grx_rect(4, 4, 796, 96, rgb16(255, 0, 0));
193
 
194
   grx_text("Test program for Gated Event Counting capacity of PCI6025E timers",
195
            7, 10, rgb16(50, 255, 50), black);
196
 
197
   grx_text("This program counting rise edges on counters source (PFI3 & PFI6) when releted gates",
198
             7, 25, rgb16(0, 255, 255), black);
199
   grx_text("(PFI 42 & 44) are enabled. Frequency Out (FOUT) is enabled and provides a frequency of 6250 Hz",
200
             7, 33, rgb16(0, 255, 255), black);
201
 
202
   grx_text("Instruction:",7, 43, rgb16(255, 0, 0), black);
203
   grx_text("Use 's' to lock counters value in right squares",
204
            7, 51, rgb16(0, 255, 255), black);
205
   grx_text("Use 'g' to block or to release alternativly counter 0 (see top-left square)",
206
             7, 58, rgb16(0, 255, 255), black);
207
 
208
   grx_text("Use 'h' to block or to release alternativly counter 1 (see bottom-left square)",
209
             7, 65, rgb16(0, 255, 255), black);
210
 
211
   grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)",
212
             7, 78, rgb16(0, 255, 0), black);
1599 tullio 213
   grx_text("CTRL-C for Exit", 7, 88, rgb16(200, 200, 0), black);
1085 pj 214
 
215
   grx_rect(1, 110, 355, 170, rgb16(0, 105, 0));
216
   grx_rect(2, 111, 354, 169, rgb16(0, 155, 0));
217
   grx_rect(3, 112, 353, 168, rgb16(0, 205, 0));
218
   grx_rect(4, 113, 352, 167, rgb16(0, 255, 0));
219
   grx_text("Counter 0 evolution", 7, 120, rgb16(255, 255, 0), black);
220
 
221
   grx_rect(455, 110, 799, 170, rgb16(0, 105, 0));
222
   grx_rect(456, 111, 798, 169, rgb16(0, 155, 0));
223
   grx_rect(457, 112, 797, 168, rgb16(0, 205, 0));
224
   grx_rect(458, 113, 796, 167, rgb16(0, 255, 0));
225
   grx_text("Counter 0 locked value", 461, 120, rgb16(255, 0, 255), black);
226
 
227
   grx_rect(360, 110, 450, 170, rgb16(0, 105, 0));
228
   grx_rect(361, 111, 449, 169, rgb16(0, 155, 0));
229
   grx_rect(362, 112, 448, 168, rgb16(0, 205, 0));
230
   grx_rect(363, 113, 447, 167, rgb16(0, 255, 0));
231
   grx_text("Gate0", 367, 120, rgb16(200, 255, 200), black);
232
   grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
233
 
234
   grx_rect(1, 190, 355, 260, rgb16(85, 85, 255));
235
   grx_rect(2, 191, 354, 259, rgb16(135, 135, 255));
236
   grx_rect(3, 192, 353, 258, rgb16(190, 190, 255));
237
   grx_rect(4, 193, 352, 257, rgb16(230, 239, 255));
238
   grx_text("Counter 1 evolution", 7, 200, white, black);
239
 
240
   grx_rect(455, 190, 799, 260, rgb16(85, 85, 255));
241
   grx_rect(456, 191, 798, 259, rgb16(135, 135, 255));
242
   grx_rect(457, 192, 797, 258, rgb16(190, 190, 255));
243
   grx_rect(458, 193, 796, 257, rgb16(230, 230, 255));
244
   grx_text("Counter 1 locked value", 461, 200, white, black);
245
 
246
   grx_rect(360, 190, 450, 260, rgb16(85, 85, 255));
247
   grx_rect(361, 191, 449, 259, rgb16(135, 135, 255));
248
   grx_rect(362, 192, 448, 258, rgb16(190, 190, 255));
249
   grx_rect(363, 193, 447, 257, rgb16(230, 230, 255));
250
   grx_text("Gate1", 367, 200, rgb16(255, 200, 255), black);
251
   grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
252
 
253
   grx_text("Counter 0 Interrupt events", 7, 340, rgb16(255, 200, 100), black);
254
   grx_text("Counter 1 Interrupt events", 461, 340, rgb16(255, 200, 100), black);
255
   grx_rect(1, 350, 355, 400, rgb16(105, 0, 0));
256
   grx_rect(2, 351, 354, 399, rgb16(155, 0, 0));
257
   grx_rect(3, 352, 353, 398, rgb16(205, 0, 0));
258
   grx_rect(4, 353, 352, 397, rgb16(255, 0, 0));
259
   grx_rect(455, 350, 799, 400, rgb16(105, 0, 0));
260
   grx_rect(456, 351, 798, 399, rgb16(155, 0, 0));
261
   grx_rect(457, 352, 797, 398, rgb16(205, 0, 0));
262
   grx_rect(458, 353, 796, 397, rgb16(255, 0, 0));
263
}
264
 
265
 
266
TASK show_per(int none)
267
{
268
   DWORD val;
269
   char buf[30];
270
 
271
   while(1){
272
      val = TIM_readCounter(C0);        //Read counter 0 value
273
      sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
274
      grx_text(buf, 7, 145, rgb16(255, 0, 0), black);
275
 
276
      val = TIM_readCounter(C1);        //Read counter 1 value
277
      sprintf(buf, "HEX: %08lx DEC: %08ld", val ,val);
278
      grx_text(buf, 7, 225, rgb16(255, 0, 0), black);
279
 
280
      task_endcycle();
281
   }
282
}
283
 
284
TASK show_aper(int dummy)
285
{
286
   DWORD val;
287
   char buf[30];
288
 
289
   while(1){
290
      val = TIM_readCounter(C0);
291
      sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
292
      grx_text(buf, 461, 145, rgb16(80, 80, 255), black);
293
 
294
      val = TIM_readCounter(C1);
295
      sprintf(buf, "HEX: %08lx DEC: %08ld", val, val);
296
      grx_text(buf, 461, 225, rgb16(80, 80, 255), black);
297
 
298
      task_endcycle();
299
   }
300
}
301
 
302
void endfun(KEY_EVT *k)
303
{
1436 giacomo 304
   close_event(NULL);
305
 
1550 pj 306
   exit(1);
1085 pj 307
}
308
 
309
void show_evt(KEY_EVT *k)
310
{
311
   task_activate(show_aper_pid);
312
}
313
 
314
void gate_change(KEY_EVT *k)
315
{
316
   if(k->ascii == 'g'){
317
      if( (out & 0x80) != 0){
318
         out &= 0x7F;
319
         grx_text("0 V", 367, 145, rgb16(255, 0, 0), black);
320
      } else {
321
         out |= 0x80;
322
         grx_text("5 V", 367, 145, rgb16(0, 255, 0), black);
323
      }
324
   } else {
325
      if( (out & 0x40) != 0){
326
         out &= 0xBF;
327
         grx_text("0 V", 367, 225, rgb16(255, 0, 0), black);
328
      } else {
329
         out |= 0x40;
330
         grx_text("5 V", 367, 225, rgb16(0, 255, 0), black);
331
      }
332
   }
333
 
334
   DIO_write(out);
335
}
336
 
337
void close_event(void *arg)
338
{
339
   TIM_disarm(2); //Disable both two counters
340
   handler_remove(INT_NO);
341
 
342
   switch(sys){
1436 giacomo 343
      case 0:     sys_shutdown_message("OK\n"); break;
344
      case 10:    sys_shutdown_message("Task <show aperiodic> down\n"); break;
345
      case 11:    sys_shutdown_message("Task <show periodic> down\n"); break;
346
      case 20:    sys_shutdown_message("No PCI bus\n"); break;
347
      case 21:    sys_shutdown_message("No National board on PCI bus\n"); break;
348
      case 30:    sys_shutdown_message("No graphic can be initialized\n"); break;
349
      case 31:    sys_shutdown_message("This graphic mode cannot be supported\n"); break;
350
      default:    sys_shutdown_message("???????????\n"); break;
1085 pj 351
   }
352
}
353
 
354
void int_evt(int intno)
355
{
356
   WORD status;
357
 
358
   status = DAQ_STC_Windowed_Mode_Read(AI_STATUS_1);
359
   if( (status & 0x8000) != 0){
360
      if( (status & 0x0008) != 0){
361
         grx_text("INT Group A raised! G0 Rolls over", 7, 360, rgb16(0, 255, 0), black);
362
         set(interrupt_a_ack, 14);
363
         DAQ_STC_Windowed_Mode_Write(INTERRUPT_A_ACK, interrupt_a_ack);
364
         clr(interrupt_a_ack, 14);
365
      }
366
      if( (status & 0x0004) != 0){
367
         grx_text("INT Group A raised! G0 gate pressed", 7, 380, rgb16(0, 255, 0), black);
368
         set(interrupt_a_ack, 15);
369
         DAQ_STC_Windowed_Mode_Write(INTERRUPT_A_ACK, interrupt_a_ack);
370
         clr(interrupt_a_ack, 15);
371
      }
372
      return;
373
   }
374
 
375
   status = DAQ_STC_Windowed_Mode_Read(AO_STATUS_1);
376
   if( (status & 0x8000) != 0){
377
      if( (status & 0x0008) != 0){
378
         grx_text("INT Group B raised! G1 Rolls over", 461, 360, rgb16(0, 255, 0), black);
379
         set(interrupt_b_ack, 14);
380
         DAQ_STC_Windowed_Mode_Write(INTERRUPT_B_ACK, interrupt_b_ack);
381
         clr(interrupt_b_ack, 14);
382
      }
383
      if( (status & 0x0004) != 0){
384
         grx_text("INT Group B raised! G1 gate pressed", 461, 380, rgb16(0, 255, 0), black);
385
         set(interrupt_b_ack, 15);
386
         DAQ_STC_Windowed_Mode_Write(INTERRUPT_B_ACK, interrupt_b_ack);
387
         clr(interrupt_b_ack, 15);
388
      }
389
      return;
390
   }
391
}
392
/* End of file: Test_ec.c */