今天编译时一直遇到error: expected ‘;’, identifier or ‘(’ before 'int’的错误,根据提示发现是int major前面有问题,但一直找不到问题所在,直到打开mpuled.h文件时才恍然大悟,原来我是把里面union mpu的分号漏掉了,错误提示里没有说这个文件,搞了好久,希望可以给后来者点思路。
#include <linux/io.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#define SMPLRT_DIV 0x19
#define CONFIG 0x1A
#define GYRO_CONFIG 0x1B
#define ACCEL_CONFIG 0x1C
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48
#define PWR_MGMT_1 0x6B
#include "mpuled.h"
int major = 11;
int minor = 0;
int dev_count = 1;
struct mychar_dev{
struct cdev mydev;
atomic_t v;
struct i2c_client *client;
};
mpuled.h文件
#ifndef MPU
#define MPU
struct accel {
unsigned short x;
unsigned short y;
unsigned short z;
};
struct gyro {
unsigned short x;
unsigned short y;
unsigned short z;
};
union mpu {
struct accel accel_data;
struct gyro gyro_data;
unsigned short temp_data;
}
#define TYPE 'g'
#define MPU_GET_ACCEL _IOR(TYPE,0,union mpu)
#define MPU_GET_GYRO _IOR(TYPE,1,union mpu)
#define MPU_GET_TEMP _IOR(TYPE,2,union mpu)
#endif