Subversion Repositories shark

Rev

Rev 1552 | Details | Compare with Previous | 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
 
1436 giacomo 32
#include <kernel/kern.h>
1085 pj 33
 
1436 giacomo 34
#include <drivers/shark_fb26.h>
35
#include <drivers/shark_keyb26.h>
1085 pj 36
 
1552 pj 37
#include <sem/sem/sem.h>
1085 pj 38
 
39
#include <drivers/pci6025e/dac.h>
40
 
41
#define  MAX_VAL         500
42
 
43
#define  WAVE_PERIOD    1000
44
#define  WAVE_WCET       200
45
#define  GRAPH_PERIOD   1000
46
#define  GRAPH_WCET      550
47
 
48
#define  TASK_GROUP        1
49
 
50
#define  DAC0_CONV       0.1
51
#define  DAC1_CONV      0.05
52
 
53
#define  INC              40
54
 
55
void createWaves(void);
56
void drawInterface(void);
57
 
58
void endfun(KEY_EVT *);
59
void close_event(void *);
60
 
61
TASK wave_body(int);
62
TASK video_body(int);
63
 
64
WORD wave0[MAX_VAL], wave1[MAX_VAL];
65
int black = rgb16(0,0,0),
66
    white = rgb16(255, 255, 255);
67
 
68
BYTE sys = 0;
69
 
70
int main(int argc, char **argv)
71
{
72
   KEY_EVT  k;
73
   HARD_TASK_MODEL   wave0, wave1;
74
   HARD_TASK_MODEL   video;
75
   PID               wave0_pid, wave1_pid, video_pid;
76
 
77
   k.flag  =  CNTR_BIT;
1599 tullio 78
   k.scan  =  KEY_C;
79
   k.ascii =  'c';
1436 giacomo 80
   k.status = KEY_PRESSED;
81
   keyb_hook(k, endfun, FALSE);
1085 pj 82
 
83
   k.flag  =  CNTL_BIT;
1436 giacomo 84
   k.status = KEY_PRESSED;
85
   keyb_hook(k, endfun, FALSE);
1085 pj 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;
1550 pj 94
      exit(1);
1085 pj 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;
1550 pj 104
      exit(1);
1085 pj 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;
1550 pj 114
      exit(1);
1085 pj 115
   }
116
 
117
   if(!reMap()){
118
      sys = 21;
1550 pj 119
      exit(1);
1085 pj 120
   }
121
 
122
   createWaves();
123
   drawInterface();
124
        //Analog output section set up
125
   DAC_Init();
126
 
127
        /*
128
        *AI_TIMEBASE div by 2; OUT_TIMEBASE div by 2;  single DAC mode
129
        *TMRDACWR = 3 OUT_TIMEBASE period; FIFO flags polarity active low
130
        *TMRDACWR disabled; DMA PIO control = FIFO DATA interface mode
131
        *UPDATE signal timebase = AO_UPDATE pulse width
132
        *UPDATE pulsewidth = 3-3.5 OUT_TIMEBASE period
133
        *UPDATE signal polarity = HIGH Z
134
        */
135
   DAC_boardInit(0x02, 0x4000);
136
 
137
   /*
138
        *LDAC0 source = UPDATE
139
        *DAC0 update immediately
140
        *LDAC1 source = UPDATE
141
        *DAC1 update immediately
142
        */
143
   DAC_LDACSourceUpdate(0x00);
144
        //End of Analog output section setup
145
 
146
 
147
   group_activate(TASK_GROUP);
148
 
149
   return 0;
150
}
151
 
152
void endfun(KEY_EVT *k)
153
{
1436 giacomo 154
   close_event(NULL);
155
 
1550 pj 156
   exit(1);
1085 pj 157
}
158
 
159
void close_event(void *arg)
160
{
161
   switch(sys){
1436 giacomo 162
      case 0:  sys_shutdown_message("Regular End!\n"); break;
163
      case 10: sys_shutdown_message("Cannot create <wave 0> task!\n"); break;
164
      case 11: sys_shutdown_message("Cannot create <wave 1> task!\n"); break;
165
      case 12: sys_shutdown_message("Cannot create <video> task!\n"); break;
166
      case 20: sys_shutdown_message("No PCI bus found!\n"); break;
167
      case 21: sys_shutdown_message("No NATIONAL PCI E-Series board found on PCI bus!\n");
1085 pj 168
               break;
1436 giacomo 169
      case 30: sys_shutdown_message("Cannot start graphic envirorment!\n"); break;
170
      case 31: sys_shutdown_message("800x600x16 video mode not supported!\n");
171
      default: sys_shutdown_message("Unknown exit event!\n"); break;
1085 pj 172
   }
173
}
174
 
175
/*
176
* Wave's samples generation
177
*/
178
void createWaves(void)
179
{
180
   int i;
1436 giacomo 181
   int value0, value1;
1085 pj 182
   BYTE direction;
183
 
184
   /* Wave0
185
         *  *   *  *  *  *  *  *
186
        ** **  ** ** ** ** ** **
187
       * ** * * ** ** ** ** ** *
188
      *  *  **  *  *  *  *  *  *
189
      --------------------------...
190
 
191
      Wave 1
192
         *               *
193
        * *             * *
194
       *   *           *   *
195
      *     *         *     *
196
      -------*-------*-------*--...
197
              *     *         *
198
               *   *           *
199
                * *
200
                 *                 */
201
 
202
   value0 = 0;
203
   value1 = 0;
204
   direction = 0;
205
   for(i=0; i<MAX_VAL; i++){
206
      wave0[i] = (value0 & 0x0FFF);
207
      wave1[i] = (value1 & 0x0FFF);
208
 
209
      value0 = (value0 + INC) % 2000;
210
      if(!direction)   value1 += INC;
211
      else             value1 -= INC;
212
 
213
      if(value1 >= 2000)    direction = 1;
214
      if(value1 <= -2000)   direction = 0;
215
   }
216
}
217
 
218
void drawInterface(void)
219
{
220
   int i;
221
 
222
   grx_rect(1, 1, 799, 69, rgb16(105, 0, 105));
223
   grx_rect(2, 2, 798, 68, rgb16(155, 0, 155));
224
   grx_rect(3, 3, 797, 67, rgb16(205, 0, 205));
225
   grx_rect(4, 4, 796, 66, rgb16(255, 0, 255));
226
 
227
   grx_text("Test program for Analog output section of PCI6025E",
228
            7, 10, rgb16(50, 255, 50), black);
229
   grx_text("DAC0 and DAC1 should generate saw-toothed wave and triangular wave",
230
            7, 33, rgb16(0, 255, 255), black);
231
   grx_text("Use an oscilloscope to test this software",
232
            7, 40, rgb16(0, 255, 255), black);
233
 
1599 tullio 234
   grx_text("CTRL-C for Exit", 7, 55, rgb16(200, 200, 0), black);
1085 pj 235
 
236
   grx_text("DAC 0", 100, 92, rgb16(200, 200, 0), black);
237
   grx_rect(1, 100, 799, 325, rgb16(0, 105, 0));
238
   grx_rect(2, 101, 798, 324, rgb16(0, 155, 0));
239
   grx_rect(3, 102, 797, 323, rgb16(0, 205, 0));
240
   grx_rect(4, 103, 796, 322, rgb16(0, 255, 0));
241
   grx_line(19, 115, 19, 320, white);
242
   grx_line(14, 315, 530, 315, white);
243
 
244
   grx_text("DAC 1", 100, 362, rgb16(200, 200, 0), black);
245
   grx_rect(1, 370, 799, 595, rgb16(105, 0, 0));
246
   grx_rect(2, 371, 798, 594, rgb16(155, 0, 0));
247
   grx_rect(3, 372, 797, 593, rgb16(205, 0, 0));
248
   grx_rect(4, 373, 796, 592, rgb16(255, 0, 0));
249
   grx_line(19, 385, 19, 585, white);
250
   grx_line(14, 485, 530, 485, white);
251
 
252
   for(i=22; i<530; i+=2){
253
      //DAC0
254
      grx_plot(i, 115, white);
255
      grx_plot(i, 215, white);
256
      //DAC1
257
      grx_plot(i, 385, white);
258
      grx_plot(i, 435, white);
259
      grx_plot(i, 535, white);
260
      grx_plot(i, 585, white);
261
   }
262
 
263
   grx_text("5 V", 540, 211, rgb16(0, 255, 0), black);
264
   grx_text("10 V", 540, 111, rgb16(0, 255, 0), black);
265
   grx_text("+5 V", 540, 431, rgb16(0, 255, 0), black);
266
   grx_text("+10 V", 540, 381, rgb16(0, 255, 0), black);
267
   grx_text("-5 V", 540, 531, rgb16(255, 0, 0), black);
268
   grx_text("-10 V", 540, 581, rgb16(255, 0 , 0), black);
269
}
270
 
271
/*
272
* Sends out waves' samples
273
*/
274
TASK wave_body(int wv)
275
{
276
   int i = 0;
277
   while(1){
278
      if(wv)
279
         DAC_output(DAC1, wave1[i]);
280
      else
281
         DAC_output(DAC0, wave0[i]);
282
 
283
      i = (i + 1) % 500;
284
      task_endcycle();
285
   }
286
}
287
 
288
/*
289
* Shows wave on screen
290
*/
291
TASK video_body(int dummy)
292
{
293
   int i = 0;
1436 giacomo 294
   int n_tmp = 0, o_tmp;
1085 pj 295
   //char buf[10];
296
 
297
   while(1){
298
      o_tmp = n_tmp;
299
      if( (wave1[i] & 0x0800) != 0 )   n_tmp = wave1[i]-0x0FFF;
300
      else                             n_tmp = wave1[i];
301
 
302
      if(i>0){
303
        grx_line(19+i, 314-wave0[i-1]*DAC0_CONV,
304
                 20+i, 314-wave0[i]*DAC0_CONV, rgb16(255, 255, 0));
305
        grx_line(19+i, 485-o_tmp*DAC1_CONV,
306
                 20+i, 485-n_tmp*DAC1_CONV, rgb16(0, 255, 255));
307
      }
308
 
309
      i = (i + 1) % 500;
310
      task_endcycle();
311
   }
312
}