Subversion Repositories shark

Rev

Rev 1085 | Rev 1436 | 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_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
#include <drivers/keyb.h>
41
#include <drivers/glib.h>
42
 
43
#include <drivers/pci6025e/timer.h>
44
#include <drivers/pci6025e/dio_ppi.h>
45
 
46
#define  SHOW_MET         30000
47
#define  SHOW_WCET        50000
48
#define  SHOW_PERIOD    1000000
49
 
50
#define  GATE_MET          2000
51
#define  GATE_WCET         5000
52
#define  GATE_PERIOD    2000000
53
 
54
#define  GATE_ACTION_P   500000
55
#define  GATE_ACTION_W    10000
56
 
57
#define  black          rgb16(0, 0, 0)
58
 
59
void endFun(KEY_EVT *);
60
void gateEvent(KEY_EVT *);
61
void showEvent(KEY_EVT *);
62
 
63
void closeEvent(void *);
64
 
65
void drawInterface(void);
66
 
67
TASK show_val_body(int);
68
TASK gate_action_body(int);
69
 
70
BYTE     sys = 0;
71
PID      show_val_pid, gate_action_pid;
72
 
73
int main(int argc, char **argv)
74
{
75
   KEY_EVT k;
76
   int modenum;
77
   SOFT_TASK_MODEL show_val_mod;
78
   HARD_TASK_MODEL gate_action_model;
79
 
80
   sys_atrunlevel(closeEvent, NULL, RUNLEVEL_BEFORE_EXIT);
81
 
82
   k.flag  =  CNTL_BIT;
83
   k.scan  =  KEY_X;
84
   k.ascii =  'x';
85
   keyb_hook(k, endFun);
86
 
87
   k.flag  =  CNTR_BIT;
88
   keyb_hook(k, endFun);
89
 
90
   k.flag  =  0;
91
   k.scan  =  KEY_G;
92
   k.ascii =  'g';
93
   keyb_hook(k, gateEvent);
94
 
95
   k.scan  =  KEY_S;
96
   k.ascii =  's';
97
   keyb_hook(k, showEvent);
98
 
99
   if(pci_init()==-1){
100
      sys = 10;
101
      sys_end();
102
   }
103
 
104
   if(!reMap()){
105
      sys = 11;
106
      sys_end();
107
   }
108
 
109
   soft_task_default_model(show_val_mod);
110
   soft_task_def_aperiodic(show_val_mod);
111
   soft_task_def_level(show_val_mod, 1);
112
   soft_task_def_met(show_val_mod, SHOW_MET);
113
   soft_task_def_wcet(show_val_mod, SHOW_WCET);
114
   soft_task_def_period(show_val_mod, SHOW_PERIOD);
115
   if( (show_val_pid = task_create("Show task", show_val_body, &show_val_mod, NULL))
116
            == NIL ){
117
      sys = 20;
118
      sys_end();
119
   }
120
 
121
   hard_task_default_model(gate_action_model);
122
   hard_task_def_mit(gate_action_model, GATE_ACTION_P);
123
   hard_task_def_wcet(gate_action_model, GATE_ACTION_W);
124
   if( (gate_action_pid = task_create("Gate Action", gate_action_body, &gate_action_model, NULL))
125
            == NIL ){
126
      sys = 22;
127
      sys_end();
128
   }
129
 
130
   if(grx_init()==-1){
131
      sys = 30;
132
      sys_end();
133
   }
134
 
135
   if( (modenum = grx_getmode(800, 600, 16)) == -1){
136
      sys = 31;
137
      sys_end();
138
   }
139
 
140
   if(grx_setmode(modenum) == -1){
141
      sys = 32;
142
      sys_end();
143
   }
144
 
145
   drawInterface();
146
 
147
   DIO_init();
148
   DIO_setup(0xFF);
149
   DIO_write(0x00);
150
 
151
        //All PFI configured as input
152
   PFIprogramming(0x0000);
153
 
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
   //C0 measures period on PFI3 with gate from PFI 4 driven by DIO7
161
   TIM_bufferedTimeMeasurement(C0, 0x04, 0x45, 0, 0);
162
 
163
   //C1 measures semiperiod on PFI 6 with gate from PFI 5 driven by FIO6
164
   TIM_bufferedTimeMeasurement(C1, 0x87, 0x46, 1, 0);
165
 
166
        //arm both counters
167
   TIM_arm(2);
168
 
169
   return 0;
170
}
171
 
172
void endFun(KEY_EVT *k)
173
{
174
   sys_end();
175
}
176
 
177
void showEvent(KEY_EVT *k)
178
{
179
   task_activate(show_val_pid);
180
}
181
 
182
void gateEvent(KEY_EVT *k)
183
{
184
   task_activate(gate_action_pid);
185
}
186
 
187
void drawInterface(void)
188
{
189
   grx_rect(1, 1, 799, 129, rgb16(105, 0, 0));
190
   grx_rect(2, 2, 798, 128, rgb16(155, 0, 0));
191
   grx_rect(3, 3, 797, 127, rgb16(205, 0, 0));
192
   grx_rect(4, 4, 796, 126, rgb16(255, 0, 0));
193
 
194
   grx_text("Test program for Buffered Period and Semiperiod measure through PCI6025E timers",
195
            7, 10, rgb16(50, 255, 50), black);
196
 
197
   grx_text("This program counting rise edges on counters source (PFI3 & PFI6) between two rising",
198
             7, 25, rgb16(0, 255, 255), black);
199
   grx_text("edges on gate (PFI 42) and beetwen each gate edge (PFI44).FOUT is enabled and",
200
             7, 33, rgb16(0, 255, 255), black);
201
   grx_text("provides a frequency of 1 MHz", 7, 41, rgb16(0, 255, 255), black);
202
   grx_text("Instruction:",7, 53, rgb16(255, 0, 0), black);
203
   grx_text("Use 's' to see counters value",
204
            7, 61, rgb16(0, 255, 255), black);
205
   grx_text("Use 'g' to enbale automatic tasks which generate square wave with freq of 0.5Hz",
206
             7, 68, rgb16(0, 255, 255), black);
207
 
208
   grx_text("And duty cycle of 75%. Counter 0 must be loaded with about 2E6 ticks and counter 1",
209
             7, 75, rgb16(0, 255, 255), black);
210
   grx_text("must be loaded alternativly with about 1.5E6 and 0.5E6 ticks",
211
             7, 83, rgb16(0, 255, 255), black);
212
 
213
   grx_text("Please connect DIO7 (pin 32) to PFI4 (pin 42) and DIO6 (pin 30) to PFI5 (pin 44)",
214
             7, 95, rgb16(0, 255, 0), black);
215
   grx_text("CTRL-X for Exit", 7, 110, rgb16(200, 200, 0), black);
216
 
217
   grx_rect(1, 147, 355, 183, rgb16(0, 105, 0));
218
   grx_rect(2, 148, 354, 182, rgb16(0, 155, 0));
219
   grx_rect(3, 149, 353, 181, rgb16(0, 205, 0));
220
   grx_rect(4, 150, 352, 180, rgb16(0, 255, 0));
221
   grx_text("Period", 7, 155, rgb16(255, 255, 0), black);
222
 
223
   grx_rect(455, 147, 799, 183, rgb16(0, 105, 0));
224
   grx_rect(456, 148, 798, 182, rgb16(0, 155, 0));
225
   grx_rect(457, 149, 797, 181, rgb16(0, 205, 0));
226
   grx_rect(458, 150, 796, 180, rgb16(0, 255, 0));
227
   grx_text("Semiperiod", 461, 155, rgb16(255, 0, 255), black);
228
}
229
 
230
TASK show_val_body(int dummy)
231
{
232
   DWORD val;
233
   char buf[40];
234
 
235
   while(1){
236
      val = TIM_readHWSaveReg(C0);
237
      sprintf(buf,"C0 %07ld", val);
238
      grx_text(buf, 7, 165, rgb16(255, 0, 0), rgb16(0, 0, 0));
239
      val = TIM_readHWSaveReg(C1);
240
      sprintf(buf,"C1 %07ld", val);
241
      grx_text(buf, 461, 165, rgb16(0, 255, 0), rgb16(0, 0, 0));
242
 
243
      task_endcycle();
244
   }
245
}
246
 
247
TASK gate_action_body(int dummy)
248
{
249
   int i;
250
   i = 0;
251
 
252
   while(1){
253
      if( (i%4)==0 )    DIO_write(0xC0);
254
      if( (i%4)==3 )    DIO_write(0x00);
255
 
256
      i++;
257
 
258
      task_activate(show_val_pid);
259
 
260
      task_endcycle();
261
   }
262
}
263
 
264
void closeEvent(void *arg)
265
{
266
   grx_close();
267
   TIM_disarm(2);
268
   switch(sys){
269
      case  0:  cprintf("Ok\n"); break;
270
      case 10:  cprintf("No PCI\n"); break;
271
      case 11:  cprintf("No National Board\n"); break;
272
      case 20:  cprintf("task <show val> down\n"); break;
273
      case 22:  cprintf("task <gate action> down\n"); break;
274
      case 30:  cprintf("Cannot initialize grx\n"); break;
275
      case 31:  cprintf("Resolution 800x600x16 not supported\n"); break;
276
      case 32:  cprintf("Cannot sets up graphic envirorment\n"); break;
277
      default:  cprintf("????????????\n"); break;
278
   }
279
}