1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2019 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_trgmux.h"
10 
11 /* Component ID definition, used by tools. */
12 #ifndef FSL_COMPONENT_ID
13 #define FSL_COMPONENT_ID "platform.drivers.trgmux"
14 #endif
15 
16 /*******************************************************************************
17  * Code
18  ******************************************************************************/
19 
20 /*!
21  * brief Configures the trigger source of the appointed peripheral.
22  *
23  * The function configures the trigger source of the appointed peripheral.
24  * Example:
25    code
26    TRGMUX_SetTriggerSource(TRGMUX0, kTRGMUX_Trgmux0Dmamux0, kTRGMUX_TriggerInput0, kTRGMUX_SourcePortPin);
27    endcode
28  * param base        TRGMUX peripheral base address.
29  * param index       The index of the TRGMUX register, see the enum trgmux_device_t
30  *                    defined in \<SOC\>.h.
31  * param input       The MUX select for peripheral trigger input
32  * param trigger_src The trigger inputs for various peripherals. See the enum trgmux_source_t
33  *                    defined in \<SOC\>.h.
34  * retval  kStatus_Success  Configured successfully.
35  * retval  kStatus_TRGMUX_Locked   Configuration failed because the register is locked.
36  */
TRGMUX_SetTriggerSource(TRGMUX_Type * base,uint32_t index,trgmux_trigger_input_t input,uint32_t trigger_src)37 status_t TRGMUX_SetTriggerSource(TRGMUX_Type *base, uint32_t index, trgmux_trigger_input_t input, uint32_t trigger_src)
38 {
39     uint32_t value;
40     status_t status;
41 
42     value = base->TRGCFG[index];
43     if (0U != (value & TRGMUX_TRGCFG_LK_MASK))
44     {
45         status = kStatus_TRGMUX_Locked;
46     }
47     else
48     {
49         /* Since all SEL bitfileds in TRGCFG register have the same length, SEL0's mask is used to access other SEL
50          * bitfileds. */
51         value = (value & ~((uint32_t)TRGMUX_TRGCFG_SEL0_MASK << (uint32_t)input)) |
52                 ((trigger_src & (uint32_t)TRGMUX_TRGCFG_SEL0_MASK) << (uint32_t)input);
53         base->TRGCFG[index] = value;
54 
55         status = kStatus_Success;
56     }
57 
58     return status;
59 }
60