initial commit to new repo

This commit is contained in:
Nicole Faerber 2021-02-14 18:03:13 +01:00
parent ccdb239b00
commit adbc36ad71
131 changed files with 52765 additions and 1 deletions

View file

@ -0,0 +1,127 @@
/*******************************************************************************
*
* HAL_FLASH.c
* Flash Library for flash memory controller of MSP430F5xx/6xx family
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 01/18/2011
*
******************************************************************************/
#include "msp430.h"
#include "HAL_FLASH.h"
void Flash_SegmentErase(unsigned int *Flash_ptr)
{
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + ERASE; // Set Erase bit
*Flash_ptr = 0; // Dummy write to erase Flash seg
while (FCTL3 & BUSY); // test busy
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
unsigned char Flash_EraseCheck(unsigned int *Flash_ptr, unsigned int len)
{
unsigned int i;
for (i = 0; i < len; i++) { // was erasing successfull?
if (*(Flash_ptr + i) != 0xFF) {
return FLASH_STATUS_ERROR;
}
}
return FLASH_STATUS_OK;
}
void FlashWrite_8(unsigned char *Data_ptr, unsigned char *Flash_ptr, unsigned int count)
{
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+WRT; // Enable byte/word write mode
while (count > 0) {
while (FCTL3 & BUSY); // test busy
*Flash_ptr++ = *Data_ptr++; // Write to Flash
count--;
}
FCTL1 = FWKEY; // Clear write bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void FlashWrite_16(unsigned int *Data_ptr, unsigned int *Flash_ptr, unsigned int count)
{
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+WRT; // Enable byte/word write mode
while (count > 0) {
while (FCTL3 & BUSY); // test busy
*Flash_ptr++ = *Data_ptr++; // Write to Flash
count--;
}
FCTL1 = FWKEY; // Clear Erase bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void FlashWrite_32(unsigned long *Data_ptr, unsigned long *Flash_ptr, unsigned int count)
{
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + BLKWRT; // Enable long-word write
while (count > 0) {
while (FCTL3 & BUSY); // test busy
*Flash_ptr++ = *Data_ptr++; // Write to Flash
count--;
}
FCTL1 = FWKEY; // Clear Erase bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void FlashMemoryFill_32(unsigned long value, unsigned long *Flash_ptr, unsigned int count)
{
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + BLKWRT; // Enable long-word write
while (count > 0) {
while (FCTL3 & BUSY); // test busy
*Flash_ptr++ = value; // Write to Flash
count--;
}
FCTL1 = FWKEY; // Clear Erase bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}

View file

@ -0,0 +1,104 @@
/*******************************************************************************
*
* HAL_FLASH.h
* Flash Library for flash memory controller of MSP430F5xx/6xx family
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 01/18/2011
*
******************************************************************************/
#ifndef HAL_FLASH_H
#define HAL_FLASH_H
//******************************************************************************
// Defines
//******************************************************************************
#define FLASH_STATUS_OK 0
#define FLASH_STATUS_ERROR 1
/*******************************************************************************
* \brief Erase a single segment of the flash memory
*
* \param *Flash_ptr Pointer into the flash segment to erase
******************************************************************************/
extern void Flash_SegmentErase(unsigned int *Flash_ptr);
/*******************************************************************************
* \brief Erase Check of the flash memory
*
* \param *Flash_ptr Pointer into the flash segment to erase
* \param len give the len in word
******************************************************************************/
extern unsigned char Flash_EraseCheck(unsigned int *Flash_ptr, unsigned int len);
/*******************************************************************************
* \brief Write data into the flash memory (Byte format)
*
* \param *Data_ptr Pointer to the Data to write
* \param *Flash_ptr Pointer into the flash to write data to
* \param count number of data to write
******************************************************************************/
extern void FlashWrite_8(unsigned char *Data_ptr, unsigned char *Flash_ptr, unsigned int count);
/*******************************************************************************
* \brief Write data into the flash memory (Word format)
*
* \param *Data_ptr Pointer to the Data to write
* \param *Flash_ptr Pointer into the flash to write data to
* \param count number of data to write
******************************************************************************/
extern void FlashWrite_16(unsigned int *Data_ptr, unsigned int *Flash_ptr, unsigned int count);
/*******************************************************************************
* \brief Write data into the flash memory (Long format)
*
* \param *Data_ptr Pointer to the Data to write
* \param *Flash_ptr Pointer into the flash to write data to
* \param count number of data to write
******************************************************************************/
extern void FlashWrite_32(unsigned long *Data_ptr, unsigned long *Flash_ptr, unsigned int count);
/*******************************************************************************
* \brief Fill data into the flash memory (Long format)
*
* \param value Pointer to the Data to write
* \param *Flash_ptr pointer into the flash to write data to
* \param count number of data to write (= byte * 4)
******************************************************************************/
extern void FlashMemoryFill_32(unsigned long value, unsigned long *Flash_ptr, unsigned int count);
#endif /* HAL_FLASH_H */

View file

@ -0,0 +1,51 @@
/* ****************************************************************************
*
* HAL_MACROS.h
* Flash Library for flash memory controller of MSP430F5xx/6xx family
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 12/15/2010
*
******************************************************************************/
#ifndef HAL_MACROS_H
#define HAL_MACROS_H
/*
* This macro is for use by other macros to form a fully valid C statement.
*/
#define st(x) do { x } while (__LINE__ == -1)
#endif /* HAL_MACROS_H */

View file

@ -0,0 +1,78 @@
/*******************************************************************************
*
* HAL_PMAP.c
* Port Mapper Library for PMAP controller of MSP430F5xx/6xx family
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 12/15/2010
*
******************************************************************************/
#include "msp430.h"
#include "HAL_PMAP.h"
#include "portmacro.h"
// Check and define PMAP function only if the device has port mapping capability
// Note: This macro is defined in the device-specific header file if this
// feature is available on a given MSP430.
#ifdef __MSP430_HAS_PORT_MAPPING__
void configure_ports(const unsigned char *port_mapping, unsigned char *PxMAPy,
unsigned char num_of_ports, unsigned char port_map_reconfig)
{
uint16_t i;
portENTER_CRITICAL();
// Get write-access to port mapping registers:
PMAPPWD = PMAPPW;
if (port_map_reconfig) {
// Allow reconfiguration during runtime:
PMAPCTL = PMAPRECFG;
}
// Configure Port Mapping:
for (i = 0; i < num_of_ports * 8; i++) {
PxMAPy[i] = port_mapping[i];
}
// Disable write-access to port mapping registers:
PMAPPWD = 0;
portEXIT_CRITICAL();
}
#endif /* __MSP430_HAS_PORT_MAPPING__ */

View file

@ -0,0 +1,58 @@
/*******************************************************************************
*
* HAL_PMAP.h
* Port Mapper Library for PMAP controller of MSP430F5xx/6xx family
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 12/15/2010
*
******************************************************************************/
#ifndef HAL_PMAP_H
#define HAL_PMAP_H
/*******************************************************************************
* \brief Configures the MSP430 Port Mapper
*
* \param *port_mapping Pointer to init Data
* \param PxMAPy Pointer start of first Port Mapper to initialize
* \param num_of_ports Number of Ports to initialize
* \param port_map_reconfig Flag to enable/disable reconfiguration
*
******************************************************************************/
extern void configure_ports(const unsigned char *port_mapping, unsigned char *PxMAPy,
unsigned char num_of_ports, unsigned char port_map_reconfig);
#endif /* HAL_PMAP_H */

View file

@ -0,0 +1,274 @@
/*******************************************************************************
*
* HAL_PMM.c
* Power Management Module Library for MSP430F5xx/6xx family
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 12/15/2010
* Modified SetVcoreUp() and SetVcoreDown() functions
*
******************************************************************************/
#include "msp430.h"
#include "HAL_PMM.h"
#define _HAL_PMM_DISABLE_SVML_
#define _HAL_PMM_DISABLE_SVSL_
#define _HAL_PMM_DISABLE_FULL_PERFORMANCE_
#ifdef _HAL_PMM_DISABLE_SVML_
#define _HAL_PMM_SVMLE SVMLE
#else
#define _HAL_PMM_SVMLE 0
#endif
#ifdef _HAL_PMM_DISABLE_SVSL_
#define _HAL_PMM_SVSLE SVSLE
#else
#define _HAL_PMM_SVSLE 0
#endif
#ifdef _HAL_PMM_DISABLE_FULL_PERFORMANCE_
#define _HAL_PMM_SVSFP SVSLFP
#define _HAL_PMM_SVMFP SVMLFP
#else
#define _HAL_PMM_SVSFP 0
#define _HAL_PMM_SVMFP 0
#endif
/*******************************************************************************
* \brief Increase Vcore by one level
*
* \param level Level to which Vcore needs to be increased
* \return status Success/failure
******************************************************************************/
static unsigned int SetVCoreUp(unsigned char level)
{
unsigned int PMMRIE_backup, SVSMHCTL_backup, SVSMLCTL_backup;
// The code flow for increasing the Vcore has been altered to work around
// the erratum FLASH37.
// Please refer to the Errata sheet to know if a specific device is affected
// DO NOT ALTER THIS FUNCTION
// Open PMM registers for write access
PMMCTL0_H = 0xA5;
// Disable dedicated Interrupts
// Backup all registers
PMMRIE_backup = PMMRIE;
PMMRIE &= ~(SVMHVLRPE | SVSHPE | SVMLVLRPE | SVSLPE | SVMHVLRIE |
SVMHIE | SVSMHDLYIE | SVMLVLRIE | SVMLIE | SVSMLDLYIE );
SVSMHCTL_backup = SVSMHCTL;
SVSMLCTL_backup = SVSMLCTL;
// Clear flags
PMMIFG = 0;
// Set SVM highside to new level and check if a VCore increase is possible
SVSMHCTL = SVMHE | SVSHE | (SVSMHRRL0 * level);
// Wait until SVM highside is settled
while ((PMMIFG & SVSMHDLYIFG) == 0);
// Clear flag
PMMIFG &= ~SVSMHDLYIFG;
// Check if a VCore increase is possible
if ((PMMIFG & SVMHIFG) == SVMHIFG) { // -> Vcc is too low for a Vcore increase
// recover the previous settings
PMMIFG &= ~SVSMHDLYIFG;
SVSMHCTL = SVSMHCTL_backup;
// Wait until SVM highside is settled
while ((PMMIFG & SVSMHDLYIFG) == 0);
// Clear all Flags
PMMIFG &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG | SVMLVLRIFG | SVMLIFG | SVSMLDLYIFG);
PMMRIE = PMMRIE_backup; // Restore PMM interrupt enable register
PMMCTL0_H = 0x00; // Lock PMM registers for write access
return PMM_STATUS_ERROR; // return: voltage not set
}
// Set also SVS highside to new level
// Vcc is high enough for a Vcore increase
SVSMHCTL |= (SVSHRVL0 * level);
// Wait until SVM highside is settled
while ((PMMIFG & SVSMHDLYIFG) == 0);
// Clear flag
PMMIFG &= ~SVSMHDLYIFG;
// Set VCore to new level
PMMCTL0_L = PMMCOREV0 * level;
// Set SVM, SVS low side to new level
SVSMLCTL = SVMLE | (SVSMLRRL0 * level) | SVSLE | (SVSLRVL0 * level);
// Wait until SVM, SVS low side is settled
while ((PMMIFG & SVSMLDLYIFG) == 0);
// Clear flag
PMMIFG &= ~SVSMLDLYIFG;
// SVS, SVM core and high side are now set to protect for the new core level
// Restore Low side settings
// Clear all other bits _except_ level settings
SVSMLCTL &= (SVSLRVL0+SVSLRVL1+SVSMLRRL0+SVSMLRRL1+SVSMLRRL2);
// Clear level settings in the backup register,keep all other bits
SVSMLCTL_backup &= ~(SVSLRVL0+SVSLRVL1+SVSMLRRL0+SVSMLRRL1+SVSMLRRL2);
// Restore low-side SVS monitor settings
SVSMLCTL |= SVSMLCTL_backup;
// Restore High side settings
// Clear all other bits except level settings
SVSMHCTL &= (SVSHRVL0+SVSHRVL1+SVSMHRRL0+SVSMHRRL1+SVSMHRRL2);
// Clear level settings in the backup register,keep all other bits
SVSMHCTL_backup &= ~(SVSHRVL0+SVSHRVL1+SVSMHRRL0+SVSMHRRL1+SVSMHRRL2);
// Restore backup
SVSMHCTL |= SVSMHCTL_backup;
// Wait until high side, low side settled
while (((PMMIFG & SVSMLDLYIFG) == 0) && ((PMMIFG & SVSMHDLYIFG) == 0));
// Clear all Flags
PMMIFG &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG | SVMLVLRIFG | SVMLIFG | SVSMLDLYIFG);
PMMRIE = PMMRIE_backup; // Restore PMM interrupt enable register
PMMCTL0_H = 0x00; // Lock PMM registers for write access
return PMM_STATUS_OK;
}
/*******************************************************************************
* \brief Decrease Vcore by one level
*
* \param level Level to which Vcore needs to be decreased
* \return status Success/failure
******************************************************************************/
static unsigned int SetVCoreDown(unsigned char level)
{
unsigned int PMMRIE_backup, SVSMHCTL_backup, SVSMLCTL_backup;
// The code flow for decreasing the Vcore has been altered to work around
// the erratum FLASH37.
// Please refer to the Errata sheet to know if a specific device is affected
// DO NOT ALTER THIS FUNCTION
// Open PMM registers for write access
PMMCTL0_H = 0xA5;
// Disable dedicated Interrupts
// Backup all registers
PMMRIE_backup = PMMRIE;
PMMRIE &= ~(SVMHVLRPE | SVSHPE | SVMLVLRPE | SVSLPE | SVMHVLRIE |
SVMHIE | SVSMHDLYIE | SVMLVLRIE | SVMLIE | SVSMLDLYIE );
SVSMHCTL_backup = SVSMHCTL;
SVSMLCTL_backup = SVSMLCTL;
// Clear flags
PMMIFG &= ~(SVMHIFG | SVSMHDLYIFG | SVMLIFG | SVSMLDLYIFG);
// Set SVM, SVS high & low side to new settings in normal mode
SVSMHCTL = SVMHE | (SVSMHRRL0 * level) | SVSHE | (SVSHRVL0 * level);
SVSMLCTL = SVMLE | (SVSMLRRL0 * level) | SVSLE | (SVSLRVL0 * level);
// Wait until SVM high side and SVM low side is settled
while ((PMMIFG & SVSMHDLYIFG) == 0 || (PMMIFG & SVSMLDLYIFG) == 0);
// Clear flags
PMMIFG &= ~(SVSMHDLYIFG + SVSMLDLYIFG);
// SVS, SVM core and high side are now set to protect for the new core level
// Set VCore to new level
PMMCTL0_L = PMMCOREV0 * level;
// Restore Low side settings
// Clear all other bits _except_ level settings
SVSMLCTL &= (SVSLRVL0+SVSLRVL1+SVSMLRRL0+SVSMLRRL1+SVSMLRRL2);
// Clear level settings in the backup register,keep all other bits
SVSMLCTL_backup &= ~(SVSLRVL0+SVSLRVL1+SVSMLRRL0+SVSMLRRL1+SVSMLRRL2);
// Restore low-side SVS monitor settings
SVSMLCTL |= SVSMLCTL_backup;
// Restore High side settings
// Clear all other bits except level settings
SVSMHCTL &= (SVSHRVL0+SVSHRVL1+SVSMHRRL0+SVSMHRRL1+SVSMHRRL2);
// Clear level settings in the backup register, keep all other bits
SVSMHCTL_backup &= ~(SVSHRVL0+SVSHRVL1+SVSMHRRL0+SVSMHRRL1+SVSMHRRL2);
// Restore backup
SVSMHCTL |= SVSMHCTL_backup;
// Wait until high side, low side settled
while (((PMMIFG & SVSMLDLYIFG) == 0) && ((PMMIFG & SVSMHDLYIFG) == 0));
// Clear all Flags
PMMIFG &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG | SVMLVLRIFG | SVMLIFG | SVSMLDLYIFG);
PMMRIE = PMMRIE_backup; // Restore PMM interrupt enable register
PMMCTL0_H = 0x00; // Lock PMM registers for write access
return PMM_STATUS_OK; // Return: OK
}
unsigned int SetVCore(unsigned char level)
{
unsigned int actlevel;
unsigned int status;
status = 0;
level &= PMMCOREV_3; // Set Mask for Max. level
actlevel = (PMMCTL0 & PMMCOREV_3); // Get actual VCore
// step by step increase or decrease
while (((level != actlevel) && (status == 0)) || (level < actlevel)) {
if (level > actlevel) {
status = SetVCoreUp(++actlevel);
}
else {
status = SetVCoreDown(--actlevel);
}
}
return status;
}

View file

@ -0,0 +1,7 @@
HAL_PMM.o: F5xx_F6xx_Core_Lib/HAL_PMM.c \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/msp430.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/msp430f5438a.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/iomacros.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/in430.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/intrinsics.h \
F5xx_F6xx_Core_Lib/HAL_PMM.h F5xx_F6xx_Core_Lib/HAL_MACROS.h

View file

@ -0,0 +1,105 @@
/*******************************************************************************
*
* HAL_PMM.h
* Power Management Module Library for MSP430F5xx/6xx family
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 12/15/2010
*
******************************************************************************/
#ifndef HAL_PMM_H
#define HAL_PMM_H
#include "HAL_MACROS.h"
/*******************************************************************************
* Macros
******************************************************************************/
#define ENABLE_SVSL() st(PMMCTL0_H = 0xA5; SVSMLCTL |= SVSLE; PMMCTL0_H = 0x00;)
#define DISABLE_SVSL() st(PMMCTL0_H = 0xA5; SVSMLCTL &= ~SVSLE; PMMCTL0_H = 0x00;)
#define ENABLE_SVML() st(PMMCTL0_H = 0xA5; SVSMLCTL |= SVMLE; PMMCTL0_H = 0x00;)
#define DISABLE_SVML() st(PMMCTL0_H = 0xA5; SVSMLCTL &= ~SVMLE; PMMCTL0_H = 0x00;)
#define ENABLE_SVSH() st(PMMCTL0_H = 0xA5; SVSMHCTL |= SVSHE; PMMCTL0_H = 0x00;)
#define DISABLE_SVSH() st(PMMCTL0_H = 0xA5; SVSMHCTL &= ~SVSHE; PMMCTL0_H = 0x00;)
#define ENABLE_SVMH() st(PMMCTL0_H = 0xA5; SVSMHCTL |= SVMHE; PMMCTL0_H = 0x00;)
#define DISABLE_SVMH() st(PMMCTL0_H = 0xA5; SVSMHCTL &= ~SVMHE; PMMCTL0_H = 0x00;)
#define ENABLE_SVSL_SVML() st(PMMCTL0_H = 0xA5; SVSMLCTL |= (SVSLE + SVMLE); PMMCTL0_H = 0x00;)
#define DISABLE_SVSL_SVML() st(PMMCTL0_H = 0xA5; SVSMLCTL &= ~(SVSLE + SVMLE); PMMCTL0_H = 0x00;)
#define ENABLE_SVSH_SVMH() st(PMMCTL0_H = 0xA5; SVSMHCTL |= (SVSHE + SVMHE); PMMCTL0_H = 0x00;)
#define DISABLE_SVSH_SVMH() st(PMMCTL0_H = 0xA5; SVSMHCTL &= ~(SVSHE + SVMHE); PMMCTL0_H = 0x00;)
#define ENABLE_SVSL_RESET() st(PMMCTL0_H = 0xA5; PMMRIE |= SVSLPE; PMMCTL0_H = 0x00;)
#define DISABLE_SVSL_RESET() st(PMMCTL0_H = 0xA5; PMMRIE &= ~SVSLPE; PMMCTL0_H = 0x00;)
#define ENABLE_SVML_INTERRUPT() st(PMMCTL0_H = 0xA5; PMMRIE |= SVMLIE; PMMCTL0_H = 0x00;)
#define DISABLE_SVML_INTERRUPT() st(PMMCTL0_H = 0xA5; PMMRIE &= ~SVMLIE; PMMCTL0_H = 0x00;)
#define ENABLE_SVSH_RESET() st(PMMCTL0_H = 0xA5; PMMRIE |= SVSHPE; PMMCTL0_H = 0x00;)
#define DISABLE_SVSH_RESET() st(PMMCTL0_H = 0xA5; PMMRIE &= ~SVSHPE; PMMCTL0_H = 0x00;)
#define ENABLE_SVMH_INTERRUPT() st(PMMCTL0_H = 0xA5; PMMRIE |= SVMHIE; PMMCTL0_H = 0x00;)
#define DISABLE_SVMH_INTERRUPT() st(PMMCTL0_H = 0xA5; PMMRIE &= ~SVMHIE; PMMCTL0_H = 0x00;)
#define CLEAR_PMM_IFGS() st(PMMCTL0_H = 0xA5; PMMIFG = 0; PMMCTL0_H = 0x00;)
// These settings use SVSH/LACE = 0
#define SVSL_ENABLED_IN_LPM_FAST_WAKE() st(PMMCTL0_H = 0xA5; SVSMLCTL |= (SVSLFP+SVSLMD); SVSMLCTL &= ~SVSMLACE; PMMCTL0_H = 0x00;)
#define SVSL_ENABLED_IN_LPM_SLOW_WAKE() st(PMMCTL0_H = 0xA5; SVSMLCTL |= SVSLMD; SVSMLCTL &= ~(SVSLFP+SVSMLACE); PMMCTL0_H = 0x00;)
#define SVSL_DISABLED_IN_LPM_FAST_WAKE() st(PMMCTL0_H = 0xA5; SVSMLCTL |= SVSLFP; SVSMLCTL &= ~(SVSLMD+SVSMLACE); PMMCTL0_H = 0x00;)
#define SVSL_DISABLED_IN_LPM_SLOW_WAKE() st(PMMCTL0_H = 0xA5; SVSMLCTL &= ~(SVSLFP+SVSMLACE+SVSLMD); PMMCTL0_H = 0x00;)
#define SVSH_ENABLED_IN_LPM_NORM_PERF() st(PMMCTL0_H = 0xA5; SVSMHCTL |= SVSHMD; SVSMHCTL &= ~(SVSMHACE+SVSHFP); PMMCTL0_H = 0x00;)
#define SVSH_ENABLED_IN_LPM_FULL_PERF() st(PMMCTL0_H = 0xA5; SVSMHCTL |= (SVSHMD+SVSHFP); SVSMHCTL &= ~SVSMHACE; PMMCTL0_H = 0x00;)
#define SVSH_DISABLED_IN_LPM_NORM_PERF() st(PMMCTL0_H = 0xA5; SVSMHCTL &= ~(SVSMHACE+SVSHFP+SVSHMD);PMMCTL0_H = 0x00;)
#define SVSH_DISABLED_IN_LPM_FULL_PERF() st(PMMCTL0_H = 0xA5; SVSMHCTL |= SVSHFP; SVSMHCTL &= ~(SVSMHACE+SVSHMD); PMMCTL0_H = 0x00;)
// These setting use SVSH/LACE = 1
#define SVSL_OPTIMIZED_IN_LPM_FAST_WAKE() st(PMMCTL0_H = 0xA5; SVSMLCTL |= (SVSLFP+SVSLMD+SVSMLACE); PMMCTL0_H = 0x00;)
#define SVSH_OPTIMIZED_IN_LPM_FULL_PERF() st(PMMCTL0_H = 0xA5; SVSMHCTL |= (SVSHMD+SVSHFP+SVSMHACE); PMMCTL0_H = 0x00;)
/*******************************************************************************
* Defines
******************************************************************************/
#define PMM_STATUS_OK 0
#define PMM_STATUS_ERROR 1
/*******************************************************************************
* \brief Set Vcore to expected level
*
* \param level Level to which Vcore needs to be increased/decreased
* \return status Success/failure
******************************************************************************/
extern unsigned int SetVCore(unsigned char level);
#endif /* HAL_PMM_H */

View file

@ -0,0 +1,158 @@
/*******************************************************************************
*
* HAL_TLV.c
* Provides Functions to Read the TLV Data Section of the MSP430 Devices
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Updated: Version 2.0 01/17/2011
*
******************************************************************************/
#include "msp430.h"
#include "HAL_TLV.h"
void Get_TLV_Info(unsigned char tag, unsigned char instance, unsigned char *length, unsigned int **data_address)
{
char *TLV_address = (char *)TLV_START; // TLV Structure Start Address
while((TLV_address < (char *)TLV_END)
&& ((*TLV_address != tag) || instance) // check for tag and instance
&& (*TLV_address != TLV_TAGEND)) // do range check first
{
if (*TLV_address == tag) instance--; // repeat till requested instance is reached
TLV_address += *(TLV_address + 1) + 2; // add (Current TAG address + LENGTH) + 2
}
if (*TLV_address == tag) // Check if Tag match happened..
{
*length = *(TLV_address + 1); // Return length = Address + 1
*data_address = (unsigned int *)(TLV_address + 2); // Return address of first data/value info = Address + 2
}
else // If there was no tag match and the end of TLV structure was reached..
{
*length = 0; // Return 0 for TAG not found
*data_address = 0; // Return 0 for TAG not found
}
}
unsigned int Get_Device_Type(void)
{
unsigned int *pDeviceType = (unsigned int *)DEVICE_ID_0;
return pDeviceType[0]; // Return Value from TLV Table
}
unsigned int Get_TLV_Memory(unsigned char instance)
{
unsigned char *pPDTAG;
unsigned char bPDTAG_bytes;
unsigned int count;
instance *= 2; // set tag for word access comparison
// TLV access Function Call
Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&pPDTAG); // Get Peripheral data pointer
for (count = 0;count <= instance; count += 2)
{
if (pPDTAG[count] == 0) return 0; // Return 0 if end reached
if (count == instance) return (pPDTAG[count] | pPDTAG[count+1]<<8);
}
return 0; // Return 0: not found
}
unsigned int Get_TLV_Peripheral(unsigned char tag, unsigned char instance)
{
unsigned char *pPDTAG;
unsigned char bPDTAG_bytes;
unsigned int count = 0;
unsigned int pcount = 0;
Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&pPDTAG); // Get Peripheral data pointer
// read memory configuration from TLV to get offset for Peripherals
while (Get_TLV_Memory(count)) {
count++;
}
pcount = pPDTAG[count * 2 + 1]; // get number of Peripheral entries
count++; // inc count to first Periperal
pPDTAG += count*2; // adjust point to first address of Peripheral
count = 0; // set counter back to 0
pcount *= 2; // align pcount for work comparision
// TLV access Function Call
for (count = 0; count <= pcount; count += 2) {
if (pPDTAG[count+1] == tag) { // test if required Peripheral is found
if (instance > 0) { // test if required instance is found
instance--;
}
else {
return (pPDTAG[count] | pPDTAG[count + 1] << 8); // Return found data
}
}
}
return 0; // Return 0: not found
}
unsigned char Get_TLV_Interrupt(unsigned char tag)
{
unsigned char *pPDTAG;
unsigned char bPDTAG_bytes;
unsigned int count = 0;
unsigned int pcount = 0;
Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&pPDTAG); // Get Peripheral data pointer
// read memory configuration from TLV to get offset for Peripherals
while (Get_TLV_Memory(count))
{
count++;
}
pcount = pPDTAG[count * 2 + 1];
count++; // inc count to first Periperal
pPDTAG += (pcount + count) * 2; // adjust point to first address of Peripheral
count = 0; // set counter back to 0
// TLV access Function Call
for (count = 0; count <= tag; count += 2)
{
if (pPDTAG[count] == 0) return 0; // Return 0: not found/end of table
if (count == tag) return (pPDTAG[count]); // Return found data
}
return 0; // Return 0: not found
}

View file

@ -0,0 +1,226 @@
/*******************************************************************************
*
* HAL_TLV.c
* Provides Functions to Read the TLV Data Section of the MSP430 Devices
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Updated: Version 2.0 01/17/2011
*
******************************************************************************/
#ifndef HAL_TLV_H
#define HAL_TLV_H
/*******************************************************************************
* Device Descriptors - Fixed Memory Locations
******************************************************************************/
#define DEVICE_ID_0 (0x1A04)
#define DEVICE_ID_1 (0x1A05)
/*******************************************************************************
* Data Types
******************************************************************************/
struct s_TLV_Die_Record {
unsigned char die_record[10];
};
struct s_TLV_ADC_Cal_Data {
unsigned int adc_gain_factor;
unsigned int adc_offset;
unsigned int adc_ref15_30_temp;
unsigned int adc_ref15_85_temp;
unsigned int adc_ref20_30_temp;
unsigned int adc_ref20_85_temp;
unsigned int adc_ref25_30_temp;
unsigned int adc_ref25_85_temp;
};
struct s_TLV_Timer_D_Cal_Data {
unsigned int TDH0CTL1_64;
unsigned int TDH0CTL1_128;
unsigned int TDH0CTL1_200;
unsigned int TDH0CTL1_256;
};
struct s_TLV_REF_Cal_Data {
unsigned int ref_ref15;
unsigned int ref_ref20;
unsigned int adc_ref25;
};
/*******************************************************************************
* Tag Defines
******************************************************************************/
#define TLV_LDTAG (0x01) /* Legacy descriptor (1xx, 2xx,
4xx families) */
#define TLV_PDTAG (0x02) /* Peripheral discovery descriptor */
#define TLV_Reserved3 (0x03) /* Future usage */
#define TLV_Reserved4 (0x04) /* Future usage */
#define TLV_BLANK (0x05) /* Blank descriptor */
#define TLV_Reserved6 (0x06) /* Future usage */
#define TLV_Reserved7 (0x07) /* Serial Number */
#define TLV_DIERECORD (0x08) /* Die Record */
#define TLV_ADCCAL (0x11) /* ADC12 calibration */
#define TLV_ADC12CAL (0x11) /* ADC12 calibration */
#define TLV_ADC10CAL (0x13) /* ADC10 calibration */
#define TLV_REFCAL (0x12) /* REF calibration */
#define TLV_TIMER_D_CAL (0x15) /* Timer_Dx calibration */
#define TLV_TAGEXT (0xFE) /* Tag extender */
#define TLV_TAGEND (0xFF) /* Tag End of Table */
/*******************************************************************************
* Peripheral Defines
******************************************************************************/
#define TLV_PID_NO_MODULE (0x00) /* No Module */
#define TLV_PID_PORTMAPPING (0x10) /* Port Mapping */
#define TLV_PID_MSP430CPUXV2 (0x23) /* MSP430CPUXV2 */
#define TLV_PID_JTAG (0x09) /* JTAG */
#define TLV_PID_SBW (0x0F) /* SBW */
#define TLV_PID_EEM_XS (0x02) /* EEM X-Small */
#define TLV_PID_EEM_S (0x03) /* EEM Small */
#define TLV_PID_EEM_M (0x04) /* EEM Medium */
#define TLV_PID_EEM_L (0x05) /* EEM Large */
#define TLV_PID_PMM (0x30) /* PMM */
#define TLV_PID_PMM_FR (0x32) /* PMM FRAM */
#define TLV_PID_FCTL (0x39) /* Flash */
#define TLV_PID_CRC16 (0x3C) /* CRC16 */
#define TLV_PID_CRC16_RB (0x3D) /* CRC16 Reverse */
#define TLV_PID_WDT_A (0x40) /* WDT_A */
#define TLV_PID_SFR (0x41) /* SFR */
#define TLV_PID_SYS (0x42) /* SYS */
#define TLV_PID_RAMCTL (0x44) /* RAMCTL */
#define TLV_PID_DMA_1 (0x46) /* DMA 1 */
#define TLV_PID_DMA_3 (0x47) /* DMA 3 */
#define TLV_PID_UCS (0x48) /* UCS */
#define TLV_PID_DMA_6 (0x4A) /* DMA 6 */
#define TLV_PID_DMA_2 (0x4B) /* DMA 2 */
#define TLV_PID_PORT1_2 (0x51) /* Port 1 + 2 / A */
#define TLV_PID_PORT3_4 (0x52) /* Port 3 + 4 / B */
#define TLV_PID_PORT5_6 (0x53) /* Port 5 + 6 / C */
#define TLV_PID_PORT7_8 (0x54) /* Port 7 + 8 / D */
#define TLV_PID_PORT9_10 (0x55) /* Port 9 + 10 / E */
#define TLV_PID_PORT11_12 (0x56) /* Port 11 + 12 / F */
#define TLV_PID_PORTU (0x5E) /* Port U */
#define TLV_PID_PORTJ (0x5F) /* Port J */
#define TLV_PID_TA2 (0x60) /* Timer A2 */
#define TLV_PID_TA3 (0x61) /* Timer A1 */
#define TLV_PID_TA5 (0x62) /* Timer A5 */
#define TLV_PID_TA7 (0x63) /* Timer A7 */
#define TLV_PID_TB3 (0x65) /* Timer B3 */
#define TLV_PID_TB5 (0x66) /* Timer B5 */
#define TLV_PID_TB7 (0x67) /* Timer B7 */
#define TLV_PID_RTC (0x68) /* RTC */
#define TLV_PID_BT_RTC (0x69) /* BT + RTC */
#define TLV_PID_BBS (0x6A) /* Battery Backup Switch */
#define TLV_PID_RTC_B (0x6B) /* RTC_B */
#define TLV_PID_TD2 (0x6C) /* Timer D2 */
#define TLV_PID_TD3 (0x6D) /* Timer D1 */
#define TLV_PID_TD5 (0x6E) /* Timer D5 */
#define TLV_PID_TD7 (0x6F) /* Timer D7 */
#define TLV_PID_TEC (0x70) /* Imer Event Control */
#define TLV_PID_RTC_C (0x71) /* RTC_C */
#define TLV_PID_AES (0x80) /* AES */
#define TLV_PID_MPY16 (0x84) /* MPY16 */
#define TLV_PID_MPY32 (0x85) /* MPY32 */
#define TLV_PID_MPU (0x86) /* MPU */
#define TLV_PID_USCI_AB (0x90) /* USCI_AB */
#define TLV_PID_USCI_A (0x91) /* USCI_A */
#define TLV_PID_USCI_B (0x92) /* USCI_B */
#define TLV_PID_EUSCI_A (0x94) /* eUSCI_A */
#define TLV_PID_EUSCI_B (0x95) /* eUSCI_B */
#define TLV_PID_REF (0xA0) /* Shared Reference */
#define TLV_PID_COMP_B (0xA8) /* COMP_B */
#define TLV_PID_COMP_D (0xA9) /* COMP_D */
#define TLV_PID_USB (0x98) /* USB */
#define TLV_PID_LCD_B (0xB1) /* LCD_B */
#define TLV_PID_LCD_C (0xB2) /* LCD_C */
#define TLV_PID_DAC12_A (0xC0) /* DAC12_A */
#define TLV_PID_SD16_B_1 (0xC8) /* SD16_B 1 Channel */
#define TLV_PID_SD16_B_2 (0xC9) /* SD16_B 2 Channel */
#define TLV_PID_SD16_B_3 (0xCA) /* SD16_B 3 Channel */
#define TLV_PID_SD16_B_4 (0xCB) /* SD16_B 4 Channel */
#define TLV_PID_SD16_B_5 (0xCC) /* SD16_B 5 Channel */
#define TLV_PID_SD16_B_6 (0xCD) /* SD16_B 6 Channel */
#define TLV_PID_SD16_B_7 (0xCE) /* SD16_B 7 Channel */
#define TLV_PID_SD16_B_8 (0xCF) /* SD16_B 8 Channel */
#define TLV_PID_ADC12_A (0xD1) /* ADC12_A */
#define TLV_PID_ADC10_A (0xD3) /* ADC10_A */
#define TLV_PID_ADC10_B (0xD4) /* ADC10_B */
#define TLV_PID_SD16_A (0xD8) /* SD16_A */
#define TLV_PID_TI_BSL (0xFC) /* BSL */
/*******************************************************************************
* \brief Get Information out of the TLV Table
*
* \param tag Tag of the TLV entry
* \param instance Instance of the Tag of the TLV entry
* \param *length return: Length of the information if found
* \param **data_address return: start pointer of Data
******************************************************************************/
void Get_TLV_Info(unsigned char tag, unsigned char instance, unsigned char *length,
unsigned int **data_address);
/*******************************************************************************
* \brief Get Device Type out of the TLV Table
*
* \return Device dependent value
******************************************************************************/
unsigned int Get_Device_Type(void);
/*******************************************************************************
* \brief Get Memory Info out of the TLV Table
*
* \param instance Index of the Instance [0..]
* \return Memory Data found
******************************************************************************/
unsigned int Get_TLV_Memory(unsigned char instance);
/*******************************************************************************
* \brief Get Peripheral Info out of the TLV Table
*
* \param tag Tag of the TLV entry
* \param instance Index of the Instance [0..]
* \return Peripheral Data found
******************************************************************************/
unsigned int Get_TLV_Peripheral(unsigned char tag, unsigned char instance);
/*******************************************************************************
* \brief Get Interrupt Info out of the TLV Table
*
* \param tag Tag of the TLV entry
* \return Interrupt Data found
******************************************************************************/
unsigned char Get_TLV_Interrupt(unsigned char tag);
#endif /* HAL_TLV_H */

View file

@ -0,0 +1,340 @@
/*******************************************************************************
*
* HAL_UCS.c
* Provides Functions to Initialize the UCS/FLL and clock sources
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 12/15/2010
* Added Functions: XT2_Stop() and XT1_Stop()
* Modified all functions to preserve drive settings
*
******************************************************************************/
#include "msp430.h"
#include "HAL_UCS.h"
// #include "hal_calibration.h"
/*******************************************************************************
* Check and define required Defines
******************************************************************************/
#ifndef XT1LFOFFG // Defines if not available in header file
#define XT1LFOFFG 0
#endif
#ifndef XT1HFOFFG // Defines if not available in header file
#define XT1HFOFFG 0
#endif
#ifndef XT2OFFG // Defines if not available in header file
#define XT2OFFG 0
#endif
#ifndef XTS // Defines if not available in header file
#define XTS 0
#endif
#ifndef XT2DRIVE_3 // Defines if not available in header file
#define XT2DRIVE_3 0
#endif
/*******************************************************************************
* \brief Initializes FLL of the UCS
*
* \param fsystem Required system frequency (MCLK) in kHz
* \param ratio Ratio between fsystem and FLLREFCLK
******************************************************************************/
static void Init_FLL(unsigned int fsystem, unsigned int ratio);
#if 0
void LFXT_Start(unsigned int xtdrive)
{
// If the drive setting is not already set to maximum
// Set it to max for LFXT startup
if ((UCSCTL6 & XT1DRIVE_3)!= XT1DRIVE_3) {
UCSCTL6_L |= XT1DRIVE1_L + XT1DRIVE0_L; // Highest drive setting for XT1startup
}
while (SFRIFG1 & OFIFG) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags fault flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
UCSCTL6 = (UCSCTL6 & ~(XT1DRIVE_3)) | (xtdrive); // set requested Drive mode
}
#endif
unsigned int LFXT_Start_Timeout(unsigned int xtdrive, unsigned int timeout)
{
// add in capacitor setting
//SetOscillatorCapacitorValues();
// If the drive setting is not already set to maximum
// Set it to max for LFXT startup
if ((UCSCTL6 & XT1DRIVE_3)!= XT1DRIVE_3) {
UCSCTL6_L |= XT1DRIVE1_L+XT1DRIVE0_L; // Highest drive setting for XT1startup
}
while ((SFRIFG1 & OFIFG) && timeout--){ // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags fault flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
UCSCTL6 = (UCSCTL6 & ~(XT1DRIVE_3)) |(xtdrive); // set Drive mode
// add in capacitor setting
//SetOscillatorCapacitorValues();
if (timeout)
return (UCS_STATUS_OK);
else
return (UCS_STATUS_ERROR);
}
#if 0
void XT1_Start(unsigned int xtdrive)
{
// Check if drive value is the expected one
if ((UCSCTL6 & XT1DRIVE_3) != xtdrive) {
UCSCTL6 &= ~XT1DRIVE_3; // Clear XT1drive field
UCSCTL6 |= xtdrive; // Set requested value
}
UCSCTL6 &= ~XT1OFF; // Enable XT1
UCSCTL6 |= XTS; // Enable HF mode
while (SFRIFG1 & OFIFG) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
}
unsigned int XT1_Start_Timeout(unsigned int xtdrive, unsigned int timeout)
{
// Check if drive value is the expected one
if ((UCSCTL6 & XT1DRIVE_3) != xtdrive) {
UCSCTL6 &= ~XT1DRIVE_3; // Clear XT1drive field
UCSCTL6 |= xtdrive; // Set requested value
}
UCSCTL6 &= ~XT1OFF; // Enable XT1
UCSCTL6 |= XTS; // Enable HF mode
while ((SFRIFG1 & OFIFG) && timeout--) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
if (timeout) {
return UCS_STATUS_OK;
}
else {
return UCS_STATUS_ERROR;
}
}
void XT1_Bypass(void)
{
UCSCTL6 |= XT1BYPASS;
while (SFRIFG1 & OFIFG) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
}
#endif
void XT1_Stop(void)
{
UCSCTL6 |= XT1OFF; // Switch off XT1 oscillator
}
#if 0
void XT2_Start(unsigned int xtdrive)
{
// Check if drive value is the expected one
if ((UCSCTL6 & XT2DRIVE_3) != xtdrive) {
UCSCTL6 &= ~XT2DRIVE_3; // Clear XT2drive field
UCSCTL6 |= xtdrive; // Set requested value
}
UCSCTL6 &= ~XT2OFF;
while (SFRIFG1 & OFIFG) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
}
unsigned int XT2_Start_Timeout(unsigned int xtdrive, unsigned int timeout)
{
// Check if drive value is the expected one
if ((UCSCTL6 & XT2DRIVE_3) != xtdrive) {
UCSCTL6 &= ~XT2DRIVE_3; // Clear XT2drive field
UCSCTL6 |= xtdrive; // Set requested value
}
UCSCTL6 &= ~XT2OFF;
while ((SFRIFG1 & OFIFG) && timeout--) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
if (timeout) {
return UCS_STATUS_OK;
}
else {
return UCS_STATUS_ERROR;
}
}
void XT2_Bypass(void)
{
#ifdef XT2BYPASS // On devices without XT2 this function will be empty
UCSCTL6 |= XT2BYPASS;
while (SFRIFG1 & OFIFG) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
#endif
}
void XT2_Stop(void)
{
UCSCTL6 |= XT2OFF; // Switch off XT2 oscillator
}
#endif
void Init_FLL_Settle(unsigned int fsystem, unsigned int ratio)
{
volatile unsigned int x;
// x = ratio * 32;
x = ratio << 5;
Init_FLL(fsystem, ratio);
/* from changes in Init_FLL we know that fll is now enabled */
while (x--) {
__delay_cycles(30);
}
}
static void Init_FLL(unsigned int fsystem, unsigned int ratio)
{
unsigned int d, dco_div_bits;
unsigned int mode;
#if 0
unsigned int srRegisterState;
#endif
mode = 0;
/* we only run this at startup and we want the fll enabled on exit */
#if 0
// Save actual state of FLL loop control, then disable it. This is needed to
// prevent the FLL from acting as we are making fundamental modifications to
// the clock setup.
srRegisterState = __get_SR_register() & SCG0;
#endif
d = ratio;
dco_div_bits = FLLD__2; // Have at least a divider of 2
if (fsystem > 16000) {
d >>= 1 ;
mode = 1;
}
else {
fsystem <<= 1; // fsystem = fsystem * 2
}
while (d > 512) {
dco_div_bits = dco_div_bits + FLLD0; // Set next higher div level
d >>= 1;
}
// Disable FLL
__bis_SR_register(SCG0);
UCSCTL0 = 0x0000; // Set DCO to lowest Tap
UCSCTL2 &= ~(0x03FF); // Reset FN bits
UCSCTL2 = dco_div_bits | (d - 1);
if (fsystem <= 630) // fsystem < 0.63MHz
UCSCTL1 = DCORSEL_0;
else if (fsystem < 1250) // 0.63MHz < fsystem < 1.25MHz
UCSCTL1 = DCORSEL_1;
else if (fsystem < 2500) // 1.25MHz < fsystem < 2.5MHz
UCSCTL1 = DCORSEL_2;
else if (fsystem < 5000) // 2.5MHz < fsystem < 5MHz
UCSCTL1 = DCORSEL_3;
else if (fsystem < 10000) // 5MHz < fsystem < 10MHz
UCSCTL1 = DCORSEL_4;
else if (fsystem < 20000) // 10MHz < fsystem < 20MHz
UCSCTL1 = DCORSEL_5;
else if (fsystem < 40000) // 20MHz < fsystem < 40MHz
UCSCTL1 = DCORSEL_6;
else
UCSCTL1 = DCORSEL_7;
// Re-enable FLL
__bic_SR_register(SCG0);
while (SFRIFG1 & OFIFG) { // Check OFIFG fault flag
UCSCTL7 &= ~(DCOFFG+XT1LFOFFG+XT1HFOFFG+XT2OFFG); // Clear OSC flaut Flags
SFRIFG1 &= ~OFIFG; // Clear OFIFG fault flag
}
/* Init fll is only run at startup - We want the fll enabled when
* this function is complete (so don't save a restore setting)
*/
#if 0
// Restore previous SCG0
__bis_SR_register(srRegisterState);
#endif
if (mode == 1) { // fsystem > 16000
SELECT_MCLK_SMCLK(SELM__DCOCLK + SELS__DCOCLK); // Select DCOCLK
}
else {
SELECT_MCLK_SMCLK(SELM__DCOCLKDIV + SELS__DCOCLKDIV); // Select DCODIVCLK
}
}

View file

@ -0,0 +1,7 @@
HAL_UCS.o: F5xx_F6xx_Core_Lib/HAL_UCS.c \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/msp430.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/msp430f5438a.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/iomacros.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/in430.h \
/opt/msp430/lib/gcc/msp430/4.7.0/../../../../msp430/include/intrinsics.h \
F5xx_F6xx_Core_Lib/HAL_UCS.h F5xx_F6xx_Core_Lib/HAL_MACROS.h

View file

@ -0,0 +1,163 @@
/*******************************************************************************
*
* HAL_UCS.h
* Provides Functions to Initialize the UCS/FLL and clock sources
*
*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Version 1.0 11/24/2009
* Updated: Version 2.0 12/15/2010
* Added Functions: XT2_Stop() and XT1_Stop()
*
******************************************************************************/
#ifndef HAL_UCS_H
#define HAL_UCS_H
#include "HAL_MACROS.h"
/*******************************************************************************
* Macros
******************************************************************************/
/* Select source for FLLREF e.g. SELECT_FLLREF(SELREF__XT1CLK) */
#define SELECT_FLLREF(source) st(UCSCTL3 = (UCSCTL3 & ~(SELREF_7)) | (source);)
/* Select source for ACLK e.g. SELECT_ACLK(SELA__XT1CLK) */
#define SELECT_ACLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (source);)
/* Select source for MCLK e.g. SELECT_MCLK(SELM__XT2CLK) */
#define SELECT_MCLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELM_7)) | (source);)
/* Select source for SMCLK e.g. SELECT_SMCLK(SELS__XT2CLK) */
#define SELECT_SMCLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELS_7)) | (source);)
/* Select source for MCLK and SMCLK e.g. SELECT_MCLK_SMCLK(SELM__DCOCLK + SELS__DCOCLK) */
#define SELECT_MCLK_SMCLK(sources) st(UCSCTL4 = (UCSCTL4 & ~(SELM_7 + SELS_7)) | (sources);)
/* set ACLK/x */
#define ACLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVA_7)) | (DIVA__##x);)
/* set MCLK/x */
#define MCLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVM_7)) | (DIVM__##x);)
/* set SMCLK/x */
#define SMCLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVS_7)) | (DIVS__##x);)
/* Select divider for FLLREF e.g. SELECT_FLLREFDIV(2) */
#define SELECT_FLLREFDIV(x) st(UCSCTL3 = (UCSCTL3 & ~(FLLREFDIV_7))|(FLLREFDIV__##x);)
/*******************************************************************************
* Defines
******************************************************************************/
#define UCS_STATUS_OK 0
#define UCS_STATUS_ERROR 1
#if 0
/*******************************************************************************
* \brief Startup routine for 32kHz Crystal on LFXT1
*
* \param xtdrive Bits defining the LFXT drive mode after startup
******************************************************************************/
extern void LFXT_Start(unsigned int xtdrive);
#endif
/*******************************************************************************
* \brief Startup routine for 32kHz Crystal on LFXT1 with timeout counter
*
* \param xtdrive Bits defining the LFXT drive mode after startup
* \param timeout Value for the timeout counter
******************************************************************************/
extern unsigned int LFXT_Start_Timeout(unsigned int xtdrive, unsigned int timeout);
#if 0
/*******************************************************************************
* \brief Startup routine for XT1
*
* \param xtdrive Bits defining the XT drive mode
******************************************************************************/
extern void XT1_Start(unsigned int xtdrive);
/*******************************************************************************
* \brief Startup routine for XT1 with timeout counter
*
* \param xtdrive Bits defining the XT drive mode
* \param timeout Value for the timeout counter
******************************************************************************/
extern unsigned int XT1_Start_Timeout(unsigned int xtdrive, unsigned int timeout);
/*******************************************************************************
* \brief Use XT1 in Bypasss mode
******************************************************************************/
extern void XT1_Bypass(void);
#endif
/*******************************************************************************
* \brief Stop XT1 oscillator
******************************************************************************/
extern void XT1_Stop(void);
#if 0
/*******************************************************************************
* \brief Startup routine for XT2
*
* \param xtdrive Bits defining the XT drive mode
******************************************************************************/
extern void XT2_Start(unsigned int xtdrive);
/*******************************************************************************
* \brief Startup routine for XT2 with timeout counter
*
* \param xtdrive Bits defining the XT drive mode
* \param timeout Value for the timeout counter
******************************************************************************/
extern unsigned int XT2_Start_Timeout(unsigned int xtdrive, unsigned int timeout);
/*******************************************************************************
* \brief Use XT2 in Bypasss mode for MCLK
******************************************************************************/
extern void XT2_Bypass(void);
/*******************************************************************************
* \brief Stop XT2 oscillator
******************************************************************************/
extern void XT2_Stop(void);
#endif
/*******************************************************************************
* \brief Initializes FLL of the UCS and wait till settled before allowing
* code execution to resume. The use of this function is preferred
* over the use of Init_FLL().
*
* \param fsystem Required system frequency (MCLK) in kHz
* \param ratio Ratio between fsystem and FLLREFCLK
******************************************************************************/
extern void Init_FLL_Settle(unsigned int fsystem, unsigned int ratio);
#endif /* HAL_UCS_H */