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

📄 funcinit.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
字号:
/*
================================================================================
* @file   UART_FuncInit.c
* @brief  Related to UART Interface initialization
* @author 2006/03/29 Michiru Kagaya
* Copyright (C)SEIKO EPSON Corp. All Rights Reserved.
================================================================================
*/

//=================================
//		include files
//=================================
#include "UART_FUNC.h"
#include "UART_FuncCom.h"
#include "UART_IF.h"

//=================================
// Static variable declaration
//=================================

// The mangement variables and the structures of this module
//------------------------------
MODULE_INFO sModuleInfo;
static unsigned char StartCnt;		// Check the number of times UART_FuncStart
//=================================
// 	Function Prototype
//=================================
static BOOL IsEnableConfigValue ( const PUART_FUNC_CONFIG psConfig );
static BOOL IsEnableHWParamValue ( const PUART_FUNC_PARAM psParam );
extern short RcvCallback( unsigned short wMsg, unsigned short wStatus, void* pRxChannel );

/*
--------------------------------------------------------------------------------
*					  UART_FuncStart
* @brief   Start the UART system
* @param   const PUART_FUNC_CONFIG psConfig : Specify the UART operation
* @retval  short
*			 STATUS_SUCCESS			: Complete normally
*			 STATUS_INVALID_PARAMETER: Parameter error
--------------------------------------------------------------------------------
*/
short UART_FuncStart( const PUART_FUNC_CONFIG psConfig )
{
	BOOL bStatus;
	short retVal;
	unsigned char index;
	UART_IF_PARAM sIFParam;

	//=========================
	// Check the parameter
	//=========================
	bStatus = IsEnableConfigValue( psConfig );
	if( bStatus == FALSE ){
		return STATUS_INVALID_PARAMETER;
	}

	//=========================
	// Initialize the internal variables
	//=========================
	index = psConfig->sParam.bChannel-1;

	sModuleInfo.sChInfo[index].state				= STATE_READY;

	// Initialize the sending parameter
	//---------------------
	sModuleInfo.sChInfo[index].txInfo.wTempSize		= psConfig->wSndBufSize;
	sModuleInfo.sChInfo[index].txInfo.pTempBuf		= psConfig->pSndBufAddr;
	sModuleInfo.sChInfo[index].txInfo.wActSize		= 0;
	sModuleInfo.sChInfo[index].txInfo.pPutAddr		= NULL;
	sModuleInfo.sChInfo[index].txInfo.wReqSize		= 0;
	sModuleInfo.sChInfo[index].txInfo.pReqAddr		= NULL;
	sModuleInfo.sChInfo[index].txInfo.pfnCallback	= NULL;

	// Initialize the receiving parameter
	//---------------------
	sModuleInfo.sChInfo[index].rxInfo.wTempSize			= psConfig->wRcvBufSize;
	sModuleInfo.sChInfo[index].rxInfo.pTempBuf			= psConfig->pRcvBufAddr;
	sModuleInfo.sChInfo[index].rxInfo.wRcvdSize			= 0;
	sModuleInfo.sChInfo[index].rxInfo.wReqSize			= 0;
	sModuleInfo.sChInfo[index].rxInfo.wActSize			= 0;
	sModuleInfo.sChInfo[index].rxInfo.pReqAddr			= NULL;
	sModuleInfo.sChInfo[index].rxInfo.pfnRcvdCallback	= psConfig->pfnRcvdEvent;
	sModuleInfo.sChInfo[index].rxInfo.pfnCallback		= NULL;

	//=========================
	// Lower module initialization
	//=========================
	sIFParam.bChannel		= psConfig->sParam.bChannel;
	sIFParam.bBaudRate		= psConfig->sParam.bBaudRate;
	sIFParam.bDataBit		= psConfig->sParam.bDataBit;
	sIFParam.bFlowControl	= psConfig->sParam.bFlowControl;
	sIFParam.bParity		= psConfig->sParam.bParity;
	sIFParam.bStopBit		= psConfig->sParam.bStopBit;

	// Confirm if this API is called for the first time.
	//---------------------------
	if( StartCnt == 0 ){
		// When it is called for the first time,initialize the lower module.
		retVal = UART_IFInit();
		if( retVal != STATUS_SUCCESS ){
			return retVal;
		}
		StartCnt++;
	}else if( StartCnt < MAX_START_CNT ){
		StartCnt++;
	}else{
		return STATUS_UNSUCCESSFUL;
	}

	// Open the lower module
	//------------------------
	retVal = UART_IFOpen( &sIFParam, RcvCallback );
	if( retVal != STATUS_SUCCESS ){
		return retVal;
	}

	//=========================
	// Modify the transmision state
	//=========================
	sModuleInfo.sChInfo[index].txInfo.state = TRAN_STATE_READY;		// Transmission preparation completion
	sModuleInfo.sChInfo[index].rxInfo.state = TRAN_STATE_READY;		// Transmission preparation completion

	return STATUS_SUCCESS;
}

/*
--------------------------------------------------------------------------------
*					UART_FuncStop
* @brief   Disable the UART
* @param   unsigned char bChannel : Stopping channel number
* @retval  short
*			STATUS_SUCCESS			: Complete normally
*			STATUS_INVALID_PARAMETER: Parameter error
--------------------------------------------------------------------------------
*/
short UART_FuncStop( unsigned char bChannel )
{
	unsigned char index;
	short wStatus;

	// Check the validation of the channel
	if( bChannel == 0 || bChannel > MAX_UART_CHANNEL ){
		return FALSE;
	}

	index = bChannel - 1;

	//===============================
	// It confirms if the selected channel is in operating.
	//===============================
	if( sModuleInfo.sChInfo[index].state <= STATE_INIT ){
		// No operation

		// When the channel that doesn't operating is specified,return STATUS_SUCCESS without executing any processing at all.
		return STATUS_SUCCESS;
	}

	//===============================
	// Initialize the internal variables
	//===============================
	sModuleInfo.sChInfo[index].state = STATE_INIT;
	sModuleInfo.sChInfo[index].rxInfo.wTempSize = 0;
	sModuleInfo.sChInfo[index].rxInfo.pTempBuf = NULL;
	sModuleInfo.sChInfo[index].txInfo.wTempSize = 0;
	sModuleInfo.sChInfo[index].txInfo.pTempBuf = NULL;
	if( StartCnt != 0 ){
		StartCnt--;
	}

	//===============================
	// Stop the lower module
	//===============================
	wStatus = UART_IFClose( bChannel );
	if( wStatus != STATUS_SUCCESS ){
		return wStatus;
	}

	return STATUS_SUCCESS;
}

/*
--------------------------------------------------------------------------------
*					  IsEnableConfigValue
* @brief	Check the settign values
* @param	const PUART_FUNC_CONFIG psConfig 	Configration information
* @retval	BOOL
*			TRUE	: Complete normally
*			FALSE	: Parameter has error
--------------------------------------------------------------------------------
*/
BOOL IsEnableConfigValue ( const PUART_FUNC_CONFIG psConfig )
{
	BOOL bStatus = TRUE;

	//===============================
	// Check parameter
	//===============================

	// Check NULL
	if( psConfig == NULL ){
		return FALSE;
	}

	// Check size
	if( psConfig->wRcvBufSize == 0 || psConfig->wSndBufSize == 0 ){
		return FALSE;
	}
	// Check pointer
	if( psConfig->pRcvBufAddr == NULL || psConfig->pSndBufAddr == NULL ){
		return FALSE;
	}

	// Check callback pointer
	if( psConfig->pfnRcvdEvent == NULL ){
		return FALSE;
	}

	// Check psConfig->sParam
	bStatus = IsEnableHWParamValue( &psConfig->sParam );
	if( bStatus != TRUE ){
		return FALSE;
	}

	return TRUE;

}

/*
--------------------------------------------------------------------------------
*					  HardwareParamCheck
* @brief 	Check hardware parameter
* @param	PUART_FUNC_PARAM psParam 	Hard ware parameter structure
* @retval	BOOL
*			TRUE	: Complete normally
*			FALSE	: Parameter has error
--------------------------------------------------------------------------------
*/
BOOL IsEnableHWParamValue ( const PUART_FUNC_PARAM psParam )
{
	//===============================
	// Check parameter
	//===============================

	// check if the channel is available
	if( psParam == NULL || psParam->bChannel == 0 || psParam->bChannel > MAX_UART_CHANNEL ){
		return FALSE;
	}

	// Check baud rate
	if( psParam->bBaudRate < UART_FUNC_BRATE_BEGIN
		|| psParam->bBaudRate > UART_FUNC_BRATE_END ){
		return FALSE;
	}
	// Check data bit
	if( psParam->bDataBit < UART_FUNC_DATABIT_BEGIN
		|| psParam->bDataBit > UART_FUNC_DATABIT_END ){
		return FALSE;
	}
	// Check Parity
	if( psParam->bParity < UART_FUNC_PRITY_BEGIN
		|| psParam->bParity > UART_FUNC_PRITY_END ){

		return FALSE;
	}
	// Check Control flow
	if( psParam->bFlowControl < UART_FUNC_FLOW_BEGIN
		|| psParam->bFlowControl > UART_FUNC_FLOW_END ){
		return FALSE;
	}
	// Check Stop bit
	if( psParam->bStopBit < UART_FUNC_STOPBIT_BEGIN
		|| psParam->bStopBit > UART_FUNC_STOPBIT_END ){
		return FALSE;
	}

	return TRUE;

}

⌨️ 快捷键说明

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