1 /***************************************************************************//**
2 * @file
3 * @brief Peripheral Reflex System (PRS) Peripheral API
4 *******************************************************************************
5 * # License
6 * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
7 *******************************************************************************
8 *
9 * SPDX-License-Identifier: Zlib
10 *
11 * The licensor of this software is Silicon Laboratories Inc.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty. In no event will the authors be held liable for any damages
15 * arising from the use of this software.
16 *
17 * Permission is granted to anyone to use this software for any purpose,
18 * including commercial applications, and to alter it and redistribute it
19 * freely, subject to the following restrictions:
20 *
21 * 1. The origin of this software must not be misrepresented; you must not
22 * claim that you wrote the original software. If you use this software
23 * in a product, an acknowledgment in the product documentation would be
24 * appreciated but is not required.
25 * 2. Altered source versions must be plainly marked as such, and must not be
26 * misrepresented as being the original software.
27 * 3. This notice may not be removed or altered from any source distribution.
28 *
29 ******************************************************************************/
30
31 #include "em_prs.h"
32 #if defined(PRS_COUNT) && (PRS_COUNT > 0)
33
34 #include "em_assert.h"
35
36 /***************************************************************************//**
37 * @addtogroup prs PRS - Peripheral Reflex System
38 * @brief Peripheral Reflex System (PRS) Peripheral API
39 * @details
40 * This module contains functions to control the PRS peripheral of Silicon
41 * Labs 32-bit MCUs and SoCs. The PRS allows configurable, fast, and autonomous
42 * communication between peripherals on the MCU or SoC.
43 * @{
44 ******************************************************************************/
45
46 /*******************************************************************************
47 ************************** LOCAL FUNCTIONS ********************************
48 ******************************************************************************/
49
50 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
51
52 /***************************************************************************//**
53 * @brief
54 * Get PRS source signal for a channel.
55 *
56 * @param[in] type
57 * PRS channel type. This can be either @ref prsTypeAsync or
58 * @ref prsTypeSync.
59 *
60 * @param[in] ch
61 * channel number.
62 *
63 * @return
64 * PRS signal assigned to the channel.
65 ******************************************************************************/
getSignal(unsigned int ch,PRS_ChType_t type)66 static PRS_Signal_t getSignal(unsigned int ch, PRS_ChType_t type)
67 {
68 PRS_Signal_t signal;
69 #if defined(_PRS_ASYNC_CH_CTRL_SOURCESEL_MASK)
70 if (type == prsTypeAsync) {
71 signal = (PRS_Signal_t) (PRS->ASYNC_CH[ch].CTRL
72 & (_PRS_ASYNC_CH_CTRL_SOURCESEL_MASK | _PRS_ASYNC_CH_CTRL_SIGSEL_MASK));
73 } else {
74 signal = (PRS_Signal_t) (PRS->SYNC_CH[ch].CTRL
75 & (_PRS_SYNC_CH_CTRL_SOURCESEL_MASK | _PRS_SYNC_CH_CTRL_SIGSEL_MASK));
76 }
77 #else
78 (void) type;
79 signal = (PRS_Signal_t) (PRS->CH[ch].CTRL
80 & (_PRS_CH_CTRL_SOURCESEL_MASK | _PRS_CH_CTRL_SIGSEL_MASK));
81 #endif
82 return signal;
83 }
84
85 #if defined(_SILICON_LABS_32B_SERIES_2)
86 /***************************************************************************//**
87 * @brief
88 * Convert an async PRS source to a sync source.
89 *
90 * @details
91 * This conversion must be done because the id's of the same peripheral
92 * source is different depending on if it's used as an asynchronous PRS source
93 * or a synchronous PRS source.
94 *
95 * @param[in] asyncSource
96 * The id of the asynchronous PRS source.
97 *
98 * @return
99 * The id of the corresponding synchronous PRS source.
100 ******************************************************************************/
PRS_ConvertToSyncSource(uint32_t asyncSource)101 uint32_t PRS_ConvertToSyncSource(uint32_t asyncSource)
102 {
103 uint32_t syncSource = 0;
104
105 switch (asyncSource) {
106 case _PRS_ASYNC_CH_CTRL_SOURCESEL_NONE:
107 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_NONE;
108 break;
109 case _PRS_ASYNC_CH_CTRL_SOURCESEL_IADC0:
110 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_IADC0;
111 break;
112 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER0:
113 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_TIMER0;
114 break;
115 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER1:
116 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_TIMER1;
117 break;
118 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER2:
119 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_TIMER2;
120 break;
121 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER3:
122 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_TIMER3;
123 break;
124 #if defined(TIMER4)
125 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER4:
126 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_TIMER4;
127 break;
128 #endif
129 #if defined(VDAC0)
130 case _PRS_ASYNC_CH_CTRL_SOURCESEL_VDAC0L:
131 syncSource = _PRS_SYNC_CH_CTRL_SOURCESEL_VDAC0;
132 break;
133 #endif
134 default:
135 EFM_ASSERT(false);
136 break;
137 }
138 return syncSource;
139 }
140
141 /***************************************************************************//**
142 * @brief
143 * Convert an async PRS signal to a sync signal.
144 *
145 * @details
146 * PRS values for TIMER2 and TIMER3 signals differ between asynchronous and
147 * synchronous PRS channels. This function must be used to handle the
148 * conversion.
149 *
150 * @param[in] asyncSource
151 * The id of the asynchronous PRS source.
152 *
153 * @param[in] asyncSignal
154 * The id of the asynchronous PRS signal.
155 *
156 * @return
157 * The id of the corresponding synchronous PRS signal.
158 ******************************************************************************/
PRS_ConvertToSyncSignal(uint32_t asyncSource,uint32_t asyncSignal)159 uint32_t PRS_ConvertToSyncSignal(uint32_t asyncSource, uint32_t asyncSignal)
160 {
161 uint32_t syncSignal = asyncSignal;
162
163 switch (asyncSource) {
164 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER0:
165 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER1:
166 switch (asyncSignal) {
167 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER1UF:
168 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER1UF;
169 break;
170 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER1OF:
171 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER1OF;
172 break;
173 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER1CC0:
174 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER1CC0;
175 break;
176 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER2CC1:
177 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER1CC1;
178 break;
179 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER2CC2:
180 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER1CC2;
181 break;
182 default:
183 EFM_ASSERT(false);
184 break;
185 }
186 break;
187 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER2:
188 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER3:
189 #if defined(_PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER4)
190 case _PRS_ASYNC_CH_CTRL_SOURCESEL_TIMER4:
191 #endif
192 switch (asyncSignal) {
193 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER2UF:
194 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER2UF;
195 break;
196 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER2OF:
197 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER2OF;
198 break;
199 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER2CC0:
200 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER2CC0;
201 break;
202 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER2CC1:
203 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER2CC1;
204 break;
205 case _PRS_ASYNC_CH_CTRL_SIGSEL_TIMER2CC2:
206 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_TIMER2CC2;
207 break;
208 default:
209 EFM_ASSERT(false);
210 break;
211 }
212 break;
213 #if defined(IADC0)
214 case _PRS_ASYNC_CH_CTRL_SOURCESEL_IADC0:
215 switch (asyncSignal) {
216 case _PRS_ASYNC_CH_CTRL_SIGSEL_IADC0SCANENTRYDONE:
217 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_IADC0SCANENTRYDONE;
218 break;
219 case _PRS_ASYNC_CH_CTRL_SIGSEL_IADC0SCANTABLEDONE:
220 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_IADC0SCANTABLEDONE;
221 break;
222 case _PRS_ASYNC_CH_CTRL_SIGSEL_IADC0SINGLEDONE:
223 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_IADC0SINGLEDONE;
224 break;
225 default:
226 EFM_ASSERT(false);
227 break;
228 }
229 break;
230 #endif
231 #if defined(VDAC0)
232 case _PRS_ASYNC_CH_CTRL_SOURCESEL_VDAC0L:
233 switch (asyncSignal) {
234 case _PRS_ASYNC_CH_CTRL_SIGSEL_VDAC0LCH0DONEASYNC:
235 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_VDAC0CH0DONESYNC;
236 break;
237 case _PRS_ASYNC_CH_CTRL_SIGSEL_VDAC0LCH1DONEASYNC:
238 syncSignal = _PRS_SYNC_CH_CTRL_SIGSEL_VDAC0CH1DONESYNC;
239 break;
240 default:
241 EFM_ASSERT(false);
242 break;
243 }
244 break;
245 #endif
246 default:
247 // No translation
248 break;
249 }
250 return syncSignal;
251 }
252
253 #endif
254
255 /** @endcond */
256
257 /*******************************************************************************
258 ************************** GLOBAL FUNCTIONS *******************************
259 ******************************************************************************/
260
261 /***************************************************************************//**
262 * @brief
263 * Set a source and signal for a channel.
264 *
265 * @param[in] ch
266 * A channel to define the signal and source for.
267 *
268 * @param[in] source
269 * A source to select for the channel. Use one of PRS_CH_CTRL_SOURCESEL_x defines.
270 *
271 * @param[in] signal
272 * A signal (for selected @p source) to use. Use one of PRS_CH_CTRL_SIGSEL_x
273 * defines.
274 *
275 * @param[in] edge
276 * An edge (for selected source/signal) to generate the pulse for.
277 ******************************************************************************/
PRS_SourceSignalSet(unsigned int ch,uint32_t source,uint32_t signal,PRS_Edge_TypeDef edge)278 void PRS_SourceSignalSet(unsigned int ch,
279 uint32_t source,
280 uint32_t signal,
281 PRS_Edge_TypeDef edge)
282 {
283 #if defined(_PRS_SYNC_CH_CTRL_MASK)
284 (void) edge;
285 EFM_ASSERT(ch < PRS_SYNC_CHAN_COUNT);
286 PRS->SYNC_CH[ch].CTRL = (source & _PRS_SYNC_CH_CTRL_SOURCESEL_MASK)
287 | (signal & _PRS_SYNC_CH_CTRL_SIGSEL_MASK);
288 #else
289 EFM_ASSERT(ch < PRS_CHAN_COUNT);
290 PRS->CH[ch].CTRL = (source & _PRS_CH_CTRL_SOURCESEL_MASK)
291 | (signal & _PRS_CH_CTRL_SIGSEL_MASK)
292 | (uint32_t)edge << _PRS_CH_CTRL_EDSEL_SHIFT;
293 #endif
294 }
295
296 #if defined(PRS_ASYNC_SUPPORTED)
297 /***************************************************************************//**
298 * @brief
299 * Set the source and asynchronous signal for a channel.
300 *
301 * @details
302 * Asynchronous reflexes are not clocked on HFPERCLK and can be used even in
303 * EM2/EM3.
304 * There is a limitation to reflexes operating in asynchronous mode in
305 * that they can only be used by a subset of the reflex consumers. See
306 * the PRS chapter in the reference manual for the complete list of
307 * supported asynchronous signals and consumers.
308 *
309 * @note
310 * This function is not supported on EFM32GxxxFyyy parts.
311 * In asynchronous mode, the edge detector only works in EM0 and should
312 * not be used. The EDSEL parameter in PRS_CHx_CTRL register is set to 0 (OFF)
313 * by default.
314 *
315 * @param[in] ch
316 * A channel to define the source and asynchronous signal for.
317 *
318 * @param[in] source
319 * A source to select for the channel. Use one of PRS_CH_CTRL_SOURCESEL_x defines.
320 *
321 * @param[in] signal
322 * An asynchronous signal (for selected @p source) to use. Use one of the
323 * PRS_CH_CTRL_SIGSEL_x defines that support asynchronous operation.
324 ******************************************************************************/
PRS_SourceAsyncSignalSet(unsigned int ch,uint32_t source,uint32_t signal)325 void PRS_SourceAsyncSignalSet(unsigned int ch,
326 uint32_t source,
327 uint32_t signal)
328 {
329 PRS_ConnectSignal(ch, prsTypeAsync, (PRS_Signal_t) (source | signal));
330 }
331 #endif
332
333 #if defined(_PRS_ROUTELOC0_MASK) || (_PRS_ROUTE_MASK)
334 /***************************************************************************//**
335 * @brief
336 * Send the output of a PRS channel to a GPIO pin.
337 *
338 * @details
339 * This function is used to send the output of a PRS channel to a GPIO pin.
340 * Note that there are certain restrictions to where a PRS channel can be
341 * routed. Consult the datasheet of the device to see if a channel can be
342 * routed to the requested GPIO pin.
343 *
344 * @param[in] ch
345 * PRS channel number.
346 *
347 * @param[in] location
348 * PRS routing location.
349 ******************************************************************************/
PRS_GpioOutputLocation(unsigned int ch,unsigned int location)350 void PRS_GpioOutputLocation(unsigned int ch,
351 unsigned int location)
352 {
353 EFM_ASSERT(ch < PRS_CHAN_COUNT);
354
355 #if defined(_PRS_ROUTE_MASK)
356 PRS->ROUTE |= (location << _PRS_ROUTE_LOCATION_SHIFT)
357 | (1 << ch);
358 #else
359 uint32_t shift = (ch % 4) * 8;
360 uint32_t mask = location << shift;
361 uint32_t locationGroup = ch / 4;
362 /* Since all ROUTELOCx registers are in consecutive memory locations, we can treat them
363 * as an array starting at ROUTELOC0 and use locationGroup to index into this array */
364 volatile uint32_t * routeloc = &PRS->ROUTELOC0;
365 routeloc[locationGroup] |= mask;
366 PRS->ROUTEPEN |= 1 << ch;
367 #endif
368 }
369 #endif
370
371 /***************************************************************************//**
372 * @brief
373 * Search for the first free PRS channel.
374 *
375 * @param[in] type
376 * PRS channel type. This can be either @ref prsTypeAsync or
377 * @ref prsTypeSync.
378 *
379 * @return
380 * Channel number >= 0 if an unused PRS channel was found. If no free PRS
381 * channel was found then -1 is returned.
382 ******************************************************************************/
PRS_GetFreeChannel(PRS_ChType_t type)383 int PRS_GetFreeChannel(PRS_ChType_t type)
384 {
385 int ch = -1;
386 PRS_Signal_t signal;
387 int max;
388
389 if (type == prsTypeAsync) {
390 max = PRS_ASYNC_CHAN_COUNT;
391 } else {
392 max = PRS_SYNC_CHAN_COUNT;
393 }
394
395 for (int i = 0; i < max; i++) {
396 signal = getSignal(i, type);
397 if (signal == prsSignalNone) {
398 ch = i;
399 break;
400 }
401 }
402 return ch;
403 }
404
405 /***************************************************************************//**
406 * @brief
407 * Reset all PRS channels
408 *
409 * @details
410 * This function will reset all the PRS channel configuration.
411 ******************************************************************************/
PRS_Reset(void)412 void PRS_Reset(void)
413 {
414 unsigned int i;
415
416 #if defined(_SILICON_LABS_32B_SERIES_2)
417 PRS->ASYNC_SWLEVEL = 0;
418 for (i = 0; i < PRS_ASYNC_CHAN_COUNT; i++) {
419 PRS->ASYNC_CH[i].CTRL = _PRS_ASYNC_CH_CTRL_RESETVALUE;
420 }
421 for (i = 0; i < PRS_SYNC_CHAN_COUNT; i++) {
422 PRS->SYNC_CH[i].CTRL = _PRS_SYNC_CH_CTRL_RESETVALUE;
423 }
424 #else
425 PRS->SWLEVEL = 0x0;
426 for (i = 0; i < PRS_CHAN_COUNT; i++) {
427 PRS->CH[i].CTRL = _PRS_CH_CTRL_RESETVALUE;
428 }
429 #endif
430 }
431
432 /***************************************************************************//**
433 * @brief
434 * Connect a PRS signal to a channel.
435 *
436 * @details
437 * This function will make the PRS signal available on the specific channel.
438 * Only a single PRS signal can be connected to any given channel.
439 *
440 * @param[in] ch
441 * PRS channel number.
442 *
443 * @param[in] type
444 * PRS channel type. This can be either @ref prsTypeAsync or
445 * @ref prsTypeSync.
446 *
447 * @param[in] signal
448 * This is the PRS signal that should be placed on the channel.
449 ******************************************************************************/
PRS_ConnectSignal(unsigned int ch,PRS_ChType_t type,PRS_Signal_t signal)450 void PRS_ConnectSignal(unsigned int ch, PRS_ChType_t type, PRS_Signal_t signal)
451 {
452 #if defined(_PRS_ASYNC_CH_CTRL_MASK)
453 // Series 2 devices
454 uint32_t sourceField = ((uint32_t)signal & _PRS_ASYNC_CH_CTRL_SOURCESEL_MASK)
455 >> _PRS_ASYNC_CH_CTRL_SOURCESEL_SHIFT;
456 uint32_t signalField = ((uint32_t)signal & _PRS_ASYNC_CH_CTRL_SIGSEL_MASK)
457 >> _PRS_ASYNC_CH_CTRL_SIGSEL_SHIFT;
458 if (type == prsTypeAsync) {
459 EFM_ASSERT(ch < PRS_ASYNC_CHAN_COUNT);
460 PRS->ASYNC_CH[ch].CTRL = PRS_ASYNC_CH_CTRL_FNSEL_A
461 | (sourceField << _PRS_ASYNC_CH_CTRL_SOURCESEL_SHIFT)
462 | (signalField << _PRS_ASYNC_CH_CTRL_SIGSEL_SHIFT);
463 } else {
464 EFM_ASSERT(ch < PRS_SYNC_CHAN_COUNT);
465 signalField = PRS_ConvertToSyncSignal(sourceField, signalField);
466 sourceField = PRS_ConvertToSyncSource(sourceField);
467 PRS->SYNC_CH[ch].CTRL = (sourceField << _PRS_SYNC_CH_CTRL_SOURCESEL_SHIFT)
468 | (signalField << _PRS_SYNC_CH_CTRL_SIGSEL_SHIFT);
469 }
470 #else
471 // Series 0 and Series 1 devices
472 uint32_t signalField = (uint32_t) signal & (_PRS_CH_CTRL_SOURCESEL_MASK
473 | _PRS_CH_CTRL_SIGSEL_MASK);
474 if (type == prsTypeAsync) {
475 #if defined(PRS_ASYNC_SUPPORTED)
476 EFM_ASSERT(ch < PRS_ASYNC_CHAN_COUNT);
477 PRS->CH[ch].CTRL = PRS_CH_CTRL_EDSEL_OFF
478 | PRS_CH_CTRL_ASYNC
479 | signalField;
480 #endif
481 } else {
482 EFM_ASSERT(ch < PRS_SYNC_CHAN_COUNT);
483 PRS->CH[ch].CTRL = PRS_CH_CTRL_EDSEL_OFF
484 | signalField;
485 }
486 #endif
487 }
488
489 #if defined(_SILICON_LABS_32B_SERIES_2)
490 /***************************************************************************//**
491 * @brief
492 * Connect a peripheral consumer to a PRS channel.
493 *
494 * @details
495 * Different peripherals can use PRS channels as their input. This function
496 * can be used to connect a peripheral consumer to a PRS channel. Multiple
497 * consumers can be connected to a single PRS channel.
498 *
499 * @param[in] ch
500 * PRS channel number.
501 *
502 * @param[in] type
503 * PRS channel type. This can be either @ref prsTypeAsync or
504 * @ref prsTypeSync.
505 *
506 * @param[in] consumer
507 * This is the PRS consumer.
508 ******************************************************************************/
PRS_ConnectConsumer(unsigned int ch,PRS_ChType_t type,PRS_Consumer_t consumer)509 void PRS_ConnectConsumer(unsigned int ch, PRS_ChType_t type, PRS_Consumer_t consumer)
510 {
511 EFM_ASSERT((uint32_t)consumer <= 0xFFF);
512 volatile uint32_t * addr = (volatile uint32_t *) PRS;
513 uint32_t offset = (uint32_t) consumer;
514 addr = addr + offset / 4;
515
516 if (consumer != prsConsumerNone) {
517 if (type == prsTypeAsync) {
518 *addr = ch << _PRS_CONSUMER_TIMER0_CC0_PRSSEL_SHIFT;
519 } else {
520 *addr = ch << _PRS_CONSUMER_TIMER0_CC0_SPRSSEL_SHIFT;
521 }
522 }
523 }
524
525 /***************************************************************************//**
526 * @brief
527 * Send the output of a PRS channel to a GPIO pin.
528 *
529 * @details
530 * This function is used to send the output of a PRS channel to a GPIO pin.
531 * Note that there are certain restrictions to where a PRS channel can be
532 * routed. Consult the datasheet of the device to see if a channel can be
533 * routed to the requested GPIO pin. Some devices for instance can only route
534 * the async channels 0-5 on GPIO pins PAx and PBx while async channels 6-11
535 * can only be routed to GPIO pins PCx and PDx
536 *
537 * @param[in] ch
538 * PRS channel number.
539 *
540 * @param[in] type
541 * PRS channel type. This can be either @ref prsTypeAsync or
542 * @ref prsTypeSync.
543 *
544 * @param[in] port
545 * GPIO port
546 *
547 * @param[in] pin
548 * GPIO pin
549 ******************************************************************************/
PRS_PinOutput(unsigned int ch,PRS_ChType_t type,GPIO_Port_TypeDef port,uint8_t pin)550 void PRS_PinOutput(unsigned int ch, PRS_ChType_t type, GPIO_Port_TypeDef port, uint8_t pin)
551 {
552 volatile uint32_t * addr;
553 if (type == prsTypeAsync) {
554 addr = &GPIO->PRSROUTE[0].ASYNCH0ROUTE;
555 } else {
556 addr = &GPIO->PRSROUTE[0].SYNCH0ROUTE;
557 }
558 addr += ch;
559 *addr = ((uint32_t)port << _GPIO_PRS_ASYNCH0ROUTE_PORT_SHIFT)
560 | (pin << _GPIO_PRS_ASYNCH0ROUTE_PIN_SHIFT);
561
562 if (type == prsTypeAsync) {
563 GPIO->PRSROUTE[0].ROUTEEN |= 0x1 << (ch + _GPIO_PRS_ROUTEEN_ASYNCH0PEN_SHIFT);
564 } else {
565 GPIO->PRSROUTE[0].ROUTEEN |= 0x1 << (ch + _GPIO_PRS_ROUTEEN_SYNCH0PEN_SHIFT);
566 }
567 }
568
569 /***************************************************************************//**
570 * @brief
571 * Combine two PRS channels using a logic function.
572 *
573 * @details
574 * This function allows you to combine the output of one PRS channel with the
575 * the signal of another PRS channel using various logic functions. Note that
576 * for series 2, config 1 devices, the hardware only allows a PRS channel to
577 * be combined with the previous channel. So for instance channel 5 can be
578 * combined only with channel 4.
579 *
580 * The logic function operates on two PRS channels called A and B. The output
581 * of PRS channel B is combined with the PRS source configured for channel A
582 * to produce an output. This output is used as the output of channel A.
583 *
584 * @param[in] chA
585 * PRS Channel for the A input.
586 *
587 * @param[in] chB
588 * PRS Channel for the B input.
589 *
590 * @param[in] logic
591 * The logic function to use when combining the Channel A and Channel B. The
592 * output of the logic function is the output of Channel A. Function like
593 * AND, OR, XOR, NOT and more are available.
594 ******************************************************************************/
PRS_Combine(unsigned int chA,unsigned int chB,PRS_Logic_t logic)595 void PRS_Combine(unsigned int chA, unsigned int chB, PRS_Logic_t logic)
596 {
597 EFM_ASSERT(chA < PRS_ASYNC_CHAN_COUNT);
598 EFM_ASSERT(chB < PRS_ASYNC_CHAN_COUNT);
599
600 #if defined(_SILICON_LABS_32B_SERIES_2_CONFIG_1)
601 EFM_ASSERT(chA == ((chB + 1) % PRS_ASYNC_CHAN_COUNT));
602 PRS->ASYNC_CH[chA].CTRL = (PRS->ASYNC_CH[chA].CTRL & ~_PRS_ASYNC_CH_CTRL_FNSEL_MASK)
603 | ((uint32_t)logic << _PRS_ASYNC_CH_CTRL_FNSEL_SHIFT);
604
605 #else
606 PRS->ASYNC_CH[chA].CTRL = (PRS->ASYNC_CH[chA].CTRL
607 & ~(_PRS_ASYNC_CH_CTRL_FNSEL_MASK
608 | _PRS_ASYNC_CH_CTRL_AUXSEL_MASK))
609 | ((uint32_t)logic << _PRS_ASYNC_CH_CTRL_FNSEL_SHIFT)
610 | ((uint32_t)chB << _PRS_ASYNC_CH_CTRL_AUXSEL_SHIFT);
611 PRS->ASYNC_CH[chB].CTRL = (PRS->ASYNC_CH[chB].CTRL & ~_PRS_ASYNC_CH_CTRL_FNSEL_MASK)
612 | PRS_ASYNC_CH_CTRL_FNSEL_DEFAULT;
613 #endif
614 }
615 #endif
616
617 /** @} (end addtogroup prs) */
618 #endif /* defined(PRS_COUNT) && (PRS_COUNT > 0) */
619