]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/sysctl.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / sysctl.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 #include <stdbool.h>
40
41 /* DriverLib Includes */
42 #include <sysctl.h>
43 #include <debug.h>
44
45 #ifdef DEBUG
46
47 static bool SysCtlSRAMBankValid(uint8_t sramBank)
48 {
49     return(
50             sramBank == SYSCTL_SRAM_BANK7 ||
51             sramBank == SYSCTL_SRAM_BANK6 ||
52             sramBank == SYSCTL_SRAM_BANK5 ||
53             sramBank == SYSCTL_SRAM_BANK4 ||
54             sramBank == SYSCTL_SRAM_BANK3 ||
55             sramBank == SYSCTL_SRAM_BANK2 ||
56             sramBank == SYSCTL_SRAM_BANK1
57     );
58 }
59
60 static bool SysCtlSRAMBankValidRet(uint8_t sramBank)
61 {
62     sramBank &= ~(SYSCTL_SRAM_BANK7 & SYSCTL_SRAM_BANK6 &
63             SYSCTL_SRAM_BANK5 & SYSCTL_SRAM_BANK4 &
64             SYSCTL_SRAM_BANK3 & SYSCTL_SRAM_BANK2 &
65             SYSCTL_SRAM_BANK1);
66
67     return (sramBank == 0);
68 }
69
70 static bool SysCtlPeripheralIsValid (uint16_t hwPeripheral)
71 {
72     hwPeripheral &= ~(SYSCTL_PERIPH_DMA & SYSCTL_PERIPH_WDT &
73             SYSCTL_PERIPH_ADC & SYSCTL_PERIPH_EUSCIB3 &
74             SYSCTL_PERIPH_EUSCIB2 & SYSCTL_PERIPH_EUSCIB1 &
75             SYSCTL_PERIPH_EUSCIB0 & SYSCTL_PERIPH_EUSCIA3 &
76             SYSCTL_PERIPH_EUSCIA2 & SYSCTL_PERIPH_EUSCIA1 &
77             SYSCTL_PERIPH_EUSCIA0 & SYSCTL_PERIPH_TIMER32_0_MODULE &
78             SYSCTL_PERIPH_TIMER16_3 & SYSCTL_PERIPH_TIMER16_2 &
79             SYSCTL_PERIPH_TIMER16_2 & SYSCTL_PERIPH_TIMER16_1 &
80             SYSCTL_PERIPH_TIMER16_0);
81
82     return (hwPeripheral == 0);
83 }
84 #endif
85
86 uint_least32_t SysCtl_getSRAMSize(void)
87 {
88     return SYSCTL->rSRAM_SIZE;
89 }
90
91 uint_least32_t SysCtl_getFlashSize(void)
92 {
93     return SYSCTL->rFLASH_SIZE;
94 }
95
96 void SysCtl_disableNMISource(uint_fast8_t flags)
97 {
98     SYSCTL->rNMI_CTLSTAT.r &= ~(flags);
99 }
100
101 void SysCtl_enableNMISource(uint_fast8_t flags)
102 {
103     SYSCTL->rNMI_CTLSTAT.r |= flags;
104 }
105
106 uint_fast8_t SysCtl_getNMISourceStatus(void)
107 {
108     return SYSCTL->rNMI_CTLSTAT.r;
109 }
110
111 void SysCtl_enableSRAMBank(uint_fast8_t sramBank)
112 {
113     ASSERT(SysCtlSRAMBankValid(sramBank));
114
115     /* Waiting for SRAM Ready Bit to be set */
116     while (!SYSCTL->rSRAM_BANKEN.b.bSRAM_RDY)
117         ;
118
119     SYSCTL->rSRAM_BANKEN.r = (sramBank | SYSCTL_SRAM_BANKEN_BNK0_EN);
120 }
121
122 void SysCtl_disableSRAMBank(uint_fast8_t sramBank)
123 {
124     ASSERT(SysCtlSRAMBankValid(sramBank));
125
126     /* Waiting for SRAM Ready Bit to be set */
127     while (!SYSCTL->rSRAM_BANKEN.b.bSRAM_RDY)
128         ;      
129
130     switch (sramBank)
131     {
132     case SYSCTL_SRAM_BANK7:
133         sramBank = SYSCTL_SRAM_BANK6 +  SYSCTL_SRAM_BANK5 + SYSCTL_SRAM_BANK4
134                         + SYSCTL_SRAM_BANK3 + SYSCTL_SRAM_BANK2 
135                         + SYSCTL_SRAM_BANK1;
136         break;
137     case SYSCTL_SRAM_BANK6:
138         sramBank =   SYSCTL_SRAM_BANK5 + SYSCTL_SRAM_BANK4
139                         + SYSCTL_SRAM_BANK3 + SYSCTL_SRAM_BANK2 
140                         + SYSCTL_SRAM_BANK1;
141         break;
142     case SYSCTL_SRAM_BANK5:
143         sramBank =   SYSCTL_SRAM_BANK4 + SYSCTL_SRAM_BANK3  
144                 + SYSCTL_SRAM_BANK2 + SYSCTL_SRAM_BANK1;
145         break;
146     case SYSCTL_SRAM_BANK4:
147         sramBank =   SYSCTL_SRAM_BANK3 + SYSCTL_SRAM_BANK2 
148                         + SYSCTL_SRAM_BANK1;
149         break;
150     case SYSCTL_SRAM_BANK3:
151         sramBank =   SYSCTL_SRAM_BANK2 + SYSCTL_SRAM_BANK1;
152         break;
153     case SYSCTL_SRAM_BANK2:
154         sramBank = SYSCTL_SRAM_BANK1;
155         break;
156     case SYSCTL_SRAM_BANK1:
157         sramBank = 0;
158         break;
159     default:
160         return;
161     }
162
163     SYSCTL->rSRAM_BANKEN.r = (sramBank | SYSCTL_SRAM_BANKEN_BNK0_EN);
164 }
165
166 void SysCtl_enableSRAMBankRetention(uint_fast8_t sramBank)
167 {
168     ASSERT(SysCtlSRAMBankValidRet(sramBank));
169
170     /* Waiting for SRAM Ready Bit to be set */
171     while (!SYSCTL->rSRAM_BANKRET.b.bSRAM_RDY)
172         ;
173
174     SYSCTL->rSRAM_BANKRET.r |= sramBank;
175 }
176
177 void SysCtl_disableSRAMBankRetention(uint_fast8_t sramBank)
178 {
179     ASSERT(SysCtlSRAMBankValidRet(sramBank));
180
181     /* Waiting for SRAM Ready Bit to be set */
182     while (!SYSCTL->rSRAM_BANKRET.b.bSRAM_RDY)
183         ;
184
185     SYSCTL->rSRAM_BANKRET.r &= ~sramBank;
186 }
187
188 void SysCtl_rebootDevice(void)
189 {
190     SYSCTL->rREBOOT_CTL.r = (SYSCTL_REBOOT_CTL_REBOOT | SYSCTL_REBOOT_KEY);
191 }
192
193 void SysCtl_enablePeripheralAtCPUHalt(uint_fast16_t devices)
194 {
195     ASSERT(SysCtlPeripheralIsValid(devices));
196     SYSCTL->rPERIHALT_CTL.r &= ~devices;
197 }
198
199 void SysCtl_disablePeripheralAtCPUHalt(uint_fast16_t devices)
200 {
201     ASSERT(SysCtlPeripheralIsValid(devices));
202     SYSCTL->rPERIHALT_CTL.r |= devices;
203 }
204
205 void SysCtl_setWDTTimeoutResetType(uint_fast8_t resetType)
206 {
207     if (resetType)
208         SYSCTL->rWDTRESET_CTL.r |=
209                 SYSCTL_WDTRESET_CTL_TIMEOUT;
210     else
211         SYSCTL->rWDTRESET_CTL.r &= ~SYSCTL_WDTRESET_CTL_TIMEOUT;
212 }
213
214 void SysCtl_setWDTPasswordViolationResetType(uint_fast8_t resetType)
215 {
216     ASSERT(resetType <= SYSCTL_HARD_RESET);
217
218     if (resetType)
219         SYSCTL->rWDTRESET_CTL.r |=
220                 SYSCTL_WDTRESET_CTL_VIOLATION;
221     else
222         SYSCTL->rWDTRESET_CTL.r &= ~SYSCTL_WDTRESET_CTL_VIOLATION;
223 }
224
225 void SysCtl_enableGlitchFilter(void)
226 {
227     SYSCTL->rDIO_GLTFLT_CTL.r |= SYSCTL_DIO_GLTFLT_CTL_GLTCH_EN;
228 }
229
230 void SysCtl_disableGlitchFilter(void)
231 {
232     SYSCTL->rDIO_GLTFLT_CTL.r &= ~SYSCTL_DIO_GLTFLT_CTL_GLTCH_EN;
233 }
234
235 uint_fast16_t SysCtl_getTempCalibrationConstant(uint32_t refVoltage,
236         uint32_t temperature)
237 {
238     return HWREG16(TLV_BASE + refVoltage + temperature);
239 }