void nvram_util_give_mutex(kal_mutexid ext_mutex_id_ptr)
{
    if (!INT_QueryExceptionStatus() && !kal_query_systemInit() && ext_mutex_id_ptr)
    {
        kal_give_mutex(ext_mutex_id_ptr);
    }
}
Beispiel #2
0
/*************************************************************************
* FUNCTION
*  mdci_read_and_wait
*
* DESCRIPTION
*  This function reads data through either mailbox channel or stream
*  channel. ONLY USED WHEN NO INTERRUPT
*
* PARAMETERS
*  channel    -    logical channel
*  buff       -    pointer to channel buffer
*
* RETURNS
*  MDIF error code.
*
*************************************************************************/
kal_uint32 mdci_read_and_wait(MDCI_CHANNEL_T channel, MDCI_BUFF_T *buff, kal_uint32 ticks)
{
    MDCI_RETURNVAL_T ret;
    MDCI_BUFF_T *chdata;
    kal_uint32 index, cur_phych;
    volatile kal_uint32 reserved_value=0;
    volatile kal_uint32 chk_channel=0;
    

    /* query if used in init stage or exception */
    if (KAL_TRUE != kal_query_systemInit() && KAL_TRUE != INT_QueryExceptionStatus())
    {
    	return MDCI_API_INVALID;
    }
    

    /* check parameters */
    if (channel >= MDCI_MAX_CHANNEL)
        return MDCI_INVALID_PARAM;
    if (buff == NULL)
        return MDCI_INVALID_PARAM;


    /* check state */
    ret = MDCI_NOT_RECEIVE;
      
    
        
    while (ticks > 0)
    {
	    for (index = mdci_readindx_for_MD; index < mdci_readindx_for_MD + MDIF_MAX_PHY; index++)
    	{
		
       	    cur_phych = index % MDIF_MAX_PHY;
    		chdata = (MDCI_BUFF_T *)MDIF_RXCHDATA + cur_phych;
    		reserved_value = *(volatile kal_uint32 *)(&(chdata->reserved));
    		chk_channel = *(volatile kal_uint32 *)(&(chdata->channel));
        	if (reserved_value == MDCI_EXCEPTION_CHECK_ID && chk_channel == channel)
        	{
        		kal_mem_cpy(buff, chdata, sizeof(MDCI_BUFF_T));
			    mdci_readindx_for_MD = cur_phych;
			    *(volatile kal_uint32*)(&(chdata->reserved)) = 0;
			    return MDCI_SUCCESS;
        	}
    	}

        ust_busy_wait(1);
       	ticks--;	
    }

    
    
    return ret;
}
Beispiel #3
0
/*************************************************************************
* FUNCTION
*  mdci_is_chanel_need_check_owner
*
* DESCRIPTION
*  This function will return if the owner need to check
*
* PARAMETERS
*  none
*
* RETURNS
*  none
*
*************************************************************************/
static kal_bool mdci_is_chanel_need_check_owner(MDCI_CHANNEL_T channel)
{
	
#ifndef __IVP__
	if(INT_QueryExceptionStatus() == KAL_TRUE  || kal_query_systemInit() == KAL_TRUE)	
	{
		return KAL_FALSE;
	}
	else
#endif /* __IVP__ */
	{

		return KAL_FALSE;
	}

}
Beispiel #4
0
/*-----------------------------------*/
static int  ReadSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer)
{
	MSP_STATUS status;
	kal_uint8 retry = 0;
	kal_uint16 read; 

	gMSDC_Handle->timeout_count = 0;	
start:
	if(!gMSDC_Handle->mIsInitialized)
	{
		//dbg_print("Read but not Initialized \r\n");
		MSDC_PDNControl(KAL_TRUE);
		return FS_MSDC_READ_SECTOR_ERROR;
	}
	MSDC_PDNControl(KAL_FALSE);
	status = MSP_CMD_ReadWriteData(Sector,Sectors,(kal_uint32*)Buffer,&read,MSP_READ);
	if(status != MSP_NOERROR)
		goto err_exit;
	
	MSDC_PDNControl(KAL_TRUE);
   return FS_NO_ERROR;
   
err_exit:
	if(retry++ <= MAX_TRY && kal_query_systemInit()== KAL_FALSE)
	{
		gMSP.is_failed = KAL_TRUE;
		if(status == MSP_ERR_TIMEOUT || status == MSDC_GPT_TIMEOUT_ERR)
			gMSDC_Handle->timeout_count++;
		if(gMSDC_Handle->timeout_count == 3 && gMSDC_Handle->mIsPresent == KAL_TRUE)
		{
			kal_print("[MSDC]:re-mount(read fail)");
			gMSDC_Handle->mIsInitialized = KAL_FALSE;
			retry = 0;
			if(MSP_Initialize() != MSP_NOERROR)
				return FS_MSDC_READ_SECTOR_ERROR;
		}		
		
		//dbg_print("read sector failed! retry: %d \r\n",retry);	
		goto start;
	}	
	MSDC_PDNControl(KAL_TRUE);	
	return FS_MSDC_READ_SECTOR_ERROR   ;
}
Beispiel #5
0
/*
* FUNCTION
*  Drv_Deinit
*
* DESCRIPTION
*     This function is the deinitial function for all device drivers.
*     This function is called once to deinitialize the device driver.
*
* CALLS
*
* PARAMETERS
*  None
*
* RETURNS
*  None
*
* GLOBALS AFFECTED
*   external_global
*/
void Drv_Deinit(void)
{
   /* Don't do driver deinit when still in system initialization stage.
      Otherwise it may cause problem in NFI booting. */
   if (KAL_FALSE == kal_query_systemInit())
   {
      custom_drv_deinit();
#ifdef  __BTMODULE_MT6601__
      BT_Radio_Shutdown();
#endif
   }

   {
	DCL_HANDLE usb_hcd;

	usb_hcd = DclUSB_HCD_Open(DCL_USB, FLAGS_NONE);
	DclUSB_HCD_Control(usb_hcd, USB_HCD_CMD_USB_HCD_VBUS_OFF, NULL); // turn off Vbus 5V
	DclUSB_HCD_Close(usb_hcd);
   }
}
/*************************************************************************
* FUNCTION
*  DclPMU_Open
*
* DESCRIPTION
*  This function is to open the PMU module and return a handle
*
* PARAMETERS
*  dev: only valid for DCL_PMU
*  flags: no sepcial flags is needed. Please use FLAGS_NONE
*
* RETURNS
*  DCL_HANDLE_INVALID: Open failed.
*  other value: a valid handle
*
*************************************************************************/
DCL_HANDLE DclPMU_Open(DCL_DEV dev, DCL_FLAGS flags)
{
	kal_uint32 handle;
#if !defined(__UBL__)		
	kal_uint32 savedMask=0;
#endif //#endif //#if !defined(__UBL__)
	
	if (dev != DCL_PMU){
		return DCL_HANDLE_INVALID;		// Incorrecr device ID
	}


#if defined(__DRV_UPMU_SHARE_LDO__)	
	while(DCL_TRUE)
	{
	kal_uint32 i;
#if !defined(__UBL__)	
	if(KAL_FALSE==kal_query_systemInit())
	{savedMask = SaveAndSetIRQMask();}
#endif //#if !defined(__UBL__)

		dcl_pmu_handle_count++;
		handle = dcl_pmu_handle_count;
		
	
		for (i=0;i<PMU_MULTIUSERS_HANDLE_NO;i++)
		{
			if (LdoShareIdxTable[i] == handle)
				break;
		}


#if !defined(__UBL__)		
	if(KAL_FALSE==kal_query_systemInit())
	{RestoreIRQMask(savedMask);}
#endif //#if !defined(__UBL__)	

		if(i>=PMU_MULTIUSERS_HANDLE_NO)
		{break;}


	}
#else

#if !defined(__UBL__)	
	if(KAL_FALSE==kal_query_systemInit())
	{savedMask = SaveAndSetIRQMask();}
#endif //#if !defined(__UBL__)

	dcl_pmu_handle_count++;
	handle = dcl_pmu_handle_count;

#if !defined(__UBL__)		
	if(KAL_FALSE==kal_query_systemInit())
	{RestoreIRQMask(savedMask);}
#endif //#if !defined(__UBL__)	

#endif //#if defined(__DRV_UPMU_SHARE_LDO__)	

	

	// Register DCL default lisr
	return handle;
}
Beispiel #7
0
/*
only allow two case:
case 1: Sectors == 1
case 2: Sectors == gMS.PagesPerBlk

*/
static int  WriteSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer)
{	
	MS_STATUS status;
	kal_uint8 PagesPerBlk,page,pages,extra[4],owflag,len;
	kal_uint32 lba,pba,i,spareblk;
	kal_uint8 *p = NULL,*ptr;
	kal_uint16 *LPTable,*FreeTable;
	kal_uint8 retry = 0;
	
	gMSDC_Handle->timeout_count = 0;
START:	
	if(!gMSDC_Handle->mIsInitialized)
	{
		//dbg_print("Write but not Initialized \r\n");
		MSDC_PDNControl(KAL_TRUE);
		return FS_MSDC_WRITE_SECTOR_ERROR;
	}
	gMS.is_write = KAL_TRUE;
	LPTable = gMS.pLPTbl;
	FreeTable = gMS.pFreeTbl;
	PagesPerBlk = gMS.PagesPerBlk;
	ptr = (kal_uint8*)Buffer;
	p = (kal_uint8 * )MS_buffer;

	// get physical block address from sector	
	lba = Sector/PagesPerBlk;
	len = page = Sector%PagesPerBlk;
	MSDC_PDNControl(KAL_FALSE);
	while(1)
	{
		if(PagesPerBlk - page < Sectors)
			len = PagesPerBlk - page;
		else
			len = Sectors;			
		ASSERT(len >= 1 && len <= 32);
		status = MS_API_LogToPhy(LPTable,lba,&pba);
		if(status != MS_NOERROR)
			goto ERR_EXIT;

		// set update status to 0
		MS_API_ReadExtraData(pba, 0, (kal_uint32 *)extra);
		owflag = extra[0];
		extra[0] &= ~MS_OVFLG_UDST;
		MS_API_WriteOWF(pba, 0, extra[0]);
		
		// read the entire block
		status = MS_API_ReadBlock(pba,(kal_uint32*)p, (kal_uint32 *)extra, 0, PagesPerBlk, &pages);
		if(status != MS_NOERROR)
		{
			goto ERR_EXIT;
		}
		if(gMS.uc_pages != 0)
		{
			MS_API_LogToPhy(LPTable,lba,&pba);
			MS_API_ReadExtraData(pba, 0, (kal_uint32 *)extra);
			owflag = extra[0];
			extra[0] &= ~MS_OVFLG_UDST;
			status = MS_API_WriteExtraData(pba, 0, (kal_uint32 *)extra);
		}
		// update the page in the memory
		kal_mem_cpy((kal_uint8*)(p+page*MS_PAGE_SIZE), (kal_uint8*)ptr, MS_PAGE_SIZE*len);
		// find a unused block from FreeTable, erase it and write updated info into it
		i = 0;
		while((FreeTable[i++] == 0xFFFF) && (i < MS_FREETABLE_SIZE));
		spareblk = FreeTable[i-1];
		status = MS_API_EraseBlock(spareblk);
		if(status != MS_NOERROR)
			goto ERR_EXIT;
		extra[0] = (owflag|MS_OVFLG_UDST);
		status = MS_API_WriteBlock(spareblk, (kal_uint32*)p, (kal_uint32*)extra, 0, PagesPerBlk, &pages);
		if(status != MS_NOERROR)
			goto ERR_EXIT;
		// update the LPTable and FreeTable
		LPTable[MS_GetLPIndex(lba)] = spareblk;
		FreeTable[i-1] = pba;
		// erase original block
		status = MS_API_EraseBlock(pba);
		if(status != MS_NOERROR)
			goto ERR_EXIT;
		if(gMS.uc_pages || gMS.de_pages)
		{
			kal_uint32 pages;
			if(gMS.uc_pages)
				pages = gMS.uc_pages;
			else
				pages = gMS.de_pages;
			for(i=0;i<32;i++)
			{
				if(pages & (1<<i))
				{
					MS_API_ReadExtraData(spareblk, i, (kal_uint32 *)extra);
					extra[0] &= ~MS_OVFLG_PGST;
					MS_API_WriteExtraData(spareblk, i, (kal_uint32 *)extra);				
				}
			}
		}
		MS_API_ReadExtraData(spareblk, 0x18, (kal_uint32 *)extra);
		Sectors -= len;
		if(Sectors == 0) break;
		ptr += 	MS_PAGE_SIZE*len;		
		page = 0;
		lba++;			
	} // end of while
	MSDC_PDNControl(KAL_TRUE);
   return FS_NO_ERROR;
   
ERR_EXIT:
	//dbg_print("W: fail %d\r\n",retry);
	if(retry++ <= MAX_TRY && kal_query_systemInit()== KAL_FALSE)
	{
		if(status == MS_ERR_TIMEOUT || status == MSDC_GPT_TIMEOUT_ERR)
			gMSDC_Handle->timeout_count++;
		if(gMSDC_Handle->timeout_count == 3 && gMSDC_Handle->mIsPresent == KAL_TRUE)
		{
			kal_print("[MSDC]:re-mount(write fail)");
			gMSDC_Handle->mIsInitialized = KAL_FALSE;
			retry = 0;
			if(MS_Initialize() != NO_ERROR)
				return FS_MSDC_READ_SECTOR_ERROR;
		}		
		//dbg_print("W: fail retry:%d adrs:%d sectors: %d \r\n",retry,Sector, Sectors);
		goto START;
	}
	MSDC_PDNControl(KAL_TRUE);
	return FS_MSDC_WRITE_SECTOR_ERROR;
	
}
Beispiel #8
0
/*-----------------------------------*/
static int  ReadSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer)
{
	MS_STATUS status;
	kal_uint8 PagesPerBlk,page,readpage,len,*ptr, extra[4];
	kal_uint32 lba,pba;
	kal_uint8 retry = 0;
	
	gMSDC_Handle->timeout_count = 0;
START:	
	if(!gMSDC_Handle->mIsInitialized)
	{
		//dbg_print("Read but not Initialized \r\n");
		MSDC_PDNControl(KAL_TRUE);
		return FS_MSDC_READ_SECTOR_ERROR;
	}
	gMS.is_write = KAL_FALSE;
	PagesPerBlk = gMS.PagesPerBlk;
	lba = Sector/PagesPerBlk;
	page = Sector%PagesPerBlk;
	ptr = (kal_uint8*) Buffer;
	MSDC_PDNControl(KAL_FALSE);
	while(1)
	{
		if(PagesPerBlk - page < Sectors)
			len = PagesPerBlk - page;
		else
			len = Sectors;			
		ASSERT(len >= 1 && len <= 32);
		status = MS_API_LogToPhy(gMS.pLPTbl,lba,&pba);
		if(status != MS_NOERROR)
			goto ERR_EXIT;//return FS_MSDC_READ_SECTOR_ERROR;
		if(len == 1)
			status = MS_API_ReadSinglePage(pba,page,(kal_uint32*)ptr,NULL);
		else
			status = MS_API_ReadBlock(pba, (kal_uint32*)ptr, NULL, page, len, &readpage);	
		if(status != MS_NOERROR)
			goto ERR_EXIT;//return FS_MSDC_READ_SECTOR_ERROR;
		//============ change the update status ====================//
		MS_API_ReadExtraData(pba, 0, (kal_uint32*)extra);
    	if(MS_UPDATE_STATUS(extra[OVERWRITE_FLAG]) == 0)
    	{
    		kal_uint32 i;
    		kal_uint16 *FreeTable, *LPTable, spareblk;
    		kal_uint8  readpage;
			// find a unused block from FreeTable, erase it and write updated info into it

			LPTable = gMS.pLPTbl;
			FreeTable = gMS.pFreeTbl;			
			i = 0;
			while((FreeTable[i++] == 0xFFFF) && (i < MS_FREETABLE_SIZE));
			spareblk = FreeTable[i-1];
			MS_API_ReadBlock(pba,(kal_uint32*)MS_buffer, (kal_uint32 *)extra, 0, PagesPerBlk, &readpage);
			extra[0] |= MS_OVFLG_UDST;
			MS_API_WriteExtraData(spareblk, 0, (kal_uint32 *)extra);
			MS_API_WriteBlock(spareblk,(kal_uint32*)MS_buffer, (kal_uint32 *)extra, 0, PagesPerBlk, &readpage);				
			MS_API_EraseBlock(pba);
			// update the LPTable and FreeTable
			LPTable[MS_GetLPIndex(lba)] = spareblk;
			FreeTable[i-1] = pba;    		
    	}
		//================================//
		Sectors -= len;
		if(Sectors == 0) break;
		page = 0;
		ptr += 	MS_PAGE_SIZE*len;
		lba++;	
	}
	MSDC_PDNControl(KAL_TRUE);
   return FS_NO_ERROR;
   
ERR_EXIT:		
	if(retry++ <= MAX_TRY && kal_query_systemInit()== KAL_FALSE)
	{		
		if(status == MS_ERR_TIMEOUT || status == MSDC_GPT_TIMEOUT_ERR)
			gMSDC_Handle->timeout_count++;
		if(gMSDC_Handle->timeout_count == 3 && gMSDC_Handle->mIsPresent == KAL_TRUE)
		{
			kal_print("[MSDC]:re-mount(read fail)");
			gMSDC_Handle->mIsInitialized = KAL_FALSE;
			retry = 0;
			if(MS_Initialize() != NO_ERROR)
				return FS_MSDC_READ_SECTOR_ERROR;
		}
		
		//dbg_print("R: fail retry:%d adrs:%d sectors: %d \r\n",retry,Sector, Sectors);
		goto START;
	}
	MSDC_PDNControl(KAL_TRUE);
	return FS_MSDC_READ_SECTOR_ERROR;
}
static int  WriteSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer)
{
    SDC_CMD_STATUS status;
    kal_uint8 retry = 0;
    kal_uint32 adrs;

#ifdef MSDC_CACHED_SUPPORT
    /*tell buffer type each time this function called*/
    if (INT_QueryIsCachedRAM(Buffer, Sectors * SECTOR_SIZE)) {
        msdc2_handle->isCachedBuf = KAL_TRUE;

    }
    else
        msdc2_handle->isCachedBuf = KAL_FALSE;
#endif

#if defined(SD_MMC_HIGH_DENSITY_SUPPORT)
    if(gSD2->flags & SD_FLAG_HCS_SUPPORT)
        adrs = Sector;
    else
#endif
        adrs = Sector * SECTOR_SIZE;
    msdc2_handle->timeout_count = 0;
start:
    if(!msdc2_handle->mIsInitialized)
    {
        //dbg_print("Write but not Initialized \r\n");
        MSDC_PDNControl2(KAL_TRUE);
        return FS_MSDC_WRITE_SECTOR_ERROR;
    }
    retry++;
    MSDC_PDNControl2(KAL_FALSE);
    if(Sectors > 1)
    {
        if(msdc2_handle->mMSDC_type == SD_CARD)
            SD_SetPreEraseBlk_2(Sectors);
        status = SD_WriteMultiBlock_2((kal_uint32)adrs,(kal_uint32*)Buffer,(kal_uint32)Sectors);
    }
    else
        status = SD_WriteSingleBlock_2((kal_uint32)adrs,(kal_uint32*)Buffer);
    if(status != NO_ERROR)
    {
        sd_w++;
        if(kal_query_systemInit()== KAL_TRUE)
        {
            MSDC_PDNControl2(KAL_TRUE);
            return FS_MSDC_WRITE_SECTOR_ERROR;
        }
        if(status == ERR_CMD_TIMEOUT || status == MSDC_GPT_TIMEOUT_ERR)
            msdc2_handle->timeout_count++;
        if(msdc2_handle->timeout_count++ == 3 && msdc2_handle->mIsPresent == KAL_TRUE)
        {
            tst_sys_trace("[MSDC]:SD re-mount (write fail)");
            msdc2_handle->mIsInitialized = KAL_FALSE;
            retry = 0;
            if(SD_Initialize_2() != NO_ERROR)
            {
                MSDC_PDNControl2(KAL_TRUE);
                return FS_MSDC_WRITE_SECTOR_ERROR;
            }
        }
        if(retry >= SD_MAX_RETRY)
        {
            MSDC_PDNControl2(KAL_TRUE);
            return FS_MSDC_WRITE_SECTOR_ERROR;
        }
        else
        {
            // kal_prompt_trace(MOD_AUD,"CRC write Error retry %d",retry);
            goto start;
        }
    }
    MSDC_PDNControl2(KAL_TRUE);
    return FS_NO_ERROR;
}
Beispiel #10
0
/*-----------------------------------*/
static int  MountDevice(void * DriveData, int DeviceNumber, int DeviceType, DWORD Flags)
{
    kal_uint8 retry = 0;

#if defined(__SIM_PLUS__)
    sd_select_enum sel;

    if((MSDC_HANDLE *)DriveData == &MSDC_Blk[0])
        sel = SD_EXT;
    else
    {
        sel = SD_SIM;
    }
    MSDC_Switch_Card(sel);
#endif


#ifdef DRV_LSD
    /*notifiedFMT may be modified by FMT and MMI tasks, but it is no need to protect this, FMT can't preempt MMI*/
    if(1 == notifiedFMT)/*in this state. we dont allow any access on memory card, we will return fail on any mount trial*/
    {
        return FS_MSDC_MOUNT_ERROR;
    }
#endif

    if(gMSDC_Handle->mIsInitialized)
        return SECTOR_SIZE;
    gMSDC_Handle->is_init_timeout = KAL_FALSE;
start:
    if(!gMSDC_Handle->mIsPresent)
    {
        //dbg_print("not present \r\n");

#if defined(_NAND_FLASH_BOOTING_)
        // add the following code for solving plug in or out the SD card during
        // NFB loading process. The card detection interruptwill disapperared
        // while interrupt controller is masked.
        IRQMask(IRQ_MSDC_CODE);
        if(*(volatile kal_uint16*)MSDC_PS & MSDC_PS_PIN0)
        {
            if(gMSDC_Handle->ins_level == MSDC_IOCTRL_PULL_UP)
                gMSDC_Handle->mIsPresent = KAL_FALSE;
            else
                gMSDC_Handle->mIsPresent = KAL_TRUE;
        }
        else
        {
            if(gMSDC_Handle->ins_level == MSDC_IOCTRL_PULL_UP)
                gMSDC_Handle->mIsPresent = KAL_TRUE;
            else
                gMSDC_Handle->mIsPresent = KAL_FALSE;
        }
        IRQUnmask(IRQ_MSDC_CODE);
#endif // _NAND_FLASH_BOOTING_

        if(!gMSDC_Handle->mIsPresent)
        {
            MSDC_PDNControl(KAL_TRUE);
            return FS_MSDC_MOUNT_ERROR;
        }
    }
    MSDC_PDNControl(KAL_FALSE);
    if(SD_Initialize() != NO_ERROR)
    {
        goto err_exit;
    }
    //if(SD_MountDevice(DeviceType) != FS_NO_ERROR)
    //return FS_MSDC_MOUNT_ERROR;

    //dbg_print("Mount success! \r\n");

#ifdef MSDC_SDMMC_NAND
    /*for SDMMC NAND, some manufacturs sale NAND with all sectors zero, we should format it first*/
    if(ReadSectors( DriveData, 0, 1, MSDC_Sector) != NO_ERROR)
        goto err_exit;
    if(0x55aa != (MSDC_Sector[128] & 0xffff0000)) { /*it doesn't have correct MBR*/
        SD_SelfFormat();
    }
    else {
        if(ReadSectors( DriveData, 1, 1, MSDC_Sector) != NO_ERROR)
            goto err_exit;
        if(0x55aa != (MSDC_Sector[128] & 0xffff0000)) { /*it doesn't have correct PBR*/
            SD_SelfFormat();
        }
    }
#endif

    MSDC_PDNControl(KAL_TRUE);

#ifdef DRV_LSD
    if(KAL_TRUE == kal_query_systemInit()) { /*we don't let access memory card before FMT get plug in message*/
        /*there is no task can access when system init*/
        notifiedFMT = 1;
        return FS_MSDC_MOUNT_ERROR;
    }
#endif

    return SECTOR_SIZE;

err_exit:
    if(retry++ <= SD_MAX_RETRY && gMSDC_Handle->is_init_timeout == KAL_FALSE)
    {
        //dbg_print("SD MountDevice failed! retry: %d \r\n",retry);
        goto start;
    }
#if defined(__MSDC_NOT_SUPPORT_HOT_PLUG__)
    gMSDC_Handle->mIsPresent = KAL_FALSE;
#endif

#if defined(__SIM_PLUS__)

    if(INT_USBBoot() == KAL_TRUE && current_card == SD_SIM)
    {
        gMSDC_Handle->mIsPresent = KAL_FALSE;
    }
#endif

    MSDC_PDNControl(KAL_TRUE);
    return FS_MSDC_MOUNT_ERROR;

}
Beispiel #11
0
/*-----------------------------------*/
static int  WriteSectors(void * DriveData, DWORD Sector, UINT Sectors, void * Buffer)
{
    SDC_CMD_STATUS status;
    kal_uint8 retry = 0;
    kal_uint32 adrs;

#if defined(__SIM_PLUS__)
    sd_select_enum sel;

    if((MSDC_HANDLE *)DriveData == &MSDC_Blk[0])
        sel = SD_EXT;
    else
        sel = SD_SIM;
    MSDC_Switch_Card(sel);
#endif

#if defined(SD_MMC_HIGH_DENSITY_SUPPORT)
    if(gSD->flags & SD_FLAG_HCS_SUPPORT)
        adrs = Sector;
    else
#endif
        adrs = Sector * SECTOR_SIZE;
    gMSDC_Handle->timeout_count = 0;
start:
    if(!gMSDC_Handle->mIsInitialized)
    {
        //dbg_print("Write but not Initialized \r\n");
        MSDC_PDNControl(KAL_TRUE);
        return FS_MSDC_WRITE_SECTOR_ERROR;
    }
    retry++;
    MSDC_PDNControl(KAL_FALSE);
#ifndef LSD_SINGLE_WRITE
    if(Sectors > 1)
    {
        if(gMSDC_Handle->mMSDC_type == SD_CARD)
            SD_SetPreEraseBlk(Sectors);
        status = SD_WriteMultiBlock((kal_uint32)adrs,(kal_uint32*)Buffer,(kal_uint32)Sectors);
    }
    else
        status = SD_WriteSingleBlock((kal_uint32)adrs,(kal_uint32*)Buffer);
#else
    while(Sectors) {
        status = SD_WriteSingleBlock((kal_uint32)adrs,(kal_uint32*)Buffer);

        if(status != NO_ERROR )
            break;
        (kal_uint8 *)Buffer += SECTOR_SIZE;
        Sector ++;
#if defined(SD_MMC_HIGH_DENSITY_SUPPORT)
        if(gSD->flags & SD_FLAG_HCS_SUPPORT)
            adrs = Sector;
        else
#endif
            adrs = Sector * SECTOR_SIZE;

        Sectors--;
    }
#endif
    if(status != NO_ERROR)
    {
        sd_w++;
        if(kal_query_systemInit()== KAL_TRUE)
        {
            MSDC_PDNControl(KAL_TRUE);
            return FS_MSDC_WRITE_SECTOR_ERROR;
        }
        //dbg_print("write retry:%d,status:%d,total %d\r\n",retry,status,sd_w);
        if(status == ERR_CMD_TIMEOUT || status == MSDC_GPT_TIMEOUT_ERR)
            gMSDC_Handle->timeout_count++;
        if(gMSDC_Handle->timeout_count++ == 3 && gMSDC_Handle->mIsPresent == KAL_TRUE)
        {
            kal_print("[MSDC]:SD re-mount (write fail)");
            gMSDC_Handle->mIsInitialized = KAL_FALSE;
            retry = 0;
            if(SD_Initialize() != NO_ERROR)
            {
                MSDC_PDNControl(KAL_TRUE);
                return FS_MSDC_WRITE_SECTOR_ERROR;
            }
        }
        if(retry >= SD_MAX_RETRY)
        {
            MSDC_PDNControl(KAL_TRUE);
            return FS_MSDC_WRITE_SECTOR_ERROR;
        }
        else
        {
            // kal_prompt_trace(MOD_AUD,"CRC write Error retry %d",retry);
            goto start;
        }
    }
    MSDC_PDNControl(KAL_TRUE);
    return FS_NO_ERROR;
}
Beispiel #12
0
/*************************************************************************
* FUNCTION
*  ds_mdci_write_and_wait
*
* DESCRIPTION
*  This function writes data through either mailbox channel or stream
*  channel. ONLY USED WHEN NO INTERRUPT
*
* PARAMETERS
*  channel    -    logical channel
*  buff       -    pointer to channel buffer
*
* RETURNS
*  MDIF error code.
*
*************************************************************************/
kal_int32 mdci_write_and_wait(MDCI_CHANNEL_T channel, MDCI_BUFF_T *buff, kal_uint32 ticks)
{
    kal_uint32 mdci_busy, phy_chann, saveaddr = 0;
    kal_int32 ret;
    MDCI_BUFF_T *chdata;
    volatile kal_uint32 reserved_value=0;


    

    /* query if used in init stage or exception */
    if (KAL_TRUE != kal_query_systemInit() && KAL_TRUE != INT_QueryExceptionStatus())
    {
    	return MDCI_API_INVALID;
    }
    
       
    
    /* check parameters */
    if (channel >= MDCI_MAX_CHANNEL)
        return MDCI_INVALID_PARAM;
    if (buff == NULL)
        return MDCI_INVALID_PARAM;


    *MDIF_ACK = 0xFFFFFFFF;



    /* check state */
    ret = MDCI_NOT_RECEIVE;
    buff->reserved = MDCI_EXCEPTION_CHECK_ID;

    /* get one physical channel */
    
    mdci_busy = *MDIF_BUSY;
    if (0xFF == mdci_busy)
    {
    	  return MDCI_NO_PHY_CHANNEL;
    }
    
    
    for (phy_chann = mdci_writeindx_for_FC ; phy_chann < (mdci_writeindx_for_FC + MDIF_MAX_PHY); phy_chann++) 
    {
	    phy_chann %= MDIF_MAX_PHY;
        chdata = (MDCI_BUFF_T *)MDIF_TXCHDATA + phy_chann;
        
        reserved_value = *(volatile kal_uint32*)(&(chdata->reserved));
        if (reserved_value == MDCI_EXCEPTION_CHECK_ID) 
        {
        		return MDCI_NO_PHY_CHANNEL;        		
        } 
        else 
        {
            /* set BUSY bit */
            *MDIF_BUSY |= (1 << phy_chann);
	        mdci_writeindx_for_FC = (phy_chann + 1)%MDIF_MAX_PHY;
            break;
        }
    }    
    
    /* set logical channel number */
    buff->channel = channel;


    /* copy channel buffer */
    chdata = (MDCI_BUFF_T *)MDIF_TXCHDATA + phy_chann;
    kal_mem_cpy(chdata, buff, sizeof(MDCI_BUFF_T));
    
    /* restore the stream buffer address */
    if (!MDCI_IS_MAILBOX(buff)) {
        MDCI_STREAM_ADDR(buff) = saveaddr;
    }

    /* start MDIF */
    *MDIF_TCHNUM = phy_chann;
    
    while (ticks > 0)
    {
        reserved_value = *(volatile kal_uint32*)(&(chdata->reserved));
        if (reserved_value != MDCI_EXCEPTION_CHECK_ID)
        {
        	ret = MDCI_SUCCESS;
        	break;	
        }
        
        ust_busy_wait(1);
    	ticks--;	
    }


    return ret;
}
Beispiel #13
0
__attribute__((section ("INTSRAM_ROCODE"))) void mdci_lisr()
{
    kal_uint32 arb, phy_chann, i, log_chann;
    MDCI_BUFF_T *buff;


    /* mask MDIF */
#if defined(MDIF_FOR_AP_SIDE)
    IRQMask(IRQ_APMDIF_CODE);
#else
    IRQMask(IRQ_MDIF_CODE);
#endif

    /* get arbitration mode */
    if (*MDIF_CON & MDIF_CON_ARB)
    {
        arb = 1;
    }
    else
    {
        arb = 0;
    }

    /* get physical channel which needs to be read */
    phy_chann = *MDIF_RCHNUM;

    //for (i = 0; i < MDIF_MAX_PHY; i++) {
     for (i = mdci_readindx_for_MD; i < mdci_readindx_for_MD + MDIF_MAX_PHY; i++)
    {
        /* get logical channel one by one*/
        if (phy_chann == 0) break;
        i = i % MDIF_MAX_PHY;
        
        /* get logical channel number */
        if (arb == 0)
        {
            buff = (MDCI_BUFF_T *)MDIF_RXCHDATA + phy_chann;
            log_chann = buff->channel;
            i = phy_chann;
        }
        else if (phy_chann & (1 << i))
        {
            buff = (MDCI_BUFF_T *)MDIF_RXCHDATA + i;
            log_chann = buff->channel;
        }
        else
        {
            continue;
        }

        /* validate logical channel */
        if (log_chann == MDCI_FORCE_RESET_MODEM_CHANNEL)
        {
            #define FORCE_RESET_MODEM   (0)
            EXT_ASSERT(FORCE_RESET_MODEM, log_chann, phy_chann, 0);
        }
        else if (log_chann >= MDCI_MAX_CHANNEL)
        {
            EXT_ASSERT(0, log_chann, phy_chann, 0);
        }
   

        /* check state */
        if (mdci_ctrl_pool[log_chann].state == MDCI_ACTIVE_READ)
        {
            /* use OR operation since a mdci_read() is waiting */
            mdci_ctrl_pool[log_chann].state |= MDCI_ACTIVE_ISR;
        }
        else if (mdci_ctrl_pool[log_chann].state == MDCI_IDLE)
        {
            mdci_ctrl_pool[log_chann].state = MDCI_ACTIVE_ISR;
        }
        else if (mdci_ctrl_pool[log_chann].state == MDCI_ACTIVE_WRITE)
        {
            /* a mdci_write() is not finished */
            EXT_ASSERT(0, phy_chann, log_chann, mdci_ctrl_pool[log_chann].state);
        }
        else if (mdci_ctrl_pool[log_chann].state == MDCI_ACTIVE_ISR)
        {
            /* a mdci_hisr() is not done yet */
            if (arb == 0)
            {
                /* not allow in sequential mode */
                EXT_ASSERT(0, phy_chann, log_chann, mdci_ctrl_pool[log_chann].state);
            }
            else
            {
                /* pend */
                break; // KC: change the continue to break due to mdif phy race condition problem.
                //continue;
            }
        }
        else
        {
            EXT_ASSERT(0, phy_chann, log_chann, mdci_ctrl_pool[log_chann].state);
        }

        /* copy channel buffer */
        kal_mem_cpy(&(mdci_ctrl_pool[log_chann].buff), buff, sizeof(MDCI_BUFF_T));

        /* ack MDIF to release the physical channel */
        *MDIF_ACK = (1 << i);
        phy_chann &= ~(1<<i);

        /* only one channel at one time under sequential mode */
        if (arb == 0)
        { 
            break;
        }
    }

    mdci_readindx_for_MD = i;


#ifndef __IVP__
    /* activate HISR */    
    if (KAL_TRUE == kal_query_systemInit())
    {
#endif /* __IVP__ */
        mdci_hisr();
#ifndef __IVP__
    }
    else
    {
        drv_active_hisr(DRV_MDIF_HISR_ID);
    }
#endif /* __IVP__ */    
}
Beispiel #14
0
/*************************************************************************
* FUNCTION
*  ccci_ipc_send_msg
*
* DESCRIPTION
*  This function is the internal api to send message
*
* PARAMETERS
*  ipc_task_id     -  
*  buffer_ptr      -
*  msg_size        -
*  wait_mode       -
*  message_to_head -
*
* RETURNS
*  status - success/fail
*
*************************************************************************/
kal_bool ccci_ipc_send_msg(kal_uint32 ipc_task_id, void *buffer_ptr, kal_uint16 msg_size,	kal_wait_mode wait_mode, kal_bool message_to_head)
{
    kal_uint32 i, j ;
    kal_uint32 retrieved_events = 0, orig_local_addr = 0 , orig_peer_addr = 0, update_buff_addr=0;
    kal_int32 result = CCCI_SUCCESS;
    ipc_ilm_t	*temp_ipc_ilm = (ipc_ilm_t *)buffer_ptr;
    ccci_io_request_t ior = {0};
	CCCI_BUFF_T *p_ccci_buff;
    kal_uint32 len = 0;
	
		
	ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_FUNC_TRA);	
    ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_TRA_ILM,
                temp_ipc_ilm, temp_ipc_ilm->src_mod_id, temp_ipc_ilm->dest_mod_id,
                temp_ipc_ilm->sap_id, temp_ipc_ilm->msg_id,
                temp_ipc_ilm->local_para_ptr, temp_ipc_ilm->peer_buff_ptr);
		
    /* get ext queue id from mapping table of task id - destnation*/
    for (i = 0; i < MAX_CCCI_IPC_TASKS; i++) 
    {
        if ( ccci_ipc_maptbl[i].task_id == ipc_task_id )
        	{
                    break;
        	}
    }
	
    /* get ext queue id from mapping table of task id - source*/
    for (j = 0; j < MAX_CCCI_IPC_TASKS; j++) 
    {
        if ( ccci_ipc_maptbl[j].task_id == temp_ipc_ilm->src_mod_id )
        	{
                    break;
        	}
    }
  
    /* check src mod id, if it's not defined in CCCI IPC, don't set used bit */
    if(j >= MAX_CCCI_IPC_TASKS)
    {
        ccci_ipc_trace(CCCI_IPC_ERR, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_FUNC_TASKID_ERROR, ipc_task_id, temp_ipc_ilm->src_mod_id);
        return KAL_FALSE;
    }
 
    /* check if the extquque id can not be found */
    if (i >= MAX_CCCI_IPC_TASKS) 
    {
	    ccci_ipc_trace(CCCI_IPC_ERR, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_FUNC_TASKID_ERROR, ipc_task_id, temp_ipc_ilm->src_mod_id);
        ((CCCI_IPC_ILM_T*)buffer_ptr)->used = 0;  
        return KAL_FALSE;
    }
  
        /* check if the extquque id is to AP */
    if ((ccci_ipc_maptbl[i].extq_id & AP_UINFY_ID_FLAG) == 0)
    {
        ccci_ipc_trace(CCCI_IPC_ERR, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_FUNC_DESTID_ERROR, ipc_task_id);
        ((CCCI_IPC_ILM_T*)buffer_ptr)->used = 0;   
	    return KAL_FALSE;
    }

    /* check if the ilm buffer is from ipc_msgsvc_allocate_ilm or not */
    if (buffer_ptr != &ccci_ipc_ilm_arr[j].ipc_ilm){
        ccci_ipc_trace(CCCI_IPC_ERR, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_FUNC_ILM_ERROR);
        return KAL_FALSE;
    }
		    
	len = sizeof(CCCI_BUFF_T) + sizeof(ipc_ilm_t);
    if (temp_ipc_ilm->local_para_ptr != NULL){          
        len+= temp_ipc_ilm->local_para_ptr->msg_len ;
    }
    if( temp_ipc_ilm->peer_buff_ptr != NULL){
        len+= sizeof(peer_buff_struct) 
            + temp_ipc_ilm->peer_buff_ptr->pdu_len 
            + temp_ipc_ilm->peer_buff_ptr->free_header_space 
            + temp_ipc_ilm->peer_buff_ptr->free_tail_space;
    }
	//assert if ilm size > CCCI_IPC_GPD size
	EXT_ASSERT(len < CCCI_IPC_GPD_SIZE, len, CCCI_IPC_GPD_SIZE, 0);

    /* Use critical section to protect ENTER */
    CCCI_IPC_ENTER_CRITICAL_SECTION
    if (KAL_TRUE == kal_query_systemInit()){ // polling mode
        ior.first_gpd = ccci_ipc_ch.p_polling_gpd;
        ior.last_gpd  = ccci_ipc_ch.p_polling_gpd;
    }
    else{
#ifdef __SDIOC_PULL_Q_ENH_DL__
        ior.num_gpd = 
#endif 
        qbmt_alloc_q_no_tail( 
                            CCCI_IPC_GPD_TYPE,            /* type */
                            1,                            /* buff_num */
                            (void **)(&ior.first_gpd),    /* pp_head */
                            (void **)(&ior.last_gpd));    /* pp_tail */
        if(ior.first_gpd == NULL){
            ccci_ipc_trace(CCCI_IPC_ERR, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_FUNC_ALLOC_GPD_ERROR);
            return KAL_FALSE;
        }
    }
    
	//initialize GPD CCCI_Header content
	p_ccci_buff = CCCIDEV_GET_QBM_DATAPTR(ior.first_gpd);
	p_ccci_buff->data[1] = (kal_uint32)len;
	p_ccci_buff->channel = (kal_uint32)ccci_ipc_ch.send_channel;
	p_ccci_buff->reserved = (kal_uint32)ccci_ipc_maptbl[i].extq_id;
    ccci_debug_add_seq(p_ccci_buff, CCCI_DEBUG_ASSERT_BIT); // add ccci seq
    QBM_DES_SET_DATALEN(ior.first_gpd, p_ccci_buff->data[1]);
    QBM_DES_SET_DATALEN(ior.first_gpd->p_data_tbd,  p_ccci_buff->data[1]);
    qbm_cal_set_checksum((kal_uint8 *)ior.first_gpd);
    qbm_cal_set_checksum((kal_uint8 *)ior.first_gpd->p_data_tbd);
    QBM_CACHE_FLUSH(ior.first_gpd, sizeof(qbm_gpd));
    QBM_CACHE_FLUSH(ior.first_gpd->p_data_tbd, sizeof(qbm_gpd));
    
    
    //copy ilm to GPD
    temp_ipc_ilm->src_mod_id =	ccci_ipc_maptbl[j].extq_id; 
    update_buff_addr = (kal_uint32)p_ccci_buff;
	update_buff_addr += sizeof(CCCI_BUFF_T);	
    CCCI_KAL_MSG_TO_AP_MSG(temp_ipc_ilm->msg_id, temp_ipc_ilm->msg_id);
	kal_mem_cpy((kal_uint8 *)update_buff_addr ,(kal_uint8 *)temp_ipc_ilm, sizeof(ipc_ilm_t));
    
	if (temp_ipc_ilm->local_para_ptr != NULL){			
			//copy loca_para_struct to GPD
			update_buff_addr += sizeof(ipc_ilm_t); //24 bytes
			orig_local_addr = update_buff_addr;
			kal_mem_cpy((kal_uint8 *)update_buff_addr,(kal_uint8 *)temp_ipc_ilm->local_para_ptr, temp_ipc_ilm->local_para_ptr->msg_len);
    }
    
    if( temp_ipc_ilm->peer_buff_ptr != NULL){
			//copy peer buff_struct to GPD
			if (temp_ipc_ilm->local_para_ptr != NULL){	 
			    update_buff_addr += temp_ipc_ilm->local_para_ptr->msg_len;//should be 4 bytes alignment?? 
			}
            else{
                update_buff_addr += sizeof(ipc_ilm_t); //24 bytes
            }
			orig_peer_addr = update_buff_addr;
			kal_mem_cpy((kal_uint8 *)update_buff_addr,(kal_uint8 *)temp_ipc_ilm->peer_buff_ptr, 
                          sizeof(peer_buff_struct) 
                          + temp_ipc_ilm->peer_buff_ptr->pdu_len 
                          + temp_ipc_ilm->peer_buff_ptr->free_header_space 
                          + temp_ipc_ilm->peer_buff_ptr->free_tail_space);
    }

    free_local_para(temp_ipc_ilm->local_para_ptr);
	temp_ipc_ilm->local_para_ptr = (local_para_struct *)orig_local_addr;//assign not NULL ptr to indicate there have content 
			
	free_peer_buff(temp_ipc_ilm->peer_buff_ptr);
	temp_ipc_ilm->peer_buff_ptr = (peer_buff_struct *)orig_peer_addr;//assign not NULL ptr to indicate there have content			

    QBM_CACHE_FLUSH(p_ccci_buff, len);
    
    if (KAL_TRUE == kal_query_systemInit()){ // polling mode
        result = ccci_polling_io(ccci_ipc_ch.send_channel, ccci_ipc_ch.p_polling_gpd, KAL_TRUE);
        CCCIDEV_RST_CCCI_COMM_GPD_LIST(ccci_ipc_ch.p_polling_gpd,ccci_ipc_ch.p_polling_gpd);
    }
    else{		
        result = ccci_ipc_ch.ccci_write_gpd(ccci_ipc_ch.send_channel, &ior, NULL);	
    	
        if (KAL_INFINITE_WAIT == wait_mode && CCCI_SUCCESS == result){		
    	    /* Wait for feedabck by retrieve event */
    	    kal_retrieve_eg_events(ccci_ipc_ch.event, 1 << i, KAL_AND_CONSUME,  &retrieved_events, KAL_SUSPEND);
        }
    }				
	/* Exit critical section */ 
	CCCI_IPC_EXIT_CRITICAL_SECTION
    ((CCCI_IPC_ILM_T*)buffer_ptr)->used = 0;  

    ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_TRA_CCCI,
                p_ccci_buff->data[0], p_ccci_buff->data[1], p_ccci_buff->channel, p_ccci_buff->reserved);
    ccci_ipc_trace(CCCI_IPC_TRACE, CCCI_IPC_MOD_DATA, CCCI_SEND_MSG_FUNC_PASS_TRA);	
		
	/* Finish */	
    if (result == CCCI_SUCCESS){
    	return KAL_TRUE;
    }
    else{
        return KAL_FALSE;
    }
        
}