📄 pxa27x_camera.c
字号:
if (!KernelLibIoControl(pHwContext->hDMAIsrHandler, IOCTL_GIISR_INFO, &Info, sizeof(Info), NULL, 0, NULL))
{
DEBUGMSG(ZONE_ERROR, (L"KernelLibIoControl call failed.\r\n"));
}
CloseBusAccessHandle(hBusAccessHandle);
}
//Create event for dwSysIntrDMA
pHwContext->hDmaIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!pHwContext->hDmaIntrEvent)
{
return FALSE;
}
if (!InterruptInitialize (pHwContext->dwSysIntrDMA, pHwContext->hDmaIntrEvent, NULL, 0))
{
return FALSE;
}
//create and start hDmaIntrThread
pHwContext->hDmaIntrThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)DMAInterruptThread,
(void*)pHwContext,
0,
NULL);
if (!pHwContext->hDmaIntrThread)
{
return FALSE;
}
//CeSetThreadPriority(pHwContext->hDmaIntrThread, GetInterruptThreadPriority());
return XLLP_STATUS_SUCCESS;
}
XLLP_STATUS_T PrvCameraDmacDeinit(HW_CONTEXT_T *pHwContext)
{
return XLLP_STATUS_SUCCESS;
}
int CameraInit(void *pData)
{
PHYSICAL_ADDRESS PA;
HANDLE hThread;
PA.QuadPart = BULVERDE_BASE_REG_PA_DMAC;
v_pDMARegs = (volatile XLLP_DMAC_T *) MmMapIoSpace(PA, sizeof(XLLP_DMAC_T), FALSE);
PA.QuadPart = BULVERDE_BASE_REG_PA_I2C;
v_pI2C = (volatile unsigned int *) MmMapIoSpace(PA, sizeof(XLLP_I2C_T), FALSE);
if (!v_pI2C)
{
return FALSE;
}
PA.QuadPart = BULVERDE_BASE_REG_PA_OST;
v_pOSTRegs = (volatile unsigned int *) MmMapIoSpace(PA, sizeof(XLLP_OST_T), FALSE);
if (!v_pOSTRegs)
{
return FALSE;
}
PA.QuadPart = BULVERDE_BASE_REG_PA_CAMERA;
v_pCIRegs = (volatile unsigned int *) MmMapIoSpace(PA, 1024, FALSE);
if (!v_pCIRegs)
{
return FALSE;
}
PA.QuadPart = BULVERDE_BASE_REG_PA_CLKMGR;
v_pClkRegs = (volatile XLLP_CLKMGR_T *) MmMapIoSpace(PA, sizeof(XLLP_CLKMGR_T), FALSE);
if (!v_pClkRegs)
{
return FALSE;
}
PA.QuadPart = BULVERDE_BASE_REG_PA_GPIO;
v_pGPIORegs = (volatile XLLP_GPIO_T *) MmMapIoSpace(PA, sizeof(XLLP_GPIO_T), FALSE);
if (!v_pGPIORegs)
{
return FALSE;
}
//OS_I2CInit();
XllpI2cInit((P_XLLP_I2C_T)(v_pI2C), (P_XLLP_GPIO_T) v_pGPIORegs, (P_XLLP_CLKMGR_T) v_pClkRegs, (XLLP_UINT32_T) 0);
VirtAddr_Last_Pn_CH0 = 0x0;
VirtAddr_Last_Pn_CH1 = 0x0;
VirtAddr_Last_Pn_CH2 = 0x0;
VirtAddr_Last_n_CH0 = 0x0;
VirtAddr_Last_n_CH1 = 0x0;
VirtAddr_Last_n_CH2 = 0x0;
VirtAddr_Phantom_Buffer = 0x0;
VirtAddr_Phantom_Buffer_Base_Address = 0x0;
PhysAddr_Phantom_Buffer = 0x0;
bFirstVideoCaptureBufferSubmitted = FALSE;
bFirstStillBufferSubmitted = FALSE;
NumBuffers = 0;
hCameraFrameReady = CreateEvent(NULL,FALSE,FALSE,CAMERA_EVENT_NAME);
hStillImageReady = CreateEvent(NULL, FALSE, FALSE, CAMERA_EVENT_STILL_IMAGE_READY);
hCameraShutdownComplete = CreateEvent(NULL, FALSE, FALSE, CAMERA_SHUTDOWN_COMPLETE);
hShutDown = CreateEvent(NULL, FALSE, FALSE, NULL);
memset(&g_HwContext.XllpCAMERA, 0, sizeof(XLLP_Camera_Context_T));
memset(&g_HwContext.XllpSENSOR, 0, sizeof(XLLP_Camera_Function_T));
memset(&g_HwContext.XllpDMA, 0, sizeof(XLLP_Camera_DMA_Context_T));
// Fill in the context structure
g_HwContext.hDriverIndex = pData;
g_HwContext.dwDmaIrq = IRQ_DMAC;
g_HwContext.XllpCAMERA.camera_functions = &g_HwContext.XllpSENSOR;
g_HwContext.XllpCAMERA.capture_mode = XLLP_CAMERA_MODE_RECORD;
// os mapped register address
g_HwContext.XllpCAMERA.clk_reg_base = (unsigned int)v_pClkRegs;
g_HwContext.XllpCAMERA.ost_reg_base = (unsigned int)v_pOSTRegs;
g_HwContext.XllpCAMERA.gpio_reg_base = (unsigned int)v_pGPIORegs;
g_HwContext.XllpCAMERA.ci_reg_base = (unsigned int)v_pCIRegs;
InitializeCriticalSection(&CameraMutex);
XllpDmacInitHandle((P_XLLP_DMAC_T)v_pDMARegs);
if(!CameraInitSensor())
{
DEBUGMSG( ZONE_ERROR, ( _T("pxa27x_camera: CameraInitSensor() failed\r\n") ) );
return FALSE;
}
PrvCameraDmacInit(&g_HwContext);
// Launch the Camera ISR
hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)CAMIntrThread,(void*)&g_HwContext,0,NULL);
CloseHandle(hThread);
// return camera context
return (int)&g_HwContext.XllpCAMERA;
}
int CameraDeinit(void)
{
RETAILMSG(1, (TEXT("CameraDeinit\r\n")));
SensorDeinitPlatform(&g_HwContext.XllpCAMERA, &g_HwContext.XllpDMA);
//OS_I2CDeinit();
if (v_pDMARegs)
{
MmUnmapIoSpace((void *)v_pDMARegs, sizeof(XLLP_DMAC_T));
v_pDMARegs = NULL;
}
if (v_pI2C)
{
MmUnmapIoSpace((PVOID)v_pI2C, sizeof(XLLP_I2C_T));
v_pI2C = NULL;
}
if (v_pOSTRegs)
{
MmUnmapIoSpace((PVOID)v_pOSTRegs, sizeof(XLLP_OST_T));
v_pOSTRegs = NULL;
}
if (v_pCIRegs)
{
MmUnmapIoSpace((PVOID)v_pCIRegs, 1024);
v_pCIRegs = NULL;
}
if (v_pClkRegs)
{
MmUnmapIoSpace((PVOID)v_pClkRegs, sizeof(XLLP_CLKMGR_T));
v_pClkRegs = NULL;
}
if (v_pGPIORegs)
{
MmUnmapIoSpace((PVOID)v_pGPIORegs, sizeof(XLLP_GPIO_T));
v_pGPIORegs = NULL;
}
DeleteCriticalSection(&CameraMutex);
CloseHandle(hCameraFrameReady);
CloseHandle(hStillImageReady);
CloseHandle(hCameraShutdownComplete);
CloseHandle(hShutDown);
return TRUE;
}
// The interrupt service thread for the camera driver.
// When an end of frame interrupt occurs, this thread signals the application through an event mechanism.
// There's one event to signal a video frame has been captured, and another event to signal that a still image buffer
// frame has been captured.
DWORD WINAPI CAMIntrThread(HW_CONTEXT_T *pHwContext)
{
HANDLE events[2];
DWORD event_id = 0;
CeSetThreadPriority(GetCurrentThread(), 1);
events[0] = pHwContext->hDMAEvent[0];
events[1] = hShutDown;
while((event_id - WAIT_OBJECT_0) != 1)
{
event_id = WaitForMultipleObjects(2, (CONST HANDLE*)events, FALSE, INFINITE);
DEBUGMSG(1, (TEXT("CAMIntrThread: got event\r\n")));
// Service the "DMA transfer complete" interrupt
// which means that a new frame of video is available.
if ((event_id - WAIT_OBJECT_0) == 0)
{
CameraInterruptHandler(&g_HwContext);
// When we perform a still capture, discard n frames of video before we signal the application
// that the data is ready
if ((!bDoStillCapture)&& bDoVideoCapture)
{
SetEvent(hCameraFrameReady);
if (pfnCameraHandleVideoFrame)
pfnCameraHandleVideoFrame( dwCameraDriverContext );
}
if (discardframes && bDoStillCapture)
{
discardframes--;
}
if (bDoStillCapture && (discardframes == 0))
{
SetEvent(hStillImageReady);
ResetEvent(hCameraFrameReady);
bDoStillCapture = FALSE;
if (pfnCameraHandleStillFrame)
pfnCameraHandleStillFrame( dwCameraDriverContext );
}
}
}
SetEvent(hCameraShutdownComplete);
ExitThread(0);
return TRUE;
}
void CameraInterruptHandler(HW_CONTEXT_T *pHwContext)
{
DEBUGMSG(1, (TEXT("CameraInterruptHandler\r\n")));
}
// Initialize the XllpCAMERA structure with driver and application specific parameters.
int CameraInitSensor(void)
{
XLLP_STATUS_T status;
// platform specific initialization
if(!SensorInitPlatform(&g_HwContext.XllpCAMERA, &g_HwContext.XllpDMA))
{
return FALSE;
}
XllpLock(I2C);
status = XllpCameraInit(&g_HwContext.XllpCAMERA);
if (status != XLLP_STATUS_SUCCESS)
{
RETAILMSG(1,(TEXT("Camera init failure!!!\r\n")));
return FALSE;
}
XllpUnlock(I2C);
return TRUE;
}
void CameraWriteRegister(unsigned char subAddress, unsigned char *bufP)
{
if(g_HwContext.XllpCAMERA.camera_functions->WriteRegister)
{
XllpLock(I2C);
g_HwContext.XllpCAMERA.camera_functions->WriteRegister(&g_HwContext.XllpCAMERA, subAddress, bufP);
CameraReadRegister(subAddress, bufP);
XllpUnlock(I2C);
}
}
void CameraReadRegister(unsigned char subAddress, unsigned char *bufP)
{
*bufP = 0;
if(g_HwContext.XllpCAMERA.camera_functions->ReadRegister)
{
XllpLock(I2C);
g_HwContext.XllpCAMERA.camera_functions->ReadRegister(&g_HwContext.XllpCAMERA, subAddress, bufP);
XllpUnlock(I2C);
}
}
// Start the video capture process initiated by the application
void CameraStartVideoCapture()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -