记录一些内核驱动层与用户层的数据交互,方便后续忘记查看:
下面附加应用层测试代码:
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
#include <poll.h>
#include <sys/select.h>
#include <sys/time.h>
#include <signal.h>
#include <fcntl.h>
#include<math.h>
#define cmd 2
/*
* @description : main主程序
* @param - argc : argv数组元素个数
* @param - argv : 具体参数
* @return : 0 成功;其他 失败
*/
int main(int argc, char *argv[])
{
int fd;
char *filename;
int ret = 0;
int val = 1;
if (argc != 2) {
printf("Error Usage!\r\n");
return -1;
}
fd = open(argv[1], O_RDWR); /* /dev/spidev */
if(fd < 0) {
printf("can't open file %s\r\n", filename);
return -1;
}
/******************************************************************/
// char data = 0xaa;
// char value;
// ret = write(fd,&data,1); //void cmt_spi3_send(uint8_t data8)
// ret = read(fd,&value,1); //uint8_t cmt_spi3_recv(void)
// printf("value = %x\n",value);
/*******************************************************************/
// ret = ioctl(fd, 1, 0);
// if (ret < 0) {
// perror("IOCTL command failed"); //void cmt_spi3_init(void)
// exit(1);
// }
/*****************************************************************/
// uint8_t value[2] = {0xaa,0x11};
// ret = ioctl(fd, 3, value);
// if (ret < 0) {
// perror("IOCTL command failed"); //void cmt_spi3_write(u8 addr, u8 dat)
// exit(1);
// }
/*********************************************************************/
// uint8_t data = 0xff;
// ret = ioctl(fd, 4, &data);
// if (ret < 0) {
// perror("IOCTL command failed"); //cmt_spi3_read(addr,&value);
// exit(1);
// }
// printf("data = %x\n",data);
/*********************************************************************/
/*********************************************************************/
// struct data {
// uint8_t buf[32];
// int len;
// };
// struct data value;
// value.buf[0] = 0xff;
// value.buf[1] = 0xaa;
// value.buf[2] = 0xee;
// value.buf[3] = 0x11;
// value.len = 4;
// ret = ioctl(fd, 5, &value);
// if (ret < 0) {
// perror("IOCTL command failed"); //cmt_spi3_write_fifo(buf, len);
// exit(1);
// }
/*********************************************************************/
struct data {
uint8_t buf[32];
int len;
};
int i;
struct data value;
value.len = 5;
ret = ioctl(fd, 6, &value);
if (ret < 0) {
perror("IOCTL command failed"); //cmt_spi3_read_fifo(buf, len);
exit(1);
}
// printf("%s\n",user_data);
for(i = 0;i<value.len;i++)
printf("value.buf[%d] = %x",i,value.buf[i]);
/**********************************************************************/
close(fd); /* 关闭文件 */
return 0;
}