⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ieee1284.c

📁 linux下驱动程序设计的文章
💻 C
📖 第 1 页 / 共 2 页
字号:
 /************************************************* *   nope - open source drivers for the yepp(tm)  * *************************************************/ /* Copyright (c) 2001, James McKenzie.  *                      All rights reserved  *  * By using this file, you agree to the terms and conditions set  * forth in the LICENCE file which can be found at the top level of  * the nope distribution. Neither James McKenzie nor anybody else   * warranties that it is legal to use this software - that is your  * problem.   *  * yepp is a trademark of Samsung.  *  *//* * ieee1284.c: * * Copyright (c) 2001 James McKenzie <james@fishsoup.dhs.org>, * All rights reserved. * */static char rcsid[] =  "$Id: ieee1284.c,v 1.24 2001/05/15 10:02:41 root Exp root $";/* * $Log: ieee1284.c,v $ * Revision 1.24  2001/05/15 10:02:41  root * # * * Revision 1.23  2001/05/09 10:43:21  root * # * * Revision 1.22  2001/05/07 17:42:58  root * # * * Revision 1.21  2001/05/07 17:34:10  root * # * * Revision 1.20  2001/05/07 00:08:37  root * # * * Revision 1.19  2001/05/07 00:08:12  root * # * * Revision 1.18  2001/01/07 22:36:20  root * # * * Revision 1.17  2001/01/07 22:26:43  root * # * * Revision 1.16  2001/01/07 17:34:54  root * # * * Revision 1.15  2001/01/07 15:58:09  root * # * * Revision 1.14  2001/01/07 15:14:43  root * # * * Revision 1.13  2001/01/07 03:48:47  root * # * * Revision 1.12  2001/01/06 18:11:23  root * # * * Revision 1.11  2001/01/06 16:51:57  root * # * * Revision 1.10  2001/01/05 03:41:34  root * # * * Revision 1.9  2001/01/04 22:04:57  root * # * * Revision 1.8  2001/01/04 22:01:29  root * # * * Revision 1.7  2001/01/04 15:51:12  root * # * * Revision 1.6  2001/01/04 15:51:02  root * # * * Revision 1.5  2001/01/04 13:52:31  root * # * * Revision 1.4  2001/01/04 06:07:21  root * # * * Revision 1.3  2001/01/04 04:39:27  root * # * * Revision 1.2  2001/01/04 02:57:39  root * # * */#include "project.h"#include <sys/io.h>static int base = 0x378;static int ecp = 0;#define WAITLOOP 50000#define LWAITTIME  8#define WAITTIME  4#define DIRWAIT  usleep(1000)#define DATA (base)#define ECPAFIFO (base)#define DSR (base+1)#define DCR (base+2)#define CFIFO (base+0x400)#define ECPDFIFO (base+0x400)#define TFIFO (base+0x400)#define CNFGA (base+0x400)#define CNFGB (base+0x401)#define ECR (base+0x402)#define DSR_NBUSY	0x80#define DSR_NACK	0x40#define DSR_PERROR	0x20#define DSR_SELECT	0x10#define DSR_NFAULT	0x08#define DCR_DIRECTION	0x20#define DCR_ACKINTEN	0x10#define DCR_SELECTIN	0x08#define DCR_NINIT	0x04#define DCR_AUTOFD	0x02#define DCR_STROBE	0x01#define ECR_MODE_SPP		0x00#define ECR_MODE_EPP		0x20#define ECR_MODE_SPP_FIFO	0x40#define ECR_MODE_ECP		0x60#define ECR_MODE_CONF		0xe0#define ECR_NERRINTREN		0x10#define ECR_DMAEN		0x08#define ECR_SERVICEINTR		0x04#define ECR_FULL		0x02#define ECR_EMPTY		0x01#define inv(a) ((a=='+') ? '-' :'+')static voiddo_dcr (int c, int v){  if (v & 0x20)    printf (" %cReadEn", c);  if (v & 0x10)    printf (" %cIntEn", c);  if (v & 0x08)    printf (" %cSelectIn", inv (c));  if (v & 0x04)    printf (" %cnInit", c);  if (v & 0x02)    printf (" %cnAutoFd", inv (c));  if (v & 0x01)    printf (" %cnStrobe", inv (c));}static voiddo_dcrud (int up, int down){  do_dcr ('+', up);  do_dcr ('-', down);}static voiddo_dsr (int c, int v){  if (v & 0x80)    printf (" %cBusy", inv (c));  if (v & 0x40)    printf (" %cnAck", c);  if (v & 0x20)    printf (" %cPError", c);  if (v & 0x10)    printf (" %cSelect", c);  if (v & 0x08)    printf (" %cnFault", c);}static voiddo_dsrud (int up, int down){  do_dsr ('+', up);  do_dsr ('-', down);}static voidset_dcr (int new){  static int old = 0;  int up, down;#ifdef DEBUG  up = (new ^ old) & new;  down = (new ^ old) & ~new;  printf ("DCR:  %02x (last %02x +%02x -%02x)", new, old, up, down);  do_dcrud (up, down);  printf ("\n");#endif  old = new;  outb_p (new, DCR);}static voidassert_dcr (int what){  int i = inb_p (DCR);  i |= what;  set_dcr (i);}static voiddeassert_dcr (int what){  int i = inb_p (DCR);  i &= ~what;  set_dcr (i);}static intread_dsr (void){  static int old = 0;  int new = inb_p (DSR);  int up, down;  up = (new ^ old) & new;  down = (new ^ old) & ~new;#ifdef DEBUG  printf ("DSR:  %02x (was  %02x +%02x -%02x)", new, old, up, down);  do_dsrud (up, down);  printf ("\n");#endif  old = new;  return new;}static voidwrite_data (int i){#ifdef DEBUG  printf ("DATA: W %02x\n", i);#endif  outb_p (i, DATA);}static intread_data (void){  int i = inb_p (DATA);#ifdef DEBUG  printf ("DATA: R %02x\n", i);#endif  return i;}static voidwrite_ecr (int i){#ifdef DEBUG  printf ("ECR:  W %02x\n", i);#endif  outb_p (i, ECR);}static intread_ecr (void){  int i = inb_p (ECR);#ifdef DEBUG  printf ("ECR:  R %02x\n", i);#endif  return i;}static inttimeup (int t, struct timeval *then){  struct timeval now, diff;  gettimeofday (&now, NULL);  timersub (&now, then, &diff);#ifdef DEBUG  printf ("Timeup %d.%06d of %d\n", diff.tv_sec, diff.tv_usec, t);#endif  if (diff.tv_sec >= t)    return 1;  return 0;}static intecr_wait (int t, int a, int d){  int i;  struct timeval start;#ifdef DEBUG  read_ecr ();  printf ("ECR:  Wait +%02x -%02x %02x...", a, d, inb_p (ECR));  fflush (stdout);#endif  gettimeofday (&start, NULL);  i = 0;  while ((inb_p (ECR) & a) != a)    {      if (i > WAITLOOP)        {          if (timeup (t, &start))            {#ifdef DEBUG              printf ("+Failed %02x\n", inb_p (ECR));              read_ecr ();#endif              return 0;            }          i = 0;        }      i++;    }  while ((inb_p (ECR) & d))    {      if (i > WAITLOOP)        {          if (timeup (t, &start))            {#ifdef DEBUG              printf ("-Failed %02x\n", inb_p (ECR));              read_ecr ();#endif              return 0;            }          i = 0;        }      i++;    }#ifdef DEBUG  printf ("Ok %02x\n", inb_p (ECR));  read_ecr ();#endif  return 1;}static intdsr_wait (int t, int a, int d){  struct timeval start;  int i = 0;#ifdef DEBUG  read_dsr ();  printf ("DSR:  Wait +%02x -%02x %02x...", a, d, inb_p (DSR));  fflush (stdout);#endif  gettimeofday (&start, NULL);  while ((inb_p (DSR) & a) != a)    {      if (i > WAITLOOP)        {          if (timeup (t, &start))            {#ifdef DEBUG              printf ("+Failed %02x\n", inb_p (DSR));              read_dsr ();#endif              return 0;            }          i = 0;        }      i++;    }  while ((inb_p (DSR) & d))    {      if (i > WAITLOOP)        {          if (timeup (t, &start))            {#ifdef DEBUG              printf ("-Failed %02x\n", inb_p (DSR));              read_dsr ();#endif              return 0;            }          i = 0;        }      i++;    }#ifdef DEBUG  printf ("Ok %02x\n", inb_p (DSR));  read_dsr ();#endif  return 1;}static intnot1284_setup (void){#ifdef DEBUG  printf ("NOT1284\n");#endif  deassert_dcr (DCR_AUTOFD);  assert_dcr (DCR_NINIT);  if (!dsr_wait (WAITTIME, DSR_PERROR | DSR_NFAULT, 0))    return 0;  deassert_dcr (DCR_DIRECTION);  assert_dcr (DCR_SELECTIN | DCR_NINIT);  if (!dsr_wait (WAITTIME, DSR_PERROR | DSR_NFAULT, 0))    return 0;  assert_dcr (DCR_AUTOFD);  if (!dsr_wait (WAITTIME, DSR_NACK | DSR_SELECT, DSR_PERROR))    return 0;  deassert_dcr (DCR_AUTOFD);  if (!dsr_wait (WAITTIME, DSR_NBUSY, 0))    return 0;  return 1;}static intieee1284_negsetup (int i){#ifdef DEBUG  printf ("1284_negsetup\n");#endif  write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_EPP);  write_data (i);  assert_dcr (DCR_AUTOFD);      //Autofd-  deassert_dcr (DCR_SELECTIN);  //Selectin+

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -