]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/pss.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / pss.c
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v01_04_00_18 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2015, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * *  Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * *  Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  * --/COPYRIGHT--*/
37 /* Standard Includes */
38 #include <stdint.h>
39
40 /* DriverLib Includes */
41 #include <pss.h>
42 #include <interrupt.h>
43 #include <debug.h>
44 #include <cpu.h>
45
46 static void __PSSUnlock()
47 {
48     PSS->rKEY.r = PSS_KEY_VALUE;
49 }
50
51 static void __PSSLock()
52 {
53     PSS->rKEY.r = 0;
54 }
55
56 void PSS_enableHighSidePinToggle(bool activeLow)
57 {
58     __PSSUnlock();
59
60     if (activeLow)
61         PSS->rCTL0.r |= (SVMHOE | SVMHOUTPOLAL);
62     else
63     {
64         BITBAND_PERI(PSS->rCTL0.r, SVMHOUTPOLAL_OFS) = 0;
65         BITBAND_PERI(PSS->rCTL0.r, SVMHOE_OFS) = 1;
66     }
67
68     __PSSLock();
69 }
70
71 void PSS_disableHighSidePinToggle(void)
72 {
73     __PSSUnlock();
74
75     BITBAND_PERI(PSS->rCTL0.r, SVMHOE_OFS) = 0;
76
77     __PSSLock();
78 }
79
80 void PSS_enableHighSide(void)
81 {
82     __PSSUnlock();
83
84     BITBAND_PERI(PSS->rCTL0.r, SVSMHOFF_OFS) = 0;
85
86     __PSSLock();
87 }
88
89 void PSS_disableHighSide(void)
90 {
91     __PSSUnlock();
92
93     BITBAND_PERI(PSS->rCTL0.r, SVSMHOFF_OFS) = 1;
94
95     __PSSLock();
96 }
97
98 void PSS_setHighSidePerformanceMode(uint_fast8_t powerMode)
99 {
100     __PSSUnlock();
101
102     if (powerMode == PSS_FULL_PERFORMANCE_MODE)
103         BITBAND_PERI(PSS->rCTL0.r, SVSMHLP_OFS) = 0;
104     else
105         BITBAND_PERI(PSS->rCTL0.r, SVSMHLP_OFS) = 1;
106
107     __PSSLock();
108 }
109
110 uint_fast8_t PSS_getHighSidePerformanceMode(void)
111 {
112     if (BITBAND_PERI(PSS->rCTL0.r, SVSMHLP_OFS))
113         return PSS_NORMAL_PERFORMANCE_MODE;
114     else
115         return PSS_FULL_PERFORMANCE_MODE;
116 }
117
118 void PSS_enableHighSideMonitor(void)
119 {
120     __PSSUnlock();
121
122     BITBAND_PERI(PSS->rCTL0.r, SVSMHS_OFS) = 1;
123
124     __PSSLock();
125 }
126
127 void PSS_disableHighSideMonitor(void)
128 {
129     __PSSUnlock();
130
131     BITBAND_PERI(PSS->rCTL0.r, SVSMHS_OFS) = 0;
132
133     __PSSLock();
134 }
135
136 void PSS_setHighSideVoltageTrigger(uint_fast8_t triggerVoltage)
137 {
138     __PSSUnlock();
139
140     ASSERT(!(triggerVoltage & 0xF8))
141
142     PSS->rCTL0.b.bSVSMHTH = triggerVoltage & 0x07;
143
144     __PSSLock();
145 }
146
147 uint_fast8_t PSS_getHighSideVoltageTrigger(void)
148 {
149     return PSS->rCTL0.b.bSVSMHTH;
150 }
151
152
153 void PSS_enableLowSide(void)
154 {
155     __PSSUnlock();
156
157     BITBAND_PERI(PSS->rCTL0.r, SVSLOFF_OFS) = 0;
158
159     __PSSLock();
160 }
161
162 void PSS_disableLowSide(void)
163 {
164     __PSSUnlock();
165
166     BITBAND_PERI(PSS->rCTL0.r, SVSLOFF_OFS) = 1;
167
168     __PSSLock();
169 }
170
171
172 void PSS_setLowSidePerformanceMode(uint_fast8_t ui8PowerMode)
173 {
174     __PSSUnlock();
175
176     if (ui8PowerMode == PSS_FULL_PERFORMANCE_MODE)
177         BITBAND_PERI(PSS->rCTL0.r, SVSLLP_OFS) = 0;
178     else
179         BITBAND_PERI(PSS->rCTL0.r, SVSLLP_OFS) = 1;
180
181     __PSSLock();
182 }
183
184 uint_fast8_t PSS_getLowSidePerformanceMode(void)
185 {
186     if (BITBAND_PERI(PSS->rCTL0.r, SVSLLP_OFS))
187         return PSS_NORMAL_PERFORMANCE_MODE;
188     else
189         return PSS_FULL_PERFORMANCE_MODE;
190 }
191
192
193 void PSS_enableInterrupt(void)
194 {
195     __PSSUnlock();
196     BITBAND_PERI(PSS->rIE.r,SVSMHIE_OFS) = 1;
197     __PSSLock();
198 }
199
200 void PSS_disableInterrupt(void)
201 {
202     __PSSUnlock();
203     BITBAND_PERI(PSS->rIE.r,SVSMHIE_OFS) = 0;
204     __PSSLock();
205 }
206
207 uint32_t PSS_getInterruptStatus(void)
208 {
209     return PSS->rIFG.r;
210 }
211
212 void PSS_clearInterruptFlag(void)
213 {
214     __PSSUnlock();
215     BITBAND_PERI(PSS->rCLRIFG.r,CLRSVSMHIFG_OFS) = 0;
216     __PSSLock();
217 }
218
219 void PSS_registerInterrupt(void (*intHandler)(void))
220 {
221     //
222     // Register the interrupt handler, returning an error if an error occurs.
223     //
224     Interrupt_registerInterrupt(INT_PSS, intHandler);
225
226     //
227     // Enable the system control interrupt.
228     //
229     Interrupt_enableInterrupt(INT_PSS);
230 }
231
232 void PSS_unregisterInterrupt(void)
233 {
234     //
235     // Disable the interrupt.
236     //
237     Interrupt_disableInterrupt(INT_PSS);
238
239     //
240     // Unregister the interrupt handler.
241     //
242     Interrupt_unregisterInterrupt(INT_PSS);
243 }