📄 dvb_device.c
字号:
enDeviceLun = (EN_PENDEV_LUN)(u32MsgData>>16);
enMediaType = (EN_MEDIA_TYPE)(u32MsgData&0x0000ffff);
switch(u8CmdID)
{
case DEVCTRL_OPEN:
enResult = dvb_devctrl_open(enMediaType, enDeviceLun);
if(EN_DEV_STATUS_SUCCESS == enResult)
{
stSendMsg.u8Cmd = DEVCTRL_OPEN_DONE;
stSendMsg.unData.u32MsgData = 0;
}
else
{
stSendMsg.u8Cmd = DEVCTRL_OPEN_ERROR;
stSendMsg.unData.u32MsgData = 0;
}
CT_OS_PutMsg(&DVB_DEVCTRL_Reply_MsgQueue, &stSendMsg, CTOS_NO_WAIT);
break;
case DEVCTRL_CLOSE:
enResult = dvb_devctrl_close(enMediaType);
break;
default:
break;
}
}
}
//--------------------------------------------------------------------
EN_PENDEV_STATUS dvb_devctrl_open(EN_MEDIA_TYPE enMediaType, EN_PENDEV_LUN enDeviceLun)
{
ST_PENDEV_HANDLEINFO *pstInfo = NULL;
void *pstPartition = NULL;
void *pstPathChainList = NULL;
void *pstFileInfoList = NULL;
void *pstDirInfoList = NULL;
void *pstFileHandleList = NULL;
ST_NODE *pstNode = NULL;
EN_FS_STATUS enFsState;
u8 u8DeviceLun = 0;
if(EN_DEV_CR_LUN0 == enDeviceLun)
{
if(FALSE == _ab8PenDeviceIsConnected[EN_DEV_CR_LUN0])
{
return EN_DEV_STATUS_FALSE;
}
}
else
{
if(FALSE == _ab8PenDeviceIsConnected[enDeviceLun-EN_DEV_USB_LUN0+1])
{
return EN_DEV_STATUS_FALSE;
}
}
if(DVB_PEBDEVICE_NO_HANDLE == _as8PenDeviceListNode[enMediaType])
{
DEVICE_MSG((" [STATUS]: Device %s(Media %s) Open\n",
enDeviceLun==EN_DEV_CR_LUN0?"CardReader":
(enDeviceLun>=EN_DEV_USB_LUN0)&&(enDeviceLun<=EN_DEV_USB_LUN31)?"USB":
"NOT SUPPORT",
enMediaType==EN_MEDIA_ALBUM?"ALBUM":
enMediaType==EN_MEDIA_MUSIC?"MUSIC":
enMediaType==EN_MEDIA_MOVIE?"MOVIE":
enMediaType==EN_MEDIA_SSU?"SSU":
enMediaType==EN_MEDIA_TS?"TS":
"NOT SUPPORT"));
// When the driver detect disk inserted, we will call this function to establish the partition and list
pstInfo = DVB_MemoryAllocate(sizeof(ST_PENDEV_HANDLEINFO));
if(NULL == pstInfo)
{
return EN_DEV_STATUS_FALSE;
}
// Get the memory of ST_PARTITION
pstPartition = DVB_MemoryAllocate(FS_GetPartitionHandleSize());
if(NULL == pstPartition)
{
DVB_MemoryFree(pstInfo);
return EN_DEV_STATUS_FALSE;
}
memset(pstPartition, 0x00, FS_GetPartitionHandleSize());
// Get the memory of ST_PENDEV_HANDLEINFO.pstPathChainList
pstPathChainList = DVB_MemoryAllocate(sizeof(ST_LIST_ITEM));
if(NULL == pstPathChainList)
{
DVB_MemoryFree(pstInfo);
DVB_MemoryFree(pstPartition);
return EN_DEV_STATUS_FALSE;
}
// Get the memory of ST_PENDEV_HANDLEINFO.pstFileInfoList
pstFileInfoList = DVB_MemoryAllocate(sizeof(ST_LIST_ITEM));
if(NULL == pstFileInfoList)
{
DVB_MemoryFree(pstInfo);
DVB_MemoryFree(pstPartition);
DVB_MemoryFree(pstPathChainList);
return EN_DEV_STATUS_FALSE;
}
// Get the memory of ST_PENDEV_HANDLEINFO.pstDirInfoList
pstDirInfoList = DVB_MemoryAllocate(sizeof(ST_LIST_ITEM));
if(NULL == pstDirInfoList)
{
DVB_MemoryFree(pstInfo);
DVB_MemoryFree(pstPartition);
DVB_MemoryFree(pstPathChainList);
DVB_MemoryFree(pstFileInfoList);
return EN_DEV_STATUS_FALSE;
}
// Get the memory of ST_PENDEV_HANDLEINFO.pstFileHandleList
pstFileHandleList = DVB_MemoryAllocate(sizeof(ST_LIST_ITEM));
if(NULL == pstFileHandleList)
{
DVB_MemoryFree(pstInfo);
DVB_MemoryFree(pstPartition);
DVB_MemoryFree(pstPathChainList);
DVB_MemoryFree(pstFileInfoList);
DVB_MemoryFree(pstDirInfoList);
return EN_DEV_STATUS_FALSE;
}
pstInfo->enMediaType = enMediaType;
pstInfo->enDeviceType = enDeviceLun;
pstInfo->b8Ready = FALSE;
pstInfo->pstDevicePartition = pstPartition;
pstInfo->pstPathChainList = pstPathChainList;
pstInfo->pstFileInfoList = pstFileInfoList;
pstInfo->pstDirInfoList = pstDirInfoList;
pstInfo->pstFileHandleList = pstFileHandleList;
if (enDeviceLun==EN_DEV_CR_LUN0)
{
u8DeviceLun = EN_DEV_CR_LUN0;
}
else
{
u8DeviceLun = enDeviceLun-EN_DEV_USB_LUN0;
}
if (enDeviceLun==EN_DEV_CR_LUN0)
{
sprintf(pstInfo->as8DeviceName, "%s%d", DVB_PENDEVICE_CARDR_NAME, u8DeviceLun);
}
else
{
sprintf(pstInfo->as8DeviceName, "%s%d", DVB_PENDEVICE_USB_NAME, u8DeviceLun);
}
_as8PenDeviceListNode[enMediaType] = _stPenDeviceChain.stPenDeviceList.Total;
DVB_LIST_GoTo_Nail(&_stPenDeviceChain.stPenDeviceList);
DVB_LIST_Add(&_stPenDeviceChain.stPenDeviceList, sizeof(ST_PENDEV_HANDLEINFO*), &pstInfo, NULL, EN_APPEND);
memset(pstPathChainList, 0x00, sizeof(ST_LIST_ITEM));
memset(pstFileInfoList, 0x00, sizeof(ST_LIST_ITEM));
memset(pstDirInfoList, 0x00, sizeof(ST_LIST_ITEM));
memset(pstFileHandleList, 0x00, sizeof(ST_LIST_ITEM));
}
else
{
pstNode = DVB_LIST_Get_Nth_Node(&_stPenDeviceChain.stPenDeviceList, (u16)_as8PenDeviceListNode[enMediaType]);
pstInfo = *(ST_PENDEV_HANDLEINFO**)DVB_LIST_Get_Obj(pstNode);
pstInfo->enMediaType = enMediaType;
pstInfo->enDeviceType = enDeviceLun;
pstInfo->b8Ready = FALSE;
LIST_DestoryList(pstInfo->pstPathChainList);
LIST_DestoryList(pstInfo->pstFileInfoList);
LIST_DestoryList(pstInfo->pstDirInfoList);
LIST_DestoryList(pstInfo->pstFileHandleList);
}
// initial fs
if(EN_DEV_CR_LUN0 == enDeviceLun)
{
#ifdef CARDREADER_ENABLE
_stCrDiskInfo.u8DevIdx = (enMediaType<<5)|(enDeviceLun-EN_DEV_CR_LUN0);
enFsState = DVB_FILECTRL_Init(EN_CARDREADER_DEVICE, &_stCrDiskInfo);
if( (EN_FS_STATUS_NO_DEVICE==enFsState) || (EN_FS_STATUS_NO_FS==enFsState) )
{
return EN_DEV_STATUS_FALSE;
}
#endif
}
else
{
#ifdef USB_ENABLE
DVB_USB_Change_LUN(enDeviceLun-EN_DEV_USB_LUN0);
_stUsbDiskInfo.u8DevIdx = (enMediaType<<5)|(enDeviceLun-EN_DEV_USB_LUN0);
enFsState = DVB_FILECTRL_Init(EN_USB_DEVICE, &_stUsbDiskInfo);
if( (EN_FS_STATUS_NO_DEVICE==enFsState) || (EN_FS_STATUS_NO_FS==enFsState) )
{
return EN_DEV_STATUS_FALSE;
}
#endif
}
pstInfo->b8Ready = TRUE;
return EN_DEV_STATUS_SUCCESS;
}
//--------------------------------------------------------------------
EN_PENDEV_STATUS dvb_devctrl_close(EN_MEDIA_TYPE enMediaType)
{
ST_PENDEV_HANDLEINFO *pstInfo = NULL;
ST_NODE *pstNode = NULL;
u16 u16Index, u16Node;
DEVICE_MSG((" [STATUS]: Media(%s) Close\n",
enMediaType==EN_MEDIA_ALBUM?"ALBUM":
enMediaType==EN_MEDIA_MUSIC?"MUSIC":
enMediaType==EN_MEDIA_MOVIE?"MOVIE":
enMediaType==EN_MEDIA_SSU?"SSU":
enMediaType==EN_MEDIA_TS?"TS":
"NOT SUPPORT"));
DVB_LIST_GoTo_Head(&_stPenDeviceChain.stPenDeviceList);
if(DVB_PEBDEVICE_NO_HANDLE != _as8PenDeviceListNode[enMediaType])
{
// Get the object of the handle_info
u16Node = _as8PenDeviceListNode[enMediaType];
pstNode = DVB_LIST_Get_Nth_Node(&_stPenDeviceChain.stPenDeviceList, (u16)u16Node);
pstInfo = *(ST_PENDEV_HANDLEINFO**)DVB_LIST_Get_Obj(pstNode);
if (pstInfo->enDeviceType == EN_DEV_CR_LUN0)
{
// CR
DVB_FILECTRL_Term(EN_CARDREADER_DEVICE, pstInfo->pstDevicePartition);
}
else
{
// USB
DVB_FILECTRL_Term(EN_USB_DEVICE, pstInfo->pstDevicePartition);
}
LIST_DestoryList(pstInfo->pstPathChainList);
LIST_DestoryList(pstInfo->pstFileInfoList);
LIST_DestoryList(pstInfo->pstDirInfoList);
LIST_DestoryList(pstInfo->pstFileHandleList);
DVB_MemoryFree(pstInfo->pstDevicePartition);
DVB_MemoryFree(pstInfo->pstPathChainList);
DVB_MemoryFree(pstInfo->pstFileInfoList);
DVB_MemoryFree(pstInfo->pstDirInfoList);
DVB_MemoryFree(pstInfo->pstFileHandleList);
DVB_LIST_Delete_Nth_Node(&_stPenDeviceChain.stPenDeviceList, (u16)u16Node);
DVB_MemoryFree(pstInfo);
_as8PenDeviceListNode[enMediaType] = EN_MEDIA_NOT_SUPPORT;
for(u16Index=0; u16Index<DVB_PEBDEVICE_MEDIA_MAX; u16Index++)
{
if((DVB_PEBDEVICE_NO_HANDLE!=_as8PenDeviceListNode[u16Index]) && (u16Node<_as8PenDeviceListNode[u16Index]))
{
_as8PenDeviceListNode[u16Index]--;
}
}
}
return EN_DEV_STATUS_SUCCESS;
}
//--------------------------------------------------------------------
bool8 DVB_DEVCTRL_HoldFs(bool8 b8Hold, EN_MEDIA_TYPE enMediaType)
{
if(b8Hold)
{
if (CT_OS_WaitOnSemaphore(&stFSHoldSemaphore, CTOS_WAIT) != EN_CTOS_SUCCESS)
return FALSE;
DVB_DEVCTRL_SwitchFs(enMediaType);
}
else
{
CT_OS_FreeSemaphore(&stFSHoldSemaphore);
}
return TRUE;
}
#ifdef PVR_ENABLE
EN_PENDEV_STATUS DVB_DEVCTRL_MsgShowNotify(DVB_DEVCTRL_MSG_NOTIFY pfNotifyFun)
{
if(NULL == pfNotifyFun)
{
return EN_DEV_STATUS_FALSE;
}
_fpMsgShowNotify = NULL;
_fpMsgShowNotify = pfNotifyFun;
return EN_DEV_STATUS_SUCCESS;
}
void DVB_DEVCTRL_Update_Partition_FreeSize(EN_PENDEV_LUN enDevLUN, u8 u8Partition, bool8 b8ShowMsg)
{
if((enDevLUN == EN_DEV_CR_LUN0) && (u8Partition < PARTITION_MAX_SUPPORT))
{
if(b8FreeCapacityForceUpdate[EN_DEV_CR_LUN0][u8Partition] == TRUE)
{
if(b8ShowMsg == TRUE)
{
if(_fpMsgShowNotify != NULL )
{
_fpMsgShowNotify(TRUE);
}
// ShowMessageBox(MSG_PLEASE_WAIT, 0);
}
DVB_FILECTRL_GetFreeCapacityWithCurrentPartition(EN_CARDREADER_DEVICE, TRUE);
if(b8ShowMsg == TRUE)
{
if(_fpMsgShowNotify != NULL)
{
_fpMsgShowNotify(FALSE);
}
// Popup_PasteBackground( );
}
b8FreeCapacityForceUpdate[EN_DEV_CR_LUN0][u8Partition] = FALSE;
}
}
else if(enDevLUN <= EN_DEV_USB_LUN31 && enDevLUN >= EN_DEV_USB_LUN0 && u8Partition < PARTITION_MAX_SUPPORT)
{
if(b8FreeCapacityForceUpdate[enDevLUN-EN_DEV_USB_LUN0+1][u8Partition] == TRUE)
{
if(b8ShowMsg == TRUE)
{
if(_fpMsgShowNotify != NULL )
{
_fpMsgShowNotify(TRUE);
}
// ShowMessageBox(MSG_PLEASE_WAIT, 0);
}
DVB_FILECTRL_GetFreeCapacityWithCurrentPartition(EN_USB_DEVICE, TRUE);
if(b8ShowMsg == TRUE)
{
if(_fpMsgShowNotify != NULL)
{
_fpMsgShowNotify(FALSE);
}
//Popup_PasteBackground( );
}
b8FreeCapacityForceUpdate[enDevLUN-EN_DEV_USB_LUN0+1][u8Partition] = FALSE;
}
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -