⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hostif_low.c

📁 本程序为ST公司开发的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
		default:			break;	}}/******************************************************************************//* Function:  hostif_activate_pending_tx                                     *//*                                                                            *//*! \brief    Framework to process messages split across several packets *  \param    void *  \return   void *  \remark *//******************************************************************************/void hostif_activate_pending_tx(uint32 which_tx){	ASSERT((which_tx == HOSTIF_SCHEDULED_ENTRY_NAME)	|| (which_tx == HOSTIF_SCHEDULED_TEXT_INFO)	|| (which_tx == HOSTIF_SCHEDULED_ROM_DATA)	|| (which_tx == HOSTIF_SCHEDULED_UPDATE_IMAGE)	|| (which_tx == HOSTIF_SCHEDULED_PLAYLIST_CONTENT)	|| (which_tx == HOSTIF_SCHEDULED_LONG_ENTRY_NAME), "Wrong parameter to hostif_have_scheduled_tx");		hostif_current_scheduled_tx = which_tx;	hostif_pending_scheduled_tx &= ~which_tx;}/******************************************************************************//* Function:  hostif_schedule_tx                                     *//*                                                                            *//*! \brief    Framework to process messages split across several packets *  \param    void *  \return   void *  \remark   if there is a long message tx in progress, schedule for *            future tx. *//******************************************************************************/void hostif_schedule_tx(uint32 which_tx){	ASSERT((which_tx == HOSTIF_SCHEDULED_ENTRY_NAME)	|| (which_tx == HOSTIF_SCHEDULED_TEXT_INFO)	|| (which_tx == HOSTIF_SCHEDULED_ROM_DATA)	|| (which_tx == HOSTIF_SCHEDULED_UPDATE_IMAGE)	|| (which_tx == HOSTIF_SCHEDULED_PLAYLIST_CONTENT)	|| (which_tx == HOSTIF_SCHEDULED_LONG_ENTRY_NAME), "Wrong parameter to hostif_schedule_tx");	if (hostif_current_scheduled_tx == 0)	{		hostif_current_scheduled_tx = which_tx;	}	else	{		hostif_pending_scheduled_tx |= which_tx;		}	}/******************************************************************************//* Function:  hostif_deschedule_tx                                     *//*                                                                            *//*! \brief    Framework to process messages split across several packets *  \param    void *  \return   void *  \remark   Remove the specified scheduled tx from current and pending *            future tx. *//******************************************************************************/void hostif_deschedule_tx(uint32 which_tx){	ASSERT((which_tx == HOSTIF_SCHEDULED_ENTRY_NAME)	|| (which_tx == HOSTIF_SCHEDULED_TEXT_INFO)	|| (which_tx == HOSTIF_SCHEDULED_ROM_DATA)	|| (which_tx == HOSTIF_SCHEDULED_UPDATE_IMAGE)	|| (which_tx == HOSTIF_SCHEDULED_PLAYLIST_CONTENT)	|| (which_tx == HOSTIF_SCHEDULED_LONG_ENTRY_NAME), "Wrong parameter to hostif_schedule_tx");	if (hostif_current_scheduled_tx == which_tx)	{		hostif_current_scheduled_tx = 0;	}	else	{		hostif_pending_scheduled_tx &= ~which_tx;	}}/******************************************************************************//* Function:  hostif_deschedule_current                                     *//*                                                                            *//*! \brief    Framework to process messages split across several packets *  \param    void *  \return   void *  \remark    *//******************************************************************************/void hostif_deschedule_current(void){	hostif_pending_scheduled_tx &= ~hostif_current_scheduled_tx;	hostif_current_scheduled_tx = 0;}/******************************************************************************//* Function:  hostif_transition_handler                                       *//*                                                                            *//*! \brief    Host interface transition handler   *  \param    void *  \return   void *  \remark *//******************************************************************************/void hostif_transition_handler(void){	hostif_block_tx_mode tx_mode = HOSTIF_NO_TX;	#if (0 != HAVE_POSITION)	hostif_update_transition_handler();#endif	if ((hostif_inevent & HOSTIF_EVT_LL_STOP_TIMEOUT) != 0)	{		/* Host did not generate the Stop condition within the timeout */		/* Reset the rx LL */		/* This condition is raised by the LL (tx and rx IRQ) */		/* The Host is probably in a bad state, no sense in trying to resend or recover */		/* The call below changes the state to HOSTIF_STATE_IDLE */		hostif_reset();	}	else if ((hostif_inevent & HOSTIF_EVT_LL_CRQ_TIMEOUT) != 0)	{		/* Host did not read our data within the timeout */		/* CIS 0.08 requires we release the CRQ line for at least 10us */		/* then retry the transmission indefinetly */		uint32 loop;						//hostif_inevent &= ~HOSTIF_EVT_LL_CRQ_TIMEOUT;		reset_hostif_inevent(HOSTIF_EVT_LL_CRQ_TIMEOUT);		i2c_soft_reset_tx(); /* releases the CRQ line */		/* wait some time , CIS 0.08 requires 10us but an email says 2us is ok */		for (loop = 0; loop < 10; loop++) // 100 with O1 optimization is approx 10us			tx_mode = HOSTIF_TX_BLOCK_RESEND;	}#if 0 //[MM] This condition is not more necessary because this event is not      //     more generated by i2c interrupt procedure		else if ((hostif_inevent & HOSTIF_EVT_LL_AF_ERR) != 0)	{						//hostif_inevent &= ~HOSTIF_EVT_LL_AF_ERR;		reset_hostif_inevent(HOSTIF_EVT_LL_AF_ERR);		/* Host did not ack one byte during our transmission: */		/* Abort the transmission and resend */		/* This event is generated by the LL (the IRQ tx) */		hostif_ll_retry_count++;		if (hostif_ll_retry_count < HOSTIF_LL_MAX_RETRY_COUNT)		{			i2c_soft_reset_tx();			tx_mode = HOSTIF_TX_BLOCK_RESEND;		}		else		{			/* This call changes the state to HOSTIF_STATE_IDLE */			hostif_reset();		}			}#endif		else if ((hostif_inevent & HOSTIF_SEND_MSGCMDEVAL) != 0)	{		//hostif_inevent &= ~HOSTIF_SEND_MSGCMDEVAL;		reset_hostif_inevent(HOSTIF_SEND_MSGCMDEVAL);		if (hostif_state == HOSTIF_STATE_IDLE)		{			tx_mode = HOSTIF_TX_MSGCMDEVAL;			hostif_have_msgcmdeval = FALSE;		}		else		{			hostif_have_msgcmdeval = TRUE;		}	}	else if ((hostif_inevent & HOSTIF_CMD_SEND_HOST_MSG) != 0)	{		//hostif_inevent &= ~HOSTIF_CMD_SEND_HOST_MSG;		reset_hostif_inevent(HOSTIF_CMD_SEND_HOST_MSG);		if (hostif_state == HOSTIF_STATE_IDLE)		{			if (fifo_pop_msg(&hostif_msg_fifo, &hostif_app_buffer[0], &hostif_app_buffer_length))			{				tx_mode = HOSTIF_TX_BLOCK_NORMAL;			}		}		/* if we are not IDLE, the message will be consumed later */	}		else if ((hostif_inevent & HOSTIF_EVT_LL_TX_COMPLETE) != 0)	{				//hostif_inevent &= ~HOSTIF_EVT_LL_TX_COMPLETE;		reset_hostif_inevent(HOSTIF_EVT_LL_TX_COMPLETE);		if (hostif_state == HOSTIF_STATE_TX_INPROGRESS)		{			hostif_state = HOSTIF_STATE_IDLE;			if (hostif_have_msgcmdeval == TRUE)			{				send_hostif_inevent(HOSTIF_SEND_MSGCMDEVAL);			}			if (fifo_has_msg(&hostif_msg_fifo) == TRUE)			{				send_hostif_inevent(HOSTIF_CMD_SEND_HOST_MSG);			}		}	}		if (hostif_state == HOSTIF_STATE_IDLE)	{		hostif_ll_retry_count = 0;	}		if (tx_mode != HOSTIF_NO_TX)	{		switch (hostifSendBlock(tx_mode))		{			case TL_inprogress:				hostif_state = HOSTIF_STATE_TX_INPROGRESS;				break;			// case TL_ready:			default:				hostif_state = HOSTIF_STATE_IDLE;				if (fifo_has_msg(&hostif_msg_fifo) == TRUE)				{					send_hostif_inevent(HOSTIF_CMD_SEND_HOST_MSG);				}				break;		}	}}#if (0 != HAVE_POSITION)/******************************************************************************//* Function:  hostif_update_transition_handler                                *//*                                                                            *//*! \brief    Host interface transition handler   *  \param    void *  \return   void *  \remark *//******************************************************************************/void hostif_update_transition_handler(void){  t_player_cmd_event player_command;	if ((hostif_inevent & HOSTIF_STORE_DATA) != 0)	{	    DISABLE_INTERRUPTS();		switch(hostif_inevent & HOSTIF_STORE_DATA_MASK)		{			case HOSTIF_STORE_DATA_ERASE :				SelectSdram(SELECT_BSPI);				if(sf_type == BL_MP25P40)				{				 hostif_store_address = HOSTIF_STORE_ADDRESS_4M;				}				else				{				 hostif_store_address = HOSTIF_STORE_ADDRESS_1M;				}				bspi_init();								bspi_rdid();				if(sf_erase_sector(hostif_store_address))				{					SelectSdram(SELECT_SDRAM);					hostif_inevent &= ~HOSTIF_STORE_DATA_ERASE;					hostif_inevent |= HOSTIF_STORE_DATA_WRITE;					break;				}				SelectSdram(SELECT_SDRAM);				hostif_inevent |= HOSTIF_STORE_DATA_DONE;				break;			case HOSTIF_STORE_DATA_WRITE :			   	SelectSdram(SELECT_BSPI);				if(!sf_busy())				{					hostif_update_checksum();					if(sf_pp(hostif_store_address, (uint8*)(&hostifStoredData),					         sizeof(hostifStoredDataType)))					{						hostif_inevent &= ~HOSTIF_STORE_DATA_WRITE;						hostif_inevent |= HOSTIF_STORE_DATA_WAIT;						SelectSdram(SELECT_SDRAM);						break;					}					hostif_inevent |= HOSTIF_STORE_DATA_DONE;				}				SelectSdram(SELECT_SDRAM);				break;			case HOSTIF_STORE_DATA_WAIT :			   	SelectSdram(SELECT_BSPI);			   					if(!sf_busy())				{					hostif_inevent |= HOSTIF_STORE_DATA_DONE;				}				SelectSdram(SELECT_SDRAM);				break;			default :				hostif_inevent &= ~HOSTIF_STORE_DATA_CLEAR;		}		ENABLE_INTERRUPTS();	}	else if ((hostif_inevent & HOSTIF_LOAD_DATA) != 0)	{		switch(hostif_inevent & HOSTIF_LOAD_DATA_MASK)		{			case HOSTIF_LOAD_DATA_READ :			    DISABLE_INTERRUPTS();				SelectSdram(SELECT_BSPI);				if(sf_type == BL_MP25P40)				{				 hostif_store_address = HOSTIF_STORE_ADDRESS_4M;				}				else				{				 hostif_store_address = HOSTIF_STORE_ADDRESS_1M;				}				bspi_init();				bspi_rdid();				sf_read(hostif_store_address, (uint8*)(&hostifStoredData),				        sizeof(hostifStoredDataType));				SelectSdram(SELECT_SDRAM);				hostif_inevent &= ~HOSTIF_LOAD_DATA_READ;				hostif_inevent |= HOSTIF_LOAD_DATA_CHECK;				ENABLE_INTERRUPTS();				//hostif_inevent &= ~HOSTIF_LOAD_DATA_READ;				//hostif_inevent |= HOSTIF_LOAD_DATA_CHECK;				break;			case HOSTIF_LOAD_DATA_CHECK :				if(!hostif_verify_checksum())				{					memset(&hostifStoredData, 0, sizeof(hostifStoredDataType));				}				//hostif_inevent |= HOSTIF_LOAD_DATA_DONE;				set_hostif_inevent(HOSTIF_LOAD_DATA_DONE);		  case HOSTIF_LOAD_DATA_DONE:		    //inform player about data from flash read        if (IS_HOSTIF_OUT_CMD_EVENT)        //some command already prepared, append flash info        {                  	GET_HOSTIF_OUT_CMD_EVENT.flash_operation = FLASH_DATA_READ;        }        else        //no command prepared, generate new command        {          player_command.command = PCMD_NONE;	          player_command.flash_operation = FLASH_DATA_READ;        	player_cmd(&player_command);        }				    /* fall through */		    			default :				//hostif_inevent &= ~HOSTIF_LOAD_DATA_CLEAR;				reset_hostif_inevent(HOSTIF_LOAD_DATA_CLEAR);				;//SelectSdram(SELECT_SDRAM);		}	}}#endif /* HAVE_POSITION *//******************************************************************************//* Function:  hostifSendBlock                                                  *//*                                                                            *//*! \brief    Host communication protocol Transport Layer Send function. *  \param msg pointer to message to trasmit (inside the app fifo) *  \param msg_len length of the message *  \param mode Type of transmission *  \return   TLStatusType *  \remark   Performs fragmentation of the message Block into packets *            and adds the BlockID and PacketNumber fields to the Block header *            if necessary. *            Returns: *               TL_inprogress: message was delivered to IRQ routine, wait *                              a local ACK to free the hostif_app_buffer *               TL_waitack:    message delivererd to IRQ routine, wait *                              a Block ACK the host to continue transport session *								THIS IS NO LONGER USED SO IT WAS REMOVED *               TL_ready:      transport session completed, hostif_app_buffer *                              can be reused *//******************************************************************************/TLStatusType hostifSendBlock(hostif_block_tx_mode mode){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -