现在看驱动就看那几个接口函数即可,现在先看初始化函数。
- DWORD CIS_Init(DWORD dwContext)
- {
- DWORD dwErr = ERROR_SUCCESS, bytes;
- RETAILMSG(MSG_EN_1, (TEXT("CIS::CIS_Init() /r/n")));
- // Allocate for our main data structure and one of it's fields.
- pCIS = (PCIS_CONTEXT)LocalAlloc( LPTR, sizeof(CIS_CONTEXT) );
- if ( !pCIS )
- return( NULL );
- pCIS->Sig = CIS_SIG;
- // 1. Virtual Alloc
- Virtual_Alloc();
- RETAILMSG(MSG_EN_1, (TEXT("CIS::Virtual_Alloc /r/n")));
- //RETAILMSG(1, (TEXT("CIS_Init : IOCTL_HAL_REQUEST_SYSINTR /r/n")));
- //这里动态申请Camera接口的中断
- if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &g_CamIrq, sizeof(UINT32), &g_CamSysIntr, sizeof(UINT32), NULL))
- {
- RETAILMSG(1, (TEXT("ERROR: CIS_INIT: Failed to request sysintr value for Camera interrupt./r/n")));
- return(0);
- }
- InitializeCriticalSection(&pCIS->RegCS);
- //MSG_EN_1控制是否打印,这里MSG_EN_1是0故没有打印出来
- RETAILMSG(MSG_EN_1, (TEXT("CIS::InitializeCriticalSection /r/n")));
- //
- // Init I2C
- //这里让我大开眼界,在驱动中调用另外一个驱动,并且方法完全和应用程序相同
- pCIS->hI2C = CreateFile( L"I2C0:",
- GENERIC_READ|GENERIC_WRITE,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, 0, 0);
- if ( INVALID_HANDLE_VALUE == pCIS->hI2C ) {
- dwErr = GetLastError();//这个查错函数也比较有意思
- //DEBUGMSG(ZONE_ERR, (TEXT("Error %d opening device '%s' /r/n"), dwErr, L"I2C0:" ));
- RETAILMSG(I2C_MSG, (TEXT("Error %d opening device '%s' /r/n"), dwErr, L"I2C0:" ));
- goto _error_exit;
- }
- RETAILMSG(MSG_EN_1, (TEXT("CIS::CreateFile(/"I2C0/") /r/n")));
- //memset((void*)pCIS->eg, 0, sizeof(pCIS->eg));
- //
- // Gat Fastcall driver-to-driver entrypoints
- //
- if ( !DeviceIoControl(pCIS->hI2C,
- IOCTL_I2C_GET_FASTCALL, //IOCTL_I2C_GET_FASTCALL是在IIC驱动里面的
- NULL, 0,
- &pCIS->fc, sizeof(pCIS->fc),
- &bytes, NULL) )
- {
- dwErr = GetLastError();
- DEBUGMSG(ZONE_ERR,(TEXT("IOCTL_I2C_GET_FASTCALL ERROR: %u /r/n"), dwErr));
- goto _error_exit;
- }
- RETAILMSG(MSG_EN_1, (TEXT("CIS::DeviceIoControl /r/n")));
- // Init H/W
- pCIS->State = INITIALIZE;
- Cam_Init();//这是摄像头读取注册表的一些信息,并初始化,我现在暂时不看这部分。
- if (!InitInterruptThread())//这个用来初始化Camera中断线程
- {
- RETAILMSG(1,(TEXT("Fail to initialize camera interrupt event/r/n")));
- return FALSE;
- }
- pCIS->Dx = D0;
- m_Dx = (_CEDEVICE_POWER_STATE)D0;
- DevicePowerNotify(_T("CIS1:"),(_CEDEVICE_POWER_STATE)D0, POWER_NAME);
- mInitialized = TRUE;
- return TRUE;
- _error_exit:
- return dwErr;
- }
DeviceIoControl到底是怎么和驱动联系起来的呢?
我发现在IIC驱动中有如下代码
// OUT: PI2C_FASTCALL
#define IOCTL_I2C_GET_FASTCALL /
CTL_CODE(FILE_DEVICE_I2C, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
还有,在I2C_IOControl中有
case IOCTL_I2C_GET_FASTCALL:
if ( (dwLenOut < sizeof(I2C_FASTCALL)) || !pBufOut ) {
bRc = FALSE;
dwErr = ERROR_INVALID_PARAMETER;
break;
}
现在来看看CTL_CODE(FILE_DEVICE_I2C, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)到底是什么意思
这个是个微软的函数
This macro creates a unique system I/O control code (IOCTL).
#define CTL_CODE(, , , ) ( (() << 16) | (() << 14) | (() << 2) | () )
现在暂时不理会先。继续往下看。
InitInterruptThread
- //这个是5.0动态中断线程,见过很多了,就不注释了。
- BOOL InitInterruptThread()
- {
- DWORD threadID; // thread ID
- BOOL bSuccess;
- CameraEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (!CameraEvent)
- {
- return FALSE;
- }
- bSuccess = InterruptInitialize(g_CamSysIntr, CameraEvent, NULL, 0);
- if (!bSuccess)
- {
- RETAILMSG(1,(TEXT("Fail to initialize camera interrupt event/r/n")));
- return FALSE;
- }
- CameraThread = CreateThread(NULL,
- 0,
- (LPTHREAD_START_ROUTINE)CameraCaptureThread,
- 0,
- 0,
- &threadID);
- if (NULL == CameraThread ) {
- RETAILMSG(1,(TEXT("Create Camera Thread Fail/r/n")));
- }
- RETAILMSG(1,(_T("CAMERA.DLL::InterruptThread Initialized./r/n")));
- return TRUE;
- }
再往下看
CameraCaptureThread
- DWORD CameraCaptureThread(void)
- {
- unsigned char tmp=0;
- static unsigned int time,old_time;
- static unsigned int cam_intr;
- DWORD dwCause; // LJY PWR040613
- //dwDisplayTimeout = INFINITE;
- SetProcPermissions((DWORD)-1);
- while(TRUE)
- {
- RETAILMSG(0,(TEXT("[CAM_HW] InterruptThread : Waiting For a Single Object/n/r")));
- //一般查询dwDisplayTimeout是一个时间常数,中断是INFINITE,在这里是个
- dwCause = WaitForSingleObject(CameraEvent, dwDisplayTimeout);
- RETAILMSG(MSG_EN_1,(_T("CameraCaptureThread(%d)++/r/n"), frame_count));
- #if 0
- if (frame_count <= 2) {
- //frame_count++;
- // Enable camera interrupt
- s2440INT->INTSUBMSK &= ~(( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));
- s2440INT->INTMSK &= ~( 1 << IRQ_CAM );
- continue;
- }
- #endif
- if (dwCause == WAIT_OBJECT_0) // LJY PWR
- {
- Lock();
- __try
- {
- if (s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_C ))
- {
- frame_count++;
- cam_intr |= ( 1 << IRQ_SUB_CAM_C );
- s2440INT->SUBSRCPND = (1<<IRQ_SUB_CAM_C);
- s2440INT->INTSUBMSK &= ~(1<<IRQ_SUB_CAM_C);
- //RETAILMSG(1,(_T("CAM_C, ts %d/r/n"), GetTickCount()));
- }
- if (s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_P ))
- {
- cam_intr |= ( 1 << IRQ_SUB_CAM_P );
- s2440INT->SUBSRCPND = (1<<IRQ_SUB_CAM_P);
- s2440INT->INTSUBMSK &= ~(1<<IRQ_SUB_CAM_P);
- //RETAILMSG(1,(_T("CAM_P, ts %d/r/n"), GetTickCount()));
- }
- if (((s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_C )) == 0) && ((s2440INT->INTSUBMSK & ( 1 << IRQ_SUB_CAM_P )) == 0))
- {
- RETAILMSG(MSG_EN_1,(_T("[CAM]NOP/r/n")));
- }
- InterruptDone(g_CamSysIntr);
- //time = GetTickCount();
- //RETAILMSG(1,(TEXT("+time:%d/r/n"),(time - old_time)));
- // Handle any interrupts on the input source
- if (cam_intr & ( 1 << IRQ_SUB_CAM_P ))
- {
- // display the image
- if (DRIVER_PREVIEW_ENABLE == 1)
- Display_Cam_Image(0,0,PREVIEW_X, PREVIEW_Y, PORT_A);
- Buffer_preview_info_update();
- cam_intr &= ~( 1 << IRQ_SUB_CAM_P );
- }
- if (cam_intr & ( 1 << IRQ_SUB_CAM_C ))
- {
- Buffer_codec_info_update();
- cam_intr &= ~( 1 << IRQ_SUB_CAM_C );
- }
- // Enable camera interrupt
- //s2440INT->INTSUBMSK &= ~(( 1 << IRQ_SUB_CAM_P )|( 1 << IRQ_SUB_CAM_C ));
- //s2440INT->INTMSK &= ~( 1 << IRQ_CAM );
- //old_time = GetTickCount();
- //RETAILMSG(1,(TEXT("-time:%d/r/n"),(old_time-time)));
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- RETAILMSG(PM_MSG, (TEXT("Camera.DLL:InterruptThread() - EXCEPTION: %d"), GetExceptionCode()));
- }
- Unlock();
- }
- else if (dwCause == WAIT_TIMEOUT)
- {
- Lock();
- RETAILMSG(PM_MSG,(_T("[CAM_HW] InterruptThread Timeout : %d msec/r/n"), dwDisplayTimeout));
- dwDisplayTimeout = INFINITE; // reset timeout until Camera Interrupt occurs
- bIdlePwrDown = TRUE; // Codec is off
- CamInterface_PowerDown();
- RETAILMSG(PM_MSG, (TEXT("[CAM_HW] InterruptThread : bIdlePwrDown = TRUE/r/n")));
- Unlock();
- }
- else
- {
- RETAILMSG(PM_MSG, (TEXT("[CAM_HW] InterruptThread : Exit %d, Cause %d/r/n"), GetLastError(), dwCause));
- }
- }
- return 0;
- }
我看上去觉得一开机就会产生这个摄像头扑捉线程,我觉得不合理,串口打印信息也没有打印出来,应该没有被调用。到底在哪里控制这些程序的调用呢?