Subversion Repositories shark

Rev

Rev 1550 | 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
 
1436 giacomo 39
#include <kernel/kern.h>
40
 
41
#include <drivers/shark_fb26.h>
42
#include <drivers/shark_keyb26.h>
43
 
1085 pj 44
#include <drivers/pci6025e/dio_ppi.h>
45
 
46
BYTE system = 0;
47
 
48
void close_event(void *);
49
TASK test_DIO(int dummy);
50
void exit_fun(KEY_EVT *);
51
void draw_screen(void);
52
 
53
int main(int argc, char **argv)
54
{
55
   HARD_TASK_MODEL   m;
56
   KEY_EVT k;
57
   PID pid_m;
58
 
59
   k.flag = CNTL_BIT;
60
   k.scan = KEY_C;
61
   k.ascii = 'c';
1436 giacomo 62
   k.status = KEY_PRESSED;
63
   keyb_hook(k, exit_fun, FALSE);
1085 pj 64
   k.flag = CNTR_BIT;
65
   k.scan = KEY_C;
66
   k.ascii = 'c';
1436 giacomo 67
   k.status = KEY_PRESSED;
68
   keyb_hook(k, exit_fun, FALSE);
1085 pj 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;
1550 pj 76
      exit(1);
1085 pj 77
   }
78
 
1436 giacomo 79
   //Look for a National board on PCI bus
1085 pj 80
   if(!reMap()){
81
      system = 21;
1550 pj 82
      exit(1);
1085 pj 83
   }
84
 
1436 giacomo 85
   //Start configuring DIO module
1085 pj 86
   DIO_init();
87
 
88
   draw_screen();
89
 
90
   task_activate(pid_m);
91
 
92
   return 0;
93
}
94
 
95
void draw_screen(void)
96
{
97
   grx_rect(5, 5, 405, 130, rgb16(255, 0, 0));
98
   grx_rect(4, 4, 406, 131, rgb16(0,255,255));
99
   grx_rect(3, 3, 407, 132, rgb16(255, 0, 0));
100
   grx_rect(15, 45, 195, 100, rgb16(255, 0, 0));
101
   grx_rect(215, 45, 395, 100, rgb16(0, 255, 0));
102
   grx_text("Test of PCI6025E DIO function",
103
            9, 7, rgb16(0, 255, 0), rgb16(0, 0, 0));
104
   grx_text("DIO 4-5-6-7 are configured in input mode",
105
            9, 20, rgb16(255, 70, 70), rgb16(0, 0, 0));
106
   grx_text("DIO 0-1-2-3 are configured in output mode",
107
            9, 28, rgb16(255, 70, 70), rgb16(0, 0, 0));
108
   grx_text("Output bits", 35, 50, rgb16(200, 0, 0), rgb16(0, 0, 0));
109
   grx_text("input bits", 235, 50, rgb16(30,255,30), rgb16(0, 0, 0));
110
   grx_text("CTRL + C to exit", 9, 115, rgb16(255,255,0), rgb16(0,0,0));
111
}
112
 
113
/*
114
* At each activation this task change output value of lowest digitals line
115
* and read value on highest digital lines, showing them at video
116
*/
117
TASK test_DIO(int dummy)
118
{
119
   BYTE  out_val = 0x00,
120
         in_val = 0;
121
   int i;
122
   char buf[10];
123
 
124
        //DIO 0..3 configured as output
125
        //DIO 4..7 configured as input
126
   DIO_setup(0x0F);
127
 
128
   while(1){
129
      DIO_write(out_val);       //sends out value
130
      in_val = DIO_read() >> 4; //reads value
131
 
132
      for(i=3; i>=0; i--){
133
         if( (out_val>>i)%2 )
134
            grx_text("1", 25+10*(3-i), 75, rgb16(255,0,0), rgb16(0,0,0));
135
         else
136
            grx_text("0", 25+10*(3-i), 75, rgb16(255,0,0), rgb16(0,0,0));
137
         if( (in_val>>i)%2 )
138
            grx_text("1", 225+10*(3-i), 75, rgb16(0,255,0), rgb16(0,0,0));
139
         else
140
            grx_text("0", 225+10*(3-i), 75, rgb16(0,255,0), rgb16(0,0,0));
141
      }
142
      sprintf(buf, "%03d", out_val);
143
      grx_text(buf, 80, 75, rgb16(255,0,0), rgb16(0,0,0));
144
      sprintf(buf, "%03d", in_val);
145
      grx_text(buf, 280, 75, rgb16(0,255,0), rgb16(0,0,0));
146
 
147
      out_val = (out_val+1)%16;
148
      task_endcycle();
149
   }
150
}
151
 
152
void close_event(void *arg)
153
{
154
   switch(system){
1436 giacomo 155
      case 0: sys_shutdown_message("Regular end\n"); break;
156
      case 10:sys_shutdown_message("Cannot create task TEST DIO\n"); break;
157
      case 21:sys_shutdown_message("No National board on PC\n"); break;
158
      case 30:sys_shutdown_message("Cannot start graphic envirorment\n"); break;
159
      default: sys_shutdown_message("Unknown exit\n"); break;
1085 pj 160
   }
161
}
162
 
163
void exit_fun(KEY_EVT *k)
164
{
165
   system = 0;
1436 giacomo 166
 
167
   close_event(NULL);
168
 
1550 pj 169
   exit(1);
1085 pj 170
}
171