您的位置:首页 > 其它

如何在 kernel 和 hal 层读取同一个标志

2016-02-20 16:19 260 查看
很多时候我们需要从 HAL 层(Hardware Abstract Layer)传一个标志给 kernel 层。一般这种传递是不能直接通过定义全局变量来实现的。

此时可以通过读写文件来实现该标志。

譬如我们有这样一个需求,在录像过程中去掉持续对焦功能,而录像预览时开启持续对焦功能。

在 HAL 层中有开始录像和停止录像的接口。

/trunk/ALPS.JB3.TDD.MP.V2_TD_xxx/mediatek/platform/mt6572/hardware/camera/hal/client/CamClient/Record/RecordClient.cpp 文件中

在 /sys/devices/platform/lens_actuator/ 目录下创建一个 VideoRec_Flag 这样的文件,在开始录像时将该文件中写入一个字节的值为1,而在停止录像时将该文件中写入一个字节的值为0。

bool
RecordClient::
startRecording()
{
bool ret = false;
//
MY_LOGD("+");
//
Mutex::Autolock _l(mModuleMtx);
//
#if 1
int flag[1]= {1};

FILE *fd = NULL;
fd = fopen("/sys/devices/platform/lens_actuator/VideoRec_Flag","w");

if(fd == NULL)
MY_LOGD("BBN_TestMode open failed");
else{
MY_LOGD("BBN_TestMode open ok");
fwrite(&flag,1,1,fd);
fclose(fd);
}
#endif

if(isEnabledState())
{
MY_LOGE("Recording has been started");
goto lbExit;
}
//
MY_LOGD("+ current mIsRecStarted=%d", mIsRecStarted);
::android_atomic_write(1, &mIsRecStarted);
//
mpParamsMgr->getVideoSize(&mi4RecWidth, &mi4RecHeight);
MY_LOGD("+ record: WxH=%dx%d, format(%s)", mi4RecWidth, mi4RecHeight, MtkCameraParameters::PIXEL_FORMAT_YUV420I);//CameraParameters::PIXEL_FORMAT_YUV420P);
//
mTimeStart = systemTime();
mTimeEnd = mTimeStart;
mFrameCount = 0;
mLastTimeStamp = 0;
//
ret = onStateChanged();
//
lbExit:
//
MY_LOGD("-");
//
return  ret;
}

/******************************************************************************
*
******************************************************************************/
bool
RecordClient::
stopRecording()
{
bool ret = false;
status_t status = NO_ERROR;
//
MY_LOGD("+");
//
#if 1
int flag[1]= {0};

FILE *fd = NULL;
fd = fopen("/sys/devices/platform/lens_actuator/VideoRec_Flag","w");

if(fd == NULL)
MY_LOGD("BBN_TestMode open failed");
else{
MY_LOGD("BBN_TestMode open ok");
fwrite(&flag,1,1,fd);
fclose(fd);
}
#endif

Mutex::Autolock _l(mModuleMtx);
//
if(!isEnabledState())
{
MY_LOGE("Recording has been stopped");
goto lbExit;
}
//
MY_LOGD("getThreadId(%d), getStrongCount(%d), this(%p)", getThreadId(), getStrongCount(), this);
//
MY_LOGD("+ current mIsRecStarted=%d", mIsRecStarted);
::android_atomic_write(0, &mIsRecStarted);
//
ret = onStateChanged();
//
mpImgBufQueue->pauseProcessor();
//
lbExit:
//
MY_LOGD("-");
//
return  ret;
}


在/trunk/ALPS.JB3.TDD.MP.V2_TD_xxx/mediatek/custom/common/kernel/imgsensor/ov5645_mipi_yuv/ov5645mipiyuv_Sensor.c 文件中

在 OV5645_FOCUS_OVT_AFC_Constant_Focus() 函数中读取之前VideoRec_Flag那个文件中的值,若为1,则进行持续对焦,否则,放弃持续对焦。在驱动文件中是通过写寄存器来实现的。

static void OV5645_FOCUS_OVT_AFC_Constant_Focus(void)
{
printk("FM50AF_VideoRec_Flag=%d \n",FM50AF_VideoRec_Flag);

if(FM50AF_VideoRec_Flag)
{
OV5645MIPI_write_cmos_sensor(0x3023,0x01);
OV5645MIPI_write_cmos_sensor(0x3022,0x06);
}
else{
OV5645MIPI_write_cmos_sensor(0x3023,0x01);
OV5645MIPI_write_cmos_sensor(0x3022,0x80);
mDELAY(10);
OV5645MIPI_write_cmos_sensor(0x3024,0x00);
OV5645MIPI_write_cmos_sensor(0x3023,0x01);
OV5645MIPI_write_cmos_sensor(0x3022,0x04);
}
}


具体的读取方式如下:

int FM50AF_VideoRec_Flag;

EXPORT_SYMBOL(FM50AF_VideoRec_Flag);

static ssize_t show_VideoRec_Flag(struct device *dev,struct device_attribute *attr, char *buf)
{
//  xlog_printk(ANDROID_LOG_DEBUG, "show_VideoRec_Flag test", "[Battery] show_BN_TestMode : %x\n", g_BN_TestMode);

printk("show_VideoRec_Flag FM50AF_VideoRec_Flag=%d \n",FM50AF_VideoRec_Flag);
return sprintf(buf, "%u\n", FM50AF_VideoRec_Flag);

}
static ssize_t store_VideoRec_Flag(struct device *dev,struct device_attribute *attr, const char *buf, size_t size)
{
char *pvalue = NULL;
unsigned int reg_BN_TestMode = 0;
printk( "store_VideoRec_Flag \n");
if(buf != NULL && size != 0)
{
printk("store_VideoRec_Flag test111", "[Battery] buf is =%s , size is =%d \n",buf,size);
printk("store_VideoRec_Flag buf= %d ,size=%d \n", *buf,size);
//  reg_BN_TestMode = simple_strtoul(buf,&pvalue,10);
FM50AF_VideoRec_Flag=*buf;
}
//  return size;
return FM50AF_VideoRec_Flag;
}
static DEVICE_ATTR(VideoRec_Flag, 0777, show_VideoRec_Flag, store_VideoRec_Flag);


这其中涉及到一些驱动文件中读写文件的格式的写法需要注意下。

至此,就可以实现该需求了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: