Subversion Repositories shark

Rev

Rev 1085 | 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_dio.c                                                    *
3
* Author:      Marco Ziglioli (Doctor Stein)                                 *
4
* Date:        22/03/2001                                                    *
5
* Last update: 22/03/2001                                                    *
6
* Description: Test STC digital lines (8 lines)                              *
7
*----------------------------------------------------------------------------*
8
* Notes:       Configure DIO 4 5 6 7 in input and DIO 0 1 2 3 in output      *
9
*              Two way to test this 8 lines:                                 *
10
*              1) Connect 4 LEDs to output lines and check LEDs lights       *
11
*                 themselves in counting order. Connect input lines to Vcc   *
12
*                 or GND and check on video that STC has readed the right    *
13
*                 nibble                                                     *
14
*              2) Connect 4 output lines with 4 input lines and check on     *
15
*                 video that the nibble readed by STC change in counting     *
16
*                 order                                                      *
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 <drivers/glib.h>
40
#include <drivers/keyb.h>
41
#include <drivers/pci6025e/dio_ppi.h>
42
 
43
BYTE system = 0;
44
 
45
void close_event(void *);
46
TASK test_DIO(int dummy);
47
void exit_fun(KEY_EVT *);
48
void draw_screen(void);
49
 
50
 
51
int main(int argc, char **argv)
52
{
53
   HARD_TASK_MODEL   m;
54
   KEY_EVT k;
55
   PID pid_m;
56
   int modenum;
57
 
58
   sys_atrunlevel(close_event, NULL, RUNLEVEL_BEFORE_EXIT);
59
 
60
   keyb_set_map(itaMap);
61
   k.flag = CNTL_BIT;
62
   k.scan = KEY_C;
63
   k.ascii = 'c';
64
   keyb_hook(k, exit_fun);
65
   k.flag = CNTR_BIT;
66
   k.scan = KEY_C;
67
   k.ascii = 'c';
68
   keyb_hook(k, exit_fun);
69
 
70
   hard_task_default_model(m);
71
   hard_task_def_wcet(m, 90000);
72
   hard_task_def_mit(m, 250000);
73
   pid_m = task_create("TEST DIO", test_DIO, &m, NULL);
74
   if(pid_m == NIL){
75
      system = 10;
76
      sys_end();
77
   }
78
 
79
        //Check if PCI bus is present
80
   if(pci_init() == -1){
81
      system = 20;
82
      sys_end();
83
   }
84
 
85
        //Look for a National board on PCI bus
86
   if(!reMap()){
87
      system = 21;
88
      sys_end();
89
   }
90
 
91
        //Start configuring DIO module
92
   DIO_init();
93
 
94
   grx_init();
95
   modenum = grx_getmode(640, 480, 16);
96
   if(modenum == -1){
97
      system = 30;
98
      sys_end();
99
   }
100
   grx_setmode(modenum);
101
 
102
   draw_screen();
103
 
104
   task_activate(pid_m);
105
 
106
   return 0;
107
}
108
 
109
void draw_screen(void)
110
{
111
   grx_rect(5, 5, 405, 130, rgb16(255, 0, 0));
112
   grx_rect(4, 4, 406, 131, rgb16(0,255,255));
113
   grx_rect(3, 3, 407, 132, rgb16(255, 0, 0));
114
   grx_rect(15, 45, 195, 100, rgb16(255, 0, 0));
115
   grx_rect(215, 45, 395, 100, rgb16(0, 255, 0));
116
   grx_text("Test of PCI6025E DIO function",
117
            9, 7, rgb16(0, 255, 0), rgb16(0, 0, 0));
118
   grx_text("DIO 4-5-6-7 are configured in input mode",
119
            9, 20, rgb16(255, 70, 70), rgb16(0, 0, 0));
120
   grx_text("DIO 0-1-2-3 are configured in output mode",
121
            9, 28, rgb16(255, 70, 70), rgb16(0, 0, 0));
122
   grx_text("Output bits", 35, 50, rgb16(200, 0, 0), rgb16(0, 0, 0));
123
   grx_text("input bits", 235, 50, rgb16(30,255,30), rgb16(0, 0, 0));
124
   grx_text("CTRL + C to exit", 9, 115, rgb16(255,255,0), rgb16(0,0,0));
125
}
126
 
127
/*
128
* At each activation this task change output value of lowest digitals line
129
* and read value on highest digital lines, showing them at video
130
*/
131
TASK test_DIO(int dummy)
132
{
133
   BYTE  out_val = 0x00,
134
         in_val = 0;
135
   int i;
136
   char buf[10];
137
 
138
        //DIO 0..3 configured as output
139
        //DIO 4..7 configured as input
140
   DIO_setup(0x0F);
141
 
142
   while(1){
143
      DIO_write(out_val);       //sends out value
144
      in_val = DIO_read() >> 4; //reads value
145
 
146
      for(i=3; i>=0; i--){
147
         if( (out_val>>i)%2 )
148
            grx_text("1", 25+10*(3-i), 75, rgb16(255,0,0), rgb16(0,0,0));
149
         else
150
            grx_text("0", 25+10*(3-i), 75, rgb16(255,0,0), rgb16(0,0,0));
151
         if( (in_val>>i)%2 )
152
            grx_text("1", 225+10*(3-i), 75, rgb16(0,255,0), rgb16(0,0,0));
153
         else
154
            grx_text("0", 225+10*(3-i), 75, rgb16(0,255,0), rgb16(0,0,0));
155
      }
156
      sprintf(buf, "%03d", out_val);
157
      grx_text(buf, 80, 75, rgb16(255,0,0), rgb16(0,0,0));
158
      sprintf(buf, "%03d", in_val);
159
      grx_text(buf, 280, 75, rgb16(0,255,0), rgb16(0,0,0));
160
 
161
      out_val = (out_val+1)%16;
162
      task_endcycle();
163
   }
164
}
165
 
166
void close_event(void *arg)
167
{
168
   grx_close();
169
   switch(system){
170
      case 0: kern_printf("Regular end\n"); break;
171
      case 10:kern_printf("Cannot create task TEST DIO\n"); break;
172
      case 20:kern_printf("Pci bus don't find\n"); break;
173
      case 21:kern_printf("No National board on PC\n"); break;
174
      case 30:kern_printf("Cannot start graphic envirorment\n"); break;
175
      default: kern_printf("Unknown exit\n"); break;
176
   }
177
}
178
 
179
void exit_fun(KEY_EVT *k)
180
{
181
   system = 0;
182
   sys_end();
183
}
184