1 /*******************************************************************************
2 * \file cy_trigmux.h
3 * \version 1.30
4 *
5 *  This file provides constants and parameter values for the Trigger multiplexer driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2016-2020 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 *     http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24 
25 /**
26 * \addtogroup group_trigmux
27 * \{
28 * The trigger multiplexer provides access to the multiplexer that selects a set
29 * of trigger output signals from different peripheral blocks to route them to the
30 * specific trigger input of another peripheral block.
31 *
32 * The functions and other declarations used in this driver are in cy_trigmux.h.
33 * You can include cy_pdl.h to get access to all functions
34 * and declarations in the PDL.
35 *
36 * The TrigMux driver is based on the trigger multiplexer's hardware block.
37 * The Trigger multiplexer block consists of multiple trigger multiplexers.
38 * These trigger multiplexers are grouped in trigger groups. All the trigger
39 * multiplexers in the trigger group share similar input options.
40 *
41 * For PERI_ver1:
42 * The trigger multiplexer groups are either reduction multiplexers or distribution
43 * multiplexers. The figure below illustrates a generic trigger multiplexer block
44 * implementation with a reduction multiplexer layer of N trigger groups and a
45 * distribution multiplexer layer of M trigger groups.
46 * \image html trigmux_architecture.png
47 * The reduction multiplexer groups have input options that are the trigger outputs
48 * coming from the different peripheral blocks and the reduction multiplexer groups
49 * route them to intermediate signals. The distribution multiplexer groups have input
50 * options from these intermediate signals and route them back to multiple peripheral
51 * blocks as their trigger inputs.
52 *
53 * For PERI_ver2:
54 * The trigger multiplexer groups structure is flat - all the groups are essentially
55 * distribution multiplexers (there are no any intermediate trigger signals), so the
56 * structure is simpler in comparison with PERI_ver1, however a bit less flexible.
57 * Additionally there are another type of trigger interconnections: one-to-one
58 * trigger lines. These are not multiplexers, only single trigger wires from/to
59 * the dedicated peripherals. Multiple groups of one-to-one trigger lines
60 * significantly improve the whole triggering interconnect system flexibility.
61 *
62 * The trigger architecture of the PSoC device is explained in the technical reference
63 * manual (TRM). Refer to the TRM to better understand the trigger multiplexer routing
64 * architecture available.
65 *
66 * \section group_trigmux_section_Configuration_Considerations Configuration Considerations
67 *
68 * For PERI_ver1:
69 * To route a trigger signal from one peripheral in the PSoC
70 * to another, the user must configure a reduction multiplexer and a distribution
71 * multiplexer. The \ref Cy_TrigMux_Connect is used to configure a trigger multiplexer connection.
72 * The user will need two calls of this API, one for the reduction multiplexer and another
73 * for the distribution multiplexer, to achieve the trigger connection from a source
74 * peripheral to a destination peripheral.
75 *
76 * For PERI_ver2:
77 * To route a trigger signal from one peripheral in the PSoC device to another, the user can configure
78 * either a trigger multiplexer using \ref Cy_TrigMux_Connect or a one-to-one trigger line
79 * using \ref Cy_TrigMux_Select. Only one function call is required to connect one peripheral
80 * to another (unlike for PERI_ver1).
81 *
82 * The Cy_TrigMux_Connect() function has two main parameters, inTrig and outTrig that
83 * refer to the input and output trigger lines connected using the multiplexer.
84 * These parameters are represented in the following format:<br>
85 * For PERI_ver1:
86 * \image html trigmux_parameter_30.png
87 * For PERI_ver2:
88 * \image html trigmux_parameter_30_2.png
89 * In addition, the \ref Cy_TrigMux_Connect function also has an invert and trigger type parameter.
90 * Refer to the API reference for a detailed description of this parameter.
91 * All the constants associated with the different trigger signals in the system
92 * (input and output) are defined as constants in the device configuration header file.
93 *
94 * For PERI_ver1:
95 * The constants for TrigMux in the device configuration header file are divided into four
96 * types based on the signal being input/output and being part of a reduction/distribution
97 * trigger multiplexer.
98 *
99 * The four types of the input/output parameters are:
100 * 1) The parameters for the reduction multiplexer's inputs (input signals of TrigMux);
101 * 2) The parameters for the reduction multiplexer's outputs (intermediate signals);
102 * 3) The parameters for the distribution multiplexer's inputs (intermediate signals);
103 * 4) The parameters for the distribution multiplexer's outputs (output signals of TrigMux).
104 *
105 * For PERI_ver2:
106 * There are two types of TrigMux signal definitions in the device configuration header:
107 * 1) The parameters for the trigger interconnection system input signals.
108 * 2) The parameters for the trigger interconnection system output signals.
109 * Also there are separate groups of trigger multiplexer input/outputs and groups of
110 * trigger one-to-one line input/outputs.
111 *
112 * Refer to the TRM for a more detailed description of this architecture and different options.
113 *
114 * The steps to connect one peripheral block to the other:
115 *
116 * For PERI_ver1:
117 * Step 1. Find the trigger group number in the Trigger Group Inputs section of the device
118 * configuration header file that corresponds to the output of the source peripheral block.
119 * For example, TRIG11_IN_TCPWM0_TR_OVERFLOW0 (see \ref group_trigmux_red_in_enums and the diagram
120 * at the top of this section) input of the Reduction multiplexers belongs to Trigger Group 11.
121 *
122 * Step 2. Find the trigger group number in the Trigger Group Outputs section of the device
123 * configuration header file that corresponds to the input of the destination peripheral block.
124 * For example, TRIG0_OUT_CPUSS_DW0_TR_IN0 (see \ref group_trigmux_dst_out_enums) output of the
125 * Distribution multiplexer belongs to Trigger Group 0.
126 *
127 * Step 3. Find the same trigger group number in the Trigger Group Inputs section of the
128 * device configuration header file that corresponds to the trigger group number found in
129 * Step 1. Select the Reduction multiplexer output that can be connected to the trigger group
130 * found in Step 2. For example, TRIG0_IN_TR_GROUP11_OUTPUT0 (see \ref group_trigmux_dst_in_enums)
131 * means that Reduction Multiplexer Output 0 of Trigger Group 11 can be connected to
132 * Trigger Group 0.
133 *
134 * Step 4. Find the same trigger group number in the Trigger Group Outputs section of the
135 * device configuration header file that corresponds to the trigger group number found in Step 2.
136 * Select the distribution multiplexer input that can be connected to the trigger group found
137 * in Step 1. For example, TRIG11_OUT_TR_GROUP0_INPUT9 (see \ref group_trigmux_red_out_enums)
138 * means that the Distribution Multiplexer Input 9 of Trigger Group 0 can be connected to the
139 * output of the Reduction multiplexer in Trigger Group 11 found in Step 3.
140 *
141 * Step 5. Call Cy_TrigMux_Connect() API twice: the first call - with the constants for the
142 * inTrig and outTrig parameters found in Steps 1 and Step 4, the second call - with the
143 * constants for the inTrig and outTrig parameters found in Steps 2 and Step 3.
144 * For example:
145 * \snippet trigmux/snippet/main.c snippet_Cy_TrigMux_PERI_ver1
146 *
147 * For PERI_ver2:
148 * Step 1. Find the trigger group number in the Trigger Group Inputs section of the device
149 * configuration header file that corresponds to the output of the source peripheral block.
150 * For example, TRIG_IN_MUX_0_TCPWM0_TR_OVERFLOW0 (see \ref group_trigmux_in_enums) TrigMux
151 * input belongs to Trigger Group 0. It is the same TCPWM0 counter 0 overflow output
152 * (as in the example for PERI_ver1).
153 *
154 * Step 2. Find the same trigger group number in the Trigger Group Outputs section of the
155 * device configuration header file that corresponds to the trigger group number found in
156 * Step 1. Select the TrigMux output that can be connected to the destination peripheral block.
157 * For example, TRIG_OUT_MUX_0_PDMA0_TR_IN0 (see \ref group_trigmux_out_enums) means that the
158 * trigger multiplexer Output 0 of Trigger Group 0 can be connected to the DW0 channel 0 trigger
159 * input (the same DMA channel as mentioned in the example for PERI_ver1).
160 *
161 * Step 3. Call Cy_TrigMux_Connect() API once:
162 * \snippet trigmux/snippet/main.c snippet_Cy_TrigMux_PERI_ver2
163 *
164 * \section group_trigmux_more_information More Information
165 * For more information on the TrigMux peripheral, refer to the technical reference manual (TRM).
166 *
167 * \section group_trigmux_Changelog Changelog
168 * <table class="doxtable">
169 *   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
170 *   <tr>
171 *     <td rowspan="2">1.30</td>
172 *     <td>Minor bug fixes.</td>
173 *     <td>Keep device specific changes under a compile time device flag.</td>
174 *   </tr>
175 *   <tr>
176 *     <td>Added new device support.</td>
177 *     <td>Added new family of device.</td>
178 *   </tr>
179 *   <tr>
180 *     <td>1.20.3</td>
181 *     <td>Minor documentation updates.</td>
182 *     <td>Removed MISRA 2004 compliance details and verified MISRA 2012 complaince.</td>
183 *   </tr>
184 *   <tr>
185 *     <td>1.20.2</td>
186 *     <td>Minor documentation updates.</td>
187 *     <td>Documentation enhancement.</td>
188 *   </tr>
189 *   <tr>
190 *     <td>1.20.1</td>
191 *     <td>Documentation is extended/improved.</td>
192 *     <td>Enhancement based on usability feedback.</td>
193 *   </tr>
194 *   <tr>
195 *     <td rowspan="3">1.20</td>
196 *     <td>Flattened the organization of the driver source code into the single source directory and the single include directory.</td>
197 *     <td>Driver library directory-structure simplification.</td>
198 *   </tr>
199 *   <tr>
200 *     <td>Added new API functions:
201 *         - \ref Cy_TrigMux_Select
202 *         - \ref Cy_TrigMux_Deselect
203 *         - \ref Cy_TrigMux_SetDebugFreeze
204 *
205 *         Modified the \ref Cy_TrigMux_SwTrigger API function logic.
206 *     </td>
207 *     <td>New devices support.</td>
208 *   </tr>
209 *   <tr>
210 *     <td>Added register access layer. Use register access macros instead
211 *         of direct register access using dereferenced pointers.</td>
212 *     <td>Makes register access device-independent, so that the PDL does
213 *         not need to be recompiled for each supported part number.</td>
214 *   </tr>
215 *   <tr>
216 *     <td>1.10.1</td>
217 *     <td>Renamed the internal macro in Cy_TrigMux_Connect()
218 *          function to CY_TRIGMUX_IS_TRIGTYPE_VALID.</td>
219 *     <td></td>
220 *   </tr>
221 *   <tr>
222 *     <td>1.10</td>
223 *     <td>The input/output bit in the trigLine parameter of the
224 *         Cy_TrigMux_SwTrigger() function is changed to 30.<br>
225 *         The invert parameter type is changed to bool.<br>
226 *         Added input parameter validation to the API functions.</td>
227 *     <td></td>
228 *   </tr>
229 *   <tr>
230 *     <td>1.0</td>
231 *     <td>Initial version</td>
232 *     <td></td>
233 *   </tr>
234 * </table>
235 *
236 * \defgroup group_trigmux_macros Macros
237 * \defgroup group_trigmux_functions Functions
238 * \defgroup group_trigmux_enums Enumerated Types
239 * \{
240 *  \defgroup group_trigmux_red_enums Reduction Trigger Mutiplexers
241 *  \{
242 *   \defgroup group_trigmux_red_in_enums Reduction Trigger Mutiplexer Inputs
243 *   \defgroup group_trigmux_red_out_enums Reduction Trigger Mutiplexer Outputs
244 *  \}
245 *  \defgroup group_trigmux_dst_enums Distribution Trigger Mutiplexers
246 *  \{
247 *   \defgroup group_trigmux_dst_in_enums Distribution Trigger Mutiplexer Inputs
248 *   \defgroup group_trigmux_dst_out_enums Distribution Trigger Mutiplexer Outputs
249 *  \}
250 *  \defgroup group_trigmux_in_enums Trigger Mutiplexer Inputs
251 *  \defgroup group_trigmux_out_enums Trigger Mutiplexer Outputs
252 *  \defgroup group_trigmux_1to1_enums One-To-One Trigger Lines
253 * \}
254 */
255 
256 #if !defined(CY_TRIGMUX_H)
257 #define CY_TRIGMUX_H
258 
259 #include "cy_device.h"
260 
261 #if defined (CY_IP_MXSPERI) || defined (CY_IP_MXPERI)
262 
263 #include "cy_syslib.h"
264 
265 #if defined(__cplusplus)
266 extern "C" {
267 #endif
268 
269 /******************************************************************************
270  * Macros
271  *****************************************************************************/
272 
273 /**
274 * \addtogroup group_trigmux_macros
275 * \{
276 */
277 
278 /** The driver major version */
279 #define CY_TRIGMUX_DRV_VERSION_MAJOR       1
280 
281 /** The driver minor version */
282 #define CY_TRIGMUX_DRV_VERSION_MINOR       30
283 
284 /** TRIGMUX PDL ID */
285 #define CY_TRIGMUX_ID                       CY_PDL_DRV_ID(0x33UL) /**< The trigger multiplexer driver identifier */
286 
287 /** Values for the cycles parameter in the \ref Cy_TrigMux_SwTrigger() function */
288 #define CY_TRIGGER_INFINITE                 (255UL) /**< The trigger will be active until the user clears it or a hardware deactivates it. */
289 #define CY_TRIGGER_DEACTIVATE               (0UL)   /**< Use this parameter value to deactivate the trigger. */
290 #define CY_TRIGGER_TWO_CYCLES               (2UL)   /**< The only valid cycles number value for PERI_ver2. */
291 
292 /** \} group_trigmux_macros */
293 
294 /** \cond BWC macros */
295 #define CY_TR_MUX_TR_INV_ENABLE            (0x01u)
296 #define CY_TR_MUX_TR_INV_DISABLE           (0x00u)
297 #define CY_TR_ACTIVATE_DISABLE             (0x00u)
298 #define CY_TR_ACTIVATE_ENABLE              (0x01u)
299 #define CY_TR_GROUP_MASK                   (0x0F00u)
300 #define CY_TR_MASK                         (0x007Fu)
301 #define CY_TR_GROUP_SHIFT                  (0x08u)
302 #define CY_TR_OUT_CTL_MASK                 (0x40000000uL)
303 #define CY_TR_OUT_CTL_SHIFT                (30u)
304 #define CY_TR_PARAM_MASK                   (CY_TR_OUT_CTL_MASK | CY_TR_GROUP_MASK | CY_TR_MASK)
305 #define CY_TR_CYCLES_MIN                   (0u)
306 #define CY_TR_CYCLES_MAX                   (255u)
307 /** \endcond */
308 
309 
310 /**
311 * \addtogroup group_trigmux_enums
312 * \{
313 */
314 
315 /******************************************************************************
316  * Enumerations
317  *****************************************************************************/
318 
319 /** The TRIGMUX error codes. */
320 typedef enum
321 {
322     CY_TRIGMUX_SUCCESS = 0x0UL,                                             /**< Successful */
323     CY_TRIGMUX_BAD_PARAM = CY_TRIGMUX_ID | CY_PDL_STATUS_ERROR | 0x1UL,     /**< One or more invalid parameters */
324     CY_TRIGMUX_INVALID_STATE = CY_TRIGMUX_ID | CY_PDL_STATUS_ERROR | 0x2UL  /**< Operation not set up or is in an improper state */
325 } cy_en_trigmux_status_t;
326 
327 /** \} group_trigmux_enums */
328 
329 /**
330 * \addtogroup group_trigmux_functions
331 * \{
332 */
333 
334 cy_en_trigmux_status_t Cy_TrigMux_Connect(uint32_t inTrig, uint32_t outTrig, bool invert, en_trig_type_t trigType);
335 cy_en_trigmux_status_t Cy_TrigMux_SwTrigger(uint32_t trigLine, uint32_t cycles);
336 cy_en_trigmux_status_t Cy_TrigMux_Select(uint32_t outTrig, bool invert, en_trig_type_t trigType);
337 cy_en_trigmux_status_t Cy_TrigMux_Deselect(uint32_t outTrig);
338 cy_en_trigmux_status_t Cy_TrigMux_SetDebugFreeze(uint32_t outTrig, bool enable);
339 
340 /** \} group_trigmux_functions */
341 
342 #if defined(__cplusplus)
343 }
344 #endif
345 
346 #endif /* CY_IP_MXSPERI, CY_IP_MXPERI */
347 
348 #endif /* CY_TRIGMUX_H */
349 
350 /** \} group_trigmux */
351 
352 /* [] END OF FILE */
353