Subversion Repositories shark

Rev

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_dac.c                                                   *
3
* Author:         Marco Ziglioli (Doctor Stein)                              *
4
* Date:           12/06/2001                                                 *
5
* Description:    Little test program for Analog Output section of PCI6025E  *
6
*----------------------------------------------------------------------------*
7
* Notes:          Connect a multimeter to DAC1 output (pin 21) and watch     *
8
*                 tension value. Use '+' and '-' on numeric pad to increase  *
9
*                 and decrise voltage                                        *
10
*                 With this program it's possible to point out possible      *
11
*                 offset errors. To correct them no software are written but *
12
*                 in National board package there's the program to calibrate *
13
*                 the board. Otherwise you can see how much is the offset    *
14
*                 and you can compensate it through software value           *
15
*****************************************************************************/
16
 
17
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
18
 *
19
 * Copyright (C) 2001 Marco Ziglioli
20
 *
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 *
35
 */
36
 
1436 giacomo 37
#include <kernel/kern.h>
38
 
39
#include <drivers/shark_fb26.h>
40
#include <drivers/shark_keyb26.h>
41
 
1085 pj 42
#include <drivers/pci6025e/dac.h>
43
 
44
#define  TASK_VOLT_PERIOD     150E3
45
#define  TASK_VOLT_WCET       080E3
46
#define  TASK_DAC_PERIOD      050E3
47
#define  TASK_DAC_WCET        020E3
48
 
49
#define  CONV                 10/2048
50
 
51
#define  TASK_GROUP           1
52
 
53
WORD  dac0_value = 0,
54
      dac1_value = 0;
55
 
56
BYTE  sys = 0;
57
BYTE  dac = 0;
58
 
59
//some colors
60
int   black = rgb16(0, 0, 0),
61
      white = rgb16(255, 255, 255);
62
 
63
void drawInterface(void);
64
void endfun(KEY_EVT *);
65
void inc(KEY_EVT *);
66
void dec(KEY_EVT *);
67
void change_dac(KEY_EVT *);
68
void close_event(void *);
69
TASK Voltage_body(int);
70
TASK DAC_Check_body(int);
71
 
72
int main(int argc, char **argv)
73
{
74
   KEY_EVT k;
75
   HARD_TASK_MODEL m, d;
76
   PID pid_m, pid_d;
77
 
78
   k.flag  =  CNTR_BIT;
79
   k.scan  =  KEY_X;
80
   k.ascii =  'x';
1436 giacomo 81
   k.status = KEY_PRESSED;
82
   keyb_hook(k, endfun, FALSE);
1085 pj 83
 
84
   k.flag  =  CNTL_BIT;
1436 giacomo 85
   k.status = KEY_PRESSED;
86
   keyb_hook(k, endfun, FALSE);
1085 pj 87
 
88
   k.flag  =  0;
89
   k.scan  =  78;
90
   k.ascii =  43;
1436 giacomo 91
   k.status = KEY_PRESSED;
92
   keyb_hook(k, inc, FALSE);
1085 pj 93
 
94
   k.flag  =  0;
95
   k.scan  =  74;
96
   k.ascii =  45;
1436 giacomo 97
   k.status = KEY_PRESSED;
98
   keyb_hook(k, dec, FALSE);
1085 pj 99
 
100
   k.flag  =  0;
101
   k.scan  =  KEY_V;
102
   k.ascii =  'v';
1436 giacomo 103
   k.status = KEY_PRESSED;
104
   keyb_hook(k, change_dac, FALSE);
1085 pj 105
 
106
   hard_task_default_model(m);
107
   hard_task_def_wcet(m, TASK_VOLT_WCET);
108
   hard_task_def_mit(m, TASK_VOLT_PERIOD);
109
   hard_task_def_group(m, TASK_GROUP);
110
   pid_m = task_create("Voltage", Voltage_body, &m, NULL);
111
   if(pid_m == NIL){
112
      sys = 30;
1550 pj 113
      exit(1);
1085 pj 114
   }
115
 
116
   hard_task_default_model(d);
117
   hard_task_def_wcet(d, TASK_DAC_WCET);
118
   hard_task_def_mit(d, TASK_DAC_PERIOD);
119
   hard_task_def_group(d, TASK_GROUP);
120
   pid_d = task_create("DAC Check", DAC_Check_body, &d, NULL);
121
   if(pid_d == NIL){
122
      sys = 31;
1550 pj 123
      exit(1);
1085 pj 124
   }
125
 
1436 giacomo 126
   //Check if a NI board is on PCI bus
1085 pj 127
   if(!reMap()){
128
      sys = 11;
1550 pj 129
      exit(1);
1085 pj 130
   }
131
 
132
   drawInterface();
133
 
134
   //Analog output section set up
135
   DAC_Init();
136
 
137
        /*
138
        *AI_TIMEBASE div by 2; OUT_TIMEBASE div by 2;  single DAC mode
139
        *TMRDACWR = 3 OUT_TIMEBASE period; FIFO flags polarity active low
140
        *TMRDACWR disabled; DMA PIO control = FIFO DATA interface mode
141
        *UPDATE signal timebase = AO_UPDATE pulse width
142
        *UPDATE pulsewidth = 3-3.5 OUT_TIMEBASE period
143
        *UPDATE signal polarity = HIGH Z
144
        */
145
   DAC_boardInit(0x02, 0x4000);
146
        /*
147
        *LDAC0 source = UPDATE
148
        *DAC0 update immediately
149
        *LDAC1 source = UPDATE
150
        *DAC1 update immediately
151
        */
152
   DAC_LDACSourceUpdate(0x00);
153
        //End of Analog output section setup
154
 
155
   group_activate(TASK_GROUP);
156
 
157
   return 0;
158
}
159
 
160
/*
161
* Every time operator select a new value to send to a DAc this TASK makes
162
* actions needed to perform the operation
163
*/
164
TASK Voltage_body(int dac_work)
165
{
166
   WORD old0_value, old1_value;
167
   char buf[6];
168
   float volt;
169
 
170
   old0_value = dac0_value;
171
   old1_value = dac1_value;
172
   while(1){
173
      if(dac){
174
         if(dac1_value != old1_value){
175
            DAC_output(DAC1, dac1_value);
176
            old1_value = dac1_value;
177
            sprintf(buf, "%04d", dac1_value);
178
            grx_text(buf, 70, 120, rgb16(180, 0, 0), rgb16(255,255,140));
179
            sprintf(buf, "%04x", dac1_value);
180
            grx_text(buf, 300, 120, rgb16(180, 0, 0), rgb16(255,255,140));
181
            if( (dac1_value & 0x0800) == 0 )
182
               volt = (float)dac1_value * (float)CONV;
183
            else
184
               volt = (float)(dac1_value-0x0FFF) * (float)CONV;
185
            sprintf(buf, "%05.2f", volt);
186
            grx_text(buf, 70, 177, rgb16(180, 40, 180), black);
187
         }
188
      } else {
189
         if(dac0_value != old0_value){
190
            DAC_output(DAC0, dac0_value);
191
            old0_value = dac0_value;
192
            sprintf(buf, "%04d", dac0_value);
193
            grx_text(buf, 521, 120, rgb16(180, 0, 0), rgb16(255,255,140));
194
            sprintf(buf, "%04x", dac0_value);
195
            grx_text(buf, 754, 120, rgb16(180, 0, 0), rgb16(255,255,140));
196
            if( (dac0_value & 0x0800) == 0 )
197
               volt = (float)dac0_value * (float)CONV;
198
            else
199
               volt = (float)(dac0_value-0x0FFF) * (float)CONV;
200
            sprintf(buf, "%05.2f", volt);
201
            grx_text(buf, 521, 177, rgb16(180, 40, 180), black);
202
         }
203
      }
204
      task_endcycle();
205
   }
206
}
207
 
208
/*
209
* This TASK show which is the DAC active
210
*/
211
TASK DAC_Check_body(int dummy)
212
{
213
   BYTE old = dac;
214
   char buf[8];
215
 
216
   while(1){
217
      if(dac != old){
218
         old = dac;
219
         sprintf(buf, "DAC %d", dac);
220
         grx_text(buf, 385, 90, rgb16(255*dac, 255*(1-dac), 0), black);
221
      }
222
      task_endcycle();
223
   }
224
}
225
 
226
void drawInterface(void)
227
{
228
   grx_rect(1, 1, 799, 69, rgb16(105, 0, 0));
229
   grx_rect(2, 2, 798, 68, rgb16(155, 0, 0));
230
   grx_rect(3, 3, 797, 67, rgb16(205, 0, 0));
231
   grx_rect(4, 4, 796, 66, rgb16(255, 0, 0));
232
 
233
   grx_text("Test program for Analog output section of PCI6025E",
234
            7, 10, rgb16(50, 255, 50), black);
235
   grx_text("Use '+' and '-' on numeric pad to change tension",
236
            7, 25, rgb16(0, 255, 255), black);
237
   grx_text("Connect a tester to DAC1 output (pin21) or to DAC0 output (pin20)",
238
            7, 33, rgb16(0, 255, 255), black);
239
   grx_text("Use 'v' to alternate change active DAC",
240
            7, 40, rgb16(0, 255, 255), black);
241
 
242
   grx_text("CTRL-X for Exit", 7, 55, rgb16(200, 200, 0), black);
243
 
244
   grx_rect(1, 80, 355, 150, rgb16(0, 105, 0));
245
   grx_rect(2, 81, 354, 149, rgb16(0, 155, 0));
246
   grx_rect(3, 82, 353, 148, rgb16(0, 205, 0));
247
   grx_rect(4, 83, 352, 147, rgb16(0, 255, 0));
248
 
249
   grx_rect(1, 160, 355, 199, rgb16(0, 105, 0));
250
   grx_rect(2, 161, 354, 198, rgb16(0, 155, 0));
251
   grx_rect(3, 162, 353, 197, rgb16(0, 205, 0));
252
   grx_rect(4, 163, 352, 196, rgb16(0, 255, 0));
253
 
254
   grx_rect(455, 80, 799, 150, rgb16(105, 105, 0));
255
   grx_rect(456, 81, 798, 149, rgb16(155, 155, 0));
256
   grx_rect(457, 82, 797, 148, rgb16(205, 205, 0));
257
   grx_rect(458, 83, 796, 147, rgb16(255, 255, 0));
258
 
259
   grx_rect(455, 160, 799, 199, rgb16(105, 105, 0));
260
   grx_rect(456, 161, 798, 198, rgb16(155, 155, 0));
261
   grx_rect(457, 162, 797, 197, rgb16(205, 205, 0));
262
   grx_rect(458, 163, 796, 196, rgb16(255, 255, 0));
263
 
264
   grx_rect(360, 80, 450, 105, rgb16(85, 85, 255));
265
   grx_rect(361, 81, 449, 104, rgb16(125, 125, 255));
266
   grx_rect(362, 82, 448, 103, rgb16(175, 175, 255));
267
   grx_rect(363, 83, 447, 102, rgb16(225, 225, 255));
268
 
269
   grx_rect(153, 93, 195, 103, rgb16(255, 0, 0));
270
   grx_text("DAC 1", 155, 95, rgb16(255, 170, 170), black);
271
 
272
   grx_rect(607, 93, 649, 103, rgb16(255, 0, 0));
273
   grx_text("DAC 0", 609, 95, rgb16(255, 255, 210), black);
274
 
275
   grx_text("Decimal", 7, 120, rgb16(120, 120, 255), black);
276
   grx_text("Hexadecimal", 200, 120, rgb16(120, 120, 255), black);
277
   grx_text("Tension", 7, 177, rgb16(120, 120, 255), black);
278
 
279
   grx_text("Decimal", 461, 120, rgb16(255, 120, 120), black);
280
   grx_text("Hexadecimal", 654, 120, rgb16(255, 120, 120), black);
281
   grx_text("Tension", 461, 177, rgb16(255, 120, 120), black);
282
}
283
 
284
void close_event(void *arg)
285
{
286
   switch(sys){
1436 giacomo 287
      case 0 : sys_shutdown_message("Regular End\n"); break;
288
      case 1 : sys_shutdown_message("End fun invoked\n"); break;
289
      case 10: sys_shutdown_message("Pci bus not found\n"); break;
290
      case 11: sys_shutdown_message("No National board found\n"); break;
291
      case 20: sys_shutdown_message("Cannot initialize graphic envirorment\n"); break;
292
      case 21: sys_shutdown_message("Cannot start envirorment in 800x600x16\n"); break;
293
      case 30: sys_shutdown_message("Cannot create task <voltage>\n"); break;
294
      case 31: sys_shutdown_message("Canot create task <DAC Check>\n"); break;
295
      case 40: sys_shutdown_message("Break on clock end event\n"); break;
296
      default: sys_shutdown_message("Unkwon exit event\n"); break;
1085 pj 297
   }
298
}
299
 
300
void endfun(KEY_EVT *k)
301
{
1436 giacomo 302
 
303
   close_event(NULL);
304
 
1550 pj 305
   exit(1);
1085 pj 306
}
307
 
308
/*
309
* Capture correct key event and increase output tension of active DAC
310
*/
311
void inc(KEY_EVT *k)
312
{
313
   if(dac){
314
      if( (dac1_value & 0x0800) == 0 && dac1_value > 0x07FF )
315
         dac1_value = 0;
316
      else
317
         dac1_value++;
318
   } else {
319
      if( (dac0_value & 0x0800) == 0 && dac0_value > 0x07FF )
320
         dac0_value = 0;
321
      else
322
         dac0_value++;
323
   }
324
}
325
 
326
/*
327
* Same as above but decrease tension
328
*/
329
void dec(KEY_EVT *k)
330
{
331
   if(dac){
332
      if(dac1_value < 1)
333
         dac1_value = 0x0FFF;
334
      else
335
         dac1_value -= 1;
336
   } else {
337
      if(dac0_value < 1)
338
         dac0_value = 0x0FFF;
339
      else
340
         dac0_value -= 1;
341
   }
342
}
343
 
344
/*
345
* Capture correct key event and change active DAC
346
*/
347
void change_dac(KEY_EVT *k)
348
{
349
   if(dac)  dac = 0;
350
   else     dac = 1;
351
}
352