Subversion Repositories shark

Rev

Rev 1655 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1655 giacomo 1
#include "kernel/kern.h"
2
 
3
#define BASE_ADDRESS 0xDC00      // Base address of PCI card
4
#define MAX_SIGNAL 650           // Max output signal
5
 
6
int i;
7
int b;
8
short tempNbr1, tempNbr2, tempNbr3, tempNbr4, tempNbr5;
9
 
10
int RTDAC4_open() {
11
 
12
     printk("Init RT-DAC4/PCI - Base Address (%x)\n",(int)(BASE_ADDRESS));
13
 
14
     return 0;
15
}
16
 
17
int RTDAC4_close() {
18
 
19
    return 0;
20
}
21
 
22
/* Reads state information into vector buf.
23
   Angle address: BASE_ADDRESS + 8   (16 bits)
24
   Cart address:  BASE_ADDRESS + 12  (16 bits)
25
*/
26
int RTDAC4_read_states(char *buf) {
27
        for (i=0; i<2; i++) {
28
                *(buf + i) = inp(BASE_ADDRESS + 4 +8 + i);  
29
                *(buf + 2 + i) = inp(BASE_ADDRESS + 4 + 12 + i);
30
        }
31
        return 0;
32
}
33
 
34
/* Control the electric motor.
35
   Max output when testing: 650.
36
   Max to motor:            1023.
37
*/
38
int RTDAC4_set_motor(const short *buff) {
39
 
40
    unsigned short dir;
41
    unsigned short brake;
42
    unsigned short readBack;
43
 
44
    if (BASE_ADDRESS == 0)
45
        return 0;
46
 
47
    dir   = inp(BASE_ADDRESS + 4*0x24); // ?
48
    brake = inp(BASE_ADDRESS + 4*0x25); // ?    
49
 
50
    tempNbr1 = (short) buff[0];
51
    tempNbr2 = (short) buff[1];
52
 
53
    if(abs(tempNbr1) <= MAX_SIGNAL) {
54
        outpw(BASE_ADDRESS + 4*0x21, ((short) abs((int) tempNbr1)));
55
        readBack = inpw(BASE_ADDRESS + 4*0x21);
56
        if (readBack == 0)
57
            brake = brake | 0x01;
58
        else
59
            brake = brake & 0xFE;
60
        if ((short) tempNbr1 < 0)
61
            dir = dir | 0x01;
62
        else
63
            dir = dir & 0xFE;
64
    }
65
 
66
    if(abs(tempNbr2) <= MAX_SIGNAL) {
67
        outpw(BASE_ADDRESS + 4*0x22, ((short) abs((int) tempNbr2)));
68
        readBack = inpw(BASE_ADDRESS + 4*0x22);
69
        if (readBack == 0)
70
            brake = brake | 0x02;
71
        else
72
            brake = brake & 0xFD;
73
        if ((short) tempNbr1 < 0)
74
            dir = dir | 0x02;
75
        else
76
            dir = dir & 0xFD;
77
    }
78
 
79
    outpw(BASE_ADDRESS + 4*0x24, dir);
80
    outpw(BASE_ADDRESS + 4*0x25, brake);
81
 
82
    return 0;
83
}
84
 
85
int RTDAC4_ioctl(unsigned int request, unsigned long l) {
86
 
87
        /**
88
         * Reset Encoders
89
         */
90
        if(request == 1) {
91
            unsigned short aux;
92
 
93
                tempNbr1 = 0;
94
                tempNbr2 = 0;
95
                tempNbr3 = 0;
96
                tempNbr4 = 0;
97
                tempNbr5 = 0;
98
 
99
                if ( BASE_ADDRESS == 0 )  
100
                {
101
                        printk("RTDAC4 ERROR: Reset encoders: BASE_ADDRESS = 0\n");
102
                        return -1;
103
                }
104
 
105
                aux = inp(BASE_ADDRESS + 4*0x05);
106
                if( tempNbr1 == 0 )  aux = aux & 0x00FE;
107
                if( tempNbr1 == 1 )  aux = aux | 0x0001;
108
                if( tempNbr2 == 0 )  aux = aux & 0x00FD;
109
                if( tempNbr2 == 1 )  aux = aux | 0x0002;
110
                if( tempNbr3 == 0 )  aux = aux & 0x00FB;
111
                if( tempNbr3 == 1 )  aux = aux | 0x0004;
112
                if( tempNbr4 == 0 )  aux = aux & 0x00F7;
113
                if( tempNbr4 == 1 )  aux = aux | 0x0008;
114
                if( tempNbr5 == 0 )  aux = aux & 0x00EF;
115
                if( tempNbr5 == 1 )  aux = aux | 0x0010;
116
 
117
                outp(BASE_ADDRESS + 4*0x05, aux);
118
 
119
                aux = inp(BASE_ADDRESS + 4*0x05);
120
 
121
                return 0;
122
        }
123
 
124
        /**
125
         * Prescaler.
126
         */
127
        else if(request == 2) {
128
                tempNbr1 = (short) l;
129
 
130
                if ( BASE_ADDRESS == 0 )  {
131
                        return -1;
132
                }
133
 
134
                if( ( tempNbr1 >= 0 ) && ( tempNbr1 <= 63 ) )
135
                {
136
                        outp(BASE_ADDRESS + 4*0x18, tempNbr1);
137
                }
138
                return 0;
139
        }
140
        return 0;
141
}
142