2 * -------------------------------------------
3 * MSP432 DriverLib - v3_10_00_09
4 * -------------------------------------------
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2014, Texas Instruments Incorporated
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
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.
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.
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.
37 /* Standard Includes */
41 /* DriverLib Includes */
47 static bool SysCtlSRAMBankValid(uint8_t sramBank)
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
60 static bool SysCtlSRAMBankValidRet(uint8_t sramBank)
62 sramBank &= ~(SYSCTL_SRAM_BANK7 & SYSCTL_SRAM_BANK6 &
63 SYSCTL_SRAM_BANK5 & SYSCTL_SRAM_BANK4 &
64 SYSCTL_SRAM_BANK3 & SYSCTL_SRAM_BANK2 &
67 return (sramBank == 0);
70 static bool SysCtlPeripheralIsValid (uint16_t hwPeripheral)
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);
82 return (hwPeripheral == 0);
86 void SysCtl_getTLVInfo(uint_fast8_t tag, uint_fast8_t instance,
87 uint_fast8_t *length, uint32_t **data_address)
89 /* TLV Structure Start Address */
90 uint32_t *TLV_address = (uint32_t *) TLV_START;
92 while (((*TLV_address != tag)) // check for tag and instance
93 && (*TLV_address != TLV_TAGEND)) // do range check first
95 if (*TLV_address == tag)
102 /* Repeat until requested instance is reached */
106 TLV_address += (*(TLV_address + 1)) + 2;
109 /* Check if Tag match happened... */
110 if (*TLV_address == tag)
112 /* Return length = Address + 1 */
113 *length = (*(TLV_address + 1))*4;
114 /* Return address of first data/value info = Address + 2 */
115 *data_address = (uint32_t *) (TLV_address + 2);
117 // If there was no tag match and the end of TLV structure was reached..
120 // Return 0 for TAG not found
122 // Return 0 for TAG not found
127 uint_least32_t SysCtl_getSRAMSize(void)
129 return SYSCTL->SRAM_SIZE;
132 uint_least32_t SysCtl_getFlashSize(void)
134 return SYSCTL->FLASH_SIZE;
137 void SysCtl_disableNMISource(uint_fast8_t flags)
139 SYSCTL->NMI_CTLSTAT &= ~(flags);
142 void SysCtl_enableNMISource(uint_fast8_t flags)
144 SYSCTL->NMI_CTLSTAT |= flags;
147 uint_fast8_t SysCtl_getNMISourceStatus(void)
149 return SYSCTL->NMI_CTLSTAT;
152 void SysCtl_enableSRAMBank(uint_fast8_t sramBank)
154 ASSERT(SysCtlSRAMBankValid(sramBank));
156 /* Waiting for SRAM Ready Bit to be set */
157 while (!(SYSCTL->SRAM_BANKEN & SYSCTL_SRAM_BANKEN_SRAM_RDY))
160 SYSCTL->SRAM_BANKEN = (sramBank | SYSCTL_SRAM_BANKEN_BNK0_EN);
163 void SysCtl_disableSRAMBank(uint_fast8_t sramBank)
165 ASSERT(SysCtlSRAMBankValid(sramBank));
167 /* Waiting for SRAM Ready Bit to be set */
168 while (!(SYSCTL->SRAM_BANKEN & SYSCTL_SRAM_BANKEN_SRAM_RDY))
173 case SYSCTL_SRAM_BANK7:
174 sramBank = SYSCTL_SRAM_BANK6 + SYSCTL_SRAM_BANK5 + SYSCTL_SRAM_BANK4
175 + SYSCTL_SRAM_BANK3 + SYSCTL_SRAM_BANK2
178 case SYSCTL_SRAM_BANK6:
179 sramBank = SYSCTL_SRAM_BANK5 + SYSCTL_SRAM_BANK4
180 + SYSCTL_SRAM_BANK3 + SYSCTL_SRAM_BANK2
183 case SYSCTL_SRAM_BANK5:
184 sramBank = SYSCTL_SRAM_BANK4 + SYSCTL_SRAM_BANK3
185 + SYSCTL_SRAM_BANK2 + SYSCTL_SRAM_BANK1;
187 case SYSCTL_SRAM_BANK4:
188 sramBank = SYSCTL_SRAM_BANK3 + SYSCTL_SRAM_BANK2
191 case SYSCTL_SRAM_BANK3:
192 sramBank = SYSCTL_SRAM_BANK2 + SYSCTL_SRAM_BANK1;
194 case SYSCTL_SRAM_BANK2:
195 sramBank = SYSCTL_SRAM_BANK1;
197 case SYSCTL_SRAM_BANK1:
204 SYSCTL->SRAM_BANKEN = (sramBank | SYSCTL_SRAM_BANKEN_BNK0_EN);
207 void SysCtl_enableSRAMBankRetention(uint_fast8_t sramBank)
209 ASSERT(SysCtlSRAMBankValidRet(sramBank));
211 /* Waiting for SRAM Ready Bit to be set */
212 while (!(SYSCTL->SRAM_BANKRET & SYSCTL_SRAM_BANKRET_SRAM_RDY))
215 SYSCTL->SRAM_BANKRET |= sramBank;
218 void SysCtl_disableSRAMBankRetention(uint_fast8_t sramBank)
220 ASSERT(SysCtlSRAMBankValidRet(sramBank));
222 /* Waiting for SRAM Ready Bit to be set */
223 while (!(SYSCTL->SRAM_BANKRET & SYSCTL_SRAM_BANKRET_SRAM_RDY))
226 SYSCTL->SRAM_BANKRET &= ~sramBank;
229 void SysCtl_rebootDevice(void)
231 SYSCTL->REBOOT_CTL = (SYSCTL_REBOOT_CTL_REBOOT | SYSCTL_REBOOT_KEY);
234 void SysCtl_enablePeripheralAtCPUHalt(uint_fast16_t devices)
236 ASSERT(SysCtlPeripheralIsValid(devices));
237 SYSCTL->PERIHALT_CTL &= ~devices;
240 void SysCtl_disablePeripheralAtCPUHalt(uint_fast16_t devices)
242 ASSERT(SysCtlPeripheralIsValid(devices));
243 SYSCTL->PERIHALT_CTL |= devices;
246 void SysCtl_setWDTTimeoutResetType(uint_fast8_t resetType)
249 SYSCTL->WDTRESET_CTL |=
250 SYSCTL_WDTRESET_CTL_TIMEOUT;
252 SYSCTL->WDTRESET_CTL &= ~SYSCTL_WDTRESET_CTL_TIMEOUT;
255 void SysCtl_setWDTPasswordViolationResetType(uint_fast8_t resetType)
257 ASSERT(resetType <= SYSCTL_HARD_RESET);
260 SYSCTL->WDTRESET_CTL |=
261 SYSCTL_WDTRESET_CTL_VIOLATION;
263 SYSCTL->WDTRESET_CTL &= ~SYSCTL_WDTRESET_CTL_VIOLATION;
266 void SysCtl_enableGlitchFilter(void)
268 SYSCTL->DIO_GLTFLT_CTL |= SYSCTL_DIO_GLTFLT_CTL_GLTCH_EN;
271 void SysCtl_disableGlitchFilter(void)
273 SYSCTL->DIO_GLTFLT_CTL &= ~SYSCTL_DIO_GLTFLT_CTL_GLTCH_EN;
276 uint_fast16_t SysCtl_getTempCalibrationConstant(uint32_t refVoltage,
277 uint32_t temperature)
279 return HWREG16(TLV_BASE + refVoltage + temperature);