Subversion Repositories shark

Rev

Rev 1436 | 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
 
1436 giacomo 40
#include <drivers/shark_keyb26.h>
41
#include <drivers/shark_fb26.h>
42
 
1085 pj 43
#include <drivers/pci6025e/dio_ppi.h>
44
 
45
void exit_fun(KEY_EVT *);
46
TASK test_ppi(int);
47
void close_event(void *);
48
void draw_screen(void);
49
 
50
BYTE system = 0;
51
 
52
int main(int argc, char **argv)
53
{
54
   HARD_TASK_MODEL   m;
55
   KEY_EVT k;
56
   PID pid_m;
57
 
58
   k.flag = CNTL_BIT;
59
   k.scan = KEY_C;
60
   k.ascii = 'c';
1436 giacomo 61
   k.status = KEY_PRESSED;
62
   keyb_hook(k, exit_fun, FALSE);
1085 pj 63
   k.flag = CNTR_BIT;
64
   k.scan = KEY_C;
65
   k.ascii = 'c';
1436 giacomo 66
   k.status = KEY_PRESSED;
67
   keyb_hook(k, exit_fun, FALSE);
1085 pj 68
 
69
   hard_task_default_model(m);
70
   hard_task_def_wcet(m, 90000);
71
   hard_task_def_mit(m, 250000);
72
   pid_m = task_create("TEST PPI", test_ppi, &m, NULL);
73
   if(pid_m == NIL){
74
      system = 10;
1550 pj 75
      exit(1);
1085 pj 76
   }
77
 
1436 giacomo 78
   //Look for a National board on PCI bus
1085 pj 79
   if(!reMap()){
80
      system = 21;
1550 pj 81
      exit(1);
1085 pj 82
   }
83
 
1436 giacomo 84
   //Start configuring DIO module
1085 pj 85
   PPI_init();
86
 
87
   draw_screen();
88
 
89
   task_activate(pid_m);
90
 
91
   return 0;
92
}
93
 
94
void draw_screen(void)
95
{
96
   grx_rect(5, 5, 610, 130, rgb16(255, 0, 0));
97
   grx_rect(4, 4, 611, 131, rgb16(0,255,255));
98
   grx_rect(3, 3, 612, 132, rgb16(255, 0, 0));
99
   grx_rect(15, 45, 195, 100, rgb16(255, 0, 0));
100
   grx_rect(215, 45, 395, 100, rgb16(0, 255, 0));
101
   grx_rect(415, 45, 595, 100, rgb16(200, 200, 255));
102
   grx_text("Test of PPI82C55MSM function (Hosted on PCI6025E)",
103
            9, 7, rgb16(0, 255, 0), rgb16(0, 0, 0));
104
   grx_text("PORT A and PORT C are configured in input mode",
105
            9, 20, rgb16(255, 70, 70), rgb16(0, 0, 0));
106
   grx_text("PORT B is configured in output mode",
107
            9, 28, rgb16(255, 70, 70), rgb16(0, 0, 0));
108
   grx_text("PORT B (Output)", 35, 50, rgb16(200, 0, 0), rgb16(0, 0, 0));
109
   grx_text("PORT A (Input)", 235, 50, rgb16(30,255,30), rgb16(0, 0, 0));
110
   grx_text("PORT C (Input)", 435, 50, rgb16(200,200,255), rgb16(0, 0, 0));
111
   grx_text("CTRL + C to exit", 9, 115, rgb16(255,255,0), rgb16(0,0,0));
112
}
113
 
114
/*
115
* At each activation this task sends out value on port B and reads values from
116
* port A and C
117
*/
118
TASK test_ppi(int dummy)
119
{
120
   BYTE val, pA, pC;
121
   int i;
122
   char buf[10];
123
 
124
   PPI_config(0x99);    //Mode 0 for all; Port A, Port C input; Port B output
125
   val = 0;
126
   while(1){
127
      PPI_write(PPI_PORT_B, val);       //sends out value
128
      pA = PPI_read(PPI_PORT_A);        //reads from port A
129
      pC = PPI_read(PPI_PORT_C);        //reads from port C
130
 
131
      for(i=7; i>=0; i--){
132
         if( (val>>i)%2 )
133
            grx_text("1", 25+10*(7-i), 75, rgb16(255,0,0), rgb16(0,0,0));
134
         else
135
            grx_text("0", 25+10*(7-i), 75, rgb16(255,0,0), rgb16(0,0,0));
136
         if( (pA>>i)%2 )
137
            grx_text("1", 225+10*(7-i), 75, rgb16(0,255,0), rgb16(0,0,0));
138
         else
139
            grx_text("0", 225+10*(7-i), 75, rgb16(0,255,0), rgb16(0,0,0));
140
         if( (pC>>i)%2 )
141
            grx_text("1", 425+10*(7-i), 75, rgb16(200,200,255), rgb16(0,0,0));
142
         else
143
            grx_text("0", 425+10*(7-i), 75, rgb16(200,200,255), rgb16(0,0,0));
144
      }
145
      sprintf(buf, "%03d", val);
146
      grx_text(buf, 140, 75, rgb16(255,0,0), rgb16(0,0,0));
147
      sprintf(buf, "%03d", pA);
148
      grx_text(buf, 340, 75, rgb16(0,255,0), rgb16(0,0,0));
149
      sprintf(buf, "%03d", pC);
150
      grx_text(buf, 540, 75, rgb16(200,200,255), rgb16(0,0,0));
151
      val++;
152
      task_endcycle();
153
   }
154
}
155
 
156
void close_event(void *arg)
157
{
158
   switch(system){
1436 giacomo 159
      case 0: sys_shutdown_message("Regular end\n"); break;
160
      case 10:sys_shutdown_message("Cannot create task 'TEST PPI'\n"); break;
161
      case 20:sys_shutdown_message("Pci bus don't find\n"); break;
162
      case 21:sys_shutdown_message("No National board on PC\n"); break;
163
      case 30:sys_shutdown_message("Cannot start graphic envirorment\n"); break;
164
      default: sys_shutdown_message("Unknown exit\n"); break;
1085 pj 165
   }
166
}
167
 
168
void exit_fun(KEY_EVT *k)
169
{
170
   system = 0;
1436 giacomo 171
 
172
   close_event(NULL);
173
 
1550 pj 174
   exit(1);
1085 pj 175
}
176
 
177
/*end of file: test_ppi.c*/