1 /***************************************************************************//**
2  * @file
3  * @brief Peripheral Reflex System (PRS) Peripheral API
4  * @author Energy Micro AS
5  * @version 3.0.0
6  *******************************************************************************
7  * @section License
8  * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
9  *******************************************************************************
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute it
13  * freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must not
16  *    claim that you wrote the original software.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  *    misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  *
21  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
22  * obligation to support this Software. Energy Micro AS is providing the
23  * Software "AS IS", with no express or implied warranties of any kind,
24  * including, but not limited to, any implied warranties of merchantability
25  * or fitness for any particular purpose or warranties against infringement
26  * of any proprietary rights of a third party.
27  *
28  * Energy Micro AS will not be liable for any consequential, incidental, or
29  * special damages, or any other relief, or for any claim by any third party,
30  * arising from your use of this Software.
31  *
32  ******************************************************************************/
33 #include "em_prs.h"
34 #include "em_assert.h"
35 #include "em_bitband.h"
36 
37 /***************************************************************************//**
38  * @addtogroup EM_Library
39  * @{
40  ******************************************************************************/
41 
42 /***************************************************************************//**
43  * @addtogroup PRS
44  * @brief Peripheral Reflex System (PRS) Peripheral API
45  * @{
46  ******************************************************************************/
47 
48 /*******************************************************************************
49  **************************   GLOBAL FUNCTIONS   *******************************
50  ******************************************************************************/
51 
52 /***************************************************************************//**
53  * @brief
54  *   Set source and signal to be used for a channel.
55  *
56  * @param[in] ch
57  *   Channel to define signal and source for.
58  *
59  * @param[in] source
60  *   Source to select for channel. Use one of PRS_CH_CTRL_SOURCESEL_x defines.
61  *
62  * @param[in] signal
63  *   Signal (for selected @p source) to use. Use one of PRS_CH_CTRL_SIGSEL_x
64  *   defines.
65  *
66  * @param[in] edge
67  *   Edge (for selected source/signal) to generate pulse for.
68  ******************************************************************************/
PRS_SourceSignalSet(unsigned int ch,uint32_t source,uint32_t signal,PRS_Edge_TypeDef edge)69 void PRS_SourceSignalSet(unsigned int ch,
70                          uint32_t source,
71                          uint32_t signal,
72                          PRS_Edge_TypeDef edge)
73 {
74   EFM_ASSERT(ch < 8);
75 
76   PRS->CH[ch].CTRL = (source & _PRS_CH_CTRL_SOURCESEL_MASK) |
77                      (signal & _PRS_CH_CTRL_SIGSEL_MASK) |
78                      (uint32_t)edge;
79 }
80 
81 #if ((defined _EFM32_TINY_FAMILY) || (defined _EFM32_GIANT_FAMILY))
82 /***************************************************************************//**
83  * @brief
84  *   Set source and asynchronous signal to be used for a channel.
85  *
86  * @details
87  *   Asynchronous reflexes are not clocked on HFPERCLK, and can be used even in
88  *   EM2/EM3.
89  *   There is a limitation to reflexes operating in asynchronous mode: they can
90  *   only be used by a subset of the reflex consumers. Please refer to PRS
91  *   chapter in the reference manual for the complete list of supported
92  *   asynchronous signals and consumers.
93  *
94  * @note
95  *   This function is only supported on the following device families:
96  *   @li Tiny Gecko (EFM32TGxxxFxx)
97  *   @li Giant Gecko (EFM32GGxxxFxxx)
98  *   In asynchronous mode, the edge detector only works in EM0, hence it shall
99  *   not be used. The EDSEL parameter in PRS_CHx_CTRL register is set to 0 (OFF)
100  *   by default.
101  *
102  * @param[in] ch
103  *   Channel to define source and asynchronous signal for.
104  *
105  * @param[in] source
106  *   Source to select for channel. Use one of PRS_CH_CTRL_SOURCESEL_x defines.
107  *
108  * @param[in] signal
109  *   Asynchronous signal (for selected @p source) to use. Use one of the
110  *   PRS_CH_CTRL_SIGSEL_x defines that support asynchronous operation.
111  ******************************************************************************/
PRS_SourceAsyncSignalSet(unsigned int ch,uint32_t source,uint32_t signal)112 void PRS_SourceAsyncSignalSet(unsigned int ch,
113                               uint32_t source,
114                               uint32_t signal)
115 {
116   EFM_ASSERT(ch < 8);
117 
118   PRS->CH[ch].CTRL = PRS_CH_CTRL_ASYNC |
119                      (source & _PRS_CH_CTRL_SOURCESEL_MASK) |
120                      (signal & _PRS_CH_CTRL_SIGSEL_MASK) |
121                      PRS_CH_CTRL_EDSEL_OFF;
122 }
123 #endif
124 
125 /** @} (end addtogroup PRS) */
126 /** @} (end addtogroup EM_Library) */
127