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 
19 
40 #include "trgmux_driver.h"
41 #include <stddef.h>
42 
43 /*******************************************************************************
44  * Variables
45  ******************************************************************************/
46 
49 
50 
51 /*******************************************************************************
52  * Code
53  ******************************************************************************/
54 
55 /*FUNCTION**********************************************************************
56  *
57  * Function Name : TRGMUX_DRV_Init
58  * Description : This function first resets the source triggers of all TRGMUX target modules
59  * to their default values, then configures the TRGMUX with all the user defined in-out mappings.
60  * If at least one of the target modules is locked, the function will not change any of the
61  * TRGMUX target modules and return an error code.
62  * This example shows how to set up the trgmux_user_config_t parameters and how to call the
63  * TRGMUX_DRV_Init() function with the required parameters:
64  * trgmux_user_config_t trgmuxConfig;
65  * trgmux_inout_mapping_config_t trgmuxInoutMappingConfig[] =
66  * {
67  * {TRGMUX_TRIG_SOURCE_TRGMUX_IN9, TRGMUX_TARGET_MODULE_DMA_CH0, false},
68  * {TRGMUX_TRIG_SOURCE_FTM1_EXT_TRIG, TRGMUX_TARGET_MODULE_TRGMUX_OUT4, true}
69  * };
70  * trgmuxConfig.numInOutMappingConfigs = 2;
71  * trgmuxConfig.inOutMappingConfig = trgmuxInoutMappingConfig;
72  * TRGMUX_DRV_Init(instance, &trgmuxConfig);
73  *
74  * Implements : TRGMUX_DRV_Init_Activity
75  *END**************************************************************************/
76 status_t TRGMUX_DRV_Init(const uint32_t instance,
77  const trgmux_user_config_t * const trgmuxUserConfig)
78 {
80  DEV_ASSERT(trgmuxUserConfig != NULL);
81 
82  status_t status;
83  TRGMUX_Type * base = s_trgmuxBase[instance];
84  uint8_t count;
85 
86  /* Reset source triggers of all TRGMUX target modules to default. */
87  status = TRGMUX_HAL_Init(base);
88 
89  if(status == STATUS_SUCCESS)
90  {
91  /* Loop through all in-out mappings in the configuration and apply them in TRGMUX */
92  for(count = 0U; count < trgmuxUserConfig->numInOutMappingConfigs; count++)
93  {
95  trgmuxUserConfig->inOutMappingConfig[count].triggerSource, \
96  trgmuxUserConfig->inOutMappingConfig[count].targetModule);
97  }
98 
99  /* Loop through all in-out mappings in the configuration and lock them if required */
100  for(count = 0U; count < trgmuxUserConfig->numInOutMappingConfigs; count++)
101  {
102  if(trgmuxUserConfig->inOutMappingConfig[count].lockTargetModuleReg)
103  {
105  trgmuxUserConfig->inOutMappingConfig[count].targetModule);
106  }
107  }
108  }
109 
110  return status;
111 }
112 
113 /*FUNCTION**********************************************************************
114  *
115  * Function Name : TRGMUX_DRV_Deinit
116  * Description : Reset to default values the source triggers corresponding to all target modules,
117  * if none of the target modules is locked.
118  *
119  * Implements : TRGMUX_DRV_Deinit_Activity
120  *END**************************************************************************/
121 status_t TRGMUX_DRV_Deinit(const uint32_t instance)
122 {
123  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
124 
125  TRGMUX_Type * base = s_trgmuxBase[instance];
126  status_t status;
127 
128  /* Reset source triggers of all TRGMUX target modules to default. */
129  status = TRGMUX_HAL_Init(base);
130 
131  return status;
132 }
133 
134 /*FUNCTION**********************************************************************
135  *
136  * Function Name : TRGMUX_DRV_SetTrigSourceForTargetModule
137  * Description : This function configures a TRGMUX link between a source trigger and a target module,
138  * if the requested target module is not locked.
139  *
140  * Implements : TRGMUX_DRV_SetTrigSourceForTargetModule_Activity
141  *END**************************************************************************/
143  const trgmux_trigger_source_t triggerSource,
144  const trgmux_target_module_t targetModule)
145 {
146  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
147 
148  TRGMUX_Type * base = s_trgmuxBase[instance];
149  status_t status;
150  bool lock;
151 
152  lock = TRGMUX_HAL_GetLockForTargetModule(base, targetModule);
153 
154  if(lock == true)
155  {
156  status = STATUS_ERROR;
157  }
158  else
159  {
160  /* Configure link between trigger source and target module. */
161  TRGMUX_HAL_SetTrigSourceForTargetModule(base, triggerSource, targetModule);
162  status = STATUS_SUCCESS;
163  }
164 
165  return status;
166 }
167 
168 /*FUNCTION**********************************************************************
169  *
170  * Function Name : TRGMUX_DRV_GetTrigSourceForTargetModule
171  * Description : This function returns the TRGMUX source trigger linked to a selected target module.
172  *
173  * Implements : TRGMUX_DRV_GetTrigSourceForTargetModule_Activity
174  *END**************************************************************************/
176  const trgmux_target_module_t targetModule)
177 {
178  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
179 
180  const TRGMUX_Type * base = s_trgmuxBase[instance];
181 
182  return TRGMUX_HAL_GetTrigSourceForTargetModule(base, targetModule);
183 }
184 
185 /*FUNCTION**********************************************************************
186  *
187  * Function Name : TRGMUX_DRV_SetLockForTargetModule
188  * Description : This function locks the TRGMUX register of a selected target module.
189  *
190  * Implements : TRGMUX_DRV_SetLockForTargetModule_Activity
191  *END**************************************************************************/
192 void TRGMUX_DRV_SetLockForTargetModule(const uint32_t instance,
193  const trgmux_target_module_t targetModule)
194 {
195  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
196 
197  TRGMUX_Type * base = s_trgmuxBase[instance];
198 
199  TRGMUX_HAL_SetLockForTargetModule(base, targetModule);
200 }
201 
202 /*FUNCTION**********************************************************************
203  *
204  * Function Name : TRGMUX_DRV_GetLockForTargetModule
205  * Description : This function gets the value of the LK bit from the TRGMUX register
206  * corresponding to the selected target module.
207  *
208  * Implements : TRGMUX_DRV_GetLockForTargetModule_Activity
209  *END**************************************************************************/
210 bool TRGMUX_DRV_GetLockForTargetModule(const uint32_t instance,
211  const trgmux_target_module_t targetModule)
212 {
213  DEV_ASSERT(instance < TRGMUX_INSTANCE_COUNT);
214 
215  const TRGMUX_Type * base = s_trgmuxBase[instance];
216 
217  return TRGMUX_HAL_GetLockForTargetModule(base, targetModule);
218 }
219 
220 /*******************************************************************************
221  * EOF
222  ******************************************************************************/
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.
Definition: trgmux_driver.h:65
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_HAL_Init(TRGMUX_Type *const base)
Restore the TRGMUX module to reset value.
Definition: trgmux_hal.c:58
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:48
bool TRGMUX_HAL_GetLockForTargetModule(const TRGMUX_Type *const base, const trgmux_target_module_t targetModule)
Get the Lock bit status of the TRGMUX register of a target module.
Definition: trgmux_hal.c:241
void TRGMUX_HAL_SetLockForTargetModule(TRGMUX_Type *const base, const trgmux_target_module_t targetModule)
Lock the TRGMUX register of a target module.
Definition: trgmux_hal.c:222
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:78
const trgmux_inout_mapping_config_t * inOutMappingConfig
Definition: trgmux_driver.h:68
uint8_t numInOutMappingConfigs
Definition: trgmux_driver.h:67
trgmux_target_module_t
Describes all possible outputs (target modules) of the TRGMUX IP.
Definition: trgmux_hal.h:125
trgmux_trigger_source_t triggerSource
Definition: trgmux_driver.h:49
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
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:76
void TRGMUX_HAL_SetTrigSourceForTargetModule(TRGMUX_Type *const base, const trgmux_trigger_source_t triggerSource, const trgmux_target_module_t targetModule)
Configures a source trigger for a target module.
Definition: trgmux_hal.c:166
trgmux_trigger_source_t
Describes all possible inputs (trigger sources) of the TRGMUX IP.
Definition: trgmux_hal.h:62
trgmux_trigger_source_t TRGMUX_HAL_GetTrigSourceForTargetModule(const TRGMUX_Type *const base, const trgmux_target_module_t targetModule)
Get the source trigger configured for a target module.
Definition: trgmux_hal.c:197
#define TRGMUX_BASE_PTRS
Definition: S32K144.h:11184
trgmux_target_module_t targetModule
Definition: trgmux_driver.h:50
#define TRGMUX_INSTANCE_COUNT
Definition: S32K144.h:11173
void TRGMUX_DRV_SetLockForTargetModule(const uint32_t instance, const trgmux_target_module_t targetModule)
Locks the TRGMUX register of a target module.