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

📄 drvps2.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*               The function is used to clear PS2 Interrupt								        	   */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t
DrvPS2_ClearInt(
	uint32_t	u32InterruptFlag
)
{
	//Write '1' to clear int
	
	if((u32InterruptFlag & DRVPS2_RXINT) == DRVPS2_RXINT)	   
		_DRVPS2_INTCLR(1);

	if((u32InterruptFlag & DRVPS2_TXINT) == DRVPS2_TXINT)
		_DRVPS2_INTCLR(2);

	return E_SUCCESS;


}	


/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_GetIntStatus                                                                 	   */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               u32InterruptFlag     -[in]   DRVPS2_RXINT / DRVPS2_TXINT                                  */
/* Returns:                                                                                                */
/*                                                                                                         */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to get the interrupt status 										   */
/*---------------------------------------------------------------------------------------------------------*/
int8_t
DrvPS2_GetIntStatus(
	uint32_t	u32InterruptFlag
)
{	
	switch(u32InterruptFlag)
	{
		case DRVPS2_RXINT:
			if(PS2->u32INTID & DRVPS2_RXINT)		  	// Rx interrupt
				return TRUE;
			break;
		case DRVPS2_TXINT:
			if(PS2->u32INTID & DRVPS2_TXINT)		    // Tx interrupt
				return TRUE;
			break;
		default:
			break;
	}

	
	return FALSE;
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_SetTxFIFODepth                                                                     */
/*                                                                                                         */
/* Parameter:        																					   */	
/*               u32TxFIFODepth   - 0 to 15                                               				   */
/*                                                                                                         */
/* Returns:                                                                                                */
/*                                                                                                         */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to set Tx FIFO Depth                                                 */
/*---------------------------------------------------------------------------------------------------------*/

void DrvPS2_SetTxFIFODepth(
	uint16_t	u32TxFIFODepth
)
{
	_DRVPS2_TXFIFO(u32TxFIFODepth);
}

 
/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_Read                                                                               */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               pu8RxBuf       	the pointer of rx buffer                                               */
/* Returns:                                                                                                */
/*               E_SUCCESS                                                                          	   */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to read one Rx byte from RX register                                 */
/*---------------------------------------------------------------------------------------------------------*/
								  
int32_t 
DrvPS2_Read(
	uint8_t		*pu8RxBuf
)
{   
	*pu8RxBuf = _DRVPS2_RXDATA();
	
    return E_SUCCESS;
	
}



/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_Write	                                                                           */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               pu32TxBuf       	the pointer of tx buffer                                               */
/*               u32WriteBytes      the bytes count of send data                                           */
/* Returns:                                                                                                */
/*               E_SUCCESS                                                                          	   */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is to write data to TX fifo and wait Tx finished by ps2                      */
/*               if data count sent is less than 16 bytes, please use macro for speed                      */
/*---------------------------------------------------------------------------------------------------------*/

int32_t 
DrvPS2_Write(
	uint32_t	*pu32TxBuf, 
	uint32_t	u32WriteBytes
)
{
    uint32_t  u32delayno, txcnt, remainder;
    uint8_t i=0;
    
    txcnt = u32WriteBytes/DRVPS2_TXFIFODEPTH;
    remainder = u32WriteBytes % DRVPS2_TXFIFODEPTH;
    if(remainder)
    	txcnt++;
    if(u32WriteBytes >= DRVPS2_TXFIFODEPTH)//Tx fifo is 16 bytes
    {
    	_DRVPS2_TXFIFO(DRVPS2_TXFIFODEPTH);
    }
    else
    {
    	_DRVPS2_TXFIFO(u32WriteBytes);
    }
	
	do
	{
		u32delayno = 0;
		while (_DRVPS2_ISTXEMPTY() != 1)
		{
			u32delayno++;
			if ( u32delayno >= 0x40000000 )     	    
				return E_DRVPS2_ERR_TIMEOUT;     	       
		}
		_DRVPS2_TXDATA0(pu32TxBuf[i++]);
		_DRVPS2_TXDATA1(pu32TxBuf[i++]);
		_DRVPS2_TXDATA2(pu32TxBuf[i++]);
		_DRVPS2_TXDATA3(pu32TxBuf[i++]);
		//memcpy((char*)&PS2->TXDATA[0], pu32TxBuf+i, txcnt);

	}while(--txcnt);

    return E_SUCCESS;
	
  
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_GetVersion                                                                        */
/*                                                                                                         */
/* Parameter:        																					   */	
/*	             None                                                                                 	   */
/* Returns:                                                                                                */
/*               Version Number                                                                            */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to get DrvPS2 Version Number                                       */
/*---------------------------------------------------------------------------------------------------------*/
int32_t
DrvPS2_GetVersion(void)
{
	return _DRVPS2_VERSION_NUM;
	
}






⌨️ 快捷键说明

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