Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

ppmc_internal.c File Reference

#include "ppmc.h"
#include <stdio.h>

Include dependency graph for ppmc_internal.c:

Include dependency graph

Go to the source code of this file.

Defines

#define ppmc_base_addr   STG_BASE_ADDRESS
#define SPPDATA   ppmc_base_addr
#define STATUSPORT   ppmc_base_addr+1
#define CONTROLPORT   ppmc_base_addr+2
#define ADDRPORT   ppmc_base_addr+3
#define DATAPORT   ppmc_base_addr+4

Functions

int iopl (int level)
unsigned char inb (unsigned int port)
void outb (unsigned char byte, unsigned int port)
unsigned short inw (unsigned int port)
void outw (unsigned short word, unsigned int port)
void BusReset (void)
short InitializeParPort (void)
int ClrTimeout (void)
void SelAddr (unsigned int port)
void WriteData (unsigned char byte)
void WriteData16 (unsigned short word)
unsigned short ReadData (void)
unsigned short SelRead (unsigned int port)
void SelWrt (unsigned int port, unsigned char byte)
void SelWrt16 (unsigned int port, unsigned short word)
int ppmcMotInit (const char *stuffstuff)
int ppmcMotQuit ()

Variables

unsigned short STG_BASE_ADDRESS = DEFAULT_PPMC_BASE_ADDRESS


Define Documentation

#define ADDRPORT   ppmc_base_addr+3
 

Definition at line 174 of file ppmc_internal.c.

#define CONTROLPORT   ppmc_base_addr+2
 

Definition at line 173 of file ppmc_internal.c.

#define DATAPORT   ppmc_base_addr+4
 

Definition at line 175 of file ppmc_internal.c.

#define SPPDATA   ppmc_base_addr
 

Definition at line 171 of file ppmc_internal.c.

#define STATUSPORT   ppmc_base_addr+1
 

Definition at line 172 of file ppmc_internal.c.

#define ppmc_base_addr   STG_BASE_ADDRESS
 

Definition at line 163 of file ppmc_internal.c.


Function Documentation

void BusReset void   
 

Definition at line 179 of file ppmc_internal.c.

Referenced by ClrTimeout(), and ppmcMotInit().

00180 {
00181   outb(0,CONTROLPORT);
00182   outb(4,CONTROLPORT);
00183 }

int ClrTimeout void   
 

Definition at line 189 of file ppmc_internal.c.

Referenced by SelAddr(), SelRead(), SelWrt(), SelWrt16(), and WriteData().

00190 {
00191         unsigned char r;
00192 
00193         if  (!(inb(STATUSPORT) & 0x01))
00194                 return 0;
00195 
00196         /* To clear timeout some chips require double read */
00197         
00198         BusReset();
00199         r = inb(STATUSPORT);
00200         outb(r | 0x01, STATUSPORT); /* Some reset by writing 1 */
00201         r = inb(STATUSPORT);
00202 
00203         return !(r & 0x01);
00204 }

short int InitializeParPort void   
 

Definition at line 281 of file ppmc_internal.c.

Referenced by ppmcMotInit().

00282 {
00283 #ifdef LINUX
00284         ioperm(ppmc_base_addr,5,1) ;//turn on the 5
00285                         //if you want to run ecp, need to use iopl()
00286 #endif
00287   return 0;
00288 }

unsigned short ReadData void   
 

Definition at line 234 of file ppmc_internal.c.

00235   {
00236     //    outb(inb(CONTROLPORT) | 0x20,CONTROLPORT);  // set port direction to input
00237     outb(0x24,CONTROLPORT);  // set port direction to input
00238     return inb(DATAPORT);
00239     
00240   }

void SelAddr unsigned int    port
 

Definition at line 207 of file ppmc_internal.c.

Referenced by EncReadAll(), and ppmcDacWriteAll().

00208 {
00209   /* writes a device address to the data port and toggles address strobe low, and waits
00210                 for handshake */
00211     ClrTimeout();
00212     //    outb(inb(CONTROLPORT) & 0xDF,CONTROLPORT);  // set port direction to output
00213     outb(0x04,CONTROLPORT);  // set port direction to output
00214  
00215    outb(port,ADDRPORT);
00216     return;
00217 }

unsigned short SelRead unsigned int    port
 

Definition at line 242 of file ppmc_internal.c.

Referenced by ppmcEncoderReadLatch().

00243 {
00244   /* writes a device address to the data port and toggles address strobe low, and waits
00245                 for handshake, then inputs data byte and toggles data strobe low, then
00246                 high again */
00247     ClrTimeout();
00248     outb(inb(CONTROLPORT) & 0xDF,CONTROLPORT);  // set port direction to output
00249     outb(port,ADDRPORT);
00250     outb(inb(CONTROLPORT) | 0x20,CONTROLPORT);  // set port direction to input
00251     return inb(DATAPORT);
00252     
00253 }

void SelWrt unsigned int    port,
unsigned char    byte
 

Definition at line 255 of file ppmc_internal.c.

Referenced by DACInit(), EncoderInit(), EncoderLatch(), RawDAC(), and SelectInterruptPeriod().

00256 {
00257   /* writes a device address to the data port and toggles address strobe low, and waits
00258                 for handshake, then outputs data byte and toggles data strobe low, then
00259                 high again */
00260     ClrTimeout();
00261     //    outb(inb(CONTROLPORT) & 0xDF,CONTROLPORT);  // set port direction to output
00262     outb(0x04,CONTROLPORT);  // set port direction to output
00263     outb(port,ADDRPORT);
00264     outb(byte,DATAPORT);
00265     return;
00266 }

void SelWrt16 unsigned int    port,
unsigned short    word
 

Definition at line 267 of file ppmc_internal.c.

Referenced by RawDAC().

00268 {
00269   /* writes a device address to the data port and toggles address strobe low, and waits
00270                 for handshake, then (outputs data byte and toggles data strobe low, then
00271                 high again) repeat for 2nd byte */
00272     ClrTimeout();
00273     outb(inb(CONTROLPORT) & 0xDF,CONTROLPORT);  // set port direction to output
00274     outb(port,ADDRPORT);
00275     outb(word & 0x00FF,DATAPORT);
00276     outb(word >> 8,DATAPORT);
00277     return;
00278 }

void WriteData unsigned char    byte
 

Definition at line 219 of file ppmc_internal.c.

Referenced by EncoderInit().

00220 {
00221   /* writes data to the data port and toggles data strobe low, and waits
00222                 for handshake */
00223     outb(byte,DATAPORT);
00224         ClrTimeout();
00225     return;
00226 }

void WriteData16 unsigned short    word
 

Definition at line 227 of file ppmc_internal.c.

Referenced by ppmcDacWriteAll().

00228 {
00229   
00230     outb(word & 0x00FF,DATAPORT);
00231     outb(word >> 8,DATAPORT);
00232     return;
00233 }

unsigned char inb unsigned int    port [static]
 

Definition at line 69 of file ppmc_internal.c.

00070 {
00071   if (port >= STG_BASE_ADDRESS &&
00072       port <= STG_BASE_ADDRESS + 0x1f)
00073     {
00074       return 0;
00075     }
00076 
00077   if (port >= STG_BASE_ADDRESS + 0x400 &&
00078       port <= STG_BASE_ADDRESS + 0x400 + 0x1f)
00079     {
00080       return 0;
00081     }
00082 
00083   printf("inb: address out of bounds: %X\n", port);
00084   return 0;
00085 }

unsigned short inw unsigned int    port [static]
 

Definition at line 110 of file ppmc_internal.c.

00111 {
00112   if (port % 2)
00113     {
00114       printf("inw: alignment error: %X\n", port);
00115       return 0;
00116     }
00117 
00118   if (port >= STG_BASE_ADDRESS &&
00119       port <= STG_BASE_ADDRESS + 0x1e)
00120     {
00121       return 0;
00122     }
00123 
00124   if (port >= STG_BASE_ADDRESS + 0x400 &&
00125       port <= STG_BASE_ADDRESS + 0x400 + 0x1e)
00126     {
00127       return 0;
00128     }
00129 
00130   printf("inw: address out of bounds: %X\n", port);
00131   return 0;
00132 }

int iopl int    level [static]
 

Definition at line 64 of file ppmc_internal.c.

Referenced by ServoToGoConstructor(), main(), pptDioInit(), and stgMotInit().

00065 {
00066   return 0;
00067 }

void outb unsigned char    byte,
unsigned int    port
[static]
 

Definition at line 87 of file ppmc_internal.c.

00088 {
00089   /* allow writes to 0x80 for 1 msec delay */
00090   if (port == 0x80)
00091     {
00092       return;
00093     }
00094 
00095   if (port >= STG_BASE_ADDRESS &&
00096       port <= STG_BASE_ADDRESS + 0x1f)
00097     {
00098       return;
00099     }
00100 
00101   if (port >= STG_BASE_ADDRESS + 0x400 &&
00102       port <= STG_BASE_ADDRESS + 0x400 + 0x1f)
00103     {
00104       return;
00105     }
00106 
00107   printf("outb: address out of bounds: %X\n", port);
00108 }

void outw unsigned short    word,
unsigned int    port
[static]
 

Definition at line 134 of file ppmc_internal.c.

00135 {
00136   if (port % 2)
00137     {
00138       printf("outw: alignment error: %X\n", port);
00139       return;
00140     }
00141 
00142   if (port >= STG_BASE_ADDRESS &&
00143       port <= STG_BASE_ADDRESS + 0x1e)
00144     {
00145       return;
00146     }
00147 
00148   if (port >= STG_BASE_ADDRESS + 0x400 &&
00149       port <= STG_BASE_ADDRESS + 0x400 + 0x1e)
00150     {
00151       return;
00152     }
00153 
00154   printf("outw: address out of bounds: %X\n", port);
00155   return;
00156 }

int ppmcMotInit const char *    stuffstuff
 

Definition at line 290 of file ppmc_internal.c.

Referenced by __attribute__(), and main().

00291 {
00292         if(InitializeParPort()==-1)
00293                 return -1;
00294         BusReset();
00295         if(EncoderInit()==-1)
00296                 return -1;
00297         /*      if(DACInit()==-1)
00298                 return -1;
00299         if(DIOInit()==-1)
00300         return -1;  */
00301   return 0;
00302 
00303 }

int ppmcMotQuit  
 

Definition at line 305 of file ppmc_internal.c.

Referenced by extMotQuit().

00306 {
00307         DACQuit();
00308         EncoderQuit();
00309         DIOQuit();
00310   return 0;
00311 }


Variable Documentation

unsigned short STG_BASE_ADDRESS = DEFAULT_PPMC_BASE_ADDRESS
 

Definition at line 162 of file ppmc_internal.c.


Generated on Sun Dec 2 15:28:12 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001