Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include "kernel/kern.h"
#define BASE_ADDRESS 0xDC00 // Base address of PCI card
#define MAX_SIGNAL 650 // Max output signal
int i
;
int b
;
short tempNbr1
, tempNbr2
, tempNbr3
, tempNbr4
, tempNbr5
;
int RTDAC4_open
() {
printk
("Init RT-DAC4/PCI - Base Address (%x)\n",(int)(BASE_ADDRESS
));
return 0;
}
int RTDAC4_close
() {
return 0;
}
/* Reads state information into vector buf.
Angle address: BASE_ADDRESS + 8 (16 bits)
Cart address: BASE_ADDRESS + 12 (16 bits)
*/
int RTDAC4_read_states
(char *buf
) {
for (i
=0; i
<2; i
++) {
*(buf
+ i
) = inp
(BASE_ADDRESS
+ 4 +8 + i
);
*(buf
+ 2 + i
) = inp
(BASE_ADDRESS
+ 4 + 12 + i
);
}
return 0;
}
/* Control the electric motor.
Max output when testing: 650.
Max to motor: 1023.
*/
int RTDAC4_set_motor
(const short *buff
) {
unsigned short dir
;
unsigned short brake
;
unsigned short readBack
;
if (BASE_ADDRESS
== 0)
return 0;
dir
= inp
(BASE_ADDRESS
+ 4*0x24); // ?
brake
= inp
(BASE_ADDRESS
+ 4*0x25); // ?
tempNbr1
= (short) buff
[0];
tempNbr2
= (short) buff
[1];
if(abs(tempNbr1
) <= MAX_SIGNAL
) {
outpw
(BASE_ADDRESS
+ 4*0x21, ((short) abs((int) tempNbr1
)));
readBack
= inpw
(BASE_ADDRESS
+ 4*0x21);
if (readBack
== 0)
brake
= brake
| 0x01;
else
brake
= brake
& 0xFE;
if ((short) tempNbr1
< 0)
dir
= dir
| 0x01;
else
dir
= dir
& 0xFE;
}
if(abs(tempNbr2
) <= MAX_SIGNAL
) {
outpw
(BASE_ADDRESS
+ 4*0x22, ((short) abs((int) tempNbr2
)));
readBack
= inpw
(BASE_ADDRESS
+ 4*0x22);
if (readBack
== 0)
brake
= brake
| 0x02;
else
brake
= brake
& 0xFD;
if ((short) tempNbr1
< 0)
dir
= dir
| 0x02;
else
dir
= dir
& 0xFD;
}
outpw
(BASE_ADDRESS
+ 4*0x24, dir
);
outpw
(BASE_ADDRESS
+ 4*0x25, brake
);
return 0;
}
int RTDAC4_ioctl
(unsigned int request
, unsigned long l
) {
/**
* Reset Encoders
*/
if(request
== 1) {
unsigned short aux
;
tempNbr1
= 0;
tempNbr2
= 0;
tempNbr3
= 0;
tempNbr4
= 0;
tempNbr5
= 0;
if ( BASE_ADDRESS
== 0 )
{
printk
("RTDAC4 ERROR: Reset encoders: BASE_ADDRESS = 0\n");
return -1;
}
aux
= inp
(BASE_ADDRESS
+ 4*0x05);
if( tempNbr1
== 0 ) aux
= aux
& 0x00FE;
if( tempNbr1
== 1 ) aux
= aux
| 0x0001;
if( tempNbr2
== 0 ) aux
= aux
& 0x00FD;
if( tempNbr2
== 1 ) aux
= aux
| 0x0002;
if( tempNbr3
== 0 ) aux
= aux
& 0x00FB;
if( tempNbr3
== 1 ) aux
= aux
| 0x0004;
if( tempNbr4
== 0 ) aux
= aux
& 0x00F7;
if( tempNbr4
== 1 ) aux
= aux
| 0x0008;
if( tempNbr5
== 0 ) aux
= aux
& 0x00EF;
if( tempNbr5
== 1 ) aux
= aux
| 0x0010;
outp
(BASE_ADDRESS
+ 4*0x05, aux
);
aux
= inp
(BASE_ADDRESS
+ 4*0x05);
return 0;
}
/**
* Prescaler.
*/
else if(request
== 2) {
tempNbr1
= (short) l
;
if ( BASE_ADDRESS
== 0 ) {
return -1;
}
if( ( tempNbr1
>= 0 ) && ( tempNbr1
<= 63 ) )
{
outp
(BASE_ADDRESS
+ 4*0x18, tempNbr1
);
}
return 0;
}
return 0;
}