Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*****************************************************************************
2
* Filename:    dio_ppi.c                                                     *    *
3
* Author:      Ziglioli Marco (Doctor Stein)                                 *
4
* Date:        16/03/2001                                                    *
5
* Description: Function to manage 8 digital lines provide from DAQ-STC and 24*
6
*              digital lines provide from 82C55A                             *
7
*----------------------------------------------------------------------------*
8
* Notes: No serial I/O available on DIO4 are implemented yet                 *
9
*****************************************************************************/
10
 
11
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
12
 *
13
 * Copyright (C) 2001 Marco Ziglioli
14
 *
15
 * This program is free software; you can redistribute it and/or modify
16
 * it under the terms of the GNU General Public License as published by
17
 * the Free Software Foundation; either version 2 of the License, or
18
 * (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
 *
29
 */
30
 
31
#include <drivers/pci6025e/dio_ppi.h>
32
 
33
/* PJ: Global data */
34
static BYTE  DIO_initialized;
35
static BYTE  PPI_initialized;
36
 
37
static BYTE  PL_Mask;                            //Configuration byte for DIO
38
static BYTE  PPI_A_Mask, PPI_B_Mask, PPI_C_Mask; /*configuration
39
                                                   bytes for PPI ports*/
40
 
41
static BYTE  PL_Configure;   //Will set true when DIO will be configured
42
static BYTE  PPI_Configure;   //Will set true when PPI will be configured
43
 
44
static WORD  dio_control, dio_output;
45
static BYTE  ppi_cfg_reg, ppi_port_a, ppi_port_b, ppi_port_c;
46
 
47
 
48
/*****************************************************************************
49
*  initializes digital lines                                                 *
50
*****************************************************************************/
51
void DIO_init(void)
52
{
53
   DIO_resetReg();
54
   DIO_initialized = 1;
55
}
56
 
57
/*****************************************************************************
58
*  Forces 0 all digital control lines                                        *
59
*****************************************************************************/
60
void DIO_resetReg(void)
61
{
62
   dio_control = 0x0000;
63
   dio_output  = 0x0000;
64
   DAQ_STC_Windowed_Mode_Write(DIO_CONTROL, dio_control);
65
 
66
}
67
/*****************************************************************************
68
*  Configure each 8 lines avaiable on board                                  *
69
*----------------------------------------------------------------------------*
70
*  In configuration byte:  0 stands for INPUT                                *
71
*                          1 stands for OUTPUT                               *
72
*****************************************************************************/
73
void config(BYTE cfg)
74
{
75
   if(DIO_initialized){
76
      dio_control |= cfg;
77
 
78
      DAQ_STC_Windowed_Mode_Write(DIO_CONTROL, dio_control);
79
      PL_Mask = cfg;
80
      PL_Configure = TRUE;   //Tells to world that DIO now are configured
81
   }
82
}
83
 
84
void DIO_config(BYTE cfg)
85
{
86
   config(cfg);
87
}
88
 
89
/*****************************************************************************
90
*  Reads a string made of 7 chars and returns configuration byte for DIO     *
91
*----------------------------------------------------------------------------*
92
*  String must be made of only eight chars which must be I or O to mean In   *
93
*  or Out. String starts with MSD and ends with LSD.                         *
94
*  Example: IIOOIIOO means D7 In D6 in D5 out ... D1 out D0 out              *
95
*  If most significal BYTE of value returned by function is different then 0 *
96
*  then configuration string is wrong and lowest significal byte is invalid  *
97
*****************************************************************************/
98
WORD DIO_setConfig(char *cfg)
99
{
100
   BYTE  i;
101
   WORD  config = 0x0000;
102
 
103
   for(i=0; i<8; i++){
104
      switch(cfg[i]){
105
         case 'I':
106
         case 'i':
107
            clr(config,(7-i));
108
            break;
109
         case 'O':
110
         case 'o':
111
            set(config,(7-i));
112
            break;
113
         default:
114
            set(config,16);   //Configuration string is wrong
115
            return config;
116
            break;
117
       }
118
    }
119
 
120
    return config;
121
}
122
 
123
/*****************************************************************************
124
*  Returns configuration byte for DIO lines. If most significal byte of word *
125
*  is different then 0 then DIO aren't yet configured so configuration byte  *
126
*  is invalid                                                                *
127
*****************************************************************************/
128
WORD DIO_getConfig(void)
129
{
130
   WORD config = 0x0000;
131
   if(PL_Configure == FALSE)
132
      set(config,16);
133
   else
134
      config = (WORD)PL_Mask;
135
 
136
   return config;
137
}
138
 
139
/*****************************************************************************
140
*  Read through Windowed mode values on digital lines                        *
141
*****************************************************************************/
142
BYTE DIO_read(void)
143
{
144
   WORD value;
145
   if(DIO_initialized){
146
      value = DAQ_STC_Windowed_Mode_Read(DIO_PARALLEL_INPUT);
147
      value &= 0x00FF;
148
      return (BYTE)value;
149
   }
150
   else   return 0;
151
}
152
 
153
/*****************************************************************************
154
*  Write through Windowed Mode values on digital IO lines                    *
155
*****************************************************************************/
156
BYTE DIO_write(BYTE out)
157
{
158
   if(DIO_initialized){
159
      dio_output = (out & PL_Mask);  /*Lines previously configured as Input
160
                                       are fixed to 0*/
161
      DAQ_STC_Windowed_Mode_Write(DIO_OUTPUT, dio_output);
162
      return 1;
163
   }
164
   else  return 0;
165
}
166
 
167
/*****************************************************************************
168
*  initializeds three PPI ports                                              *
169
*****************************************************************************/
170
void PPI_init(void)
171
{
172
   PPI_resetReg();
173
   PPI_initialized = 1;
174
}
175
 
176
/*****************************************************************************
177
*  Force all PPI configuration registers to 0                                *
178
*****************************************************************************/
179
void PPI_resetReg(void)
180
{
181
   ppi_cfg_reg =  0x80;
182
   ppi_port_a  =  0x00;
183
   ppi_port_b  =  0x00;
184
   ppi_port_c  =  0x00;
185
   Immediate_Writeb(PPI_CFG_REG, ppi_cfg_reg);
186
}
187
 
188
/*****************************************************************************
189
*  Setting up OKI MSM82C55A                                                  *
190
*  BYTE cfg can be write throgh this rules:                                  *
191
*     D7 -> Fixs to 1 (Chip understands in this way that you are sending a   *
192
*                       control word)                                        *
193
*     D6|                        MODE | 0 | 1 | 2 |                          *
194
*       |-> Set up port A mode   D6   | 0 | 0 | 1 | ( x=Don't care)          *
195
*     D5|                        D5   | 0 | 1 | x |                          *
196
*     D4 -> Sets direction of port A byte (0=Output; 1=Input)                *
197
*     D3 -> Sets direction of port C higher nibble (0=Output; 1=Input        *
198
*     D2 -> Sets Mode for port B (0=Mode 0; 1=Mode 1)                        *
199
*     D1 -> Sets direction of port B byte (0=Output; 1=Input)                *
200
*     D0 -> Sets direction of port C lower nibble (0=Output; 1=Input)        *
201
*----------------------------------------------------------------------------*
202
*  Examples:                                                                 *
203
*        0x80  means Mode0 PA, PB, PC in output mode                         *
204
*        0x99  means Mode0 PA, PC input mode and PB output mode              *
205
*        0x8A  means Mode0 PA, lower PC nibble in output and PB, higher PC   *
206
*                          nibble in input mode                              *
207
*****************************************************************************/
208
void PPI_config(BYTE cfg)
209
{
210
   if(PPI_initialized){
211
      //Setting up control word bit
212
      set(cfg,7);
213
      ppi_cfg_reg = cfg;
214
      Immediate_Writeb(PPI_CFG_REG, ppi_cfg_reg);
215
      PPI_A_Mask = PPI_B_Mask = PPI_C_Mask = 0;
216
 
217
      //Setting up configuration masks and enable configuration byte
218
      if(cfg&0x01)   PPI_C_Mask |= 0x0F;
219
      if(cfg&0x02)   PPI_B_Mask = 0xFF;
220
      if(cfg&0x08)   PPI_C_Mask |= 0xF0;
221
      if(cfg&0x10)   PPI_A_Mask = 0xFF;
222
      PPI_Configure = TRUE;
223
   }
224
}
225
 
226
/*****************************************************************************
227
*  WORD PPI_setConfig(BYTE PA, BYTE PA_MODE, BYTE PB, BYTE PB_MODE,          *
228
*                     BYTE HighPC, BYTE LowPC)                               *
229
*----------------------------------------------------------------------------*
230
*  This routine reads 6 arguments that describe configration for PPI and     *
231
*  return configuration byte to use with PPI_Config function.                *
232
*  Arguments have these means:                                               *
233
*  PA -> Direction of Port A (0 output, 1 input)                             *
234
*  PA_Mode -> 0 Basic Mode, 1 Strobe Input output, 2 bidirectional IOø       *
235
*  PB -> Direction of PORT B (0 output, 1 input)                             *
236
*  PB_Mode -> 0 Basic Mode, 1 Strobe IO                                      *
237
*  HighPC -> Direction of high nibble of Port C (0 output, 1 input)øø        *
238
*  LowPC -> Direction of low nibble of port C (0 output, 1 input)øø          *
239
*  If most significal byte of returned word is different than 0 than         *
240
*  configuration parameters is wrong and less significant byte is invalid    *
241
*----------------------------------------------------------------------------*
242
*  ø  Bidirectional IO is available only on port A                           *
243
*  øø Available only in mode 0 (basic IO). If other modes are selected PORT  *
244
*     C is used to perform handshake and HighPC and LowPC are ignored        *
245
*****************************************************************************/
246
WORD PPI_setConfig(BYTE PA, BYTE PA_Mode, BYTE PB, BYTE PB_Mode,
247
                   BYTE HighPC, BYTE LowPC)
248
{
249
   WORD config = 0x0000;
250
 
251
   switch(PA){
252
      case 0: clr(config,4); break;
253
      case 1: set(config,4); break;
254
      default: set(config,16); return config;
255
   }
256
 
257
   switch(PA_Mode){
258
      case 0: clr(config,5); clr(config,6); break;
259
      case 1: set(config,5); clr(config,6); break;
260
      case 2: set(config,6); break;
261
      default: set(config,16); return config;
262
   }
263
 
264
   switch(PB){
265
      case 0: clr(config,1); break;
266
      case 1: set(config,1); break;
267
      default: set(config,16); return config;
268
   }
269
 
270
   switch(PB_Mode){
271
      case 0: clr(config,2); break;
272
      case 1: set(config,2); break;
273
      default: set(config,16); return config;
274
   }
275
 
276
   switch(HighPC){
277
      case 0: clr(config,3); break;
278
      case 1: set(config,3); break;
279
      default: set(config,16); return config;
280
   }
281
 
282
   switch(HighPC){
283
      case 0: clr(config,0); break;
284
      case 1: set(config,0); break;
285
      default: set(config,16); return config;
286
   }
287
 
288
   set(config,7);    //Force meaning of control word
289
 
290
   return config;
291
}
292
 
293
/*****************************************************************************
294
*                    void PPI_getConfig(BYTE port)                           *
295
*----------------------------------------------------------------------------*
296
*  Returns configuration BYTE of specified PORT (0 = A, 1 = B, 2 = C)        *
297
*  If most significal byte of returned word is different than 0 than PPI     *
298
*  isn't yet configured and configuration low significal byte is invalid     *
299
*****************************************************************************/
300
WORD PPI_getConfig(BYTE port)
301
{
302
   WORD config = 0x00;
303
   if(PPI_Configure){
304
      switch(port){
305
         case 0: config = (WORD)PPI_A_Mask; break;
306
         case 1: config = (WORD)PPI_B_Mask; break;
307
         case 2: config = (WORD)PPI_C_Mask; break;
308
         default: set(config,16); break; //Parameter wrong
309
      }
310
   } else {
311
      set(config,16);   //Ports aren't configured
312
   }
313
 
314
   return config;
315
}
316
 
317
/*****************************************************************************
318
*  Read from specificated PPI port                                           *
319
*****************************************************************************/
320
BYTE PPI_read(BYTE off)
321
{
322
   if(PPI_initialized)     return Immediate_Readb(off);
323
   else                    return 0;
324
}
325
 
326
/*****************************************************************************
327
*  Write val into specificated PPI port                                      *
328
*****************************************************************************/
329
void PPI_write(BYTE off, BYTE val)
330
{
331
   if(PPI_initialized)  Immediate_Writeb(off, val);
332
}
333
 
334
/*****************************************************************************
335
*  Returns address of specified port (0 = A, 1 = B, 2 = C, other = CFG)      *
336
*****************************************************************************/
337
BYTE PPI_getAddress(BYTE port)
338
{
339
   switch(port){
340
      case 0:  return PPI_PORT_A;
341
      case 1:  return PPI_PORT_B;
342
      case 2:  return PPI_PORT_C;
343
      default: return PPI_CFG_REG;
344
   }
345
}
346
/*End of file: dio_ppi.c*/