参考 AURIX™ TC3xx User Manual Part-1
ERU, Event Request Unit, 外部请求单元. TC3XX User Manual 第9章System Control Units (SCU)
第5小节介绍了ERU.
先来看一下系统控制单元SCU, SCU是控制各种系统功能的子模块的集群, 包括:
这些子模块共享一个公共总线接口.
其中, ERU用于在输入引脚的每个上升沿和下降沿生成中断:
ERU特性列表:
TC3xx ERU相比TC2xx ERU最重要的变化是:
ERU Overview:
这些任务由以下构建块(building block)处理:
可以从大量输入信号中选择ERU的输入, 这些输入中的16个直接来自输入端口,而其他输入则来自各种外围模块状态信号.
REQxy Digital PORT Input Glitch Filter (FILT), 毛刺滤波器仅在端口(PORTS)可用, 用寄存器EIFILT配置, 用于抑制信号噪声导致PORTS的输入引脚上发生的不必要的快速转换, 类似于延时消抖. 滤波器预分频器可以设置为1到15之间的值,从而提供从10ns ~ >2µs的可能的毛刺特性范围, 通常,3~5 Tfilt的深度就足够了. 默认情况下,它是清除的. 如果清除了DEPTH,则所有过滤器均处于非活动状态:
Event Trigger Logic (ETLx), 事件触发逻辑, 基于边缘检测模块,在该模块中,可以分别启用对上升沿或下降沿的检测. 如果两个使能位都被置位(例如处理触发输入),则两个边沿都会导致触发事件. 四个ETL单元中的每对都有一个关联的EICRy寄存器,该寄存器控制ETL的所有选项(该寄存器还保存关联的ERS单元对的控制位):
Output Gating Unit (OGU), 输出门控单元, 每个OGU的功能可以分成2个部分:
可用的ERU外部中断引脚其实是非常少的, 自己设计板子的时候万万注意:
参考 ERU_Interrupt_1 for KIT_AURIX_TC397_TFT
本例中用P02.1模拟产生方波, 连接P02.1和P02.0, 在P02.0的每一个升降沿产生中断, 中断里面翻转LED.
本例的配置步骤如下图:
Cpu0_Main.c代码如下:
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
#include "Ifx_Types.h"
#include "IfxSrc.h"
#include "IfxScuEru.h"
#include "Bsp.h"
#define TRIGGER_PIN &MODULE_P02,1 /* Pin which can be controlled via debugger
to trigger interrupt */
#define LED &MODULE_P13,0 /* LED which gets toggled in Interrupt Service Routine */
#define ISR_PRIORITY_SCUERU_INT0 40 /* Define the SCU ERU interrupt priority */
#define REQ_IN &IfxScu_REQ3C_P02_0_IN /* External request pin */
typedef struct
{
IfxScu_Req_In *reqPin; /* External request pin */
IfxScuEru_InputChannel inputChannel; /* Input channel EICRm depending on input pin */
IfxScuEru_InputNodePointer triggerSelect; /* Input node pointer */
IfxScuEru_OutputChannel outputChannel; /* Output channel */
volatile Ifx_SRC_SRCR *src; /* Service request register */
} ERUconfig;
ERUconfig g_ERUconfig;
IFX_INTERRUPT(SCUERU_Int0_Handler, 0, ISR_PRIORITY_SCUERU_INT0);
void SCUERU_Int0_Handler(void)
{
IfxPort_setPinState(LED, IfxPort_State_toggled); /* Toggle LED */
}
void core0_main(void)
{
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
//initLED, initPin
IfxPort_setPinMode(LED, IfxPort_Mode_outputPushPullGeneral);
IfxPort_setPinMode(TRIGGER_PIN, IfxPort_Mode_outputPushPullGeneral);
IfxPort_setPinState(LED, IfxPort_State_high);
IfxPort_setPinState(TRIGGER_PIN, IfxPort_State_high);
initTime();
//initERU
/* Trigger pin */
g_ERUconfig.reqPin = REQ_IN; /* Select external request pin */
/* Initialize this pin with pull-down enabled
* This function will also configure the input multiplexers of the ERU (Register EXISx)
*/
IfxScuEru_initReqPin(g_ERUconfig.reqPin, IfxPort_InputMode_pullDown);
/* Determine input channel depending on input pin */
g_ERUconfig.inputChannel = (IfxScuEru_InputChannel) g_ERUconfig.reqPin->channelId;
/* Input channel configuration */
IfxScuEru_enableRisingEdgeDetection(g_ERUconfig.inputChannel); /* Interrupt triggers on
rising edge (Register RENx) and */
IfxScuEru_enableFallingEdgeDetection(g_ERUconfig.inputChannel); /* on falling edge (Register FENx) */
/* Signal destination */
g_ERUconfig.outputChannel = IfxScuEru_OutputChannel_0; /* OGU channel 0 */
/* Event from input ETL0 triggers output OGU0 (signal TRx0) */
g_ERUconfig.triggerSelect = IfxScuEru_InputNodePointer_0;
/* Connecting Matrix, Event Trigger Logic ETL block */
/* Enable generation of trigger event (Register EIENx) */
IfxScuEru_enableTriggerPulse(g_ERUconfig.inputChannel);
/* Determination of output channel for trigger event (Register INPx) */
IfxScuEru_connectTrigger(g_ERUconfig.inputChannel, g_ERUconfig.triggerSelect);
/* Configure Output channels, OutputGating Unit OGU (Register IGPy) */
IfxScuEru_setInterruptGatingPattern(g_ERUconfig.outputChannel, IfxScuEru_InterruptGatingPattern_alwaysActive);
/* Service request configuration */
/* Get source pointer depending on outputChannel (SRC_SCUERU0 for outputChannel0) */
g_ERUconfig.src = &MODULE_SRC.SCU.SCUERU[(int) g_ERUconfig.outputChannel % 4];
IfxSrc_init(g_ERUconfig.src, IfxSrc_Tos_cpu0, ISR_PRIORITY_SCUERU_INT0);
IfxSrc_enable(g_ERUconfig.src);
while(1)
{
IfxPort_setPinState(TRIGGER_PIN, IfxPort_State_toggled);
waitTime(TimeConst_1s);
}
}
编译运行, 短接P02.0和P02.1, 可以看到LED每秒翻转一次.
欢迎扫描关注我的微信公众号, 及时获取最新文章: