/**
* @file xmc_eru.h
* @date 2016-03-10
*
* @cond
*********************************************************************************************************************
* XMClib v2.1.24 - XMC Peripheral Driver Library
*
* Copyright (c) 2015-2019, Infineon Technologies AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
* following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
* Infineon Technologies AG dave@infineon.com).
*********************************************************************************************************************
*
* Change History
* --------------
*
* 2015-02-20:
* - Initial
* - Documentation updates
*
* 2015-06-20:
* - Removed version macros and declaration of GetDriverVersion API
*
* 2015-10-07:
* - Doc update for XMC_ERU_ETL_CONFIG_t field
*
* 2016-03-10:
* - XMC_ERU_ETL_GetEdgeDetection() API is added to get the configured edge for event generation.
*
* @endcond
*/
#ifndef XMC_ERU_H
#define XMC_ERU_H
/*********************************************************************************************************************
* HEADER FILES
********************************************************************************************************************/
#include "xmc_common.h"
/**
* @addtogroup XMClib XMC Peripheral Library
* @{
*/
/**
* @addtogroup ERU
* @brief Event Request Unit (ERU) driver for the XMC microcontroller family.
*
* The Event Request Unit (ERU) is a versatile multiple input event detection and processing unit.
* The ERU module can be used to expand the P-to-P connections of the device: ports-to-peripherals,
* peripherals-to-peripherals and ports-to-ports. It also offers configurable logic, that allows the generation of
* triggers, pattern detection and real-time signal monitoring.
*
* @image html "eru_overview.png"
*
* The driver is divided into two sections:
* \par Event trigger logic (ERU_ETL):
* This section of the LLD provides the configuration structure XMC_ERU_ETL_CONFIG_t and the initialization function
* XMC_ERU_ETL_Init().\n
* It can be used to:
* -# Select one out of two inputs (A and B). For each of these two inputs, a vector of 4 possible signals is available.
* (XMC_ERU_ETL_SetSource())
* -# Logically combine the two input signals to a common trigger. (XMC_ERU_ETL_SetSource())
* -# Define the transition (edge selection, or by software) that leads to a trigger event and can also store this status.
* (XMC_ERU_ETL_SetEdgeDetection() and XMC_ERU_ETL_SetStatusFlag())
* -# Distribute the events and status flags to the output channels. (XMC_ERU_ETL_EnableOutputTrigger())
*
* \par Output gating unit (ERU_OGU):
* This section of the LLD provides the provides the configuration structure XMC_ERU_OGU_CONFIG_t and the initialization
* function XMC_ERU_ETL_OGU_Init().
* It can be used to:
* -# Combine the trigger events and status information and gates the output depending on a gating signal.
* (XMC_ERU_OGU_EnablePatternDetection(), XMC_ERU_OGU_DisablePeripheralTrigger(), XMC_ERU_OGU_SetServiceRequestMode())
* @{
*/
/*********************************************************************************************************************
* MACROS
********************************************************************************************************************/
#if defined(ERU0)
#define XMC_ERU0 ((XMC_ERU_t *) ERU0_BASE) /**< ERU module 0 */
#endif
#if defined(ERU1)
#define XMC_ERU1 ((XMC_ERU_t *) ERU1_BASE) /**< ERU module 1, only available in XMC4 family */
#endif
#if UC_FAMILY == XMC1
#include "xmc1_eru_map.h"
#endif
#if UC_FAMILY == XMC4
#include "xmc4_eru_map.h"
#endif
#if defined(XMC_ERU0) && defined(XMC_ERU1)
#define XMC_ERU_CHECK_MODULE_PTR(PTR) (((PTR)== XMC_ERU0) | ((PTR)== XMC_ERU1))
#elif defined(XMC_ERU0)
#define XMC_ERU_CHECK_MODULE_PTR(PTR) (((PTR)== XMC_ERU0))
#elif defined(XMC_ERU1)
#define XMC_ERU_CHECK_MODULE_PTR(PTR) (((PTR)== XMC_ERU0))
#endif
/*********************************************************************************************************************
* ENUMS
********************************************************************************************************************/
/**
* Defines input signal for path A of ERSx(Event request source, x = [0 to 3]) unit.
* @image html "eru_input_a.png" "ETLx Input A selection"
*/
typedef enum XMC_ERU_ETL_INPUT_A
{
XMC_ERU_ETL_INPUT_A0 = 0x0U, /**< input A0 is selected */
XMC_ERU_ETL_INPUT_A1 = 0x1U, /**< input A1 is selected */
XMC_ERU_ETL_INPUT_A2 = 0x2U, /**< input A2 is selected */
XMC_ERU_ETL_INPUT_A3 = 0x3U /**< input A3 is selected */
} XMC_ERU_ETL_INPUT_A_t;
/**
* Defines input signal for path B of ERSx(Event request source, x = [0 to 3]) unit.
* @image html "eru_input_b.png" "ETLx Input B selection"
*/
typedef enum XMC_ERU_ETL_INPUT_B
{
XMC_ERU_ETL_INPUT_B0 = 0x0U, /**< input B0 is selected */
XMC_ERU_ETL_INPUT_B1 = 0x1U, /**< input B1 is selected */
XMC_ERU_ETL_INPUT_B2 = 0x2U, /**< input B2 is selected */
XMC_ERU_ETL_INPUT_B3 = 0x3U /**< input B3 is selected */
} XMC_ERU_ETL_INPUT_B_t;
/**
* Defines input path combination along with polarity for event generation by ERSx(Event request source) unit to
* ETLx(Event trigger logic),x = [0 to 3] unit.
* @image html "eru_input_trigger.png" "ETLx input trigger signal generation"
*/
typedef enum XMC_ERU_ETL_SOURCE
{
XMC_ERU_ETL_SOURCE_A = 0x0U, /**< select (A) path as a event source */
XMC_ERU_ETL_SOURCE_B = 0x1U, /**< select (B) path as a event source */
XMC_ERU_ETL_SOURCE_A_OR_B = 0x2U, /**< select (A OR B) path as a event source */
XMC_ERU_ETL_SOURCE_A_AND_B = 0x3U, /**< select (A AND B) path as a event source */
XMC_ERU_ETL_SOURCE_NOT_A = 0x4U, /**< select (inverted A) path as a event source */
XMC_ERU_ETL_SOURCE_NOT_A_OR_B = 0x6U, /**< select (inverted A OR B) path as a event source */
XMC_ERU_ETL_SOURCE_NOT_A_AND_B = 0x7U, /**< select (inverted A AND B) path as a event source */
XMC_ERU_ETL_SOURCE_NOT_B = 0x9U, /**< select (inverted B) path as a event source */
XMC_ERU_ETL_SOURCE_A_OR_NOT_B = 0xaU, /**< select (A OR inverted B) path as a event source */
XMC_ERU_ETL_SOURCE_A_AND_NOT_B = 0xbU, /**< select (A AND inverted B) path as a event source */
XMC_ERU_ETL_SOURCE_NOT_A_OR_NOT_B = 0xeU, /**< select (inverted A OR inverted B) path as a event
source */
XMC_ERU_ETL_SOURCE_NOT_A_AND_NOT_B = 0xfU /**< select (inverted A AND inverted B) path as a event
source */
} XMC_ERU_ETL_SOURCE_t;
/**
* Defines trigger edge for the event generation by ETLx (Event Trigger Logic, x = [0 to 3]) unit, by getting the signal
* from ERSx(Event request source, x = [0 to 3]) unit.
*/
typedef enum XMC_ERU_ETL_EDGE_DETECTION
{
XMC_ERU_ETL_EDGE_DETECTION_DISABLED = 0U, /**< no event enabled */
XMC_ERU_ETL_EDGE_DETECTION_RISING = 1U, /**< detection of rising edge generates the event */
XMC_ERU_ETL_EDGE_DETECTION_FALLING = 2U, /**< detection of falling edge generates the event */
XMC_ERU_ETL_EDGE_DETECTION_BOTH = 3U /**< detection of either edges generates the event */
} XMC_ERU_ETL_EDGE_DETECTION_t;
/**
* Defines Output Channel of OGUy(Output gating unit y = [0 to 3]) to be mapped by the trigger pulse generated by
* ETLx(Event Trigger Logic, x = [0 to 3]) unit.
* @note Generation of output trigger pulse need to be enabled @ref XMC_ERU_OGU_PERIPHERAL_TRIGGER_t
* @image html "eru_connection_matrix.png" "ERU_ETL ERU_OGU Connection matrix"
*/
typedef enum XMC_ERU_ETL_OUTPUT_TRIGGER_CHANNEL
{
XMC_ERU_ETL_OUTPUT_TRIGGER_CHANNEL0 = 0U, /**< Event from input ETLx triggers output OGU0 */
XMC_ERU_ETL_OUTPUT_TRIGGER_CHANNEL1 = 1U, /**< Event from input ETLx triggers output OGU1 */
XMC_ERU_ETL_OUTPUT_TRIGGER_CHANNEL2 = 2U, /**< Event from input ETLx triggers output OGU2 */
XMC_ERU_ETL_OUTPUT_TRIGGER_CHANNEL3 = 3U, /**< Event from input ETLx triggers output OGU3 */
} XMC_ERU_ETL_OUTPUT_TRIGGER_CHANNEL_t;
/**
* Defines generation of the trigger pulse by ETLx(Event Trigger Logic, x = [0 to 3]) unit.
* Use type XMC_ERU_ETL_OUTPUT_TRIGGER_t for this enum.
*/
typedef enum XMC_ERU_ETL_OUTPUT_TRIGGER
{
XMC_ERU_ETL_OUTPUT_TRIGGER_DISABLED = 0U, /**< trigger pulse generation disabled */
XMC_ERU_ETL_OUTPUT_TRIGGER_ENABLED = 1U /**< trigger pulse generation enabled */
} XMC_ERU_ETL_OUTPUT_TRIGGER_t;
/**
* Defines status flag reset mode generated by ETLx(Event Trigger Logic, x = [0 to 3]) unit.
* Use type XMC_ERU_ETL_STATUS_FLAG_MODE_t for this enum.
*/
typedef enum XMC_ERU_ETL_STATUS_FLAG_MODE
{
XMC_ERU_ETL_STATUS_FLAG_MODE_SWCTRL = 0U, /**< Status flag is in sticky mode. Retain the same state until
cleared by software. In case of pattern match this mode
is used. */
XMC_ERU_ETL_STATUS_FLAG_MODE_HWCTRL = 1U /**< Status flag is in non-sticky mode. Automatically cleared by
the opposite edge detection.\n
eg. if positive edge is selected as trigger event, for the
negative edge event the status flag is cleared. */
} XMC_ERU_ETL_STATUS_FLAG_MODE_t;
/**
* Defines pattern detection feature to be enabled or not in OGUy(Output gating unit, y = [0 to 3]).
*
*/
typedef enum XMC_ERU_OGU_PATTERN_DETECTION
{
XMC_ERU_OGU_PATTERN_DETECTION_DISABLED = 0U, /**< Pattern match is disabled */
XMC_ERU_OGU_PATTERN_DETECTION_ENABLED = 1U /**< Pattern match is enabled, the selected status flags of
ETLx(Event Trigger Logic, x = [0 to 3]) unit, are
used in pattern detection. */
} XMC_ERU_OGU_PATTERN_DETECTION_t;
/**
* Defines the inputs for Pattern detection. The configured status flag signal from the ETLx(Event Trigger Logic,
* x = [0 to 3]) unit indicates the pattern to be detected.
*/
typedef enum XMC_ERU_OGU_PATTERN_DETECTION_INPUT
{
XMC_ERU_OGU_PATTERN_DETECTION_INPUT0 = 1U, /**< Status flag ETL0, participating in pattern match */
XMC_ERU_OGU_PATTERN_DETECTION_INPUT1 = 2U, /**< Status flag ETL1, participating in pattern match */
XMC_ERU_OGU_PATTERN_DETECTION_INPUT2 = 4U, /**< Status flag ETL0, participating in pattern match */
XMC_ERU_OGU_PATTERN_DETECTION_INPUT3 = 8U /**< Status flag ETL0, participating in pattern match */
} XMC_ERU_OGU_PATTERN_DETECTION_INPUT_t;
/**
* Defines peripheral trigger signal for event generation. Based on the selected peripheral for event generation,
* the trigger signal is mapped.
*/
typedef enum XMC_ERU_OGU_PERIPHERAL_TRIGGER
{
XMC_ERU_OGU_PERIPHERAL_TRIGGER1 = 1U, /**< OGUy1 signal is mapped for event generation */
XMC_ERU_OGU_PERIPHERAL_TRIGGER2 = 2U, /**< OGUy2 signal is mapped for event generation */
XMC_ERU_OGU_PERIPHERAL_TRIGGER3 = 3U /**< OGUy3 signal is mapped for event generation */
} XMC_ERU_OGU_PERIPHERAL_TRIGGER_t;
/**
* Defines the gating scheme for service request generation. In later stage of the OGUy(Output gating unit,
* y = [0 to 3]) based on the gating scheme selected ERU_GOUTy(gated output signal) output is defined.
* @image html "interrupt_gating_signal.png" "Interrupt gating signal"
*/
typedef enum XMC_ERU_OGU_SERVICE_REQUEST
{
XMC_ERU_OGU_SERVICE_REQUEST_DISABLED = 0U, /**< Service request blocked, ERUx_GOUTy = 0 */
XMC_ERU_OGU_SERVICE_REQUEST_ON_TRIGGER = 1U, /**< Service request generated enabled, ERUx_GOUTy = 1 */
XMC_ERU_OGU_SERVICE_REQUEST_ON_TRIGGER_AND_PATTERN_MATCH = 2U, /**< Service request generated on trigger
event and input pattern match,
ERUx_GOUTy = ~pattern matching result*/
XMC_ERU_OGU_SERVICE_REQUEST_ON_TRIGGER_AND_PATTERN_MISMATCH = 3U/**< Service request generated on trigger
event and input pattern mismatch,
ERUx_GOUTy = pattern matching result*/
} XMC_ERU_OGU_SERVICE_REQUEST_t;
/*********************************************************************************************************************
* DATA STRUCTURES
********************************************************************************************************************/
/*Anonymous structure/union guard start*/
#if defined(__CC_ARM)
#pragma push
#pragma anon_unions
#elif defined(__TASKING__)
#pragma warning 586
#endif
/**
* ERU module
*/
typedef struct {
union {
__IO uint32_t EXISEL;
struct {
__IO uint32_t EXS0A : 2;
__IO uint32_t EXS0B : 2;
__IO uint32_t EXS1A : 2;
__IO uint32_t EXS1B : 2;
__IO uint32_t EXS2A : 2;
__IO uint32_t EXS2B : 2;
__IO uint32_t EXS3A : 2;
__IO uint32_t EXS3B : 2;
} EXISEL_b;
};
__I uint32_t RESERVED0[3];
union {
__IO uint32_t EXICON[4];
struct {
__IO uint32_t PE : 1;
__IO uint32_t LD : 1;
__IO uint32_t ED : 2;
__IO uint32_t OCS : 3;
__IO uint32_t FL : 1;
__IO uint32_t SS : 4;
__I uint32_t RESERVED1 : 20;
} EXICON_b[4];
};
union {
__IO uint32_t EXOCON[4];
struct {
__IO uint32_t ISS : 2;
__IO uint32_t GEEN : 1;
__I uint32_t PDR : 1;
__IO uint32_t GP : 2;
uint32_t : 6;
__IO uint32_t IPEN : 4;
__I uint32_t RESERVED2 : 16;
} EXOCON_b[4];
};
} XMC_ERU_t;
/**
* \if XMC4
* Structure for initializing ERUx_ETLy (x = [0..1], y = [0..4]) module.
* \endif
* \if XMC1
* Structure for initializing ERUx_ETLy (x = [0], y = [0..4]) module.
* \endif
*/
typedef struct XMC_ERU_ETL_CONFIG
{
union
{
uint32_t input; /**< While configuring the bit fields, the values have to be shifted according to the position */
struct
{
uint32_t input_a: 2; /**< Configures input A. Refer @ref XMC_ERU_ETL_INPUT_A_t for valid values */
uint32_t input_b: 2; /**< Configures input B. Refer @ref XMC_ERU_ETL_INPUT_B_t for valid values */
uint32_t : 28;
};
};
union
{
uint32_t raw;
struct
{
uint32_t enable_output_trigger: 1; /**< Enables the generation of trigger pulse(PE), for the configured edge
detection. This accepts boolean values as input. */
uint32_t status_flag_mode: 1; /**< Enables the status flag auto clear(LD), for the opposite edge of the
configured event edge. This accepts boolean values as input. */
uint32_t edge_detection: 2; /**< Configure the event trigger edge(FE, RE).
Refer @ref XMC_ERU_ETL_EDGE_DETECTION_t for valid values. */
uint32_t output_trigger_channel: 3; /**< Output channel select(OCS) for ETLx output trigger pulse.
Refer @ref XMC_ERU_ETL_OUTPUT_TRIGGER_CHANNEL_t for valid values. */
uint32_t : 1;
uint32_t source: 4; /**< Input path combination along with polarity for event generation.
Refer @ref XMC_ERU_ETL_SOURCE_t for valid values. */
uint32_t : 20;
};
};
} XMC_ERU_ETL_CONFIG_t;
/**
* \if XMC4
* Structure for initializing ERUx_OGUy (x = [0..1], y = [0..4]) module.
* \endif
* \if XMC1
* Structure for initializing ERUx_OGUy (x = [0], y = [0..4]) module.
* \endif
*/
typedef union XMC_ERU_OGU_CONFIG
{
uint32_t raw;
struct
{
uint32_t peripheral_trigger: 2; /**< peripheral trigger(ISS) input selection.
Refer @ref XMC_ERU_OGU_PERIPHERAL_TRIGGER_t for valid values. */
uint32_t enable_pattern_detection: 1; /**< Enable generation of(GEEN) event for pattern detection result change.
This accepts boolean values as input. */
uint32_t : 1;
uint32_t service_request: 2; /**< Gating(GP) on service request generation for pattern detection result.
Refer @ref XMC_ERU_OGU_SERVICE_REQUEST_t for valid values. */
uint32_t : 6;
uint32_t pattern_detection_input: 4; /**< Enable input for the pattern detection(IPENx, x = [0 to 3]).
Refer @ref XMC_ERU_OGU_PATTERN_DETECTION_INPUT_t for valid values.
OR combination of the enum items given as input */
uint32_t : 16;
};
} XMC_ERU_OGU_CONFIG_t;
/*Anonymous structure/union guard end */
#if defined(__CC_ARM)
#pragma pop
#elif defined(__TASKING__)
#pragma warning restore
#endif
/*********************************************************************************************************************
* API PROTOTYPES
********************************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @param eru A constant pointer to XMC_ERU_t, pointing to the ERU base address
*
* @return None
*
* \parDescription:
* \if XMC4
* If ERU1 module is selected, it enables clock and releases reset.
* \endif
* \if XMC1
* Abstract API, not mandatory to call.
* \endif
* \par
* This API is called by XMC_ERU_ETL_Init() or XMC_ERU_OGU_Init() and therefore no need to call it explicitly during
* initialization sequence. Call this API to enable ERU1 module once again if the module is disabled by calling
* XMC_ERU_Disable(). For ERU0 module clock gating and reset features are not available.
*
* \parNote:
* \if XMC4
* 1. Required to configure ERU1 module again after calling XMC_ERU_Disable(). Since the all the registers are
* reset with default values.
* \endif
* \parRelated APIs:
* XMC_ERU_ETL_Init(), XMC_ERU_OGU_Init(), XMC_ERU_Disable().
*/
void XMC_ERU_Enable(XMC_ERU_t *const eru);
/**
* @param eru A constant pointer to XMC_ERU_t, pointing to the ERU base address
*
* @return None
*
* \parDescription:
* \if XMC4
* Disables clock and releases reset for ERU1 module.
* \endif
* \if XMC1
* Abstract API, not mandatory to call.
* \endif
*
* \parNote:
* \if XMC4
* 1. Required to configure ERU1 module again after calling XMC_ERU_ETL_Init() or XMC_ERU_OGU_Init(). Since the all the
* registers are reset with default values.
* \endif
* \parRelated APIs:
* XMC_ERU_Enable()
*/
void XMC_ERU_Disable(XMC_ERU_t *const eru);
/* ERU_ETL APIs */
/**
* @param eru A constant pointer to XMC_ERU_t, pointing to the ERU base address
* @param channel ERU_ETLx(Event trigger logic unit) channel
* Range : [0 to 3]
* @param config pointer to a constant ERU_ETLx configuration data structure.
* Refer data structure XMC_ERU_ETL_CONFIG_t for detail.
*
* @return None
*
* Description:
* Initializes the selected ERU_ETLx \a channel with the \a config structure.
*
* Invokes XMC_ERU_Enable() to enable \a eru module clock. Then configures
*