Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1659 giacomo 1
/*==============================================================*/
2
/*  LIBRERIA DI GESTIONE DELLA SCHEDA PCL-812                   */
3
/*      Marco Caccamo, 6-2-2000                                 */
4
/*==============================================================*/
5
 
6
/*--------------------------------------------------------------*/
7
/* Register bit:    7    6    5    4    3    2    1    0        */
8
/*--------------------------------------------------------------*/
9
/* ABUFL        D7   D6   D5   D4   D3   D2   D1   D0           */
10
/* ABUFH        0    0    0   DRDY  D3   D2   D1   D0           */
11
/*--------------------------------------------------------------*/
12
/* SELEC        X    X    X    X    C3   C2   C1   C0           */
13
/*--------------------------------------------------------------*/
14
/* CTRLB        X    X    X    X    X    S2   S1   S0           */
15
/*--------------------------------------------------------------*/
16
/* TRIGG        X    X    X    X    X    X    X    TR           */
17
 
18
 
19
 
20
#include <kernel/kern.h>
21
#define BASE    0x220       /* indirizzo base     BIT       */
22
#define ABUFL   (BASE + 4)  /* low byte for AD/DA   (0 - 7) */
23
#define ABUFH   (BASE + 5)  /* high byte for AD/DA  (8 -13) */
24
#define IBUFL   (BASE + 6)  /* low byte for DIN (0 - 7)     */
25
#define IBUFH   (BASE + 7)  /* high byte for DIN    (8 -15) */
26
#define SELEC   (BASE + 10) /* select AD channel    (0 - 3) */
27
#define CTRLB   (BASE + 11) /* control register     (0 - 2) */
28
#define TRIGG   (BASE + 12) /* A/D trigger control  (0)     */
29
#define OBUFL   (BASE + 13) /* low byte for DOUT    (0 - 7) */
30
#define OBUFH   (BASE + 14) /* high byte for DOUT   (8 -15) */
31
 
32
/*--------------------------------------------------------------*/
33
/*  AD_CONV(ch)     ritorna il valore (in volt) convertito      */
34
/*          dal canale ch dell'ingresso analogico.              */
35
/*          Volt range: [-10,10], Resolution: 2.4 mV              */
36
/*--------------------------------------------------------------*/
37
 
38
float   ad_conv(int ch)         /* AD channel [0-15]        */
39
{
40
int     lb, hb;                  /* low byte, high byte [0,255]  */
41
int     n;                       /* converted value [-8192,8191] */
42
float   v;                       /* value in volt     [-10,10] */
43
 
44
    outp(SELEC, ch);     /* set AD channel   */
45
    outp(CTRLB, 1);      /* enable software trigger */
46
    outp(TRIGG, 1);      /* trigger AD converter */
47
 
48
    do {                            /* wait conversion  */
49
      hb = 0xff & inp(ABUFH); /* read high byte   */
50
    } while ((hb & 0x10) == 16);    /* loop if (bit 4 == 1) */
51
 
52
    lb = 0xff & inp(ABUFL);         /* read low byte    */
53
 
54
    n = (hb * 256 + lb); // -4096; //- 2048;     /* compose number   */
55
    //cprintf();
56
    v = (20. * (float)n ) / 4096 - 10.; //2048.;      /* convert n in volt    */
57
    return(v);
58
}
59
 
60
/*--------------------------------------------------------------*/
61
/*  DA_CONV(float v,int ch) converte in analogico il valore in volt */
62
/*  passato come parametro sul canale ch.                     */
63
/*  Volt range: [0,5], Resolution: 1.2 mV                       */
64
/*  return(-1) se non viene eseguita la conversione             */
65
/*  altrimenti return(0)                                        */
66
/*--------------------------------------------------------------*/
67
 
68
int da_conv(float v, int ch)   /* value (in volt) to convert   */
69
{
70
int lb, hb;             /* low byte, high byte  */
71
float   x;              /* value to convert */
72
 
73
 
74
 
75
    if (v  > 5 || v < 0)
76
      return(-1);
77
    else{
78
      x = ((v / 5.) * 4095.);     /* compose number   */
79
 
80
      hb = (int) x / 256;        /* compute high byte    */
81
      lb = (int) x % 256;        /* compute low byte */
82
 
83
      if(ch == 2) {
84
	outp(IBUFL, lb);          /* write lb in IBUFL    */
85
	outp(IBUFH, hb);          /* write hb in IBUFL    */
86
      }
87
      else if(ch == 1) {
88
	outp(ABUFL, lb);          /* write lb in ABUFL    */
89
	outp(ABUFH, hb);          /* write hb in ABUFH    */
90
      }
91
      else return(-1);
92
 
93
      return(0);
94
    }
95
}
96
 
97
/*--------------------------------------------------------------*/
98
/*  PAR_IN()        ritorna il valore letto sui 16 bit          */
99
/*          della porta parallela di ingresso.                  */
100
/*--------------------------------------------------------------*/
101
 
102
int par_in()
103
{
104
int lb, hb;             /* low byte, high byte  */
105
int n;                  /* value on 16 bit  */
106
 
107
    lb = 0xff & inp(IBUFL);     /* read low byte    */
108
    hb = 0xff & inp(IBUFH);     /* read high byte   */
109
 
110
    n = hb * 256 + lb;          /* compose number   */
111
    return(n);
112
}
113
 
114
/*--------------------------------------------------------------*/
115
/*  PAR_OUT(n)      scrive il valore n sui 16 bit               */
116
/*          della porta parallela di uscita.                    */
117
/*--------------------------------------------------------------*/
118
 
119
void    par_out(n)
120
int n;                  /* value to write   */
121
{
122
int lb, hb;             /* low byte, high byte  */
123
 
124
    hb = n / 256;           /* extract high byte    */
125
    lb = n % 256;           /* extract low byte */
126
 
127
    outp(OBUFL,lb);         /* write low byte   */
128
    outp(OBUFH,hb);         /* write high byte  */
129
}
130
 
131
/*--------------------------------------------------------------*/