📄 cardmng.c
字号:
/****************************************************************************/
INT CardIoCtrl(UINT16 driveno, UINT16 command, VOID *buffer)
{
driveno = driveno;
switch(command) {
/* 低级格式化 */
case FLASH_COMMAND_FORMAT:
return TRUE;
/* 查询相关信息 */
case FLASH_COMMAND_GETINFO:
if (!cardPartition.totalSector) {
return FALSE;
}
((MFlashInfo *)buffer)->uPageSize = 512; //must be 512
((MFlashInfo *)buffer)->uPageSum = cardPartition.totalSector;
return TRUE;
}
return FALSE;
}
/****************************************************************************/
/* FUNCTION: CardRawOpen */
/* DESCRIPTION:do nothing */
/* INPUTS: */
/* OUTPUTS: */
/* RETURN: */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ =========================*/
/* Victor 2004-07-30 create */
/****************************************************************************/
INT CardRawOpen(UINT16 driveno)
{
driveno = driveno;
return FALSE;
}
/****************************************************************************/
/* FUNCTION: CardOpen */
/* DESCRIPTION:power on the card and initialize the card */
/* INPUTS: driveno not used */
/* OUTPUTS: */
/* RETURN: */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ =====================*/
/* Victor 2004-07-30 create */
/****************************************************************************/
INT CardOpen(UINT16 driveno)
{
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
if(CardInitial() < 0){
return FALSE;
}
return TRUE;
}
/****************************************************************************/
/* FUNCTION: CardClose */
/* DESCRIPTION:power off the card */
/* INPUTS: */
/* OUTPUTS: */
/* RETURN: */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ============================*/
/* Victor 2004-07-30 create */
/****************************************************************************/
INT CardClose(UINT16 driveno)
{
driveno = driveno;
CardPowerOff();
return TRUE;
}
/****************************************************************************/
/* FUNCTION: CardIo */
/* DESCRIPTION:This function reads or writes data from and to the card */
/* based on the 'reading' parameter. */
/* INPUTS: driveno The number assigned to the card Disk */
/* dwLogicalPage The page number to read or write */
/* buffer Pointer to the data to be placed from */
/* a read or stored on a write */
/* uPages Number of page to be read or written */
/* reading Indicates whether or not we are reading */
/* or writing */
/* OUTPUTS: >= 0 I/O data length */
/*
/* RETURN: */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ============================*/
/* Victor 2004-07-30 create */
/****************************************************************************/
INT CardIo(UINT16 driveno, UINT32 dwLogicalPage, VOID *buffer, UINT16 uPages, INT reading)
{
INT i, offset;
UINT8 *pB;
UINT32 dwTotalLen;
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
pB = buffer;
dwTotalLen = 0;
offset = (dwLogicalPage + cardPartition.firstSector) * PAGE_SIZE;
while (uPages)
{
if (reading)
{
if(ReadBlock(offset, PAGE_SIZE, pB) < 0){
return dwTotalLen;
}
dwTotalLen += PAGE_SIZE;
}
else
{
if(WriteBlock(offset, PAGE_SIZE, pB) < 0){
return dwTotalLen;
}
dwTotalLen += PAGE_SIZE;
}
uPages--;
offset += PAGE_SIZE;
pB += PAGE_SIZE;
}
return dwTotalLen;
}
/****************************************************************************/
/* FUNCTION: CardCheck */
/* DESCRIPTION:check if the card is existent */
/* INPUTS: driveno not used */
/* OUTPUTS: NU_SUCCESS card is exsitent */
/* CARD_ERR_INEXISTENT card is not exsitent */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Victor 2004-07-30 create */
/****************************************************************************/
INT CardCheck(UINT16 driveno)
{
InitialIO();
if(__IsCardExist() == FALSE){
return CARD_ERR_INEXISTENT;
}
return(NU_SUCCESS);
}
/****************************************************************************/
/* FUNCTION: CardHISR */
/* DESCRIPTION:high level interrupt service rounting for inserting or */
/* taking out the card */
/* INPUTS: */
/* OUTPUTS: */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Victor 2004-07-31 create */
/****************************************************************************/
void CardHISR(void)
{
NU_Reset_Timer(&g_mCardTimer, __CardTimerFunc, 2, 2, NU_ENABLE_TIMER);
}
/****************************************************************************/
/* FUNCTION: CardLISR */
/* DESCRIPTION:low level interrupt service rounting for inserting or */
/* taking out the card */
/* INPUTS: vector not used */
/* OUTPUTS: */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Victor 2004-07-31 create */
/****************************************************************************/
void CardLISR(INT vector)
{
*((volatile UINT8 *)0x300270) &= ~0x01; // disable interrupt: EP0(D0) = 0
NU_Activate_HISR(&CardHISRControl); // active HISR
/*
if(*((UINT8 *)0x402c4) & 0x01){ // if card has not been inserted
*((volatile UINT8 *)0x402C8) &= ~0x01; // then interrupt trigered by low level: SPPT0(D0) = 0
}else{ // if card has been inserted
*((volatile UINT8 *)0x402C8) |= 0x01; // then interrupt trigered by high level: SPPT0(D0) = 1
}
zsj_del
*/
if (IsCardExist())
*((volatile UINT8 *)0x3003c2) &= ~0x01; // then interrupt trigered by low level: SPPT0(D0) = 0
else
*((volatile UINT8 *)0x3003c2) |= 0x01; // then interrupt trigered by high level: SPPT0(D0) = 1
*((volatile UINT8 *)0x300280) |= 0x01; // reset interrupt flag: FP0(D0) = 1
*((volatile UINT8 *)0x300270) |= 0x01; // enable interrupt: EP0(D0) = 1
}
/****************************************************************************/
/* FUNCTION: CardSetupService */
/* DESCRIPTION:setup card service */
/* INPUTS: */
/* OUTPUTS: TRUE setup */
/* FALSE not setup */
/****************************************************************************/
/* NAME DATE REMARKS */
/* ========== ============ ==============================================*/
/* Victor 2004-07-31 create */
/****************************************************************************/
BOOL CardSetupService(void)
{
UINT8 *pointer;
ISRFUNC pOldVector;
// if((pointer = MemAlloc(STACK_SIZE)) == NU_NULL){ //121
// return FALSE;
//}
if( NU_Allocate_Memory(&g_mpCommMemPool,&pointer,STACK_SIZE, NU_NO_SUSPEND) == NU_NULL)
{
return FALSE;
}
// Create card in/out HISR. This HISR is activated by the CardLISR associated with vector 16.
if(NU_Create_HISR(&CardHISRControl, "CARDINOUTHISR", CardHISR, 2, pointer, STACK_SIZE) != NU_SUCCESS){
// MemFree(pointer);
NU_Deallocate_Memory(pointer);
return FALSE;
}
/* Creat timer for check card status */
if (NU_Create_Timer(&g_mCardTimer,"CARD_TIMEOUT",__CardTimerFunc, 0,2,2,NU_DISABLE_TIMER) != NU_SUCCESS) {
// MemFree(pointer);
NU_Deallocate_Memory(pointer);
NU_Delete_HISR(&CardHISRControl);
return FALSE;
}
// Registe card in/out LISR
NU_Register_LISR(16, CardLISR, &pOldVector);
return TRUE;
}
VOID __CardTimerFunc(UNSIGNED Param)
{
UINT32 dwMsgX = CARD_INSERT;
BOOL bPort = __IsCardExist();
if (g_bCardConnect != bPort) {
if(!bPort) { // if card has not been inserted
// post card out message to project, project should close the card disk.
dwMsgX = CARD_REMOVE;
}
// g_bCardConnect = bPort;
#ifndef __FOR_BOOT__
MsgPost(NULL,EV_CARD,dwMsgX);
#endif
}
NU_Control_Timer(&g_mCardTimer, NU_DISABLE_TIMER);
}
BOOL IsCardExist(VOID)
{
if(MMC_IS_INSERT)
{ //133新板子要用p22
return TRUE;
}
return FALSE;
}
BOOL __IsCardExist(void)
{
return IsCardExist();
}
VOID SetCardStatus(BOOL bConnect)
{
g_bCardConnect = bConnect;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -