📄 sdio_drv.c
字号:
{
cmd52.adrs = 0x100*function+i;
status=SDIO_Cmd52(&cmd52);
sdio_fbr_reg[i] = cmd52.data;
}
return status;
#else
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
}
/*************************************************************************
* FUNCTION
* SDIO_read_power_control
*
* DESCRIPTION
* This function is to read card's power control
*
* PARAMETERS
* None
*
* RETURNS
* SDC_CMD_STATUS
*
* GLOBALS AFFECTED
* only used for SDIO bus driver
*************************************************************************/
SDC_CMD_STATUS SDIO_read_power_control(void)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
cmd52.rw = SDIO_READ;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 0x12;
cmd52.data = 0;
status=SDIO_Cmd52(&cmd52);
gSDIO.power_control = cmd52.data;
return status;
}
/*************************************************************************
* FUNCTION
* SDIO_support_MPS
*
* DESCRIPTION
* This function is to query card's power control
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
* only used for SDIO bus driver
*************************************************************************/
kal_bool SDIO_support_MPS(void)
{
return ((gSDIO.power_control&0x1));
}
/*************************************************************************
* FUNCTION
* SDIO_enable_MPS
*
* DESCRIPTION
* This function is to enable card's power control
*
* PARAMETERS
* enable: enable or disable
*
* RETURNS
* SDC_CMD_STATUS
*
* GLOBALS AFFECTED
* only used for SDIO bus driver
*************************************************************************/
SDC_CMD_STATUS SDIO_enable_MPS(kal_bool enable)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
cmd52.rw = SDIO_WRITE;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 0x12;
if(enable)
cmd52.data |= 0x2;
else
cmd52.data &= ~0x2;
status=SDIO_Cmd52(&cmd52);
if(enable)
gSDIO.power_control |= 0x2;
else
gSDIO.power_control &= ~0x2;
return status;
}
/*************************************************************************
* FUNCTION
* SDIO_read_capacity
*
* DESCRIPTION
* This function is to read card's capacity
*
* PARAMETERS
* enable: None
*
* RETURNS
* SDC_CMD_STATUS
*
* GLOBALS AFFECTED
* only used for SDIO bus driver
*************************************************************************/
SDC_CMD_STATUS SDIO_read_capacity(void)
{
SDC_CMD_STATUS status=NO_ERROR;
#if 1
gSDIO.capability = sdio_cccr_reg[8];
#else
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
return status;
}
/*************************************************************************
* FUNCTION
* SDIO_support_SDC
*
* DESCRIPTION
* This function is to query if card can support SDC
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*query card capacity*/
kal_bool SDIO_support_SDC(void)
{
return ((gSDIO.capability&0x1));
}
/*************************************************************************
* FUNCTION
* SDIO_support_SMB
*
* DESCRIPTION
* This function is to query if card can support Multiple Block
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool SDIO_support_SMB(void)
{
return ((gSDIO.capability&0x2)>>1);
}
/*************************************************************************
* FUNCTION
* SDIO_support_SRW
*
* DESCRIPTION
* This function is to query if card can support Suspend/Resume
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool SDIO_support_SRW(void)
{
return ((gSDIO.capability&0x4)>>2);
}
/*************************************************************************
* FUNCTION
* SDIO_support_SBS
*
* DESCRIPTION
* This function is to query if card can support Read/Wait
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool SDIO_support_SBS(void)
{
return ((gSDIO.capability&0x8)>>3);
}
/*************************************************************************
* FUNCTION
* SDIO_support_S4MI
*
* DESCRIPTION
* This function is to query if card can support interrupt during multiple block
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool SDIO_support_S4MI(void)
{
return ((gSDIO.capability&0x10)>>4);
}
/*************************************************************************
* FUNCTION
* SDIO_enable_E4MI
*
* DESCRIPTION
* This function is to enable interrupt during multiple block
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
* only used for SDIO bus driver
*************************************************************************/
SDC_CMD_STATUS SDIO_enable_E4MI(kal_bool enable)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
kal_uint8 temp_data;
if(!SDIO_support_S4MI())
return SDIO_4MI_NOT_SUPPORT;
cmd52.rw = SDIO_WRITE;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 8;
if(enable)
{
cmd52.data = 0x20;
temp_data=0x20;
}
else
{
cmd52.data = 0;
temp_data=0;
}
if((status = SDIO_Cmd52(&cmd52))==NO_ERROR)
{
/*double check*/
cmd52.rw = SDIO_READ;
status = SDIO_Cmd52(&cmd52);
if((cmd52.data&0x20)!=temp_data)
ASSERT(0);
if(enable)
gSDIO.capability|=0x20;
else
gSDIO.capability&=~0x20;
}
return status;
}
/*************************************************************************
* FUNCTION
* SDIO_enable_E4MI
*
* DESCRIPTION
* This function is to query if card is a low speed card
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool SDIO_support_LSC(void)
{
return ((gSDIO.capability&0x40)>>6);
}
/*************************************************************************
* FUNCTION
* SDIO_support_4BLS
*
* DESCRIPTION
* This function is to query if card can support 4-bits in low speed card
*
* PARAMETERS
* None
*
* RETURNS
* support or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool SDIO_support_4BLS(void)
{
return ((gSDIO.capability&0x80)>>7);
}
/*************************************************************************
* FUNCTION
* SDIO_configure_bus
*
* DESCRIPTION
* This function is to configure bus width
*
* PARAMETERS
* bus: bus width
*
* RETURNS
* bus
*
* GLOBALS AFFECTED
*
*************************************************************************/
SDC_CMD_STATUS SDIO_configure_bus(SD_BITWIDTH bus)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
cmd52.rw = SDIO_READ;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 7;
if((status = SDIO_Cmd52(&cmd52))!=NO_ERROR)
{
return status;
}
cmd52.data &= ~0x3;
cmd52.data |= (bus|0x80);/*also disable card detection*/
cmd52.rw = SDIO_WRITE;
if((status = SDIO_Cmd52(&cmd52))!=NO_ERROR)
{
return status;
}
gSDIO.bit_width=bus;
if(bus==BIT_4W)
MSDC_SET_BIT32(SDC_CFG,SDC_CFG_MDLEN);
return NO_ERROR;
}
/*************************************************************************
* FUNCTION
* SDIO_enable_IO
*
* DESCRIPTION
* This function is to enable function
*
* PARAMETERS
* function: function id
* enable: enable or disable
* RETURNS
* SDC_CMD_STATUS
*
* GLOBALS AFFECTED
*
*************************************************************************/
SDC_CMD_STATUS SDIO_enable_IO(SDIO_function_id_enum function, kal_bool enable)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
SDIO_dispatch_IO(SDIO_FUCN_0);
cmd52.rw = SDIO_READ;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 2;
if((status = SDIO_Cmd52(&cmd52))!=NO_ERROR)
{
SDIO_resume_IO(SDIO_FUCN_0);
return status;
}
if(enable)
cmd52.data |= (function<<1);
else
cmd52.data &= ~(function<<1);
cmd52.rw = SDIO_WRITE;
if((status = SDIO_Cmd52(&cmd52))!=NO_ERROR)
{
SDIO_resume_IO(SDIO_FUCN_0);
return status;
}
SDIO_resume_IO(SDIO_FUCN_0);
return NO_ERROR;
}
/*************************************************************************
* FUNCTION
* SDIO_check_IO_ready
*
* DESCRIPTION
* This function is to check function status
*
* PARAMETERS
* function: function id
* *ready: ready or not
* RETURNS
* SDC_CMD_STATUS
*
* GLOBALS AFFECTED
*
*************************************************************************/
SDC_CMD_STATUS SDIO_check_IO_ready(SDIO_function_id_enum function, kal_bool *ready)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
SDIO_dispatch_IO(SDIO_FUCN_0);
cmd52.rw = SDIO_READ;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 3;
status = SDIO_Cmd52(&cmd52);
*ready=(cmd52.data&(1<<function))>>function;
SDIO_resume_IO(SDIO_FUCN_0);
return status;
}
/*************************************************************************
* FUNCTION
* SDIO_enable_IO_Int
*
* DESCRIPTION
* This function is to configure function interrupt enable
*
* PARAMETERS
* function: function id
* enable: enable or diable
* RETURNS
* SDC_CMD_STATUS
*
* GLOBALS AFFECTED
*
*************************************************************************/
SDC_CMD_STATUS SDIO_enable_IO_Int(SDIO_function_id_enum function, kal_bool enable)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
SDIO_dispatch_IO(SDIO_FUCN_0);
cmd52.rw = SDIO_READ;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 4;
if((status = SDIO_Cmd52(&cmd52))!=NO_ERROR)
{
SDIO_resume_IO(SDIO_FUCN_0);
return status;
}
if(enable)
cmd52.data |= (1<<function);
else
cmd52.data &= ~(1<<function);
cmd52.rw = SDIO_WRITE;
status = SDIO_Cmd52(&cmd52);
SDIO_resume_IO(SDIO_FUCN_0);
return status;
}
/*************************************************************************
* FUNCTION
* SDIO_int_registration
*
* DESCRIPTION
* This function is to register interrupt handler
*
* PARAMETERS
* function: function id
* func: interrupt handler
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void SDIO_int_registration(SDIO_function_id_enum function, void (func)(void))
{
gSDIO.callback[function]=func;
}
/*************************************************************************
* FUNCTION
* SDIO_HISR_Entry
*
* DESCRIPTION
* This function is to handle SDIO interrupt
*
* PARAMETERS
* None
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
SDC_CMD_STATUS int_status;
void SDIO_HISR_Entry(void)
{
cmd52_config_struct cmd52;
kal_uint32 count;
if(gSDIO.state!=CMD&&gSDIO.state!=TRN)
{
#ifdef MSDC_INT
kal_set_eg_events(MSDC_Events,EVENT_SDMCIRQ,KAL_OR);
#endif
}
else
{
#if 1
cmd52.rw = SDIO_READ;
cmd52.func = 0;
cmd52.raw = KAL_FALSE;
cmd52.stop = KAL_FALSE;
cmd52.adrs = 5;
if((int_status = SDIO_Cmd52_isr(&cmd52))==NO_ERROR)
{
for(count=SDIO_FUCN_1;count<SDIO_MAX_FUCN_ID;count++)
{
if(cmd52.data&(1<<count))
gSDIO.callback[count]();
}
}
else
{
/*dbg_print("int read failed\r\n");*/
}
#endif
}
}
/*************************************************************************
* FUNCTION
* SDIO_check_IO_Int
*
* DESCRIPTION
* This function is to check interrupt status
*
* PARAMETERS
* function: function id
* *pending: interrupt status
*
* RETURNS
* SDC_CMD_STATUS
*
* GLOBALS AFFECTED
*
*************************************************************************/
SDC_CMD_STATUS SDIO_check_IO_Int(SDIO_function_id_enum function, kal_bool *pending)
{
SDC_CMD_STATUS status;
cmd52_config_struct cmd52;
SDIO_dispatch_IO(SDIO_FUCN_0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -