drv_interrupt.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 134 行
C
134 行
/**************************************************************************/
/* */
/* Copyright (C) 2005 Oki Electric Industry Co., LTD. */
/* */
/* System Name : uPLAT7D series */
/* Module Name : uPLAT7D interrupt drivers program */
/* File Name : drv_interrupt.c */
/* Revision : 01.00 */
/* Create : LXF 05/12/26 */
/* */
/**************************************************************************/
#include "common.h"
#include "drv_common.h"
#include "hal_api.h"
#include "drv_interrupt.h"
#include "hal_pio.h"
#include "intrinsics.h"
#define FIQ_PORT_SEL_MASK 0xffcfffff
#define FIQ_PORT_SEL_SET 0x00200000
#define EXINT1_PORT_SEL_MASK 0xff3fffff
#define EXINT1_PORT_SEL_SET 0x00800000
/******************************/
/* Private defines */
/******************************/
/*--------- variable ---------*/
static uint16_t int_primary;
/*--------- function ---------*/
/******************************/
/* Public defines */
/******************************/
volatile uint16_t count_interval;
void update_count(uint16_t);
/************************************************************************/
/* */
/* Function Name : smpDrv_OpenInterrupt */
/* Input : param Parameter of interrupt. */
/* Output : DRV_OK(1) */
/* : DRV_PARAM_ERROR(-2) */
/* */
/* Note : Open the driver of interrupt. */
/* */
/************************************************************************/
int16_t smpDrv_OpenInterrupt(const uPLAT_InterruptParam *param) {
int16_t rtnVal = DRV_OK;
uPLAT_PioFunctionParam port_param;
int_primary = param->primary;
if (param->primary == INT_FIQ) {
/* Get port function. */
rtnVal = uplat7dHAL_PioGetFunction(&port_param);
if (rtnVal != DRV_OK) {
return rtnVal;
}
/* Set FIQ port third function. */
port_param.port_sel1 = (port_param.port_sel1 & FIQ_PORT_SEL_MASK)
| FIQ_PORT_SEL_SET;
rtnVal = uplat7dHAL_PioSetFunction(&port_param);
if (rtnVal != DRV_OK) {
return rtnVal;
}
}
else if (param->primary == INT_EXINT1) {
/* Get port function. */
rtnVal = uplat7dHAL_PioGetFunction(&port_param);
if (rtnVal != DRV_OK) {
return rtnVal;
}
/* Set FIQ port third function. */
port_param.port_sel1 = (port_param.port_sel1 & EXINT1_PORT_SEL_MASK)
| EXINT1_PORT_SEL_SET;
rtnVal = uplat7dHAL_PioSetFunction(&port_param);
if (rtnVal != DRV_OK) {
return rtnVal;
}
}
rtnVal = uplat7dHAL_InterruptSetPrimary(param);
if (param->primary == INT_FIQ) {
/* Enable fiq interrupt. */
__enable_interrupt(); // fiq_en();
}
else {
/* Enable irq interrupt. */
__enable_interrupt(); // irq_en();
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : smpDrv_CloseInterrupt */
/* Input : void */
/* Output : DRV_OK(1) */
/* : DRV_PARAM_ERROR(-2) */
/* */
/* Note : Close the driver of interrupt. */
/* */
/************************************************************************/
int16_t smpDrv_CloseInterrupt(void) {
int16_t rtnVal = DRV_OK;
if (int_primary == INT_FIQ) {
/* Disable fiq interrupt. */
__disable_interrupt();//fiq_dis();
}
else {
/* Disable irq interrupt. */
__disable_interrupt(); //irq_dis(); /* Disable Interrupt */
}
return rtnVal;
}
/************************************************************************/
/* */
/* Function Name : update_count */
/* Input : i */
/* Output : void */
/* */
/* Note : Update timer count interval. */
/* */
/************************************************************************/
void update_count(uint16_t i) {
count_interval += 50;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?