📄 cardhandler.c
字号:
/* **************************************************************************************
* Copyright (c) 2004 ZORAN Corporation, All Rights Reserved
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
*
* File: "CardHandler.c"
*
* Description:
* ============
* Handle messages relating to memory card/USB playback.
*
* Log:
* ====
* $Revision: $
* Last Modified by $Author: $ at $Modtime: $
****************************************************************************************
* Updates:
****************************************************************************************
* $Log: $
*
*
**************************************************************************************** */
#include "config.h"
#ifdef SUPPORT_FLASH_CARD
#define CARDEVENTHANDLER_C
#ifdef DEBUG_DRIVE_TRACE
#undef IFTRACE
#define IFTRACE if (gTraceDrive)
#include "Debug\DbgMain.h"
#endif
#include <embedded.h>
#include "Include\SysDefs.h"
#include "kernel\eventdef.h"
#include "kernel\ker_api.h"
#include "Kernel\uITRON\rtos.h"
#include "Playcore\Coremain\Coremain.h"
#include "Playcore\FileSys\FileSystem.h"
#include "Playcore\nav_clips\clip.h"
#include "Playcore\coremain\coregdef.h"
#include "playcore\exception\exception.h"
#include "drive\drv_api.h"
#include "Drive\zfe\zfe.h"
#include "Drive\Zfe\Shared\Pmq\pmq.h"
#include "drive\zfe\Disc\npm\npm.h"
#include "Decoder_I96\MCU\mem_mngr.h"
#include "services\include\_heap.h"
#include "mcu_api.h"
#include "bsi_api.h"
#include "Decoder_I96\Dec_API.h"
#include "debug\dbgmain.h"
#include _FCU_LL_DIR_
#include "Drive\Zfe\Card\CardHandler.h"
#include "Drive\Zfe\Card\CardReaderDriver.h"
#include "mediacards\include\register.h"
#include "Playcore\FileSys\filesyssubfunction.h"
#include "Playcore\FileSys\filex\fx_api.h"
#include "Playcore\FileSys\FileX\fx_fil.h"
#include "PBC\Decode\decode.h"
#ifdef D_CARD_USB_READSPEED_TEST
#include "cpu\cpu_api.h"
#endif
#include "Playcore\timing\timing.h"
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
#include "Decoder_setting\sdram_config.h"
#include "Drive\Zfe\zfe_mcu_address.h"
#include "Drive\Zfe\zfe_address.h"
#include "Drive\Zfe\Shared\Fef\fef.h"
#include "io_hal_api.h"
#endif//D_USE_USB_SDRAM_DECODER_BUFF
typedef struct{
FileHandle* pFileOnPlay;
BOOL gbPlayCommandPending;
BOOL gbStopException;
WORD wDeviceId;
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
UINT32 dwOffsetInSdramBuff; //in byte
#endif//D_USE_USB_SDRAM_DECODER_BUFF
UINT32 VCBSize;
UINT32 ACBSize;
}CARD_HANDLER_STRUCT;
static CARD_HANDLER_STRUCT * gstCardHandler = NULL;
#ifdef D_CARD_USB_READSPEED_TEST
static char* card_str[NUM_OF_CARDS] =
{
"SD",
"MMC",
"MS",
"MSPro",
"CF",
"SM",
"xD",
"USB"
};
#endif
#ifdef I86_USB_SUPPORT
extern BOOL far gbIsUSBDriver;
extern void acknowledge_card_detect_msg(void);
#endif
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
UINT32 g_timer0=0;
UINT32 g_timer1=0;
UINT32 g_timer2=0;
#define DECODER_SDRAM_GAP_SIZE (0x2000UL) // 8KB
#define USB_CARD_SECTOR_SIZE (512UL)
#ifndef SDRAM_1X16MBITS
#define DECODER_SDRAM_ADDR 0x300000UL//TB_START_AVI // in word
#define DECODER_SDRAM_SIZE (0x20000UL) // 256KB in word
#else
extern MEM_MNGR_ST MEM_MngrSt;
#define DECODER_SDRAM_ADDR ((1808ul)*512ul) //TB start
#define DECODER_SDRAM_SIZE ((1890ul-1808ul)*512ul)//1890 is USB buffer start
#endif
static void _FlashCard_InitDecoderSdramBuffer(void);
void FlashCard_UpdateBtsBuff(UINT32 dwNewBtsStopAddr);
static UINT32 _FlashCard_GetAvailableSpaceInDecoderSdramBuff(UINT32 dwBtsStopPtr);
#endif//D_USE_USB_SDRAM_DECODER_BUFF
static void FlashCard_constructor(void);
static void FlashCard_destructor(void);
static BOOL FlashCard_StreamFeeder(void);
static void FlashCard_PlayFile(PMQ_MSG * msg);
static void FlashCard_PausePlay(PMQ_MSG * msg);
static void FlashCard_AbortPlay(void);
static void FlashCard_PushDataToDVP(void);
static void FlashCard_Queue_Play(void);
/*
Desc: Activate the handler, init the golbal variables of handler and FCU.
In: None
Out: None
Return: None
*/
static void FlashCard_constructor(void)
{
dbg_printf(("card handler: enters active mode.\n"));
if(NULL != gstCardHandler)
{
tr_printf(("Card handler, Fatal! alreay activated.\n"));
return;
}
gstCardHandler = MEM_Allocate(DEFAULT_HEAP, sizeof(CARD_HANDLER_STRUCT));
if(NULL == gstCardHandler)
{
tr_printf(("Card handler, Fatal! low system resource.\n"));
return;
}
//File is in close state.
gstCardHandler->pFileOnPlay= NULL;
gstCardHandler->gbStopException = FALSE;
}
/*
Desc: Deactivate the handler.
Termainate FCU driver.
In: None
Out: None
Return: None
*/
static void FlashCard_destructor(void)
{
dbg_printf(("card handler: enters idle mode.\n"));
if(NULL == gstCardHandler)
{
tr_printf(("Card handler, Fatal! alreay deactivated.\n"));
return;
}
MEM_Free(DEFAULT_HEAP, gstCardHandler);
gstCardHandler = NULL;
if( gstCardHandler->pFileOnPlay != NULL )
{
tr_printf(("Card handler Fatal! playback not aborted before go to idle state.\b"));
}
core_subscribe_card_tick_20(FALSE);
}
/**********************************************************************************
* Purpose : Play a file on flash card
* Input Parameters : msg-
* :
* :
* Output Parameters :
* Return Value : no return
* Description :
* Comments :
**********************************************************************************/
static void FlashCard_PlayFile(PMQ_MSG * msg)
{
//todo: do we have param1 and param2 with NPM message?
//open play file, msg->param1 is the start cluster num of the file, (msg->param2-msg->param1) is the file size in blocks.
//FileSys_FileOpen(&(gstCardHandler->FfileOnPlay), msg->param1, 0,
// (DWORD)((msg->param2 - msg->param1 + 1) * LOGICAL_BLOCK_SIZE));
FileHandle* pFile = (FileHandle*)msg->param1;
if( NULL == pFile )
{
tr_printf(("FAIL: FlashCard_PlayFile(): the pFile is empty."));
return;
}
if( NULL == pFile->pFileXPtr )
{
tr_printf(("FAIL: FlashCard_PlayFile(): the pFile->pFileXPtr is empty."));
return;
}
gstCardHandler->pFileOnPlay = pFile;
gstCardHandler->wDeviceId = pFile->pDeviceObj->wDeviceId;
dbg_printf(("flash card play file, start:%lx, size:%lx.\n ",
gstCardHandler->pFileOnPlay->pFileXPtr->fx_file_first_physical_cluster,
gstCardHandler->pFileOnPlay->pFileXPtr->fx_file_current_file_size));
gstCardHandler->gbPlayCommandPending = FALSE;
gstCardHandler->gbStopException = FALSE;
//get ACB and VCB size
gstCardHandler->VCBSize = (MEM_MngrSt.mapInfo->memCodeBuff[MEM_BUFF_VCB_ID].ulSize)*2 ;
gstCardHandler->ACBSize = (MEM_MngrSt.mapInfo->memCodeBuff[MEM_BUFF_ACB_ID].ulSize)*2 ;
if(PST_SCAN == gcs.pstate)
{
gstCardHandler->VCBSize = gstCardHandler->VCBSize > 400*1024ul?400*1024ul:gstCardHandler->VCBSize;
gstCardHandler->ACBSize = gstCardHandler->ACBSize > 200*1024ul?200*1024ul:gstCardHandler->ACBSize;
}
dbg_printf(("gstCardHandler->VCBSize = %ldK, gstCardHandler->ACBSize = %ldK\n",
(gstCardHandler->VCBSize+16)/1024, (gstCardHandler->ACBSize+16)/1024));
core_subscribe_card_tick_20(TRUE);
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
if (card_type == CARD_TYPE_SM ||
card_type == CARD_TYPE_XD)
_FlashCard_InitDecoderSdramBuffer();
#endif//D_USE_USB_SDRAM_DECODER_BUFF
FlashCard_Queue_Play();
}
/**********************************************************************************
* Purpose : Stop feeding data from card
* Input Parameters : Pause/Resume
* :
* :
* Output Parameters :
* Return Value : no return
* Description :
* Comments :
**********************************************************************************/
static void FlashCard_PausePlay(PMQ_MSG * msg)
{
dbg_printf(("Flash card, play paused.\n"));
if(TRUE == (BOOL)(msg->param1)) //Pause the play
gstCardHandler->gbPlayCommandPending = FALSE;
else //Resume the pause play
gstCardHandler->gbPlayCommandPending = TRUE;
}
/**********************************************************************************
* Purpose : Stop Playing file on flash card
* Input Parameters :
* :
* :
* Output Parameters :
* Return Value : no return
* Description :
* Comments :
**********************************************************************************/
static void FlashCard_AbortPlay(void)
{
dbg_printf(("Flash card, play aborted.\n"));
//close play file
gstCardHandler->pFileOnPlay = NULL;
gstCardHandler->gbPlayCommandPending = FALSE;
gstCardHandler->gbStopException = FALSE;
core_subscribe_card_tick_20(FALSE);
}
/**********************************************************************************
* Purpose : Process the messages about flash card
* Input Parameters : msg -
* :
* :
* Output Parameters :
* Return Value : NULL - If this event handler process this msg and
this msg is no use for other handlers,return NULL
msg - If this event handler can not handle this msg, just return it
* Description :
* Comments : Process all the messages about flash card
**********************************************************************************/
void Card_Handler(PMQ_MSG * curr_msg)
{
while (1)
{
switch (curr_msg->op)
{
case PMQ_MSG_DELETED:
break;
case CARD_ACTIVATE:
FlashCard_constructor();
break;
case CARD_DEACTIVATE:
FlashCard_destructor();
break;
case CARD_MSG_PLAY:
FlashCard_PlayFile(curr_msg);
break;
case CARD_MSG_PAUSE:
FlashCard_PausePlay(curr_msg);
break;
case CARD_MSG_ABORT:
FlashCard_AbortPlay();
break;
case CARD_TICK_20:
FlashCard_OnTick();
acknowledge_card_tick_20();
break;
case CARD_MSG_DETECTION:
#ifndef D_NO_DISC
if( NPM_IsFcuRamAccessible() )
#endif
{
CardDetection_RegularCheck();
}
#ifdef I86_USB_SUPPORT
acknowledge_card_detect_msg();
#endif
break;
default:
return;
}
/* Received the next message and remove it from the queue */
PMQ_ReceiveMessage(curr_msg);
PMQ_DeleteMsgQueTail();
}
}
void FlashCard_OnTick(void)
{
if(( NULL != gstCardHandler->pFileOnPlay) && (TRUE == gstCardHandler->gbPlayCommandPending))
{
if(FALSE == FlashCard_StreamFeeder())
ie_send(IE_CORE_CARD_PLAY_ERROR); //Probably the card has been removed.
//todo: report file read error to navigator.
/*{
UINT32 dwData;
MCU_ReadPointersRAM(MCU_PTR_BTS_RD_ADDR, &dwData);
dbg_printf(("BTS read ptr = 0x%08lx, ", dwData));
MCU_ReadPointersRAM(MCU_PTR_BTS_STOP_ADDR, &dwData);
dbg_printf(("BTS stop ptr = 0x%08lx\n", dwData));
}*/
}
}
/*
Desc: read the file and feed data to decoder.
if got end_of_file or any read error, close the file, and return false.
Otherwise return TRUE.
*/
#define DATA_TRANSFER_GRANULARITY 2048
#define DATA_TRANSFER_MAX_UNITS (1L * DATA_TRANSFER_GRANULARITY)
#define TRANSFER_UNIT_SIZE (2048*8ul)
//BOOL debug_enable_write_data = TRUE;
static BOOL FlashCard_StreamFeeder(void)
{
#ifdef D_CARD_USB_READSPEED_TEST
static UINT32 tick1;
UINT32 tick2;
static UINT32 size;
#endif
UINT32 audioGap = MCU_ReadCodeBufferFullness(MCU_AUDIO_CODE_BUFFER, MCU_FULLNESS_IN_BYTES);
UINT32 VideoGap = MCU_ReadCodeBufferFullness(MCU_VIDEO_CODE_BUFFER, MCU_FULLNESS_IN_BYTES);
BOOL cIsNoEccVideoPlaying = FALSE;
if (audioGap < gstCardHandler->ACBSize || VideoGap < gstCardHandler->VCBSize)
{
//check video buffer if video stream available.
switch (DEC_GetApplMode())
{
case DEC_APPL_MPEG_CLIP:
case DEC_APPL_DIVX311:
case DEC_APPL_DIVX4_5:
case DEC_APPL_XVID:
#ifdef IS_ASF_CAPABLE
case DEC_APPL_ASF:
#endif
#ifdef IS_MP4_CAPABLE
case DEC_APPL_MP4:
#endif
cIsNoEccVideoPlaying = TRUE;
audioGap = ((gstCardHandler->ACBSize - audioGap) / DATA_TRANSFER_GRANULARITY) * DATA_TRANSFER_GRANULARITY;
VideoGap = ((gstCardHandler->VCBSize - VideoGap) / DATA_TRANSFER_GRANULARITY) * DATA_TRANSFER_GRANULARITY;
if(VideoGap < audioGap || 0 == gstCardHandler->ACBSize)
audioGap = VideoGap;
break;
default:
cIsNoEccVideoPlaying = FALSE;
audioGap = ((gstCardHandler->ACBSize - audioGap) / DATA_TRANSFER_GRANULARITY) * DATA_TRANSFER_GRANULARITY;
break;
}
//don't spend too much time in this function, so limit the number of sectors to transfter.
if(audioGap > (2048*20ul) )
audioGap = (2048*20ul);
if((DEC_CBSELECT_AVI == DEC_GetCBSelect())&&(PST_PAUSE == gcs.pstate)&&(DCD_GetCurrDecodedFrame() > 1))
return TRUE;
if (audioGap >= DATA_TRANSFER_MAX_UNITS)
{
UINT32 i = audioGap;
UINT status = FX_SUCCESS;
while(i > 0)
{
UINT32 unit = TRANSFER_UNIT_SIZE;
if(i < TRANSFER_UNIT_SIZE)
{
unit = i;
}
if(unit > gstCardHandler->pFileOnPlay->dwEndAddr - gstCardHandler->pFileOnPlay->dwCurrentPosition)
unit = gstCardHandler->pFileOnPlay->dwEndAddr - gstCardHandler->pFileOnPlay->dwCurrentPosition;
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
//unit = ((unit + USB_CARD_SECTOR_SIZE -1)/USB_CARD_SECTOR_SIZE) * USB_CARD_SECTOR_SIZE;
if (card_type == CARD_TYPE_SM ||
card_type == CARD_TYPE_XD)
{
if( (gstCardHandler->dwOffsetInSdramBuff + unit) > DECODER_SDRAM_SIZE*2 )
unit = DECODER_SDRAM_SIZE*2 - gstCardHandler->dwOffsetInSdramBuff;
audioGap = _FlashCard_GetAvailableSpaceInDecoderSdramBuff(DECODER_SDRAM_ADDR + gstCardHandler->dwOffsetInSdramBuff/2);
if( unit > audioGap )
unit = audioGap;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -