📄 cardhandler.c
字号:
#if 0
if( !debug_enable_write_data )
unit = 0;
#endif
// currently, BSI is busy.
if( (unit == 0)/* || (unit < USB_CARD_SECTOR_SIZE) */)
break;
}
#endif//D_USE_USB_SDRAM_DECODER_BUFF
i -= unit;
if( PBC_IsPlaybackFinished() && (PBC_GetState() != PBC_STATE_INIT) )
{
dbg_printf(("Flash card, play file finished 1.\n"));
FlashCard_AbortPlay();
return FALSE;
}
if(TRUE == gstCardHandler->gbStopException)
{
FlashCard_AbortPlay();
return TRUE;
}
if (FALSE == FileSysSuper_Request(gstCardHandler->wDeviceId))
return FALSE;
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
if (card_type == CARD_TYPE_SM ||
card_type == CARD_TYPE_XD)
{
dbg_printf(("current write address 0x%08lx, size 0x%08lx\n", (DECODER_SDRAM_ADDR + gstCardHandler->dwOffsetInSdramBuff/2), unit));
#ifdef D_CARD_USB_READSPEED_TEST
tick2 =cpu_gen_timer();
#endif
if ((status = fx_file_read((gstCardHandler->pFileOnPlay->pFileXPtr),
(UINT8*)((DECODER_SDRAM_ADDR + gstCardHandler->dwOffsetInSdramBuff/2)|DECODER_SDRAM_MASK), unit,&audioGap, cIsNoEccVideoPlaying)) != FX_SUCCESS)
{
// TODO: Check Divx scan in card.
gstCardHandler->dwOffsetInSdramBuff += audioGap;
FlashCard_UpdateBtsBuff(DECODER_SDRAM_ADDR + gstCardHandler->dwOffsetInSdramBuff/2);
dbg_printf(("dwOffsetInSdramBuff = 0x%08lx\n", gstCardHandler->dwOffsetInSdramBuff));
//if(!((get_cbselect() == DEC_LL_CBSELECT_MPEG4_CLIP) && (PST_SCAN == gcs.pstate)))
FlashCard_PushDataToDVP();
tr_printf(("Flash card, play file finished. error code = %02x\n",status));
FlashCard_AbortPlay();
FileSysSuper_Release(gstCardHandler->wDeviceId);
if( FX_END_OF_FILE == status )
return TRUE;
else
return FALSE;
}
#ifdef D_CARD_USB_READSPEED_TEST
tick1 += cpu_gen_timer()-tick2;
size += unit;
if (size >= 5ul*1000ul*1000ul)
{
tr_printf(("\n[%s] play data size:%ld in %ldus\n",card_str[card_type],size,tick1));
tick1 =0;
size =0;
}
#endif
{
gstCardHandler->dwOffsetInSdramBuff += unit;
if( gstCardHandler->dwOffsetInSdramBuff > DECODER_SDRAM_SIZE*2 )
{
tr_printf(("FATAL: out of decoder SDRAM buffer range!\n"));
}
if( gstCardHandler->dwOffsetInSdramBuff == DECODER_SDRAM_SIZE*2 )
gstCardHandler->dwOffsetInSdramBuff = 0;
//tr_printf(("\nu-%lx-f-%lx",unit,gstCardHandler->dwOffsetInSdramBuff));
FlashCard_UpdateBtsBuff(DECODER_SDRAM_ADDR + gstCardHandler->dwOffsetInSdramBuff/2);
dbg_printf(("dwOffsetInSdramBuff = 0x%08lx\n", gstCardHandler->dwOffsetInSdramBuff));
}
}
else
#endif //D_USE_USB_SDRAM_DECODER_BUFF
{
#ifdef D_CARD_USB_READSPEED_TEST
tick2 =cpu_gen_timer();
#endif
if ((status = fx_file_read((gstCardHandler->pFileOnPlay->pFileXPtr),DECODER_BUFFER,unit,&audioGap, cIsNoEccVideoPlaying)) != FX_SUCCESS)
{
// TODO: Check Divx scan in card.
//if(!((get_cbselect() == DEC_LL_CBSELECT_MPEG4_CLIP) && (PST_SCAN == gcs.pstate)))
FlashCard_PushDataToDVP();
dbg_printf(("Flash card, play file finished. error code = %02x\n",status));
FlashCard_AbortPlay();
FileSysSuper_Release(gstCardHandler->wDeviceId);
if( FX_END_OF_FILE == status )
return TRUE;
else
return FALSE;
}
#ifdef D_CARD_USB_READSPEED_TEST
tick1 += cpu_gen_timer()-tick2;
size+=unit;
if (size >= 5ul*1000ul*1000ul)
{
tr_printf(("\n[%s] play data size:%ld in %ldus\n",card_str[card_type],size,tick1));
tick1 = 0;
size = 0;
}
#endif
}
FileSysSuper_Release(gstCardHandler->wDeviceId);
gstCardHandler->pFileOnPlay->dwCurrentPosition += unit;
if(gstCardHandler->pFileOnPlay->dwCurrentPosition >= gstCardHandler->pFileOnPlay->dwEndAddr )
{
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
/*
-- before pushing data, must make sure that BTS has read all data from SDRAM
-- otherwise, DVP may still wait data from BSI, typical case is
-- black screen when play JPG
*/
if (card_type == CARD_TYPE_SM ||
card_type == CARD_TYPE_XD)
{
UINT32 dwReadPtr, dwStopPtr;
MCU_ReadPointersRAM(MCU_PTR_BTS_RD_ADDR, &dwReadPtr);
MCU_ReadPointersRAM(MCU_PTR_BTS_STOP_ADDR, &dwStopPtr);
while (dwReadPtr != dwStopPtr )
{
MCU_ReadPointersRAM(MCU_PTR_BTS_RD_ADDR, &dwReadPtr);
usleep(1ul);
tr_printf(("\nwaiting... r:%lx s:%lx ",dwReadPtr,dwStopPtr));
}
}
#endif
// play boundary is received.
// TODO: Check Divx scan in card.
//if(!((get_cbselect() == DEC_LL_CBSELECT_MPEG4_CLIP) && (PST_SCAN == gcs.pstate)))
FlashCard_PushDataToDVP();
dbg_printf(("Flash card, play file finished. 2\n"));
FlashCard_AbortPlay();
return TRUE;
}
}
return TRUE;
}
}
return TRUE;
}
/*
Desc: flag that play command is queued.
caller: core task.
*/
static void FlashCard_Queue_Play(void)
{
gstCardHandler->gbPlayCommandPending = TRUE;
}
/*
Desc: This function feeds 4K bytes of dummy data to BSI.
It's purpose is to push the playload data stuck in BSI FIFO to DVP.
In: none
Out: 4k bytes of dummy data is fed to BSI.
Return: none
*/
static void FlashCard_PushDataToDVP(void)
{
UINT8 buffer[32];
UINT16 i;
BSI_SetBitstreamPath (BITSTREAM_PATH_CPU);
memset (buffer,0x00,32);
for (i=0;i<64u;i++)
{
if( PBC_IsPlaybackFinished() || (PBC_STATE_INIT==PBC_GetState()) || (PBC_STATE_IDLE==PBC_GetState()) )
{
tr_printf(("Decoder is finished.\n"));
return;
}
BSI_BitstreamWrite8Bit(buffer,32);
}
}
/*
Desc: Initialize FCU, card detection module, and send CARD_ACTIVATE to drive task.
It's called by core task. It can be seen as a synchronous function because
hardware is initialzed immediately while CARD_ACTIVATE doesn't requires synchronization.
In: none
Out: FCU and card detection module are initialized. CARD_ACTIVATE is sent to drive task.
Return: TRUE, successful.
FALSE, failed.
*/
BOOL FlashCard_Activate(void)
{
#ifndef I86_USB_SUPPORT //
FcuInit();
#endif
CardDetection_Init();
FlashCard_constructor(); //Card_SendMessage(CARD_ACTIVATE,0, 0, 0);
return TRUE;
}
/*
Desc: Terminate FCU, card detection module, and send CARD_DEACTIVATE to drive task.
It's called by core task. It can be seen as a synchronous function because
hardware is terminated immediately while CARD_DEACTIVATE doesn't requires synchronization.
In: none
Out: FCU and card detection module are terminated. CARD_DEACTIVATE is sent to drive task.
Return: TRUE, successful.
FALSE, failed.
*/
BOOL FlashCard_Deactivate(void)
{
FcuTerminate();
CardDetection_Term();
Card_SendMessage(CARD_DEACTIVATE,0, 0, 0);
return TRUE;
}
void FlashCard_Exception(void)
{
wai_sem(SEM_FSSUPER_ID);
gstCardHandler->gbStopException = TRUE;
sig_sem(SEM_FSSUPER_ID);
}
/*
Desc: Is playback finished?
TRUE - no play command queued and the stream file is closed.
FALSE - otherwise conditions.
caller: core task.
*/
BOOL FlashCard_IsPlayDone(void)
{
if((FALSE == gstCardHandler->gbPlayCommandPending )&& (NULL == gstCardHandler->pFileOnPlay))
return TRUE;
else
return FALSE;
}
BOOL FlashCard_IsReading(void)
{
if (NULL != gstCardHandler->pFileOnPlay)
return TRUE;
else
return FALSE;
}
BOOL FlashCard_IsPlayPaused(void)
{
if(FALSE == gstCardHandler->gbPlayCommandPending )
return TRUE;
else
return FALSE;
}
/*
Desc: Get the size of the part of the file that has been played.
In: None.
Out: None
Return: size in blocks. When the file is closed, returns 0.
*/
DWORD FlashCard_GetPlaybackSize(void)
{
UINT16 timeout = 100;
while(gstCardHandler->gbPlayCommandPending && timeout != 0)
{
timeout--;
usleep(10000ul);
}
if(NULL != gstCardHandler->pFileOnPlay)
{
UINT32 audio = MCU_ReadCodeBufferFullness(MCU_AUDIO_CODE_BUFFER, MCU_FULLNESS_IN_BYTES);
UINT32 video = MCU_ReadCodeBufferFullness(MCU_VIDEO_CODE_BUFFER, MCU_FULLNESS_IN_BYTES);
return (gstCardHandler->pFileOnPlay->pFileXPtr->fx_file_current_file_offset - audio - video) >> 11;
}
else
return 0;
}
#ifdef D_USE_USB_SDRAM_DECODER_BUFF
#ifndef D_NO_DISC
extern void FEF_DisableClientSlot(UINT16 slot_mask, UINT16 pmi_mask);
#else
static void FEF_DisableClientSlot(UINT16 slot_mask, UINT16 pmi_mask)
{
UINT16 slots_status;
outport(FE_MCU_SLOTS_CTRL, slot_mask);
do
{
slots_status = inport(FE_MCU_SLOTS_STATUS);
} while (((~slots_status) & slot_mask) || (slots_status & pmi_mask));
}
#endif
static void _FlashCard_InitDecoderSdramBuffer(void)
{
STATUS_REG SRkeep;
SRkeep = InterruptDisable();
// select BSI source
BSI_SetBitstreamPath (BITSTREAM_PATH_FE);
BSI_Reset(BSI_RESET_BTS_FIFO);
outport(FE_MCU_SEC_SIZE, (UINT16)USB_CARD_SECTOR_SIZE);
Serv_SetParamBits(FE_CONFIG,
(FE_CONFIG_MEDIA_DVD | FE_CONFIG_CLK_CD_BLOCK | FE_CONFIG_EDC_DESCRAMBLER_BYPASS_ON),
(FE_CONFIG_MEDIA_MASK | FE_CONFIG_CLK_MASK | FE_CONFIG_EDC_DESCRAMBLER_BYPASS_MASK),
&guiFEConfig);
//disable all clients
FEF_DisableClientSlot((FE_SLOTS_CTRL_ECC_DISABLE |
FE_SLOTS_CTRL_ERR_DISABLE |
FE_SLOTS_CTRL_EDC_DISABLE |
FE_SLOTS_CTRL_STP_DISABLE |
FE_SLOTS_CTRL_BTS_DISABLE),
(FE_SLOTS_STATUS_ECC_REQ_IN_PMI |
FE_SLOTS_STATUS_ERR_REQ_IN_PMI |
FE_SLOTS_STATUS_EDC_REQ_IN_PMI |
FE_SLOTS_STATUS_STP_REQ_IN_PMI |
FE_SLOTS_STATUS_BTS_REQ_IN_PMI));
outport(FE_MCU_IF_CONFIG, FE_MCU_IF_CONFIG_ALL_FLUSH );
// reset AV buffer
MCU_WritePointersRAM(MCU_PTR_FE_BUF_START_ADDR, DECODER_SDRAM_ADDR);
MCU_WritePointersRAM(MCU_PTR_FE_BUF_END_ADDR, DECODER_SDRAM_ADDR + DECODER_SDRAM_SIZE);
MCU_WritePointersRAM(MCU_PTR_BTS_RD_ADDR, DECODER_SDRAM_ADDR);
MCU_WritePointersRAM(MCU_PTR_BTS_STOP_ADDR, DECODER_SDRAM_ADDR);
//MCU_WritePointersRAM(MCU_PTR_STP_WR_ADDR, DECODER_SDRAM_ADDR);
//MCU_WritePointersRAM(MCU_PTR_STP_STOP_ADDR, DECODER_SDRAM_ADDR);
//MCU_WritePointersRAM(MCU_PTR_FTA_BUF_END_ADDR, DECODER_SDRAM_ADDR + DECODER_SDRAM_SIZE);
//MCU_WritePointersRAM(MCU_PTR_FTA_BUF_START_ADDR, DECODER_SDRAM_ADDR);
//MCU_WritePointersRAM(MCU_PTR_FTA_WR_ADDR, DECODER_SDRAM_ADDR);
//outport(TSI_MAX_AV_PACKETS_ADDR, (UINT16)1920);
//outport(TSI_MAX_SEC_PACKETS_ADDR, (UINT16)114);
// reset FE.
//outport(FE_CLOCK_DISABLE, FE_CLOCK_DISABLE_ALL);
//outport(FE_CLOCK_DISABLE, FE_CLOCK_DISABLE_BTS );
outport(FE_CLOCK_DISABLE, FE_CLOCK_DISABLE_EDC |
FE_CLOCK_DISABLE_BTS);
Serv_SetParamBits(FE_INIT, FE_INIT_BTS, FE_INIT_BTS, &guiFEInit);
//Serv_SetParamBits(FE_INIT, (FE_INIT_BTS | FE_INIT_ECC | FE_INIT_EDC), (FE_INIT_BTS | FE_INIT_ECC | FE_INIT_EDC), &guiFEInit);
Serv_ClearParamBits(FE_INIT, FE_INIT_BTS, &guiFEInit);
//Serv_ClearParamBits(FE_INIT, (FE_INIT_BTS | FE_INIT_ECC | FE_INIT_EDC), &guiFEInit);
// Reset sections buffer.
outport(FE_MCU_BUFF_CTRL, FE_BUFF_CTRL_RESET_STP_FULL | FE_BUFF_CTRL_SET_BTS_EMPTY);
//outport(FE_MCU_BUFF_CTRL, FE_BUFF_CTRL_INIT_ALL);
//outport(FE_CLOCK_DISABLE, (FE_CLOCK_DISABLE_ALL & (~FE_CLOCK_DISABLE_BTS)) );
outport(FE_CLOCK_DISABLE, FE_CLOCK_ENABLE_ALL );
//enable BTS client
//outport(FE_MCU_BUFF_CTRL, FE_BUFF_CTRL_RESET_BTS_EMPTY);
outport(FE_MCU_SLOTS_CTRL, /*FE_SLOTS_CTRL_STP_ENABLE|*/FE_SLOTS_CTRL_BTS_ENABLE);
// clear all interrupt
outport(FE_MCU_INT_STATUS, FE_MCU_INTR_BTS_PTR_STARV_MASK);
/* mask all interrupts and stop TB fullness monitoring. */
//Serv_WriteParam(FE_MCU_INT_MASK, FE_MCU_INTR_ALL_PTR_MASK, &FEF_IntMask);
#if 0
outport(FE_MCU_INT_MASK, 0x77);
setvect(FE_MCU_VEC, FEF_Isr);
outport(FE_MCU_CON, 0x0010 | FE_MCU_PRIORITY);
outport(IMASK,inport(IMASK) & (~IMASK_FE_MCU));
#endif
/*
MCU_WritePointersRAM(MCU_PTR_STP_WR_ADDR, DECODER_SDRAM_ADDR);
//MCU_WritePointersRAM(MCU_PTR_BTS_RD_ADDR, MEM_MngrSt.mapInfo->memTrackBuff[TB_DVP_ENTRY_FTA].ulStartAddress);
MCU_WritePointersRAM(MCU_PTR_STP_STOP_ADDR, DECODER_SDRAM_ADDR);
//outport(TSI_MAX_AV_PACKETS_ADDR, (UINT16)1920);
//MCU_WritePointersRAM(MCU_PTR_FTA_WR_ADDR, DECODER_SDRAM_ADDR);
//outport(TSI_MAX_SEC_PACKETS_ADDR, (UINT16)1920);
outport(FE_MCU_BUFF_CTRL, FE_BUFF_CTRL_RESET_STP_FULL |
FE_BUFF_CTRL_SET_BTS_EMPTY);
outport(FE_CLOCK_DISABLE, FE_CLOCK_DISABLE_EDC |
FE_CLOCK_DISABLE_BTS);
Serv_SetParamBits(FE_INIT, FE_INIT_BTS, FE_INIT_BTS, &guiFEInit);
Serv_ClearParamBits(FE_INIT, FE_INIT_BTS, &guiFEInit);
outport(FE_CLOCK_DISABLE, FE_CLOCK_ENABLE_ALL);
outport(FE_MCU_SLOTS_CTRL, (FE_SLOTS_CTRL_STP_ENABLE | FE_SLOTS_CTRL_BTS_ENABLE));
*/
gstCardHandler->dwOffsetInSdramBuff = 0;
set_SR(SRkeep);
g_timer0 = timing_get_clock();
g_timer2 = 0UL;
return;
}
void FlashCard_UpdateBtsBuff(UINT32 dwNewBtsStopAddr)
{
UINT32 dwBtsReadPtr;
STATUS_REG SRkeep;
SRkeep = InterruptDisable();
MCU_WritePointersRAM(MCU_PTR_BTS_STOP_ADDR, dwNewBtsStopAddr);
outport(FE_MCU_BUFF_CTRL, FE_BUFF_CTRL_RESET_BTS_EMPTY);
//outport(FE_MCU_BUFF_CTRL, FE_BUFF_CTRL_RESET_FREEZE_BTS);
MCU_ReadPointersRAM(MCU_PTR_BTS_RD_ADDR, &dwBtsReadPtr);
set_SR(SRkeep);
dbg_printf(("BTS read ptr = 0x%08lx, BTS stop ptr = 0x%08lx\n", dwBtsReadPtr, dwNewBtsStopAddr));
g_timer1= timing_get_clock();
g_timer2 += timing_get_diff(g_timer0, g_timer1);
if( (gstCardHandler->pFileOnPlay->dwCurrentPosition > (400UL*1024)) && (g_timer0 != 0xffffffffUL ))
{
tr_printf(("read 400KB timing is %ldus\n", g_timer2));
g_timer0 = 0xffffffffUL;
}
else if(g_timer0 != 0xffffffffUL )
g_timer0 = g_timer1;
return;
}
static UINT32 _FlashCard_GetAvailableSpaceInDecoderSdramBuff(UINT32 dwBtsStopPtr)
{
UINT32 dwBtsReadPtr;
UINT32 dwAvailableSpace;
MCU_ReadPointersRAM(MCU_PTR_BTS_RD_ADDR, &dwBtsReadPtr);
if( dwBtsStopPtr < dwBtsReadPtr )
dwAvailableSpace = dwBtsReadPtr - dwBtsStopPtr;
else
dwAvailableSpace = dwBtsReadPtr + DECODER_SDRAM_SIZE - dwBtsStopPtr;
//dwAvailableSpace = DECODER_SDRAM_SIZE - dwAvailableSpace;
dwAvailableSpace *= 2;
//snap to the sector border
dwAvailableSpace = (dwAvailableSpace/USB_CARD_SECTOR_SIZE) * USB_CARD_SECTOR_SIZE;
// need keep a gap between stop and read point.
if( dwAvailableSpace >= DECODER_SDRAM_GAP_SIZE )
dwAvailableSpace -= DECODER_SDRAM_GAP_SIZE;
else
{
dwAvailableSpace = 0;
dbg_printf(("FATAL: Decoder SDRAM gap is not enough!\n"));
}
return dwAvailableSpace;
}
#endif//D_USE_USB_SDRAM_DECODER_BUFF
#endif // #ifdef SUPPORT_FLASH_CARD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -