⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbvideo_state.c

📁 MTK平台绝密核心代码之 USB驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
		USBVideo_Send_Msg(USBVIDEO_MSG_MED_START_SUCCESS_CNF, g_USBVideo.commit_video_index, g_USBVideo.video_compression_index);
		g_USBVideo.state = USBVIDEO_STATE_SEND;
	}
	else
		EXT_ASSERT(0, (kal_uint32)g_USBVideo.video_start_state, 0, 0);
}

/* Handler for change video size request from USB HISR */
static void USBVideo_Change_Video_Size_Hdlr(ilm_struct *p_recv_ilm, USB_DEVICE_TYPE device_type)
{
	kal_uint32 savedMask;

	if((g_USBVideo.state==USBVIDEO_STATE_PRE_PAUSE) || (g_USBVideo.state==USBVIDEO_STATE_PAUSE)
		||(g_USBVideo.state==USBVIDEO_STATE_STOP) || (g_USBVideo.state==USBVIDEO_STATE_STILL))
	{
		/* do nothing, new size will be get each time send this JPEG*/
		return;
	}
	
	/* clear buffer and wait DMA done */
	savedMask = SaveAndSetIRQMask();
	if(USB_DMA_Get_Run_Status(g_USBVideo.txpipe->byEP)==KAL_TRUE)
	{
		if(g_USBVideo.video_control.dma_type==USBVIDEO_DMA_VIDEO)
		{
			/* Not that for incall dma case, some resume cnf has been sent to media task already
			   So the handler is the same as video */
		
			/* DMA is running, after DMA done read pointer will increment */
			if(g_USBVideo.video_control.video_buffer_read_index==(USBVIDEO_VIDEO_BUFFER_NUMBER-1))
				g_USBVideo.video_control.video_buffer_write_index = 0;
			else
				g_USBVideo.video_control.video_buffer_write_index = g_USBVideo.video_control.video_buffer_read_index+1;
			g_USBVideo.video_control.video_buffer_full = KAL_FALSE;
		}
		else if((g_USBVideo.video_control.dma_type==USBVIDEO_DMA_STILL) 
			||(g_USBVideo.video_control.dma_type==USBVIDEO_DMA_INCALL_JPEG))
		{
			g_USBVideo.video_control.video_buffer_write_index = 0;
			g_USBVideo.video_control.video_buffer_full = KAL_FALSE;
		}
		else
		{
			EXT_ASSERT(0, g_USBVideo.video_control.dma_type, g_USBVideo.state, 0);
		}
	}
	else
	{
		/* clear the buffer */
		g_USBVideo.video_control.video_buffer_read_index = g_USBVideo.video_control.video_buffer_write_index;
		g_USBVideo.video_control.video_buffer_full = KAL_FALSE;
		g_USBVideo.video_control.sent_video_size = 0;
		/* buffer is empty, send msg for next complete buffer */
		g_USBVideo.video_control.send_video_msg = KAL_TRUE;
	}
	RestoreIRQMask(savedMask);
	
	/* Notify media task to change video size */	
	g_USBVideo.state = USBVIDEO_STATE_DROP;
	USBVideo_Send_Msg(USBVIDEO_MSG_MED_CHANGE_VIDEO_IND, g_USBVideo.commit_video_index, g_USBVideo.video_compression_index);	
	
}

/* Handler for complete video buffer filling from camera HISR */
static void USBVideo_Video_Complete_Hdlr(ilm_struct *p_recv_ilm, USB_DEVICE_TYPE device_type)
{
	kal_uint8 commit_still_index = g_USBVideo.commit_still_index;
	
	if((g_USBVideo.state==USBVIDEO_STATE_PRE_PAUSE) || (g_USBVideo.state==USBVIDEO_STATE_PAUSE))
		EXT_ASSERT(0, (kal_uint32)g_USBVideo.state,g_USBVideo.video_control.video_buffer_read_index, 
					g_USBVideo.video_control.video_buffer_write_index);

	if((g_USBVideo.state==USBVIDEO_STATE_STOP) 
		||((g_USBVideo.state==USBVIDEO_STATE_STILL)&&(commit_still_index!=0)))
		return;

	if(g_USBVideo.state==USBVIDEO_STATE_STILL)
	{
	#ifndef  __PRODUCTION_RELEASE__
		if(commit_still_index==0)
			ASSERT(0);
	#endif	
		g_USBVideo.state = USBVIDEO_STATE_SEND;
	}

	g_USBVideo.video_control.dma_type = USBVIDEO_DMA_VIDEO;
	USBVideo_Send_Video();
}

/* Handler for video DMA done from DMA HISR */
static void USBVideo_Video_DMA_Done_Hdlr(ilm_struct *p_recv_ilm, USB_DEVICE_TYPE device_type)
{
	kal_bool	bBufferEmpty = KAL_FALSE;
	kal_uint32 savedMask;
	usbvideo_default_JPEG_Info*p_default_jpeg;
	kal_uint32 total_size;
	kal_bool bEPEmpty;
	kal_uint32 count;
	kal_uint8 commit_still_index = g_USBVideo.commit_still_index;
	// for debug 
	static kal_uint8 dmadone_video_buff_write_index;
	static kal_uint8 dmadone_video_buff_read_index;
	static kal_bool dmadone_video_buff_full_flag;

	if(g_USBVideo.state==USBVIDEO_STATE_PAUSE)
		EXT_ASSERT(0, (kal_uint32)g_USBVideo.state, 0, 0);

	if(g_USBVideo.state==USBVIDEO_STATE_STOP)
		return;

	if(g_USBVideo.video_control.dma_done_type == USBVIDEO_DMA_DONE_COMPLETE)
	{
		/* send NULL packet only when dma done type is complete, not stop */
		total_size = g_USBVideo.video_control.video_size[g_USBVideo.video_control.video_buffer_read_index]; 
		count = total_size/(USBVIDEO_MAX_PAYLOAD_LENGTH -USBVIDEO_PAYLOAD_HEADER_LENGTH);
		if(total_size%(USBVIDEO_MAX_PAYLOAD_LENGTH -USBVIDEO_PAYLOAD_HEADER_LENGTH)!=0)
			count++;
		if(((total_size+count*USBVIDEO_PAYLOAD_HEADER_LENGTH)%USB_EP_BULK_MAXP) == 0)
		{
			/* multiple of 64 bytes */
	
			/* make sure previous packets are already sent out
			   maybe last DMA data has triggered DMA done but data are still in FIFO*/
			bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			/* If cable plug out at this time, add timeout to avoid looping here */
			while((bEPEmpty == KAL_FALSE)&&(count<100))
			{
				count++;	
				kal_sleep_task(1);	
				bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			}
	
			/* send out a NULL packet */
			USB_EPFIFOWrite(g_USBVideo.txpipe->byEP, 0, NULL);
			USB_EP_Bulk_In_Ready(g_USBVideo.txpipe->byEP);
		
			/* mak sure previous NULL pkt has been sent out
			   avoid next DMA data in FIFO sent out instead of previos NULL pkt.*/
		
			bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			/* If cable plug out at this time, add timeout to avoid looping here */
			count = 0;
			while((bEPEmpty == KAL_FALSE)&&(count<100))
			{
				count++;	
				kal_sleep_task(1);	
				bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			}
		}
	}	
	
	if(g_USBVideo.state == USBVIDEO_STATE_PRE_PAUSE)
	{
		/* stop pre-pause timer */
		GPTI_StopItem(g_USBVideo.video_control.timer_handle);
		g_USBVideo.state = USBVIDEO_STATE_PAUSE;	
		USBVideo_Send_Msg(USBVIDEO_MSG_MED_PAUSE_CNF, (kal_uint32)KAL_TRUE, 0);
		//p_default_jpeg = g_USBVideo.mmi_param->usbvideo_get_incall_jpeg_info(&incall_size_num);
		p_default_jpeg = g_USBVideo.default_jpeg_info;
		savedMask = SaveAndSetIRQMask();
		g_USBVideo.video_control.still_count = 0;
		g_USBVideo.video_control.sent_video_size = 0;
		g_USBVideo.video_control.incall_jpeg_addr = p_default_jpeg[g_USBVideo.commit_video_index - 1].start_addr;
		g_USBVideo.video_control.incall_jpeg_size = p_default_jpeg[g_USBVideo.commit_video_index - 1].size;
		RestoreIRQMask(savedMask);
		g_USBVideo.video_control.dma_type = USBVIDEO_DMA_INCALL_JPEG;
		USBVideo_Send_Incall_JPEG();
	}
	else if((g_USBVideo.state==USBVIDEO_STATE_STILL)&&(commit_still_index!=0))
	{
		/* Send still capture request to media task*/
		savedMask = SaveAndSetIRQMask();	
		g_USBVideo.video_control.sent_video_size = 0;
		g_USBVideo.video_control.video_buffer_read_index = 0;
		g_USBVideo.video_control.video_buffer_write_index = 0;
		g_USBVideo.video_control.video_buffer_full = KAL_FALSE;
		g_USBVideo.video_control.send_video_msg = KAL_TRUE;
		RestoreIRQMask(savedMask);
		USBVideo_Send_Msg(USBVIDEO_MSG_MED_STILL_CAPTURE_IND, commit_still_index, g_USBVideo.commit_still_compression_index);	
	}
	else
	{
		if(g_USBVideo.state==USBVIDEO_STATE_STILL)   /*  commit_still_index == 0  */
		{
		#ifndef  __PRODUCTION_RELEASE__
			if(commit_still_index==0)
				ASSERT(0);
		#endif	
			g_USBVideo.state = USBVIDEO_STATE_SEND;
		}
		
		savedMask = SaveAndSetIRQMask();
		g_USBVideo.video_control.sent_video_size = 0;
		g_USBVideo.video_control.video_buffer_read_index++;
		if(g_USBVideo.video_control.video_buffer_read_index==USBVIDEO_VIDEO_BUFFER_NUMBER)
			g_USBVideo.video_control.video_buffer_read_index = 0;
		if(g_USBVideo.video_control.video_buffer_full==KAL_TRUE)
		{
			if(g_USBVideo.video_control.video_buffer_read_index==g_USBVideo.video_control.video_buffer_write_index)
				EXT_ASSERT(0, g_USBVideo.video_control.video_buffer_read_index,
							g_USBVideo.video_control.video_buffer_write_index, 0);	
			g_USBVideo.video_control.video_buffer_full = KAL_FALSE;
		}
		if(g_USBVideo.video_control.video_buffer_read_index==g_USBVideo.video_control.video_buffer_write_index)
		{
			/* buffer empty */
			bBufferEmpty = KAL_TRUE;
			g_USBVideo.video_control.send_video_msg = KAL_TRUE;
		}
		
		dmadone_video_buff_write_index = g_USBVideo.video_control.video_buffer_write_index;
		dmadone_video_buff_read_index = g_USBVideo.video_control.video_buffer_read_index;
		dmadone_video_buff_full_flag = g_USBVideo.video_control.video_buffer_full;
	
		RestoreIRQMask(savedMask);
		
		kal_prompt_trace(MOD_USB, "dma done v buff r %d, w%d, f %d\n", dmadone_video_buff_read_index, 
					dmadone_video_buff_write_index, dmadone_video_buff_full_flag);
					
		if(bBufferEmpty==KAL_FALSE)
		{
			g_USBVideo.video_control.dma_type = USBVIDEO_DMA_VIDEO;
			USBVideo_Send_Video();
		}	
	}	
}

/* Handler for still DMA done from DMA HISR */
static void USBVideo_Still_DMA_Done_Hdlr(ilm_struct *p_recv_ilm, USB_DEVICE_TYPE device_type)
{
	kal_uint32 savedMask;
	usbvideo_default_JPEG_Info*p_default_jpeg;
	kal_uint32 total_size;
	kal_bool bEPEmpty;
	kal_uint32 count;
	kal_uint8 commit_still_index = g_USBVideo.commit_still_index;

	if(g_USBVideo.state==USBVIDEO_STATE_PAUSE)
		EXT_ASSERT(0, (kal_uint32)g_USBVideo.state, 0, 0);

	if(g_USBVideo.state==USBVIDEO_STATE_STOP)
		return;	

	if(g_USBVideo.video_control.dma_done_type == USBVIDEO_DMA_DONE_COMPLETE)
	{
		/* send NULL packet only when dma done type is complete */
		total_size = g_USBVideo.video_control.still_size;
		count = total_size/(USBVIDEO_MAX_PAYLOAD_LENGTH -USBVIDEO_PAYLOAD_HEADER_LENGTH);
		if(total_size%(USBVIDEO_MAX_PAYLOAD_LENGTH -USBVIDEO_PAYLOAD_HEADER_LENGTH)!=0)
			count++;
		if(((total_size+count*USBVIDEO_PAYLOAD_HEADER_LENGTH)%USB_EP_BULK_MAXP) == 0)
		{
			/* multiple of 64 bytes */
			
			/* make sure previous packets are already sent out
			   maybe last DMA data has triggered DMA done but data are still in FIFO*/
			bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			/* If cable plug out at this time, add timeout to avoid looping here */
			while((bEPEmpty == KAL_FALSE)&&(count<100))
			{
				count++;	
				kal_sleep_task(1);	
				bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			}
	
			/* send out a NULL packet */
			USB_EPFIFOWrite(g_USBVideo.txpipe->byEP, 0, NULL);
			USB_EP_Bulk_In_Ready(g_USBVideo.txpipe->byEP);
		
			/* mak sure previous NULL pkt has been sent out
			   avoid next DMA data in FIFO sent out instead of previos NULL pkt.*/
	
			bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			/* If cable plug out at this time, add timeout to avoid looping here */
			count = 0;
			while((bEPEmpty == KAL_FALSE)&&(count<100))
			{
				count++;	
				kal_sleep_task(1);	
				bEPEmpty = USB_Is_EP_Bulk_In_Empty(g_USBVideo.txpipe->byEP);
			}
		}
	}		

	if(g_USBVideo.state == USBVIDEO_STATE_PRE_PAUSE)
	{
		/* stop pre-pause timer */
		GPTI_StopItem(g_USBVideo.video_control.timer_handle);
		g_USBVideo.state = USBVIDEO_STATE_PAUSE;	
		USBVideo_Send_Msg(USBVIDEO_MSG_MED_PAUSE_CNF, (kal_uint32)KAL_TRUE, 0);
		//p_incall_param = g_USBVideo.mmi_param->usbvideo_get_incall_jpeg_info(&incall_size_num);
		p_default_jpeg = g_USBVideo.default_jpeg_info;
		savedMask = SaveAndSetIRQMask();
		g_USBVideo.video_control.still_count = 0;
		g_USBVideo.video_control.sent_video_size = 0;
		g_USBVideo.video_control.send_video_msg = KAL_TRUE;
		g_USBVideo.video_control.incall_jpeg_addr = p_default_jpeg[g_USBVideo.commit_video_index - 1].start_addr;
		g_USBVideo.video_control.incall_jpeg_size = p_default_jpeg[g_USBVideo.commit_video_index - 1].size;
		RestoreIRQMask(savedMask);
		g_USBVideo.video_control.dma_type = USBVIDEO_DMA_INCALL_JPEG;
		USBVideo_Send_Incall_JPEG();
	}
	else if((g_USBVideo.state == USBVIDEO_STATE_SEND) || (g_USBVideo.state == USBVIDEO_STATE_DROP))
	{
		/* already enter send state when still partial done */
		savedMask = SaveAndSetIRQMask();
		g_USBVideo.video_control.sent_video_size = 0;
		g_USBVideo.video_control.send_video_msg = KAL_TRUE;
		/* update read pointer so that video can start to capture in this buffer */
		g_USBVideo.video_control.video_buffer_read_index = 0;
		g_USBVideo.video_control.video_buffer_full = KAL_FALSE;	
		RestoreIRQMask(savedMask);
	}
	else if(g_USBVideo.state == USBVIDEO_STATE_STILL)
	{
		if((g_USBVideo.video_control.still_count>0) && (commit_still_index!=0))
		{
			/* send still image again */
			savedMask = SaveAndSetIRQMask();
			g_USBVideo.video_control.sent_video_size = 0;
			g_USBVideo.video_control.video_buffer_read_index = 0;
			g_USBVideo.video_control.video_buffer_write_index = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -