]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/pss.c
Update MSP432 projects to use updated driver library files.
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / pss.c
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v3_10_00_09 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2014, 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->KEY = PSS_KEY_VALUE;
49 }
50
51 static void __PSSLock()
52 {
53     PSS->KEY = 0;
54 }
55
56
57 void PSS_enableForcedDCDCOperation(void)
58 {
59     __PSSUnlock();
60
61     BITBAND_PERI(PSS->CTL0, PSS_CTL0_DCDC_FORCE_OFS) = 1;
62
63     __PSSLock();
64 }
65
66 void PSS_disableForcedDCDCOperation(void)
67 {
68     __PSSUnlock();
69
70     BITBAND_PERI(PSS->CTL0, PSS_CTL0_DCDC_FORCE_OFS) = 0;
71
72     __PSSLock();
73
74 }
75
76 void PSS_enableHighSidePinToggle(bool activeLow)
77 {
78     __PSSUnlock();
79
80     if (activeLow)
81         PSS->CTL0 |= (PSS_CTL0_SVMHOE | PSS_CTL0_SVMHOUTPOLAL);
82     else
83     {
84         BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVMHOUTPOLAL_OFS) = 0;
85         BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVMHOE_OFS) = 1;
86     }
87
88     __PSSLock();
89 }
90
91 void PSS_disableHighSidePinToggle(void)
92 {
93     __PSSUnlock();
94
95     BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVMHOE_OFS) = 0;
96
97     __PSSLock();
98 }
99
100 void PSS_enableHighSide(void)
101 {
102     __PSSUnlock();
103
104     BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVSMHOFF_OFS) = 0;
105
106     __PSSLock();
107 }
108
109 void PSS_disableHighSide(void)
110 {
111     __PSSUnlock();
112
113     BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVSMHOFF_OFS) = 1;
114
115     __PSSLock();
116 }
117
118 void PSS_setHighSidePerformanceMode(uint_fast8_t powerMode)
119 {
120     __PSSUnlock();
121
122     if (powerMode == PSS_FULL_PERFORMANCE_MODE)
123         BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVSMHLP_OFS) = 0;
124     else
125         BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVSMHLP_OFS) = 1;
126
127     __PSSLock();
128 }
129
130 uint_fast8_t PSS_getHighSidePerformanceMode(void)
131 {
132     if (BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVSMHLP_OFS))
133         return PSS_NORMAL_PERFORMANCE_MODE;
134     else
135         return PSS_FULL_PERFORMANCE_MODE;
136 }
137
138 void PSS_enableHighSideMonitor(void)
139 {
140     __PSSUnlock();
141
142     BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVSMHS_OFS) = 1;
143
144     __PSSLock();
145 }
146
147 void PSS_disableHighSideMonitor(void)
148 {
149     __PSSUnlock();
150
151     BITBAND_PERI(PSS->CTL0, PSS_CTL0_SVSMHS_OFS) = 0;
152
153     __PSSLock();
154 }
155
156 void PSS_setHighSideVoltageTrigger(uint_fast8_t triggerVoltage)
157 {
158     __PSSUnlock();
159
160     ASSERT(!(triggerVoltage & 0xF8))
161
162     PSS->CTL0 &= ~PSS_CTL0_SVSMHTH_MASK;
163     PSS->CTL0 |= (triggerVoltage & 0x07) << PSS_CTL0_SVSMHTH_OFS;
164
165     __PSSLock();
166 }
167
168 uint_fast8_t PSS_getHighSideVoltageTrigger(void)
169 {
170     return (uint_fast8_t)((PSS->CTL0 & PSS_CTL0_SVSMHTH_MASK)
171                 >> PSS_CTL0_SVSMHTH_OFS);
172 }
173
174 void PSS_enableInterrupt(void)
175 {
176     __PSSUnlock();
177     BITBAND_PERI(PSS->IE,PSS_IE_SVSMHIE_OFS) = 1;
178     __PSSLock();
179 }
180
181 void PSS_disableInterrupt(void)
182 {
183     __PSSUnlock();
184     BITBAND_PERI(PSS->IE,PSS_IE_SVSMHIE_OFS) = 0;
185     __PSSLock();
186 }
187
188 uint32_t PSS_getInterruptStatus(void)
189 {
190     return PSS->IFG;
191 }
192
193 void PSS_clearInterruptFlag(void)
194 {
195     __PSSUnlock();
196     BITBAND_PERI(PSS->CLRIFG,PSS_CLRIFG_CLRSVSMHIFG_OFS) = 0;
197     __PSSLock();
198 }
199
200 void PSS_registerInterrupt(void (*intHandler)(void))
201 {
202     //
203     // Register the interrupt handler, returning an error if an error occurs.
204     //
205     Interrupt_registerInterrupt(INT_PSS, intHandler);
206
207     //
208     // Enable the system control interrupt.
209     //
210     Interrupt_enableInterrupt(INT_PSS);
211 }
212
213 void PSS_unregisterInterrupt(void)
214 {
215     //
216     // Disable the interrupt.
217     //
218     Interrupt_disableInterrupt(INT_PSS);
219
220     //
221     // Unregister the interrupt handler.
222     //
223     Interrupt_unregisterInterrupt(INT_PSS);
224 }