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

📄 drvps2.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include "NUC1xx.h"

/*---------------------------------------------------------------------------------------------------------*/
/* Includes of local headers                                                                               */
/*---------------------------------------------------------------------------------------------------------*/
#include "DrvPS2.h"
#include "DrvSYS.h"


/*---------------------------------------------------------------------------------------------------------*/
/* Macro, type and constant definitions                                                                    */
/*---------------------------------------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------------------------------------*/
/* Global variables                                                                                        */
/*---------------------------------------------------------------------------------------------------------*/
static PFN_DRVPS2_CALLBACK *g_pfnPS2callback = NULL;
 	

/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_Open                                                                        	   */
/*                                                                                                         */
/* Parameter:        																					   */	
/*               None                                    	                                     		   */
/*                                                                                                         */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               E_SUCCESS                                                                          	   */
/*                                                                                                         */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to initialize PS2                                                   */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvPS2_Open(void)
{
	SYS->IPRSTC2.PS2_RST = 1;
    SYS->IPRSTC2.PS2_RST = 0;

    SYSCLK->APBCLK.PS2_EN = 1;

    _DRVPS2_PS2ENABLE();  
    _DRVPS2_TXFIFO(1);
    
    _DRVPS2_CLRFIFO();

	return E_SUCCESS;
}



/*---------------------------------------------------------------------------------------------------------*/
/* Function:        DrvPS2_Close                                                                          */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*					None                                                                                   */
/* RETURN                                                                                                  */
/*                  None                                                                                   */
/* Side effects:                                                                                           */
/* Description:                                                                                            */
/*                  Disable PS2 IP, disable ISR.                                                  		   */
/*---------------------------------------------------------------------------------------------------------*/

void DrvPS2_Close()
{
	PS2->PS2CON.PS2EN = 0;
	SYSCLK->APBCLK.PS2_EN = 0;
	
	SYS->IPRSTC2.PS2_RST = 1;
    SYS->IPRSTC2.PS2_RST = 0;
    
    PS2->PS2CON.TXFIFO_DEPTH = 0;
}


/*---------------------------------------------------------------------------------------------------------*/
/* Interrupt Handler                                                                                 	   */
/*---------------------------------------------------------------------------------------------------------*/
void PS2_IRQHandler(void)
{
    uint32_t u32IntStatus;

    u32IntStatus = PS2->u32INTID;
    PS2->u32INTID = 3;
    if(g_pfnPS2callback != NULL)
    {
        g_pfnPS2callback(u32IntStatus);
    }
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_EnableInt                                                                     	   */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               u32InterruptFlag -[in]	DRVPS2_TXINT/DRVPS2_RXINT                                          */
/* Returns:                                                                                                */
/*                                                                                                         */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to enable PS2 Interrupt and Install the call back function          */
/*---------------------------------------------------------------------------------------------------------*/
int32_t
DrvPS2_EnableInt(
	uint32_t  u32InterruptFlag,
	PFN_DRVPS2_CALLBACK pfncallback
)
{

	PS2->PS2CON.TXINTEN = (u32InterruptFlag & DRVPS2_TXINT)?1:0;
	PS2->PS2CON.RXINTEN = (u32InterruptFlag & DRVPS2_RXINT)?1:0;

	g_pfnPS2callback = pfncallback;
	
	NVIC_SetPriority (PS2_IRQn, (1<<__NVIC_PRIO_BITS) - 2);
	NVIC_EnableIRQ(PS2_IRQn);

	return E_SUCCESS;

}

																  
/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_IsIntEnabled                                                                 	   */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               u32InterruptFlag -[in]	DRVPS2_TXINT/DRVPS2_RXINT                                          */
/* Returns:                                                                                                */
/*                                                                                                         */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to get the interrupt enable status								   */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t 
DrvPS2_IsIntEnabled(
	uint32_t	u32InterruptFlag
)
{
	uint32_t u32Reg = *((uint32_t *)&(PS2->PS2CON));
	return (u32Reg &
		 (u32InterruptFlag & (DRVPS2_RXINT | DRVPS2_TXINT)));
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_DisableInt                                                                   	   */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               u32InterruptFlag -[in]	DRVPS2_TXINT/DRVPS2_RXINT										   */
/* Returns:                                                                                                */
/*                                                                                                         */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */
/*               The function is used to disable PS2 Interrupt and uninstall the call back function        */
/*---------------------------------------------------------------------------------------------------------*/
 
void DrvPS2_DisableInt(
	uint32_t	u32InterruptFlag
)
{
	if(u32InterruptFlag & DRVPS2_TXINT)
		_DRVPS2_TXINTDISABLE();
	if(u32InterruptFlag & DRVPS2_RXINT)
		_DRVPS2_RXINTDISABLE();

	g_pfnPS2callback = NULL;
    NVIC_DisableIRQ(PS2_IRQn);

}


/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvPS2_ClearInt                                                                     	   */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               u32InterruptFlag     -[in]   DRVPS2_TXINT/DRVPS2_RXINT                                    */
/* Returns:                                                                                                */
/*                                                                                                         */
/* Side effects:                                                                                           */
/*                                                                                                         */
/* Description:                                                                                            */

⌨️ 快捷键说明

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