E8卡 linux 系统 读写 高通 字库芯片
2017-04-18 16:57
429 查看
在E8卡上通过linux的spi驱动读写高通字库芯片。
spi是分主从的,字库芯片不会主动通过spi发送数据。只有在linux上发起读操作的时候,字库才会把他的数据发送出来。
/*
* spi mode
*/
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
printf("can't set spi mode");
ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
printf("can't get spi mode");
/*
* bits per word
*/
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
printf("can't set bits per word");
ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
printf("can't get bits per word");
/*
* max speed hz
*/
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf("can't set max speed hz");
ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf("can't get max speed hz");
printf("spi mode: %d\n", mode);
printf("bits per word: %d\n", bits);
printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
//spi 发送缓冲区
unsigned char tx[1024] = {0};
//spi 接收缓冲区
unsigned char tx2[1024] = {0};
//字库芯片读命令
tx[0] = 0x03;
//3个字节的地址数据
tx[1] = (unsigned char)((address&0xff0000)>>16);
tx[2] = (unsigned char)((address&0xff00)>>8);
tx[3] = (unsigned char)(address&0xFF);
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx, //发送缓冲区
.rx_buf = (unsigned long)tx2,// 接收缓冲区
.len = 4+buflen, //buflen 是字库数据的长度,由于在发送前4个字节时,字库芯片是不往主机发送数据。如果想读取buflen长度的字库数据,主机必须再发送长度为buflen的任意数据,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
};
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
接收到的字库数据,就在tx2中。
spi是分主从的,字库芯片不会主动通过spi发送数据。只有在linux上发起读操作的时候,字库才会把他的数据发送出来。
/*
* spi mode
*/
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
printf("can't set spi mode");
ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
printf("can't get spi mode");
/*
* bits per word
*/
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
printf("can't set bits per word");
ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
printf("can't get bits per word");
/*
* max speed hz
*/
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf("can't set max speed hz");
ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf("can't get max speed hz");
printf("spi mode: %d\n", mode);
printf("bits per word: %d\n", bits);
printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);
//spi 发送缓冲区
unsigned char tx[1024] = {0};
//spi 接收缓冲区
unsigned char tx2[1024] = {0};
//字库芯片读命令
tx[0] = 0x03;
//3个字节的地址数据
tx[1] = (unsigned char)((address&0xff0000)>>16);
tx[2] = (unsigned char)((address&0xff00)>>8);
tx[3] = (unsigned char)(address&0xFF);
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx, //发送缓冲区
.rx_buf = (unsigned long)tx2,// 接收缓冲区
.len = 4+buflen, //buflen 是字库数据的长度,由于在发送前4个字节时,字库芯片是不往主机发送数据。如果想读取buflen长度的字库数据,主机必须再发送长度为buflen的任意数据,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
};
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
接收到的字库数据,就在tx2中。
相关文章推荐
- SPI的读写GT21L字库芯片
- Linux系统如何查看及修改文件读写权限查看文件权限的语句:
- Linux系统下如何查看及修改文件读写权限
- Linux下读写芯片的I2C寄存器
- Linux下读写芯片的I2C寄存器
- Linux系统下如何查看及修改文件读写权限
- Linux 系统初始化NOR FLash芯片及驱动
- Linux下读写芯片的I2C寄存器
- Linux下文件读写操作一例(系统调用方式)
- Linux系统下如何查看及修改文件读写权限
- 移植交换芯片SDK到Linux系统
- Linux系统如何查看及修改文件读写权限(ZZ)
- Linux系统下如何查看及修改文件读写权限
- Linux下读写芯片的I2C寄存器
- Linux系统下如何查看及修改文件读写权限
- 8259A芯片中断号与linux 系统中断号的对应关系
- Linux系统下如何查看及修改文件读写权限
- DK80000针对Linux系统开发(芯片是TI公司OMP3530(cortex-A8+c64+核))
- 8259A芯片中断号与linux 系统中断号的对应关系
- Mavell 8686无线芯片在 Linux 系统移植