📄 test9914_c.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 <stdio.h>
#include <linux/ioport.h>
#include <asm/types.h>
#include <sys/io.h>
#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 & ADR_MASK}, /* set card's primary GPIB address */
{RE, ADSR, PAD & 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 <-- 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 + -