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 #ifndef __EM_PRS_H
34 #define __EM_PRS_H
35 
36 #include "em_part.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /***************************************************************************//**
43  * @addtogroup EM_Library
44  * @{
45  ******************************************************************************/
46 
47 /***************************************************************************//**
48  * @addtogroup PRS
49  * @{
50  ******************************************************************************/
51 
52 /*******************************************************************************
53  ********************************   ENUMS   ************************************
54  ******************************************************************************/
55 
56 /** Edge detection type. */
57 typedef enum
58 {
59   prsEdgeOff  = PRS_CH_CTRL_EDSEL_OFF,      /**< Leave signal as is. */
60   prsEdgePos  = PRS_CH_CTRL_EDSEL_POSEDGE,  /**< Generate pules on positive edge. */
61   prsEdgeNeg  = PRS_CH_CTRL_EDSEL_NEGEDGE,  /**< Generate pules on negative edge. */
62   prsEdgeBoth = PRS_CH_CTRL_EDSEL_BOTHEDGES /**< Generate pules on both edges. */
63 } PRS_Edge_TypeDef;
64 
65 /*******************************************************************************
66  *****************************   PROTOTYPES   **********************************
67  ******************************************************************************/
68 
69 /***************************************************************************//**
70  * @brief
71  *   Set level control bit for one or more channels.
72  *
73  * @details
74  *   The level value for a channel is XORed with both the pulse possible issued
75  *   by PRS_PulseTrigger() and the PRS input signal selected for the channel(s).
76  *
77  * @param[in] level
78  *   Level to use for channels indicated by @p mask. Use logical OR combination
79  *   of PRS_SWLEVEL_CHnLEVEL defines for channels to set high level, otherwise 0.
80  *
81  * @param[in] mask
82  *   Mask indicating which channels to set level for. Use logical OR combination
83  *   of PRS_SWLEVEL_CHnLEVEL defines.
84  ******************************************************************************/
PRS_LevelSet(uint32_t level,uint32_t mask)85 __STATIC_INLINE void PRS_LevelSet(uint32_t level, uint32_t mask)
86 {
87   PRS->SWLEVEL = (PRS->SWLEVEL & ~mask) | (level & mask);
88 }
89 
90 
91 /***************************************************************************//**
92  * @brief
93  *   Trigger a high pulse (one HFPERCLK) for one or more channels.
94  *
95  * @details
96  *   Setting a bit for a channel causes the bit in the register to remain high
97  *   for one HFPERCLK cycle. The pulse is XORed with both the corresponding bit
98  *   in PRS SWLEVEL register and the PRS input signal selected for the
99  *   channel(s).
100  *
101  * @param[in] channels
102  *   Logical ORed combination of channels to trigger a pulse for. Use
103  *   PRS_SWPULSE_CHnPULSE defines.
104  ******************************************************************************/
PRS_PulseTrigger(uint32_t channels)105 __STATIC_INLINE void PRS_PulseTrigger(uint32_t channels)
106 {
107   PRS->SWPULSE = channels & _PRS_SWPULSE_MASK;
108 }
109 
110 void PRS_SourceSignalSet(unsigned int ch,
111                          uint32_t source,
112                          uint32_t signal,
113                          PRS_Edge_TypeDef edge);
114 
115 #if ((defined _EFM32_TINY_FAMILY) || (defined _EFM32_GIANT_FAMILY))
116 void PRS_SourceAsyncSignalSet(unsigned int ch,
117                               uint32_t source,
118                               uint32_t signal);
119 #endif
120 
121 /** @} (end addtogroup PRS) */
122 /** @} (end addtogroup EM_Library) */
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif /* __EM_PRS_H */
129