Subversion Repositories shark

Rev

Rev 1085 | 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_ppi.c                                                    *
3
* Author:      Marco Ziglioli (Doctor Stein)                                 *
4
* Date:        22/05/2001                                                    *
5
* Description: Test PPI82C55MSM on NI DAQ PCI6025E                           *
6
*----------------------------------------------------------------------------*
7
* Notes:       Configures port A and port C in input and port B in output    *
8
*              Test 1:                                                       *
9
*              Now connect port B to port A and watch on video value changes *
10
*              in counting order. After connect port B to port C and watch   *
11
*              the same events on port C                                     *
12
*              Test 2:                                                       *
13
*              Connect 8 LEDs on port B and port A and port C lines to Vcc or*
14
*              GND. Now run this test and watch 8 diode changing in counting *
15
*              mode and on screen port A and port C values displayed         *
16
*****************************************************************************/
17
 
18
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
19
 *
20
 * Copyright (C) 2001 Marco Ziglioli
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
 
39
 
40
#include <drivers/keyb.h>
41
#include <drivers/glib.h>
42
#include <drivers/pci6025e/dio_ppi.h>
43
 
44
void exit_fun(KEY_EVT *);
45
TASK test_ppi(int);
46
void close_event(void *);
47
void draw_screen(void);
48
 
49
BYTE system = 0;
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 PPI", test_ppi, &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
   PPI_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, 610, 130, rgb16(255, 0, 0));
112
   grx_rect(4, 4, 611, 131, rgb16(0,255,255));
113
   grx_rect(3, 3, 612, 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_rect(415, 45, 595, 100, rgb16(200, 200, 255));
117
   grx_text("Test of PPI82C55MSM function (Hosted on PCI6025E)",
118
            9, 7, rgb16(0, 255, 0), rgb16(0, 0, 0));
119
   grx_text("PORT A and PORT C are configured in input mode",
120
            9, 20, rgb16(255, 70, 70), rgb16(0, 0, 0));
121
   grx_text("PORT B is configured in output mode",
122
            9, 28, rgb16(255, 70, 70), rgb16(0, 0, 0));
123
   grx_text("PORT B (Output)", 35, 50, rgb16(200, 0, 0), rgb16(0, 0, 0));
124
   grx_text("PORT A (Input)", 235, 50, rgb16(30,255,30), rgb16(0, 0, 0));
125
   grx_text("PORT C (Input)", 435, 50, rgb16(200,200,255), rgb16(0, 0, 0));
126
   grx_text("CTRL + C to exit", 9, 115, rgb16(255,255,0), rgb16(0,0,0));
127
}
128
 
129
/*
130
* At each activation this task sends out value on port B and reads values from
131
* port A and C
132
*/
133
TASK test_ppi(int dummy)
134
{
135
   BYTE val, pA, pC;
136
   int i;
137
   char buf[10];
138
 
139
   PPI_config(0x99);    //Mode 0 for all; Port A, Port C input; Port B output
140
   val = 0;
141
   while(1){
142
      PPI_write(PPI_PORT_B, val);       //sends out value
143
      pA = PPI_read(PPI_PORT_A);        //reads from port A
144
      pC = PPI_read(PPI_PORT_C);        //reads from port C
145
 
146
      for(i=7; i>=0; i--){
147
         if( (val>>i)%2 )
148
            grx_text("1", 25+10*(7-i), 75, rgb16(255,0,0), rgb16(0,0,0));
149
         else
150
            grx_text("0", 25+10*(7-i), 75, rgb16(255,0,0), rgb16(0,0,0));
151
         if( (pA>>i)%2 )
152
            grx_text("1", 225+10*(7-i), 75, rgb16(0,255,0), rgb16(0,0,0));
153
         else
154
            grx_text("0", 225+10*(7-i), 75, rgb16(0,255,0), rgb16(0,0,0));
155
         if( (pC>>i)%2 )
156
            grx_text("1", 425+10*(7-i), 75, rgb16(200,200,255), rgb16(0,0,0));
157
         else
158
            grx_text("0", 425+10*(7-i), 75, rgb16(200,200,255), rgb16(0,0,0));
159
      }
160
      sprintf(buf, "%03d", val);
161
      grx_text(buf, 140, 75, rgb16(255,0,0), rgb16(0,0,0));
162
      sprintf(buf, "%03d", pA);
163
      grx_text(buf, 340, 75, rgb16(0,255,0), rgb16(0,0,0));
164
      sprintf(buf, "%03d", pC);
165
      grx_text(buf, 540, 75, rgb16(200,200,255), rgb16(0,0,0));
166
      val++;
167
      task_endcycle();
168
   }
169
}
170
 
171
void close_event(void *arg)
172
{
173
   grx_close();
174
   switch(system){
175
      case 0: kern_printf("Regular end\n"); break;
176
      case 10:kern_printf("Cannot create task 'TEST PPI'\n"); break;
177
      case 20:kern_printf("Pci bus don't find\n"); break;
178
      case 21:kern_printf("No National board on PC\n"); break;
179
      case 30:kern_printf("Cannot start graphic envirorment\n"); break;
180
      default: kern_printf("Unknown exit\n"); break;
181
   }
182
}
183
 
184
void exit_fun(KEY_EVT *k)
185
{
186
   system = 0;
187
   sys_end();
188
}
189
 
190
/*end of file: test_ppi.c*/