您的位置:首页 > 运维架构 > Linux

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中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: