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

📄 test9914_c.htm

📁 9914芯片寄存器测试源文件,自检芯片使用
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0050)http://www.physics.brocku.ca/~edik/gpib/test9914.c -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2769" name=GENERATOR></HEAD>
<BODY><PRE>#include &lt;stdio.h&gt;
#include &lt;linux/ioport.h&gt;
#include &lt;asm/types.h&gt;
#include &lt;sys/io.h&gt;
#include "registers.h"

#define	BASE	0x240
#define	PAD	0
			/* read access */
#define     ISR0	BASE	/* interrupt status 0	*/
#define     ISR1	BASE+1	/* interrupt status 1	*/
#define     ADSR	BASE+2	/* adress status	*/
#define     BSR		BASE+3	/* bus-status		*/
#define     HPIBSR	BASE+4	/* hpib-status		*/
#define     UNUSEDR	BASE+5	/* unused for reading 	*/
#define     CPTR	BASE+6	/* command pass thru	*/
#define     DIR		BASE+7	/* data in register	*/

#define	WR	1
#define RE	2

static char *act[] = { "", "WRITE", "READ " };

typedef struct {
  int	action;
  unsigned short int	reg;
  unsigned char		data;
  } CHECKLIST;

CHECKLIST t1[] = {
	/* test 1 : set and check PAD */
  {WR, AUXCR, AUX_CS},		/* enable reset state */
  {WR, IMR0,  0x00},		/* clear imr0 */
  {RE, ISR0,  0x00},		/* by reading */
  {WR, IMR1,  0x00},		/* clear imr1 */
  {RE, ISR1,  0x00},		/* by reading */
  {WR, ADR,   PAD &amp; ADR_MASK},	/* set card's primary GPIB address */
  {RE, ADSR,  PAD &amp; ADR_MASK},	/* check card's primary GPIB address */
  {WR, ADR,   ADR_EDPA | ADR_DAT | ADR_DAL},	/* disable secondary address */
  {WR, AUXCR, 0x00},		/* clear reset state */
  {RE, DIR,   0x00},
  {WR, AUXCR, AUX_HLDA | AUX_CS},	/* holdoff on all data */
	/* test 2 : try to write out some data, by talking and hearing it back */
  {WR, AUXCR, AUX_CS},	/* reset chip */
  {WR, AUXCR, 0x00},
  {WR, IMR0,  0x00},		/* clear imr0 */
  {RE, ISR0,  0x00},		/* by reading */
  {WR, IMR1,  0x00},		/* clear imr1 */
  {RE, ISR1,  0x00},		/* by reading */
  {WR, AUXCR, AUX_TON | AUX_CS},/* set to talker */
  {WR, CDOR,  0x55},		/* assert some data */
  {RE, CPTR,  0x55},		/* hear it on the line */
  {WR, ADR,   ADR_DAT},		/* disable talking */
  {RE, CPTR,  0x00},		/* make sure it is not talking */
  {WR, ADR,   0x00},		/* clear disable talking, i.e. enable talking */
	/* test 3 : check DIR by listening for silence */
  {WR, AUXCR, AUX_CS},		/* reset chip */
  {WR, AUXCR, 0x00},
  {WR, IMR0,  0x00},		/* clear imr0 */
  {RE, ISR0,  0x00},		/* by reading */
  {WR, IMR1,  0x00},		/* clear imr1 */
  {RE, ISR1,  0x00},		/* by reading */
  {WR, AUXCR, AUX_LON | AUX_CS},/* listener on */
  {RE, DIR,   0x00},		/* read in 00 */
  {0}
  };

int main()
{
  int	err = 0, i = 0, j;
  unsigned char	byte;

  err = ioperm(BASE, 8, 1);
  if (err) {
    printf("cannot access %#04x, are you root?\n",BASE);
    exit(1);
    }

  printf("Test started.\n");

  while ((j=t1[i].action) != 0) {
    printf("%02d: %s, 0x%04x, 0x%02x", i, act[j], t1[i].reg, t1[i].data);

    if(t1[i].action == RE) {
	byte = inb(t1[i].reg);
	if (byte != t1[i].data) { 
	  err = 1;
          printf(" != 0x%02x &lt;-- error\n", byte);
	  }
	else
          printf(" ok\n");
	}
 
    if(t1[i].action == WR) {
	outb(t1[i].data,t1[i].reg);
        printf("\n");
	}

    i++;
    }

  if (err) 
    printf("Test failed.\n");
  else
    printf("Test succeeded.\n");

  exit(err);

}
</PRE></BODY></HTML>

⌨️ 快捷键说明

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