📄 test.c
字号:
#include <sys/ioctl.h>#include <unistd.h>#include <stdio.h>#include <fcntl.h>#define DEVICE_AAA "/dev/dsp"int fd;#define DEVICE_RESET 100 /*Control Register*/#define HPIC1stWr 0 /*Write first byte */#define HPIC2ndWr 1 /*Write second byte*/#define HPIC1stRd 2 /*Read first byte*/#define HPIC2ndRd 3 /*Read second byte*//*Data transfer with Post increment after read and preincrement before write.*/#define HPI1stWr 4 /*Write first byte */#define HPI2ndWr 5 /*Write second byte*/#define HPI1stRd 6 /*Read first byte*/#define HPI2ndRd 7 /*Read second byte*/ /*Address Register*/#define HPIA1stWr 8 /*Write first byte */#define HPIA2ndWr 9 /*Write second byte*/#define HPIA1stRd 10 /*Read first byte*/#define HPIA2ndRd 11 /*Read second byte*/ /*Data Latches*/#define HPIDL1stWr 12 /*Write first byte */#define HPIDL2ndWr 13 /*Write second byte*/#define HPIDL1stRd 14 /*Read first byte*/#define HPIDL2ndRd 15 /*Read second byte*/ void AC48xDeviceReset(){ unsigned long para; ioctl(fd,DEVICE_RESET,¶);}void AC48xDeviceWriteByte(void *AC48xPtr,unsigned long cmd,unsigned char data){ ioctl(fd,cmd,&data);}unsigned char AC48xDeviceReadByte(void *AC48xPtr,unsigned long cmd){ unsigned char data; ioctl(fd,cmd,&data); return data;}int main(){ unsigned short addr=0x1000; fd=open("/dev/dsp",O_RDWR); printf("fd=%d\n",fd); AC48xDeviceReset(); //Reset AC48xDeviceWriteByte(0,HPIA1stWr,(addr-1)>>8); //Write starting addr 0x1000 AC48xDeviceWriteByte(0,HPIA2ndWr,(addr-1) & 0xff); { unsigned short buf[256]; int i; for(i=0;i<=0xff;i++)buf[i]=(i<<8)|(0xff-i); write(fd,buf,256*sizeof(unsigned short)); } AC48xDeviceWriteByte(0,HPIA1stWr,addr>>8); AC48xDeviceWriteByte(0,HPIA2ndWr,addr & 0xff); { int i; unsigned short buf[256]; read(fd,buf,256*2); for(i=0; i<=0xff;i++)printf("%x\n",buf[i]); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -