高通平台上测试spi字符设备程序,如下:
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/ioctl.h>
#include <sys/stat.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
//定义要访问的设备文件名
static const char *device = "/dev/dev_mcu" ;
int main()
{ int i;
int fd = -1;
char val[]={0x02,0xd1,0x0a,0x00,0x01,0xc6,0x29} ;
char ret[255] ;
//打开设备文件
printf("start to open device .\n");
// udelay(1000);
fd = open(device, O_RDWR);
if(fd == -1)
{
printf("Failed to open device .\n");
return -1;
}
printf("start to open device succesful. \n");
//写入
for(i=0;i<7;i++)
printf("Write index %x value 0x%02x to %s.\n\n",i, val[i], device);
write(fd, val, sizeof(val));
//读取respone值
printf("Read ret value :\n");
for(i=0;i<9;i++){
read(fd, ret, 1);
// printf("index %d : 0x%02x.\n\n", i,ret[0]);
}
printf("read device end. \n");
close(fd);
return 0;
}
android.mk文件如下:
LOCAL_PATH := $(call my-dir)
commonSources :=
commonSharedLibraries := libc libcutils libutils
include $(CLEAR_VARS)
LOCAL_MODULE := spitest
LOCAL_SRC_FILES += $(commonSources) main.c
LOCAL_C_INCLUDES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include/
LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
LOCAL_SHARED_LIBRARIES := $(commonSharedLibraries)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/kernel-tests
LOCAL_MODULE_OWNER := qcom
include $(BUILD_EXECUTABLE)