Esempio n. 1
0
/* 延时指定毫秒时间 */
void	mDelaymS( UINT8 ms )
{
	while ( ms -- ) {
		mDelayuS( 250 );
		mDelayuS( 250 );
		mDelayuS( 250 );
		mDelayuS( 250 );
	}
}
Esempio n. 2
0
File: CH376.c Progetto: AlexGora/cox
//*****************************************************************************
//
//! \brief Initial CH376 as USB host.
//!
//! \param None
//!
//! \return error code defined in hw_CH376INC.h.
//
//*****************************************************************************
UINT8   mInitCH376Host( void )
{
    UINT8   res;
    CH376PortInit( );
    xWriteCH376Cmd( CMD11_CHECK_EXIST );
    xWriteCH376Data( 0x65 );
    res = xReadCH376Data( );
    xEndCH376Cmd( );
    if ( res != 0x9A ) return( ERR_USB_UNKNOWN );
    xWriteCH376Cmd( CMD11_SET_USB_MODE );
    xWriteCH376Data( 0x06 );
    mDelayuS( 20 );
    res = xReadCH376Data( );
    xEndCH376Cmd( );
#ifdef  CH376_USE_SOFTWARE_SPI
#ifdef  CH376_SPI_SDO_INT
    xWriteCH376Cmd( CMD20_SET_SDO_INT );
    xWriteCH376Data( 0x16 );
    xWriteCH376Data( 0x90 );
    xEndCH376Cmd( );
#endif
#endif
    if ( res == CMD_RET_SUCCESS ) return( USB_INT_SUCCESS );
    else return( ERR_USB_UNKNOWN );
}
Esempio n. 3
0
File: CH376.c Progetto: AlexGora/cox
//*****************************************************************************
//
//! \brief Write command to CH376.
//!
//! \param mCmd command value
//!
//! \details Write command to CH376.
//!
//! \return None.
//
//*****************************************************************************
void    xWriteCH376Cmd( UINT8 mCmd )
{
    CH376_SPI_CS_SET;
    CH376_SPI_CS_CLR;
    SPIDataOut(mCmd);
    mDelayuS(2);
}
Esempio n. 4
0
File: CH376.c Progetto: AlexGora/cox
//*****************************************************************************
//
//! \brief Write command to CH376.
//!
//! \param mCmd command value
//!
//! \details Write command to CH376.
//!
//! \return None.
//
//*****************************************************************************
void    xWriteCH376Cmd( UINT8 mCmd )
{
    //
    // to avoid not asserting CS PIN
    //
    CH376_SPI_CS_SET;
    CH376_SPI_CS_CLR;
    xSPISingleDataReadWrite( CH376_SPI_PORT, mCmd);
    //
    // make sure that read or write cycle must longer than 1.5us
    //
    mDelayuS(2);
}
Esempio n. 5
0
UINT8	mInitCH376Host( void )  /* 初始化CH376 */
{
	UINT8	res;
	CH376_PORT_INIT( );  /* 接口硬件初始化 */
	xWriteCH376Cmd( CMD11_CHECK_EXIST );  /* 测试单片机与CH376之间的通讯接口 */
	xWriteCH376Data( 0x65 );
	res = xReadCH376Data( );
//	xEndCH376Cmd( );  // 并口方式不需要
	if ( res != 0x9A ) return( ERR_USB_UNKNOWN );  /* 通讯接口不正常,可能原因有:接口连接异常,其它设备影响(片选不唯一),串口波特率,一直在复位,晶振不工作 */
	xWriteCH376Cmd( CMD11_SET_USB_MODE );  /* 设备USB工作模式 */
	xWriteCH376Data( 0x06 );
	mDelayuS( 20 );
	res = xReadCH376Data( );
//	xEndCH376Cmd( );  // 并口方式不需要
	if ( res == CMD_RET_SUCCESS ) return( USB_INT_SUCCESS );
	else return( ERR_USB_UNKNOWN );  /* 设置模式错误 */
}