wd33c93Lib.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:9k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* wd33c93Lib.c - WD33C93 SCSI-Bus Interface Controller (SBIC) library */
  2. /* Copyright 1989-1995 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01f,02May98,sbs  changed sbicRegRead to sbicRegWrite in sbicRegWrite() 
  8.                  function (SPR #20923)
  9. 01e,06may96,jds  yet more doc tweaks
  10. 01d,01may96,jds  more doc tweaks
  11. 01c,20sep95,jdi  doc tweaks.
  12. 01b,21feb95,rhp  doc: Describe connection to wd33c93Lib1 more explicitly.
  13. 01a,10oct94,jds  written; derived from previous wd33c93Lib.h
  14. */
  15. /*
  16. DESCRIPTION
  17. This library contains the main interface routines to the Western
  18. Digital WD33C93 and WD33C93A SCSI-Bus Interface Controllers (SBIC). However,
  19. these routines simply switch the calls to either the SCSI-1 or SCSI-2
  20. drivers, implemented in wd33c93Lib1 and wd33c93Lib2 respectively, as configued
  21. by the Board Support Package (BSP). 
  22. In order to configure the SCSI-1 driver, which depends upon scsi1Lib, the 
  23. wd33c93CtrlCreate() routine, defined in wd33c93Lib1, must be invoked. Similarly,
  24. wd33c93CtrlCreateScsi2(), defined in wd33c93Lib2 and dependent on scsi2Lib, 
  25. must be called to configure and initialize the SCSI-2 driver.
  26. INCLUDE FILES
  27. wd33c93.h, wd33c93_1.h, wd33c93_2.h
  28. SEE ALSO: scsiLib, scsi1Lib, scsi2Lib, wd33c93Lib1, wd33c93Lib2,
  29. .I "Western Digital WD33C92/93 SCSI-Bus Interface Controller,"
  30. .I "Western Digital WD33C92A/93A SCSI-Bus Interface Controller,"
  31. .pG "I/O System"
  32. */
  33. #include "vxWorks.h"
  34. #include "memLib.h"
  35. #include "logLib.h"
  36. #include "scsiLib.h"
  37. #include "stdlib.h"
  38. #include "errnoLib.h"
  39. #include "stdio.h"
  40. #include "sysLib.h"
  41. #include "intLib.h"
  42. #include "tickLib.h"
  43. #include "taskLib.h"
  44. #include "msgQLib.h"
  45. /* data structures */
  46. typedef struct wd33c93functbl
  47.     {
  48.     FUNCPTR sbicCommand;
  49.     FUNCPTR sbicIntr;
  50.     FUNCPTR sbicRegRead;
  51.     FUNCPTR sbicRegWrite;
  52.     FUNCPTR sbicXferCountGet;
  53.     FUNCPTR sbicXferCountSet;
  54.     FUNCPTR wd33c93CtrlInit;
  55.     FUNCPTR wd33c93Show;
  56.     } SCSIDRV_FUNC_TBL;
  57. /* globals */
  58. SCSIDRV_FUNC_TBL *pWd33c93IfTbl;
  59. /*******************************************************************************
  60. *
  61. * wd33c93IfTblInit - create and partially initialize a WD33C93 SBIC structure
  62. *
  63. * NOMANUAL
  64. */
  65. void wd33c93IfTblInit ()
  66.     {
  67.     /* clear allocation to initialize the table */
  68.     pWd33c93IfTbl = calloc (1, sizeof (SCSIDRV_FUNC_TBL));
  69.     }
  70. /*******************************************************************************
  71. *
  72. * wd33c93CtrlInit - initialize the user-specified fields in an SBIC structure
  73. *
  74. * This routine initializes an SBIC structure, after the structure is created
  75. * with either wd33c93CtrlCreate() or wd33c93CtrlCreateScsi2().  
  76. * This structure must be initialized before the SBIC
  77. * can be used.  It may be called more than once; however, it should
  78. * be called only while there is no activity on the SCSI interface.
  79. *
  80. * Before returning, this routine pulses RST (reset) on the SCSI bus, thus
  81. * resetting all attached devices.
  82. *
  83. * The input parameters are as follows:
  84. * .iP <pSbic> 4
  85. * a pointer to the WD_33C93_SCSI_CTRL structure created with
  86. * wd33c93CtrlCreate() or wd33c93CtrlCreateScsi2().
  87. * .iP <scsiCtrlBusId>
  88. * the SCSI bus ID of the SBIC, in the range 0 - 7.  The ID is somewhat
  89. * arbitrary; the value 7, or highest priority, is conventional.
  90. * .iP <defaultSelTimeOut>
  91. * the timeout, in microseconds, for selecting a SCSI device attached to this
  92. * controller.  This value is used as a default if no timeout is specified in
  93. * scsiPhysDevCreate().  The recommended value zero (0) specifies
  94. * SCSI_DEF_SELECT_TIMEOUT (250 millisec).  The maximum timeout possible is
  95. * approximately 2 seconds.  Values exceeding this revert to the
  96. * maximum.  For more information about chip timeouts, see the manuals
  97. * .I "Western Digital WD33C92/93 SCSI-Bus Interface Controller,"
  98. * .I "Western Digital WD33C92A/93A SCSI-Bus Interface Controller."
  99. * .iP <scsiPriority>
  100. * the priority to which a task is set when performing a SCSI
  101. * transaction.  Valid priorities are 0 to 255.  Alternatively, the value -1
  102. * specifies that the priority should not be altered during SCSI transactions.
  103. *
  104. * RETURNS: OK, or ERROR if a parameter is out of range.
  105. *
  106. * SEE ALSO: scsiPhysDevCreate(),
  107. * .I "Western Digital WD33C92/93 SCSI-Bus Interface Controller,"
  108. * .I "Western Digital WD33C92A/93A SCSI-Bus Interface Controller"
  109. */
  110. STATUS wd33c93CtrlInit
  111.     (
  112.     FAST int   *pSbic,             /* ptr to SBIC info                       */
  113.     FAST int   scsiCtrlBusId,     /* SCSI bus ID of this SBIC               */
  114.     FAST UINT  defaultSelTimeOut, /* default dev. select timeout (microsec) */
  115.     int        scsiPriority       /* priority of task when doing SCSI I/O   */
  116.     )
  117.     {
  118.     if (pWd33c93IfTbl->wd33c93CtrlInit != NULL)
  119. return ((int) (pWd33c93IfTbl->wd33c93CtrlInit) (pSbic, scsiCtrlBusId,
  120.        defaultSelTimeOut, scsiPriority));
  121.     else
  122. return ((int) ERROR);
  123.     }
  124. /*******************************************************************************
  125. *
  126. * sbicXferCountSet - load the SBIC transfer counter with the specified count
  127. *
  128. * RETURNS: OK, or ERROR if <count> is not in the
  129. * range 0 - WD_33C93_MAX_BYTES_PER_XFER.
  130. *
  131. * NOMANUAL
  132. */
  133. int sbicXferCountSet
  134.     (
  135.     FAST int  *pSbic,   /* ptr to SBIC info    */
  136.     FAST UINT  count    /* count value to load */
  137.     )
  138.     {
  139.     if (pWd33c93IfTbl->sbicXferCountSet != NULL)
  140. return ((int) (pWd33c93IfTbl->sbicXferCountSet) (pSbic, count));
  141.     else
  142. return ((int) ERROR);
  143.     }
  144. /*******************************************************************************
  145. *
  146. * sbicXferCountGet - fetch the SBIC transfer count
  147. *
  148. * The value of the transfer counter is copied to *pCount.
  149. *
  150. * RETURNS: N/A.
  151. *
  152. * NOMANUAL
  153. */
  154. void sbicXferCountGet
  155.     (
  156.     FAST int  *pSbic,   /* ptr to SBIC info      */
  157.     FAST int  *pCount   /* ptr to returned value */
  158.     )
  159.     {
  160.     if (pWd33c93IfTbl->sbicXferCountGet != NULL)
  161.         (pWd33c93IfTbl->sbicXferCountGet) (pSbic, pCount);
  162.     }
  163. /*******************************************************************************
  164. *
  165. * sbicCommand - write a command code to the SBIC Command Register
  166. *
  167. * RETURNS: N/A.
  168. *
  169. * NOMANUAL
  170. */
  171. void sbicCommand
  172.     (
  173.     int  *pSbic,        /* ptr to SBIC info */
  174.     UINT8 cmdCode       /* new command code */
  175.     )
  176.     {
  177.     if (pWd33c93IfTbl->sbicCommand != NULL)
  178. (pWd33c93IfTbl->sbicCommand) (pSbic, cmdCode);
  179.     }
  180. /*******************************************************************************
  181. *
  182. * sbicIntr - interrupt service routine for the SBIC
  183. *
  184. * RETURNS: N/A.
  185. *
  186. * NOMANUAL
  187. */
  188. void sbicIntr
  189.     (
  190.     int *pSbic          /* ptr to SBIC info */
  191.     )
  192.     {
  193.     if (pWd33c93IfTbl->sbicIntr != NULL)
  194. (pWd33c93IfTbl->sbicIntr) (pSbic);
  195.     }
  196. /*******************************************************************************
  197. *
  198. * sbicRegRead - Get the contents of a specified SBIC register
  199. *
  200. * RETURNS: N/A.
  201. *
  202. * NOMANUAL
  203. */
  204. void sbicRegRead
  205.     (
  206.     int  *pSbic,         /* ptr to an SBIC structure */
  207.     UINT8 regAdrs,       /* register to read         */
  208.     int  *pDatum         /* put data here            */
  209.     )
  210.     {
  211.     if (pWd33c93IfTbl->sbicRegRead != NULL)
  212. (pWd33c93IfTbl->sbicRegRead) (pSbic, regAdrs, pDatum);
  213.     }
  214. /*******************************************************************************
  215. *
  216. * sbicRegWrite - write a value to a specified SBIC register
  217. *
  218. * RETURNS: N/A.
  219. *
  220. * NOMANUAL
  221. */
  222. void sbicRegWrite
  223.     (
  224.     int  *pSbic,         /* ptr to an SBIC structure */
  225.     UINT8 regAdrs,       /* register to write        */
  226.     UINT8 datum          /* data to write            */
  227.     )
  228.     {
  229.     if (pWd33c93IfTbl->sbicRegWrite != NULL)
  230. (pWd33c93IfTbl->sbicRegWrite) (pSbic, regAdrs, datum);
  231.     }
  232. /*******************************************************************************
  233. *
  234. * wd33c93Show - display the values of all readable WD33C93 chip registers
  235. *
  236. * This routine displays the state of the SBIC registers in a user-friendly
  237. * manner.  It is useful primarily for debugging.  It should not be invoked
  238. * while another running process is accessing the SCSI controller.
  239. *
  240. * EXAMPLE:
  241. * .CS
  242. *     -> wd33c93Show
  243. *     REG #00 (Own ID         ) = 0x07
  244. *     REG #01 (Control        ) = 0x00
  245. *     REG #02 (Timeout Period ) = 0x20
  246. *     REG #03 (Sectors        ) = 0x00
  247. *     REG #04 (Heads          ) = 0x00
  248. *     REG #05 (Cylinders MSB  ) = 0x00 
  249. *     REG #06 (Cylinders LSB  ) = 0x00
  250. *     REG #07 (Log. Addr. MSB ) = 0x00
  251. *     REG #08 (Log. Addr. 2SB ) = 0x00
  252. *     REG #09 (Log. Addr. 3SB ) = 0x00
  253. *     REG #0a (Log. Addr. LSB ) = 0x00
  254. *     REG #0b (Sector Number  ) = 0x00
  255. *     REG #0c (Head Number    ) = 0x00 
  256. *     REG #0d (Cyl. Number MSB) = 0x00
  257. *     REG #0e (Cyl. Number LSB) = 0x00
  258. *     REG #0f (Target LUN     ) = 0x00
  259. *     REG #10 (Command Phase  ) = 0x00
  260. *     REG #11 (Synch. Transfer) = 0x00
  261. *     REG #12 (Xfer Count MSB ) = 0x00
  262. *     REG #13 (Xfer Count 2SB ) = 0x00
  263. *     REG #14 (Xfer Count LSB ) = 0x00
  264. *     REG #15 (Destination ID ) = 0x03
  265. *     REG #16 (Source ID      ) = 0x00
  266. *     REG #17 (SCSI Status    ) = 0x42
  267. *     REG #18 (Command        ) = 0x07
  268. * .CE
  269. *
  270. * RETURNS: OK, or ERROR if <pScsiCtrl> and <pSysScsiCtrl> are both NULL.
  271. */
  272. int wd33c93Show
  273.     (
  274.     FAST int *pScsiCtrl   /* ptr to SCSI controller info */
  275.     )
  276.     {
  277.     if (pWd33c93IfTbl->wd33c93Show != NULL)
  278. return ((int) (pWd33c93IfTbl->wd33c93Show) (pScsiCtrl));
  279.     else
  280. return ((int) ERROR);
  281.     }