📄 dvb_device.c
字号:
#include <stdio.h>
#include "dvb_device.h"
#include "dvb_sys.h"
#include "task_cfg.h"
#ifdef CARDREADER_ENABLE
#include "dvb_cardreader.h"
#endif
#ifdef USB_ENABLE
#include "dvb_usb.h"
#endif
#include ".\FileSystem\file_control.h"
#ifdef CT216T_ELGIST_MM
#include "ct_os.h"
#endif
#include "list_ctrl.h"
//--------------------------------------------------------------------
#if 0
#define DEVICE_MSG(p)
#else
#define DEVICE_MSG(p) printf p
#endif
#if 1
#define DEVICE_DEBUG(p)
#else
#define DEVICE_DEBUG(p) printf p
#endif
#define DVB_PEBDEVICE_MAX 40
#define DVB_PEBDEVICE_MEDIA_MAX 7
#define DVB_PEBDEVICE_NO_PARTITION -1
#define DVB_PEBDEVICE_NO_HANDLE -1
#define DVB_PENDEVICE_CARDR_NAME "/dev/cardr"
#define DVB_PENDEVICE_USB_NAME "/dev/usb"
//--------------------------------------------------------------------
DVB_DEVCTRL_NOTIFY _fpDevicePluginNotify = NULL;
DVB_DEVCTRL_NOTIFY _fpDevicePlugoutNotify[DVB_PEBDEVICE_MEDIA_MAX] =
{
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
#ifdef PVR_ENABLE
DVB_DEVCTRL_MSG_NOTIFY _fpMsgShowNotify = NULL;
#endif
//--------------------------------------------------------------------
typedef struct
{
ST_LIST stPenDeviceList; // pen_device_handle_info list
} ST_PENDEV_CHAIN;
static ST_PENDEV_CHAIN _stPenDeviceChain;
static s8 _as8PenDeviceListNode[DVB_PEBDEVICE_MEDIA_MAX] =
{
EN_MEDIA_NOT_SUPPORT,
EN_MEDIA_NOT_SUPPORT,
EN_MEDIA_NOT_SUPPORT,
EN_MEDIA_NOT_SUPPORT,
EN_MEDIA_NOT_SUPPORT,
EN_MEDIA_NOT_SUPPORT,
EN_MEDIA_NOT_SUPPORT,
};
static bool8 _ab8PenDeviceIsConnected[DVB_PEBDEVICE_MAX] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
#define DEVCTRL_OPEN 0x01
#define DEVCTRL_OPEN_DONE 0x02
#define DEVCTRL_OPEN_ERROR 0x03
#define DEVCTRL_CLOSE 0x11
#define DEVCTRL_CLOSE_DONE 0x12
#define DEVCTRL_CLOSE_ERROR 0x13
#define DEVCTRL_QUEUE_SIZE 1024
static CTOS_QUEUE DVB_DEVCTRL_Request_MsgQueue;
static u32 u32DevCtrlRequestQueueMsg[DEVCTRL_QUEUE_SIZE];
static CTOS_QUEUE DVB_DEVCTRL_Reply_MsgQueue;
static u32 u32DevCtrlReplyQueueMsg[DEVCTRL_QUEUE_SIZE];
static CTOS_SEMAPHORE DVB_DEVCRL_Semaphore;
static CTOS_TASK DVB_DEVCTRL_Task;
static u8 _au8DevCtrlStack[DVB_DEVCTRL_TASK_STACK_SIZE];
#ifdef CARDREADER_ENABLE
static ST_FS_DEV_INFO _stCrDiskInfo;
#endif
#ifdef USB_ENABLE
static ST_FS_DEV_INFO _stUsbDiskInfo;
#endif
static bool8 _b8DevCtrlStackInitial = FALSE;
//static EN_MEDIA_TYPE _enMediaType;
//static EN_PENDEV_LUN _enDeviceLun;
#ifdef PVR_ENABLE
#define PARTITION_MAX_SUPPORT (10)
static bool8 b8FreeCapacityForceUpdate[DVB_PEBDEVICE_MAX][PARTITION_MAX_SUPPORT] = {{FALSE}};
//static bool8 b8FreeCapacityForceUpdate[DVB_PEBDEVICE_MAX] = {FALSE};
#endif
static CTOS_SEMAPHORE stFSHoldSemaphore;
static void dvb_devctrl_task(void);
static EN_PENDEV_STATUS dvb_devctrl_open(EN_MEDIA_TYPE enMediaType, EN_PENDEV_LUN enDeviceLun);
static EN_PENDEV_STATUS dvb_devctrl_close(EN_MEDIA_TYPE enMediaType);
//--------------------------------------------------------------------
EN_PENDEV_STATUS DVB_DEVCTRL_RegisterDevice(EN_PENDEV_LUN enDeviceLun)
{
DEVICE_DEBUG((" [STATUS]: %s %d\n", __FUNCTION__, enDeviceLun));
#ifdef PVR_ENABLE
u8 u8Index;
#endif
if(EN_DEV_CR_LUN0 == enDeviceLun)
{
_ab8PenDeviceIsConnected[EN_DEV_CR_LUN0] = TRUE;
#ifdef PVR_ENABLE
for(u8Index=0; u8Index < PARTITION_MAX_SUPPORT; u8Index++)
{
b8FreeCapacityForceUpdate[EN_DEV_CR_LUN0][u8Index] = TRUE;
}
//b8FreeCapacityForceUpdate[EN_DEV_CR_LUN0] = TRUE;
#endif
}
else
{
_ab8PenDeviceIsConnected[enDeviceLun-EN_DEV_USB_LUN0+1] = TRUE;
#ifdef PVR_ENABLE
for(u8Index=0; u8Index < PARTITION_MAX_SUPPORT; u8Index++)
{
b8FreeCapacityForceUpdate[enDeviceLun-EN_DEV_USB_LUN0+1][u8Index] = TRUE;
}
//b8FreeCapacityForceUpdate[enDeviceLun-EN_DEV_USB_LUN0+1] = TRUE;
#endif
}
if (NULL != _fpDevicePluginNotify)
{
_fpDevicePluginNotify(enDeviceLun);
}
return EN_DEV_STATUS_SUCCESS;
}
//--------------------------------------------------------------------
EN_PENDEV_STATUS DVB_DEVCTRL_UnRegisterDevice(EN_PENDEV_LUN enDeviceLun)
{
ST_PENDEV_HANDLEINFO *pstInfo = NULL;
ST_NODE *pstNode = NULL;
//DVB_DEVCTRL_NOTIFY fpNotify[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
u16 u16Index, u16PenDevCnt;
#ifdef PVR_ENABLE
u8 u8Index;
#endif
//DVB_LIST_GoTo_Head(&_stPenDeviceChain.stPenDeviceList);
//for(u16Index=0; u16Index<DVB_PEBDEVICE_MEDIA_MAX; u16Index++)
//{
// pstNode = DVB_LIST_Get_Nth_Node(&_stPenDeviceChain.stPenDeviceList, (u16)u16Index);
// pstInfo = *(ST_PENDEV_HANDLEINFO**)DVB_LIST_Get_Obj(pstNode);
//
// if( (enDeviceLun==pstInfo->enDeviceType) && (NULL!=_fpDeviceNotify[pstInfo->enMediaType]) )
// {
// fpNotify[u16Index] = _fpDeviceNotify[pstInfo->enMediaType];
// _fpDeviceNotify[pstInfo->enMediaType] = NULL;
// }
//}
DVB_LIST_GoTo_Head(&_stPenDeviceChain.stPenDeviceList);
//u16PenDevCnt = DVB_PEBDEVICE_MEDIA_MAX;
u16PenDevCnt = DVB_LIST_Get_Count(&_stPenDeviceChain.stPenDeviceList);
for(u16Index=0; u16Index<u16PenDevCnt; u16Index++)
{
pstNode = DVB_LIST_Get_Nth_Node(&_stPenDeviceChain.stPenDeviceList, u16Index);
pstInfo = *(ST_PENDEV_HANDLEINFO**)DVB_LIST_Get_Obj(pstNode);
if(enDeviceLun!=pstInfo->enDeviceType)
{
continue;
}
if(NULL!=_fpDevicePlugoutNotify[pstInfo->enMediaType])
{
_fpDevicePlugoutNotify[pstInfo->enMediaType](enDeviceLun);
_fpDevicePlugoutNotify[pstInfo->enMediaType] = NULL;
}
}
if(EN_DEV_CR_LUN0 == enDeviceLun)
{
_ab8PenDeviceIsConnected[EN_DEV_CR_LUN0] = FALSE;
#ifdef PVR_ENABLE
for(u8Index = 0 ; u8Index < PARTITION_MAX_SUPPORT; u8Index++)
{
b8FreeCapacityForceUpdate[EN_DEV_CR_LUN0][u8Index] = FALSE;
}
//b8FreeCapacityForceUpdate[EN_DEV_CR_LUN0] = FALSE;
#endif
}
else
{
_ab8PenDeviceIsConnected[enDeviceLun-EN_DEV_USB_LUN0+1] = FALSE;
#ifdef PVR_ENABLE
for(u8Index = 0 ; u8Index < PARTITION_MAX_SUPPORT; u8Index++)
{
b8FreeCapacityForceUpdate[enDeviceLun-EN_DEV_USB_LUN0+1][u8Index] = FALSE;
}
//b8FreeCapacityForceUpdate[enDeviceLun-EN_DEV_USB_LUN0+1] = FALSE;
#endif
}
return EN_DEV_STATUS_SUCCESS;
}
//--------------------------------------------------------------------
EN_PENDEV_STATUS DVB_DEVCTRL_LookupByMedia(EN_MEDIA_TYPE enMediaType, ST_PENDEV_HANDLEINFO *pstDeviceInfo)
{
ST_PENDEV_HANDLEINFO *pstInfo = NULL;
ST_NODE *pstNode = NULL;
DEVICE_DEBUG((" [STATUS]: %s %d\n", __FUNCTION__, enMediaType));
if( (NULL==pstDeviceInfo) || (EN_MEDIA_TS<enMediaType) )
{
return EN_DEV_STATUS_FALSE;
}
if(DVB_PEBDEVICE_NO_HANDLE != _as8PenDeviceListNode[enMediaType])
{
pstNode = DVB_LIST_Get_Nth_Node(&_stPenDeviceChain.stPenDeviceList, (u16)_as8PenDeviceListNode[enMediaType]);
pstInfo = *(ST_PENDEV_HANDLEINFO**)DVB_LIST_Get_Obj(pstNode);
// Compared with enMediaType
if(enMediaType == pstInfo->enMediaType)
{
pstDeviceInfo->enMediaType = pstInfo->enMediaType;
pstDeviceInfo->enDeviceType = pstInfo->enDeviceType;
pstDeviceInfo->b8Ready = pstInfo->b8Ready;
pstDeviceInfo->pstDevicePartition = pstInfo->pstDevicePartition;
pstDeviceInfo->pstPathChainList = pstInfo->pstPathChainList;
pstDeviceInfo->pstFileInfoList = pstInfo->pstFileInfoList;
pstDeviceInfo->pstDirInfoList = pstInfo->pstDirInfoList;
pstDeviceInfo->pstFileHandleList = pstInfo->pstFileHandleList;
memcpy(pstDeviceInfo->as8DeviceName, pstInfo->as8DeviceName, 16);
return EN_DEV_STATUS_SUCCESS;
}
}
// Not found any device matched with enDeviceLun
pstDeviceInfo->enMediaType = EN_MEDIA_NOT_SUPPORT;
pstDeviceInfo->enDeviceType = EN_DEV_NOT_SUPPORT;
pstDeviceInfo->b8Ready = FALSE;
pstDeviceInfo->as8DeviceName[0] = '\0';
pstDeviceInfo->pstDevicePartition = NULL;
pstDeviceInfo->pstPathChainList = NULL;
pstDeviceInfo->pstFileInfoList = NULL;
pstDeviceInfo->pstDirInfoList = NULL;
pstDeviceInfo->pstFileHandleList = NULL;
return EN_DEV_STATUS_FALSE;
}
//--------------------------------------------------------------------
EN_PENDEV_STATUS DVB_DEVCTRL_LookupByLun(EN_PENDEV_LUN enDeviceLun, ST_PENDEV_HANDLEINFO *pstDeviceInfo)
{
ST_PENDEV_HANDLEINFO *pstInfo = NULL;
ST_NODE *pstNode = NULL;
u16 u16Index;
DEVICE_DEBUG((" [STATUS]: %s %d\n", __FUNCTION__, enDeviceLun));
if(NULL == pstDeviceInfo)
{
return EN_DEV_STATUS_FALSE;
}
DVB_LIST_GoTo_Head(&_stPenDeviceChain.stPenDeviceList);
for(u16Index=0; u16Index<DVB_PEBDEVICE_MEDIA_MAX; u16Index++)
{
if(DVB_PEBDEVICE_NO_HANDLE != _as8PenDeviceListNode[u16Index])
{
// Get the object of the handle_info
pstNode = DVB_LIST_Get_Nth_Node(&_stPenDeviceChain.stPenDeviceList, (u16)_as8PenDeviceListNode[u16Index]);
pstInfo = *(ST_PENDEV_HANDLEINFO**)DVB_LIST_Get_Obj(pstNode);
if(enDeviceLun == pstInfo->enDeviceType)
{
pstDeviceInfo->enMediaType = pstInfo->enMediaType;
pstDeviceInfo->enDeviceType = pstInfo->enDeviceType;
pstDeviceInfo->b8Ready = pstInfo->b8Ready;
pstDeviceInfo->pstDevicePartition = pstInfo->pstDevicePartition;
pstDeviceInfo->pstPathChainList = pstInfo->pstPathChainList;
pstDeviceInfo->pstFileInfoList = pstInfo->pstFileInfoList;
pstDeviceInfo->pstDirInfoList = pstInfo->pstDirInfoList;
pstDeviceInfo->pstFileHandleList = pstInfo->pstFileHandleList;
memcpy(pstDeviceInfo->as8DeviceName, pstInfo->as8DeviceName, 16);
return EN_DEV_STATUS_SUCCESS;
}
}
}
// Not found any device matched with enDeviceLun
pstDeviceInfo->enMediaType = EN_MEDIA_NOT_SUPPORT;
pstDeviceInfo->enDeviceType = EN_DEV_NOT_SUPPORT;
pstDeviceInfo->b8Ready = FALSE;
pstDeviceInfo->as8DeviceName[0] = '\0';
pstDeviceInfo->pstDevicePartition = NULL;
pstDeviceInfo->pstPathChainList = NULL;
pstDeviceInfo->pstFileInfoList = NULL;
pstDeviceInfo->pstDirInfoList = NULL;
pstDeviceInfo->pstFileHandleList = NULL;
return EN_DEV_STATUS_FALSE;
}
//--------------------------------------------------------------------
EN_PENDEV_STATUS DVB_DEVCTRL_Open(EN_MEDIA_TYPE enMediaType, EN_PENDEV_LUN enDeviceLun)
{
MSG_PARAMETER stSendMsg, stRecvMsg;
EN_CTOS_STATUS enStatus;
u8 u8CmdID = 0;
u32 u32MsgData = 0;
u32 u32RecvMsgLen = 0;
EN_PENDEV_STATUS enResult = EN_DEV_STATUS_FALSE;
if (FALSE == _b8DevCtrlStackInitial)
{
DEVICE_DEBUG((" [ERROR]: %s - DVB_DEVCTRL not initial\n", __FUNCTION__));
return EN_DEV_STATUS_FALSE;
}
if (EN_CTOS_SUCCESS != CT_OS_WaitOnSemaphore(&DVB_DEVCRL_Semaphore, CTOS_WAIT))
{
DEVICE_DEBUG((" [ERROR]: %s - wait semaphore error\n", __FUNCTION__));
return EN_DEV_STATUS_FALSE;
}
//_enMediaType = enMediaType;
//_enDeviceLun = enDeviceLun;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -