1.驱动源文件目录:hardware/invensense/libsensors/MPLSensor.cpp
2.操作设备文件的关键部分
其中操作了四个设备文件:
mpu_int_fd = open("/dev/mpuirq", O_RDWR);
accel_fd = open("/dev/accelirq", O_RDWR);
timer_fd = open("/dev/timerirq", O_RDWR);
*sl_handle = (void*) open("/dev/mpu", O_RDWR);
SensorBase.cpp源文件目录:【 hardware/invensense/libsensors/SensorBase.cpp】
MPLSensor::MPLSensor() :
SensorBase(NULL, NULL),
mMpuAccuracy(0), mNewData(0),
mDmpStarted(false),
mMasterSensorMask(INV_ALL_SENSORS),
mLocalSensorMask(ALL_MPL_SENSORS_NP), mPollTime(-1),
mCurFifoRate(-1), mHaveGoodMpuCal(false), mHaveGoodCompassCal(false),
mUseTimerIrqAccel(false), mUsetimerIrqCompass(true),
mUseTimerirq(false), mSampleCount(0),
mEnabled(0), mPendingMask(0)
{
..........................
mpu_int_fd = open("/dev/mpuirq", O_RDWR);
if (mpu_int_fd == -1) {
ALOGE("could not open the mpu irq device node");
} else {
fcntl(mpu_int_fd, F_SETFL, O_NONBLOCK);
//ioctl(mpu_int_fd, MPUIRQ_SET_TIMEOUT, 0);
mIrqFds.add(MPUIRQ_FD, mpu_int_fd);
mPollFds[MPUIRQ_FD].fd = mpu_int_fd;
mPollFds[MPUIRQ_FD].events = POLLIN;
}
accel_fd = open("/dev/accelirq", O_RDWR);
if (accel_fd == -1) {
ALOGE("could not open the accel irq device node");
} else {
fcntl(accel_fd, F_SETFL, O_NONBLOCK);
//ioctl(accel_fd, SLAVEIRQ_SET_TIMEOUT, 0);
mIrqFds.add(ACCELIRQ_FD, accel_fd);
mPollFds[ACCELIRQ_FD].fd = accel_fd;
mPollFds[ACCELIRQ_FD].events = POLLIN;
}
timer_fd = open("/dev/timerirq", O_RDWR);
if (timer_fd == -1) {
ALOGE("could not open the timer irq device node");
} else {
fcntl(timer_fd, F_SETFL, O_NONBLOCK);
//ioctl(timer_fd, TIMERIRQ_SET_TIMEOUT, 0);
mIrqFds.add(TIMERIRQ_FD, timer_fd);
mPollFds[TIMERIRQ_FD].fd = timer_fd;
mPollFds[TIMERIRQ_FD].events = POLLIN;
}
data_fd = mpu_int_fd;
if ((accel_fd == -1) && (timer_fd != -1)) {
//no accel irq and timer available
mUseTimerIrqAccel = true;
//ALOGD("MPLSensor falling back to timerirq for accel data");
}
........................
}
mlsl_linux_mpu.c的源文件目录【hardware/invensense/mlsdk/platform/linux/mlsl_linux_mpu.c】
#define I2CDEV "/dev/mpu"
inv_error_t inv_serial_open(char const *port, void **sl_handle)
{
INVENSENSE_FUNC_START;
if (NULL == port) {
port = I2CDEV;
}
*sl_handle = (void*) open(port, O_RDWR);
if(sl_handle < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */
MPL_LOGE("inv_serial_open\n");
MPL_LOGE("I2C Error %d: Cannot open Adapter %s\n", errno, port);
return INV_ERROR_SERIAL_OPEN_ERROR;
} else {
MPL_LOGI("inv_serial_open: %s\n", port);
}
return INV_SUCCESS;
}