S32 SDK
trgmux_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
38 #include <stddef.h>
39 #include "trgmux_driver.h"
40 #include "trgmux_hw_access.h"
41 
42 /*******************************************************************************
43  * Variables
44  ******************************************************************************/
45 
48 
49 
50 /*******************************************************************************
51  * Code
52  ******************************************************************************/
53 
54 /*FUNCTION**********************************************************************
55  *
56  * Function Name : TRGMUX_DRV_Init
57  * Description : This function first resets the source triggers of all TRGMUX target modules
58  * to their default values, then configures the TRGMUX with all the user defined in-out mappings.
59  * If at least one of the target modules is locked, the function will not change any of the
60  * TRGMUX target modules and return an error code.
61  * This example shows how to set up the trgmux_user_config_t parameters and how to call the
62  * TRGMUX_DRV_Init() function with the required parameters:
63  * trgmux_user_config_t trgmuxConfig;
64  * trgmux_inout_mapping_config_t trgmuxInoutMappingConfig[] =
65  * {
66  * {TRGMUX_TRIG_SOURCE_TRGMUX_IN9, TRGMUX_TARGET_MODULE_DMA_CH0, false},
67  * {TRGMUX_TRIG_SOURCE_FTM1_EXT_TRIG, TRGMUX_TARGET_MODULE_TRGMUX_OUT4, true}
68  * };
69  * trgmuxConfig.numInOutMappingConfigs = 2;
70  * trgmuxConfig.inOutMappingConfig = trgmuxInoutMappingConfig;
71  * TRGMUX_DRV_Init(instance, &trgmuxConfig);
72  *
73  * Implements : TRGMUX_DRV_Init_Activity
74  *END**************************************************************************/
75 status_t TRGMUX_DRV_Init(const uint32_t instance,
76  const trgmux_user_config_t * const trgmuxUserConfig)
77 {
79  DEV_ASSERT(trgmuxUserConfig != NULL);
80 
81  status_t status;
82  TRGMUX_Type * base = s_trgmuxBase[instance];
83  uint8_t count;
84 
85  /* Reset source triggers of all TRGMUX target modules to default. */
86  status = TRGMUX_Init(base);
87 
88  if (status == STATUS_SUCCESS)
89  {
90  /* Loop through all in-out mappings in the configuration and apply them in TRGMUX */
91  for (count = 0U; count < trgmuxUserConfig->numInOutMappingConfigs; count++)
92  {
93  TRGMUX_SetTrigSourceForTargetModule(base, trgmuxUserConfig->inOutMappingConfig[count].triggerSource,
94  trgmuxUserConfig->inOutMappingConfig[count].targetModule);
95  }
96 
97  /* Loop through all in-out mappings in the configuration and lock them if required */
98  for (count = 0U; count < trgmuxUserConfig->numInOutMappingConfigs; count++)
99  {
100  if (trgmuxUserConfig->inOutMappingConfig[count].lockTargetModuleReg)
101  {
102  TRGMUX_SetLockForTargetModule(base, trgmuxUserConfig->inOutMappingConfig[count].targetModule);
103  }
104  }
105  }
106 
107  return status;
108 }
109 
110 /*FUNCTION**********************************************************************
111  *
112  * Function Name : TRGMUX_DRV_Deinit
113  * Description : Reset to default values the source triggers corresponding to all target modules,
114  * if none of the target modules is locked.
115  *
116  * Implements : TRGMUX_DRV_Deinit_Activity
117  *END**************************************************************************/
118 status_t TRGMUX_DRV_Deinit(const uint32_t instance)
119 {
120  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
121 
122  TRGMUX_Type * base = s_trgmuxBase[instance];
123  status_t status;
124 
125  /* Reset source triggers of all TRGMUX target modules to default. */
126  status = TRGMUX_Init(base);
127 
128  return status;
129 }
130 
131 /*FUNCTION**********************************************************************
132  *
133  * Function Name : TRGMUX_DRV_SetTrigSourceForTargetModule
134  * Description : This function configures a TRGMUX link between a source trigger and a target module,
135  * if the requested target module is not locked.
136  *
137  * Implements : TRGMUX_DRV_SetTrigSourceForTargetModule_Activity
138  *END**************************************************************************/
140  const trgmux_trigger_source_t triggerSource,
141  const trgmux_target_module_t targetModule)
142 {
143  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
144 
145  TRGMUX_Type * base = s_trgmuxBase[instance];
146  status_t status;
147  bool lock;
148 
149  lock = TRGMUX_GetLockForTargetModule(base, targetModule);
150 
151  if (lock == true)
152  {
153  status = STATUS_ERROR;
154  }
155  else
156  {
157  /* Configure link between trigger source and target module. */
158  TRGMUX_SetTrigSourceForTargetModule(base, triggerSource, targetModule);
159  status = STATUS_SUCCESS;
160  }
161 
162  return status;
163 }
164 
165 /*FUNCTION**********************************************************************
166  *
167  * Function Name : TRGMUX_DRV_GetTrigSourceForTargetModule
168  * Description : This function returns the TRGMUX source trigger linked to a selected target module.
169  *
170  * Implements : TRGMUX_DRV_GetTrigSourceForTargetModule_Activity
171  *END**************************************************************************/
173  const trgmux_target_module_t targetModule)
174 {
175  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
176 
177  const TRGMUX_Type * base = s_trgmuxBase[instance];
178 
179  return TRGMUX_GetTrigSourceForTargetModule(base, targetModule);
180 }
181 
182 /*FUNCTION**********************************************************************
183  *
184  * Function Name : TRGMUX_DRV_SetLockForTargetModule
185  * Description : This function locks the TRGMUX register of a selected target module.
186  *
187  * Implements : TRGMUX_DRV_SetLockForTargetModule_Activity
188  *END**************************************************************************/
189 void TRGMUX_DRV_SetLockForTargetModule(const uint32_t instance,
190  const trgmux_target_module_t targetModule)
191 {
192  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
193 
194  TRGMUX_Type * base = s_trgmuxBase[instance];
195 
196  TRGMUX_SetLockForTargetModule(base, targetModule);
197 }
198 
199 /*FUNCTION**********************************************************************
200  *
201  * Function Name : TRGMUX_DRV_GetLockForTargetModule
202  * Description : This function gets the value of the LK bit from the TRGMUX register
203  * corresponding to the selected target module.
204  *
205  * Implements : TRGMUX_DRV_GetLockForTargetModule_Activity
206  *END**************************************************************************/
207 bool TRGMUX_DRV_GetLockForTargetModule(const uint32_t instance,
208  const trgmux_target_module_t targetModule)
209 {
210  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
211 
212  const TRGMUX_Type * base = s_trgmuxBase[instance];
213 
214  return TRGMUX_GetLockForTargetModule(base, targetModule);
215 }
216 
217 /*******************************************************************************
218  * EOF
219  ******************************************************************************/
trgmux_trigger_source_t
Describes all possible inputs (trigger sources) of the TRGMUX IP Note: entries in this enum are aff...
Definition: trgmux_driver.h:68
trgmux_trigger_source_t TRGMUX_DRV_GetTrigSourceForTargetModule(const uint32_t instance, const trgmux_target_module_t targetModule)
Get the source trigger configured for a target module.
User configuration structure for the TRGMUX driver.
status_t TRGMUX_DRV_SetTrigSourceForTargetModule(const uint32_t instance, const trgmux_trigger_source_t triggerSource, const trgmux_target_module_t targetModule)
Configure a source trigger for a selected target module.
status_t TRGMUX_DRV_Deinit(const uint32_t instance)
Reset to default values the source triggers corresponding to all target modules, if none of the targe...
static TRGMUX_Type *const s_trgmuxBase[TRGMUX_INSTANCE_COUNT]
Table of base addresses for TRGMUX instances.
Definition: trgmux_driver.c:47
bool TRGMUX_DRV_GetLockForTargetModule(const uint32_t instance, const trgmux_target_module_t targetModule)
Get the Lock bit status of the TRGMUX register of a target module.
#define DEV_ASSERT(x)
Definition: devassert.h:77
const trgmux_inout_mapping_config_t * inOutMappingConfig
uint8_t numInOutMappingConfigs
trgmux_trigger_source_t triggerSource
trgmux_target_module_t
Describes all possible outputs (target modules) of the TRGMUX IP Note: entries in this enum are aff...
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
status_t TRGMUX_DRV_Init(const uint32_t instance, const trgmux_user_config_t *const trgmuxUserConfig)
Initialize a TRGMUX instance for operation.
Definition: trgmux_driver.c:75
#define TRGMUX_BASE_PTRS
Definition: S32K142.h:11109
trgmux_target_module_t targetModule
#define TRGMUX_INSTANCE_COUNT
Definition: S32K142.h:11098
void TRGMUX_DRV_SetLockForTargetModule(const uint32_t instance, const trgmux_target_module_t targetModule)
Locks the TRGMUX register of a target module.