Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*****************************************************************************
2
* Filename:       wave.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 an oscilloscope to DACs output pins (20 & 21) and  *
8
*                 watch the waveforms.                                       *
9
*                 and decrise voltage                                        *
10
*****************************************************************************/
11
 
12
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
13
 *
14
 * Copyright (C) 2001 Marco Ziglioli
15
 *
16
 * This program is free software; you can redistribute it and/or modify
17
 * it under the terms of the GNU General Public License as published by
18
 * the Free Software Foundation; either version 2 of the License, or
19
 * (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
 *
30
 */
31
 
32
 
33
 
34
#include <drivers/glib.h>
35
#include <drivers/keyb.h>
36
#include <modules/sem.h>
37
 
38
#include <drivers/pci6025e/dac.h>
39
 
40
#define  MAX_VAL         500
41
 
42
#define  WAVE_PERIOD    1000
43
#define  WAVE_WCET       200
44
#define  GRAPH_PERIOD   1000
45
#define  GRAPH_WCET      550
46
 
47
#define  TASK_GROUP        1
48
 
49
#define  DAC0_CONV       0.1
50
#define  DAC1_CONV      0.05
51
 
52
#define  INC              40
53
 
54
void createWaves(void);
55
void drawInterface(void);
56
 
57
void endfun(KEY_EVT *);
58
void close_event(void *);
59
 
60
TASK wave_body(int);
61
TASK video_body(int);
62
 
63
WORD wave0[MAX_VAL], wave1[MAX_VAL];
64
int black = rgb16(0,0,0),
65
    white = rgb16(255, 255, 255);
66
 
67
BYTE sys = 0;
68
 
69
int main(int argc, char **argv)
70
{
71
   KEY_EVT  k;
72
   HARD_TASK_MODEL   wave0, wave1;
73
   HARD_TASK_MODEL   video;
74
   PID               wave0_pid, wave1_pid, video_pid;
75
   int modenum;
76
 
77
   k.flag  =  CNTR_BIT;
78
   k.scan  =  KEY_X;
79
   k.ascii =  'x';
80
   keyb_hook(k, endfun);
81
 
82
   k.flag  =  CNTL_BIT;
83
   keyb_hook(k, endfun);
84
 
85
   sys_atrunlevel(close_event, NULL, RUNLEVEL_BEFORE_EXIT);
86
 
87
   hard_task_default_model(wave0);
88
   hard_task_def_wcet(wave0, WAVE_WCET);
89
   hard_task_def_mit(wave0, WAVE_PERIOD);
90
   hard_task_def_arg(wave0, 0);
91
   hard_task_def_group(wave0, TASK_GROUP);
92
   if( (wave0_pid = task_create("Wave 0", wave_body, &wave0, NULL)) == NIL ){
93
      sys = 10;
94
      sys_end();
95
   }
96
 
97
   hard_task_default_model(wave1);
98
   hard_task_def_wcet(wave1, WAVE_WCET);
99
   hard_task_def_mit(wave1, WAVE_PERIOD);
100
   hard_task_def_arg(wave1, (void *)1);
101
   hard_task_def_group(wave1, TASK_GROUP);
102
   if( (wave1_pid = task_create("Wave 1", wave_body, &wave1, NULL)) == NIL ){
103
      sys = 11;
104
      sys_end();
105
   }
106
 
107
   hard_task_default_model(video);
108
   hard_task_def_wcet(video, GRAPH_WCET);
109
   hard_task_def_mit(video, GRAPH_PERIOD);
110
   hard_task_def_group(video, TASK_GROUP);
111
   if( (video_pid = task_create("Video task", video_body, &video, NULL))
112
           == NIL ){
113
      sys = 12;
114
      sys_end();
115
   }
116
 
117
   if(pci_init() == -1){
118
      sys = 20;
119
      sys_end();
120
   }
121
 
122
   if(!reMap()){
123
      sys = 21;
124
      sys_end();
125
   }
126
 
127
   if(grx_init() == -1){
128
      sys = 30;
129
      sys_end();
130
   }
131
 
132
   if( (modenum = grx_getmode(800, 600, 16)) == -1 ){
133
      sys = 31;
134
      sys_end();
135
   }
136
 
137
   grx_setmode(modenum);
138
 
139
   createWaves();
140
   drawInterface();
141
        //Analog output section set up
142
   DAC_Init();
143
 
144
        /*
145
        *AI_TIMEBASE div by 2; OUT_TIMEBASE div by 2;  single DAC mode
146
        *TMRDACWR = 3 OUT_TIMEBASE period; FIFO flags polarity active low
147
        *TMRDACWR disabled; DMA PIO control = FIFO DATA interface mode
148
        *UPDATE signal timebase = AO_UPDATE pulse width
149
        *UPDATE pulsewidth = 3-3.5 OUT_TIMEBASE period
150
        *UPDATE signal polarity = HIGH Z
151
        */
152
   DAC_boardInit(0x02, 0x4000);
153
 
154
   /*
155
        *LDAC0 source = UPDATE
156
        *DAC0 update immediately
157
        *LDAC1 source = UPDATE
158
        *DAC1 update immediately
159
        */
160
   DAC_LDACSourceUpdate(0x00);
161
        //End of Analog output section setup
162
 
163
 
164
   group_activate(TASK_GROUP);
165
 
166
   return 0;
167
}
168
 
169
void endfun(KEY_EVT *k)
170
{
171
   sys_end();
172
}
173
 
174
void close_event(void *arg)
175
{
176
   grx_close();
177
   switch(sys){
178
      case 0:  cprintf("Regular End!\n"); break;
179
      case 10: cprintf("Cannot create <wave 0> task!\n"); break;
180
      case 11: cprintf("Cannot create <wave 1> task!\n"); break;
181
      case 12: cprintf("Cannot create <video> task!\n"); break;
182
      case 20: cprintf("No PCI bus found!\n"); break;
183
      case 21: cprintf("No NATIONAL PCI E-Series board found on PCI bus!\n");
184
               break;
185
      case 30: cprintf("Cannot start graphic envirorment!\n"); break;
186
      case 31: cprintf("800x600x16 video mode not supported!\n");
187
      default: cprintf("Unknown exit event!\n"); break;
188
   }
189
}
190
 
191
/*
192
* Wave's samples generation
193
*/
194
void createWaves(void)
195
{
196
   int i;
197
   WORD value0, value1;
198
   BYTE direction;
199
 
200
   /* Wave0
201
         *  *   *  *  *  *  *  *
202
        ** **  ** ** ** ** ** **
203
       * ** * * ** ** ** ** ** *
204
      *  *  **  *  *  *  *  *  *
205
      --------------------------...
206
 
207
      Wave 1
208
         *               *
209
        * *             * *
210
       *   *           *   *
211
      *     *         *     *
212
      -------*-------*-------*--...
213
              *     *         *
214
               *   *           *
215
                * *
216
                 *                 */
217
 
218
   value0 = 0;
219
   value1 = 0;
220
   direction = 0;
221
   for(i=0; i<MAX_VAL; i++){
222
      wave0[i] = (value0 & 0x0FFF);
223
      wave1[i] = (value1 & 0x0FFF);
224
 
225
      value0 = (value0 + INC) % 2000;
226
      if(!direction)   value1 += INC;
227
      else             value1 -= INC;
228
 
229
      if(value1 >= 2000)    direction = 1;
230
      if(value1 <= -2000)   direction = 0;
231
   }
232
}
233
 
234
void drawInterface(void)
235
{
236
   int i;
237
 
238
   grx_rect(1, 1, 799, 69, rgb16(105, 0, 105));
239
   grx_rect(2, 2, 798, 68, rgb16(155, 0, 155));
240
   grx_rect(3, 3, 797, 67, rgb16(205, 0, 205));
241
   grx_rect(4, 4, 796, 66, rgb16(255, 0, 255));
242
 
243
   grx_text("Test program for Analog output section of PCI6025E",
244
            7, 10, rgb16(50, 255, 50), black);
245
   grx_text("DAC0 and DAC1 should generate saw-toothed wave and triangular wave",
246
            7, 33, rgb16(0, 255, 255), black);
247
   grx_text("Use an oscilloscope to test this software",
248
            7, 40, rgb16(0, 255, 255), black);
249
 
250
   grx_text("CTRL-X for Exit", 7, 55, rgb16(200, 200, 0), black);
251
 
252
   grx_text("DAC 0", 100, 92, rgb16(200, 200, 0), black);
253
   grx_rect(1, 100, 799, 325, rgb16(0, 105, 0));
254
   grx_rect(2, 101, 798, 324, rgb16(0, 155, 0));
255
   grx_rect(3, 102, 797, 323, rgb16(0, 205, 0));
256
   grx_rect(4, 103, 796, 322, rgb16(0, 255, 0));
257
   grx_line(19, 115, 19, 320, white);
258
   grx_line(14, 315, 530, 315, white);
259
 
260
   grx_text("DAC 1", 100, 362, rgb16(200, 200, 0), black);
261
   grx_rect(1, 370, 799, 595, rgb16(105, 0, 0));
262
   grx_rect(2, 371, 798, 594, rgb16(155, 0, 0));
263
   grx_rect(3, 372, 797, 593, rgb16(205, 0, 0));
264
   grx_rect(4, 373, 796, 592, rgb16(255, 0, 0));
265
   grx_line(19, 385, 19, 585, white);
266
   grx_line(14, 485, 530, 485, white);
267
 
268
   for(i=22; i<530; i+=2){
269
      //DAC0
270
      grx_plot(i, 115, white);
271
      grx_plot(i, 215, white);
272
      //DAC1
273
      grx_plot(i, 385, white);
274
      grx_plot(i, 435, white);
275
      grx_plot(i, 535, white);
276
      grx_plot(i, 585, white);
277
   }
278
 
279
   grx_text("5 V", 540, 211, rgb16(0, 255, 0), black);
280
   grx_text("10 V", 540, 111, rgb16(0, 255, 0), black);
281
   grx_text("+5 V", 540, 431, rgb16(0, 255, 0), black);
282
   grx_text("+10 V", 540, 381, rgb16(0, 255, 0), black);
283
   grx_text("-5 V", 540, 531, rgb16(255, 0, 0), black);
284
   grx_text("-10 V", 540, 581, rgb16(255, 0 , 0), black);
285
}
286
 
287
/*
288
* Sends out waves' samples
289
*/
290
TASK wave_body(int wv)
291
{
292
   int i = 0;
293
   while(1){
294
      if(wv)
295
         DAC_output(DAC1, wave1[i]);
296
      else
297
         DAC_output(DAC0, wave0[i]);
298
 
299
      i = (i + 1) % 500;
300
      task_endcycle();
301
   }
302
}
303
 
304
/*
305
* Shows wave on screen
306
*/
307
TASK video_body(int dummy)
308
{
309
   int i = 0;
310
   int n_tmp, o_tmp;
311
   //char buf[10];
312
 
313
   while(1){
314
      o_tmp = n_tmp;
315
      if( (wave1[i] & 0x0800) != 0 )   n_tmp = wave1[i]-0x0FFF;
316
      else                             n_tmp = wave1[i];
317
 
318
      if(i>0){
319
        grx_line(19+i, 314-wave0[i-1]*DAC0_CONV,
320
                 20+i, 314-wave0[i]*DAC0_CONV, rgb16(255, 255, 0));
321
        grx_line(19+i, 485-o_tmp*DAC1_CONV,
322
                 20+i, 485-n_tmp*DAC1_CONV, rgb16(0, 255, 255));
323
      }
324
 
325
      i = (i + 1) % 500;
326
      task_endcycle();
327
   }
328
}