Subversion Repositories shark

Rev

Rev 1550 | Details | Compare with Previous | 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
 
1436 giacomo 44
#include <drivers/shark_keyb26.h>
45
#include <drivers/shark_fb26.h>
46
 
1085 pj 47
#include <drivers/pci6025e/timer.h>
48
#include <drivers/pci6025e/dio_ppi.h>
49
 
50
#define TASK_MET  20000
51
#define TASK_WCET 50000
52
#define TASK_PERIOD 100000
53
 
54
#define PERIOD 1000000
55
 
56
void endFun(KEY_EVT *);
57
void gateEvent(KEY_EVT *);
58
 
59
void drawInterface(void);
60
void closeEvent(void *);
61
 
62
TASK show_body(int);
63
TASK gate_body(int);
64
 
65
BYTE sys = 0;
66
PID c0_gate_pid, c1_gate_pid, show_pid;
67
int black = rgb16(0, 0, 0);
68
 
69
int main(int argc, char **argv)
70
{
71
   KEY_EVT k;
72
   SOFT_TASK_MODEL show_model;
73
   HARD_TASK_MODEL gating;
74
 
75
   k.flag = CNTL_BIT;
1599 tullio 76
   k.scan = KEY_C;
77
   k.ascii = 'c';
1436 giacomo 78
   k.status = KEY_PRESSED;
79
   keyb_hook(k, endFun, FALSE);
1085 pj 80
 
81
   k.flag = CNTR_BIT;
1436 giacomo 82
   k.status = KEY_PRESSED;
83
   keyb_hook(k, endFun, FALSE);
1085 pj 84
 
85
   k.flag = 0;
86
   k.scan = KEY_G;
87
   k.ascii = 'g';
1436 giacomo 88
   k.status = KEY_PRESSED;
89
   keyb_hook(k, gateEvent, FALSE);
1085 pj 90
 
91
   k.scan = KEY_H;
92
   k.ascii = 'h';
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, gateEvent, 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_model);
1436 giacomo 107
   soft_task_def_level(show_model, 2);
1085 pj 108
   soft_task_def_met(show_model, TASK_MET);
109
   soft_task_def_wcet(show_model, TASK_WCET);
110
   soft_task_def_aperiodic(show_model);
111
   soft_task_def_period(show_model, TASK_PERIOD);
112
   if( (show_pid = task_create("Show task", show_body, &show_model, NULL))
113
         == NIL ){
114
      sys = 20;
1550 pj 115
      exit(1);
1085 pj 116
   }
117
 
118
   hard_task_default_model(gating);
119
   hard_task_def_mit(gating, PERIOD);
120
   hard_task_def_wcet(gating, 20000);
121
   hard_task_def_arg(gating, C0);
122
   if( (c0_gate_pid = task_create("C0 Gate task", gate_body, &gating, NULL)) == NIL ){
123
      sys = 21;
1550 pj 124
      exit(1);
1085 pj 125
   }
126
 
127
   hard_task_def_arg(gating, (void *)C1);
128
   if( (c1_gate_pid = task_create("C1 Gate task", gate_body, &gating, NULL)) == NIL ){
129
      sys = 22;
1550 pj 130
      exit(1);
1085 pj 131
   }
132
 
133
   drawInterface();
134
        //Enable DIO to manage gates
135
   DIO_init();
136
   DIO_setup(0xFF);
137
   DIO_write(0x00);
138
 
139
        //All PFI configured as input
140
   PFIprogramming(0x0000);
141
        //Fout provide 1MHz: timebase = 20MHz; divided by 2; on FOUT pin also divided by 10
142
   setIntClock(0, 1, 10);
143
 
144
        //Reset both counters
145
   TIM_reset(2);
146
 
147
        //Source PFI3(41); Gate PFI 4(42); Measure period
148
   TIM_timeMeasurement(C0, 0x04, 0x45, 0, 0x00, 0);
149
 
150
        //Source PFI6(45); Gate PFI 5(44); Measure pulsewidth
151
   TIM_timeMeasurement(C1, 0x87, 0x46, 1, 0x00, 0);
152
 
153
        //Arm both counter
154
   TIM_arm(2);
155
 
156
   return 0;
157
}
158
 
159
TASK show_body(int dummy)
160
{
161
   DWORD val;
162
   char buf[20];
163
 
164
   while(1){
165
      val = TIM_readHWSaveReg(C0);
166
      sprintf(buf, "%ld", val);
167
      grx_text(buf, 600, 471, rgb16(0, 255, 0), black);
168
      val = TIM_readHWSaveReg(C1);
169
      sprintf(buf, "%ld", val);
170
      grx_text(buf, 200, 471, rgb16(255, 0, 0), black);
171
 
172
      task_endcycle();
173
   }
174
}
175
 
176
TASK gate_body(int counter)
177
{
178
   BYTE out;
179
 
180
   if(counter == C0)    out = 0x80;
181
   else                 out = 0x40;
182
 
183
   while(1){
184
      DIO_write(out);
185
      if(counter == C0){
186
         if(out)  out = 0x00;
187
         else     out = 0x80;
188
      } else {
189
         if(out)  out = 0x40;
190
         else     out = 0x00;
191
      }
192
 
193
      task_endcycle();
194
   }
195
}
196
 
197
void drawInterface(void)
198
{
199
   grx_rect(1, 1, 799, 120, rgb16(105, 0, 0));
200
   grx_rect(2, 2, 798, 119, rgb16(155, 0, 0));
201
   grx_rect(3, 3, 797, 118, rgb16(205, 0, 0));
202
   grx_rect(4, 4, 796, 117, rgb16(255, 0, 0));
203
 
204
   grx_text("Test program for single period and pulsewidth measurement features",
205
            7, 10, rgb16(200, 200, 0), black);
206
 
207
   grx_text("This program measures single period and pulsewidth of a square wave",
208
            7, 20, rgb16(0, 255, 0), black);
209
   grx_text("with frequency of 0.5 Hz", 7, 28, rgb16(0, 255, 0), black);
210
   grx_text("Please connect PFI3 & PFI6 (41 & 45) to FOUT pin (50) or to 1Mhz frequency source",
211
            7, 40, rgb16(255, 0, 0), black);
212
   grx_text("Connect also DIO7 (32) to PFI4 (42) and DIO6 to PFI5 (44)",
213
            7, 48, rgb16(255, 0, 0), black);
214
   grx_text("Commands:", 7, 60, rgb16(0, 120, 0), black);
215
   grx_text("Use 'g' to start wave generation on DIO7",
216
            7, 70, rgb16(0, 255, 255), black);
217
   grx_text("Use 'h' to start wave generation on DIO6",
218
            7, 78, rgb16(0, 255, 255), black);
219
   grx_text("Use 's' to show Hardware Save Registers content",
220
            7, 86, rgb16(0, 255, 255), black);
1599 tullio 221
   grx_text("CTRL-C to exit", 7, 105, rgb16(255, 255, 0), black);
1085 pj 222
 
223
   grx_rect(197, 127, 603, 423, rgb16(0, 255, 0));
224
   grx_rect(198, 128, 602, 422, rgb16(0, 205, 0));
225
   grx_rect(199, 129, 601, 421, rgb16(0, 155, 0));
226
   grx_rect(200, 130, 600, 420, rgb16(0, 105, 0));
227
   grx_line(215, 405, 215, 150, rgb16(255, 255, 255));
228
   grx_line(210, 400, 580, 400, rgb16(255, 255, 255));
229
   grx_line(220, 395, 220, 170, rgb16(0, 0, 255));
230
   grx_line(220, 170, 390, 170, rgb16(0, 0, 255));
231
   grx_line(390, 170, 390, 395, rgb16(0, 0, 255));
232
   grx_line(390, 395, 560, 395, rgb16(0, 0, 255));
233
   grx_line(220, 150, 560, 150, rgb16(0, 255, 0));
234
   grx_line(220, 155, 390, 155, rgb16(255, 0, 0));
235
 
236
   grx_rect(1, 450, 390, 503, rgb16(105, 0, 0));
237
   grx_rect(2, 451, 389, 502, rgb16(155, 0, 0));
238
   grx_rect(3, 452, 388, 501, rgb16(205, 0, 0));
239
   grx_rect(4, 453, 387, 500, rgb16(255, 0, 0));
240
   grx_text("Pulsewidth: [us]", 7, 471, rgb16(255, 0, 0), black);
241
 
242
   grx_rect(410, 450, 799, 503, rgb16(105, 0, 0));
243
   grx_rect(411, 451, 798, 502, rgb16(155, 0, 0));
244
   grx_rect(412, 452, 797, 501, rgb16(205, 0, 0));
245
   grx_rect(413, 453, 796, 500, rgb16(255, 0, 0));
246
   grx_text("Period: [us]", 416, 471, rgb16(0, 255, 0), black);
247
}
248
 
249
void endFun(KEY_EVT *k)
250
{
1436 giacomo 251
   closeEvent(NULL);
252
 
1550 pj 253
   exit(1);
1085 pj 254
}
255
 
256
void gateEvent(KEY_EVT *k)
257
{
258
   if(k->scan == KEY_G)    task_activate(c0_gate_pid);
259
   if(k->scan == KEY_H)    task_activate(c1_gate_pid);
260
   if(k->scan == KEY_S)    task_activate(show_pid);
261
}
262
 
263
void closeEvent(void *arg)
264
{
265
   TIM_disarm(2);
266
 
267
   switch(sys){
1436 giacomo 268
      case 0:  sys_shutdown_message("OK\n"); break;
269
      case 10: sys_shutdown_message("No PCI bus found\n"); break;
270
      case 11: sys_shutdown_message("No NATIONAL board found\n"); break;
271
      case 20: sys_shutdown_message("task <show value> down!!\n"); break;
272
      case 21: sys_shutdown_message("task <C0 gate manage> down!!!\n"); break;
273
      case 22: sys_shutdown_message("task <C1 gate manage> down!!!\n"); break;
274
      case 30: sys_shutdown_message("Cannot init graphic envirorment\n"); break;
275
      case 31: sys_shutdown_message("graphic mode 800x600x16 not supported\n"); break;
276
      default: sys_shutdown_message("???????????????\n"); break;
1085 pj 277
   }
278
}