TI didn't make getting their Driverlib.h very easy...

This commit is contained in:
William Miceli
2021-02-15 21:50:28 -05:00
parent ef74b58b8a
commit 281edcc924
4071 changed files with 1560990 additions and 30 deletions

View File

@@ -13,4 +13,5 @@
<createSlaveProjects value=""/>
<templateProperties value="id=com.ti.common.project.core.emptyProjectWithMainTemplate_msp430"/>
<filesToOpen value="main.c"/>
<isTargetManual value="false"/>
</projectOptions>

View File

@@ -27,65 +27,65 @@
<listOptionValue builtIn="false" value="PRODUCTS="/>
<listOptionValue builtIn="false" value="PRODUCT_MACRO_IMPORTS={}"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.678917450" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="20.2.2.LTS" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.678917450" name="Compiler version" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="20.2.2.LTS" valueType="string"/>
<targetPlatform id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.targetPlatformDebug.1686604176" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.targetPlatformDebug"/>
<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.builderDebug.1035113199" name="GNU Make.Debug" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.builderDebug"/>
<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.builderDebug.1035113199" keepEnvironmentInBuildfile="false" name="GNU Make" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.builderDebug"/>
<tool id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.compilerDebug.451721089" name="MSP430 Compiler" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.compilerDebug">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEFINE.1034999629" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEFINE" valueType="definedSymbols">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEFINE.1034999629" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEFINE" valueType="definedSymbols">
<listOptionValue builtIn="false" value="__MSP430F5438A__"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DATA_MODEL.1982319007" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DATA_MODEL" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DATA_MODEL.restricted" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.USE_HW_MPY.839697334" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.USE_HW_MPY" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.USE_HW_MPY.F5" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU21.1498371215" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU21" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU22.1347764874" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU22" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU23.223698529" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU23" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU40.868186196" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU40" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_VERSION.168969666" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_VERSION.mspx" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.PRINTF_SUPPORT.1230388639" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.PRINTF_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.PRINTF_SUPPORT.minimal" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEBUGGING_MODEL.1140512912" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEBUGGING_MODEL" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEBUGGING_MODEL.SYMDEBUG__DWARF" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WARNING.1406726001" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DATA_MODEL.1982319007" name="Specify the data memory model. (--data_model)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DATA_MODEL" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DATA_MODEL.restricted" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.USE_HW_MPY.839697334" name="Inline hardware multiply version of RTS mpy routine (--use_hw_mpy)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.USE_HW_MPY" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.USE_HW_MPY.F5" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU21.1498371215" name="Workaround specified silicon errata (--silicon_errata) [CPU21]" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU21" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU22.1347764874" name="Workaround specified silicon errata (--silicon_errata) [CPU22]" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU22" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU23.223698529" name="Workaround specified silicon errata (--silicon_errata) [CPU23]" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU23" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU40.868186196" name="Workaround specified silicon errata (--silicon_errata) [CPU40]" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_ERRATA.CPU40" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_VERSION.168969666" name="Silicon version (--silicon_version, -v)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.SILICON_VERSION.mspx" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.PRINTF_SUPPORT.1230388639" name="Level of printf/scanf support required (--printf_support)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.PRINTF_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.PRINTF_SUPPORT.minimal" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEBUGGING_MODEL.1140512912" name="Debugging model" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEBUGGING_MODEL" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DEBUGGING_MODEL.SYMDEBUG__DWARF" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WARNING.1406726001" name="Treat diagnostic &lt;id&gt; as warning (--diag_warning, -pdsw)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
<listOptionValue builtIn="false" value="225"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DISPLAY_ERROR_NUMBER.639983600" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WRAP.673457726" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.INCLUDE_PATH.998084769" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.INCLUDE_PATH" valueType="includePath">
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DISPLAY_ERROR_NUMBER.639983600" name="Emit diagnostic identifier numbers (--display_error_number, -pden)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WRAP.673457726" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.INCLUDE_PATH.998084769" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.INCLUDE_PATH" valueType="includePath">
<listOptionValue builtIn="false" value="${CCS_BASE_ROOT}/msp430/include"/>
<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.ADVICE__POWER.281919587" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.ADVICE__POWER" useByScannerDiscovery="false" value="all" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.ADVICE__POWER.281919587" name="Enable checking of ULP power rules (--advice:power)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compilerID.ADVICE__POWER" useByScannerDiscovery="false" value="all" valueType="string"/>
<inputType id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__C_SRCS.649948500" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__C_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__CPP_SRCS.1922478661" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__CPP_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__ASM_SRCS.257483495" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__ASM_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__ASM2_SRCS.1060828934" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.compiler.inputType__ASM2_SRCS"/>
</tool>
<tool id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.linkerDebug.1895650803" name="MSP430 Linker" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exe.linkerDebug">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.LIBRARY.1968433009" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.LIBRARY" useByScannerDiscovery="false" valueType="libs">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.LIBRARY.1968433009" name="Include library file or command file as input (--library, -l)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.LIBRARY" useByScannerDiscovery="false" valueType="libs">
<listOptionValue builtIn="false" value="libmath.a"/>
<listOptionValue builtIn="false" value="libc.a"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.SEARCH_PATH.1190398542" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.SEARCH_PATH" valueType="libPaths">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.SEARCH_PATH.1190398542" name="Add &lt;dir&gt; to library search path (--search_path, -i)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.SEARCH_PATH" valueType="libPaths">
<listOptionValue builtIn="false" value="${CCS_BASE_ROOT}/msp430/include"/>
<listOptionValue builtIn="false" value="${CCS_BASE_ROOT}/msp430/lib/5xx_6xx_FRxx"/>
<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/lib"/>
<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.USE_HW_MPY.764148548" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.USE_HW_MPY" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.USE_HW_MPY.F5" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.CINIT_HOLD_WDT.1490623933" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.CINIT_HOLD_WDT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.CINIT_HOLD_WDT.on" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.HEAP_SIZE.220900653" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.HEAP_SIZE" useByScannerDiscovery="false" value="160" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.STACK_SIZE.1680122353" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.STACK_SIZE" useByScannerDiscovery="false" value="160" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.OUTPUT_FILE.1830748118" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.OUTPUT_FILE" useByScannerDiscovery="false" value="${ProjName}.out" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.MAP_FILE.431232515" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.MAP_FILE" useByScannerDiscovery="false" value="${ProjName}.map" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.XML_LINK_INFO.404225481" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.XML_LINK_INFO" useByScannerDiscovery="false" value="${ProjName}_linkInfo.xml" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DISPLAY_ERROR_NUMBER.499077561" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DIAG_WRAP.1247294302" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.USE_HW_MPY.764148548" name="Deprecated: Now a compiler option instead of linker option (--use_hw_mpy)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.USE_HW_MPY" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.USE_HW_MPY.F5" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.CINIT_HOLD_WDT.1490623933" name="Hold watchdog timer during cinit auto-initialization (--cinit_hold_wdt)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.CINIT_HOLD_WDT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.CINIT_HOLD_WDT.on" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.HEAP_SIZE.220900653" name="Heap size for C/C++ dynamic memory allocation (--heap_size, -heap)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.HEAP_SIZE" useByScannerDiscovery="false" value="160" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.STACK_SIZE.1680122353" name="Set C system stack size (--stack_size, -stack)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.STACK_SIZE" useByScannerDiscovery="false" value="160" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.OUTPUT_FILE.1830748118" name="Specify output file name (--output_file, -o)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.OUTPUT_FILE" useByScannerDiscovery="false" value="${ProjName}.out" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.MAP_FILE.431232515" name="Link information (map) listed into &lt;file&gt; (--map_file, -m)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.MAP_FILE" useByScannerDiscovery="false" value="${ProjName}.map" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.XML_LINK_INFO.404225481" name="Detailed link information data-base into &lt;file&gt; (--xml_link_info, -xml_link_info)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.XML_LINK_INFO" useByScannerDiscovery="false" value="${ProjName}_linkInfo.xml" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DISPLAY_ERROR_NUMBER.499077561" name="Emit diagnostic identifier numbers (--display_error_number)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DIAG_WRAP.1247294302" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.MSP430_20.2.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
<inputType id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exeLinker.inputType__CMD_SRCS.1501370142" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exeLinker.inputType__CMD_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exeLinker.inputType__CMD2_SRCS.647611469" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exeLinker.inputType__CMD2_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exeLinker.inputType__GEN_CMDS.1250645545" name="Generated Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.exeLinker.inputType__GEN_CMDS"/>
</tool>
<tool id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.416580317" name="MSP430 Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex">
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.ROMWIDTH.1815441028" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.ROMWIDTH" useByScannerDiscovery="false" value="8" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.MEMWIDTH.89895246" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.MEMWIDTH" useByScannerDiscovery="false" value="8" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.ROMWIDTH.1815441028" name="Specify rom width (--romwidth, -romwidth=width)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.ROMWIDTH" useByScannerDiscovery="false" value="8" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.MEMWIDTH.89895246" name="Specify memory width (--memwidth, -memwidth=width)" superClass="com.ti.ccstudio.buildDefinitions.MSP430_20.2.hex.MEMWIDTH" useByScannerDiscovery="false" value="8" valueType="string"/>
</tool>
</toolChain>
</folderInfo>
@@ -190,4 +190,5 @@
<project id="SunseekerTelemetryAndLightingSystem.com.ti.ccstudio.buildDefinitions.MSP430.ProjectType.1491572593" name="MSP430" projectType="com.ti.ccstudio.buildDefinitions.MSP430.ProjectType"/>
</storageModule>
<storageModule moduleId="scannerConfiguration"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject>

View File

@@ -18,6 +18,7 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.rtsc.xdctools.buildDefinitions.XDC.xdcNature</nature>
<nature>com.ti.ccstudio.core.ccsNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>

View File

@@ -0,0 +1,4 @@
ccsVersionValidationPolicy=warning
compilerVersionValidationPolicy=flexible
eclipse.preferences.version=1
productVersionsValidationPolicy=flexible

View File

@@ -0,0 +1,210 @@
//*****************************************************************************
//
// adc10_a.c - Driver for the adc10_a Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup adc10_a_api adc10_a
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_ADC10_A__
#include "adc10_a.h"
#include <assert.h>
bool ADC10_A_init (uint16_t baseAddress,
uint16_t sampleHoldSignalSourceSelect,
uint8_t clockSourceSelect,
uint16_t clockSourceDivider)
{
bool retVal = STATUS_SUCCESS;
//Turn OFF ADC10_A Module & Clear Interrupt Registers
HWREG16(baseAddress + OFS_ADC10IFG) &= 0x0000; //Reset ALL interrupt flags
//Set ADC10_A Control 1
HWREG16(baseAddress + OFS_ADC10CTL1) =
sampleHoldSignalSourceSelect //Setup the Sample-and-Hold Source
+ (clockSourceDivider & ADC10DIV_7) //Set Clock Divider
+ clockSourceSelect; //Setup Clock Source
//Set ADC10_A Control 2
HWREG16(baseAddress + OFS_ADC10CTL2) =
(clockSourceDivider & (ADC10PDIV_1 | ADC10PDIV_2)) //Set Clock Pre-Divider
+ ADC10RES; //Default resolution to 10-bits
return ( retVal) ;
}
void ADC10_A_enable (uint16_t baseAddress)
{
//Reset the ADC10ON bit to enable the ADC10_A Module
HWREG16(baseAddress + OFS_ADC10CTL0) |= ADC10ON;
}
void ADC10_A_disable (uint16_t baseAddress)
{
//Set the ADC10ON bit to disable the ADC10_A Module
HWREG16(baseAddress + OFS_ADC10CTL0) &= ~ADC10ON;
}
void ADC10_A_setupSamplingTimer (uint16_t baseAddress,
uint16_t clockCycleHoldCount,
uint16_t multipleSamplesEnabled)
{
HWREG16(baseAddress + OFS_ADC10CTL1) |= ADC10SHP;
//Reset and Set CB Control 0 Bits
HWREG16(baseAddress + OFS_ADC10CTL0) &= ~(ADC10SHT_15 + ADC10MSC);
HWREG16(baseAddress + OFS_ADC10CTL0) |= clockCycleHoldCount
+ multipleSamplesEnabled;
}
void ADC10_A_disableSamplingTimer (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_ADC10CTL1) &= ~(ADC10SHP);
}
void ADC10_A_configureMemory (uint16_t baseAddress,
uint8_t inputSourceSelect,
uint8_t positiveRefVoltageSourceSelect,
uint8_t negativeRefVoltageSourceSelect)
{
//Make sure the ENC bit is cleared before configuring a Memory Buffer Control
assert( !(HWREG16(baseAddress + OFS_ADC10CTL0) & ADC10ENC) );
if(!(HWREG16(baseAddress + OFS_ADC10CTL0) & ADC10ENC))
{
assert(inputSourceSelect <= ADC10_A_INPUT_A15);
assert(positiveRefVoltageSourceSelect <= ADC10_A_VREFPOS_INT);
assert(negativeRefVoltageSourceSelect <= ADC10_A_VREFNEG_EXT);
//Reset and Set the Memory Buffer Control Bits
HWREG8(baseAddress + OFS_ADC10MCTL0) = inputSourceSelect
+ positiveRefVoltageSourceSelect +
negativeRefVoltageSourceSelect;
}
}
void ADC10_A_enableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
HWREG16(baseAddress + OFS_ADC10IE) |= interruptMask;
}
void ADC10_A_disableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
HWREG16(baseAddress + OFS_ADC10IE) &= ~(interruptMask);
}
void ADC10_A_clearInterrupt (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
HWREG16(baseAddress + OFS_ADC10IFG) &= ~(interruptFlagMask);
}
uint16_t ADC10_A_getInterruptStatus (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
return ( HWREG16(baseAddress + OFS_ADC10IFG) & interruptFlagMask );
}
void ADC10_A_startConversion (uint16_t baseAddress,
uint8_t conversionSequenceModeSelect)
{
//Reset the ENC bit to set the conversion mode sequence
HWREG16(baseAddress + OFS_ADC10CTL0) &= ~(ADC10ENC);
HWREG16(baseAddress + OFS_ADC10CTL1) |= conversionSequenceModeSelect;
HWREG16(baseAddress + OFS_ADC10CTL0) |= ADC10ENC + ADC10SC;
}
void ADC10_A_disableConversions (uint16_t baseAddress, bool preempt)
{
if (ADC10_A_PREEMPTCONVERSION == preempt){
HWREG16(baseAddress + OFS_ADC10CTL1) &= ~(ADC10CONSEQ_3);
//Reset conversion sequence mode to single-channel, single-conversion
} else if ( ~(HWREG16(baseAddress + OFS_ADC10CTL1) & ADC10CONSEQ_3) ){
//To prevent preemoption of a single-channel, single-conversion we must
//wait for the ADC core to finish the conversion.
while (HWREG16(baseAddress + OFS_ADC10CTL1) & ADC10BUSY) ;
}
HWREG16(baseAddress + OFS_ADC10CTL0) &= ~(ADC10ENC);
}
int16_t ADC10_A_getResults (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_ADC10MEM0) );
}
void ADC10_A_setResolution (uint16_t baseAddress,
uint8_t resolutionSelect)
{
HWREG16(baseAddress + OFS_ADC10CTL2) &= ~(ADC10RES);
HWREG16(baseAddress + OFS_ADC10CTL2) |= resolutionSelect;
}
void ADC10_A_setSampleHoldSignalInversion (uint16_t baseAddress,
uint16_t invertedSignal)
{
HWREG16(baseAddress + OFS_ADC10CTL1) &= ~(ADC10ISSH);
HWREG16(baseAddress + OFS_ADC10CTL1) |= invertedSignal;
}
void ADC10_A_setDataReadBackFormat (uint16_t baseAddress,
uint16_t readBackFormat)
{
HWREG16(baseAddress + OFS_ADC10CTL2) &= ~(ADC10DF);
HWREG16(baseAddress + OFS_ADC10CTL2) |= readBackFormat;
}
void ADC10_A_enableReferenceBurst (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_ADC10CTL2) |= ADC10REFBURST;
}
void ADC10_A_disableReferenceBurst (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_ADC10CTL2) &= ~(ADC10REFBURST);
}
void ADC10_A_setReferenceBufferSamplingRate (uint16_t baseAddress,
uint16_t samplingRateSelect)
{
HWREG16(baseAddress + OFS_ADC10CTL2) &= ~(ADC10SR);
HWREG16(baseAddress + OFS_ADC10CTL2) |= samplingRateSelect;
}
void ADC10_A_setWindowComp (uint16_t baseAddress,
uint16_t highThreshold,
uint16_t lowThreshold)
{
HWREG16(baseAddress + OFS_ADC10HI) = highThreshold;
HWREG16(baseAddress + OFS_ADC10LO) = lowThreshold;
}
uint32_t ADC10_A_getMemoryAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_ADC10MEM0 );
}
uint16_t ADC10_A_isBusy (uint16_t baseAddress)
{
return (HWREG16(baseAddress + OFS_ADC10CTL1) & ADC10BUSY);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for adc10_a_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,883 @@
//*****************************************************************************
//
// adc10_a.h - Driver for the ADC10_A Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_ADC10_A_H__
#define __MSP430WARE_ADC10_A_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_ADC10_A__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the clockSourceSelect
// parameter for functions: ADC10_A_init().
//
//*****************************************************************************
#define ADC10_A_CLOCKSOURCE_ADC10OSC (ADC10SSEL_0)
#define ADC10_A_CLOCKSOURCE_ACLK (ADC10SSEL_1)
#define ADC10_A_CLOCKSOURCE_MCLK (ADC10SSEL_2)
#define ADC10_A_CLOCKSOURCE_SMCLK (ADC10SSEL_3)
//*****************************************************************************
//
// The following are values that can be passed to the clockSourceDivider
// parameter for functions: ADC10_A_init().
//
//*****************************************************************************
#define ADC10_A_CLOCKDIVIDER_1 (ADC10DIV_0 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_2 (ADC10DIV_1 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_3 (ADC10DIV_2 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_4 (ADC10DIV_3 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_5 (ADC10DIV_4 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_6 (ADC10DIV_5 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_7 (ADC10DIV_6 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_8 (ADC10DIV_7 + ADC10PDIV_0)
#define ADC10_A_CLOCKDIVIDER_12 (ADC10DIV_2 + ADC10PDIV_1)
#define ADC10_A_CLOCKDIVIDER_16 (ADC10DIV_3 + ADC10PDIV_1)
#define ADC10_A_CLOCKDIVIDER_20 (ADC10DIV_4 + ADC10PDIV_1)
#define ADC10_A_CLOCKDIVIDER_24 (ADC10DIV_5 + ADC10PDIV_1)
#define ADC10_A_CLOCKDIVIDER_28 (ADC10DIV_6 + ADC10PDIV_1)
#define ADC10_A_CLOCKDIVIDER_32 (ADC10DIV_7 + ADC10PDIV_1)
#define ADC10_A_CLOCKDIVIDER_64 (ADC10DIV_0 + ADC10PDIV_2)
#define ADC10_A_CLOCKDIVIDER_128 (ADC10DIV_1 + ADC10PDIV_2)
#define ADC10_A_CLOCKDIVIDER_192 (ADC10DIV_2 + ADC10PDIV_2)
#define ADC10_A_CLOCKDIVIDER_256 (ADC10DIV_3 + ADC10PDIV_2)
#define ADC10_A_CLOCKDIVIDER_320 (ADC10DIV_4 + ADC10PDIV_2)
#define ADC10_A_CLOCKDIVIDER_384 (ADC10DIV_5 + ADC10PDIV_2)
#define ADC10_A_CLOCKDIVIDER_448 (ADC10DIV_6 + ADC10PDIV_2)
#define ADC10_A_CLOCKDIVIDER_512 (ADC10DIV_7 + ADC10PDIV_2)
//*****************************************************************************
//
// The following are values that can be passed to the
// sampleHoldSignalSourceSelect parameter for functions: ADC10_A_init().
//
//*****************************************************************************
#define ADC10_A_SAMPLEHOLDSOURCE_SC (ADC10SHS_0)
#define ADC10_A_SAMPLEHOLDSOURCE_1 (ADC10SHS_1)
#define ADC10_A_SAMPLEHOLDSOURCE_2 (ADC10SHS_2)
#define ADC10_A_SAMPLEHOLDSOURCE_3 (ADC10SHS_3)
//*****************************************************************************
//
// The following are values that can be passed to the multipleSamplesEnabled
// parameter for functions: ADC10_A_setupSamplingTimer().
//
//*****************************************************************************
#define ADC10_A_MULTIPLESAMPLESDISABLE (!(ADC10MSC))
#define ADC10_A_MULTIPLESAMPLESENABLE (ADC10MSC)
//*****************************************************************************
//
// The following are values that can be passed to the clockCycleHoldCount
// parameter for functions: ADC10_A_setupSamplingTimer().
//
//*****************************************************************************
#define ADC10_A_CYCLEHOLD_4_CYCLES (ADC10SHT_0)
#define ADC10_A_CYCLEHOLD_8_CYCLES (ADC10SHT_1)
#define ADC10_A_CYCLEHOLD_16_CYCLES (ADC10SHT_2)
#define ADC10_A_CYCLEHOLD_32_CYCLES (ADC10SHT_3)
#define ADC10_A_CYCLEHOLD_64_CYCLES (ADC10SHT_4)
#define ADC10_A_CYCLEHOLD_96_CYCLES (ADC10SHT_5)
#define ADC10_A_CYCLEHOLD_128_CYCLES (ADC10SHT_6)
#define ADC10_A_CYCLEHOLD_192_CYCLES (ADC10SHT_7)
#define ADC10_A_CYCLEHOLD_256_CYCLES (ADC10SHT_8)
#define ADC10_A_CYCLEHOLD_384_CYCLES (ADC10SHT_9)
#define ADC10_A_CYCLEHOLD_512_CYCLES (ADC10SHT_10)
#define ADC10_A_CYCLEHOLD_768_CYCLES (ADC10SHT_11)
#define ADC10_A_CYCLEHOLD_1024_CYCLES (ADC10SHT_12)
//*****************************************************************************
//
// The following are values that can be passed to the
// positiveRefVoltageSourceSelect parameter for functions:
// ADC10_A_configureMemory().
//
//*****************************************************************************
#define ADC10_A_VREFPOS_AVCC (!(ADC10SREF0 + ADC10SREF1))
#define ADC10_A_VREFPOS_EXT (ADC10SREF1)
#define ADC10_A_VREFPOS_INT (ADC10SREF0)
//*****************************************************************************
//
// The following are values that can be passed to the inputSourceSelect
// parameter for functions: ADC10_A_configureMemory().
//
//*****************************************************************************
#define ADC10_A_INPUT_A0 (ADC10INCH_0)
#define ADC10_A_INPUT_A1 (ADC10INCH_1)
#define ADC10_A_INPUT_A2 (ADC10INCH_2)
#define ADC10_A_INPUT_A3 (ADC10INCH_3)
#define ADC10_A_INPUT_A4 (ADC10INCH_4)
#define ADC10_A_INPUT_A5 (ADC10INCH_5)
#define ADC10_A_INPUT_A6 (ADC10INCH_6)
#define ADC10_A_INPUT_A7 (ADC10INCH_7)
#define ADC10_A_INPUT_A8 (ADC10INCH_8)
#define ADC10_A_INPUT_A9 (ADC10INCH_9)
#define ADC10_A_INPUT_TEMPSENSOR (ADC10INCH_10)
#define ADC10_A_INPUT_BATTERYMONITOR (ADC10INCH_11)
#define ADC10_A_INPUT_A12 (ADC10INCH_12)
#define ADC10_A_INPUT_A13 (ADC10INCH_13)
#define ADC10_A_INPUT_A14 (ADC10INCH_14)
#define ADC10_A_INPUT_A15 (ADC10INCH_15)
//*****************************************************************************
//
// The following are values that can be passed to the
// negativeRefVoltageSourceSelect parameter for functions:
// ADC10_A_configureMemory().
//
//*****************************************************************************
#define ADC10_A_VREFNEG_AVSS (!(ADC10SREF2))
#define ADC10_A_VREFNEG_EXT (ADC10SREF2)
//*****************************************************************************
//
// The following are values that can be passed to the interruptMask parameter
// for functions: ADC10_A_enableInterrupt(), and ADC10_A_disableInterrupt().
//
//*****************************************************************************
#define ADC10_A_TIMEOVERFLOW_INT (ADC10TOVIE)
#define ADC10_A_OVERFLOW_INT (ADC10OVIE)
#define ADC10_A_ABOVETHRESHOLD_INT (ADC10HIIE)
#define ADC10_A_BELOWTHRESHOLD_INT (ADC10LOIE)
#define ADC10_A_INSIDEWINDOW_INT (ADC10INIE)
#define ADC10_A_COMPLETED_INT (ADC10IE0)
//*****************************************************************************
//
// The following are values that can be passed to the interruptFlagMask
// parameter for functions: ADC10_A_clearInterrupt(), and
// ADC10_A_getInterruptStatus().
//
//*****************************************************************************
#define ADC10_A_TIMEOVERFLOW_INTFLAG (ADC10TOVIFG)
#define ADC10_A_OVERFLOW_INTFLAG (ADC10OVIFG)
#define ADC10_A_ABOVETHRESHOLD_INTFLAG (ADC10HIIFG)
#define ADC10_A_BELOWTHRESHOLD_INTFLAG (ADC10LOIFG)
#define ADC10_A_INSIDEWINDOW_INTFLAG (ADC10INIFG)
#define ADC10_A_COMPLETED_INTFLAG (ADC10IFG0)
//*****************************************************************************
//
// The following are values that can be passed to the
// conversionSequenceModeSelect parameter for functions:
// ADC10_A_startConversion().
//
//*****************************************************************************
#define ADC10_A_SINGLECHANNEL (ADC10CONSEQ_0)
#define ADC10_A_SEQOFCHANNELS (ADC10CONSEQ_1)
#define ADC10_A_REPEATED_SINGLECHANNEL (ADC10CONSEQ_2)
#define ADC10_A_REPEATED_SEQOFCHANNELS (ADC10CONSEQ_3)
//*****************************************************************************
//
// The following are values that can be passed to the preempt parameter for
// functions: ADC10_A_disableConversions().
//
//*****************************************************************************
#define ADC10_A_COMPLETECONVERSION false
#define ADC10_A_PREEMPTCONVERSION true
//*****************************************************************************
//
// The following are values that can be passed to the resolutionSelect
// parameter for functions: ADC10_A_setResolution().
//
//*****************************************************************************
#define ADC10_A_RESOLUTION_8BIT (!(ADC10RES))
#define ADC10_A_RESOLUTION_10BIT (ADC10RES)
//*****************************************************************************
//
// The following are values that can be passed to the invertedSignal parameter
// for functions: ADC10_A_setSampleHoldSignalInversion().
//
//*****************************************************************************
#define ADC10_A_NONINVERTEDSIGNAL (!(ADC10ISSH))
#define ADC10_A_INVERTEDSIGNAL (ADC10ISSH)
//*****************************************************************************
//
// The following are values that can be passed to the readBackFormat parameter
// for functions: ADC10_A_setDataReadBackFormat().
//
//*****************************************************************************
#define ADC10_A_UNSIGNED_BINARY (!(ADC10DF))
#define ADC10_A_SIGNED_2SCOMPLEMENT (ADC10DF)
//*****************************************************************************
//
// The following are values that can be passed to the samplingRateSelect
// parameter for functions: ADC10_A_setReferenceBufferSamplingRate().
//
//*****************************************************************************
#define ADC10_A_MAXSAMPLINGRATE_200KSPS (!(ADC10SR))
#define ADC10_A_MAXSAMPLINGRATE_50KSPS (ADC10SR)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the ADC10_A_isBusy() function.
//
//*****************************************************************************
#define ADC10_A_BUSY ADC10BUSY
#define ADC10_A_NOTBUSY 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the ADC10_A Module.
//!
//! This function initializes the ADC module to allow for analog-to-digital
//! conversions. Specifically this function sets up the sample-and-hold signal
//! and clock sources for the ADC core to use for conversions. Upon successful
//! completion of the initialization all of the ADC control registers will be
//! reset, excluding the memory controls and reference module bits, the given
//! parameters will be set, and the ADC core will be turned on (Note, that the
//! ADC core only draws power during conversions and remains off when not
//! converting).Note that sample/hold signal sources are device dependent. Note
//! that if re-initializing the ADC after starting a conversion with the
//! startConversion() function, the disableConversion() must be called BEFORE
//! this function can be called.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param sampleHoldSignalSourceSelect is the signal that will trigger a
//! sample-and-hold for an input signal to be converted. This parameter
//! is device specific and sources should be found in the device's
//! datasheet
//! Valid values are:
//! - \b ADC10_A_SAMPLEHOLDSOURCE_SC
//! - \b ADC10_A_SAMPLEHOLDSOURCE_1
//! - \b ADC10_A_SAMPLEHOLDSOURCE_2
//! - \b ADC10_A_SAMPLEHOLDSOURCE_3
//! \n Modified bits are \b ADC10SHSx of \b ADC10CTL1 register.
//! \param clockSourceSelect selects the clock that will be used by the ADC10_A
//! core and the sampling timer if a sampling pulse mode is enabled.
//! Valid values are:
//! - \b ADC10_A_CLOCKSOURCE_ADC10OSC [Default] - MODOSC 5 MHz
//! oscillator from the UCS
//! - \b ADC10_A_CLOCKSOURCE_ACLK - The Auxiliary Clock
//! - \b ADC10_A_CLOCKSOURCE_MCLK - The Master Clock
//! - \b ADC10_A_CLOCKSOURCE_SMCLK - The Sub-Master Clock
//! \n Modified bits are \b ADC10SSELx of \b ADC10CTL1 register.
//! \param clockSourceDivider selects the amount that the clock will be
//! divided.
//! Valid values are:
//! - \b ADC10_A_CLOCKDIVIDER_1 [Default]
//! - \b ADC10_A_CLOCKDIVIDER_2
//! - \b ADC10_A_CLOCKDIVIDER_3
//! - \b ADC10_A_CLOCKDIVIDER_4
//! - \b ADC10_A_CLOCKDIVIDER_5
//! - \b ADC10_A_CLOCKDIVIDER_6
//! - \b ADC10_A_CLOCKDIVIDER_7
//! - \b ADC10_A_CLOCKDIVIDER_8
//! - \b ADC10_A_CLOCKDIVIDER_12
//! - \b ADC10_A_CLOCKDIVIDER_16
//! - \b ADC10_A_CLOCKDIVIDER_20
//! - \b ADC10_A_CLOCKDIVIDER_24
//! - \b ADC10_A_CLOCKDIVIDER_28
//! - \b ADC10_A_CLOCKDIVIDER_32
//! - \b ADC10_A_CLOCKDIVIDER_64
//! - \b ADC10_A_CLOCKDIVIDER_128
//! - \b ADC10_A_CLOCKDIVIDER_192
//! - \b ADC10_A_CLOCKDIVIDER_256
//! - \b ADC10_A_CLOCKDIVIDER_320
//! - \b ADC10_A_CLOCKDIVIDER_384
//! - \b ADC10_A_CLOCKDIVIDER_448
//! - \b ADC10_A_CLOCKDIVIDER_512
//! \n Modified bits are \b ADC10DIVx of \b ADC10CTL1 register; bits \b
//! ADC10PDIVx of \b ADC10CTL2 register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the initialization process.
//
//*****************************************************************************
extern bool ADC10_A_init(uint16_t baseAddress,
uint16_t sampleHoldSignalSourceSelect,
uint8_t clockSourceSelect,
uint16_t clockSourceDivider);
//*****************************************************************************
//
//! \brief Enables the ADC10_A block.
//!
//! This will enable operation of the ADC10_A block.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! Modified bits are \b ADC10ON of \b ADC10CTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the ADC10_A block.
//!
//! This will disable operation of the ADC10_A block.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! Modified bits are \b ADC10ON of \b ADC10CTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets up and enables the Sampling Timer Pulse Mode.
//!
//! This function sets up the sampling timer pulse mode which allows the
//! sample/hold signal to trigger a sampling timer to sample-and-hold an input
//! signal for a specified number of clock cycles without having to hold the
//! sample/hold signal for the entire period of sampling. Note that if a
//! conversion has been started with the startConversion() function, then a
//! call to disableConversions() is required before this function may be
//! called.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param clockCycleHoldCount sets the amount of clock cycles to sample-and-
//! hold for the memory buffer.
//! Valid values are:
//! - \b ADC10_A_CYCLEHOLD_4_CYCLES [Default]
//! - \b ADC10_A_CYCLEHOLD_8_CYCLES
//! - \b ADC10_A_CYCLEHOLD_16_CYCLES
//! - \b ADC10_A_CYCLEHOLD_32_CYCLES
//! - \b ADC10_A_CYCLEHOLD_64_CYCLES
//! - \b ADC10_A_CYCLEHOLD_96_CYCLES
//! - \b ADC10_A_CYCLEHOLD_128_CYCLES
//! - \b ADC10_A_CYCLEHOLD_192_CYCLES
//! - \b ADC10_A_CYCLEHOLD_256_CYCLES
//! - \b ADC10_A_CYCLEHOLD_384_CYCLES
//! - \b ADC10_A_CYCLEHOLD_512_CYCLES
//! - \b ADC10_A_CYCLEHOLD_768_CYCLES
//! - \b ADC10_A_CYCLEHOLD_1024_CYCLES
//! \n Modified bits are \b ADC10SHTx of \b ADC10CTL0 register.
//! \param multipleSamplesEnabled allows multiple conversions to start without
//! a trigger signal from the sample/hold signal
//! Valid values are:
//! - \b ADC10_A_MULTIPLESAMPLESDISABLE - a timer trigger will be needed
//! to start every ADC conversion.
//! - \b ADC10_A_MULTIPLESAMPLESENABLE - during a sequenced and/or
//! repeated conversion mode, after the first conversion, no
//! sample/hold signal is necessary to start subsequent samples.
//! \n Modified bits are \b ADC10MSC of \b ADC10CTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_setupSamplingTimer(uint16_t baseAddress,
uint16_t clockCycleHoldCount,
uint16_t multipleSamplesEnabled);
//*****************************************************************************
//
//! \brief Disables Sampling Timer Pulse Mode.
//!
//! Disables the Sampling Timer Pulse Mode. Note that if a conversion has been
//! started with the startConversion() function, then a call to
//! disableConversions() is required before this function may be called.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_disableSamplingTimer(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Configures the controls of the selected memory buffer.
//!
//! Maps an input signal conversion into the memory buffer, as well as the
//! positive and negative reference voltages for each conversion being stored
//! into the memory buffer. If the internal reference is used for the positive
//! reference voltage, the internal REF module has to control the voltage
//! level. Note that if a conversion has been started with the
//! startConversion() function, then a call to disableConversions() is required
//! before this function may be called. If conversion is not disabled, this
//! function does nothing.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param inputSourceSelect is the input that will store the converted data
//! into the specified memory buffer.
//! Valid values are:
//! - \b ADC10_A_INPUT_A0 [Default]
//! - \b ADC10_A_INPUT_A1
//! - \b ADC10_A_INPUT_A2
//! - \b ADC10_A_INPUT_A3
//! - \b ADC10_A_INPUT_A4
//! - \b ADC10_A_INPUT_A5
//! - \b ADC10_A_INPUT_A6
//! - \b ADC10_A_INPUT_A7
//! - \b ADC10_A_INPUT_A8
//! - \b ADC10_A_INPUT_A9
//! - \b ADC10_A_INPUT_TEMPSENSOR
//! - \b ADC10_A_INPUT_BATTERYMONITOR
//! - \b ADC10_A_INPUT_A12
//! - \b ADC10_A_INPUT_A13
//! - \b ADC10_A_INPUT_A14
//! - \b ADC10_A_INPUT_A15
//! \n Modified bits are \b ADC10INCHx of \b ADC10MCTL0 register.
//! \param positiveRefVoltageSourceSelect is the reference voltage source to
//! set as the upper limit for the conversion that is to be stored in
//! the specified memory buffer.
//! Valid values are:
//! - \b ADC10_A_VREFPOS_AVCC [Default]
//! - \b ADC10_A_VREFPOS_EXT
//! - \b ADC10_A_VREFPOS_INT
//! \n Modified bits are \b ADC10SREF of \b ADC10MCTL0 register.
//! \param negativeRefVoltageSourceSelect is the reference voltage source to
//! set as the lower limit for the conversion that is to be stored in
//! the specified memory buffer.
//! Valid values are:
//! - \b ADC10_A_VREFNEG_AVSS
//! - \b ADC10_A_VREFNEG_EXT
//! \n Modified bits are \b ADC10SREF of \b ADC10CTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_configureMemory(uint16_t baseAddress,
uint8_t inputSourceSelect,
uint8_t positiveRefVoltageSourceSelect,
uint8_t negativeRefVoltageSourceSelect);
//*****************************************************************************
//
//! \brief Enables selected ADC10_A interrupt sources.
//!
//! Enables the indicated ADC10_A interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param interruptMask is the bit mask of the memory buffer interrupt sources
//! to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b ADC10_A_TIMEOVERFLOW_INT - Interrupts when a new conversion is
//! starting before the previous one has finished
//! - \b ADC10_A_OVERFLOW_INT - Interrupts when a new conversion is
//! about to overwrite the previous one
//! - \b ADC10_A_ABOVETHRESHOLD_INT - Interrupts when the input signal
//! has gone above the high threshold of the window comparator
//! - \b ADC10_A_BELOWTHRESHOLD_INT - Interrupts when the input signal
//! has gone below the low threshold of the low window comparator
//! - \b ADC10_A_INSIDEWINDOW_INT - Interrupts when the input signal is
//! in between the high and low thresholds of the window comparator
//! - \b ADC10_A_COMPLETED_INT - Interrupt for new conversion data in
//! the memory buffer
//!
//! Modified bits of \b ADC10IE register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_enableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Disables selected ADC10_A interrupt sources.
//!
//! Disables the indicated ADC10_A interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param interruptMask is the bit mask of the memory buffer interrupt sources
//! to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b ADC10_A_TIMEOVERFLOW_INT - Interrupts when a new conversion is
//! starting before the previous one has finished
//! - \b ADC10_A_OVERFLOW_INT - Interrupts when a new conversion is
//! about to overwrite the previous one
//! - \b ADC10_A_ABOVETHRESHOLD_INT - Interrupts when the input signal
//! has gone above the high threshold of the window comparator
//! - \b ADC10_A_BELOWTHRESHOLD_INT - Interrupts when the input signal
//! has gone below the low threshold of the low window comparator
//! - \b ADC10_A_INSIDEWINDOW_INT - Interrupts when the input signal is
//! in between the high and low thresholds of the window comparator
//! - \b ADC10_A_COMPLETED_INT - Interrupt for new conversion data in
//! the memory buffer
//!
//! Modified bits of \b ADC10IE register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_disableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Clears ADC10_A selected interrupt flags.
//!
//! The selected ADC10_A interrupt flags are cleared, so that it no longer
//! asserts. The memory buffer interrupt flags are only cleared when the memory
//! buffer is accessed.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param interruptFlagMask is a bit mask of the interrupt flags to be
//! cleared.
//! Mask value is the logical OR of any of the following:
//! - \b ADC10_A_TIMEOVERFLOW_INTFLAG - Interrupts flag when a new
//! conversion is starting before the previous one has finished
//! - \b ADC10_A_OVERFLOW_INTFLAG - Interrupts flag when a new
//! conversion is about to overwrite the previous one
//! - \b ADC10_A_ABOVETHRESHOLD_INTFLAG - Interrupts flag when the input
//! signal has gone above the high threshold of the window comparator
//! - \b ADC10_A_BELOWTHRESHOLD_INTFLAG - Interrupts flag when the input
//! signal has gone below the low threshold of the low window
//! comparator
//! - \b ADC10_A_INSIDEWINDOW_INTFLAG - Interrupts flag when the input
//! signal is in between the high and low thresholds of the window
//! comparator
//! - \b ADC10_A_COMPLETED_INTFLAG - Interrupt flag for new conversion
//! data in the memory buffer
//!
//! Modified bits of \b ADC10IFG register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_clearInterrupt(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Returns the status of the selected memory interrupt flags.
//!
//! Returns the status of the selected interrupt flags.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param interruptFlagMask is a bit mask of the interrupt flags status to be
//! returned.
//! Mask value is the logical OR of any of the following:
//! - \b ADC10_A_TIMEOVERFLOW_INTFLAG - Interrupts flag when a new
//! conversion is starting before the previous one has finished
//! - \b ADC10_A_OVERFLOW_INTFLAG - Interrupts flag when a new
//! conversion is about to overwrite the previous one
//! - \b ADC10_A_ABOVETHRESHOLD_INTFLAG - Interrupts flag when the input
//! signal has gone above the high threshold of the window comparator
//! - \b ADC10_A_BELOWTHRESHOLD_INTFLAG - Interrupts flag when the input
//! signal has gone below the low threshold of the low window
//! comparator
//! - \b ADC10_A_INSIDEWINDOW_INTFLAG - Interrupts flag when the input
//! signal is in between the high and low thresholds of the window
//! comparator
//! - \b ADC10_A_COMPLETED_INTFLAG - Interrupt flag for new conversion
//! data in the memory buffer
//!
//! \return The current interrupt flag status for the corresponding mask.
//
//*****************************************************************************
extern uint16_t ADC10_A_getInterruptStatus(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Enables/Starts an Analog-to-Digital Conversion.
//!
//! This function enables/starts the conversion process of the ADC. If the
//! sample/hold signal source chosen during initialization was ADC10OSC, then
//! the conversion is started immediately, otherwise the chosen sample/hold
//! signal source starts the conversion by a rising edge of the signal. Keep in
//! mind when selecting conversion modes, that for sequenced and/or repeated
//! modes, to keep the sample/hold-and-convert process continuing without a
//! trigger from the sample/hold signal source, the multiple samples must be
//! enabled using the ADC10_A_setupSamplingTimer() function. Also note that
//! when a sequence conversion mode is selected, the first input channel is the
//! one mapped to the memory buffer, the next input channel selected for
//! conversion is one less than the input channel just converted (i.e. A1 comes
//! after A2), until A0 is reached, and if in repeating mode, then the next
//! input channel will again be the one mapped to the memory buffer. Note that
//! after this function is called, the ADC10_A_stopConversions() has to be
//! called to re-initialize the ADC, reconfigure a memory buffer control,
//! enable/disable the sampling timer, or to change the internal reference
//! voltage.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param conversionSequenceModeSelect determines the ADC operating mode.
//! Valid values are:
//! - \b ADC10_A_SINGLECHANNEL [Default] - one-time conversion of a
//! single channel into a single memory buffer
//! - \b ADC10_A_SEQOFCHANNELS - one time conversion of multiple
//! channels into the specified starting memory buffer and each
//! subsequent memory buffer up until the conversion is stored in a
//! memory buffer dedicated as the end-of-sequence by the memory's
//! control register
//! - \b ADC10_A_REPEATED_SINGLECHANNEL - repeated conversions of one
//! channel into a single memory buffer
//! - \b ADC10_A_REPEATED_SEQOFCHANNELS - repeated conversions of
//! multiple channels into the specified starting memory buffer and
//! each subsequent memory buffer up until the conversion is stored
//! in a memory buffer dedicated as the end-of-sequence by the
//! memory's control register
//! \n Modified bits are \b ADC10CONSEQx of \b ADC10CTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_startConversion(uint16_t baseAddress,
uint8_t conversionSequenceModeSelect);
//*****************************************************************************
//
//! \brief Disables the ADC from converting any more signals.
//!
//! Disables the ADC from converting any more signals. If there is a conversion
//! in progress, this function can stop it immediately if the preempt parameter
//! is set as ADC10_A_PREEMPTCONVERSION, by changing the conversion mode to
//! single-channel, single-conversion and disabling conversions. If the
//! conversion mode is set as single-channel, single-conversion and this
//! function is called without preemption, then the ADC core conversion status
//! is polled until the conversion is complete before disabling conversions to
//! prevent unpredictable data. If the ADC10_A_startConversion() has been
//! called, then this function has to be called to re-initialize the ADC,
//! reconfigure a memory buffer control, enable/disable the sampling pulse
//! mode, or change the internal reference voltage.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param preempt specifies if the current conversion should be pre-empted
//! before the end of the conversion
//! Valid values are:
//! - \b ADC10_A_COMPLETECONVERSION - Allows the ADC10_A to end the
//! current conversion before disabling conversions.
//! - \b ADC10_A_PREEMPTCONVERSION - Stops the ADC10_A immediately, with
//! unpredictable results of the current conversion. Cannot be used
//! with repeated conversion.
//!
//! Modified bits of \b ADC10CTL1 register and bits of \b ADC10CTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_disableConversions(uint16_t baseAddress,
bool preempt);
//*****************************************************************************
//
//! \brief Returns the raw contents of the specified memory buffer.
//!
//! Returns the raw contents of the specified memory buffer. The format of the
//! content depends on the read-back format of the data: if the data is in
//! signed 2's complement format then the contents in the memory buffer will be
//! left-justified with the least-significant bits as 0's, whereas if the data
//! is in unsigned format then the contents in the memory buffer will be right-
//! justified with the most-significant bits as 0's.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! \return A Signed Integer of the contents of the specified memory buffer.
//
//*****************************************************************************
extern int16_t ADC10_A_getResults(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Use to change the resolution of the converted data.
//!
//! This function can be used to change the resolution of the converted data
//! from the default of 12-bits.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param resolutionSelect determines the resolution of the converted data.
//! Valid values are:
//! - \b ADC10_A_RESOLUTION_8BIT
//! - \b ADC10_A_RESOLUTION_10BIT [Default]
//! \n Modified bits are \b ADC10RES of \b ADC10CTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_setResolution(uint16_t baseAddress,
uint8_t resolutionSelect);
//*****************************************************************************
//
//! \brief Use to invert or un-invert the sample/hold signal
//!
//! This function can be used to invert or un-invert the sample/hold signal.
//! Note that if a conversion has been started with the startConversion()
//! function, then a call to disableConversions() is required before this
//! function may be called.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param invertedSignal set if the sample/hold signal should be inverted
//! Valid values are:
//! - \b ADC10_A_NONINVERTEDSIGNAL [Default] - a sample-and-hold of an
//! input signal for conversion will be started on a rising edge of
//! the sample/hold signal.
//! - \b ADC10_A_INVERTEDSIGNAL - a sample-and-hold of an input signal
//! for conversion will be started on a falling edge of the
//! sample/hold signal.
//! \n Modified bits are \b ADC10ISSH of \b ADC10CTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_setSampleHoldSignalInversion(uint16_t baseAddress,
uint16_t invertedSignal);
//*****************************************************************************
//
//! \brief Use to set the read-back format of the converted data
//!
//! Sets the format of the converted data: how it will be stored into the
//! memory buffer, and how it should be read back. The format can be set as
//! right-justified (default), which indicates that the number will be
//! unsigned, or left-justified, which indicates that the number will be signed
//! in 2's complement format. This change affects all memory buffers for
//! subsequent conversions.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param readBackFormat is the specified format to store the conversions in
//! the memory buffer.
//! Valid values are:
//! - \b ADC10_A_UNSIGNED_BINARY [Default]
//! - \b ADC10_A_SIGNED_2SCOMPLEMENT
//! \n Modified bits are \b ADC10DF of \b ADC10CTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_setDataReadBackFormat(uint16_t baseAddress,
uint16_t readBackFormat);
//*****************************************************************************
//
//! \brief Enables the reference buffer's burst ability.
//!
//! Enables the reference buffer's burst ability, allowing the reference buffer
//! to turn off while the ADC is not converting, and automatically turning on
//! when the ADC needs the generated reference voltage for a conversion.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_enableReferenceBurst(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the reference buffer's burst ability.
//!
//! Disables the reference buffer's burst ability, forcing the reference buffer
//! to remain on continuously.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_disableReferenceBurst(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Use to set the reference buffer's sampling rate.
//!
//! Sets the reference buffer's sampling rate to the selected sampling rate.
//! The default sampling rate is maximum of 200-ksps, and can be reduced to a
//! maximum of 50-ksps to conserve power.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param samplingRateSelect is the specified maximum sampling rate.
//! Valid values are:
//! - \b ADC10_A_MAXSAMPLINGRATE_200KSPS [Default]
//! - \b ADC10_A_MAXSAMPLINGRATE_50KSPS
//! \n Modified bits are \b ADC10SR of \b ADC10CTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_setReferenceBufferSamplingRate(uint16_t baseAddress,
uint16_t samplingRateSelect);
//*****************************************************************************
//
//! \brief Sets the high and low threshold for the window comparator feature.
//!
//! Sets the high and low threshold for the window comparator feature. Use the
//! ADC10HIIE, ADC10INIE, ADC10LOIE interrupts to utilize this feature.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//! \param highThreshold is the upper bound that could trip an interrupt for
//! the window comparator.
//! \param lowThreshold is the lower bound that could trip on interrupt for the
//! window comparator.
//!
//! \return None
//
//*****************************************************************************
extern void ADC10_A_setWindowComp(uint16_t baseAddress,
uint16_t highThreshold,
uint16_t lowThreshold);
//*****************************************************************************
//
//! \brief Returns the address of the memory buffer for the DMA module.
//!
//! Returns the address of the memory buffer. This can be used in conjunction
//! with the DMA to store the converted data directly to memory.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! \return The memory address of the memory buffer
//
//*****************************************************************************
extern uint32_t ADC10_A_getMemoryAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the busy status of the ADC10_A core.
//!
//! Returns the status of the ADC core if there is a conversion currently
//! taking place.
//!
//! \param baseAddress is the base address of the ADC10_A module.
//!
//! \return One of the following:
//! - \b ADC10_A_BUSY
//! - \b ADC10_A_NOTBUSY
//! \n indicating if there is a conversion currently taking place
//
//*****************************************************************************
extern uint16_t ADC10_A_isBusy(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_ADC10_A_H__

View File

@@ -0,0 +1,241 @@
//*****************************************************************************
//
// adc12_a.c - Driver for the adc12_a Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup adc12_a_api adc12_a
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_ADC12_PLUS__
#include "adc12_a.h"
#include <assert.h>
bool ADC12_A_init (uint16_t baseAddress,
uint16_t sampleHoldSignalSourceSelect,
uint8_t clockSourceSelect,
uint16_t clockSourceDivider)
{
//Make sure the ENC bit is cleared before initializing the ADC12_A
HWREG8(baseAddress + OFS_ADC12CTL0_L) &= ~ADC12ENC;
bool retVal = STATUS_SUCCESS;
//Turn OFF ADC12_A Module & Clear Interrupt Registers
HWREG16(baseAddress + OFS_ADC12CTL0) &= ~(ADC12ON + ADC12OVIE + ADC12TOVIE
+ ADC12ENC + ADC12SC);
HWREG16(baseAddress + OFS_ADC12IE) &= 0x0000; //Reset ALL interrupt enables
HWREG16(baseAddress + OFS_ADC12IFG) &= 0x0000; //Reset ALL interrupt flags
//Set ADC12_A Control 1
HWREG16(baseAddress + OFS_ADC12CTL1) =
sampleHoldSignalSourceSelect //Setup the Sample-and-Hold Source
+ (clockSourceDivider & ADC12DIV_7) //Set Clock Divider
+ clockSourceSelect; //Setup Clock Source
//Set ADC12_A Control 2
HWREG16(baseAddress + OFS_ADC12CTL2) =
(clockSourceDivider & ADC12PDIV) //Set Clock Pre-Divider
+ ADC12RES_2; //Default resolution to 12-bits
return ( retVal) ;
}
void ADC12_A_enable (uint16_t baseAddress)
{
//Enable the ADC12_A Module
HWREG8(baseAddress + OFS_ADC12CTL0_L) |= ADC12ON;
}
void ADC12_A_disable (uint16_t baseAddress)
{
//Disable ADC12_A module
HWREG8(baseAddress + OFS_ADC12CTL0_L) &= ~ADC12ON;
}
void ADC12_A_setupSamplingTimer (uint16_t baseAddress,
uint16_t clockCycleHoldCountLowMem,
uint16_t clockCycleHoldCountHighMem,
uint16_t multipleSamplesEnabled)
{
HWREG16(baseAddress + OFS_ADC12CTL1) |= ADC12SHP;
//Reset clock cycle hold counts and msc bit before setting them
HWREG16(baseAddress + OFS_ADC12CTL0) &=
~(ADC12SHT0_15 + ADC12SHT1_15 + ADC12MSC);
//Set clock cycle hold counts and msc bit
HWREG16(baseAddress + OFS_ADC12CTL0) |= clockCycleHoldCountLowMem
+ (clockCycleHoldCountHighMem << 4)
+ multipleSamplesEnabled;
}
void ADC12_A_disableSamplingTimer (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_ADC12CTL1) &= ~(ADC12SHP);
}
void ADC12_A_configureMemory(uint16_t baseAddress,
ADC12_A_configureMemoryParam *param)
{
//Make sure the ENC bit is cleared before configuring a Memory Buffer Control
assert( !(HWREG16(baseAddress + OFS_ADC12CTL0) & ADC12ENC) );
if(!(HWREG16(baseAddress + OFS_ADC12CTL0) & ADC12ENC))
{
//Set the offset in respect to ADC12MCTL0
uint16_t memoryBufferControlOffset =
(OFS_ADC12MCTL0 + param->memoryBufferControlIndex);
//Reset the memory buffer control and Set the input source
HWREG8(baseAddress + memoryBufferControlOffset) =
param->inputSourceSelect //Set Input Source
+ param->positiveRefVoltageSourceSelect //Set Vref+
+ param->negativeRefVoltageSourceSelect //Set Vref-
+ param->endOfSequence; //Set End of Sequence
}
}
void ADC12_A_enableInterrupt (uint16_t baseAddress,
uint32_t interruptMask)
{
if (interruptMask & ADC12_A_CONVERSION_TIME_OVERFLOW_IE) {
HWREG16(baseAddress + OFS_ADC12CTL0) |= ADC12TOVIE;
interruptMask &= ~ADC12_A_CONVERSION_TIME_OVERFLOW_IE;
}
if (interruptMask & ADC12_A_OVERFLOW_IE) {
HWREG16(baseAddress + OFS_ADC12CTL0) |= ADC12OVIE;
interruptMask &= ~ADC12_A_OVERFLOW_IE;
}
HWREG16(baseAddress + OFS_ADC12IE) |= interruptMask;
}
void ADC12_A_disableInterrupt (uint16_t baseAddress,
uint32_t interruptMask)
{
if (interruptMask & ADC12_A_CONVERSION_TIME_OVERFLOW_IE) {
HWREG16(baseAddress + OFS_ADC12CTL0) &= ~(ADC12TOVIE);
interruptMask &= ~ADC12_A_CONVERSION_TIME_OVERFLOW_IE;
}
if (interruptMask & ADC12_A_OVERFLOW_IE) {
HWREG16(baseAddress + OFS_ADC12CTL0) &= ~(ADC12OVIE);
interruptMask &= ~ADC12_A_OVERFLOW_IE;
}
HWREG16(baseAddress + OFS_ADC12IE) &= ~(interruptMask);
}
void ADC12_A_clearInterrupt (uint16_t baseAddress,
uint16_t memoryInterruptFlagMask)
{
HWREG16(baseAddress + OFS_ADC12IFG) &= ~(memoryInterruptFlagMask);
}
uint16_t ADC12_A_getInterruptStatus (uint16_t baseAddress,
uint16_t memoryInterruptFlagMask)
{
return ( HWREG16(baseAddress + OFS_ADC12IFG) & memoryInterruptFlagMask );
}
void ADC12_A_startConversion (uint16_t baseAddress,
uint16_t startingMemoryBufferIndex,
uint8_t conversionSequenceModeSelect)
{
//Reset the ENC bit to set the starting memory address and conversion mode
//sequence
HWREG8(baseAddress + OFS_ADC12CTL0_L) &= ~(ADC12ENC);
//Reset the bits about to be set
HWREG16(baseAddress + OFS_ADC12CTL1) &= ~(ADC12CSTARTADD_15 + ADC12CONSEQ_3);
HWREG8(baseAddress + OFS_ADC12CTL1_H) |= (startingMemoryBufferIndex << 4);
HWREG8(baseAddress + OFS_ADC12CTL1_L) |= conversionSequenceModeSelect;
HWREG8(baseAddress + OFS_ADC12CTL0_L) |= ADC12ENC + ADC12SC;
}
void ADC12_A_disableConversions (uint16_t baseAddress, bool preempt)
{
if (ADC12_A_PREEMPTCONVERSION == preempt) {
HWREG8(baseAddress + OFS_ADC12CTL1_L) &= ~(ADC12CONSEQ_3);
//Reset conversion sequence mode to single-channel, single-conversion
}
else if (~(HWREG8(baseAddress + OFS_ADC12CTL1_L) & ADC12CONSEQ_3)) {
//To prevent preemoption of a single-channel, single-conversion we must
//wait for the ADC core to finish the conversion.
while (ADC12_A_isBusy(baseAddress)) ;
}
HWREG8(baseAddress + OFS_ADC12CTL0_L) &= ~(ADC12ENC);
}
uint16_t ADC12_A_getResults (uint16_t baseAddress, uint8_t memoryBufferIndex)
{
//(0x20 + (memoryBufferIndex * 2)) == offset of ADC12MEMx
return ( HWREG16(baseAddress + (0x20 + (memoryBufferIndex * 2))) );
}
void ADC12_A_setResolution (uint16_t baseAddress,
uint8_t resolutionSelect)
{
HWREG8(baseAddress + OFS_ADC12CTL2_L) &= ~(ADC12RES_3);
HWREG8(baseAddress + OFS_ADC12CTL2_L) |= resolutionSelect;
}
void ADC12_A_setSampleHoldSignalInversion (uint16_t baseAddress,
uint16_t invertedSignal)
{
HWREG16(baseAddress + OFS_ADC12CTL1) &= ~(ADC12ISSH);
HWREG16(baseAddress + OFS_ADC12CTL1) |= invertedSignal;
}
void ADC12_A_setDataReadBackFormat (uint16_t baseAddress,
uint8_t readBackFormat)
{
HWREG8(baseAddress + OFS_ADC12CTL2_L) &= ~(ADC12DF);
HWREG8(baseAddress + OFS_ADC12CTL2_L) |= readBackFormat;
}
void ADC12_A_enableReferenceBurst (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_ADC12CTL2_L) |= ADC12REFBURST;
}
void ADC12_A_disableReferenceBurst (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_ADC12CTL2_L) &= ~(ADC12REFBURST);
}
void ADC12_A_setReferenceBufferSamplingRate (uint16_t baseAddress,
uint8_t samplingRateSelect)
{
HWREG8(baseAddress + OFS_ADC12CTL2_L) &= ~(ADC12SR);
HWREG8(baseAddress + OFS_ADC12CTL2_L) |= samplingRateSelect;
}
uint32_t ADC12_A_getMemoryAddressForDMA (uint16_t baseAddress,
uint8_t memoryIndex)
{
return ( baseAddress + (0x20 + (memoryIndex * 2)) );
}
uint16_t ADC12_A_isBusy (uint16_t baseAddress)
{
return (HWREG8(baseAddress + OFS_ADC12CTL1_L) & ADC12BUSY);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for adc12_a_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,345 @@
//*****************************************************************************
//
// aes.c - Driver for the aes Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup aes_api aes
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_AES__
#include "aes.h"
#include <assert.h>
uint8_t AES_setCipherKey (uint16_t baseAddress,
const uint8_t * CipherKey
)
{
uint8_t i = 0;
uint16_t tempVariable = 0;
// Wait until AES accelerator is busy
while(AESBUSY == (HWREG16(baseAddress + OFS_AESASTAT) & AESBUSY) );
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(CipherKey[i]);
tempVariable = tempVariable | ((uint16_t)(CipherKey[i + 1]) << 8);
HWREG16(baseAddress + OFS_AESAKEY) = tempVariable;
}
// Wait until key is written
while(0x00 == (HWREG16(baseAddress + OFS_AESASTAT) & AESKEYWR ));
return STATUS_SUCCESS;
}
uint8_t AES_encryptData (uint16_t baseAddress,
const uint8_t * Data,
uint8_t * encryptedData)
{
uint8_t i;
uint16_t tempData = 0;
uint16_t tempVariable = 0;
// Set module to encrypt mode
HWREG16(baseAddress + OFS_AESACTL0) &= ~AESOP_3;
// Write data to encrypt to module
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(Data[i]);
tempVariable = tempVariable | ((uint16_t)(Data[i+1]) << 8);
HWREG16(baseAddress + OFS_AESADIN) = tempVariable;
}
// Key that is already written shall be used
// Encryption is initialized by setting AESKEYWR to 1
HWREG16(baseAddress + OFS_AESASTAT) |= AESKEYWR;
// Wait unit finished ~167 MCLK
while(AESBUSY == (HWREG16(baseAddress + OFS_AESASTAT) & AESBUSY) );
// Write encrypted data back to variable
for (i = 0; i < 16; i = i + 2)
{
tempData = HWREG16(baseAddress + OFS_AESADOUT);
*(encryptedData + i) = (uint8_t)tempData;
*(encryptedData +i + 1) = (uint8_t)(tempData >> 8);
}
return STATUS_SUCCESS;
}
uint8_t AES_decryptData (uint16_t baseAddress,
const uint8_t * Data,
uint8_t * decryptedData)
{
uint8_t i;
uint16_t tempData = 0;
uint16_t tempVariable = 0;
// Set module to decrypt mode
HWREG16(baseAddress + OFS_AESACTL0) |= (AESOP_3);
// Write data to decrypt to module
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(Data[i+1] << 8);
tempVariable = tempVariable | ((uint16_t)(Data[i]));
HWREG16(baseAddress + OFS_AESADIN) = tempVariable;
}
// Key that is already written shall be used
// Now decryption starts
HWREG16(baseAddress + OFS_AESASTAT) |= AESKEYWR;
// Wait unit finished ~167 MCLK
while(AESBUSY == (HWREG16(baseAddress + OFS_AESASTAT) & AESBUSY ));
// Write encrypted data back to variable
for (i = 0; i < 16; i = i + 2)
{
tempData = HWREG16(baseAddress + OFS_AESADOUT);
*(decryptedData + i ) = (uint8_t)tempData;
*(decryptedData +i + 1) = (uint8_t)(tempData >> 8);
}
return STATUS_SUCCESS;
}
uint8_t AES_setDecipherKey (uint16_t baseAddress,
const uint8_t * CipherKey)
{
uint8_t i;
uint16_t tempVariable = 0;
// Set module to decrypt mode
HWREG16(baseAddress + OFS_AESACTL0) &= ~(AESOP0);
HWREG16(baseAddress + OFS_AESACTL0) |= AESOP1;
// Write cipher key to key register
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(CipherKey[i]);
tempVariable = tempVariable | ((uint16_t)(CipherKey[i + 1]) << 8);
HWREG16(baseAddress + OFS_AESAKEY) = tempVariable;
}
// Wait until key is processed ~52 MCLK
while((HWREG16(baseAddress + OFS_AESASTAT) & AESBUSY) == AESBUSY);
return STATUS_SUCCESS;
}
void AES_clearInterrupt (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_AESACTL0) &= ~AESRDYIFG;
}
uint32_t AES_getInterruptStatus (uint16_t baseAddress)
{
return ((HWREG8(baseAddress + OFS_AESACTL0) & AESRDYIFG) << 0x04);
}
void AES_enableInterrupt (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_AESACTL0) |= AESRDYIE;
}
void AES_disableInterrupt (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_AESACTL0) &= ~AESRDYIE;
}
void AES_reset (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_AESACTL0) |= AESSWRST;
}
uint8_t AES_startEncryptData (uint16_t baseAddress,
const uint8_t * Data,
uint8_t * encryptedData)
{
uint8_t i;
uint16_t tempVariable = 0;
// Set module to encrypt mode
HWREG16(baseAddress + OFS_AESACTL0) &= ~AESOP_3;
// Write data to encrypt to module
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(Data[i]);
tempVariable = tempVariable | ((uint16_t)(Data[i+1]) << 8);
HWREG16(baseAddress + OFS_AESADIN) = tempVariable;
}
// Key that is already written shall be used
// Encryption is initialized by setting AESKEYWR to 1
HWREG16(baseAddress + OFS_AESASTAT) |= AESKEYWR;
return STATUS_SUCCESS;
}
uint8_t AES_startDecryptData (uint16_t baseAddress,
const uint8_t * Data)
{
uint8_t i;
uint16_t tempVariable = 0;
// Set module to decrypt mode
HWREG16(baseAddress + OFS_AESACTL0) |= (AESOP_3);
// Write data to decrypt to module
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(Data[i+1] << 8);
tempVariable = tempVariable | ((uint16_t)(Data[i]));
HWREG16(baseAddress + OFS_AESADIN) = tempVariable;
}
// Key that is already written shall be used
// Now decryption starts
HWREG16(baseAddress + OFS_AESASTAT) |= AESKEYWR;
return STATUS_SUCCESS;
}
uint8_t AES_startSetDecipherKey (uint16_t baseAddress,
const uint8_t * CipherKey)
{
uint8_t i;
uint16_t tempVariable = 0;
HWREG16(baseAddress + OFS_AESACTL0) &= ~(AESOP0);
HWREG16(baseAddress + OFS_AESACTL0) |= AESOP1;
// Write cipher key to key register
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(CipherKey[i]);
tempVariable = tempVariable | ((uint16_t)(CipherKey[i+1]) << 8);
HWREG16(baseAddress + OFS_AESAKEY) = tempVariable;
}
return STATUS_SUCCESS;
}
uint8_t AES_getDataOut(uint16_t baseAddress,
uint8_t *OutputData
)
{
uint8_t i;
uint16_t tempData = 0;
// If module is busy, exit and return failure
if( AESBUSY == (HWREG16(baseAddress + OFS_AESASTAT) & AESBUSY))
return STATUS_FAIL;
// Write encrypted data back to variable
for (i = 0; i < 16; i = i + 2)
{
tempData = HWREG16(baseAddress + OFS_AESADOUT);
*(OutputData + i) = (uint8_t)tempData;
*(OutputData +i + 1) = (uint8_t)(tempData >> 8);
}
return STATUS_SUCCESS;
}
uint8_t AES_isBusy (uint16_t baseAddress)
{
return (HWREG16(baseAddress + OFS_AESASTAT) & AESBUSY);
}
void AES_clearErrorFlag (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_AESACTL0) &= ~AESERRFG;
}
uint32_t AES_getErrorFlagStatus (uint16_t baseAddress)
{
return (HWREG8(baseAddress + OFS_AESACTL0) & AESERRFG);
}
uint8_t AES_startDecryptDataUsingEncryptionKey (
uint16_t baseAddress,
const uint8_t * Data)
{
uint8_t i;
uint16_t tempVariable = 0;
// Set module to decrypt mode
HWREG16(baseAddress + OFS_AESACTL0) &= ~(AESOP1);
HWREG16(baseAddress + OFS_AESACTL0) |= AESOP0;
// Write data to decrypt to module
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(Data[i+1] << 8);
tempVariable = tempVariable | ((uint16_t)(Data[i]));
HWREG16(baseAddress + OFS_AESADIN) = tempVariable;
}
// Key that is already written shall be used
// Now decryption starts
HWREG16(baseAddress + OFS_AESASTAT) |= AESKEYWR;
return STATUS_SUCCESS;
}
uint8_t AES_decryptDataUsingEncryptionKey (uint16_t baseAddress,
const uint8_t * Data,
uint8_t * decryptedData)
{
uint8_t i;
uint16_t tempData = 0;
uint16_t tempVariable = 0;
// Set module to decrypt mode
HWREG16(baseAddress + OFS_AESACTL0) &= ~(AESOP1);
HWREG16(baseAddress + OFS_AESACTL0) |= AESOP0;
// Write data to decrypt to module
for (i = 0; i < 16; i = i + 2)
{
tempVariable = (uint16_t)(Data[i+1] << 8);
tempVariable = tempVariable | ((uint16_t)(Data[i]));
HWREG16(baseAddress + OFS_AESADIN) = tempVariable;
}
// Key that is already written shall be used
// Now decryption starts
HWREG16(baseAddress + OFS_AESASTAT) |= AESKEYWR;
// Wait unit finished ~214 MCLK
while(AESBUSY == (HWREG16(baseAddress + OFS_AESASTAT) & AESBUSY) );
// Write encrypted data back to variable
for (i = 0; i < 16; i = i + 2)
{
tempData = HWREG16(baseAddress + OFS_AESADOUT);
*(decryptedData + i ) = (uint8_t)tempData;
*(decryptedData +i + 1) = (uint8_t)(tempData >> 8);
}
return STATUS_SUCCESS;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for aes_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,387 @@
//*****************************************************************************
//
// aes.h - Driver for the AES Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_AES_H__
#define __MSP430WARE_AES_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_AES__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the AES_isBusy() function.
//
//*****************************************************************************
#define AES_BUSY AESBUSY
#define AES_NOT_BUSY 0x00
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the AES_getErrorFlagStatus() function.
//
//*****************************************************************************
#define AES_ERROR_OCCURRED AESERRFG
#define AES_NO_ERROR 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Loads a 128 bit cipher key to AES module.
//!
//! This function loads a 128 bit cipher key to AES module.
//!
//! \param baseAddress is the base address of the AES module.
//! \param CipherKey is a pointer to an uint8_t array with a length of 16 bytes
//! that contains a 128 bit cipher key.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_setCipherKey(uint16_t baseAddress,
const uint8_t *CipherKey);
//*****************************************************************************
//
//! \brief Encrypts a block of data using the AES module.
//!
//! The cipher key that is used for encryption should be loaded in advance by
//! using function \b AES_setCipherKey()
//!
//! \param baseAddress is the base address of the AES module.
//! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
//! contains data to be encrypted.
//! \param encryptedData is a pointer to an uint8_t array with a length of 16
//! bytes in that the encrypted data will be written.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_encryptData(uint16_t baseAddress,
const uint8_t *Data,
uint8_t *encryptedData);
//*****************************************************************************
//
//! \brief Decrypts a block of data using the AES module.
//!
//! This function requires a pre-generated decryption key. A key can be loaded
//! and pre-generated by using function \b AES_startSetDecipherKey() or \b
//! AES_setDecipherKey(). The decryption takes 167 MCLK.
//!
//! \param baseAddress is the base address of the AES module.
//! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
//! contains encrypted data to be decrypted.
//! \param decryptedData is a pointer to an uint8_t array with a length of 16
//! bytes in that the decrypted data will be written.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_decryptData(uint16_t baseAddress,
const uint8_t *Data,
uint8_t *decryptedData);
//*****************************************************************************
//
//! \brief Sets the decipher key The API
//!
//! The API \b AES_startSetDecipherKey() or \b AES_setDecipherKey() must be
//! invoked before invoking \b AES_setDecipherKey().
//!
//! \param baseAddress is the base address of the AES module.
//! \param CipherKey is a pointer to an uint8_t array with a length of 16 bytes
//! that contains the initial AES key.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_setDecipherKey(uint16_t baseAddress,
const uint8_t *CipherKey);
//*****************************************************************************
//
//! \brief Clears the AES ready interrupt flag.
//!
//! This function clears the AES ready interrupt flag. This flag is
//! automatically cleared when AESADOUT is read, or when AESAKEY or AESADIN is
//! written. This function should be used when the flag needs to be reset and
//! it has not been automatically cleared by one of the previous actions.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! Modified bits are \b AESRDYIFG of \b AESACTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void AES_clearInterrupt(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Gets the AES ready interrupt flag status.
//!
//! This function checks the AES ready interrupt flag. This flag is
//! automatically cleared when AESADOUT is read, or when AESAKEY or AESADIN is
//! written. This function can be used to confirm that this has been done.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! \return uint32_t - AES_READY_INTERRUPT or 0x00.
//
//*****************************************************************************
extern uint32_t AES_getInterruptStatus(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables AES ready interrupt.
//!
//! Enables AES ready interrupt. This interrupt is reset by a PUC, but not
//! reset by AES_reset. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! Modified bits are \b AESRDYIE of \b AESACTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void AES_enableInterrupt(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables AES ready interrupt.
//!
//! Disables AES ready interrupt. This interrupt is reset by a PUC, but not
//! reset by AES_reset.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! Modified bits are \b AESRDYIE of \b AESACTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void AES_disableInterrupt(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Resets AES Module immediately.
//!
//! This function performs a software reset on the AES Module, note that this
//! does not affect the AES ready interrupt.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! Modified bits are \b AESSWRST of \b AESACTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void AES_reset(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Starts an encryption process on the AES module.
//!
//! This is the non-blocking equivalent of AES_encryptData(). The cipher key
//! that is used for decryption should be loaded in advance by using function
//! \b AES_setCipherKey(). It is recommended to use interrupt to check for
//! procedure completion then using AES_getDataOut() API to retrieve the
//! encrypted data.
//!
//! \param baseAddress is the base address of the AES module.
//! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
//! contains data to be encrypted.
//! \param encryptedData is a pointer to an uint8_t array with a length of 16
//! bytes in that the encrypted data will be written.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_startEncryptData(uint16_t baseAddress,
const uint8_t *Data,
uint8_t *encryptedData);
//*****************************************************************************
//
//! \brief Decrypts a block of data using the AES module.
//!
//! This is the non-blocking equivalent of AES_decryptData(). This function
//! requires a pre-generated decryption key. A key can be loaded and pre-
//! generated by using function \b AES_setDecipherKey() or \b
//! AES_startSetDecipherKey(). The decryption takes 167 MCLK. It is recommended
//! to use interrupt to check for procedure completion then using
//! AES_getDataOut() API to retrieve the decrypted data.
//!
//! \param baseAddress is the base address of the AES module.
//! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
//! contains encrypted data to be decrypted.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_startDecryptData(uint16_t baseAddress,
const uint8_t *Data);
//*****************************************************************************
//
//! \brief Loads the decipher key.
//!
//! This is the non-blocking equivalent of AES_setDecipherKey(). The API \b
//! AES_startSetDecipherKey() or \b AES_setDecipherKey() must be invoked before
//! invoking \b AES_startSetDecipherKey().
//!
//! \param baseAddress is the base address of the AES module.
//! \param CipherKey is a pointer to an uint8_t array with a length of 16 bytes
//! that contains the initial AES key.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_startSetDecipherKey(uint16_t baseAddress,
const uint8_t *CipherKey);
//*****************************************************************************
//
//! \brief Reads back the output data from AES module.
//!
//! This function is meant to use after an encryption or decryption process
//! that was started and finished by initiating an interrupt by use of the \b
//! AES_startEncryptData() or \b AES_startDecryptData() functions.
//!
//! \param baseAddress is the base address of the AES module.
//! \param OutputData is a pointer to an uint8_t array with a length of 16
//! bytes in which the output data of the AES module is available. If
//! AES module is busy returns NULL.
//!
//! \return STATUS_SUCCESS if AES is not busy, STATUS_FAIL if it is busy
//
//*****************************************************************************
extern uint8_t AES_getDataOut(uint16_t baseAddress,
uint8_t *OutputData);
//*****************************************************************************
//
//! \brief Gets the AES module busy status.
//!
//! Gets the AES module busy status. If a key or data are written while the AES
//! module is busy, an error flag will be thrown.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! \return One of the following:
//! - \b AES_BUSY
//! - \b AES_NOT_BUSY
//! \n indicating if encryption/decryption/key generation is taking
//! place
//
//*****************************************************************************
extern uint8_t AES_isBusy(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Clears the AES error flag.
//!
//! Clears the AES error flag that results from a key or data being written
//! while the AES module is busy. Modified bit is AESERRFG of AESACTL0
//! register.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! Modified bits are \b AESERRFG of \b AESACTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void AES_clearErrorFlag(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Gets the AES error flag status.
//!
//! Checks the AES error flag that results from a key or data being written
//! while the AES module is busy. If the flag is set, it needs to be cleared
//! using AES_clearErrorFlag.
//!
//! \param baseAddress is the base address of the AES module.
//!
//! \return One of the following:
//! - \b AES_ERROR_OCCURRED
//! - \b AES_NO_ERROR
//! \n indicating if AESAKEY or AESADIN were written while an AES
//! operation was in progress
//
//*****************************************************************************
extern uint32_t AES_getErrorFlagStatus(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief DEPRECATED Starts an decryption process on the AES module.
//!
//! This is the non-blocking equivalent of AES_decryptDataUsingEncryptionKey().
//! This function can be used to decrypt data by using the same key as used for
//! a previous performed encryption. The decryption takes 214 MCLK.
//!
//! \param baseAddress is the base address of the AES module.
//! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
//! contains encrypted data to be decrypted.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_startDecryptDataUsingEncryptionKey(uint16_t baseAddress,
const uint8_t *Data);
//*****************************************************************************
//
//! \brief DEPRECATED Decrypts a block of data using the AES module.
//!
//! This function can be used to decrypt data by using the same key as used for
//! a previous performed encryption. The decryption takes 214 MCLK.
//!
//! \param baseAddress is the base address of the AES module.
//! \param Data is a pointer to an uint8_t array with a length of 16 bytes that
//! contains encrypted data to be decrypted.
//! \param decryptedData is a pointer to an uint8_t array with a length of 16
//! bytes in that the decrypted data will be written.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint8_t AES_decryptDataUsingEncryptionKey(uint16_t baseAddress,
const uint8_t *Data,
uint8_t *decryptedData);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_AES_H__

View File

@@ -0,0 +1,79 @@
//*****************************************************************************
//
// battbak.c - Driver for the battbak Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup battbak_api battbak
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_BATTERY_CHARGER__
#include "battbak.h"
#include <assert.h>
uint16_t BattBak_unlockBackupSubSystem (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_BAKCTL) &= ~(LOCKBAK);
return (HWREG8(baseAddress + OFS_BAKCTL) & LOCKBAK);
}
void BattBak_enableBackupSupplyToADC (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_BAKCTL) |= BAKADC;
}
void BattBak_disableBackupSupplyToADC (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_BAKCTL) &= ~(BAKADC);
}
void BattBak_switchToBackupSupplyManually (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_BAKCTL) |= BAKSW;
}
void BattBak_disable (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_BAKCTL) |= BAKDIS;
}
void BattBak_initAndEnableCharger (uint16_t baseAddress,
uint8_t chargerEndVoltage,
uint8_t chargeCurrent)
{
HWREG16(baseAddress +
OFS_BAKCHCTL) = CHPWD + chargerEndVoltage + chargeCurrent + CHEN;
}
void BattBak_disableCharger (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_BAKCHCTL) = CHPWD;
}
void BattBak_setBackupRAMData (uint16_t baseAddress,
uint8_t backupRAMSelect,
uint16_t data)
{
HWREG16(baseAddress + backupRAMSelect) = data;
}
uint16_t BattBak_getBackupRAMData (uint16_t baseAddress,
uint8_t backupRAMSelect)
{
return ( HWREG16(baseAddress + backupRAMSelect) );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for battbak_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,251 @@
//*****************************************************************************
//
// battbak.h - Driver for the BATTBAK Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_BATTBAK_H__
#define __MSP430WARE_BATTBAK_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_BATTERY_CHARGER__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the BattBak_unlockBackupSubSystem() function.
//
//*****************************************************************************
#define BATTBAK_UNLOCKFAILURE (LOCKBAK)
#define BATTBAK_UNLOCKSUCCESS (0x0)
//*****************************************************************************
//
// The following are values that can be passed to the chargerEndVoltage
// parameter for functions: BattBak_initAndEnableCharger().
//
//*****************************************************************************
#define BATTBAK_CHARGERENDVOLTAGE_VCC (BAKCHV0)
#define BATTBAK_CHARGERENDVOLTAGE2_7V (BAKCHV1)
//*****************************************************************************
//
// The following are values that can be passed to the chargeCurrent parameter
// for functions: BattBak_initAndEnableCharger().
//
//*****************************************************************************
#define BATTBAK_CHARGECURRENT_5KOHM (BAKCHC0)
#define BATTBAK_CHARGECURRENT_10KOHM (BAKCHC1)
#define BATTBAK_CHARGECURRENT_20KOHM (BAKCHC0 + BAKCHC1)
//*****************************************************************************
//
// The following are values that can be passed to the backupRAMSelect parameter
// for functions: BattBak_setBackupRAMData(), and BattBak_getBackupRAMData().
//
//*****************************************************************************
#define BATTBAK_RAMSELECT_0 (0x0000)
#define BATTBAK_RAMSELECT_1 (0x0002)
#define BATTBAK_RAMSELECT_2 (0x0004)
#define BATTBAK_RAMSELECT_3 (0x0006)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Unlocks any pending backup input pins and RTC_B interrupts to be
//! serviced.
//!
//! This function unlocks the ability to view and service any pending backup
//! input pin interrupts, as well as pending RTC_B interrupts. The backup sub-
//! system can only be unlocked when the backup domain has settled, so this
//! function returns the status of the unlock bit after it has been to be
//! verified by user code. Please note, the backup sub-system should only be
//! unlocked after modifying the RTC_B registers.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//!
//! \return One of the following:
//! - \b BATTBAK_UNLOCKFAILURE backup system has not yet settled
//! - \b BATTBAK_UNLOCKSUCCESS successfully unlocked
//! \n indicating if the backup system has been successfully unlocked
//
//*****************************************************************************
extern uint16_t BattBak_unlockBackupSubSystem(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables the backup supply to be measured by the ADC battery monitor
//! input.
//!
//! This function enables the backup supply signal to be monitored by the ADC
//! battery supply monitor input, to allow a measurement of the voltage from
//! the backup battery.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//!
//! \return None
//
//*****************************************************************************
extern void BattBak_enableBackupSupplyToADC(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the backup supply input to the ADC module.
//!
//! This function disables the ability to monitor the backup supply voltage
//! from the ADC battery monitor input.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//!
//! \return None
//
//*****************************************************************************
extern void BattBak_disableBackupSupplyToADC(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Manually switches to backup supply.
//!
//! This function uses software to manually switch to the backup battery
//! supply. Once this bit is set, it will be automatically reset by a POR and
//! the system returns to an automatic switch to backup supply.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//!
//! \return None
//
//*****************************************************************************
extern void BattBak_switchToBackupSupplyManually(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables backup battery system.
//!
//! This function disables the battery backup system from being used. The
//! battery backup system is re-enabled after a power cycle.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//!
//! \return None
//
//*****************************************************************************
extern void BattBak_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Initializes and enables the backup battery charger.
//!
//! This function initializes the backup battery charger with the selected
//! settings.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//! \param chargerEndVoltage is the maximum voltage to charge the backup
//! battery to.
//! Valid values are:
//! - \b BATTBAK_CHARGERENDVOLTAGE_VCC - charges backup battery up to
//! Vcc
//! - \b BATTBAK_CHARGERENDVOLTAGE2_7V - charges backup battery up to
//! 2.7V OR up to Vcc if Vcc is less than 2.7V.
//! \n Modified bits are \b BAKCHVx of \b BAKCHCTL register.
//! \param chargeCurrent is the maximum current to charge the backup battery
//! at.
//! Valid values are:
//! - \b BATTBAK_CHARGECURRENT_5KOHM
//! - \b BATTBAK_CHARGECURRENT_10KOHM
//! - \b BATTBAK_CHARGECURRENT_20KOHM
//! \n Modified bits are \b BAKCHCx of \b BAKCHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void BattBak_initAndEnableCharger(uint16_t baseAddress,
uint8_t chargerEndVoltage,
uint8_t chargeCurrent);
//*****************************************************************************
//
//! \brief Disables and resets backup battery charger settings.
//!
//! This function clears all backup battery charger settings and disables it.
//! To re-enable the charger, a call to BattBak_initAndEnableCharger() is
//! required.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//!
//! \return None
//
//*****************************************************************************
extern void BattBak_disableCharger(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets data into the selected backup RAM space.
//!
//! This function sets the given 16-bit data into the selected backup RAM
//! space.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//! \param backupRAMSelect is the backup RAM space to set data into.
//! Valid values are:
//! - \b BATTBAK_RAMSELECT_0
//! - \b BATTBAK_RAMSELECT_1
//! - \b BATTBAK_RAMSELECT_2
//! - \b BATTBAK_RAMSELECT_3
//! \param data is the data to set into the selected backup RAM space.
//!
//! \return None
//
//*****************************************************************************
extern void BattBak_setBackupRAMData(uint16_t baseAddress,
uint8_t backupRAMSelect,
uint16_t data);
//*****************************************************************************
//
//! \brief Returns the data from the selected backup RAM space.
//!
//! This function returns the 16-bit data currently residing in the selected
//! backup RAM space.
//!
//! \param baseAddress is the base address of the BATTBAK module.
//! \param backupRAMSelect is the backup RAM space to read out from.
//! Valid values are:
//! - \b BATTBAK_RAMSELECT_0
//! - \b BATTBAK_RAMSELECT_1
//! - \b BATTBAK_RAMSELECT_2
//! - \b BATTBAK_RAMSELECT_3
//!
//! \return Data residing in the selected backup RAM space.
//
//*****************************************************************************
extern uint16_t BattBak_getBackupRAMData(uint16_t baseAddress,
uint8_t backupRAMSelect);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_BATTBAK_H__

View File

@@ -0,0 +1,210 @@
//*****************************************************************************
//
// comp_b.c - Driver for the comp_b Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup comp_b_api comp_b
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_COMPB__
#include "comp_b.h"
#include <assert.h>
bool Comp_B_init(uint16_t baseAddress, Comp_B_initParam *param)
{
bool retVal = STATUS_SUCCESS;
//Reset COMPB Control 1 & Interrupt Registers for initialization (OFS_CBCTL3
//is not reset because it controls the input buffers of the analog signals
//and may cause parasitic effects if an analog signal is still attached and
//the buffer is re-enabled
HWREG16(baseAddress + OFS_CBCTL0) &= 0x0000;
HWREG16(baseAddress + OFS_CBINT) &= 0x0000;
//Clear reference voltage and reference source
HWREG16(baseAddress + OFS_CBCTL2) &= ~(CBRS_3 | CBREFL_3);
//Set the Positive Terminal
if(COMP_B_VREF != param->positiveTerminalInput) {
//Enable Positive Terminal Input Mux and Set it to the appropriate input
HWREG16(baseAddress + OFS_CBCTL0) |= CBIPEN + param->positiveTerminalInput;
//Disable the input buffer
HWREG16(baseAddress + OFS_CBCTL3) |= (1 << param->positiveTerminalInput);
}
else {
//Reset and Set COMPB Control 2 Register
//Set Vref to go to (+)terminal
HWREG16(baseAddress + OFS_CBCTL2) &= ~(CBRSEL);
}
//Set the Negative Terminal
if (COMP_B_VREF != param->negativeTerminalInput) {
//Enable Negative Terminal Input Mux and Set it to the appropriate input
HWREG16(baseAddress + OFS_CBCTL0) |= CBIMEN + (param->negativeTerminalInput << 8);
//Disable the input buffer
HWREG16(baseAddress + OFS_CBCTL3) |= (1 << param->negativeTerminalInput);
}
else {
//Reset and Set COMPB Control 2 Register
//Set Vref to go to (-) terminal
HWREG16(baseAddress + OFS_CBCTL2) |= CBRSEL;
}
//Reset and Set COMPB Control 1 Register
HWREG16(baseAddress + OFS_CBCTL1) =
param->powerModeSelect //Set the power mode
+ param->outputFilterEnableAndDelayLevel //Set the filter enable bit and delay
+ param->invertedOutputPolarity; //Set the polarity of the output
return (retVal);
}
void Comp_B_configureReferenceVoltage(uint16_t baseAddress,
Comp_B_configureReferenceVoltageParam *param)
{
//Set to VREF0
HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBMRVS);
//Reset COMPB Control 2 Bits (Except for CBRSEL which is set in Comp_Init())
HWREG16(baseAddress + OFS_CBCTL2) &= CBRSEL;
//Set Voltage Source (Vcc | Vref, resistor ladder or not)
if (COMP_B_VREFBASE_VCC == param->supplyVoltageReferenceBase) {
HWREG16(baseAddress + OFS_CBCTL2) |= CBRS_1; //Vcc with resistor ladder
}
else if (param->lowerLimitSupplyVoltageFractionOf32 == 32) {
//If the lower limit is 32, then the upper limit has to be 32 due to the
//assertion that upper must be >= to the lower limit. If the numerator is
//equal to 32, then the equation would be 32/32 == 1, therefore no resistor
//ladder is needed
HWREG16(baseAddress + OFS_CBCTL2) |= CBRS_3; //Vref, no resistor ladder
}
else {
HWREG16(baseAddress + OFS_CBCTL2) |= CBRS_2; //Vref with resistor ladder
}
//Set COMPD Control 2 Register
HWREG16(baseAddress + OFS_CBCTL2) |=
param->supplyVoltageReferenceBase //Set Supply Voltage Base
+ ((param->upperLimitSupplyVoltageFractionOf32 - 1) << 8) //Set Supply Voltage Num.
+ (param->lowerLimitSupplyVoltageFractionOf32 - 1);
HWREG16(baseAddress + OFS_CBCTL2) &= ~(CBREFACC);
HWREG16(baseAddress + OFS_CBCTL2) |= param->referenceAccuracy;
}
void Comp_B_enableInterrupt(uint16_t baseAddress,
uint16_t interruptMask)
{
//Set the Interrupt enable bit
HWREG16(baseAddress + OFS_CBINT) |= interruptMask;
}
void Comp_B_disableInterrupt(uint16_t baseAddress,
uint16_t interruptMask)
{
HWREG16(baseAddress + OFS_CBINT) &= ~(interruptMask);
}
void Comp_B_clearInterrupt(uint16_t baseAddress,
uint16_t interruptFlagMask)
{
HWREG16(baseAddress + OFS_CBINT) &= ~(interruptFlagMask);
}
uint8_t Comp_B_getInterruptStatus(uint16_t baseAddress,
uint16_t interruptFlagMask)
{
return(HWREG16(baseAddress + OFS_CBINT) & interruptFlagMask);
}
void Comp_B_setInterruptEdgeDirection(uint16_t baseAddress,
uint16_t edgeDirection)
{
//Set the edge direction that will trigger an interrupt
if(COMP_B_RISINGEDGE == edgeDirection) {
HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBIES);
}
else if(COMP_B_FALLINGEDGE == edgeDirection) {
HWREG16(baseAddress + OFS_CBCTL1) |= CBIES;
}
}
void Comp_B_toggleInterruptEdgeDirection(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_CBCTL1) ^= CBIES;
}
void Comp_B_enable(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_CBCTL1) |= CBON;
}
void Comp_B_disable(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBON);
}
void Comp_B_shortInputs(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_CBCTL1) |= CBSHORT;
}
void Comp_B_unshortInputs(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBSHORT);
}
void Comp_B_disableInputBuffer(uint16_t baseAddress,
uint8_t inputPort)
{
HWREG16(baseAddress + OFS_CBCTL3) |= (1 << inputPort);
}
void Comp_B_enableInputBuffer(uint16_t baseAddress,
uint8_t inputPort)
{
HWREG16(baseAddress + OFS_CBCTL3) &= ~(1 << inputPort);
}
void Comp_B_swapIO(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_CBCTL1) ^= CBEX;
}
uint16_t Comp_B_outputValue(uint16_t baseAddress)
{
return (HWREG16(baseAddress + OFS_CBCTL1) & CBOUT);
}
void Comp_B_selectReferenceVoltage(uint16_t baseAddress, uint16_t selectType,
uint16_t selectVRef)
{
HWREG16(baseAddress + OFS_CBCTL1) &= ~(CBMRVS | CBMRVL);
if(selectType == COMP_B_VREF_MANUAL_SELECT) {
HWREG16(baseAddress + OFS_CBCTL1) |= CBMRVS;
if(selectVRef == COMP_B_SELECT_VREF1) {
HWREG16(baseAddress + OFS_CBCTL1) |= CBMRVL;
}
}
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for comp_b_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,649 @@
//*****************************************************************************
//
// comp_b.h - Driver for the COMP_B Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_COMP_B_H__
#define __MSP430WARE_COMP_B_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_COMPB__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the Comp_B_init() function as the param parameter.
//
//*****************************************************************************
typedef struct Comp_B_initParam {
//! Selects the input to the positive terminal.
//! \n Valid values are:
//! - \b COMP_B_INPUT0 [Default]
//! - \b COMP_B_INPUT1
//! - \b COMP_B_INPUT2
//! - \b COMP_B_INPUT3
//! - \b COMP_B_INPUT4
//! - \b COMP_B_INPUT5
//! - \b COMP_B_INPUT6
//! - \b COMP_B_INPUT7
//! - \b COMP_B_INPUT8
//! - \b COMP_B_INPUT9
//! - \b COMP_B_INPUT10
//! - \b COMP_B_INPUT11
//! - \b COMP_B_INPUT12
//! - \b COMP_B_INPUT13
//! - \b COMP_B_INPUT14
//! - \b COMP_B_INPUT15
//! - \b COMP_B_VREF
uint8_t positiveTerminalInput;
//! Selects the input to the negative terminal.
//! \n Valid values are:
//! - \b COMP_B_INPUT0 [Default]
//! - \b COMP_B_INPUT1
//! - \b COMP_B_INPUT2
//! - \b COMP_B_INPUT3
//! - \b COMP_B_INPUT4
//! - \b COMP_B_INPUT5
//! - \b COMP_B_INPUT6
//! - \b COMP_B_INPUT7
//! - \b COMP_B_INPUT8
//! - \b COMP_B_INPUT9
//! - \b COMP_B_INPUT10
//! - \b COMP_B_INPUT11
//! - \b COMP_B_INPUT12
//! - \b COMP_B_INPUT13
//! - \b COMP_B_INPUT14
//! - \b COMP_B_INPUT15
//! - \b COMP_B_VREF
uint8_t negativeTerminalInput;
//! Selects the power mode at which the Comp_B module will operate at.
//! \n Valid values are:
//! - \b COMP_B_POWERMODE_HIGHSPEED [Default]
//! - \b COMP_B_POWERMODE_NORMALMODE
//! - \b COMP_B_POWERMODE_ULTRALOWPOWER
uint16_t powerModeSelect;
//! Controls the output filter delay state, which is either off or enabled
//! with a specified delay level. This parameter is device specific and
//! delay levels should be found in the device's datasheet.
//! \n Valid values are:
//! - \b COMP_B_FILTEROUTPUT_OFF [Default]
//! - \b COMP_B_FILTEROUTPUT_DLYLVL1
//! - \b COMP_B_FILTEROUTPUT_DLYLVL2
//! - \b COMP_B_FILTEROUTPUT_DLYLVL3
//! - \b COMP_B_FILTEROUTPUT_DLYLVL4
uint8_t outputFilterEnableAndDelayLevel;
//! Controls if the output will be inverted or not
//! \n Valid values are:
//! - \b COMP_B_NORMALOUTPUTPOLARITY [Default]
//! - \b COMP_B_INVERTEDOUTPUTPOLARITY
uint16_t invertedOutputPolarity;
} Comp_B_initParam;
//*****************************************************************************
//
//! \brief Used in the Comp_B_configureReferenceVoltage() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct Comp_B_configureReferenceVoltageParam {
//! Decides the source and max amount of Voltage that can be used as a
//! reference.
//! \n Valid values are:
//! - \b COMP_B_VREFBASE_VCC
//! - \b COMP_B_VREFBASE1_5V
//! - \b COMP_B_VREFBASE2_0V
//! - \b COMP_B_VREFBASE2_5V
uint16_t supplyVoltageReferenceBase;
//! Is the numerator of the equation to generate the reference voltage for
//! the lower limit reference voltage.
uint16_t lowerLimitSupplyVoltageFractionOf32;
//! Is the numerator of the equation to generate the reference voltage for
//! the upper limit reference voltage.
uint16_t upperLimitSupplyVoltageFractionOf32;
//! is the reference accuracy setting of the Comp_B. Clocked is for low
//! power/low accuracy.
//! \n Valid values are:
//! - \b COMP_B_ACCURACY_STATIC
//! - \b COMP_B_ACCURACY_CLOCKED
uint16_t referenceAccuracy;
} Comp_B_configureReferenceVoltageParam;
//*****************************************************************************
//
// The following are values that can be passed to the powerModeSelect parameter
// for functions: Comp_B_init(); the param parameter for functions:
// Comp_B_init().
//
//*****************************************************************************
#define COMP_B_POWERMODE_HIGHSPEED (CBPWRMD_0)
#define COMP_B_POWERMODE_NORMALMODE (CBPWRMD_1)
#define COMP_B_POWERMODE_ULTRALOWPOWER (CBPWRMD_2)
//*****************************************************************************
//
// The following are values that can be passed to the positiveTerminalInput
// parameter for functions: Comp_B_init(); the inputPort parameter for
// functions: Comp_B_disableInputBuffer(), and Comp_B_enableInputBuffer(); the
// param parameter for functions: Comp_B_init(), and Comp_B_init(); the
// negativeTerminalInput parameter for functions: Comp_B_init().
//
//*****************************************************************************
#define COMP_B_INPUT0 (CBIPSEL_0)
#define COMP_B_INPUT1 (CBIPSEL_1)
#define COMP_B_INPUT2 (CBIPSEL_2)
#define COMP_B_INPUT3 (CBIPSEL_3)
#define COMP_B_INPUT4 (CBIPSEL_4)
#define COMP_B_INPUT5 (CBIPSEL_5)
#define COMP_B_INPUT6 (CBIPSEL_6)
#define COMP_B_INPUT7 (CBIPSEL_7)
#define COMP_B_INPUT8 (CBIPSEL_8)
#define COMP_B_INPUT9 (CBIPSEL_9)
#define COMP_B_INPUT10 (CBIPSEL_10)
#define COMP_B_INPUT11 (CBIPSEL_11)
#define COMP_B_INPUT12 (CBIPSEL_12)
#define COMP_B_INPUT13 (CBIPSEL_13)
#define COMP_B_INPUT14 (CBIPSEL_14)
#define COMP_B_INPUT15 (CBIPSEL_15)
#define COMP_B_VREF (0x10)
//*****************************************************************************
//
// The following are values that can be passed to the
// outputFilterEnableAndDelayLevel parameter for functions: Comp_B_init(); the
// param parameter for functions: Comp_B_init().
//
//*****************************************************************************
#define COMP_B_FILTEROUTPUT_OFF 0x00
#define COMP_B_FILTEROUTPUT_DLYLVL1 (CBF + CBFDLY_0)
#define COMP_B_FILTEROUTPUT_DLYLVL2 (CBF + CBFDLY_1)
#define COMP_B_FILTEROUTPUT_DLYLVL3 (CBF + CBFDLY_2)
#define COMP_B_FILTEROUTPUT_DLYLVL4 (CBF + CBFDLY_3)
//*****************************************************************************
//
// The following are values that can be passed to the invertedOutputPolarity
// parameter for functions: Comp_B_init(); the param parameter for functions:
// Comp_B_init().
//
//*****************************************************************************
#define COMP_B_NORMALOUTPUTPOLARITY (!(CBOUTPOL))
#define COMP_B_INVERTEDOUTPUTPOLARITY (CBOUTPOL)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: Comp_B_configureReferenceVoltage().
//
//*****************************************************************************
#define COMP_B_ACCURACY_STATIC (!CBREFACC)
#define COMP_B_ACCURACY_CLOCKED (CBREFACC)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: Comp_B_configureReferenceVoltage().
//
//*****************************************************************************
#define COMP_B_VREFBASE_VCC (CBREFL_0)
#define COMP_B_VREFBASE1_5V (CBREFL_1)
#define COMP_B_VREFBASE2_0V (CBREFL_2)
#define COMP_B_VREFBASE2_5V (CBREFL_3)
//*****************************************************************************
//
// The following are values that can be passed to the interruptMask parameter
// for functions: Comp_B_enableInterrupt(), and Comp_B_disableInterrupt().
//
//*****************************************************************************
#define COMP_B_OUTPUT_INT CBIE
#define COMP_B_OUTPUTINVERTED_INT CBIIE
//*****************************************************************************
//
// The following are values that can be passed to the interruptFlagMask
// parameter for functions: Comp_B_clearInterrupt(), and
// Comp_B_getInterruptStatus() as well as returned by the
// Comp_B_getInterruptStatus() function.
//
//*****************************************************************************
#define COMP_B_OUTPUT_FLAG CBIFG
#define COMP_B_OUTPUTINVERTED_FLAG CBIIFG
//*****************************************************************************
//
// The following are values that can be passed to the edgeDirection parameter
// for functions: Comp_B_setInterruptEdgeDirection().
//
//*****************************************************************************
#define COMP_B_RISINGEDGE (!(CBIES))
#define COMP_B_FALLINGEDGE (CBIES)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the Comp_B_outputValue() function.
//
//*****************************************************************************
#define COMP_B_LOW (0x0)
#define COMP_B_HIGH (CBOUT)
//*****************************************************************************
//
// The following are values that can be passed to the selectType parameter for
// functions: Comp_B_selectReferenceVoltage().
//
//*****************************************************************************
#define COMP_B_VREF_AUTO_SELECT 0x0000
#define COMP_B_VREF_MANUAL_SELECT CBMRVS
//*****************************************************************************
//
// The following are values that can be passed to the selectVRef parameter for
// functions: Comp_B_selectReferenceVoltage().
//
//*****************************************************************************
#define COMP_B_SELECT_VREF0 0x0000
#define COMP_B_SELECT_VREF1 CBMRVL
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the Comp_B Module.
//!
//! Upon successful initialization of the Comp_B module, this function will
//! have reset all necessary register bits and set the given options in the
//! registers. To actually use the Comp_B module, the Comp_B_enable() function
//! must be explicitly called before use. If a Reference Voltage is set to a
//! terminal, the Voltage should be set using the Comp_B_setReferenceVoltage()
//! function.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param param is the pointer to struct for initialization.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the initialization process.
//
//*****************************************************************************
extern bool Comp_B_init(uint16_t baseAddress,
Comp_B_initParam *param);
//*****************************************************************************
//
//! \brief Generates a Reference Voltage to the terminal selected during
//! initialization.
//!
//! Use this function to generate a voltage to serve as a reference to the
//! terminal selected at initialization. The voltage is determined by the
//! equation: Vbase * (Numerator / 32). If the upper and lower limit voltage
//! numerators are equal, then a static reference is defined, whereas they are
//! different then a hysteresis effect is generated.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param param is the pointer to struct for reference voltage configuration.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_configureReferenceVoltage(uint16_t baseAddress,
Comp_B_configureReferenceVoltageParam *param);
//*****************************************************************************
//
//! \brief Enables selected Comp_B interrupt sources.
//!
//! Enables the indicated Comp_B interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param interruptMask is the bit mask of the interrupt sources to be
//! enabled.
//! Mask value is the logical OR of any of the following:
//! - \b COMP_B_OUTPUT_INT - Output interrupt
//! - \b COMP_B_OUTPUTINVERTED_INT - Output interrupt inverted polarity
//! \n Modified bits of \b CBINT register.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_enableInterrupt(uint16_t baseAddress,
uint16_t interruptMask);
//*****************************************************************************
//
//! \brief Disables selected Comp_B interrupt sources.
//!
//! Disables the indicated Comp_B interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param interruptMask is the bit mask of the interrupt sources to be
//! disabled.
//! Mask value is the logical OR of any of the following:
//! - \b COMP_B_OUTPUT_INT - Output interrupt
//! - \b COMP_B_OUTPUTINVERTED_INT - Output interrupt inverted polarity
//! \n Modified bits of \b CBINT register.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_disableInterrupt(uint16_t baseAddress,
uint16_t interruptMask);
//*****************************************************************************
//
//! \brief Clears Comp_B interrupt flags.
//!
//! The Comp_B interrupt source is cleared, so that it no longer asserts. The
//! highest interrupt flag is automatically cleared when an interrupt vector
//! generator is used.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param interruptFlagMask is a bit mask of the interrupt sources to be
//! cleared.
//! Mask value is the logical OR of any of the following:
//! - \b COMP_B_OUTPUT_FLAG - Output interrupt
//! - \b COMP_B_OUTPUTINVERTED_FLAG - Output interrupt inverted polarity
//! \n Modified bits of \b CBINT register.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_clearInterrupt(uint16_t baseAddress,
uint16_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Gets the current Comp_B interrupt status.
//!
//! This returns the interrupt status for the Comp_B module based on which flag
//! is passed.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param interruptFlagMask is the masked interrupt flag status to be
//! returned.
//! Mask value is the logical OR of any of the following:
//! - \b COMP_B_OUTPUT_FLAG - Output interrupt
//! - \b COMP_B_OUTPUTINVERTED_FLAG - Output interrupt inverted polarity
//!
//! \return Logical OR of any of the following:
//! - \b COMP_B_OUTPUT_FLAG Output interrupt
//! - \b COMP_B_OUTPUTINVERTED_FLAG Output interrupt inverted polarity
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t Comp_B_getInterruptStatus(uint16_t baseAddress,
uint16_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Explicitly sets the edge direction that would trigger an interrupt.
//!
//! This function will set which direction the output will have to go, whether
//! rising or falling, to generate an interrupt based on a non-inverted
//! interrupt.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param edgeDirection determines which direction the edge would have to go
//! to generate an interrupt based on the non-inverted interrupt flag.
//! Valid values are:
//! - \b COMP_B_RISINGEDGE [Default] - sets the bit to generate an
//! interrupt when the output of the Comp_B falls from LOW to HIGH if
//! the normal interrupt bit is set(and HIGH to LOW if the inverted
//! interrupt enable bit is set).
//! - \b COMP_B_FALLINGEDGE - sets the bit to generate an interrupt when
//! the output of the Comp_B rises from HIGH to LOW if the normal
//! interrupt bit is set(and LOW to HIGH if the inverted interrupt
//! enable bit is set).
//! \n Modified bits are \b CBIES of \b CBCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_setInterruptEdgeDirection(uint16_t baseAddress,
uint16_t edgeDirection);
//*****************************************************************************
//
//! \brief Toggles the edge direction that would trigger an interrupt.
//!
//! This function will toggle which direction the output will have to go,
//! whether rising or falling, to generate an interrupt based on a non-inverted
//! interrupt. If the direction was rising, it is now falling, if it was
//! falling, it is now rising.
//!
//! \param baseAddress is the base address of the COMP_B module.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_toggleInterruptEdgeDirection(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Turns on the Comp_B module.
//!
//! This function sets the bit that enables the operation of the Comp_B module.
//!
//! \param baseAddress is the base address of the COMP_B module.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Turns off the Comp_B module.
//!
//! This function clears the CBON bit disabling the operation of the Comp_B
//! module, saving from excess power consumption.
//!
//! \param baseAddress is the base address of the COMP_B module.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Shorts the two input pins chosen during initialization.
//!
//! This function sets the bit that shorts the devices attached to the input
//! pins chosen from the initialization of the Comp_B.
//!
//! \param baseAddress is the base address of the COMP_B module.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_shortInputs(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the short of the two input pins chosen during
//! initialization.
//!
//! This function clears the bit that shorts the devices attached to the input
//! pins chosen from the initialization of the Comp_B.
//!
//! \param baseAddress is the base address of the COMP_B module.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_unshortInputs(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the input buffer of the selected input port to effectively
//! allow for analog signals.
//!
//! This function sets the bit to disable the buffer for the specified input
//! port to allow for analog signals from any of the Comp_B input pins. This
//! bit is automatically set when the input is initialized to be used with the
//! Comp_B module. This function should be used whenever an analog input is
//! connected to one of these pins to prevent parasitic voltage from causing
//! unexpected results.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param inputPort is the port in which the input buffer will be disabled.
//! Valid values are:
//! - \b COMP_B_INPUT0 [Default]
//! - \b COMP_B_INPUT1
//! - \b COMP_B_INPUT2
//! - \b COMP_B_INPUT3
//! - \b COMP_B_INPUT4
//! - \b COMP_B_INPUT5
//! - \b COMP_B_INPUT6
//! - \b COMP_B_INPUT7
//! - \b COMP_B_INPUT8
//! - \b COMP_B_INPUT9
//! - \b COMP_B_INPUT10
//! - \b COMP_B_INPUT11
//! - \b COMP_B_INPUT12
//! - \b COMP_B_INPUT13
//! - \b COMP_B_INPUT14
//! - \b COMP_B_INPUT15
//! - \b COMP_B_VREF
//! \n Modified bits are \b CBPDx of \b CBCTL3 register.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_disableInputBuffer(uint16_t baseAddress,
uint8_t inputPort);
//*****************************************************************************
//
//! \brief Enables the input buffer of the selected input port to allow for
//! digital signals.
//!
//! This function clears the bit to enable the buffer for the specified input
//! port to allow for digital signals from any of the Comp_B input pins. This
//! should not be reset if there is an analog signal connected to the specified
//! input pin to prevent from unexpected results.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param inputPort is the port in which the input buffer will be enabled.
//! Valid values are:
//! - \b COMP_B_INPUT0 [Default]
//! - \b COMP_B_INPUT1
//! - \b COMP_B_INPUT2
//! - \b COMP_B_INPUT3
//! - \b COMP_B_INPUT4
//! - \b COMP_B_INPUT5
//! - \b COMP_B_INPUT6
//! - \b COMP_B_INPUT7
//! - \b COMP_B_INPUT8
//! - \b COMP_B_INPUT9
//! - \b COMP_B_INPUT10
//! - \b COMP_B_INPUT11
//! - \b COMP_B_INPUT12
//! - \b COMP_B_INPUT13
//! - \b COMP_B_INPUT14
//! - \b COMP_B_INPUT15
//! - \b COMP_B_VREF
//! \n Modified bits are \b CBPDx of \b CBCTL3 register.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_enableInputBuffer(uint16_t baseAddress,
uint8_t inputPort);
//*****************************************************************************
//
//! \brief Toggles the bit that swaps which terminals the inputs go to, while
//! also inverting the output of the Comp_B.
//!
//! This function toggles the bit that controls which input goes to which
//! terminal. After initialization, this bit is set to 0, after toggling it
//! once the inputs are routed to the opposite terminal and the output is
//! inverted.
//!
//! \param baseAddress is the base address of the COMP_B module.
//!
//! \return None
//
//*****************************************************************************
extern void Comp_B_swapIO(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the output value of the Comp_B module.
//!
//! Returns the output value of the Comp_B module.
//!
//! \param baseAddress is the base address of the COMP_B module.
//!
//! \return One of the following:
//! - \b COMP_B_LOW
//! - \b COMP_B_HIGH
//! \n indicating the output value of the Comp_B module
//
//*****************************************************************************
extern uint16_t Comp_B_outputValue(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Modifies how comparator output selects between VREF0 or VREF1.
//!
//! Only applicable in certain Comp_B reference sources. Consult
//! Comp_B_configureReferenceVoltage for details. If COMP_B_VREF_AUTO_SELECT,
//! then comparator output state chooses between VREF0 and VREF1. If
//! COMP_B_VREF_MANUAL_SELECT, then selectVRef param chooses.
//!
//! \param baseAddress is the base address of the COMP_B module.
//! \param selectType determines whether VREF instance is chosen automatically
//! or manually
//! Valid values are:
//! - \b COMP_B_VREF_AUTO_SELECT [Default] - VREF instance is chosen by
//! comparator output state.
//! - \b COMP_B_VREF_MANUAL_SELECT - VREF instance is chosen by user
//! (CBCTL1. CBMRVL bit)
//! \n Modified bits are \b CBMRVS of \b CBCTL1 register.
//! \param selectVRef selects VREF0 or VREF1. Only applicable if VREF instance
//! is set up to be chosen manually
//! Valid values are:
//! - \b COMP_B_SELECT_VREF0 [Default]
//! - \b COMP_B_SELECT_VREF1
//! \n Modified bits are \b CBMRVL of \b CBCTL1 register.
//!
//
//*****************************************************************************
extern void Comp_B_selectReferenceVoltage(uint16_t baseAddress,
uint16_t selectType,
uint16_t selectVRef);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_COMP_B_H__

View File

@@ -0,0 +1,72 @@
//*****************************************************************************
//
// crc.c - Driver for the crc Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup crc_api crc
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_CRC__
#include "crc.h"
#include <assert.h>
void CRC_setSeed (uint16_t baseAddress,
uint16_t seed)
{
HWREG16(baseAddress + OFS_CRCINIRES) = seed;
}
void CRC_set16BitData (uint16_t baseAddress,
uint16_t dataIn)
{
HWREG16(baseAddress + OFS_CRCDI) = dataIn;
}
void CRC_set8BitData (uint16_t baseAddress,
uint8_t dataIn)
{
HWREG8(baseAddress + OFS_CRCDI_L) = dataIn;
}
void CRC_set16BitDataReversed (uint16_t baseAddress,
uint16_t dataIn)
{
HWREG16(baseAddress + OFS_CRCDIRB) = dataIn;
}
void CRC_set8BitDataReversed (uint16_t baseAddress,
uint8_t dataIn)
{
HWREG8(baseAddress + OFS_CRCDIRB_L) = dataIn;
}
uint16_t CRC_getData (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_CRCDI) );
}
uint16_t CRC_getResult (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_CRCINIRES) );
}
uint16_t CRC_getResultBitsReversed (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_CRCRESR) );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for crc_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,178 @@
//*****************************************************************************
//
// crc.h - Driver for the CRC Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_CRC_H__
#define __MSP430WARE_CRC_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_CRC__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Sets the seed for the CRC.
//!
//! This function sets the seed for the CRC to begin generating a signature
//! with the given seed and all passed data. Using this function resets the CRC
//! signature.
//!
//! \param baseAddress is the base address of the CRC module.
//! \param seed is the seed for the CRC to start generating a signature from.
//! \n Modified bits are \b CRCINIRES of \b CRCINIRES register.
//!
//! \return None
//
//*****************************************************************************
extern void CRC_setSeed(uint16_t baseAddress,
uint16_t seed);
//*****************************************************************************
//
//! \brief Sets the 16 bit data to add into the CRC module to generate a new
//! signature.
//!
//! This function sets the given data into the CRC module to generate the new
//! signature from the current signature and new data.
//!
//! \param baseAddress is the base address of the CRC module.
//! \param dataIn is the data to be added, through the CRC module, to the
//! signature.
//! \n Modified bits are \b CRCDI of \b CRCDI register.
//!
//! \return None
//
//*****************************************************************************
extern void CRC_set16BitData(uint16_t baseAddress,
uint16_t dataIn);
//*****************************************************************************
//
//! \brief Sets the 8 bit data to add into the CRC module to generate a new
//! signature.
//!
//! This function sets the given data into the CRC module to generate the new
//! signature from the current signature and new data.
//!
//! \param baseAddress is the base address of the CRC module.
//! \param dataIn is the data to be added, through the CRC module, to the
//! signature.
//! \n Modified bits are \b CRCDI of \b CRCDI register.
//!
//! \return None
//
//*****************************************************************************
extern void CRC_set8BitData(uint16_t baseAddress,
uint8_t dataIn);
//*****************************************************************************
//
//! \brief Translates the 16 bit data by reversing the bits in each byte and
//! then sets this data to add into the CRC module to generate a new signature.
//!
//! This function first reverses the bits in each byte of the data and then
//! generates the new signature from the current signature and new translated
//! data.
//!
//! \param baseAddress is the base address of the CRC module.
//! \param dataIn is the data to be added, through the CRC module, to the
//! signature.
//! \n Modified bits are \b CRCDIRB of \b CRCDIRB register.
//!
//! \return None
//
//*****************************************************************************
extern void CRC_set16BitDataReversed(uint16_t baseAddress,
uint16_t dataIn);
//*****************************************************************************
//
//! \brief Translates the 8 bit data by reversing the bits in each byte and
//! then sets this data to add into the CRC module to generate a new signature.
//!
//! This function first reverses the bits in each byte of the data and then
//! generates the new signature from the current signature and new translated
//! data.
//!
//! \param baseAddress is the base address of the CRC module.
//! \param dataIn is the data to be added, through the CRC module, to the
//! signature.
//! \n Modified bits are \b CRCDIRB of \b CRCDIRB register.
//!
//! \return None
//
//*****************************************************************************
extern void CRC_set8BitDataReversed(uint16_t baseAddress,
uint8_t dataIn);
//*****************************************************************************
//
//! \brief Returns the value currently in the Data register.
//!
//! This function returns the value currently in the data register. If set in
//! byte bits reversed format, then the translated data would be returned.
//!
//! \param baseAddress is the base address of the CRC module.
//!
//! \return The value currently in the data register
//
//*****************************************************************************
extern uint16_t CRC_getData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the value pf the Signature Result.
//!
//! This function returns the value of the signature result generated by the
//! CRC.
//!
//! \param baseAddress is the base address of the CRC module.
//!
//! \return The value currently in the data register
//
//*****************************************************************************
extern uint16_t CRC_getResult(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the bit-wise reversed format of the Signature Result.
//!
//! This function returns the bit-wise reversed format of the Signature Result.
//!
//! \param baseAddress is the base address of the CRC module.
//!
//! \return The bit-wise reversed format of the Signature Result
//
//*****************************************************************************
extern uint16_t CRC_getResultBitsReversed(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_CRC_H__

View File

@@ -0,0 +1,281 @@
//*****************************************************************************
//
// ctsd16.c - Driver for the ctsd16 Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup ctsd16_api ctsd16
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_CTSD16__
#include "ctsd16.h"
#include <assert.h>
void CTSD16_init(uint16_t baseAddress, uint16_t chargePumpBurstRequest,
uint8_t referenceSelect)
{
// Reset all interrupts and flags
HWREG16(baseAddress + OFS_CTSD16IE) &= 0x0000; //Reset ALL interrupt enables
HWREG16(baseAddress + OFS_CTSD16IFG) &= 0x0000; //Reset ALL interrupt flags
// Configure CTSD16
HWREG16(baseAddress + OFS_CTSD16CTL) &= ~(CTSD16RRIBURST | CTSD16OFFG |
CTSD16REFS);
HWREG16(baseAddress + OFS_CTSD16CTL) |= chargePumpBurstRequest | referenceSelect;
return;
}
void CTSD16_initConverter(uint16_t baseAddress, uint8_t converter,
uint16_t conversionMode, uint8_t inputChannel)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x06));
// Clearing previous settings for configuration
HWREG16(address) &= ~(CTSD16SC | CTSD16SNGL);
HWREG16(address) |= conversionMode;
address += 0x2;
HWREG16(address) &= ~(CTSD16INCH4 | CTSD16INCH3 | CTSD16INCH2 |
CTSD16INCH1 | CTSD16INCH0);
HWREG16(address) |= inputChannel;
}
void CTSD16_initConverterAdvanced(uint16_t baseAddress,
CTSD16_initConverterAdvancedParam *param)
{
uint16_t address;
// Getting correct CTSD16CCTLx register
address = baseAddress + (OFS_CTSD16CCTL0 + (param->converter * 0x06));
// Clearing previous settings for configuration
HWREG16(address) &= ~(CTSD16SC | CTSD16SNGL | CTSD16GRP | CTSD16OSR__32 |
CTSD16DF);
HWREG16(address) |= (param->groupEnable | param->conversionMode | param->oversampleRatio | param->dataFormat);
// Getting correct CTSD16INCTLx register
address += 0x2;
HWREG16(address) &= ~(CTSD16RRI | CTSD16INTDLY | CTSD16GAIN2 |
CTSD16GAIN1 | CTSD16GAIN0 | CTSD16INCH4 | CTSD16INCH3 | CTSD16INCH2 |
CTSD16INCH1 | CTSD16INCH0);
HWREG16(address) |= (param->railToRailInput | param->interruptDelay |
param->gain | param->inputChannel);
}
void CTSD16_startConverterConversion(uint16_t baseAddress,
uint8_t converter)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x06));
// Setting CTSD16SC bit to start conversion
HWREG16(address) |= CTSD16SC;
}
void CTSD16_stopConverterConversion(uint16_t baseAddress,
uint8_t converter)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x06));
// Setting CTSD16SC bit to start conversion
HWREG16(address) &= ~(CTSD16SC);
}
void CTSD16_setConverterDataFormat(uint16_t baseAddress,
uint8_t converter,
uint8_t dataFormat)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x06));
// Clearing previous settings for configuration
HWREG8(address) &= ~CTSD16DF;
HWREG8(address) |= dataFormat;
}
void CTSD16_setInputChannel(uint16_t baseAddress,
uint8_t converter,
uint8_t inputChannel)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16INCTL0 + (converter * 0x06));
// Clear previous settings
HWREG16(address) &= ~(CTSD16INCH4 | CTSD16INCH3 | CTSD16INCH2 |
CTSD16INCH1 | CTSD16INCH0);
HWREG16(address) |= inputChannel;
}
void CTSD16_setRailToRailInput(uint16_t baseAddress,
uint8_t converter,
uint16_t railToRailInput)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16INCTL0 + (converter * 0x06));
// Clear previous settings
HWREG16(address) &= ~CTSD16RRI;
HWREG16(address) |= railToRailInput;
}
void CTSD16_setInterruptDelay(uint16_t baseAddress,
uint8_t converter,
uint16_t interruptDelay)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16INCTL0 + (converter * 0x06));
// Clear previous settings
HWREG16(address) &= ~CTSD16INTDLY;
HWREG16(address) |= interruptDelay;
}
void CTSD16_setOversampling(uint16_t baseAddress,
uint8_t converter,
uint16_t oversampleRatio)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x06));
// Setting CTSD16SC bit to start conversion
HWREG16(address) |= oversampleRatio;
}
void CTSD16_setGain(uint16_t baseAddress,
uint8_t converter,
uint8_t gain)
{
uint16_t address;
address = baseAddress + (OFS_CTSD16INCTL0 + (converter * 0x06));
// Clear previous settings
HWREG16(address) &= ~(CTSD16GAIN2 | CTSD16GAIN1 | CTSD16GAIN0);
HWREG16(address) |= gain;
}
uint32_t CTSD16_getResults(uint16_t baseAddress,
uint8_t converter)
{
volatile uint16_t OSR;
uint16_t address = baseAddress + (OFS_CTSD16MEM0 + (converter * 0x02));
// Get high word result
HWREG16(baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x02))) &= ~(CTSD16LSBACC);
uint32_t highResult = (uint32_t)HWREG16(address);
// Get low word result
HWREG16(baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x02))) |= CTSD16LSBACC;
uint16_t lowResult = HWREG16(address);
HWREG16(baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x02))) &= ~(CTSD16LSBACC);
// Determine the OSR and combine the high and low result words as appropriate
OSR = HWREG16(baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x02))) & (CTSD16OSR0 | CTSD16OSR1);
if(OSR == CTSD16_OVERSAMPLE_256)
{
return (highResult << 8) | lowResult;
}
else if(OSR == CTSD16_OVERSAMPLE_128)
{
return (highResult << 5) | lowResult;
}
else if(OSR == CTSD16_OVERSAMPLE_64)
{
return (highResult << 2) | lowResult;
}
else // OSR = CTSD16_OVERSAMPLE_32
{
return (highResult);
}
}
uint16_t CTSD16_getHighWordResults(uint16_t baseAddress,
uint8_t converter)
{
// Calculate address of MEM results
uint16_t address = baseAddress + (OFS_CTSD16MEM0 + (converter * 0x02));
// Get high word result
HWREG16(baseAddress + (OFS_CTSD16CCTL0 + (converter * 0x02))) &= ~(CTSD16LSBACC);
uint16_t highResult = HWREG16(address);
return(highResult);
}
uint16_t CTSD16_isRailToRailInputReady(uint16_t baseAddress)
{
return HWREG16(baseAddress + OFS_CTSD16CTL) & CTSD16RRIRDY;
}
void CTSD16_enableInterrupt (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
//Enable Interrupt
HWREG16(baseAddress + OFS_CTSD16IE) |= (mask << converter);
}
void CTSD16_disableInterrupt (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
//Enable Interrupt
HWREG16(baseAddress + OFS_CTSD16IE) &= ~(mask << converter);
}
void CTSD16_clearInterrupt (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
HWREG16(baseAddress + OFS_CTSD16IFG) &= ~(mask << converter);
}
uint16_t CTSD16_getInterruptStatus (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
return ( HWREG16(baseAddress + OFS_CTSD16IFG) & (mask << converter) );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for ctsd16_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,827 @@
//*****************************************************************************
//
// ctsd16.h - Driver for the CTSD16 Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_CTSD16_H__
#define __MSP430WARE_CTSD16_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_CTSD16__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the CTSD16_initConverterAdvanced() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct CTSD16_initConverterAdvancedParam {
//! The converter to initialize.
//! \n Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
uint8_t converter;
//! Determines whether the converter will do continuous samples or a single
//! sample
//! \n Valid values are:
//! - \b CTSD16_CONTINUOUS_MODE [Default]
//! - \b CTSD16_SINGLE_MODE
uint16_t conversionMode;
//! \n Valid values are:
//! - \b CTSD16_NOT_GROUPED
//! - \b CTSD16_GROUPED [Default]
uint8_t groupEnable;
//! Selects oversampling ratio for the converter
//! \n Valid values are:
//! - \b CTSD16_INPUT_CH0
//! - \b CTSD16_INPUT_CH1
//! - \b CTSD16_INPUT_CH2
//! - \b CTSD16_INPUT_CH3
//! - \b CTSD16_INPUT_CH4
//! - \b CTSD16_INPUT_CH5
//! - \b CTSD16_INPUT_CH6
//! - \b CTSD16_INPUT_CH7
//! - \b CTSD16_INPUT_CH8
//! - \b CTSD16_INPUT_CH9
//! - \b CTSD16_INPUT_CH10
//! - \b CTSD16_INPUT_CH11
//! - \b CTSD16_INPUT_CH12
//! - \b CTSD16_INPUT_CH13
//! - \b CTSD16_INPUT_CH14
//! - \b CTSD16_INPUT_CH15
//! - \b CTSD16_INPUT_CH16
//! - \b CTSD16_INPUT_CH17
//! - \b CTSD16_INPUT_CH18
uint8_t inputChannel;
//! Selects how the data format of the results
//! \n Valid values are:
//! - \b CTSD16_DATA_FORMAT_BINARY [Default]
//! - \b CTSD16_DATA_FORMAT_2COMPLEMENT
uint8_t dataFormat;
//! Determines the rail-to-rail input enabled or disabled.
//! \n Valid values are:
//! - \b CTSD16_RTR_INPUT_ENABLE
//! - \b CTSD16_RTR_INPUT_DISABLE [Default]
uint16_t railToRailInput;
//! Selects the delay for the interrupt
//! \n Valid values are:
//! - \b CTSD16_FIRST_SAMPLE_INTERRUPT
//! - \b CTSD16_FOURTH_SAMPLE_INTERRUPT [Default]
uint16_t interruptDelay;
//! Selects oversampling ratio for the converter
//! \n Valid values are:
//! - \b CTSD16_OVERSAMPLE_32
//! - \b CTSD16_OVERSAMPLE_64
//! - \b CTSD16_OVERSAMPLE_128
//! - \b CTSD16_OVERSAMPLE_256 [Default]
uint16_t oversampleRatio;
//! Selects the gain for the converter
//! \n Valid values are:
//! - \b CTSD16_GAIN_1 [Default]
//! - \b CTSD16_GAIN_2
//! - \b CTSD16_GAIN_4
//! - \b CTSD16_GAIN_8
//! - \b CTSD16_GAIN_16
uint8_t gain;
} CTSD16_initConverterAdvancedParam;
//*****************************************************************************
//
// The following are values that can be passed to the converter parameter for
// functions: CTSD16_setConverterDataFormat(),
// CTSD16_startConverterConversion(), CTSD16_stopConverterConversion(),
// CTSD16_setInputChannel(), CTSD16_setInterruptDelay(),
// CTSD16_setOversampling(), CTSD16_setGain(), CTSD16_setRailToRailInput(),
// CTSD16_getResults(), CTSD16_getHighWordResults(), CTSD16_enableInterrupt(),
// CTSD16_disableInterrupt(), CTSD16_clearInterrupt(),
// CTSD16_getInterruptStatus(), and CTSD16_initConverter(); the param parameter
// for functions: CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_CONVERTER_0 0
#define CTSD16_CONVERTER_1 1
#define CTSD16_CONVERTER_2 2
#define CTSD16_CONVERTER_3 3
#define CTSD16_CONVERTER_4 4
#define CTSD16_CONVERTER_5 5
#define CTSD16_CONVERTER_6 6
//*****************************************************************************
//
// The following are values that can be passed to the oversampleRatio parameter
// for functions: CTSD16_setOversampling(); the param parameter for functions:
// CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_OVERSAMPLE_32 (CTSD16OSR__32)
#define CTSD16_OVERSAMPLE_64 (CTSD16OSR__64)
#define CTSD16_OVERSAMPLE_128 (CTSD16OSR__128)
#define CTSD16_OVERSAMPLE_256 (CTSD16OSR__256)
//*****************************************************************************
//
// The following are values that can be passed to the inputChannel parameter
// for functions: CTSD16_initConverter(), and CTSD16_setInputChannel(); the
// param parameter for functions: CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_INPUT_CH0 (CTSD16INCH_0)
#define CTSD16_INPUT_CH1 (CTSD16INCH_1)
#define CTSD16_INPUT_CH2 (CTSD16INCH_2)
#define CTSD16_INPUT_CH3 (CTSD16INCH_3)
#define CTSD16_INPUT_CH4 (CTSD16INCH_4)
#define CTSD16_INPUT_CH5 (CTSD16INCH_5)
#define CTSD16_INPUT_CH6 (CTSD16INCH_6)
#define CTSD16_INPUT_CH7 (CTSD16INCH_7)
#define CTSD16_INPUT_CH8 (CTSD16INCH_8)
#define CTSD16_INPUT_CH9 (CTSD16INCH_9)
#define CTSD16_INPUT_CH10 (CTSD16INCH_10)
#define CTSD16_INPUT_CH11 (CTSD16INCH_11)
#define CTSD16_INPUT_CH12 (CTSD16INCH_12)
#define CTSD16_INPUT_CH13 (CTSD16INCH_13)
#define CTSD16_INPUT_CH14 (CTSD16INCH_14)
#define CTSD16_INPUT_CH15 (CTSD16INCH_15)
#define CTSD16_INPUT_CH16 (CTSD16INCH_16)
#define CTSD16_INPUT_CH17 (CTSD16INCH_17)
#define CTSD16_INPUT_CH18 (CTSD16INCH_18)
//*****************************************************************************
//
// The following are values that can be passed to the dataFormat parameter for
// functions: CTSD16_setConverterDataFormat(); the param parameter for
// functions: CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_DATA_FORMAT_BINARY (0x00)
#define CTSD16_DATA_FORMAT_2COMPLEMENT (CTSD16DF)
//*****************************************************************************
//
// The following are values that can be passed to the gain parameter for
// functions: CTSD16_setGain(); the param parameter for functions:
// CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_GAIN_1 (CTSD16GAIN_1)
#define CTSD16_GAIN_2 (CTSD16GAIN_2)
#define CTSD16_GAIN_4 (CTSD16GAIN_4)
#define CTSD16_GAIN_8 (CTSD16GAIN_8)
#define CTSD16_GAIN_16 (CTSD16GAIN_16)
//*****************************************************************************
//
// The following are values that can be passed to the interruptDelay parameter
// for functions: CTSD16_setInterruptDelay(); the param parameter for
// functions: CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_FIRST_SAMPLE_INTERRUPT (CTSD16INTDLY)
#define CTSD16_FOURTH_SAMPLE_INTERRUPT (0x00)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_NOT_GROUPED (0x00)
#define CTSD16_GROUPED (CTSD16GRP)
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: CTSD16_enableInterrupt(), CTSD16_disableInterrupt(),
// CTSD16_clearInterrupt(), and CTSD16_getInterruptStatus() as well as returned
// by the CTSD16_getInterruptStatus() function.
//
//*****************************************************************************
#define CTSD16_CONVERTER_INTERRUPT (CTSD16IE0)
#define CTSD16_CONVERTER_OVERFLOW_INTERRUPT (CTSD16OVIE0)
//*****************************************************************************
//
// The following are values that can be passed to the chargePumpBurstRequest
// parameter for functions: CTSD16_init().
//
//*****************************************************************************
#define CTSD16_RTR_INPUT_CHARGEPUMP_BURST_REQUEST_ENABLE (CTSD16RRIBURST)
#define CTSD16_RTR_INPUT_CHARGEPUMP_BURST_REQUEST_DISABLE (0x0)
//*****************************************************************************
//
// The following are values that can be passed to the referenceSelect parameter
// for functions: CTSD16_init().
//
//*****************************************************************************
#define CTSD16_REF_EXTERNAL (0x0)
#define CTSD16_REF_INTERNAL (CTSD16REFS)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: CTSD16_initConverterAdvanced(); the conversionMode parameter for
// functions: CTSD16_initConverter().
//
//*****************************************************************************
#define CTSD16_CONTINUOUS_MODE (0x0)
#define CTSD16_SINGLE_MODE (CTSD16SNGL)
//*****************************************************************************
//
// The following are values that can be passed to the railToRailInput parameter
// for functions: CTSD16_setRailToRailInput(); the param parameter for
// functions: CTSD16_initConverterAdvanced().
//
//*****************************************************************************
#define CTSD16_RTR_INPUT_ENABLE (CTSD16RRI)
#define CTSD16_RTR_INPUT_DISABLE (0x0)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the CTSD16_isRailToRailInputReady() function.
//
//*****************************************************************************
#define CTSD16_RTR_INPUT_READY (CTSD16RRIRDY)
#define CTSD16_RTR_INPUT_NOT_READY (0x0)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the CTSD16 Module
//!
//! This function initializes the CTSD16 module sigma-delta analog-to-digital
//! conversions. Specifically the function sets up the clock source for the
//! CTSD16 core to use for conversions. Upon completion of the initialization
//! the CTSD16 interrupt registers will be reset and the given parameters will
//! be set. The converter configuration settings are independent of this
//! function. The default clock frequency for CTSD16 is: f_CTSD16 = 1.024MHz
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param chargePumpBurstRequest sets the rail-to-rail input charge pump burst
//! mode request enabled or disabled.
//! Valid values are:
//! - \b CTSD16_RTR_INPUT_CHARGEPUMP_BURST_REQUEST_ENABLE
//! - \b CTSD16_RTR_INPUT_CHARGEPUMP_BURST_REQUEST_DISABLE [Default]
//! \n Modified bits are \b CTSD16RRIBURST of \b CTSD16CTL register.
//! \param referenceSelect selects the reference source for the CTSD16 core.
//! Valid values are:
//! - \b CTSD16_REF_EXTERNAL [Default]
//! - \b CTSD16_REF_INTERNAL
//! \n Modified bits are \b CTSD16REFS of \b CTSD16CTL register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_init(uint16_t baseAddress,
uint16_t chargePumpBurstRequest,
uint8_t referenceSelect);
//*****************************************************************************
//
//! \brief Configure CTSD16 converter
//!
//! This function initializes a converter of the CTSD16 module. Upon completion
//! the converter will be ready for a conversion and can be started with the
//! CTSD16_startConverterConversion(). Additional configuration such as data
//! format can be configured in CTSD16_setDataFormat().
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter the converter to initialize.
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param conversionMode determines whether the converter will do continuous
//! samples or a single sample.
//! Valid values are:
//! - \b CTSD16_CONTINUOUS_MODE [Default]
//! - \b CTSD16_SINGLE_MODE
//! \n Modified bits are \b CTSD16SNGL of \b CTSD16CTL register.
//! \param inputChannel selects oversampling ratio for the converter
//! Valid values are:
//! - \b CTSD16_INPUT_CH0
//! - \b CTSD16_INPUT_CH1
//! - \b CTSD16_INPUT_CH2
//! - \b CTSD16_INPUT_CH3
//! - \b CTSD16_INPUT_CH4
//! - \b CTSD16_INPUT_CH5
//! - \b CTSD16_INPUT_CH6
//! - \b CTSD16_INPUT_CH7
//! - \b CTSD16_INPUT_CH8
//! - \b CTSD16_INPUT_CH9
//! - \b CTSD16_INPUT_CH10
//! - \b CTSD16_INPUT_CH11
//! - \b CTSD16_INPUT_CH12
//! - \b CTSD16_INPUT_CH13
//! - \b CTSD16_INPUT_CH14
//! - \b CTSD16_INPUT_CH15
//! - \b CTSD16_INPUT_CH16
//! - \b CTSD16_INPUT_CH17
//! - \b CTSD16_INPUT_CH18
//! \n Modified bits are \b CTSD16INCHx of \b CTSD16INCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_initConverter(uint16_t baseAddress,
uint8_t converter,
uint16_t conversionMode,
uint8_t inputChannel);
//*****************************************************************************
//
//! \brief Configure CTSD16 converter - Advanced Configure
//!
//! This function initializes a converter of the CTSD16 module with more
//! configuration parameters. Upon completion the converter will be ready for a
//! conversion and can be started with the CTSD16_startConverterConversion().
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param param for initilization
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_initConverterAdvanced(uint16_t baseAddress,
CTSD16_initConverterAdvancedParam *param);
//*****************************************************************************
//
//! \brief Start Conversion for Converter
//!
//! This function starts a single converter.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be started
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \n Modified bits are \b CTSD16SC of \b CTSD16CCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_startConverterConversion(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Stop Conversion for Converter
//!
//! This function stops a single converter.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be stopped
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \n Modified bits are \b CTSD16SC of \b CTSD16CCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_stopConverterConversion(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Set CTSD16 converter data format
//!
//! This function sets the converter format so that the resulting data can be
//! viewed in either binary or 2's complement.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be configured. Check check
//! datasheet for available converters on device.
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param dataFormat selects how the data format of the results
//! Valid values are:
//! - \b CTSD16_DATA_FORMAT_BINARY [Default]
//! - \b CTSD16_DATA_FORMAT_2COMPLEMENT
//! \n Modified bits are \b CTSD16DFx of \b CTSD16CCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_setConverterDataFormat(uint16_t baseAddress,
uint8_t converter,
uint8_t dataFormat);
//*****************************************************************************
//
//! \brief Set the input channel for specified converter
//!
//! This function configures the input channel. For MSP430F5xx_6xx devices,
//! users can choose either analog input or internal temperature input.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be configured
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param inputChannel selects oversampling ratio for the converter
//! Valid values are:
//! - \b CTSD16_INPUT_CH0
//! - \b CTSD16_INPUT_CH1
//! - \b CTSD16_INPUT_CH2
//! - \b CTSD16_INPUT_CH3
//! - \b CTSD16_INPUT_CH4
//! - \b CTSD16_INPUT_CH5
//! - \b CTSD16_INPUT_CH6
//! - \b CTSD16_INPUT_CH7
//! - \b CTSD16_INPUT_CH8
//! - \b CTSD16_INPUT_CH9
//! - \b CTSD16_INPUT_CH10
//! - \b CTSD16_INPUT_CH11
//! - \b CTSD16_INPUT_CH12
//! - \b CTSD16_INPUT_CH13
//! - \b CTSD16_INPUT_CH14
//! - \b CTSD16_INPUT_CH15
//! - \b CTSD16_INPUT_CH16
//! - \b CTSD16_INPUT_CH17
//! - \b CTSD16_INPUT_CH18
//! \n Modified bits are \b CTSD16INCHx of \b CTSD16INCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_setInputChannel(uint16_t baseAddress,
uint8_t converter,
uint8_t inputChannel);
//*****************************************************************************
//
//! \brief Enable/Disable rail-to-rail input for specified converter
//!
//! This function enable/disables rail-to-rail input for specified converter.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be configured
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param railToRailInput sets rail-to-rail input enabled/disabled.
//! Valid values are:
//! - \b CTSD16_RTR_INPUT_ENABLE
//! - \b CTSD16_RTR_INPUT_DISABLE [Default]
//! \n Modified bits are \b CTSD16RRI of \b CTSD16INCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_setRailToRailInput(uint16_t baseAddress,
uint8_t converter,
uint16_t railToRailInput);
//*****************************************************************************
//
//! \brief Configures the delay for an interrupt to trigger
//!
//! This function configures the delay for the first interrupt service request
//! for the corresponding converter. This feature delays the interrupt request
//! for a completed conversion by up to four conversion cycles allowing the
//! digital filter to settle prior to generating an interrupt request.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be stopped
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param interruptDelay selects the delay for the interrupt
//! Valid values are:
//! - \b CTSD16_FIRST_SAMPLE_INTERRUPT
//! - \b CTSD16_FOURTH_SAMPLE_INTERRUPT [Default]
//! \n Modified bits are \b CTSD16INTDLYx of \b CTSD16INCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_setInterruptDelay(uint16_t baseAddress,
uint8_t converter,
uint16_t interruptDelay);
//*****************************************************************************
//
//! \brief Configures the oversampling ratio for a converter
//!
//! This function configures the oversampling ratio for a given converter.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be configured
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param oversampleRatio selects oversampling ratio for the converter
//! Valid values are:
//! - \b CTSD16_OVERSAMPLE_32
//! - \b CTSD16_OVERSAMPLE_64
//! - \b CTSD16_OVERSAMPLE_128
//! - \b CTSD16_OVERSAMPLE_256 [Default]
//! \n Modified bits are \b CTSD16OSRx of \b CTSD16CCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_setOversampling(uint16_t baseAddress,
uint8_t converter,
uint16_t oversampleRatio);
//*****************************************************************************
//
//! \brief Configures the gain for the converter
//!
//! This function configures the gain for a single converter.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter that will be configured
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param gain selects the gain for the converter
//! Valid values are:
//! - \b CTSD16_GAIN_1 [Default]
//! - \b CTSD16_GAIN_2
//! - \b CTSD16_GAIN_4
//! - \b CTSD16_GAIN_8
//! - \b CTSD16_GAIN_16
//! \n Modified bits are \b CTSD16GAINx of \b CTSD16INCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_setGain(uint16_t baseAddress,
uint8_t converter,
uint8_t gain);
//*****************************************************************************
//
//! \brief Returns the results for a converter
//!
//! This function gets the results from the CTSD16MEMx register for upper
//! 16-bit and lower 16-bit results, and concatenates them to form a long. The
//! actual result is a maximum 24 bits.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter who's results will be returned
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//!
//! \return Result of conversion
//
//*****************************************************************************
extern uint32_t CTSD16_getResults(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Returns the high word results for a converter
//!
//! This function gets the upper 16-bit result from the CTSD16MEMx register and
//! returns it.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter selects the converter who's results will be returned
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//!
//! \return High word result of conversion
//
//*****************************************************************************
extern uint16_t CTSD16_getHighWordResults(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Returns the rail-to-rail input ready status
//!
//! This function returns the rail-to-rail input ready status.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//!
//! \return ready status
//! Return Logical OR of any of the following:
//! - \b CTSD16_RTR_INPUT_READY
//! - \b CTSD16_RTR_INPUT_NOT_READY
//! \n Returns the rail-to-rail input ready status.
//
//*****************************************************************************
extern uint16_t CTSD16_isRailToRailInputReady(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables interrupts for the CTSD16 Module
//!
//! This function enables interrupts for the CTSD16 module. Does not clear
//! interrupt flags.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param mask is the bit mask of the converter interrupt sources to be
//! enabled.
//! Mask value is the logical OR of any of the following:
//! - \b CTSD16_CONVERTER_INTERRUPT
//! - \b CTSD16_CONVERTER_OVERFLOW_INTERRUPT
//! \n Modified bits are \b CTSD16OVIEx of \b CTSD16IE register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_enableInterrupt(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
//! \brief Disables interrupts for the CTSD16 Module
//!
//! This function disables interrupts for the CTSD16 module.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param mask is the bit mask of the converter interrupt sources to be
//! disabled.
//! Mask value is the logical OR of any of the following:
//! - \b CTSD16_CONVERTER_INTERRUPT
//! - \b CTSD16_CONVERTER_OVERFLOW_INTERRUPT
//! \n Modified bits are \b CTSD16OVIEx of \b CTSD16IE register.
//!
//! Modified bits of \b SD24BIE register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_disableInterrupt(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
//! \brief Clears interrupts for the CTSD16 Module
//!
//! This function clears interrupt flags for the CTSD16 module.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param mask is the bit mask of the converter interrupt sources to clear.
//! Mask value is the logical OR of any of the following:
//! - \b CTSD16_CONVERTER_INTERRUPT
//! - \b CTSD16_CONVERTER_OVERFLOW_INTERRUPT
//! \n Modified bits are \b CTSD16OVIFGx of \b CTSD16IFG register.
//!
//! \return None
//
//*****************************************************************************
extern void CTSD16_clearInterrupt(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
//! \brief Returns the interrupt status for the CTSD16 Module
//!
//! This function returns interrupt flag statuses for the CTSD16 module.
//!
//! \param baseAddress is the base address of the CTSD16 module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b CTSD16_CONVERTER_0
//! - \b CTSD16_CONVERTER_1
//! - \b CTSD16_CONVERTER_2
//! - \b CTSD16_CONVERTER_3
//! - \b CTSD16_CONVERTER_4
//! - \b CTSD16_CONVERTER_5
//! - \b CTSD16_CONVERTER_6
//! \param mask is the bit mask of the converter interrupt sources to return.
//! Mask value is the logical OR of any of the following:
//! - \b CTSD16_CONVERTER_INTERRUPT
//! - \b CTSD16_CONVERTER_OVERFLOW_INTERRUPT
//!
//! \return Logical OR of any of the following:
//! - \b CTSD16_CONVERTER_INTERRUPT
//! - \b CTSD16_CONVERTER_OVERFLOW_INTERRUPT
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint16_t CTSD16_getInterruptStatus(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_CTSD16_H__

View File

@@ -0,0 +1,212 @@
//*****************************************************************************
//
// dac12_a.c - Driver for the dac12_a Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup dac12_a_api dac12_a
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_DAC12_2__
#include "dac12_a.h"
#include <assert.h>
bool DAC12_A_init(uint16_t baseAddress, DAC12_A_initParam *param)
{
baseAddress += param->submoduleSelect; //Add 0x10 to base address IF
//DAC12_A_1 is selected.
HWREG16(baseAddress + OFS_DAC12_0CTL1) &= ~(DAC12OG + DAC12DFJ);
//Reset and Set DAC12_A Control 0 Bits
HWREG16(baseAddress + OFS_DAC12_0CTL0) = param->outputSelect
+ param->positiveReferenceVoltage
+ param->amplifierSetting
+ param->conversionTriggerSelect;
if (DAC12_A_VREFx1 == param->outputVoltageMultiplier){
HWREG16(baseAddress + OFS_DAC12_0CTL0) |= DAC12IR;
} else if (DAC12_A_VREFx2 == param->outputVoltageMultiplier){
HWREG16(baseAddress + OFS_DAC12_0CTL1) |= DAC12OG;
}
//else if(DAC12_A_VREFx3 == outputVoltageMultiplier)
//Both DAC12IR and DAC12OG values == 0
return ( STATUS_SUCCESS) ;
}void DAC12_A_setAmplifierSetting (uint16_t baseAddress,
uint8_t submoduleSelect,
uint8_t amplifierSetting)
{
//Reset amplifier setting to set it
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) &= ~(DAC12AMP_7);
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) |= amplifierSetting;
}
void DAC12_A_disable (uint16_t baseAddress,
uint8_t submoduleSelect)
{
//Reset amplifier setting to turn DAC12_A off completely
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) &= ~(DAC12AMP_7);
}
void DAC12_A_enableGrouping (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_DAC12_0CTL0) |= DAC12GRP;
}
void DAC12_A_disableGrouping (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_DAC12_0CTL0) &= ~(DAC12GRP);
}
void DAC12_A_enableInterrupt (uint16_t baseAddress,
uint8_t submoduleSelect)
{
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) |= DAC12IE;
}
void DAC12_A_disableInterrupt (uint16_t baseAddress,
uint8_t submoduleSelect)
{
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) &= ~(DAC12IE);
}
uint16_t DAC12_A_getInterruptStatus (uint16_t baseAddress,
uint8_t submoduleSelect)
{
return (HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) & DAC12IFG);
}
void DAC12_A_clearInterrupt (uint16_t baseAddress,
uint8_t submoduleSelect)
{
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) &= ~(DAC12IFG);
}
void DAC12_A_calibrateOutput (uint16_t baseAddress,
uint8_t submoduleSelect)
{
//Unlock Calibration
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CALCTL) = DAC12PW;
//Start Calibration
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) |= DAC12CALON;
//Wait for Calibration to Finish
while (HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) & DAC12CALON);
//Lock Calibration
HWREG16(baseAddress + submoduleSelect +
OFS_DAC12_0CALCTL) = DAC12PW + DAC12LOCK;
}
uint16_t DAC12_A_getCalibrationData (uint16_t baseAddress,
uint8_t submoduleSelect)
{
return ((uint16_t)(HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CALDAT))) ;
}
void DAC12_A_setCalibrationOffset (uint16_t baseAddress,
uint8_t submoduleSelect,
uint16_t calibrationOffsetValue)
{
//Unlock Calibration
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CALCTL) = DAC12PW;
//Set Calibration Offset
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CALDAT) =
calibrationOffsetValue;
//Lock Calibration
HWREG16(baseAddress + submoduleSelect +
OFS_DAC12_0CALCTL) = DAC12PW + DAC12LOCK;
}
void DAC12_A_enableConversions (uint16_t baseAddress,
uint8_t submoduleSelect)
{
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) |= DAC12ENC;
}
void DAC12_A_setData (uint16_t baseAddress,
uint8_t submoduleSelect,
uint16_t data)
{
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0DAT) = data;
}
void DAC12_A_disableConversions (uint16_t baseAddress,
uint8_t submoduleSelect)
{
HWREG16(baseAddress + submoduleSelect + OFS_DAC12_0CTL0) &= ~(DAC12ENC);
}
void DAC12_A_setResolution (uint16_t baseAddress,
uint8_t submoduleSelect,
uint16_t resolutionSelect)
{
//Store the ENC bit status
uint16_t conversionsEnabledStatus =
( HWREG16(baseAddress + OFS_DAC12_0CTL0) & (DAC12ENC) );
baseAddress += submoduleSelect; //Add 0x10 to base address IF
//DAC12_A_1 is selected.
if (DAC12_A_RESOLUTION_8BIT == resolutionSelect){
HWREG16(baseAddress + OFS_DAC12_0CTL0) |= DAC12RES;
} else if (DAC12_A_RESOLUTION_12BIT == resolutionSelect){
HWREG16(baseAddress + OFS_DAC12_0CTL0) &= ~(DAC12RES);
}
//Restore the ENC bit status
HWREG16(baseAddress + OFS_DAC12_0CTL0) |= conversionsEnabledStatus;
}
void DAC12_A_setInputDataFormat (uint16_t baseAddress,
uint8_t submoduleSelect,
uint8_t inputJustification,
uint8_t inputSign)
{
//Store the ENC bit status
uint16_t conversionsEnabledStatus =
( HWREG16(baseAddress + OFS_DAC12_0CTL0) & (DAC12ENC) );
baseAddress += submoduleSelect; //Add 0x10 to base address IF
//DAC12_A_1 is selected.
if (DAC12_A_JUSTIFICATION_LEFT == inputJustification){
HWREG16(baseAddress + OFS_DAC12_0CTL1) |= DAC12DFJ;
} else if (DAC12_A_JUSTIFICATION_RIGHT == inputJustification){
HWREG16(baseAddress + OFS_DAC12_0CTL1) &= ~(DAC12DFJ);
}
if (DAC12_A_SIGNED_2SCOMPLEMENT == inputSign){
HWREG16(baseAddress + OFS_DAC12_0CTL0) |= DAC12DF;
} else if (DAC12_A_UNSIGNED_BINARY == inputSign){
HWREG16(baseAddress + OFS_DAC12_0CTL0) &= ~(DAC12DF);
}
//Restore the ENC bit status
HWREG16(baseAddress + OFS_DAC12_0CTL0) |= conversionsEnabledStatus;
}
uint32_t DAC12_A_getDataBufferMemoryAddressForDMA (uint16_t baseAddress,
uint8_t submoduleSelect)
{
return ( baseAddress + submoduleSelect + OFS_DAC12_0DAT );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for dac12_a_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,665 @@
//*****************************************************************************
//
// dac12_a.h - Driver for the DAC12_A Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_DAC12_A_H__
#define __MSP430WARE_DAC12_A_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_DAC12_2__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the DAC12_A_init() function as the param parameter.
//
//*****************************************************************************
typedef struct DAC12_A_initParam {
//! Decides which DAC12_A sub-module to configure.
//! \n Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
uint8_t submoduleSelect;
//! Selects the output pin that the selected DAC12_A module will output to.
//! \n Valid values are:
//! - \b DAC12_A_OUTPUT_1 [Default]
//! - \b DAC12_A_OUTPUT_2
uint16_t outputSelect;
//! Is the upper limit voltage that the data can be converted in to.
//! \n Valid values are:
//! - \b DAC12_A_VREF_INT [Default]
//! - \b DAC12_A_VREF_AVCC
//! - \b DAC12_A_VREF_EXT - For devices with CTSD16, use Ref module
//! Ref_enableReferenceVoltageOutput/Ref__disableReferenceVoltageOutput
//! to select VeREF(external reference signal) or VREFBG(internally
//! generated reference signal)
uint16_t positiveReferenceVoltage;
//! Is the multiplier of the Vout voltage.
//! \n Valid values are:
//! - \b DAC12_A_VREFx1 [Default]
//! - \b DAC12_A_VREFx2
//! - \b DAC12_A_VREFx3
uint16_t outputVoltageMultiplier;
//! Is the setting of the settling speed and current of the Vref+ and the
//! Vout buffer.
//! \n Valid values are:
//! - \b DAC12_A_AMP_OFF_PINOUTHIGHZ [Default] - Initialize the DAC12_A
//! Module with settings, but do not turn it on.
//! - \b DAC12_A_AMP_OFF_PINOUTLOW - Initialize the DAC12_A Module with
//! settings, and allow it to take control of the selected output pin to
//! pull it low (Note: this takes control away port mapping module).
//! - \b DAC12_A_AMP_LOWIN_LOWOUT - Select a slow settling speed and
//! current for Vref+ input buffer and for Vout output buffer.
//! - \b DAC12_A_AMP_LOWIN_MEDOUT - Select a slow settling speed and
//! current for Vref+ input buffer and a medium settling speed and
//! current for Vout output buffer.
//! - \b DAC12_A_AMP_LOWIN_HIGHOUT - Select a slow settling speed and
//! current for Vref+ input buffer and a high settling speed and current
//! for Vout output buffer.
//! - \b DAC12_A_AMP_MEDIN_MEDOUT - Select a medium settling speed and
//! current for Vref+ input buffer and for Vout output buffer.
//! - \b DAC12_A_AMP_MEDIN_HIGHOUT - Select a medium settling speed and
//! current for Vref+ input buffer and a high settling speed and current
//! for Vout output buffer.
//! - \b DAC12_A_AMP_HIGHIN_HIGHOUT - Select a high settling speed and
//! current for Vref+ input buffer and for Vout output buffer.
uint8_t amplifierSetting;
//! Selects the trigger that will start a conversion.
//! \n Valid values are:
//! - \b DAC12_A_TRIGGER_ENCBYPASS [Default] - Automatically converts data
//! as soon as it is written into the data buffer. (Note: Do not use
//! this selection if grouping DAC's).
//! - \b DAC12_A_TRIGGER_ENC - Requires a call to enableConversions() to
//! allow a conversion, but starts a conversion as soon as data is
//! written to the data buffer (Note: with DAC12_A module's grouped,
//! data has to be set in BOTH DAC12_A data buffers to start a
//! conversion).
//! - \b DAC12_A_TRIGGER_TA - Requires a call to enableConversions() to
//! allow a conversion, and a rising edge of Timer_A's Out1 (TA1) to
//! start a conversion.
//! - \b DAC12_A_TRIGGER_TB - Requires a call to enableConversions() to
//! allow a conversion, and a rising edge of Timer_B's Out2 (TB2) to
//! start a conversion.
uint16_t conversionTriggerSelect;
} DAC12_A_initParam;
//*****************************************************************************
//
// The following are values that can be passed to the positiveReferenceVoltage
// parameter for functions: DAC12_A_init(); the param parameter for functions:
// DAC12_A_init().
//
//*****************************************************************************
#define DAC12_A_VREF_INT (DAC12SREF_0)
#define DAC12_A_VREF_AVCC (DAC12SREF_1)
#define DAC12_A_VREF_EXT (DAC12SREF_2)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: DAC12_A_init(); the amplifierSetting parameter for functions:
// DAC12_A_init(), and DAC12_A_setAmplifierSetting().
//
//*****************************************************************************
#define DAC12_A_AMP_OFF_PINOUTHIGHZ (DAC12AMP_0)
#define DAC12_A_AMP_OFF_PINOUTLOW (DAC12AMP_1)
#define DAC12_A_AMP_LOWIN_LOWOUT (DAC12AMP_2)
#define DAC12_A_AMP_LOWIN_MEDOUT (DAC12AMP_3)
#define DAC12_A_AMP_LOWIN_HIGHOUT (DAC12AMP_4)
#define DAC12_A_AMP_MEDIN_MEDOUT (DAC12AMP_5)
#define DAC12_A_AMP_MEDIN_HIGHOUT (DAC12AMP_6)
#define DAC12_A_AMP_HIGHIN_HIGHOUT (DAC12AMP_7)
//*****************************************************************************
//
// The following are values that can be passed to the outputSelect parameter
// for functions: DAC12_A_init(); the param parameter for functions:
// DAC12_A_init().
//
//*****************************************************************************
#define DAC12_A_OUTPUT_1 (!(DAC12OPS))
#define DAC12_A_OUTPUT_2 (DAC12OPS)
//*****************************************************************************
//
// The following are values that can be passed to the submoduleSelect parameter
// for functions: DAC12_A_init(), DAC12_A_setAmplifierSetting(),
// DAC12_A_disable(), DAC12_A_enableInterrupt(), DAC12_A_disableInterrupt(),
// DAC12_A_getInterruptStatus(), DAC12_A_clearInterrupt(),
// DAC12_A_calibrateOutput(), DAC12_A_getCalibrationData(),
// DAC12_A_setCalibrationOffset(), DAC12_A_enableConversions(),
// DAC12_A_setData(), DAC12_A_disableConversions(), DAC12_A_setResolution(),
// DAC12_A_setInputDataFormat(), and
// DAC12_A_getDataBufferMemoryAddressForDMA(); the param parameter for
// functions: DAC12_A_init().
//
//*****************************************************************************
#define DAC12_A_SUBMODULE_0 (0x00)
#define DAC12_A_SUBMODULE_1 (0x10)
//*****************************************************************************
//
// The following are values that can be passed to the outputVoltageMultiplier
// parameter for functions: DAC12_A_init(); the param parameter for functions:
// DAC12_A_init().
//
//*****************************************************************************
#define DAC12_A_VREFx1 (DAC12IR)
#define DAC12_A_VREFx2 (DAC12OG)
#define DAC12_A_VREFx3 (0x0)
//*****************************************************************************
//
// The following are values that can be passed to the conversionTriggerSelect
// parameter for functions: DAC12_A_init(); the param parameter for functions:
// DAC12_A_init().
//
//*****************************************************************************
#define DAC12_A_TRIGGER_ENCBYPASS (DAC12LSEL_0)
#define DAC12_A_TRIGGER_ENC (DAC12LSEL_1)
#define DAC12_A_TRIGGER_TA (DAC12LSEL_2)
#define DAC12_A_TRIGGER_TB (DAC12LSEL_3)
//*****************************************************************************
//
// The following are values that can be passed to the resolutionSelect
// parameter for functions: DAC12_A_setResolution().
//
//*****************************************************************************
#define DAC12_A_RESOLUTION_8BIT (DAC12RES)
#define DAC12_A_RESOLUTION_12BIT (!(DAC12RES))
//*****************************************************************************
//
// The following are values that can be passed to the inputJustification
// parameter for functions: DAC12_A_setInputDataFormat().
//
//*****************************************************************************
#define DAC12_A_JUSTIFICATION_RIGHT (!(DAC12DFJ))
#define DAC12_A_JUSTIFICATION_LEFT (DAC12DFJ)
//*****************************************************************************
//
// The following are values that can be passed to the inputSign parameter for
// functions: DAC12_A_setInputDataFormat().
//
//*****************************************************************************
#define DAC12_A_UNSIGNED_BINARY (!(DAC12DF))
#define DAC12_A_SIGNED_2SCOMPLEMENT (DAC12DF)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the DAC12_A_getInterruptStatus() function.
//
//*****************************************************************************
#define DAC12_A_INT_ACTIVE (DAC12IFG)
#define DAC12_A_INT_INACTIVE (0x00)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the DAC12_A module with the specified settings.
//!
//! This function initializes the DAC12_A module with the specified settings.
//! Upon successful completion of the initialization of this module the control
//! registers and interrupts of this module are all reset, and the specified
//! variables will be set. Please note, that if conversions are enabled with
//! the enableConversions() function, then disableConversions() must be called
//! before re-initializing the DAC12_A module with this function.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param param is the pointer to struct for initialization.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the initialization process.
//
//*****************************************************************************
extern bool DAC12_A_init(uint16_t baseAddress,
DAC12_A_initParam *param);
//*****************************************************************************
//
//! \brief Sets the amplifier settings for the Vref+ and Vout buffers.
//!
//! This function sets the amplifier settings of the DAC12_A module for the
//! Vref+ and Vout buffers without re-initializing the DAC12_A module. This can
//! be used to disable the control of the pin by the DAC12_A module.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//! \param amplifierSetting is the setting of the settling speed and current of
//! the Vref+ and the Vout buffer.
//! Valid values are:
//! - \b DAC12_A_AMP_OFF_PINOUTHIGHZ [Default] - Initialize the DAC12_A
//! Module with settings, but do not turn it on.
//! - \b DAC12_A_AMP_OFF_PINOUTLOW - Initialize the DAC12_A Module with
//! settings, and allow it to take control of the selected output pin
//! to pull it low (Note: this takes control away port mapping
//! module).
//! - \b DAC12_A_AMP_LOWIN_LOWOUT - Select a slow settling speed and
//! current for Vref+ input buffer and for Vout output buffer.
//! - \b DAC12_A_AMP_LOWIN_MEDOUT - Select a slow settling speed and
//! current for Vref+ input buffer and a medium settling speed and
//! current for Vout output buffer.
//! - \b DAC12_A_AMP_LOWIN_HIGHOUT - Select a slow settling speed and
//! current for Vref+ input buffer and a high settling speed and
//! current for Vout output buffer.
//! - \b DAC12_A_AMP_MEDIN_MEDOUT - Select a medium settling speed and
//! current for Vref+ input buffer and for Vout output buffer.
//! - \b DAC12_A_AMP_MEDIN_HIGHOUT - Select a medium settling speed and
//! current for Vref+ input buffer and a high settling speed and
//! current for Vout output buffer.
//! - \b DAC12_A_AMP_HIGHIN_HIGHOUT - Select a high settling speed and
//! current for Vref+ input buffer and for Vout output buffer.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_setAmplifierSetting(uint16_t baseAddress,
uint8_t submoduleSelect,
uint8_t amplifierSetting);
//*****************************************************************************
//
//! \brief Clears the amplifier settings to disable the DAC12_A module.
//!
//! This function clears the amplifier settings for the selected DAC12_A module
//! to disable the DAC12_A module.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! Modified bits are \b DAC12AMP_7 of \b DAC12_xCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_disable(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Enables grouping of two DAC12_A modules in a dual DAC12_A system.
//!
//! This function enables grouping two DAC12_A modules in a dual DAC12_A
//! system. Both DAC12_A modules will work in sync, converting data at the same
//! time. To convert data, the same trigger should be set for both DAC12_A
//! modules during initialization (which should not be
//! DAC12_A_TRIGGER_ENCBYPASS), the enableConversions() function needs to be
//! called with both DAC12_A modules, and data needs to be set for both DAC12_A
//! modules separately.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//!
//! Modified bits are \b DAC12GRP of \b DAC12_xCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_enableGrouping(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables grouping of two DAC12_A modules in a dual DAC12_A system.
//!
//! This function disables grouping of two DAC12_A modules in a dual DAC12_A
//! system.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_disableGrouping(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables the DAC12_A module interrupt source.
//!
//! This function to enable the DAC12_A module interrupt, which throws an
//! interrupt when the data buffer is available for new data to be set. Only
//! the sources that are enabled can be reflected to the processor interrupt;
//! disabled sources have no effect on the processor. Note that an interrupt is
//! not thrown when DAC12_A_TRIGGER_ENCBYPASS has been set for the parameter
//! conversionTriggerSelect in initialization. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_enableInterrupt(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Disables the DAC12_A module interrupt source.
//!
//! Enables the DAC12_A module interrupt source. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_disableInterrupt(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Returns the status of the DAC12_A module interrupt flag.
//!
//! This function returns the status of the DAC12_A module interrupt flag. Note
//! that an interrupt is not thrown when DAC12_A_TRIGGER_ENCBYPASS has been set
//! for the conversionTriggerSelect parameter in initialization.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! \return One of the following:
//! - \b DAC12_A_INT_ACTIVE
//! - \b DAC12_A_INT_INACTIVE
//! \n indicating the status for the selected DAC12_A module
//
//*****************************************************************************
extern uint16_t DAC12_A_getInterruptStatus(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Clears the DAC12_A module interrupt flag.
//!
//! The DAC12_A module interrupt flag is cleared, so that it no longer asserts.
//! Note that an interrupt is not thrown when DAC12_A_TRIGGER_ENCBYPASS has
//! been set for the parameter conversionTriggerSelect in initialization.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! Modified bits are \b DAC12IFG of \b DAC12_xCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_clearInterrupt(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Calibrates the output offset.
//!
//! This function disables the calibration lock, starts the calibration, whats
//! for the calibration to complete, and then re-locks the calibration lock.
//! Please note, this function should be called after initializing the dac12
//! module, and before using it.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! Modified bits are \b DAC12CALON of \b DAC12_xCTL0 register; bits \b DAC12PW
//! of \b DAC12_xCALCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_calibrateOutput(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Returns the calibrated offset of the output buffer.
//!
//! This function returns the calibrated offset of the output buffer. The
//! output buffer offset is used to obtain accurate results from the output
//! pin. This function should only be used while the calibration lock is
//! enabled. Only the lower byte of the word of the register is returned, and
//! the value is between -128 and +127.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! \return The calibrated offset of the output buffer.
//
//*****************************************************************************
extern uint16_t DAC12_A_getCalibrationData(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Returns the calibrated offset of the output buffer.
//!
//! This function is used to manually set the calibration offset value. The
//! calibration is automatically unlocked and re-locked to be able to allow for
//! the offset value to be set.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//! \param calibrationOffsetValue calibration offset value
//!
//! Modified bits are \b DAC12LOCK of \b DAC12_xCALDAT register; bits \b
//! DAC12PW of \b DAC12_xCTL0 register; bits \b DAC12PW of \b DAC12_xCALCTL
//! register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_setCalibrationOffset(uint16_t baseAddress,
uint8_t submoduleSelect,
uint16_t calibrationOffsetValue);
//*****************************************************************************
//
//! \brief Enables triggers to start conversions.
//!
//! This function is used to allow triggers to start a conversion. Note that
//! this function does not need to be used if DAC12_A_TRIGGER_ENCBYPASS was set
//! for the conversionTriggerSelect parameter during initialization. If DAC
//! grouping is enabled, this has to be called for both DAC's.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! Modified bits are \b DAC12ENC of \b DAC12_xCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_enableConversions(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Sets the given data into the buffer to be converted.
//!
//! This function is used to set the given data into the data buffer of the
//! DAC12_A module. The data given should be in the format set (12-bit
//! Unsigned, Right-justified by default). Note if DAC12_A_TRIGGER_ENCBYPASS
//! was set for the conversionTriggerSelect during initialization then using
//! this function will set the data and automatically trigger a conversion. If
//! any other trigger was set during initialization, then the
//! DAC12_A_enableConversions() function needs to be called before a conversion
//! can be started. If grouping DAC's and DAC12_A_TRIGGER_ENC was set during
//! initialization, then both data buffers must be set before a conversion will
//! be started.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//! \param data is the data to be set into the DAC12_A data buffer to be
//! converted.
//! \n Modified bits are \b DAC12_DATA of \b DAC12_xDAT register.
//!
//! Modified bits of \b DAC12_xDAT register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_setData(uint16_t baseAddress,
uint8_t submoduleSelect,
uint16_t data);
//*****************************************************************************
//
//! \brief Disables triggers to start conversions.
//!
//! This function is used to disallow triggers to start a conversion. Note that
//! this function does not have any affect if DAC12_A_TRIGGER_ENCBYPASS was set
//! for the conversionTriggerSelect parameter during initialization.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! Modified bits are \b DAC12ENC of \b DAC12_xCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_disableConversions(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
//! \brief Sets the resolution to be used by the DAC12_A module.
//!
//! This function sets the resolution of the data to be converted.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//! \param resolutionSelect is the resolution to use for conversions.
//! Valid values are:
//! - \b DAC12_A_RESOLUTION_8BIT
//! - \b DAC12_A_RESOLUTION_12BIT [Default]
//! \n Modified bits are \b DAC12RES of \b DAC12_xCTL0 register.
//!
//! Modified bits are \b DAC12ENC and \b DAC12RES of \b DAC12_xCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_setResolution(uint16_t baseAddress,
uint8_t submoduleSelect,
uint16_t resolutionSelect);
//*****************************************************************************
//
//! \brief Sets the input data format for the DAC12_A module.
//!
//! This function sets the input format for the binary data to be converted.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//! \param inputJustification is the justification of the data to be converted.
//! Valid values are:
//! - \b DAC12_A_JUSTIFICATION_RIGHT [Default]
//! - \b DAC12_A_JUSTIFICATION_LEFT
//! \n Modified bits are \b DAC12DFJ of \b DAC12_xCTL1 register.
//! \param inputSign is the sign of the data to be converted.
//! Valid values are:
//! - \b DAC12_A_UNSIGNED_BINARY [Default]
//! - \b DAC12_A_SIGNED_2SCOMPLEMENT
//! \n Modified bits are \b DAC12DF of \b DAC12_xCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void DAC12_A_setInputDataFormat(uint16_t baseAddress,
uint8_t submoduleSelect,
uint8_t inputJustification,
uint8_t inputSign);
//*****************************************************************************
//
//! \brief Returns the address of the specified DAC12_A data buffer for the DMA
//! module.
//!
//! Returns the address of the specified memory buffer. This can be used in
//! conjunction with the DMA to obtain the data directly from memory.
//!
//! \param baseAddress is the base address of the DAC12_A module.
//! \param submoduleSelect decides which DAC12_A sub-module to configure.
//! Valid values are:
//! - \b DAC12_A_SUBMODULE_0
//! - \b DAC12_A_SUBMODULE_1
//!
//! \return The address of the specified memory buffer
//
//*****************************************************************************
extern uint32_t DAC12_A_getDataBufferMemoryAddressForDMA(uint16_t baseAddress,
uint8_t submoduleSelect);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_DAC12_A_H__

View File

@@ -0,0 +1,163 @@
//*****************************************************************************
//
// dma.c - Driver for the dma Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup dma_api dma
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#if defined(__MSP430_HAS_DMAX_3__) || defined(__MSP430_HAS_DMAX_6__)
#include "dma.h"
#include <assert.h>
void DMA_init( DMA_initParam *param){
uint8_t triggerOffset = (param->channelSelect >> 4);
//Reset and Set DMA Control 0 Register
HWREG16(DMA_BASE + param->channelSelect + OFS_DMA0CTL) =
param->transferModeSelect //Set Transfer Mode
+ param->transferUnitSelect //Set Transfer Unit Size
+ param->triggerTypeSelect; //Set Trigger Type
//Set Transfer Size Amount
HWREG16(DMA_BASE + param->channelSelect + OFS_DMA0SZ) = param->transferSize;
if (triggerOffset & 0x01){ //Odd Channel
HWREG16(DMA_BASE + (triggerOffset & 0x0E)) &= 0x00FF; //Reset Trigger Select
HWREG16(DMA_BASE +
(triggerOffset & 0x0E)) |= (param->triggerSourceSelect << 8);
} else { //Even Channel
HWREG16(DMA_BASE + (triggerOffset & 0x0E)) &= 0xFF00; //Reset Trigger Select
HWREG16(DMA_BASE + (triggerOffset & 0x0E)) |= param->triggerSourceSelect;
}
}
void DMA_setTransferSize (uint8_t channelSelect,
uint16_t transferSize)
{
//Set Transfer Size Amount
HWREG16(DMA_BASE + channelSelect + OFS_DMA0SZ) = transferSize;
}
uint16_t DMA_getTransferSize (uint8_t channelSelect)
{
//Get Transfer Size Amount
return HWREG16(DMA_BASE + channelSelect + OFS_DMA0SZ);
}
void DMA_setSrcAddress (uint8_t channelSelect,
uint32_t srcAddress,
uint16_t directionSelect)
{
//Set the Source Address
__data16_write_addr((unsigned short)(DMA_BASE + channelSelect + OFS_DMA0SA),
srcAddress);
//Reset bits before setting them
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMASRCINCR_3);
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= directionSelect;
}
void DMA_setDstAddress (uint8_t channelSelect,
uint32_t dstAddress,
uint16_t directionSelect)
{
//Set the Destination Address
__data16_write_addr((unsigned short)(DMA_BASE + channelSelect + OFS_DMA0DA),
dstAddress);
//Reset bits before setting them
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMADSTINCR_3);
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= (directionSelect << 2);
}
void DMA_enableTransfers (uint8_t channelSelect)
{
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= DMAEN;
}
void DMA_disableTransfers (uint8_t channelSelect)
{
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAEN);
}
void DMA_startTransfer (uint8_t channelSelect)
{
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= DMAREQ;
}
void DMA_enableInterrupt (uint8_t channelSelect)
{
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) |= DMAIE;
}
void DMA_disableInterrupt (uint8_t channelSelect)
{
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAIE);
}
uint16_t DMA_getInterruptStatus (uint8_t channelSelect)
{
return (HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) & DMAIFG);
}
void DMA_clearInterrupt (uint8_t channelSelect)
{
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAIFG);
}
uint16_t DMA_getNMIAbortStatus (uint8_t channelSelect)
{
return (HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) & DMAABORT);
}
void DMA_clearNMIAbort (uint8_t channelSelect)
{
HWREG16(DMA_BASE + channelSelect + OFS_DMA0CTL) &= ~(DMAABORT);
}
void DMA_disableTransferDuringReadModifyWrite (void)
{
HWREG16(DMA_BASE + OFS_DMACTL4) |= DMARMWDIS;
}
void DMA_enableTransferDuringReadModifyWrite (void)
{
HWREG16(DMA_BASE + OFS_DMACTL4) &= ~(DMARMWDIS);
}
void DMA_enableRoundRobinPriority (void)
{
HWREG16(DMA_BASE + OFS_DMACTL4) |= ROUNDROBIN;
}
void DMA_disableRoundRobinPriority (void)
{
HWREG16(DMA_BASE + OFS_DMACTL4) &= ~(ROUNDROBIN);
}
void DMA_enableNMIAbort (void)
{
HWREG16(DMA_BASE + OFS_DMACTL4) |= ENNMI;
}
void DMA_disableNMIAbort (void)
{
HWREG16(DMA_BASE + OFS_DMACTL4) &= ~(ENNMI);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for dma_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,716 @@
//*****************************************************************************
//
// dma.h - Driver for the DMA Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_DMA_H__
#define __MSP430WARE_DMA_H__
#include "inc/hw_memmap.h"
#if defined(__MSP430_HAS_DMAX_3__) || defined(__MSP430_HAS_DMAX_6__)
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the DMA_init() function as the param parameter.
//
//*****************************************************************************
typedef struct DMA_initParam {
//! Is the specified channel to initialize.
//! \n Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
uint8_t channelSelect;
//! Is the transfer mode of the selected channel.
//! \n Valid values are:
//! - \b DMA_TRANSFER_SINGLE [Default] - Single transfer, transfers
//! disabled after transferAmount of transfers.
//! - \b DMA_TRANSFER_BLOCK - Multiple transfers of transferAmount,
//! transfers disabled once finished.
//! - \b DMA_TRANSFER_BURSTBLOCK - Multiple transfers of transferAmount
//! interleaved with CPU activity, transfers disabled once finished.
//! - \b DMA_TRANSFER_REPEATED_SINGLE - Repeated single transfer by
//! trigger.
//! - \b DMA_TRANSFER_REPEATED_BLOCK - Multiple transfers of transferAmount
//! by trigger.
//! - \b DMA_TRANSFER_REPEATED_BURSTBLOCK - Multiple transfers of
//! transferAmount by trigger interleaved with CPU activity.
uint16_t transferModeSelect;
//! Is the amount of transfers to complete in a block transfer mode, as
//! well as how many transfers to complete before the interrupt flag is
//! set. Valid value is between 1-65535, if 0, no transfers will occur.
uint16_t transferSize;
//! Is the source that will trigger the start of each transfer, note that
//! the sources are device specific.
//! \n Valid values are:
//! - \b DMA_TRIGGERSOURCE_0 [Default]
//! - \b DMA_TRIGGERSOURCE_1
//! - \b DMA_TRIGGERSOURCE_2
//! - \b DMA_TRIGGERSOURCE_3
//! - \b DMA_TRIGGERSOURCE_4
//! - \b DMA_TRIGGERSOURCE_5
//! - \b DMA_TRIGGERSOURCE_6
//! - \b DMA_TRIGGERSOURCE_7
//! - \b DMA_TRIGGERSOURCE_8
//! - \b DMA_TRIGGERSOURCE_9
//! - \b DMA_TRIGGERSOURCE_10
//! - \b DMA_TRIGGERSOURCE_11
//! - \b DMA_TRIGGERSOURCE_12
//! - \b DMA_TRIGGERSOURCE_13
//! - \b DMA_TRIGGERSOURCE_14
//! - \b DMA_TRIGGERSOURCE_15
//! - \b DMA_TRIGGERSOURCE_16
//! - \b DMA_TRIGGERSOURCE_17
//! - \b DMA_TRIGGERSOURCE_18
//! - \b DMA_TRIGGERSOURCE_19
//! - \b DMA_TRIGGERSOURCE_20
//! - \b DMA_TRIGGERSOURCE_21
//! - \b DMA_TRIGGERSOURCE_22
//! - \b DMA_TRIGGERSOURCE_23
//! - \b DMA_TRIGGERSOURCE_24
//! - \b DMA_TRIGGERSOURCE_25
//! - \b DMA_TRIGGERSOURCE_26
//! - \b DMA_TRIGGERSOURCE_27
//! - \b DMA_TRIGGERSOURCE_28
//! - \b DMA_TRIGGERSOURCE_29
//! - \b DMA_TRIGGERSOURCE_30
//! - \b DMA_TRIGGERSOURCE_31
uint8_t triggerSourceSelect;
//! Is the specified size of transfers.
//! \n Valid values are:
//! - \b DMA_SIZE_SRCWORD_DSTWORD [Default]
//! - \b DMA_SIZE_SRCBYTE_DSTWORD
//! - \b DMA_SIZE_SRCWORD_DSTBYTE
//! - \b DMA_SIZE_SRCBYTE_DSTBYTE
uint8_t transferUnitSelect;
//! Is the type of trigger that the trigger signal needs to be to start a
//! transfer.
//! \n Valid values are:
//! - \b DMA_TRIGGER_RISINGEDGE [Default]
//! - \b DMA_TRIGGER_HIGH - A trigger would be a high signal from the
//! trigger source, to be held high through the length of the
//! transfer(s).
uint8_t triggerTypeSelect;
} DMA_initParam;
//*****************************************************************************
//
// The following are values that can be passed to the triggerSourceSelect
// parameter for functions: DMA_init(); the param parameter for functions:
// DMA_init().
//
//*****************************************************************************
#define DMA_TRIGGERSOURCE_0 (0x00)
#define DMA_TRIGGERSOURCE_1 (0x01)
#define DMA_TRIGGERSOURCE_2 (0x02)
#define DMA_TRIGGERSOURCE_3 (0x03)
#define DMA_TRIGGERSOURCE_4 (0x04)
#define DMA_TRIGGERSOURCE_5 (0x05)
#define DMA_TRIGGERSOURCE_6 (0x06)
#define DMA_TRIGGERSOURCE_7 (0x07)
#define DMA_TRIGGERSOURCE_8 (0x08)
#define DMA_TRIGGERSOURCE_9 (0x09)
#define DMA_TRIGGERSOURCE_10 (0x0A)
#define DMA_TRIGGERSOURCE_11 (0x0B)
#define DMA_TRIGGERSOURCE_12 (0x0C)
#define DMA_TRIGGERSOURCE_13 (0x0D)
#define DMA_TRIGGERSOURCE_14 (0x0E)
#define DMA_TRIGGERSOURCE_15 (0x0F)
#define DMA_TRIGGERSOURCE_16 (0x10)
#define DMA_TRIGGERSOURCE_17 (0x11)
#define DMA_TRIGGERSOURCE_18 (0x12)
#define DMA_TRIGGERSOURCE_19 (0x13)
#define DMA_TRIGGERSOURCE_20 (0x14)
#define DMA_TRIGGERSOURCE_21 (0x15)
#define DMA_TRIGGERSOURCE_22 (0x16)
#define DMA_TRIGGERSOURCE_23 (0x17)
#define DMA_TRIGGERSOURCE_24 (0x18)
#define DMA_TRIGGERSOURCE_25 (0x19)
#define DMA_TRIGGERSOURCE_26 (0x1A)
#define DMA_TRIGGERSOURCE_27 (0x1B)
#define DMA_TRIGGERSOURCE_28 (0x1C)
#define DMA_TRIGGERSOURCE_29 (0x1D)
#define DMA_TRIGGERSOURCE_30 (0x1E)
#define DMA_TRIGGERSOURCE_31 (0x1F)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: DMA_init(); the transferModeSelect parameter for functions:
// DMA_init().
//
//*****************************************************************************
#define DMA_TRANSFER_SINGLE (DMADT_0)
#define DMA_TRANSFER_BLOCK (DMADT_1)
#define DMA_TRANSFER_BURSTBLOCK (DMADT_2)
#define DMA_TRANSFER_REPEATED_SINGLE (DMADT_4)
#define DMA_TRANSFER_REPEATED_BLOCK (DMADT_5)
#define DMA_TRANSFER_REPEATED_BURSTBLOCK (DMADT_6)
//*****************************************************************************
//
// The following are values that can be passed to the channelSelect parameter
// for functions: DMA_init(), DMA_setTransferSize(), DMA_getTransferSize(),
// DMA_setSrcAddress(), DMA_setDstAddress(), DMA_enableTransfers(),
// DMA_disableTransfers(), DMA_startTransfer(), DMA_enableInterrupt(),
// DMA_disableInterrupt(), DMA_getInterruptStatus(), DMA_clearInterrupt(),
// DMA_getNMIAbortStatus(), and DMA_clearNMIAbort(); the param parameter for
// functions: DMA_init().
//
//*****************************************************************************
#define DMA_CHANNEL_0 (0x00)
#define DMA_CHANNEL_1 (0x10)
#define DMA_CHANNEL_2 (0x20)
#define DMA_CHANNEL_3 (0x30)
#define DMA_CHANNEL_4 (0x40)
#define DMA_CHANNEL_5 (0x50)
#define DMA_CHANNEL_6 (0x60)
#define DMA_CHANNEL_7 (0x70)
//*****************************************************************************
//
// The following are values that can be passed to the triggerTypeSelect
// parameter for functions: DMA_init(); the param parameter for functions:
// DMA_init().
//
//*****************************************************************************
#define DMA_TRIGGER_RISINGEDGE (!(DMALEVEL))
#define DMA_TRIGGER_HIGH (DMALEVEL)
//*****************************************************************************
//
// The following are values that can be passed to the transferUnitSelect
// parameter for functions: DMA_init(); the param parameter for functions:
// DMA_init().
//
//*****************************************************************************
#define DMA_SIZE_SRCWORD_DSTWORD (!(DMASRCBYTE + DMADSTBYTE))
#define DMA_SIZE_SRCBYTE_DSTWORD (DMASRCBYTE)
#define DMA_SIZE_SRCWORD_DSTBYTE (DMADSTBYTE)
#define DMA_SIZE_SRCBYTE_DSTBYTE (DMASRCBYTE + DMADSTBYTE)
//*****************************************************************************
//
// The following are values that can be passed to the directionSelect parameter
// for functions: DMA_setSrcAddress(), and DMA_setDstAddress().
//
//*****************************************************************************
#define DMA_DIRECTION_UNCHANGED (DMASRCINCR_0)
#define DMA_DIRECTION_DECREMENT (DMASRCINCR_2)
#define DMA_DIRECTION_INCREMENT (DMASRCINCR_3)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the DMA_getInterruptStatus() function.
//
//*****************************************************************************
#define DMA_INT_INACTIVE (0x0)
#define DMA_INT_ACTIVE (DMAIFG)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the DMA_getNMIAbortStatus() function.
//
//*****************************************************************************
#define DMA_NOTABORTED (0x0)
#define DMA_ABORTED (DMAABORT)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the specified DMA channel.
//!
//! This function initializes the specified DMA channel. Upon successful
//! completion of initialization of the selected channel the control registers
//! will be cleared and the given variables will be set. Please note, if
//! transfers have been enabled with the enableTransfers() function, then a
//! call to disableTransfers() is necessary before re-initialization. Also
//! note, that the trigger sources are device dependent and can be found in the
//! device family data sheet. The amount of DMA channels available are also
//! device specific.
//!
//! \param param is the pointer to struct for initialization.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the initialization process.
//
//*****************************************************************************
extern void DMA_init(DMA_initParam *param);
//*****************************************************************************
//
//! \brief Sets the specified amount of transfers for the selected DMA channel.
//!
//! This function sets the specified amount of transfers for the selected DMA
//! channel without having to reinitialize the DMA channel.
//!
//! \param channelSelect is the specified channel to set source address
//! direction for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//! \param transferSize is the amount of transfers to complete in a block
//! transfer mode, as well as how many transfers to complete before the
//! interrupt flag is set. Valid value is between 1-65535, if 0, no
//! transfers will occur.
//! \n Modified bits are \b DMAxSZ of \b DMAxSZ register.
//!
//! \return None
//
//*****************************************************************************
extern void DMA_setTransferSize(uint8_t channelSelect,
uint16_t transferSize);
//*****************************************************************************
//
//! \brief Gets the amount of transfers for the selected DMA channel.
//!
//! This function gets the amount of transfers for the selected DMA channel
//! without having to reinitialize the DMA channel.
//!
//! \param channelSelect is the specified channel to set source address
//! direction for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return the amount of transfers
//
//*****************************************************************************
extern uint16_t DMA_getTransferSize(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Sets source address and the direction that the source address will
//! move after a transfer.
//!
//! This function sets the source address and the direction that the source
//! address will move after a transfer is complete. It may be incremented,
//! decremented or unchanged.
//!
//! \param channelSelect is the specified channel to set source address
//! direction for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//! \param srcAddress is the address of where the data will be transferred
//! from.
//! \n Modified bits are \b DMAxSA of \b DMAxSA register.
//! \param directionSelect is the specified direction of the source address
//! after a transfer.
//! Valid values are:
//! - \b DMA_DIRECTION_UNCHANGED
//! - \b DMA_DIRECTION_DECREMENT
//! - \b DMA_DIRECTION_INCREMENT
//! \n Modified bits are \b DMASRCINCR of \b DMAxCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void DMA_setSrcAddress(uint8_t channelSelect,
uint32_t srcAddress,
uint16_t directionSelect);
//*****************************************************************************
//
//! \brief Sets the destination address and the direction that the destination
//! address will move after a transfer.
//!
//! This function sets the destination address and the direction that the
//! destination address will move after a transfer is complete. It may be
//! incremented, decremented, or unchanged.
//!
//! \param channelSelect is the specified channel to set the destination
//! address direction for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//! \param dstAddress is the address of where the data will be transferred to.
//! \n Modified bits are \b DMAxDA of \b DMAxDA register.
//! \param directionSelect is the specified direction of the destination
//! address after a transfer.
//! Valid values are:
//! - \b DMA_DIRECTION_UNCHANGED
//! - \b DMA_DIRECTION_DECREMENT
//! - \b DMA_DIRECTION_INCREMENT
//! \n Modified bits are \b DMADSTINCR of \b DMAxCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void DMA_setDstAddress(uint8_t channelSelect,
uint32_t dstAddress,
uint16_t directionSelect);
//*****************************************************************************
//
//! \brief Enables transfers to be triggered.
//!
//! This function enables transfers upon appropriate trigger of the selected
//! trigger source for the selected channel.
//!
//! \param channelSelect is the specified channel to enable transfer for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return None
//
//*****************************************************************************
extern void DMA_enableTransfers(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Disables transfers from being triggered.
//!
//! This function disables transfer from being triggered for the selected
//! channel. This function should be called before any re-initialization of the
//! selected DMA channel.
//!
//! \param channelSelect is the specified channel to disable transfers for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return None
//
//*****************************************************************************
extern void DMA_disableTransfers(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Starts a transfer if using the default trigger source selected in
//! initialization.
//!
//! This functions triggers a transfer of data from source to destination if
//! the trigger source chosen from initialization is the DMA_TRIGGERSOURCE_0.
//! Please note, this function needs to be called for each (repeated-)single
//! transfer, and when transferAmount of transfers have been complete in
//! (repeated-)block transfers.
//!
//! \param channelSelect is the specified channel to start transfers for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return None
//
//*****************************************************************************
extern void DMA_startTransfer(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Enables the DMA interrupt for the selected channel.
//!
//! Enables the DMA interrupt source. Only the sources that are enabled can be
//! reflected to the processor interrupt; disabled sources have no effect on
//! the processor. Does not clear interrupt flags.
//!
//! \param channelSelect is the specified channel to enable the interrupt for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return None
//
//*****************************************************************************
extern void DMA_enableInterrupt(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Disables the DMA interrupt for the selected channel.
//!
//! Disables the DMA interrupt source. Only the sources that are enabled can be
//! reflected to the processor interrupt; disabled sources have no effect on
//! the processor.
//!
//! \param channelSelect is the specified channel to disable the interrupt for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return None
//
//*****************************************************************************
extern void DMA_disableInterrupt(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Returns the status of the interrupt flag for the selected channel.
//!
//! Returns the status of the interrupt flag for the selected channel.
//!
//! \param channelSelect is the specified channel to return the interrupt flag
//! status from.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return One of the following:
//! - \b DMA_INT_INACTIVE
//! - \b DMA_INT_ACTIVE
//! \n indicating the status of the current interrupt flag
//
//*****************************************************************************
extern uint16_t DMA_getInterruptStatus(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Clears the interrupt flag for the selected channel.
//!
//! This function clears the DMA interrupt flag is cleared, so that it no
//! longer asserts.
//!
//! \param channelSelect is the specified channel to clear the interrupt flag
//! for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return None
//
//*****************************************************************************
extern void DMA_clearInterrupt(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Returns the status of the NMIAbort for the selected channel.
//!
//! This function returns the status of the NMI Abort flag for the selected
//! channel. If this flag has been set, it is because a transfer on this
//! channel was aborted due to a interrupt from an NMI.
//!
//! \param channelSelect is the specified channel to return the status of the
//! NMI Abort flag for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return One of the following:
//! - \b DMA_NOTABORTED
//! - \b DMA_ABORTED
//! \n indicating the status of the NMIAbort for the selected channel
//
//*****************************************************************************
extern uint16_t DMA_getNMIAbortStatus(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Clears the status of the NMIAbort to proceed with transfers for the
//! selected channel.
//!
//! This function clears the status of the NMI Abort flag for the selected
//! channel to allow for transfers on the channel to continue.
//!
//! \param channelSelect is the specified channel to clear the NMI Abort flag
//! for.
//! Valid values are:
//! - \b DMA_CHANNEL_0
//! - \b DMA_CHANNEL_1
//! - \b DMA_CHANNEL_2
//! - \b DMA_CHANNEL_3
//! - \b DMA_CHANNEL_4
//! - \b DMA_CHANNEL_5
//! - \b DMA_CHANNEL_6
//! - \b DMA_CHANNEL_7
//!
//! \return None
//
//*****************************************************************************
extern void DMA_clearNMIAbort(uint8_t channelSelect);
//*****************************************************************************
//
//! \brief Disables the DMA from stopping the CPU during a Read-Modify-Write
//! Operation to start a transfer.
//!
//! This function allows the CPU to finish any read-modify-write operations it
//! may be in the middle of before transfers of and DMA channel stop the CPU.
//!
//!
//! \return None
//
//*****************************************************************************
extern void DMA_disableTransferDuringReadModifyWrite(void);
//*****************************************************************************
//
//! \brief Enables the DMA to stop the CPU during a Read-Modify-Write Operation
//! to start a transfer.
//!
//! This function allows the DMA to stop the CPU in the middle of a read-
//! modify-write operation to transfer data.
//!
//!
//! \return None
//
//*****************************************************************************
extern void DMA_enableTransferDuringReadModifyWrite(void);
//*****************************************************************************
//
//! \brief Enables Round Robin prioritization.
//!
//! This function enables Round Robin Prioritization of DMA channels. In the
//! case of Round Robin Prioritization, the last DMA channel to have
//! transferred data then has the last priority, which comes into play when
//! multiple DMA channels are ready to transfer at the same time.
//!
//!
//! \return None
//
//*****************************************************************************
extern void DMA_enableRoundRobinPriority(void);
//*****************************************************************************
//
//! \brief Disables Round Robin prioritization.
//!
//! This function disables Round Robin Prioritization, enabling static
//! prioritization of the DMA channels. In static prioritization, the DMA
//! channels are prioritized with the lowest DMA channel index having the
//! highest priority (i.e. DMA Channel 0 has the highest priority).
//!
//!
//! \return None
//
//*****************************************************************************
extern void DMA_disableRoundRobinPriority(void);
//*****************************************************************************
//
//! \brief Enables a NMI to interrupt a DMA transfer.
//!
//! This function allow NMI's to interrupting any DMA transfer currently in
//! progress and stops any future transfers to begin before the NMI is done
//! processing.
//!
//!
//! \return None
//
//*****************************************************************************
extern void DMA_enableNMIAbort(void);
//*****************************************************************************
//
//! \brief Disables any NMI from interrupting a DMA transfer.
//!
//! This function disables NMI's from interrupting any DMA transfer currently
//! in progress.
//!
//!
//! \return None
//
//*****************************************************************************
extern void DMA_disableNMIAbort(void);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_DMA_H__

View File

@@ -0,0 +1,43 @@
#include "inc/hw_memmap.h"
#include "eusci_b_i2c.h"
#include "ctsd16.h"
#include "battbak.h"
#include "timer_b.h"
#include "timer_d.h"
#include "eusci_a_spi.h"
#include "eusci_a_uart.h"
#include "comp_b.h"
#include "tlv.h"
#include "dac12_a.h"
#include "timer_a.h"
#include "usci_a_uart.h"
#include "pmm.h"
#include "sysctl.h"
#include "adc10_a.h"
#include "sfr.h"
#include "mpy32.h"
#include "wdt_a.h"
#include "ucs.h"
#include "pmap.h"
#include "rtc_a.h"
#include "usci_b_i2c.h"
#include "usci_b_spi.h"
#include "ldopwr.h"
#include "lcd_c.h"
#include "tec.h"
#include "rtc_c.h"
#include "gpio.h"
#include "adc12_a.h"
#include "aes.h"
#include "oa.h"
#include "rtc_b.h"
#include "sd24_b.h"
#include "ram.h"
#include "dma.h"
#include "ref.h"
#include "eusci_b_spi.h"
#include "usci_a_spi.h"
#include "lcd_b.h"
#include "flashctl.h"
#include "crc.h"

View File

@@ -0,0 +1,197 @@
//*****************************************************************************
//
// eusci_a_spi.c - Driver for the eusci_a_spi Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup eusci_a_spi_api eusci_a_spi
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_EUSCI_Ax__
#include "eusci_a_spi.h"
#include <assert.h>
void EUSCI_A_SPI_initMaster (uint16_t baseAddress,
EUSCI_A_SPI_initMasterParam *param)
{
//Disable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
//Reset OFS_UCAxCTLW0 values
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCCKPH + UCCKPL + UC7BIT + UCMSB +
UCMST + UCMODE_3 + UCSYNC);
//Reset OFS_UCAxCTLW0 values
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSSEL_3);
//Select Clock
HWREG16(baseAddress + OFS_UCAxCTLW0) |= (uint16_t)param->selectClockSource;
HWREG16(baseAddress + OFS_UCAxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
/*
* Configure as SPI master mode.
* Clock phase select, polarity, msb
* UCMST = Master mode
* UCSYNC = Synchronous mode
* UCMODE_0 = 3-pin SPI
*/
HWREG16(baseAddress + OFS_UCAxCTLW0) |= (
param->msbFirst +
param->clockPhase +
param->clockPolarity +
UCMST +
UCSYNC +
param->spiMode
);
//No modulation
HWREG16(baseAddress + OFS_UCAxMCTLW) = 0;
}
void EUSCI_A_SPI_select4PinFunctionality (uint16_t baseAddress,
uint16_t select4PinFunctionality
)
{
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCSTEM;
HWREG16(baseAddress + OFS_UCAxCTLW0) |= select4PinFunctionality;
}
void EUSCI_A_SPI_changeMasterClock (uint16_t baseAddress,
EUSCI_A_SPI_changeMasterClockParam *param)
{
//Disable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
HWREG16(baseAddress + OFS_UCAxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSWRST);
}
void EUSCI_A_SPI_initSlave (uint16_t baseAddress, EUSCI_A_SPI_initSlaveParam *param)
{
//Disable USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
//Reset OFS_UCAxCTLW0 register
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCMSB +
UC7BIT +
UCMST +
UCCKPL +
UCCKPH +
UCMODE_3
);
//Clock polarity, phase select, msbFirst, SYNC, Mode0
HWREG16(baseAddress + OFS_UCAxCTLW0) |= (param->clockPhase +
param->clockPolarity +
param->msbFirst +
UCSYNC +
param->spiMode
);
}
void EUSCI_A_SPI_changeClockPhasePolarity (uint16_t baseAddress,
uint16_t clockPhase,
uint16_t clockPolarity
)
{
//Disable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCCKPH + UCCKPL);
HWREG16(baseAddress + OFS_UCAxCTLW0) |= (
clockPhase +
clockPolarity
);
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSWRST);
}
void EUSCI_A_SPI_transmitData ( uint16_t baseAddress,
uint8_t transmitData
)
{
HWREG16(baseAddress + OFS_UCAxTXBUF) = transmitData;
}
uint8_t EUSCI_A_SPI_receiveData (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_UCAxRXBUF)) ;
}
void EUSCI_A_SPI_enableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG16(baseAddress + OFS_UCAxIE) |= mask;
}
void EUSCI_A_SPI_disableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG16(baseAddress + OFS_UCAxIE) &= ~mask;
}
uint8_t EUSCI_A_SPI_getInterruptStatus (uint16_t baseAddress,
uint8_t mask
)
{
return ( HWREG16(baseAddress + OFS_UCAxIFG) & mask );
}
void EUSCI_A_SPI_clearInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG16(baseAddress + OFS_UCAxIFG) &= ~mask;
}
void EUSCI_A_SPI_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSWRST);
}
void EUSCI_A_SPI_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
}
uint32_t EUSCI_A_SPI_getReceiveBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxRXBUF );
}
uint32_t EUSCI_A_SPI_getTransmitBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxTXBUF );
}
uint16_t EUSCI_A_SPI_isBusy (uint16_t baseAddress)
{
//Return the bus busy status.
return (HWREG16(baseAddress + OFS_UCAxSTATW) & UCBUSY);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for eusci_a_spi_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,495 @@
//*****************************************************************************
//
// eusci_a_spi.h - Driver for the EUSCI_A_SPI Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_EUSCI_A_SPI_H__
#define __MSP430WARE_EUSCI_A_SPI_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_EUSCI_Ax__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the EUSCI_A_SPI_changeMasterClock() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct EUSCI_A_SPI_changeMasterClockParam {
//! Is the frequency of the selected clock source in Hz
uint32_t clockSourceFrequency;
//! Is the desired clock rate in Hz for SPI communication
uint32_t desiredSpiClock;
} EUSCI_A_SPI_changeMasterClockParam;
//*****************************************************************************
//
//! \brief Used in the EUSCI_A_SPI_initSlave() function as the param parameter.
//
//*****************************************************************************
typedef struct EUSCI_A_SPI_initSlaveParam {
//! Controls the direction of the receive and transmit shift register.
//! \n Valid values are:
//! - \b EUSCI_A_SPI_MSB_FIRST
//! - \b EUSCI_A_SPI_LSB_FIRST [Default]
uint16_t msbFirst;
//! Is clock phase select.
//! \n Valid values are:
//! - \b EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
//! - \b EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
uint16_t clockPhase;
//! Is clock polarity select
//! \n Valid values are:
//! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
uint16_t clockPolarity;
//! Is SPI mode select
//! \n Valid values are:
//! - \b EUSCI_A_SPI_3PIN
//! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_HIGH
//! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_LOW
uint16_t spiMode;
} EUSCI_A_SPI_initSlaveParam;
//*****************************************************************************
//
//! \brief Used in the EUSCI_A_SPI_initMaster() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct EUSCI_A_SPI_initMasterParam {
//! Selects Clock source. Refer to device specific datasheet for available
//! options.
//! \n Valid values are:
//! - \b EUSCI_A_SPI_CLOCKSOURCE_ACLK
//! - \b EUSCI_A_SPI_CLOCKSOURCE_SMCLK
uint8_t selectClockSource;
//! Is the frequency of the selected clock source in Hz
uint32_t clockSourceFrequency;
//! Is the desired clock rate in Hz for SPI communication
uint32_t desiredSpiClock;
//! Controls the direction of the receive and transmit shift register.
//! \n Valid values are:
//! - \b EUSCI_A_SPI_MSB_FIRST
//! - \b EUSCI_A_SPI_LSB_FIRST [Default]
uint16_t msbFirst;
//! Is clock phase select.
//! \n Valid values are:
//! - \b EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
//! - \b EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
uint16_t clockPhase;
//! Is clock polarity select
//! \n Valid values are:
//! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
uint16_t clockPolarity;
//! Is SPI mode select
//! \n Valid values are:
//! - \b EUSCI_A_SPI_3PIN
//! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_HIGH
//! - \b EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_LOW
uint16_t spiMode;
} EUSCI_A_SPI_initMasterParam;
//*****************************************************************************
//
// The following are values that can be passed to the clockPhase parameter for
// functions: EUSCI_A_SPI_changeClockPhasePolarity(); the param parameter for
// functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave().
//
//*****************************************************************************
#define EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT 0x00
#define EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT UCCKPH
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave().
//
//*****************************************************************************
#define EUSCI_A_SPI_MSB_FIRST UCMSB
#define EUSCI_A_SPI_LSB_FIRST 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave(); the
// clockPolarity parameter for functions:
// EUSCI_A_SPI_changeClockPhasePolarity().
//
//*****************************************************************************
#define EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH UCCKPL
#define EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_SPI_initMaster().
//
//*****************************************************************************
#define EUSCI_A_SPI_CLOCKSOURCE_ACLK UCSSEL__ACLK
#define EUSCI_A_SPI_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_SPI_initMaster(), and EUSCI_A_SPI_initSlave().
//
//*****************************************************************************
#define EUSCI_A_SPI_3PIN UCMODE_0
#define EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_HIGH UCMODE_1
#define EUSCI_A_SPI_4PIN_UCxSTE_ACTIVE_LOW UCMODE_2
//*****************************************************************************
//
// The following are values that can be passed to the select4PinFunctionality
// parameter for functions: EUSCI_A_SPI_select4PinFunctionality().
//
//*****************************************************************************
#define EUSCI_A_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS 0x0000
#define EUSCI_A_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE UCSTEM
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: EUSCI_A_SPI_enableInterrupt(), EUSCI_A_SPI_disableInterrupt(),
// EUSCI_A_SPI_getInterruptStatus(), and EUSCI_A_SPI_clearInterrupt() as well
// as returned by the EUSCI_A_SPI_getInterruptStatus() function.
//
//*****************************************************************************
#define EUSCI_A_SPI_TRANSMIT_INTERRUPT UCTXIE
#define EUSCI_A_SPI_RECEIVE_INTERRUPT UCRXIE
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the EUSCI_A_SPI_isBusy() function.
//
//*****************************************************************************
#define EUSCI_A_SPI_BUSY UCBUSY
#define EUSCI_A_SPI_NOT_BUSY 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the SPI Master block.
//!
//! Upon successful initialization of the SPI master block, this function will
//! have set the bus speed for the master, but the SPI Master block still
//! remains disabled and must be enabled with EUSCI_A_SPI_enable()
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI Master module.
//! \param param is the pointer to struct for master initialization.
//!
//! Modified bits are \b UCCKPH, \b UCCKPL, \b UC7BIT, \b UCMSB, \b UCSSELx and
//! \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern void EUSCI_A_SPI_initMaster(uint16_t baseAddress,
EUSCI_A_SPI_initMasterParam *param);
//*****************************************************************************
//
//! \brief Selects 4Pin Functionality
//!
//! This function should be invoked only in 4-wire mode. Invoking this function
//! has no effect in 3-wire mode.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param select4PinFunctionality selects 4 pin functionality
//! Valid values are:
//! - \b EUSCI_A_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS
//! - \b EUSCI_A_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE
//!
//! Modified bits are \b UCSTEM of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_select4PinFunctionality(uint16_t baseAddress,
uint16_t select4PinFunctionality);
//*****************************************************************************
//
//! \brief Initializes the SPI Master clock. At the end of this function call,
//! SPI module is left enabled.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param param is the pointer to struct for master clock setting.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_changeMasterClock(uint16_t baseAddress,
EUSCI_A_SPI_changeMasterClockParam *param);
//*****************************************************************************
//
//! \brief Initializes the SPI Slave block.
//!
//! Upon successful initialization of the SPI slave block, this function will
//! have initialized the slave block, but the SPI Slave block still remains
//! disabled and must be enabled with EUSCI_A_SPI_enable()
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI Slave module.
//! \param param is the pointer to struct for slave initialization.
//!
//! Modified bits are \b UCMSB, \b UCMST, \b UC7BIT, \b UCCKPL, \b UCCKPH, \b
//! UCMODE and \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern void EUSCI_A_SPI_initSlave(uint16_t baseAddress,
EUSCI_A_SPI_initSlaveParam *param);
//*****************************************************************************
//
//! \brief Changes the SPI clock phase and polarity. At the end of this
//! function call, SPI module is left enabled.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param clockPhase is clock phase select.
//! Valid values are:
//! - \b EUSCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
//! [Default]
//! - \b EUSCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
//! \param clockPolarity is clock polarity select
//! Valid values are:
//! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b EUSCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
//!
//! Modified bits are \b UCCKPL, \b UCCKPH and \b UCSWRST of \b UCAxCTLW0
//! register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_changeClockPhasePolarity(uint16_t baseAddress,
uint16_t clockPhase,
uint16_t clockPolarity);
//*****************************************************************************
//
//! \brief Transmits a byte from the SPI Module.
//!
//! This function will place the supplied data into SPI transmit data register
//! to start transmission.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param transmitData data to be transmitted from the SPI module
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_transmitData(uint16_t baseAddress,
uint8_t transmitData);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the SPI Module.
//!
//! This function reads a byte of data from the SPI receive data Register.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//!
//! \return Returns the byte received from by the SPI module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t EUSCI_A_SPI_receiveData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables individual SPI interrupt sources.
//!
//! Enables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIFG register and bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_enableInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Disables individual SPI interrupt sources.
//!
//! Disables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_disableInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Gets the current SPI interrupt status.
//!
//! This returns the interrupt status for the SPI module based on which flag is
//! passed.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
//!
//! \return Logical OR of any of the following:
//! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t EUSCI_A_SPI_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears the selected SPI interrupt status flag.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//! \param mask is the masked interrupt flag to be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_A_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_clearInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Enables the SPI block.
//!
//! This will enable operation of the SPI block.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the SPI block.
//!
//! This will disable operation of the SPI block.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_SPI_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the RX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI RX Buffer. This can be used in conjunction
//! with the DMA to store the received data directly to memory.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//!
//! \return the address of the RX Buffer
//
//*****************************************************************************
extern uint32_t EUSCI_A_SPI_getReceiveBufferAddress(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the TX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI TX Buffer. This can be used in conjunction
//! with the DMA to obtain transmitted data directly from memory.
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//!
//! \return the address of the TX Buffer
//
//*****************************************************************************
extern uint32_t EUSCI_A_SPI_getTransmitBufferAddress(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Indicates whether or not the SPI bus is busy.
//!
//! This function returns an indication of whether or not the SPI bus is
//! busy.This function checks the status of the bus via UCBBUSY bit
//!
//! \param baseAddress is the base address of the EUSCI_A_SPI module.
//!
//! \return One of the following:
//! - \b EUSCI_A_SPI_BUSY
//! - \b EUSCI_A_SPI_NOT_BUSY
//! \n indicating if the EUSCI_A_SPI is busy
//
//*****************************************************************************
extern uint16_t EUSCI_A_SPI_isBusy(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_EUSCI_A_SPI_H__

View File

@@ -0,0 +1,236 @@
//*****************************************************************************
//
// eusci_a_uart.c - Driver for the eusci_a_uart Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup eusci_a_uart_api eusci_a_uart
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_EUSCI_Ax__
#include "eusci_a_uart.h"
#include <assert.h>
bool EUSCI_A_UART_init(uint16_t baseAddress, EUSCI_A_UART_initParam *param)
{
bool retVal = STATUS_SUCCESS;
//Disable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
//Clock source select
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCSSEL_3;
HWREG16(baseAddress + OFS_UCAxCTLW0) |= (uint16_t)param->selectClockSource;
//MSB, LSB select
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCMSB;
HWREG16(baseAddress + OFS_UCAxCTLW0) |= param->msborLsbFirst;
//UCSPB = 0(1 stop bit) OR 1(2 stop bits)
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCSPB;
HWREG16(baseAddress + OFS_UCAxCTLW0) |= param->numberofStopBits;
//Parity
switch (param->parity){
case EUSCI_A_UART_NO_PARITY:
//No Parity
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCPEN;
break;
case EUSCI_A_UART_ODD_PARITY:
//Odd Parity
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCPEN;
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCPAR;
break;
case EUSCI_A_UART_EVEN_PARITY:
//Even Parity
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCPEN;
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCPAR;
break;
}
//BaudRate Control Register
HWREG16(baseAddress + OFS_UCAxBRW ) = param->clockPrescalar;
//Modulation Control Register
HWREG16(baseAddress + OFS_UCAxMCTLW) = ((param->secondModReg <<8)
+ (param->firstModReg <<4) + param->overSampling );
//Asynchronous mode & 8 bit character select & clear mode
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSYNC +
UC7BIT +
UCMODE_3
);
//Configure UART mode.
HWREG16(baseAddress + OFS_UCAxCTLW0) |= param->uartMode ;
//Reset UCRXIE, UCBRKIE, UCDORM, UCTXADDR, UCTXBRK
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCRXEIE + UCBRKIE + UCDORM +
UCTXADDR + UCTXBRK
);
return (retVal);
}
void EUSCI_A_UART_transmitData ( uint16_t baseAddress,
uint8_t transmitData
)
{
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCAxIE) & UCTXIE)){
//Poll for transmit interrupt flag
while (!(HWREG16(baseAddress + OFS_UCAxIFG) & UCTXIFG));
}
HWREG16(baseAddress + OFS_UCAxTXBUF) = transmitData;
}
uint8_t EUSCI_A_UART_receiveData (uint16_t baseAddress)
{
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCAxIE) & UCRXIE)){
//Poll for receive interrupt flag
while (!(HWREG16(baseAddress + OFS_UCAxIFG) & UCRXIFG));
}
return ( HWREG16(baseAddress + OFS_UCAxRXBUF)) ;
}
void EUSCI_A_UART_enableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
uint8_t locMask;
locMask = (mask & (EUSCI_A_UART_RECEIVE_INTERRUPT
| EUSCI_A_UART_TRANSMIT_INTERRUPT
| EUSCI_A_UART_STARTBIT_INTERRUPT
| EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT));
HWREG16(baseAddress + OFS_UCAxIE) |= (uint16_t)locMask;
locMask = (mask & (EUSCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT
| EUSCI_A_UART_BREAKCHAR_INTERRUPT));
HWREG16(baseAddress + OFS_UCAxCTLW0) |= (uint16_t)locMask;
}
void EUSCI_A_UART_disableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
uint8_t locMask;
locMask = (mask & (EUSCI_A_UART_RECEIVE_INTERRUPT
| EUSCI_A_UART_TRANSMIT_INTERRUPT
| EUSCI_A_UART_STARTBIT_INTERRUPT
| EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT));
HWREG16(baseAddress + OFS_UCAxIE) &= (uint16_t)~locMask;
locMask = (mask & (EUSCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT
| EUSCI_A_UART_BREAKCHAR_INTERRUPT));
HWREG16(baseAddress + OFS_UCAxCTLW0) &= (uint16_t)~locMask;
}
uint8_t EUSCI_A_UART_getInterruptStatus (uint16_t baseAddress,
uint8_t mask)
{
return ( HWREG16(baseAddress + OFS_UCAxIFG) & mask );
}
void EUSCI_A_UART_clearInterrupt (uint16_t baseAddress, uint16_t mask)
{
//Clear the UART interrupt source.
HWREG16(baseAddress + OFS_UCAxIFG) &= ~(mask);
}
void EUSCI_A_UART_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~(UCSWRST);
}
void EUSCI_A_UART_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCSWRST;
}
uint8_t EUSCI_A_UART_queryStatusFlags (uint16_t baseAddress,
uint8_t mask)
{
return ( HWREG16(baseAddress + OFS_UCAxSTATW) & mask );
}
void EUSCI_A_UART_setDormant (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCDORM;
}
void EUSCI_A_UART_resetDormant (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_UCAxCTLW0) &= ~UCDORM;
}
void EUSCI_A_UART_transmitAddress (uint16_t baseAddress,
uint8_t transmitAddress)
{
//Set UCTXADDR bit
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCTXADDR;
//Place next byte to be sent into the transmit buffer
HWREG16(baseAddress + OFS_UCAxTXBUF) = transmitAddress;
}
void EUSCI_A_UART_transmitBreak (uint16_t baseAddress)
{
//Set UCTXADDR bit
HWREG16(baseAddress + OFS_UCAxCTLW0) |= UCTXBRK;
//If current mode is automatic baud-rate detection
if (EUSCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE ==
(HWREG16(baseAddress + OFS_UCAxCTLW0) &
EUSCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE)){
HWREG16(baseAddress + OFS_UCAxTXBUF) = EUSCI_A_UART_AUTOMATICBAUDRATE_SYNC;
} else {
HWREG16(baseAddress + OFS_UCAxTXBUF) = DEFAULT_SYNC;
}
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCAxIE) & UCTXIE)){
//Poll for transmit interrupt flag
while (!(HWREG16(baseAddress + OFS_UCAxIFG) & UCTXIFG));
}
}
uint32_t EUSCI_A_UART_getReceiveBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxRXBUF );
}
uint32_t EUSCI_A_UART_getTransmitBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxTXBUF );
}
void EUSCI_A_UART_selectDeglitchTime(uint16_t baseAddress,
uint16_t deglitchTime
)
{
HWREG16(baseAddress + OFS_UCAxCTLW1) &= ~(UCGLIT1 + UCGLIT0);
HWREG16(baseAddress + OFS_UCAxCTLW1) |= deglitchTime;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for eusci_a_uart_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,574 @@
//*****************************************************************************
//
// eusci_a_uart.h - Driver for the EUSCI_A_UART Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_EUSCI_A_UART_H__
#define __MSP430WARE_EUSCI_A_UART_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_EUSCI_Ax__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
// The following values are the sync characters possible.
//
//*****************************************************************************
#define DEFAULT_SYNC 0x00
#define EUSCI_A_UART_AUTOMATICBAUDRATE_SYNC 0x55
//*****************************************************************************
//
//! \brief Used in the EUSCI_A_UART_init() function as the param parameter.
//
//*****************************************************************************
typedef struct EUSCI_A_UART_initParam {
//! Selects Clock source. Refer to device specific datasheet for available
//! options.
//! \n Valid values are:
//! - \b EUSCI_A_UART_CLOCKSOURCE_SMCLK
//! - \b EUSCI_A_UART_CLOCKSOURCE_ACLK
uint8_t selectClockSource;
//! Is the value to be written into UCBRx bits
uint16_t clockPrescalar;
//! Is First modulation stage register setting. This value is a pre-
//! calculated value which can be obtained from the Device Users Guide.
//! This value is written into UCBRFx bits of UCAxMCTLW.
uint8_t firstModReg;
//! Is Second modulation stage register setting. This value is a pre-
//! calculated value which can be obtained from the Device Users Guide.
//! This value is written into UCBRSx bits of UCAxMCTLW.
uint8_t secondModReg;
//! Is the desired parity.
//! \n Valid values are:
//! - \b EUSCI_A_UART_NO_PARITY [Default]
//! - \b EUSCI_A_UART_ODD_PARITY
//! - \b EUSCI_A_UART_EVEN_PARITY
uint8_t parity;
//! Controls direction of receive and transmit shift register.
//! \n Valid values are:
//! - \b EUSCI_A_UART_MSB_FIRST
//! - \b EUSCI_A_UART_LSB_FIRST [Default]
uint16_t msborLsbFirst;
//! Indicates one/two STOP bits
//! \n Valid values are:
//! - \b EUSCI_A_UART_ONE_STOP_BIT [Default]
//! - \b EUSCI_A_UART_TWO_STOP_BITS
uint16_t numberofStopBits;
//! Selects the mode of operation
//! \n Valid values are:
//! - \b EUSCI_A_UART_MODE [Default]
//! - \b EUSCI_A_UART_IDLE_LINE_MULTI_PROCESSOR_MODE
//! - \b EUSCI_A_UART_ADDRESS_BIT_MULTI_PROCESSOR_MODE
//! - \b EUSCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE
uint16_t uartMode;
//! Indicates low frequency or oversampling baud generation
//! \n Valid values are:
//! - \b EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION
//! - \b EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION
uint8_t overSampling;
} EUSCI_A_UART_initParam;
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_UART_init().
//
//*****************************************************************************
#define EUSCI_A_UART_NO_PARITY 0x00
#define EUSCI_A_UART_ODD_PARITY 0x01
#define EUSCI_A_UART_EVEN_PARITY 0x02
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_UART_init().
//
//*****************************************************************************
#define EUSCI_A_UART_MSB_FIRST UCMSB
#define EUSCI_A_UART_LSB_FIRST 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_UART_init().
//
//*****************************************************************************
#define EUSCI_A_UART_MODE UCMODE_0
#define EUSCI_A_UART_IDLE_LINE_MULTI_PROCESSOR_MODE UCMODE_1
#define EUSCI_A_UART_ADDRESS_BIT_MULTI_PROCESSOR_MODE UCMODE_2
#define EUSCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE UCMODE_3
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_UART_init().
//
//*****************************************************************************
#define EUSCI_A_UART_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
#define EUSCI_A_UART_CLOCKSOURCE_ACLK UCSSEL__ACLK
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_UART_init().
//
//*****************************************************************************
#define EUSCI_A_UART_ONE_STOP_BIT 0x00
#define EUSCI_A_UART_TWO_STOP_BITS UCSPB
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_A_UART_init().
//
//*****************************************************************************
#define EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION 0x01
#define EUSCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION 0x00
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: EUSCI_A_UART_enableInterrupt(), and
// EUSCI_A_UART_disableInterrupt().
//
//*****************************************************************************
#define EUSCI_A_UART_RECEIVE_INTERRUPT UCRXIE
#define EUSCI_A_UART_TRANSMIT_INTERRUPT UCTXIE
#define EUSCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT UCRXEIE
#define EUSCI_A_UART_BREAKCHAR_INTERRUPT UCBRKIE
#define EUSCI_A_UART_STARTBIT_INTERRUPT UCSTTIE
#define EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT UCTXCPTIE
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: EUSCI_A_UART_getInterruptStatus(), and
// EUSCI_A_UART_clearInterrupt() as well as returned by the
// EUSCI_A_UART_getInterruptStatus() function.
//
//*****************************************************************************
#define EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG UCRXIFG
#define EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG UCTXIFG
#define EUSCI_A_UART_STARTBIT_INTERRUPT_FLAG UCSTTIFG
#define EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG UCTXCPTIFG
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: EUSCI_A_UART_queryStatusFlags() as well as returned by the
// EUSCI_A_UART_queryStatusFlags() function.
//
//*****************************************************************************
#define EUSCI_A_UART_LISTEN_ENABLE UCLISTEN
#define EUSCI_A_UART_FRAMING_ERROR UCFE
#define EUSCI_A_UART_OVERRUN_ERROR UCOE
#define EUSCI_A_UART_PARITY_ERROR UCPE
#define EUSCI_A_UART_BREAK_DETECT UCBRK
#define EUSCI_A_UART_RECEIVE_ERROR UCRXERR
#define EUSCI_A_UART_ADDRESS_RECEIVED UCADDR
#define EUSCI_A_UART_IDLELINE UCIDLE
#define EUSCI_A_UART_BUSY UCBUSY
//*****************************************************************************
//
// The following are values that can be passed to the deglitchTime parameter
// for functions: EUSCI_A_UART_selectDeglitchTime().
//
//*****************************************************************************
#define EUSCI_A_UART_DEGLITCH_TIME_2ns 0x00
#define EUSCI_A_UART_DEGLITCH_TIME_50ns UCGLIT0
#define EUSCI_A_UART_DEGLITCH_TIME_100ns UCGLIT1
#define EUSCI_A_UART_DEGLITCH_TIME_200ns (UCGLIT0 + UCGLIT1)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Advanced initialization routine for the UART block. The values to be
//! written into the clockPrescalar, firstModReg, secondModReg and overSampling
//! parameters should be pre-computed and passed into the initialization
//! function.
//!
//! Upon successful initialization of the UART block, this function will have
//! initialized the module, but the UART block still remains disabled and must
//! be enabled with EUSCI_A_UART_enable(). To calculate values for
//! clockPrescalar, firstModReg, secondModReg and overSampling please use the
//! link below.
//!
//! http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param param is the pointer to struct for initialization.
//!
//! Modified bits are \b UCPEN, \b UCPAR, \b UCMSB, \b UC7BIT, \b UCSPB, \b
//! UCMODEx and \b UCSYNC of \b UCAxCTL0 register; bits \b UCSSELx and \b
//! UCSWRST of \b UCAxCTL1 register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL of the initialization process
//
//*****************************************************************************
extern bool EUSCI_A_UART_init(uint16_t baseAddress,
EUSCI_A_UART_initParam *param);
//*****************************************************************************
//
//! \brief Transmits a byte from the UART Module.Please note that if TX
//! interrupt is disabled, this function manually polls the TX IFG flag waiting
//! for an indication that it is safe to write to the transmit buffer and does
//! not time-out
//!
//! This function will place the supplied data into UART transmit data register
//! to start transmission
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param transmitData data to be transmitted from the UART module
//!
//! Modified bits of \b UCAxTXBUF register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_transmitData(uint16_t baseAddress,
uint8_t transmitData);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the UART Module.
//!
//! This function reads a byte of data from the UART receive data Register.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! Modified bits of \b UCAxRXBUF register.
//!
//! \return Returns the byte received from by the UART module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t EUSCI_A_UART_receiveData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables individual UART interrupt sources.
//!
//! Enables the indicated UART interrupt sources. The interrupt flag is first
//! and then the corresponding interrupt is enabled. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_UART_RECEIVE_INTERRUPT - Receive interrupt
//! - \b EUSCI_A_UART_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b EUSCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT - Receive
//! erroneous-character interrupt enable
//! - \b EUSCI_A_UART_BREAKCHAR_INTERRUPT - Receive break character
//! interrupt enable
//! - \b EUSCI_A_UART_STARTBIT_INTERRUPT - Start bit received interrupt
//! enable
//! - \b EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT - Transmit complete
//! interrupt enable
//!
//! Modified bits of \b UCAxCTL1 register and bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_enableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Disables individual UART interrupt sources.
//!
//! Disables the indicated UART interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_UART_RECEIVE_INTERRUPT - Receive interrupt
//! - \b EUSCI_A_UART_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b EUSCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT - Receive
//! erroneous-character interrupt enable
//! - \b EUSCI_A_UART_BREAKCHAR_INTERRUPT - Receive break character
//! interrupt enable
//! - \b EUSCI_A_UART_STARTBIT_INTERRUPT - Start bit received interrupt
//! enable
//! - \b EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT - Transmit complete
//! interrupt enable
//!
//! Modified bits of \b UCAxCTL1 register and bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_disableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current UART interrupt status.
//!
//! This returns the interrupt status for the UART module based on which flag
//! is passed.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_STARTBIT_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG
//!
//! Modified bits of \b UCAxIFG register.
//!
//! \return Logical OR of any of the following:
//! - \b EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_STARTBIT_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG
//! \n indicating the status of the masked flags
//
//*****************************************************************************
extern uint8_t EUSCI_A_UART_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears UART interrupt sources.
//!
//! The UART interrupt source is cleared, so that it no longer asserts. The
//! highest interrupt flag is automatically cleared when an interrupt vector
//! generator is used.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param mask is a bit mask of the interrupt sources to be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_STARTBIT_INTERRUPT_FLAG
//! - \b EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG
//!
//! Modified bits of \b UCAxIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_clearInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Enables the UART block.
//!
//! This will enable operation of the UART block.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the UART block.
//!
//! This will disable operation of the UART block.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Gets the current UART status flags.
//!
//! This returns the status for the UART module based on which flag is passed.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_A_UART_LISTEN_ENABLE
//! - \b EUSCI_A_UART_FRAMING_ERROR
//! - \b EUSCI_A_UART_OVERRUN_ERROR
//! - \b EUSCI_A_UART_PARITY_ERROR
//! - \b EUSCI_A_UART_BREAK_DETECT
//! - \b EUSCI_A_UART_RECEIVE_ERROR
//! - \b EUSCI_A_UART_ADDRESS_RECEIVED
//! - \b EUSCI_A_UART_IDLELINE
//! - \b EUSCI_A_UART_BUSY
//!
//! Modified bits of \b UCAxSTAT register.
//!
//! \return Logical OR of any of the following:
//! - \b EUSCI_A_UART_LISTEN_ENABLE
//! - \b EUSCI_A_UART_FRAMING_ERROR
//! - \b EUSCI_A_UART_OVERRUN_ERROR
//! - \b EUSCI_A_UART_PARITY_ERROR
//! - \b EUSCI_A_UART_BREAK_DETECT
//! - \b EUSCI_A_UART_RECEIVE_ERROR
//! - \b EUSCI_A_UART_ADDRESS_RECEIVED
//! - \b EUSCI_A_UART_IDLELINE
//! - \b EUSCI_A_UART_BUSY
//! \n indicating the status of the masked interrupt flags
//
//*****************************************************************************
extern uint8_t EUSCI_A_UART_queryStatusFlags(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Sets the UART module in dormant mode
//!
//! Puts USCI in sleep mode Only characters that are preceded by an idle-line
//! or with address bit set UCRXIFG. In UART mode with automatic baud-rate
//! detection, only the combination of a break and sync field sets UCRXIFG.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! Modified bits of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_setDormant(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Re-enables UART module from dormant mode
//!
//! Not dormant. All received characters set UCRXIFG.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! Modified bits are \b UCDORM of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_resetDormant(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Transmits the next byte to be transmitted marked as address
//! depending on selected multiprocessor mode
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param transmitAddress is the next byte to be transmitted
//!
//! Modified bits of \b UCAxTXBUF register and bits of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_transmitAddress(uint16_t baseAddress,
uint8_t transmitAddress);
//*****************************************************************************
//
//! \brief Transmit break.
//!
//! Transmits a break with the next write to the transmit buffer. In UART mode
//! with automatic baud-rate detection,
//! EUSCI_A_UART_AUTOMATICBAUDRATE_SYNC(0x55) must be written into UCAxTXBUF to
//! generate the required break/sync fields. Otherwise, DEFAULT_SYNC(0x00) must
//! be written into the transmit buffer. Also ensures module is ready for
//! transmitting the next data.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! Modified bits of \b UCAxTXBUF register and bits of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_transmitBreak(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the RX Buffer of the UART for the DMA module.
//!
//! Returns the address of the UART RX Buffer. This can be used in conjunction
//! with the DMA to store the received data directly to memory.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! \return Address of RX Buffer
//
//*****************************************************************************
extern uint32_t EUSCI_A_UART_getReceiveBufferAddress(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the TX Buffer of the UART for the DMA module.
//!
//! Returns the address of the UART TX Buffer. This can be used in conjunction
//! with the DMA to obtain transmitted data directly from memory.
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//!
//! \return Address of TX Buffer
//
//*****************************************************************************
extern uint32_t EUSCI_A_UART_getTransmitBufferAddress(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets the deglitch time
//!
//! \param baseAddress is the base address of the EUSCI_A_UART module.
//! \param deglitchTime is the selected deglitch time
//! Valid values are:
//! - \b EUSCI_A_UART_DEGLITCH_TIME_2ns
//! - \b EUSCI_A_UART_DEGLITCH_TIME_50ns
//! - \b EUSCI_A_UART_DEGLITCH_TIME_100ns
//! - \b EUSCI_A_UART_DEGLITCH_TIME_200ns
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_A_UART_selectDeglitchTime(uint16_t baseAddress,
uint16_t deglitchTime);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_EUSCI_A_UART_H__

View File

@@ -0,0 +1,578 @@
//*****************************************************************************
//
// eusci_b_i2c.c - Driver for the eusci_b_i2c Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup eusci_b_i2c_api eusci_b_i2c
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_EUSCI_Bx__
#include "eusci_b_i2c.h"
#include <assert.h>
void EUSCI_B_I2C_initMaster (uint16_t baseAddress,
EUSCI_B_I2C_initMasterParam *param
)
{
uint16_t preScalarValue;
//Disable the USCI module and clears the other bits of control register
HWREG16(baseAddress + OFS_UCBxCTLW0) = UCSWRST;
//Configure Automatic STOP condition generation
HWREG16(baseAddress + OFS_UCBxCTLW1) &= ~UCASTP_3;
HWREG16(baseAddress + OFS_UCBxCTLW1) |= (uint16_t)param->autoSTOPGeneration;
//Byte Count Threshold
HWREG16(baseAddress + OFS_UCBxTBCNT) = param->byteCounterThreshold;
/*
* Configure as I2C master mode.
* UCMST = Master mode
* UCMODE_3 = I2C mode
* UCSYNC = Synchronous mode
*/
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCMST + UCMODE_3 + UCSYNC;
//Configure I2C clock source
HWREG16(baseAddress + OFS_UCBxCTLW0) |= (param->selectClockSource + UCSWRST);
/*
* Compute the clock divider that achieves the fastest speed less than or
* equal to the desired speed. The numerator is biased to favor a larger
* clock divider so that the resulting clock is always less than or equal
* to the desired clock, never greater.
*/
preScalarValue = (uint16_t)(param->i2cClk / param->dataRate);
HWREG16(baseAddress + OFS_UCBxBRW) = preScalarValue;
}
void EUSCI_B_I2C_initSlave (uint16_t baseAddress,
EUSCI_B_I2C_initSlaveParam *param
)
{
//Disable the USCI module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
//Clear USCI master mode
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCMST;
//Configure I2C as Slave and Synchronous mode
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCMODE_3 + UCSYNC;
//Set up the slave address.
HWREG16(baseAddress + OFS_UCBxI2COA0 + param->slaveAddressOffset)
= param->slaveAddress + param->slaveOwnAddressEnable;
}
void EUSCI_B_I2C_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSWRST);
}
void EUSCI_B_I2C_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
}
void EUSCI_B_I2C_setSlaveAddress (uint16_t baseAddress,
uint8_t slaveAddress
)
{
//Set the address of the slave with which the master will communicate.
HWREG16(baseAddress + OFS_UCBxI2CSA) = (slaveAddress);
}
void EUSCI_B_I2C_setMode (uint16_t baseAddress,
uint16_t mode
)
{
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~EUSCI_B_I2C_TRANSMIT_MODE;
HWREG16(baseAddress + OFS_UCBxCTLW0) |= mode;
}
uint8_t EUSCI_B_I2C_getMode (uint16_t baseAddress)
{
//Read the I2C mode.
return ((HWREG16(baseAddress + OFS_UCBxCTLW0) & UCTR));
}
void EUSCI_B_I2C_slavePutData (uint16_t baseAddress,
uint8_t transmitData
)
{
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = transmitData;
}
uint8_t EUSCI_B_I2C_slaveGetData (uint16_t baseAddress)
{
//Read a byte.
return (HWREG16(baseAddress + OFS_UCBxRXBUF));
}
uint16_t EUSCI_B_I2C_isBusBusy (uint16_t baseAddress)
{
//Return the bus busy status.
return (HWREG16(baseAddress + OFS_UCBxSTATW) & UCBBUSY);
}
uint16_t EUSCI_B_I2C_masterIsStopSent (uint16_t baseAddress)
{
return (HWREG16(baseAddress + OFS_UCBxCTLW0) & UCTXSTP);
}
uint16_t EUSCI_B_I2C_masterIsStartSent (uint16_t baseAddress)
{
return (HWREG16(baseAddress + OFS_UCBxCTLW0) & UCTXSTT);
}
void EUSCI_B_I2C_enableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
//Enable the interrupt masked bit
HWREG16(baseAddress + OFS_UCBxIE) |= mask;
}
void EUSCI_B_I2C_disableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
//Disable the interrupt masked bit
HWREG16(baseAddress + OFS_UCBxIE) &= ~(mask);
}
void EUSCI_B_I2C_clearInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
//Clear the I2C interrupt source.
HWREG16(baseAddress + OFS_UCBxIFG) &= ~(mask);
}
uint16_t EUSCI_B_I2C_getInterruptStatus (uint16_t baseAddress,
uint16_t mask
)
{
//Return the interrupt status of the request masked bit.
return (HWREG16(baseAddress + OFS_UCBxIFG) & mask);
}
void EUSCI_B_I2C_masterSendSingleByte (uint16_t baseAddress,
uint8_t txData
)
{
//Store current TXIE status
uint16_t txieStatus = HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
//Clear transmit interrupt flag before enabling interrupt again
HWREG16(baseAddress + OFS_UCBxIFG) &= ~(UCTXIFG);
//Reinstate transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) |= txieStatus;
}
uint8_t EUSCI_B_I2C_masterReceiveSingleByte (uint16_t baseAddress)
{
//Set USCI in Receive mode
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCTR;
//Send start condition
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTT;
//Poll for start condition transmission
while(HWREG16(baseAddress + OFS_UCBxCTLW0) & UCTXSTT);
//Send stop condition
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
//Poll for receive interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCRXIFG));
//Send single byte data.
return (HWREG16(baseAddress + OFS_UCBxRXBUF));
}
bool EUSCI_B_I2C_masterSendSingleByteWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
// Creating variable for second timeout scenario
uint32_t timeout2 = timeout;
//Store current TXIE status
uint16_t txieStatus = HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout);
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout2);
//Check if transfer timed out
if (timeout2 == 0){
return (STATUS_FAIL);
}
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
//Clear transmit interrupt flag before enabling interrupt again
HWREG16(baseAddress + OFS_UCBxIFG) &= ~(UCTXIFG);
//Reinstate transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) |= txieStatus;
return (STATUS_SUCCESS);
}
void EUSCI_B_I2C_masterSendMultiByteStart (uint16_t baseAddress,
uint8_t txData
)
{
//Store current transmit interrupt enable
uint16_t txieStatus = HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
//Reinstate transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) |= txieStatus;
}
bool EUSCI_B_I2C_masterSendMultiByteStartWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
//Store current transmit interrupt enable
uint16_t txieStatus = HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout);
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
//Reinstate transmit interrupt enable
HWREG16(baseAddress + OFS_UCBxIE) |= txieStatus;
return(STATUS_SUCCESS);
}
void EUSCI_B_I2C_masterSendMultiByteNext (uint16_t baseAddress,
uint8_t txData
)
{
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
}
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
}
bool EUSCI_B_I2C_masterSendMultiByteNextWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout);
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
}
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
return(STATUS_SUCCESS);
}
void EUSCI_B_I2C_masterSendMultiByteFinish (uint16_t baseAddress,
uint8_t txData
)
{
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
}
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
}
bool EUSCI_B_I2C_masterSendMultiByteFinishWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
uint32_t timeout2 = timeout;
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout) ;
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
}
//Send single byte data.
HWREG16(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout2) ;
//Check if transfer timed out
if (timeout2 == 0){
return (STATUS_FAIL);
}
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
return(STATUS_SUCCESS);
}
void EUSCI_B_I2C_masterSendStart (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTT;
}
void EUSCI_B_I2C_masterSendMultiByteStop (uint16_t baseAddress)
{
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
}
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
}
bool EUSCI_B_I2C_masterSendMultiByteStopWithTimeout (uint16_t baseAddress,
uint32_t timeout)
{
//If interrupts are not used, poll for flags
if (!(HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout) ;
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
}
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
return (STATUS_SUCCESS);
}
void EUSCI_B_I2C_masterReceiveStart (uint16_t baseAddress)
{
//Set USCI in Receive mode
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCTR;
//Send start
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTT;
}
uint8_t EUSCI_B_I2C_masterReceiveMultiByteNext (uint16_t baseAddress)
{
return (HWREG16(baseAddress + OFS_UCBxRXBUF));
}
uint8_t EUSCI_B_I2C_masterReceiveMultiByteFinish (uint16_t baseAddress)
{
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
//Wait for Stop to finish
while (HWREG16(baseAddress + OFS_UCBxCTLW0) & UCTXSTP)
// Wait for RX buffer
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCRXIFG)) ;
//Capture data from receive buffer after setting stop bit due to
//MSP430 I2C critical timing.
return (HWREG16(baseAddress + OFS_UCBxRXBUF));
}
bool EUSCI_B_I2C_masterReceiveMultiByteFinishWithTimeout (uint16_t baseAddress,
uint8_t *txData,
uint32_t timeout
)
{
uint32_t timeout2 = timeout;
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
//Wait for Stop to finish
while ((HWREG16(baseAddress + OFS_UCBxCTLW0) & UCTXSTP) && --timeout);
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
// Wait for RX buffer
while ((!(HWREG16(baseAddress + OFS_UCBxIFG) & UCRXIFG)) && --timeout2);
//Check if transfer timed out
if (timeout2 == 0){
return (STATUS_FAIL);
}
//Capture data from receive buffer after setting stop bit due to
//MSP430 I2C critical timing.
*txData = (HWREG8(baseAddress + OFS_UCBxRXBUF));
return (STATUS_SUCCESS);
}
void EUSCI_B_I2C_masterReceiveMultiByteStop (uint16_t baseAddress)
{
//Send stop condition.
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTXSTP;
}
void EUSCI_B_I2C_enableMultiMasterMode(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCMM;
}
void EUSCI_B_I2C_disableMultiMasterMode(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCMM;
}
uint8_t EUSCI_B_I2C_masterReceiveSingle (uint16_t baseAddress)
{
//Polling RXIFG0 if RXIE is not enabled
if(!(HWREG16(baseAddress + OFS_UCBxIE) & UCRXIE0)) {
while(!(HWREG16(baseAddress + OFS_UCBxIFG) & UCRXIFG0));
}
//Read a byte.
return (HWREG16(baseAddress + OFS_UCBxRXBUF));
}
uint32_t EUSCI_B_I2C_getReceiveBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxRXBUF );
}
uint32_t EUSCI_B_I2C_getTransmitBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxTXBUF );
}
void EUSCI_B_I2C_setTimeout(uint16_t baseAddress, uint16_t timeout)
{
uint16_t tempUCBxCTLW0;
//Save value of UCSWRST bit before we disable eUSCI module
tempUCBxCTLW0 = HWREG16(baseAddress + OFS_UCBxCTLW0);
//Disable the USCI module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
//Set timeout
HWREG16(baseAddress + OFS_UCBxCTLW1) = (HWREG16(baseAddress + OFS_UCBxCTLW1) & (~UCCLTO_3)) | timeout;
//Restore value of UCSWRST bit
HWREG16(baseAddress + OFS_UCBxCTLW0) = tempUCBxCTLW0;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for eusci_b_i2c_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,195 @@
//*****************************************************************************
//
// eusci_b_spi.c - Driver for the eusci_b_spi Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup eusci_b_spi_api eusci_b_spi
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_EUSCI_Bx__
#include "eusci_b_spi.h"
#include <assert.h>
void EUSCI_B_SPI_initMaster (uint16_t baseAddress,
EUSCI_B_SPI_initMasterParam *param)
{
//Disable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
//Reset OFS_UCBxCTLW0 values
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCCKPH + UCCKPL + UC7BIT + UCMSB +
UCMST + UCMODE_3 + UCSYNC);
//Reset OFS_UCBxCTLW0 values
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSSEL_3);
//Select Clock
HWREG16(baseAddress + OFS_UCBxCTLW0) |= (uint16_t)param->selectClockSource;
HWREG16(baseAddress + OFS_UCBxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
/*
* Configure as SPI master mode.
* Clock phase select, polarity, msb
* UCMST = Master mode
* UCSYNC = Synchronous mode
* UCMODE_0 = 3-pin SPI
*/
HWREG16(baseAddress + OFS_UCBxCTLW0) |= (
param->msbFirst +
param->clockPhase +
param->clockPolarity +
UCMST +
UCSYNC +
param->spiMode
);
}
void EUSCI_B_SPI_select4PinFunctionality (uint16_t baseAddress,
uint16_t select4PinFunctionality
)
{
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~UCSTEM;
HWREG16(baseAddress + OFS_UCBxCTLW0) |= select4PinFunctionality;
}
void EUSCI_B_SPI_changeMasterClock (uint16_t baseAddress,
EUSCI_B_SPI_changeMasterClockParam *param)
{
//Disable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
HWREG16(baseAddress + OFS_UCBxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSWRST);
}
void EUSCI_B_SPI_initSlave (uint16_t baseAddress, EUSCI_B_SPI_initSlaveParam *param)
{
//Disable USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
//Reset OFS_UCBxCTLW0 register
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCMSB +
UC7BIT +
UCMST +
UCCKPL +
UCCKPH +
UCMODE_3
);
//Clock polarity, phase select, msbFirst, SYNC, Mode0
HWREG16(baseAddress + OFS_UCBxCTLW0) |= (param->clockPhase +
param->clockPolarity +
param->msbFirst +
UCSYNC +
param->spiMode
);
}
void EUSCI_B_SPI_changeClockPhasePolarity (uint16_t baseAddress,
uint16_t clockPhase,
uint16_t clockPolarity
)
{
//Disable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCCKPH + UCCKPL);
HWREG16(baseAddress + OFS_UCBxCTLW0) |= (
clockPhase +
clockPolarity
);
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSWRST);
}
void EUSCI_B_SPI_transmitData ( uint16_t baseAddress,
uint8_t transmitData
)
{
HWREG16(baseAddress + OFS_UCBxTXBUF) = transmitData;
}
uint8_t EUSCI_B_SPI_receiveData (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_UCBxRXBUF)) ;
}
void EUSCI_B_SPI_enableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG16(baseAddress + OFS_UCBxIE) |= mask;
}
void EUSCI_B_SPI_disableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG16(baseAddress + OFS_UCBxIE) &= ~mask;
}
uint8_t EUSCI_B_SPI_getInterruptStatus (uint16_t baseAddress,
uint8_t mask
)
{
return ( HWREG16(baseAddress + OFS_UCBxIFG) & mask );
}
void EUSCI_B_SPI_clearInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG16(baseAddress + OFS_UCBxIFG) &= ~mask;
}
void EUSCI_B_SPI_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) &= ~(UCSWRST);
}
void EUSCI_B_SPI_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCSWRST;
}
uint32_t EUSCI_B_SPI_getReceiveBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxRXBUF );
}
uint32_t EUSCI_B_SPI_getTransmitBufferAddress (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxTXBUF );
}
uint16_t EUSCI_B_SPI_isBusy (uint16_t baseAddress)
{
//Return the bus busy status.
return (HWREG16(baseAddress + OFS_UCBxSTATW) & UCBUSY);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for eusci_b_spi_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,495 @@
//*****************************************************************************
//
// eusci_b_spi.h - Driver for the EUSCI_B_SPI Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_EUSCI_B_SPI_H__
#define __MSP430WARE_EUSCI_B_SPI_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_EUSCI_Bx__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the EUSCI_B_SPI_initMaster() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct EUSCI_B_SPI_initMasterParam {
//! Selects Clock source. Refer to device specific datasheet for available
//! options.
//! \n Valid values are:
//! - \b EUSCI_B_SPI_CLOCKSOURCE_ACLK
//! - \b EUSCI_B_SPI_CLOCKSOURCE_SMCLK
uint8_t selectClockSource;
//! Is the frequency of the selected clock source in Hz
uint32_t clockSourceFrequency;
//! Is the desired clock rate in Hz for SPI communication
uint32_t desiredSpiClock;
//! Controls the direction of the receive and transmit shift register.
//! \n Valid values are:
//! - \b EUSCI_B_SPI_MSB_FIRST
//! - \b EUSCI_B_SPI_LSB_FIRST [Default]
uint16_t msbFirst;
//! Is clock phase select.
//! \n Valid values are:
//! - \b EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
//! - \b EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
uint16_t clockPhase;
//! Is clock polarity select
//! \n Valid values are:
//! - \b EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
uint16_t clockPolarity;
//! Is SPI mode select
//! \n Valid values are:
//! - \b EUSCI_B_SPI_3PIN
//! - \b EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH
//! - \b EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_LOW
uint16_t spiMode;
} EUSCI_B_SPI_initMasterParam;
//*****************************************************************************
//
//! \brief Used in the EUSCI_B_SPI_initSlave() function as the param parameter.
//
//*****************************************************************************
typedef struct EUSCI_B_SPI_initSlaveParam {
//! Controls the direction of the receive and transmit shift register.
//! \n Valid values are:
//! - \b EUSCI_B_SPI_MSB_FIRST
//! - \b EUSCI_B_SPI_LSB_FIRST [Default]
uint16_t msbFirst;
//! Is clock phase select.
//! \n Valid values are:
//! - \b EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
//! - \b EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
uint16_t clockPhase;
//! Is clock polarity select
//! \n Valid values are:
//! - \b EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
uint16_t clockPolarity;
//! Is SPI mode select
//! \n Valid values are:
//! - \b EUSCI_B_SPI_3PIN
//! - \b EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH
//! - \b EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_LOW
uint16_t spiMode;
} EUSCI_B_SPI_initSlaveParam;
//*****************************************************************************
//
//! \brief Used in the EUSCI_B_SPI_changeMasterClock() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct EUSCI_B_SPI_changeMasterClockParam {
//! Is the frequency of the selected clock source in Hz
uint32_t clockSourceFrequency;
//! Is the desired clock rate in Hz for SPI communication
uint32_t desiredSpiClock;
} EUSCI_B_SPI_changeMasterClockParam;
//*****************************************************************************
//
// The following are values that can be passed to the clockPhase parameter for
// functions: EUSCI_B_SPI_changeClockPhasePolarity(); the param parameter for
// functions: EUSCI_B_SPI_initMaster(), and EUSCI_B_SPI_initSlave().
//
//*****************************************************************************
#define EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT 0x00
#define EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT UCCKPH
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_B_SPI_initMaster(), and EUSCI_B_SPI_initSlave().
//
//*****************************************************************************
#define EUSCI_B_SPI_MSB_FIRST UCMSB
#define EUSCI_B_SPI_LSB_FIRST 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_B_SPI_initMaster(), and EUSCI_B_SPI_initSlave(); the
// clockPolarity parameter for functions:
// EUSCI_B_SPI_changeClockPhasePolarity().
//
//*****************************************************************************
#define EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH UCCKPL
#define EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_B_SPI_initMaster().
//
//*****************************************************************************
#define EUSCI_B_SPI_CLOCKSOURCE_ACLK UCSSEL__ACLK
#define EUSCI_B_SPI_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: EUSCI_B_SPI_initMaster(), and EUSCI_B_SPI_initSlave().
//
//*****************************************************************************
#define EUSCI_B_SPI_3PIN UCMODE_0
#define EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH UCMODE_1
#define EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_LOW UCMODE_2
//*****************************************************************************
//
// The following are values that can be passed to the select4PinFunctionality
// parameter for functions: EUSCI_B_SPI_select4PinFunctionality().
//
//*****************************************************************************
#define EUSCI_B_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS 0x0000
#define EUSCI_B_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE UCSTEM
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: EUSCI_B_SPI_enableInterrupt(), EUSCI_B_SPI_disableInterrupt(),
// EUSCI_B_SPI_getInterruptStatus(), and EUSCI_B_SPI_clearInterrupt() as well
// as returned by the EUSCI_B_SPI_getInterruptStatus() function.
//
//*****************************************************************************
#define EUSCI_B_SPI_TRANSMIT_INTERRUPT UCTXIE
#define EUSCI_B_SPI_RECEIVE_INTERRUPT UCRXIE
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the EUSCI_B_SPI_isBusy() function.
//
//*****************************************************************************
#define EUSCI_B_SPI_BUSY UCBUSY
#define EUSCI_B_SPI_NOT_BUSY 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the SPI Master block.
//!
//! Upon successful initialization of the SPI master block, this function will
//! have set the bus speed for the master, but the SPI Master block still
//! remains disabled and must be enabled with EUSCI_B_SPI_enable()
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI Master module.
//! \param param is the pointer to struct for master initialization.
//!
//! Modified bits are \b UCCKPH, \b UCCKPL, \b UC7BIT, \b UCMSB, \b UCSSELx and
//! \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern void EUSCI_B_SPI_initMaster(uint16_t baseAddress,
EUSCI_B_SPI_initMasterParam *param);
//*****************************************************************************
//
//! \brief Selects 4Pin Functionality
//!
//! This function should be invoked only in 4-wire mode. Invoking this function
//! has no effect in 3-wire mode.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param select4PinFunctionality selects 4 pin functionality
//! Valid values are:
//! - \b EUSCI_B_SPI_PREVENT_CONFLICTS_WITH_OTHER_MASTERS
//! - \b EUSCI_B_SPI_ENABLE_SIGNAL_FOR_4WIRE_SLAVE
//!
//! Modified bits are \b UCSTEM of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_select4PinFunctionality(uint16_t baseAddress,
uint16_t select4PinFunctionality);
//*****************************************************************************
//
//! \brief Initializes the SPI Master clock. At the end of this function call,
//! SPI module is left enabled.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param param is the pointer to struct for master clock setting.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_changeMasterClock(uint16_t baseAddress,
EUSCI_B_SPI_changeMasterClockParam *param);
//*****************************************************************************
//
//! \brief Initializes the SPI Slave block.
//!
//! Upon successful initialization of the SPI slave block, this function will
//! have initialized the slave block, but the SPI Slave block still remains
//! disabled and must be enabled with EUSCI_B_SPI_enable()
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI Slave module.
//! \param param is the pointer to struct for slave initialization.
//!
//! Modified bits are \b UCMSB, \b UCMST, \b UC7BIT, \b UCCKPL, \b UCCKPH, \b
//! UCMODE and \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern void EUSCI_B_SPI_initSlave(uint16_t baseAddress,
EUSCI_B_SPI_initSlaveParam *param);
//*****************************************************************************
//
//! \brief Changes the SPI clock phase and polarity. At the end of this
//! function call, SPI module is left enabled.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param clockPhase is clock phase select.
//! Valid values are:
//! - \b EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
//! [Default]
//! - \b EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
//! \param clockPolarity is clock polarity select
//! Valid values are:
//! - \b EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
//!
//! Modified bits are \b UCCKPL, \b UCCKPH and \b UCSWRST of \b UCAxCTLW0
//! register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_changeClockPhasePolarity(uint16_t baseAddress,
uint16_t clockPhase,
uint16_t clockPolarity);
//*****************************************************************************
//
//! \brief Transmits a byte from the SPI Module.
//!
//! This function will place the supplied data into SPI transmit data register
//! to start transmission.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param transmitData data to be transmitted from the SPI module
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_transmitData(uint16_t baseAddress,
uint8_t transmitData);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the SPI Module.
//!
//! This function reads a byte of data from the SPI receive data Register.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//!
//! \return Returns the byte received from by the SPI module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t EUSCI_B_SPI_receiveData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables individual SPI interrupt sources.
//!
//! Enables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_B_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIFG register and bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_enableInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Disables individual SPI interrupt sources.
//!
//! Disables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_B_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_disableInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Gets the current SPI interrupt status.
//!
//! This returns the interrupt status for the SPI module based on which flag is
//! passed.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_B_SPI_RECEIVE_INTERRUPT
//!
//! \return Logical OR of any of the following:
//! - \b EUSCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_B_SPI_RECEIVE_INTERRUPT
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t EUSCI_B_SPI_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears the selected SPI interrupt status flag.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//! \param mask is the masked interrupt flag to be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b EUSCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b EUSCI_B_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_clearInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Enables the SPI block.
//!
//! This will enable operation of the SPI block.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the SPI block.
//!
//! This will disable operation of the SPI block.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTLW0 register.
//!
//! \return None
//
//*****************************************************************************
extern void EUSCI_B_SPI_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the RX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI RX Buffer. This can be used in conjunction
//! with the DMA to store the received data directly to memory.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//!
//! \return the address of the RX Buffer
//
//*****************************************************************************
extern uint32_t EUSCI_B_SPI_getReceiveBufferAddress(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the TX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI TX Buffer. This can be used in conjunction
//! with the DMA to obtain transmitted data directly from memory.
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//!
//! \return the address of the TX Buffer
//
//*****************************************************************************
extern uint32_t EUSCI_B_SPI_getTransmitBufferAddress(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Indicates whether or not the SPI bus is busy.
//!
//! This function returns an indication of whether or not the SPI bus is
//! busy.This function checks the status of the bus via UCBBUSY bit
//!
//! \param baseAddress is the base address of the EUSCI_B_SPI module.
//!
//! \return One of the following:
//! - \b EUSCI_B_SPI_BUSY
//! - \b EUSCI_B_SPI_NOT_BUSY
//! \n indicating if the EUSCI_B_SPI is busy
//
//*****************************************************************************
extern uint16_t EUSCI_B_SPI_isBusy(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_EUSCI_B_SPI_H__

View File

@@ -0,0 +1,277 @@
//*****************************************************************************
//
// flashctl.c - Driver for the flashctl Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup flashctl_api flashctl
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_FLASH__
#include "flashctl.h"
#include <assert.h>
void FlashCtl_eraseSegment ( uint8_t *flash_ptr){
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
//Set Erase bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + ERASE;
//Dummy write to erase Flash seg
*flash_ptr = 0;
//test busy
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY) ;
//Clear ERASE bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
void FlashCtl_eraseBank ( uint8_t *flash_ptr){
uint16_t interruptState;
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY);
//FLASH34 errata: no concurrent access to flash bank while erasing
interruptState = __get_interrupt_state();
__disable_interrupt();
__no_operation();
//Set MERAS bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + MERAS;
//Dummy write to erase Flash seg
*flash_ptr = 0;
//test busy
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY);
//FLASH34 errata
//Re-enable interrupt state to whatever it was before
if (interruptState & GIE)
{
__enable_interrupt();
}
//Clear MERAS bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
void FlashCtl_performMassErase ( uint8_t *flash_ptr){
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY) ;
//Set MERAS bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + MERAS + ERASE;
//Dummy write to erase Flash seg
*flash_ptr = 0;
//test busy
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY) ;
//Clear MERAS bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
bool FlashCtl_performEraseCheck (uint8_t *flash_ptr,
uint16_t numberOfBytes
)
{
uint16_t i;
for (i = 0; i < numberOfBytes; i++)
{
//was erasing successfull?
if ((*(flash_ptr + i)) != 0xFF){
return ( STATUS_FAIL) ;
}
}
return ( STATUS_SUCCESS) ;
}
void FlashCtl_write8 (uint8_t *data_ptr,
uint8_t *flash_ptr,
uint16_t count
)
{
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
//Enable byte/word write mode
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + WRT;
while (count > 0)
{
//test busy
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY) ;
//Write to Flash
*flash_ptr++ = *data_ptr++;
count--;
}
//Clear WRT bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
void FlashCtl_write16 (uint16_t *data_ptr,
uint16_t *flash_ptr,
uint16_t count
)
{
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
//Enable byte/word write mode
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + WRT;
while (count > 0)
{
//test busy
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY) ;
//Write to Flash
*flash_ptr++ = *data_ptr++;
count--;
}
//Clear WRT bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
void FlashCtl_write32 (uint32_t *data_ptr,
uint32_t *flash_ptr,
uint16_t count
)
{
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
//Enable long-word write
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + BLKWRT;
while (count > 0)
{
//test busy
while (HWREG8(FLASH_BASE + OFS_FCTL3) & BUSY) ;
//Write to Flash
*flash_ptr++ = *data_ptr++;
count--;
}
//Clear BLKWRT bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
void FlashCtl_fillMemory32 (uint32_t value,
uint32_t *flash_ptr,
uint16_t count
)
{
//Clear Lock bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY;
//Enable long-word write
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY + BLKWRT;
//test busy
while (count > 0)
{
while ((HWREG8(FLASH_BASE + OFS_FCTL3)) & BUSY) ;
//Write to Flash
*flash_ptr++ = value;
count--;
}
//Clear BLKWRT bit
HWREG16(FLASH_BASE + OFS_FCTL1) = FWKEY;
//Set LOCK bit
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY + LOCK;
}
uint8_t FlashCtl_getStatus (uint8_t mask
)
{
return ((HWREG8(FLASH_BASE + OFS_FCTL3) & mask ));
}
void FlashCtl_lockInfoA (void)
{
//Disable global interrupts while doing RMW operation on LOCKA bit
uint16_t gieStatus;
gieStatus = __get_SR_register() & GIE; //Store current SR register
__disable_interrupt(); //Disable global interrupt
//Set the LOCKA bit in FCTL3.
//Since LOCKA toggles when you write a 1 (and writing 0 has no effect),
//read the register, XOR with LOCKA mask, mask the lower byte
//and write it back.
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY
+ ((HWREG16(FLASH_BASE + OFS_FCTL3) ^ LOCKA) & 0xFF);
//Reinstate SR register to restore global interrupt enable status
__bis_SR_register(gieStatus);
}
void FlashCtl_unlockInfoA (void)
{
//Disable global interrupts while doing RMW operation on LOCKA bit
uint16_t gieStatus;
gieStatus = __get_SR_register() & GIE; //Store current SR register
__disable_interrupt(); //Disable global interrupt
//Clear the LOCKA bit in FCTL3.
//Since LOCKA toggles when you write a 1 (and writing 0 has no effect),
//read the register, mask the lower byte, and write it back.
HWREG16(FLASH_BASE + OFS_FCTL3) = FWKEY
+ (HWREG16(FLASH_BASE + OFS_FCTL3) & 0xFF);
//Reinstate SR register to restore global interrupt enable status
__bis_SR_register(gieStatus);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for flashctl_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,247 @@
//*****************************************************************************
//
// flashctl.h - Driver for the FLASHCTL Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_FLASHCTL_H__
#define __MSP430WARE_FLASHCTL_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_FLASH__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: FlashCtl_getStatus() as well as returned by the
// FlashCtl_getStatus() function.
//
//*****************************************************************************
#define FLASHCTL_READY_FOR_NEXT_WRITE WAIT
#define FLASHCTL_ACCESS_VIOLATION_INTERRUPT_FLAG ACCVIFG
#define FLASHCTL_PASSWORD_WRITTEN_INCORRECTLY KEYV
#define FLASHCTL_BUSY BUSY
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Erase a single segment of the flash memory.
//!
//! For devices like MSP430i204x, if the specified segment is the information
//! flash segment, the FLASH_unlockInfo API must be called prior to calling
//! this API.
//!
//! \param flash_ptr is the pointer into the flash segment to be erased
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_eraseSegment(uint8_t *flash_ptr);
//*****************************************************************************
//
//! \brief Erase a single bank of the flash memory.
//!
//! This function erases a single bank of the flash memory. This API will
//! erase the entire flash if device contains only one flash bank.
//!
//! \param flash_ptr is a pointer into the bank to be erased
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_eraseBank(uint8_t *flash_ptr);
//*****************************************************************************
//
//! \brief Erase all flash memory.
//!
//! This function erases all the flash memory banks. For devices like
//! MSP430i204x, this API erases main memory and information flash memory if
//! the FLASH_unlockInfo API was previously executed (otherwise the information
//! flash is not erased). Also note that erasing information flash memory in
//! the MSP430i204x impacts the TLV calibration constants located at the
//! information memory.
//!
//! \param flash_ptr is a pointer into the bank to be erased
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_performMassErase(uint8_t *flash_ptr);
//*****************************************************************************
//
//! \brief Erase check of the flash memory
//!
//! This function checks bytes in flash memory to make sure that they are in an
//! erased state (are set to 0xFF).
//!
//! \param flash_ptr is the pointer to the starting location of the erase check
//! \param numberOfBytes is the number of bytes to be checked
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern bool FlashCtl_performEraseCheck(uint8_t *flash_ptr,
uint16_t numberOfBytes);
//*****************************************************************************
//
//! \brief Write data into the flash memory in byte format, pass by reference
//!
//! This function writes a byte array of size count into flash memory. Assumes
//! the flash memory is already erased and unlocked. FlashCtl_eraseSegment can
//! be used to erase a segment.
//!
//! \param data_ptr is the pointer to the data to be written
//! \param flash_ptr is the pointer into which to write the data
//! \param count number of times to write the value
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_write8(uint8_t *data_ptr,
uint8_t *flash_ptr,
uint16_t count);
//*****************************************************************************
//
//! \brief Write data into the flash memory in 16-bit word format, pass by
//! reference
//!
//! This function writes a 16-bit word array of size count into flash memory.
//! Assumes the flash memory is already erased and unlocked.
//! FlashCtl_eraseSegment can be used to erase a segment.
//!
//! \param data_ptr is the pointer to the data to be written
//! \param flash_ptr is the pointer into which to write the data
//! \param count number of times to write the value
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_write16(uint16_t *data_ptr,
uint16_t *flash_ptr,
uint16_t count);
//*****************************************************************************
//
//! \brief Write data into the flash memory in 32-bit word format, pass by
//! reference
//!
//! This function writes a 32-bit array of size count into flash memory.
//! Assumes the flash memory is already erased and unlocked.
//! FlashCtl_eraseSegment can be used to erase a segment.
//!
//! \param data_ptr is the pointer to the data to be written
//! \param flash_ptr is the pointer into which to write the data
//! \param count number of times to write the value
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_write32(uint32_t *data_ptr,
uint32_t *flash_ptr,
uint16_t count);
//*****************************************************************************
//
//! \brief Write data into the flash memory in 32-bit word format, pass by
//! value
//!
//! This function writes a 32-bit data value into flash memory, count times.
//! Assumes the flash memory is already erased and unlocked.
//! FlashCtl_eraseSegment can be used to erase a segment.
//!
//! \param value value to fill memory with
//! \param flash_ptr is the pointer into which to write the data
//! \param count number of times to write the value
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_fillMemory32(uint32_t value,
uint32_t *flash_ptr,
uint16_t count);
//*****************************************************************************
//
//! \brief Check FlashCtl status to see if it is currently busy erasing or
//! programming
//!
//! This function checks the status register to determine if the flash memory
//! is ready for writing.
//!
//! \param mask FLASHCTL status to read
//! Mask value is the logical OR of any of the following:
//! - \b FLASHCTL_READY_FOR_NEXT_WRITE
//! - \b FLASHCTL_ACCESS_VIOLATION_INTERRUPT_FLAG
//! - \b FLASHCTL_PASSWORD_WRITTEN_INCORRECTLY
//! - \b FLASHCTL_BUSY
//!
//! \return Logical OR of any of the following:
//! - \b FLASHCTL_READY_FOR_NEXT_WRITE
//! - \b FLASHCTL_ACCESS_VIOLATION_INTERRUPT_FLAG
//! - \b FLASHCTL_PASSWORD_WRITTEN_INCORRECTLY
//! - \b FLASHCTL_BUSY
//! \n indicating the status of the FlashCtl
//
//*****************************************************************************
extern uint8_t FlashCtl_getStatus(uint8_t mask);
//*****************************************************************************
//
//! \brief Locks the information flash memory segment A
//!
//! This function is typically called after an erase or write operation on the
//! information flash segment is performed by any of the other API functions in
//! order to re-lock the information flash segment.
//!
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_lockInfoA(void);
//*****************************************************************************
//
//! \brief Unlocks the information flash memory segment A
//!
//! This function must be called before an erase or write operation on the
//! information flash segment is performed by any of the other API functions.
//!
//!
//! \return None
//
//*****************************************************************************
extern void FlashCtl_unlockInfoA(void);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_FLASHCTL_H__

View File

@@ -0,0 +1,449 @@
//*****************************************************************************
//
// gpio.c - Driver for the gpio Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup gpio_api gpio
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PORT1_R__
#include "gpio.h"
#include <assert.h>
static const uint16_t GPIO_PORT_TO_BASE[] = {
0x00,
#if defined(__MSP430_HAS_PORT1_R__)
__MSP430_BASEADDRESS_PORT1_R__,
#elif defined(__MSP430_HAS_PORT1__)
__MSP430_BASEADDRESS_PORT1__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT2_R__)
__MSP430_BASEADDRESS_PORT2_R__,
#elif defined(__MSP430_HAS_PORT2__)
__MSP430_BASEADDRESS_PORT2__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT3_R__)
__MSP430_BASEADDRESS_PORT3_R__,
#elif defined(__MSP430_HAS_PORT3__)
__MSP430_BASEADDRESS_PORT3__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT4_R__)
__MSP430_BASEADDRESS_PORT4_R__,
#elif defined(__MSP430_HAS_PORT4__)
__MSP430_BASEADDRESS_PORT4__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT5_R__)
__MSP430_BASEADDRESS_PORT5_R__,
#elif defined(__MSP430_HAS_PORT5__)
__MSP430_BASEADDRESS_PORT5__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT6_R__)
__MSP430_BASEADDRESS_PORT6_R__,
#elif defined(__MSP430_HAS_PORT6__)
__MSP430_BASEADDRESS_PORT6__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT7_R__)
__MSP430_BASEADDRESS_PORT7_R__,
#elif defined(__MSP430_HAS_PORT7__)
__MSP430_BASEADDRESS_PORT7__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT8_R__)
__MSP430_BASEADDRESS_PORT8_R__,
#elif defined(__MSP430_HAS_PORT8__)
__MSP430_BASEADDRESS_PORT8__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT9_R__)
__MSP430_BASEADDRESS_PORT9_R__,
#elif defined(__MSP430_HAS_PORT9__)
__MSP430_BASEADDRESS_PORT9__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT10_R__)
__MSP430_BASEADDRESS_PORT10_R__,
#elif defined(__MSP430_HAS_PORT10__)
__MSP430_BASEADDRESS_PORT10__,
#else
0xFFFF,
#endif
#if defined(__MSP430_HAS_PORT11_R__)
__MSP430_BASEADDRESS_PORT11_R__,
#elif defined(__MSP430_HAS_PORT11__)
__MSP430_BASEADDRESS_PORT11__,
#else
0xFFFF,
#endif
0xFFFF,
#if defined(__MSP430_HAS_PORTJ_R__)
__MSP430_BASEADDRESS_PORTJ_R__
#elif defined(__MSP430_HAS_PORTJ__)
__MSP430_BASEADDRESS_PORTJ__
#else
0xFFFF
#endif
};
void GPIO_setAsOutputPin(uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PASEL) &= ~selectedPins;
HWREG16(baseAddress + OFS_PADIR) |= selectedPins;
return;
}
void GPIO_setAsInputPin(uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PASEL) &= ~selectedPins;
HWREG16(baseAddress + OFS_PADIR) &= ~selectedPins;
HWREG16(baseAddress + OFS_PAREN) &= ~selectedPins;
}
void GPIO_setAsPeripheralModuleFunctionOutputPin(uint8_t selectedPort,
uint16_t selectedPins
) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PADIR) |= selectedPins;
HWREG16(baseAddress + OFS_PASEL) |= selectedPins;
}
void GPIO_setAsPeripheralModuleFunctionInputPin(uint8_t selectedPort,
uint16_t selectedPins
) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PADIR) &= ~selectedPins;
HWREG16(baseAddress + OFS_PASEL) |= selectedPins;
}
void GPIO_setOutputHighOnPin (uint8_t selectedPort,
uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PAOUT) |= selectedPins;
}
void GPIO_setOutputLowOnPin (uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PAOUT) &= ~selectedPins;
}
void GPIO_toggleOutputOnPin (uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PAOUT) ^= selectedPins;
}
void GPIO_setAsInputPinWithPullDownResistor(uint8_t selectedPort,
uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PASEL) &= ~selectedPins;
HWREG16(baseAddress + OFS_PADIR) &= ~selectedPins;
HWREG16(baseAddress + OFS_PAREN) |= selectedPins;
HWREG16(baseAddress + OFS_PAOUT) &= ~selectedPins;
}
void GPIO_setAsInputPinWithPullUpResistor(uint8_t selectedPort,
uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PASEL) &= ~selectedPins;
HWREG16(baseAddress + OFS_PADIR) &= ~selectedPins;
HWREG16(baseAddress + OFS_PAREN) |= selectedPins;
HWREG16(baseAddress + OFS_PAOUT) |= selectedPins;
}
uint8_t GPIO_getInputPinValue(uint8_t selectedPort,
uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
uint16_t inputPinValue = HWREG16(baseAddress + OFS_PAIN) & (selectedPins);
if(inputPinValue > 0){
return (GPIO_INPUT_PIN_HIGH);
}
return (GPIO_INPUT_PIN_LOW);
}
void GPIO_enableInterrupt(uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PAIE) |= selectedPins;
}
void GPIO_disableInterrupt(uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PAIE) &= ~selectedPins;
}
uint16_t GPIO_getInterruptStatus(uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
if((baseAddress & 0x1) ^ 0x1)
{
return (HWREG8(baseAddress + OFS_PAIFG_H) & selectedPins);
}
else
{
return (HWREG8(baseAddress + OFS_PAIFG) & selectedPins);
}
}
else {
return (HWREG16(baseAddress + OFS_PAIFG) & selectedPins);
}
}
void GPIO_clearInterrupt(uint8_t selectedPort, uint16_t selectedPins) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
HWREG16(baseAddress + OFS_PAIFG) &= ~selectedPins;
}
void GPIO_selectInterruptEdge(uint8_t selectedPort, uint16_t selectedPins,
uint8_t edgeSelect) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
if (GPIO_LOW_TO_HIGH_TRANSITION == edgeSelect){
HWREG16(baseAddress + OFS_PAIES) &= ~selectedPins;
}
else {
HWREG16(baseAddress + OFS_PAIES) |= selectedPins;
}
}
void GPIO_setDriveStrength(uint8_t selectedPort, uint16_t selectedPins,
uint8_t driveStrength) {
uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];
#ifndef NDEBUG
if(baseAddress == 0xFFFF) {
return;
}
#endif
// Shift by 8 if port is even (upper 8-bits)
if((selectedPort & 1) ^ 1) {
selectedPins <<= 8;
}
if(GPIO_REDUCED_OUTPUT_DRIVE_STRENGTH == driveStrength) {
HWREG16(baseAddress + OFS_PADS) &= ~selectedPins;
} else {
HWREG16(baseAddress + OFS_PADS) |= selectedPins;
}
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for gpio_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,45 @@
#ifndef __HW_MEMMAP__
#define __HW_MEMMAP__
#define __DRIVERLIB_MSP430F5XX_6XX_FAMILY__
//*****************************************************************************
//
// Include device specific header file
//
//*****************************************************************************
#include <msp430.h>
#include "msp430f5xx_6xxgeneric.h"
#include "stdint.h"
#include "stdbool.h"
//*****************************************************************************
//
// SUCCESS and FAILURE for API return value
//
//*****************************************************************************
#define STATUS_SUCCESS 0x01
#define STATUS_FAIL 0x00
//*****************************************************************************
//
// Macro for enabling assert statements for debugging
//
//*****************************************************************************
#define NDEBUG
//*****************************************************************************
//
// Macros for hardware access
//
//*****************************************************************************
#define HWREG32(x) \
(*((volatile uint32_t *)((uint16_t)x)))
#define HWREG16(x) \
(*((volatile uint16_t *)((uint16_t)x)))
#define HWREG8(x) \
(*((volatile uint8_t *)((uint16_t)x)))
#endif // #ifndef __HW_MEMMAP__

View File

@@ -0,0 +1,11 @@
#ifndef __DRIVERLIB_VERSION__
#define DRIVERLIB_VER_MAJOR 2
#define DRIVERLIB_VER_MINOR 91
#define DRIVERLIB_VER_PATCH 13
#define DRIVERLIB_VER_BUILD 01
#endif
#define getVersion() ((uint32_t)DRIVERLIB_VER_MAJOR<<24 | \
(uint32_t)DRIVERLIB_VER_MINOR<<16 | \
(uint32_t)DRIVERLIB_VER_PATCH<<8 | \
(uint32_t)DRIVERLIB_VER_BUILD)

View File

@@ -0,0 +1,298 @@
//*****************************************************************************
//
// lcd_b.c - Driver for the lcd_b Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup lcd_b_api lcd_b
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_LCD_B__
#include "lcd_b.h"
#include <assert.h>
//*****************************************************************************
//
// Initialization parameter instance
//
//*****************************************************************************
const LCD_B_initParam LCD_B_INIT_PARAM = {
LCD_B_CLOCKSOURCE_ACLK,
LCD_B_CLOCKDIVIDER_1,
LCD_B_CLOCKPRESCALAR_1,
LCD_B_STATIC,
LCD_B_SEGMENTS_DISABLED
};
static void setLCDFunction(uint16_t baseAddress, uint8_t index, uint16_t value)
{
switch (index){
case 0:
HWREG16(baseAddress + OFS_LCDBPCTL0) |= value;
break;
case 1:
HWREG16(baseAddress + OFS_LCDBPCTL1) |= value;
break;
case 2:
HWREG16(baseAddress + OFS_LCDBPCTL2) |= value;
break;
case 3:
HWREG16(baseAddress + OFS_LCDBPCTL3) |= value;
break;
default:break;
}
}
void LCD_B_init(uint16_t baseAddress, LCD_B_initParam *initParams)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~(LCDMX0 | LCDMX1 | LCDSSEL | LCDSON
| LCDDIV_31);
HWREG16(baseAddress + OFS_LCDBCTL0) |= initParams->muxRate;
HWREG16(baseAddress + OFS_LCDBCTL0) |= initParams->clockSource;
HWREG16(baseAddress + OFS_LCDBCTL0) |= initParams->segments;
HWREG16(baseAddress + OFS_LCDBCTL0) |= initParams->clockDivider;
HWREG16(baseAddress + OFS_LCDBCTL0) |= initParams->clockPrescalar;
}
void LCD_B_on(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDBCTL0) |= LCDON;
}
void LCD_B_off(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
}
void LCD_B_clearInterrupt(uint16_t baseAddress, uint16_t mask)
{
HWREG8(baseAddress + OFS_LCDBCTL1_L) &= ~(mask>>8);
}
uint16_t LCD_B_getInterruptStatus(uint16_t baseAddress, uint16_t mask)
{
return (HWREG8(baseAddress + OFS_LCDBCTL1_L) & (mask>>8));
}
void LCD_B_enableInterrupt (uint16_t baseAddress, uint16_t mask)
{
HWREG16(baseAddress + OFS_LCDBCTL1) |= mask;
}
void LCD_B_disableInterrupt (uint16_t baseAddress, uint16_t mask)
{
HWREG16(baseAddress + OFS_LCDBCTL1) &= ~mask;
}
void LCD_B_clearAllMemory(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDBMEMCTL) |= LCDCLRM;
}
void LCD_B_clearAllBlinkingMemory(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDBMEMCTL) |= LCDCLRBM;
}
void LCD_B_selectDisplayMemory(uint16_t baseAddress, uint16_t displayMemory)
{
HWREG16(baseAddress + OFS_LCDBMEMCTL) &= ~LCDDISP;
HWREG16(baseAddress + OFS_LCDBMEMCTL) |= displayMemory;
}
void LCD_B_setBlinkingControl (uint16_t baseAddress,
uint8_t clockDivider,
uint8_t clockPrescalar,
uint8_t mode)
{
HWREG16(baseAddress + OFS_LCDBBLKCTL) &= ~(LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2
| LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKPRE2 | LCDBLKMOD0 | LCDBLKMOD1);
HWREG16(baseAddress + OFS_LCDBBLKCTL) |= clockDivider | clockPrescalar | mode;
}
void LCD_B_enableChargePump(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDBVCTL) |= LCDCPEN;
}
void LCD_B_disableChargePump(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~LCDCPEN;
}
void LCD_B_selectBias(uint16_t baseAddress, uint16_t bias)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~LCD2B;
HWREG16(baseAddress + OFS_LCDBVCTL) |= bias;
}
void LCD_B_selectChargePumpReference(uint16_t baseAddress, uint16_t reference)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~VLCDREF_3;
HWREG16(baseAddress + OFS_LCDBVCTL) |= reference;
}
void LCD_B_setVLCDSource(uint16_t baseAddress,
uint16_t vlcdSource,
uint16_t v2v3v4Source,
uint16_t v5Source)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~VLCDEXT;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~LCDREXT;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~LCDEXTBIAS;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~R03EXT;
HWREG16(baseAddress + OFS_LCDBVCTL) |= vlcdSource;
HWREG16(baseAddress + OFS_LCDBVCTL) |= v2v3v4Source;
HWREG16(baseAddress + OFS_LCDBVCTL) |= v5Source;
}
void LCD_B_setVLCDVoltage(uint16_t baseAddress,
uint16_t voltage)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDBVCTL) &= ~VLCD_15;
HWREG16(baseAddress + OFS_LCDBVCTL) |= voltage;
}
void LCD_B_setPinAsLCDFunction (uint16_t baseAddress, uint8_t pin)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
uint8_t idx = pin>>4;
uint16_t val = 1<<(pin & 0xF);
setLCDFunction(baseAddress, idx, val);
}
void LCD_B_setPinAsPortFunction (uint16_t baseAddress, uint8_t pin)
{
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
uint8_t idx = pin>>4;
uint16_t val = 1<<(pin & 0xF);
switch (idx){
case 0:
HWREG16(baseAddress + OFS_LCDBPCTL0) &= ~val;
break;
case 1:
HWREG16(baseAddress + OFS_LCDBPCTL1) &= ~val;
break;
case 2:
HWREG16(baseAddress + OFS_LCDBPCTL2) &= ~val;
break;
case 3:
HWREG16(baseAddress + OFS_LCDBPCTL3) &= ~val;
break;
default:break;
}
}
void LCD_B_setPinAsLCDFunctionEx(uint16_t baseAddress,
uint8_t startPin,
uint8_t endPin)
{
uint8_t startIdx = startPin>>4;
uint8_t endIdx = endPin>>4;
uint8_t startPos = startPin & 0xF;
uint8_t endPos = endPin & 0xF;
uint16_t val = 0;
uint8_t i = 0;
HWREG16(baseAddress + OFS_LCDBCTL0) &= ~LCDON;
if (startIdx == endIdx) {
val = (0xFFFF>>(15-endPos)) & (0xFFFF<<startPos);
setLCDFunction(baseAddress, startIdx, val);
}
else {
val = 0xFFFF>>(15-endPos);
setLCDFunction(baseAddress, endIdx, val);
for (i=endIdx-1; i>startIdx; i--) {
setLCDFunction(baseAddress, i, 0xFFFF);
}
val = 0xFFFF<<startPos;
setLCDFunction(baseAddress, startIdx, val);
}
}
void LCD_B_setMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDM1 + memory) = mask;
}
void LCD_B_updateMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDM1 + memory) |= mask;
}
void LCD_B_toggleMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDM1 + memory) ^= mask;
}
void LCD_B_clearMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDM1 + memory) &= ~mask;
}
void LCD_B_setBlinkingMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDBM1 + memory) = mask;
}
void LCD_B_updateBlinkingMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDBM1 + memory) |= mask;
}
void LCD_B_toggleBlinkingMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDBM1 + memory) ^= mask;
}
void LCD_B_clearBlinkingMemory(uint16_t baseAddress, uint8_t memory, uint8_t mask)
{
HWREG8(baseAddress + OFS_LCDBM1 + memory) &= ~mask;
}
void LCD_B_configureChargePump(uint16_t baseAddress, uint16_t autoDisabled)
{
HWREG16(baseAddress + OFS_LCDBCPCTL) &= ~(LCDCPDIS7 | LCDCPDIS6 | LCDCPDIS5
| LCDCPDIS4 | LCDCPDIS3 | LCDCPDIS2 | LCDCPDIS1 | LCDCPDIS0);
HWREG16(baseAddress + OFS_LCDBCPCTL) |= autoDisabled;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for lcd_b_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,408 @@
//*****************************************************************************
//
// lcd_c.c - Driver for the lcd_c Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup lcd_c_api lcd_c
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_LCD_C__
#include "lcd_c.h"
#include <assert.h>
//*****************************************************************************
//
// Initialization parameter instance
//
//*****************************************************************************
const LCD_C_initParam LCD_C_INIT_PARAM = {
LCD_C_CLOCKSOURCE_ACLK,
LCD_C_CLOCKDIVIDER_1,
LCD_C_CLOCKPRESCALAR_1,
LCD_C_STATIC,
LCD_C_STANDARD_WAVEFORMS,
LCD_C_SEGMENTS_DISABLED
};
static void setLCDFunction(uint16_t baseAddress, uint8_t index, uint16_t value)
{
switch(index) {
case 0:
HWREG16(baseAddress + OFS_LCDCPCTL0) |= value;
break;
case 1:
HWREG16(baseAddress + OFS_LCDCPCTL1) |= value;
break;
case 2:
HWREG16(baseAddress + OFS_LCDCPCTL2) |= value;
break;
case 3:
#ifdef LCDS48
HWREG16(baseAddress + OFS_LCDCPCTL3) |= value;
#endif //LCDS48
break;
default: break;
}
}
void LCD_C_init(uint16_t baseAddress, LCD_C_initParam *initParams)
{
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~(LCDMX0 | LCDMX1 | LCDMX2 | LCDSSEL
| LCDLP | LCDSON | LCDDIV_31);
HWREG16(baseAddress + OFS_LCDCCTL0) |= initParams->muxRate;
HWREG16(baseAddress + OFS_LCDCCTL0) |= initParams->clockSource;
HWREG16(baseAddress + OFS_LCDCCTL0) |= initParams->waveforms;
HWREG16(baseAddress + OFS_LCDCCTL0) |= initParams->segments;
HWREG16(baseAddress + OFS_LCDCCTL0) |= initParams->clockDivider;
HWREG16(baseAddress + OFS_LCDCCTL0) |= initParams->clockPrescalar;
}
void LCD_C_on(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDCCTL0) |= LCDON;
}
void LCD_C_off(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
}
void LCD_C_clearInterrupt(uint16_t baseAddress, uint16_t mask)
{
HWREG8(baseAddress + OFS_LCDCCTL1_L) &= ~(mask>>8);
}
uint16_t LCD_C_getInterruptStatus(uint16_t baseAddress, uint16_t mask)
{
return (HWREG8(baseAddress + OFS_LCDCCTL1_L) & (mask>>8));
}
void LCD_C_enableInterrupt(uint16_t baseAddress, uint16_t mask)
{
HWREG16(baseAddress + OFS_LCDCCTL1) |= mask;
}
void LCD_C_disableInterrupt (uint16_t baseAddress, uint16_t mask)
{
HWREG16(baseAddress + OFS_LCDCCTL1) &= ~mask;
}
void LCD_C_clearMemory(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDCMEMCTL) |= LCDCLRM;
}
void LCD_C_clearBlinkingMemory(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDCMEMCTL) |= LCDCLRBM;
}
void LCD_C_selectDisplayMemory(uint16_t baseAddress, uint16_t displayMemory)
{
HWREG16(baseAddress + OFS_LCDCMEMCTL) &= ~LCDDISP;
HWREG16(baseAddress + OFS_LCDCMEMCTL) |= displayMemory;
}
void LCD_C_setBlinkingControl (uint16_t baseAddress,
uint8_t clockDivider,
uint8_t clockPrescalar,
uint8_t mode)
{
HWREG16(baseAddress + OFS_LCDCBLKCTL) &= ~(LCDBLKDIV0 | LCDBLKDIV1 | LCDBLKDIV2 |
LCDBLKPRE0 | LCDBLKPRE1 | LCDBLKPRE2 |
LCDBLKMOD0 | LCDBLKMOD1
);
HWREG16(baseAddress + OFS_LCDCBLKCTL) |= clockDivider | clockPrescalar | mode;
}
void LCD_C_enableChargePump(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDCVCTL) |= LCDCPEN;
}
void LCD_C_disableChargePump(uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~LCDCPEN;
}
void LCD_C_selectBias(uint16_t baseAddress, uint16_t bias)
{
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~LCD2B;
HWREG16(baseAddress + OFS_LCDCVCTL) |= bias;
}
void LCD_C_selectChargePumpReference(uint16_t baseAddress, uint16_t reference)
{
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~VLCDREF_3;
HWREG16(baseAddress + OFS_LCDCVCTL) |= reference;
}
void LCD_C_setVLCDSource(uint16_t baseAddress, uint16_t vlcdSource,
uint16_t v2v3v4Source,
uint16_t v5Source)
{
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~VLCDEXT;
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~LCDREXT;
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~LCDEXTBIAS;
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~R03EXT;
HWREG16(baseAddress + OFS_LCDCVCTL) |= vlcdSource;
HWREG16(baseAddress + OFS_LCDCVCTL) |= v2v3v4Source;
HWREG16(baseAddress + OFS_LCDCVCTL) |= v5Source;
}
void LCD_C_setVLCDVoltage(uint16_t baseAddress, uint16_t voltage)
{
HWREG16(baseAddress + OFS_LCDCVCTL) &= ~VLCD_15;
HWREG16(baseAddress + OFS_LCDCVCTL) |= voltage;
}
void LCD_C_setPinAsLCDFunction(uint16_t baseAddress, uint8_t pin)
{
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
uint8_t idx = pin>>4;
uint16_t val = 1<<(pin & 0xF);
setLCDFunction(baseAddress, idx, val);
}
void LCD_C_setPinAsPortFunction (uint16_t baseAddress, uint8_t pin)
{
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
uint8_t idx = pin >> 4;
uint16_t val = 1 << (pin & 0xF);
switch(idx) {
case 0:
HWREG16(baseAddress + OFS_LCDCPCTL0) &= ~val;
break;
case 1:
HWREG16(baseAddress + OFS_LCDCPCTL1) &= ~val;
break;
case 2:
HWREG16(baseAddress + OFS_LCDCPCTL2) &= ~val;
break;
case 3:
#ifdef LCDS48
HWREG16(baseAddress + OFS_LCDCPCTL3) &= ~val;
#endif //LCDS48
break;
default: break;
}
}
void LCD_C_setPinAsLCDFunctionEx(uint16_t baseAddress, uint8_t startPin,
uint8_t endPin)
{
uint8_t startIdx = startPin>>4;
uint8_t endIdx = endPin>>4;
uint8_t startPos = startPin & 0xF;
uint8_t endPos = endPin & 0xF;
uint16_t val = 0;
uint8_t i = 0;
HWREG16(baseAddress + OFS_LCDCCTL0) &= ~LCDON;
if (startIdx == endIdx) {
val = (0xFFFF>>(15-endPos)) & (0xFFFF<<startPos);
setLCDFunction(baseAddress, startIdx, val);
}
else {
val = 0xFFFF>>(15-endPos);
setLCDFunction(baseAddress, endIdx, val);
for (i=endIdx-1; i>startIdx; i--)
setLCDFunction(baseAddress, i, 0xFFFF);
val = 0xFFFF<<startPos;
setLCDFunction(baseAddress, startIdx, val);
}
}
void LCD_C_setMemory(uint16_t baseAddress, uint8_t pin, uint8_t value)
{
uint8_t muxRate = HWREG16(baseAddress + OFS_LCDCCTL0)
& (LCDMX2 | LCDMX1 | LCDMX0);
// static, 2-mux, 3-mux, 4-mux
if (muxRate <= (LCDMX1 | LCDMX0)) {
if (pin & 1) {
HWREG8(baseAddress + OFS_LCDM1 + pin/2) &= 0x0F;
HWREG8(baseAddress + OFS_LCDM1 + pin/2) |= (value & 0xF) << 4;
}
else {
HWREG8(baseAddress + OFS_LCDM1 + pin/2) &= 0xF0;
HWREG8(baseAddress + OFS_LCDM1 + pin/2) |= (value & 0xF);
}
}
else {
//5-mux, 6-mux, 7-mux, 8-mux
HWREG8(baseAddress + OFS_LCDM1 + pin) = value;
}
}
uint8_t LCD_C_getMemory(uint16_t baseAddress, uint8_t pin)
{
uint8_t muxRate = HWREG16(baseAddress + OFS_LCDCCTL0)
& (LCDMX2 | LCDMX1 | LCDMX0);
// static, 2-mux, 3-mux, 4-mux
if(muxRate <= (LCDMX1 | LCDMX0))
{
if(pin & 1)
{
return (HWREG8(baseAddress + OFS_LCDM1 + pin / 2) >> 4);
}
else
{
return (HWREG8(baseAddress + OFS_LCDM1 + pin / 2) & 0xF);
}
}
else
{
//5-mux, 6-mux, 7-mux, 8-mux
return HWREG8(baseAddress + OFS_LCDM1 + pin);
}
}
void LCD_C_setMemoryWithoutOverwrite(uint16_t baseAddress, uint8_t pin, uint8_t value)
{
uint8_t muxRate = HWREG16(baseAddress + OFS_LCDCCTL0)
& (LCDMX2 | LCDMX1 | LCDMX0);
value |= LCD_C_getMemory(baseAddress, pin);
// static, 2-mux, 3-mux, 4-mux
if(muxRate <= (LCDMX1 | LCDMX0))
{
if(pin & 1)
{
HWREG8(baseAddress + OFS_LCDM1 + pin / 2) &= 0x0F;
HWREG8(baseAddress + OFS_LCDM1 + pin / 2) |= (value & 0xF) << 4;
}
else
{
HWREG8(baseAddress + OFS_LCDM1 + pin / 2) &= 0xF0;
HWREG8(baseAddress + OFS_LCDM1 + pin / 2) |= (value & 0xF);
}
}
else
{
//5-mux, 6-mux, 7-mux, 8-mux
HWREG8(baseAddress + OFS_LCDM1 + pin) = value;
}
}
void LCD_C_setBlinkingMemory(uint16_t baseAddress, uint8_t pin, uint8_t value)
{
uint8_t muxRate = HWREG16(baseAddress + OFS_LCDCCTL0)
& (LCDMX2 | LCDMX1 | LCDMX0);
// static, 2-mux, 3-mux, 4-mux
if (muxRate <= (LCDMX1 | LCDMX0)) {
if (pin & 1) {
HWREG8(baseAddress + OFS_LCDBM1 + pin/2) &= 0x0F;
HWREG8(baseAddress + OFS_LCDBM1 + pin/2) |= (value & 0xF) << 4;
}
else {
HWREG8(baseAddress + OFS_LCDBM1 + pin/2) &= 0xF0;
HWREG8(baseAddress + OFS_LCDBM1 + pin/2) |= (value & 0xF);
}
}
else {
//5-mux, 6-mux, 7-mux, 8-mux
HWREG8(baseAddress + OFS_LCDBM1 + pin) = value;
}
}
uint8_t LCD_C_getBlinkingMemory(uint16_t baseAddress, uint8_t pin)
{
uint8_t muxRate = HWREG16(baseAddress + OFS_LCDCCTL0)
& (LCDMX2 | LCDMX1 | LCDMX0);
// static, 2-mux, 3-mux, 4-mux
if(muxRate <= (LCDMX1 | LCDMX0))
{
if(pin & 1)
{
return (HWREG8(baseAddress + OFS_LCDBM1 + pin / 2) >> 4);
}
else
{
return (HWREG8(baseAddress + OFS_LCDBM1 + pin / 2) & 0xF);
}
}
else
{
//5-mux, 6-mux, 7-mux, 8-mux
return HWREG8(baseAddress + OFS_LCDBM1 + pin);
}
}
void LCD_C_setBlinkingMemoryWithoutOverwrite(uint16_t baseAddress, uint8_t pin, uint8_t value)
{
uint8_t muxRate = HWREG16(baseAddress + OFS_LCDCCTL0)
& (LCDMX2 | LCDMX1 | LCDMX0);
value |= LCD_C_getBlinkingMemory(baseAddress, pin);
// static, 2-mux, 3-mux, 4-mux
if(muxRate <= (LCDMX1 | LCDMX0))
{
if(pin & 1)
{
HWREG8(baseAddress + OFS_LCDBM1 + pin / 2) &= 0x0F;
HWREG8(baseAddress + OFS_LCDBM1 + pin / 2) |= (value & 0xF) << 4;
}
else
{
HWREG8(baseAddress + OFS_LCDBM1 + pin / 2) &= 0xF0;
HWREG8(baseAddress + OFS_LCDBM1 + pin / 2) |= (value & 0xF);
}
}
else
{
//5-mux, 6-mux, 7-mux, 8-mux
HWREG8(baseAddress + OFS_LCDBM1 + pin) = value;
}
}
void LCD_C_configChargePump(uint16_t baseAddress, uint16_t syncToClock,
uint16_t functionControl)
{
HWREG16(baseAddress + OFS_LCDCCPCTL) &= ~(LCDCPCLKSYNC);
HWREG16(baseAddress + OFS_LCDCCPCTL) &= ~(LCDCPDIS7 | LCDCPDIS6 | LCDCPDIS5
| LCDCPDIS4 | LCDCPDIS3 | LCDCPDIS2 | LCDCPDIS1 | LCDCPDIS0);
HWREG16(baseAddress + OFS_LCDCCPCTL) |= syncToClock | functionControl;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for lcd_c_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,167 @@
//*****************************************************************************
//
// ldopwr.c - Driver for the ldopwr Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup ldopwr_api ldopwr
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PU__
#include "ldopwr.h"
#include <assert.h>
void LDOPWR_unLockConfiguration ( uint16_t baseAddress )
{
HWREG16(baseAddress + OFS_LDOKEYPID) = 0x9628;
}
void LDOPWR_lockConfiguration ( uint16_t baseAddress )
{
HWREG16(baseAddress + OFS_LDOKEYPID) = 0x0000;
}
void LDOPWR_enablePort_U_inputs (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_PUCTL_H) |= PUIPE_H;
}
void LDOPWR_disablePort_U_inputs (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_PUCTL_H) &= ~PUIPE_H;
}
void LDOPWR_enablePort_U_outputs (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_PUCTL_L) |= PUOPE;
}
void LDOPWR_disablePort_U_outputs (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_PUCTL_L) &= ~PUOPE;
}
uint8_t LDOPWR_getPort_U1_inputData (uint16_t baseAddress )
{
return ((HWREG8(baseAddress + OFS_PUCTL_L) & PUIN1) >> 3 );
}
uint8_t LDOPWR_getPort_U0_inputData (uint16_t baseAddress )
{
return ((HWREG8(baseAddress + OFS_PUCTL_L) & PUIN0) >> 2 );
}
uint8_t LDOPWR_getPort_U1_outputData (uint16_t baseAddress )
{
return ((HWREG8(baseAddress + OFS_PUCTL_L) & PUOUT1) >> 1 );
}
uint8_t LDOPWR_getPort_U0_outputData (uint16_t baseAddress )
{
return (HWREG8(baseAddress + OFS_PUCTL_L) & PUOUT0);
}
void LDOPWR_setPort_U1_outputData (uint16_t baseAddress,
uint8_t value
)
{
if (LDOPWR_PORTU_PIN_HIGH == value){
HWREG8(baseAddress + OFS_PUCTL_L) |= PUOUT1;
} else {
HWREG8(baseAddress + OFS_PUCTL_L) &= ~PUOUT1;
}
}
void LDOPWR_setPort_U0_outputData (uint16_t baseAddress,
uint8_t value
)
{
if (LDOPWR_PORTU_PIN_HIGH == value){
HWREG8(baseAddress + OFS_PUCTL_L) |= PUOUT0;
} else {
HWREG8(baseAddress + OFS_PUCTL_L) &= ~PUOUT0;
}
}
void LDOPWR_togglePort_U1_outputData (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_PUCTL_L) ^= PUOUT1;
}
void LDOPWR_togglePort_U0_outputData (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_PUCTL_L) ^= PUOUT0;
}
void LDOPWR_enableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG8(baseAddress + OFS_LDOPWRCTL_H) |= mask;
}
void LDOPWR_disableInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG8(baseAddress + OFS_LDOPWRCTL_H) &= ~mask;
}
void LDOPWR_enable (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_LDOPWRCTL_H) |= LDOOEN_H;
}
void LDOPWR_disable (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_LDOPWRCTL_H) &= ~LDOOEN_H;
}
uint8_t LDOPWR_getInterruptStatus (uint16_t baseAddress,
uint16_t mask
)
{
return (HWREG8(baseAddress + OFS_LDOPWRCTL_L) & mask);
}
void LDOPWR_clearInterrupt (uint16_t baseAddress,
uint16_t mask
)
{
HWREG8(baseAddress + OFS_LDOPWRCTL_L) &= ~mask;
}
uint8_t LDOPWR_isLDOInputValid (uint16_t baseAddress)
{
return (HWREG8(baseAddress + OFS_LDOPWRCTL_L) & LDOBGVBV);
}
void LDOPWR_enableOverloadAutoOff (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_LDOPWRCTL_L) |= OVLAOFF_L;
}
void LDOPWR_disableOverloadAutoOff (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_LDOPWRCTL_L) &= ~OVLAOFF_L;
}
uint8_t LDOPWR_getOverloadAutoOffStatus (uint16_t baseAddress)
{
return (HWREG8(baseAddress + OFS_LDOPWRCTL_L) & OVLAOFF_L);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for ldopwr_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,434 @@
//*****************************************************************************
//
// ldopwr.h - Driver for the LDOPWR Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_LDOPWR_H__
#define __MSP430WARE_LDOPWR_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PU__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the value parameter for
// functions: LDOPWR_setPort_U1_outputData(), and
// LDOPWR_setPort_U0_outputData() as well as returned by the
// LDOPWR_getPort_U1_inputData() function, the LDOPWR_getPort_U0_inputData()
// function, the LDOPWR_getPort_U1_outputData() function and the
// LDOPWR_getPort_U0_outputData() function.
//
//*****************************************************************************
#define LDOPWR_PORTU_PIN_HIGH PUOUT0
#define LDOPWR_PORTU_PIN_LOW 0x00
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the LDOPWR_isLDOInputValid() function.
//
//*****************************************************************************
#define LDOPWR_LDO_INPUT_VALID LDOBGVBV
#define LDOPWR_LDO_INPUT_INVALID 0x00
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the LDOPWR_getOverloadAutoOffStatus() function.
//
//*****************************************************************************
#define LDOPWR_AUTOOFF_ENABLED OVLAOFF_H
#define LDOPWR_AUTOOFF_DISABLED 0x00
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: LDOPWR_enableInterrupt(), LDOPWR_disableInterrupt(),
// LDOPWR_getInterruptStatus(), and LDOPWR_clearInterrupt() as well as returned
// by the LDOPWR_getInterruptStatus() function.
//
//*****************************************************************************
#define LDOPWR_LDOI_VOLTAGE_GOING_OFF_INTERRUPT LDOOFFIE_H
#define LDOPWR_LDOI_VOLTAGE_COMING_ON_INTERRUPT LDOONIE_H
#define LDOPWR_LDO_OVERLOAD_INDICATION_INTERRUPT LDOOVLIE_H
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Unlocks the configuration registers and enables write access
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b LDOKEYPID register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_unLockConfiguration(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Locks the configuration registers and disables write access
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b LDOKEYPID register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_lockConfiguration(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables Port U inputs
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_enablePort_U_inputs(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables Port U inputs
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_disablePort_U_inputs(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables Port U outputs
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_enablePort_U_outputs(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables Port U inputs
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_disablePort_U_outputs(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns PU.1 input data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! \return One of the following:
//! - \b LDOPWR_PORTU_PIN_HIGH
//! - \b LDOPWR_PORTU_PIN_LOW
//
//*****************************************************************************
extern uint8_t LDOPWR_getPort_U1_inputData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns PU.0 input data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! \return One of the following:
//! - \b LDOPWR_PORTU_PIN_HIGH
//! - \b LDOPWR_PORTU_PIN_LOW
//
//*****************************************************************************
extern uint8_t LDOPWR_getPort_U0_inputData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns PU.1 output data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! \return One of the following:
//! - \b LDOPWR_PORTU_PIN_HIGH
//! - \b LDOPWR_PORTU_PIN_LOW
//
//*****************************************************************************
extern uint8_t LDOPWR_getPort_U1_outputData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns PU.0 output data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! \return One of the following:
//! - \b LDOPWR_PORTU_PIN_HIGH
//! - \b LDOPWR_PORTU_PIN_LOW
//
//*****************************************************************************
extern uint8_t LDOPWR_getPort_U0_outputData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets PU.1 output data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//! \param value
//! Valid values are:
//! - \b LDOPWR_PORTU_PIN_HIGH
//! - \b LDOPWR_PORTU_PIN_LOW
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_setPort_U1_outputData(uint16_t baseAddress,
uint8_t value);
//*****************************************************************************
//
//! \brief Sets PU.0 output data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//! \param value
//! Valid values are:
//! - \b LDOPWR_PORTU_PIN_HIGH
//! - \b LDOPWR_PORTU_PIN_LOW
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_setPort_U0_outputData(uint16_t baseAddress,
uint8_t value);
//*****************************************************************************
//
//! \brief Toggles PU.1 output data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_togglePort_U1_outputData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Toggles PU.0 output data
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b PUCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_togglePort_U0_outputData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables LDO-PWR module interrupts
//!
//! Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the LDOPWR module.
//! \param mask mask of interrupts to enable
//! Mask value is the logical OR of any of the following:
//! - \b LDOPWR_LDOI_VOLTAGE_GOING_OFF_INTERRUPT
//! - \b LDOPWR_LDOI_VOLTAGE_COMING_ON_INTERRUPT
//! - \b LDOPWR_LDO_OVERLOAD_INDICATION_INTERRUPT
//!
//! Modified bits of \b LDOPWRCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_enableInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Disables LDO-PWR module interrupts
//!
//! \param baseAddress is the base address of the LDOPWR module.
//! \param mask mask of interrupts to disable
//! Mask value is the logical OR of any of the following:
//! - \b LDOPWR_LDOI_VOLTAGE_GOING_OFF_INTERRUPT
//! - \b LDOPWR_LDOI_VOLTAGE_COMING_ON_INTERRUPT
//! - \b LDOPWR_LDO_OVERLOAD_INDICATION_INTERRUPT
//!
//! Modified bits of \b LDOPWRCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_disableInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Enables LDO-PWR module
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b LDOPWRCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables LDO-PWR module
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b LDOPWRCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the interrupt status of LDO-PWR module interrupts
//!
//! \param baseAddress is the base address of the LDOPWR module.
//! \param mask mask of interrupts to get the status of
//! Mask value is the logical OR of any of the following:
//! - \b LDOPWR_LDOI_VOLTAGE_GOING_OFF_INTERRUPT
//! - \b LDOPWR_LDOI_VOLTAGE_COMING_ON_INTERRUPT
//! - \b LDOPWR_LDO_OVERLOAD_INDICATION_INTERRUPT
//!
//! \return Logical OR of any of the following:
//! - \b LDOPWR_LDOI_VOLTAGE_GOING_OFF_INTERRUPT
//! - \b LDOPWR_LDOI_VOLTAGE_COMING_ON_INTERRUPT
//! - \b LDOPWR_LDO_OVERLOAD_INDICATION_INTERRUPT
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t LDOPWR_getInterruptStatus(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Clears the interrupt status of LDO-PWR module interrupts
//!
//! \param baseAddress is the base address of the LDOPWR module.
//! \param mask mask of interrupts to clear the status of
//! Mask value is the logical OR of any of the following:
//! - \b LDOPWR_LDOI_VOLTAGE_GOING_OFF_INTERRUPT
//! - \b LDOPWR_LDOI_VOLTAGE_COMING_ON_INTERRUPT
//! - \b LDOPWR_LDO_OVERLOAD_INDICATION_INTERRUPT
//!
//! Modified bits of \b LDOPWRCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_clearInterrupt(uint16_t baseAddress,
uint16_t mask);
//*****************************************************************************
//
//! \brief Returns if the the LDOI is valid and within bounds
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! \return One of the following:
//! - \b LDOPWR_LDO_INPUT_VALID
//! - \b LDOPWR_LDO_INPUT_INVALID
//
//*****************************************************************************
extern uint8_t LDOPWR_isLDOInputValid(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables the LDO overload auto-off
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b LDOPWRCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_enableOverloadAutoOff(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the LDO overload auto-off
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! Modified bits of \b LDOPWRCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void LDOPWR_disableOverloadAutoOff(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns if the LDOI overload auto-off is enabled or disabled
//!
//! \param baseAddress is the base address of the LDOPWR module.
//!
//! \return One of the following:
//! - \b LDOPWR_AUTOOFF_ENABLED
//! - \b LDOPWR_AUTOOFF_DISABLED
//
//*****************************************************************************
extern uint8_t LDOPWR_getOverloadAutoOffStatus(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_LDOPWR_H__

View File

@@ -0,0 +1,145 @@
//*****************************************************************************
//
// mpy32.c - Driver for the mpy32 Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup mpy32_api mpy32
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_MPY32__
#include "mpy32.h"
#include <assert.h>
void MPY32_setWriteDelay (uint16_t writeDelaySelect)
{
HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~(MPYDLY32 + MPYDLYWRTEN);
HWREG16(MPY32_BASE + OFS_MPY32CTL0) |= writeDelaySelect;
}
void MPY32_enableSaturationMode (void)
{
HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYSAT;
}
void MPY32_disableSaturationMode (void)
{
HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYSAT);
}
uint8_t MPY32_getSaturationMode (void)
{
return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &(MPYSAT));
}
void MPY32_enableFractionalMode (void)
{
HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) |= MPYFRAC;
}
void MPY32_disableFractionalMode (void)
{
HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &= ~(MPYFRAC);
}
uint8_t MPY32_getFractionalMode (void)
{
return (HWREG8(MPY32_BASE + OFS_MPY32CTL0_L) &(MPYFRAC));
}
void MPY32_setOperandOne8Bit (uint8_t multiplicationType,
uint8_t operand)
{
HWREG8(MPY32_BASE + OFS_MPY + multiplicationType) = operand;
}
void MPY32_setOperandOne16Bit (uint8_t multiplicationType,
uint16_t operand)
{
HWREG16(MPY32_BASE + OFS_MPY + multiplicationType) = operand;
}
void MPY32_setOperandOne24Bit (uint8_t multiplicationType,
uint32_t operand)
{
multiplicationType <<= 1;
HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;
HWREG8(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);
}
void MPY32_setOperandOne32Bit (uint8_t multiplicationType,
uint32_t operand)
{
multiplicationType <<= 1;
HWREG16(MPY32_BASE + OFS_MPY32L + multiplicationType) = operand;
HWREG16(MPY32_BASE + OFS_MPY32H + multiplicationType) = (operand >> 16);
}
void MPY32_setOperandTwo8Bit (uint8_t operand)
{
HWREG8(MPY32_BASE + OFS_OP2) = operand;
}
void MPY32_setOperandTwo16Bit (uint16_t operand)
{
HWREG16(MPY32_BASE + OFS_OP2) = operand;
}
void MPY32_setOperandTwo24Bit (uint32_t operand)
{
HWREG16(MPY32_BASE + OFS_OP2L) = operand;
HWREG8(MPY32_BASE + OFS_OP2H) = (operand >> 16);
}
void MPY32_setOperandTwo32Bit (uint32_t operand)
{
HWREG16(MPY32_BASE + OFS_OP2L) = operand;
HWREG16(MPY32_BASE + OFS_OP2H) = (operand >> 16);
}
uint64_t MPY32_getResult (void)
{
uint64_t result;
result = HWREG16(MPY32_BASE + OFS_RES0);
result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES1) << 16);
result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES2) << 32);
result += ((uint64_t)HWREG16(MPY32_BASE + OFS_RES3) << 48);
return ( result );
}
uint16_t MPY32_getSumExtension (void)
{
return ( HWREG16(MPY32_BASE + OFS_SUMEXT) );
}
uint16_t MPY32_getCarryBitValue (void)
{
return ( HWREG16(MPY32_BASE + OFS_MPY32CTL0) | MPYC);
}
void MPY32_clearCarryBitValue (void)
{
HWREG16(MPY32_BASE + OFS_MPY32CTL0) &= ~MPYC;
}
void MPY32_preloadResult (uint64_t result)
{
HWREG16(MPY32_BASE + OFS_RES0) = (result & 0xFFFF);
HWREG16(MPY32_BASE + OFS_RES1) = ((result >> 16) & 0xFFFF);
HWREG16(MPY32_BASE + OFS_RES2) = ((result >> 32) & 0xFFFF);
HWREG16(MPY32_BASE + OFS_RES3) = ((result >> 48) & 0xFFFF);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for mpy32_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,414 @@
//*****************************************************************************
//
// mpy32.h - Driver for the MPY32 Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_MPY32_H__
#define __MSP430WARE_MPY32_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_MPY32__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
// The following are values that can be passed to the writeDelaySelect
// parameter for functions: MPY32_setWriteDelay().
//
//*****************************************************************************
#define MPY32_WRITEDELAY_OFF (!(MPYDLY32 + MPYDLYWRTEN))
#define MPY32_WRITEDELAY_32BIT (MPYDLYWRTEN)
#define MPY32_WRITEDELAY_64BIT (MPYDLY32 + MPYDLYWRTEN)
//*****************************************************************************
//
// The following are values that can be passed to the multiplicationType
// parameter for functions: MPY32_setOperandOne8Bit(),
// MPY32_setOperandOne16Bit(), MPY32_setOperandOne24Bit(), and
// MPY32_setOperandOne32Bit().
//
//*****************************************************************************
#define MPY32_MULTIPLY_UNSIGNED (0x00)
#define MPY32_MULTIPLY_SIGNED (0x02)
#define MPY32_MULTIPLYACCUMULATE_UNSIGNED (0x04)
#define MPY32_MULTIPLYACCUMULATE_SIGNED (0x06)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the MPY32_getSaturationMode() function.
//
//*****************************************************************************
#define MPY32_SATURATION_MODE_DISABLED 0x00
#define MPY32_SATURATION_MODE_ENABLED MPYSAT
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the MPY32_getFractionalMode() function.
//
//*****************************************************************************
#define MPY32_FRACTIONAL_MODE_DISABLED 0x00
#define MPY32_FRACTIONAL_MODE_ENABLED MPYFRAC
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Sets the write delay setting for the MPY32 module.
//!
//! This function sets up a write delay to the MPY module's registers, which
//! holds any writes to the registers until all calculations are complete.
//! There are two different settings, one which waits for 32-bit results to be
//! ready, and one which waits for 64-bit results to be ready. This prevents
//! unpredicatble results if registers are changed before the results are
//! ready.
//!
//! \param writeDelaySelect delays the write to any MPY32 register until the
//! selected bit size of result has been written.
//! Valid values are:
//! - \b MPY32_WRITEDELAY_OFF [Default] - writes are not delayed
//! - \b MPY32_WRITEDELAY_32BIT - writes are delayed until a 32-bit
//! result is available in the result registers
//! - \b MPY32_WRITEDELAY_64BIT - writes are delayed until a 64-bit
//! result is available in the result registers
//! \n Modified bits are \b MPYDLY32 and \b MPYDLYWRTEN of \b MPY32CTL0
//! register.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setWriteDelay(uint16_t writeDelaySelect);
//*****************************************************************************
//
//! \brief Enables Saturation Mode.
//!
//! This function enables saturation mode. When this is enabled, the result
//! read out from the MPY result registers is converted to the most-positive
//! number in the case of an overflow, or the most-negative number in the case
//! of an underflow. Please note, that the raw value in the registers does not
//! reflect the result returned, and if the saturation mode is disabled, then
//! the raw value of the registers will be returned instead.
//!
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_enableSaturationMode(void);
//*****************************************************************************
//
//! \brief Disables Saturation Mode.
//!
//! This function disables saturation mode, which allows the raw result of the
//! MPY result registers to be returned.
//!
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_disableSaturationMode(void);
//*****************************************************************************
//
//! \brief Gets the Saturation Mode.
//!
//! This function gets the current saturation mode.
//!
//!
//! \return Gets the Saturation Mode
//! Return one of the following:
//! - \b MPY32_SATURATION_MODE_DISABLED
//! - \b MPY32_SATURATION_MODE_ENABLED
//! \n Gets the Saturation Mode
//
//*****************************************************************************
extern uint8_t MPY32_getSaturationMode(void);
//*****************************************************************************
//
//! \brief Enables Fraction Mode.
//!
//! This function enables fraction mode.
//!
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_enableFractionalMode(void);
//*****************************************************************************
//
//! \brief Disables Fraction Mode.
//!
//! This function disables fraction mode.
//!
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_disableFractionalMode(void);
//*****************************************************************************
//
//! \brief Gets the Fractional Mode.
//!
//! This function gets the current fractional mode.
//!
//!
//! \return Gets the fractional mode
//! Return one of the following:
//! - \b MPY32_FRACTIONAL_MODE_DISABLED
//! - \b MPY32_FRACTIONAL_MODE_ENABLED
//! \n Gets the Fractional Mode
//
//*****************************************************************************
extern uint8_t MPY32_getFractionalMode(void);
//*****************************************************************************
//
//! \brief Sets an 8-bit value into operand 1.
//!
//! This function sets the first operand for multiplication and determines what
//! type of operation should be performed. Once the second operand is set, then
//! the operation will begin.
//!
//! \param multiplicationType is the type of multiplication to perform once the
//! second operand is set.
//! Valid values are:
//! - \b MPY32_MULTIPLY_UNSIGNED
//! - \b MPY32_MULTIPLY_SIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
//! \param operand is the 8-bit value to load into the 1st operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandOne8Bit(uint8_t multiplicationType,
uint8_t operand);
//*****************************************************************************
//
//! \brief Sets an 16-bit value into operand 1.
//!
//! This function sets the first operand for multiplication and determines what
//! type of operation should be performed. Once the second operand is set, then
//! the operation will begin.
//!
//! \param multiplicationType is the type of multiplication to perform once the
//! second operand is set.
//! Valid values are:
//! - \b MPY32_MULTIPLY_UNSIGNED
//! - \b MPY32_MULTIPLY_SIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
//! \param operand is the 16-bit value to load into the 1st operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandOne16Bit(uint8_t multiplicationType,
uint16_t operand);
//*****************************************************************************
//
//! \brief Sets an 24-bit value into operand 1.
//!
//! This function sets the first operand for multiplication and determines what
//! type of operation should be performed. Once the second operand is set, then
//! the operation will begin.
//!
//! \param multiplicationType is the type of multiplication to perform once the
//! second operand is set.
//! Valid values are:
//! - \b MPY32_MULTIPLY_UNSIGNED
//! - \b MPY32_MULTIPLY_SIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
//! \param operand is the 24-bit value to load into the 1st operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandOne24Bit(uint8_t multiplicationType,
uint32_t operand);
//*****************************************************************************
//
//! \brief Sets an 32-bit value into operand 1.
//!
//! This function sets the first operand for multiplication and determines what
//! type of operation should be performed. Once the second operand is set, then
//! the operation will begin.
//!
//! \param multiplicationType is the type of multiplication to perform once the
//! second operand is set.
//! Valid values are:
//! - \b MPY32_MULTIPLY_UNSIGNED
//! - \b MPY32_MULTIPLY_SIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_UNSIGNED
//! - \b MPY32_MULTIPLYACCUMULATE_SIGNED
//! \param operand is the 32-bit value to load into the 1st operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandOne32Bit(uint8_t multiplicationType,
uint32_t operand);
//*****************************************************************************
//
//! \brief Sets an 8-bit value into operand 2, which starts the multiplication.
//!
//! This function sets the second operand of the multiplication operation and
//! starts the operation.
//!
//! \param operand is the 8-bit value to load into the 2nd operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandTwo8Bit(uint8_t operand);
//*****************************************************************************
//
//! \brief Sets an 16-bit value into operand 2, which starts the
//! multiplication.
//!
//! This function sets the second operand of the multiplication operation and
//! starts the operation.
//!
//! \param operand is the 16-bit value to load into the 2nd operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandTwo16Bit(uint16_t operand);
//*****************************************************************************
//
//! \brief Sets an 24-bit value into operand 2, which starts the
//! multiplication.
//!
//! This function sets the second operand of the multiplication operation and
//! starts the operation.
//!
//! \param operand is the 24-bit value to load into the 2nd operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandTwo24Bit(uint32_t operand);
//*****************************************************************************
//
//! \brief Sets an 32-bit value into operand 2, which starts the
//! multiplication.
//!
//! This function sets the second operand of the multiplication operation and
//! starts the operation.
//!
//! \param operand is the 32-bit value to load into the 2nd operand.
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_setOperandTwo32Bit(uint32_t operand);
//*****************************************************************************
//
//! \brief Returns an 64-bit result of the last multiplication operation.
//!
//! This function returns all 64 bits of the result registers
//!
//!
//! \return The 64-bit result is returned as a uint64_t type
//
//*****************************************************************************
extern uint64_t MPY32_getResult(void);
//*****************************************************************************
//
//! \brief Returns the Sum Extension of the last multiplication operation.
//!
//! This function returns the Sum Extension of the MPY module, which either
//! gives the sign after a signed operation or shows a carry after a multiply-
//! and-accumulate operation. The Sum Extension acts as a check for overflows
//! or underflows.
//!
//!
//! \return The value of the MPY32 module Sum Extension.
//
//*****************************************************************************
extern uint16_t MPY32_getSumExtension(void);
//*****************************************************************************
//
//! \brief Returns the Carry Bit of the last multiplication operation.
//!
//! This function returns the Carry Bit of the MPY module, which either gives
//! the sign after a signed operation or shows a carry after a multiply- and-
//! accumulate operation.
//!
//!
//! \return The value of the MPY32 module Carry Bit 0x0 or 0x1.
//
//*****************************************************************************
extern uint16_t MPY32_getCarryBitValue(void);
//*****************************************************************************
//
//! \brief Clears the Carry Bit of the last multiplication operation.
//!
//! This function clears the Carry Bit of the MPY module
//!
//!
//! \return The value of the MPY32 module Carry Bit 0x0 or 0x1.
//
//*****************************************************************************
extern void MPY32_clearCarryBitValue(void);
//*****************************************************************************
//
//! \brief Preloads the result register
//!
//! This function Preloads the result register
//!
//! \param result value to preload the result register to
//!
//! \return None
//
//*****************************************************************************
extern void MPY32_preloadResult(uint64_t result);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_MPY32_H__

View File

@@ -0,0 +1,119 @@
//*****************************************************************************
//
// oa.c - Driver for the oa Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup oa_api oa
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_OA_0__
#include "oa.h"
#include <assert.h>
void OA_openSwitch( uint16_t baseAddress,
uint8_t positiveInputMask,
uint8_t negativeInputMask,
uint8_t groundMask
)
{
HWREG16(baseAddress + OFS_OA0PSW) &= ~positiveInputMask;
HWREG16(baseAddress + OFS_OA0NSW) &= ~negativeInputMask;
HWREG16(baseAddress + OFS_OA0GSW) &= ~groundMask;
}
void OA_closeSwitch(uint16_t baseAddress,
uint8_t positiveInputMask,
uint8_t negativeInputMask,
uint8_t groundMask
)
{
HWREG16(baseAddress + OFS_OA0PSW) |= positiveInputMask;
HWREG16(baseAddress + OFS_OA0NSW) |= negativeInputMask;
HWREG16(baseAddress + OFS_OA0GSW) |= groundMask;
}
uint8_t OA_getSwitchStatus(uint16_t baseAddress,
uint8_t inputTerminal
)
{
uint8_t returnValue = 0;
switch(inputTerminal)
{
case OA_POSITIVE_INPUT_TERMINAL_SWITCHES:
returnValue = (HWREG16(baseAddress + OFS_OA0PSW) & (PSW3 |
PSW2 |
PSW1 |
PSW0)
);
break;
case OA_NEGATIVE_INPUT_TERMINAL_SWITCHES:
returnValue = (HWREG16(baseAddress + OFS_OA0NSW) & (NSW4 |
NSW3 |
NSW2 |
NSW1 |
NSW0)
);
break;
case OA_GROUND_SWITCHES:
returnValue = (HWREG16(baseAddress + OFS_OA0GSW) & (GSW1 |
GSW0)
);
break;
}
return returnValue;
}
uint8_t OA_getRailToRailInputReadyStatus(uint16_t baseAddress)
{
return ((HWREG8(baseAddress + OFS_OA0CTL0) & OARRIRDY));
}
uint8_t OA_getRailToRailInputStatus(uint16_t baseAddress)
{
return ((HWREG8(baseAddress + OFS_OA0CTL0) & OARRI));
}
void OA_enableRailToRailInput(uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_OA0CTL0) |= OARRI;
}
void OA_disableRailToRailInput(uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_OA0CTL0) &= ~OARRI;
}
void OA_disableAmplifierMode(uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_OA0CTL0) &= ~OAM;
}
void OA_enableAmplifierMode(uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_OA0CTL0) |= OAM;
}
uint8_t OA_getAmplifierModeStatus(uint16_t baseAddress)
{
return ((HWREG8(baseAddress + OFS_OA0CTL0) & OAM));
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for oa_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,285 @@
//*****************************************************************************
//
// oa.h - Driver for the OA Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_OA_H__
#define __MSP430WARE_OA_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_OA_0__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the positiveInputMask
// parameter for functions: OA_openSwitch(), and OA_closeSwitch().
//
//*****************************************************************************
#define OA_POSITIVE_INPUT_TERMINAL_SWITCH0 PSW0
#define OA_POSITIVE_INPUT_TERMINAL_SWITCH1 PSW1
#define OA_POSITIVE_INPUT_TERMINAL_SWITCH2 PSW2
#define OA_POSITIVE_INPUT_TERMINAL_SWITCH3 PSW3
#define OA_POSITIVE_INPUT_TERMINAL_NONE 0x00
//*****************************************************************************
//
// The following are values that can be passed to the negativeInputMask
// parameter for functions: OA_openSwitch(), and OA_closeSwitch().
//
//*****************************************************************************
#define OA_NEGATIVE_INPUT_TERMINAL_SWITCH0 NSW0
#define OA_NEGATIVE_INPUT_TERMINAL_SWITCH1 NSW1
#define OA_NEGATIVE_INPUT_TERMINAL_SWITCH2 NSW2
#define OA_NEGATIVE_INPUT_TERMINAL_SWITCH3 NSW3
#define OA_NEGATIVE_INPUT_TERMINAL_SWITCH4 NSW4
#define OA_NEGATIVE_INPUT_TERMINAL_NONE 0x00
//*****************************************************************************
//
// The following are values that can be passed to the groundMask parameter for
// functions: OA_openSwitch(), and OA_closeSwitch().
//
//*****************************************************************************
#define OA_GROUND_SWITCH0 GSW0
#define OA_GROUND_SWITCH1 GSW1
#define OA_GROUND_NONE 0x00
//*****************************************************************************
//
// The following are values that can be passed to the inputTerminal parameter
// for functions: OA_getSwitchStatus().
//
//*****************************************************************************
#define OA_POSITIVE_INPUT_TERMINAL_SWITCHES 0x00
#define OA_NEGATIVE_INPUT_TERMINAL_SWITCHES 0x01
#define OA_GROUND_SWITCHES 0x02
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the OA_getRailToRailInputReadyStatus() function.
//
//*****************************************************************************
#define OA_INPUT_READY OARRIRDY
#define OA_INPUT_NOT_READY 0x00
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the OA_getRailToRailInputStatus() function.
//
//*****************************************************************************
#define OA_INPUT_ENABLED OARRI
#define OA_INPUT_DISABLED (0x00)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the OA_getAmplifierModeStatus() function.
//
//*****************************************************************************
#define OA_AMPLIFIER_MODE_ENABLED OAM
#define OA_AMPLIFIER_MODE_DISABLED (0x00)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Opens the positive input terminal, negative input terminal and
//! ground switch of the OA Module per user selection
//!
//! \param baseAddress is the base address of the OA module.
//! \param positiveInputMask
//! Mask value is the logical OR of any of the following:
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH0
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH1
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH2
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH3
//! - \b OA_POSITIVE_INPUT_TERMINAL_NONE
//! \param negativeInputMask
//! Mask value is the logical OR of any of the following:
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH0
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH1
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH2
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH3
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH4
//! - \b OA_NEGATIVE_INPUT_TERMINAL_NONE
//! \param groundMask
//! Mask value is the logical OR of any of the following:
//! - \b OA_GROUND_SWITCH0
//! - \b OA_GROUND_SWITCH1
//! - \b OA_GROUND_NONE
//!
//! \return None
//
//*****************************************************************************
extern void OA_openSwitch(uint16_t baseAddress,
uint8_t positiveInputMask,
uint8_t negativeInputMask,
uint8_t groundMask);
//*****************************************************************************
//
//! \brief Closes the positive input terminal, negative input terminal and
//! ground switch of the OA Module per user selection.
//!
//! \param baseAddress is the base address of the OA module.
//! \param positiveInputMask
//! Mask value is the logical OR of any of the following:
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH0
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH1
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH2
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCH3
//! - \b OA_POSITIVE_INPUT_TERMINAL_NONE
//! \param negativeInputMask
//! Mask value is the logical OR of any of the following:
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH0
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH1
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH2
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH3
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCH4
//! - \b OA_NEGATIVE_INPUT_TERMINAL_NONE
//! \param groundMask
//! Mask value is the logical OR of any of the following:
//! - \b OA_GROUND_SWITCH0
//! - \b OA_GROUND_SWITCH1
//! - \b OA_GROUND_NONE
//!
//! \return None
//
//*****************************************************************************
extern void OA_closeSwitch(uint16_t baseAddress,
uint8_t positiveInputMask,
uint8_t negativeInputMask,
uint8_t groundMask);
//*****************************************************************************
//
//! \brief Gets the positive input terminal, negative input terminal and ground
//! switch status of the OA Module per user selection.
//!
//! \param baseAddress is the base address of the OA module.
//! \param inputTerminal
//! Valid values are:
//! - \b OA_POSITIVE_INPUT_TERMINAL_SWITCHES
//! - \b OA_NEGATIVE_INPUT_TERMINAL_SWITCHES
//! - \b OA_GROUND_SWITCHES
//!
//! \return Logical OR of the switches that are closed in the selected
//! inputTerminal
//
//*****************************************************************************
extern uint8_t OA_getSwitchStatus(uint16_t baseAddress,
uint8_t inputTerminal);
//*****************************************************************************
//
//! \brief Gets the rail to rail input ready status
//!
//! \param baseAddress is the base address of the OA module.
//!
//! \return One of the following:
//! - \b OA_INPUT_READY
//! - \b OA_INPUT_NOT_READY
//
//*****************************************************************************
extern uint8_t OA_getRailToRailInputReadyStatus(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Gets the rail to rail input status
//!
//! \param baseAddress is the base address of the OA module.
//!
//! \return One of the following:
//! - \b OA_INPUT_ENABLED
//! - \b OA_INPUT_DISABLED
//
//*****************************************************************************
extern uint8_t OA_getRailToRailInputStatus(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables the rail to rail input
//!
//! \param baseAddress is the base address of the OA module.
//!
//! \return None
//
//*****************************************************************************
extern void OA_enableRailToRailInput(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the rail to rail input
//!
//! \param baseAddress is the base address of the OA module.
//!
//! \return None
//
//*****************************************************************************
extern void OA_disableRailToRailInput(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the amplifier mode
//!
//! \param baseAddress is the base address of the OA module.
//!
//! \return None
//
//*****************************************************************************
extern void OA_disableAmplifierMode(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables the amplifier mode
//!
//! \param baseAddress is the base address of the OA module.
//!
//! \return None
//
//*****************************************************************************
extern void OA_enableAmplifierMode(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Gets the amplifier mode status
//!
//! \param baseAddress is the base address of the OA module.
//!
//! \return One of the following:
//! - \b OA_AMPLIFIER_MODE_ENABLED
//! - \b OA_AMPLIFIER_MODE_DISABLED
//
//*****************************************************************************
extern uint8_t OA_getAmplifierModeStatus(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_OA_H__

View File

@@ -0,0 +1,56 @@
//*****************************************************************************
//
// pmap.c - Driver for the pmap Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup pmap_api pmap
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PORT_MAPPING__
#include "pmap.h"
#include <assert.h>
void PMAP_initPorts ( uint16_t baseAddress,
PMAP_initPortsParam *param)
{
//Store current interrupt state, then disable all interrupts
uint16_t globalInterruptState = __get_SR_register() & GIE;
__disable_interrupt();
//Get write-access to port mapping registers:
HWREG16(baseAddress + OFS_PMAPKEYID) = PMAPPW;
//Enable/Disable reconfiguration during runtime
HWREG8(baseAddress + OFS_PMAPCTL) &= ~PMAPRECFG;
HWREG8(baseAddress + OFS_PMAPCTL) |= param->portMapReconfigure;
//Configure Port Mapping:
uint16_t i;
for (i = 0; i < param->numberOfPorts * 8; i++)
{
param->PxMAPy[i] = param->portMapping[i];
}
//Disable write-access to port mapping registers:
HWREG8(baseAddress + OFS_PMAPKEYID) = 0;
//Restore previous interrupt state
__bis_SR_register(globalInterruptState);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for pmap_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,86 @@
//*****************************************************************************
//
// pmap.h - Driver for the PMAP Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_PMAP_H__
#define __MSP430WARE_PMAP_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PORT_MAPPING__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the PMAP_initPorts() function as the param parameter.
//
//*****************************************************************************
typedef struct PMAP_initPortsParam {
//! Is the pointer to init Data
const uint8_t* portMapping;
//! Is the pointer start of first PMAP to initialize
uint8_t* PxMAPy;
//! Is the number of Ports to initialize
uint8_t numberOfPorts;
//! Is used to enable/disable reconfiguration
//! \n Valid values are:
//! - \b PMAP_ENABLE_RECONFIGURATION
//! - \b PMAP_DISABLE_RECONFIGURATION [Default]
uint8_t portMapReconfigure;
} PMAP_initPortsParam;
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: PMAP_initPorts().
//
//*****************************************************************************
#define PMAP_ENABLE_RECONFIGURATION PMAPRECFG
#define PMAP_DISABLE_RECONFIGURATION 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief This function configures the MSP430 Port Mapper
//!
//! This function port maps a set of pins to a new set.
//!
//!
//! Modified bits of \b PMAPKETID register and bits of \b PMAPCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMAP_initPorts(uint16_t baseAddress,
PMAP_initPortsParam *param);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_PMAP_H__

View File

@@ -0,0 +1,508 @@
//*****************************************************************************
//
// pmm.c - Driver for the pmm Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup pmm_api pmm
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PMM__
#include "pmm.h"
#include <assert.h>
void PMM_enableSvsL (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= SVSLE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsL (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) &= ~SVSLE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvmL (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= SVMLE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvmL (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) &= ~SVMLE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsH (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= SVSHE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsH (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) &= ~SVSHE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvmH (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= SVMHE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvmH (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) &= ~SVMHE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsLSvmL (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= (SVSLE + SVMLE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsLSvmL (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) &= ~(SVSLE + SVMLE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsHSvmH (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= (SVSHE + SVMHE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsHSvmH (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) &= ~(SVSHE + SVMHE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsLReset (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) |= SVSLPE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsLReset (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) &= ~SVSLPE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvmLInterrupt (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) |= SVMLIE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvmLInterrupt (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) &= ~SVMLIE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsHReset (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) |= SVSHPE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsHReset (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) &= ~SVSHPE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvmHInterrupt (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) |= SVMHIE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvmHInterrupt (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMRIE) &= ~SVMHIE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_clearPMMIFGS (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_PMMIFG) = 0;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsLInLPMFastWake (void)
{
//These settings use SVSH/LACE = 0
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= (SVSLFP + SVSLMD);
HWREG16(PMM_BASE + OFS_SVSMLCTL) &= ~SVSMLACE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsLInLPMSlowWake (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= SVSLMD;
HWREG16(PMM_BASE + OFS_SVSMLCTL) &= ~(SVSLFP + SVSMLACE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsLInLPMFastWake (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= SVSLFP;
HWREG16(PMM_BASE + OFS_SVSMLCTL) &= ~(SVSLMD + SVSMLACE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsLInLPMSlowWake (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) &= ~(SVSLFP + SVSMLACE + SVSLMD);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsHInLPMNormPerf (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= SVSHMD;
HWREG16(PMM_BASE + OFS_SVSMHCTL) &= ~(SVSMHACE + SVSHFP);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_enableSvsHInLPMFullPerf (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= (SVSHMD + SVSHFP);
HWREG16(PMM_BASE + OFS_SVSMHCTL) &= ~SVSMHACE;
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsHInLPMNormPerf (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) &= ~(SVSMHACE + SVSHFP + SVSHMD);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_disableSvsHInLPMFullPerf (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= SVSHFP;
HWREG16(PMM_BASE + OFS_SVSMHCTL) &= ~(SVSMHACE + SVSHMD);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_optimizeSvsLInLPMFastWake (void)
{
//These setting use SVSH/LACE = 1
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= (SVSLFP + SVSLMD + SVSMLACE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
void PMM_optimizeSvsHInLPMFullPerf (void)
{
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= (SVSHMD + SVSHFP + SVSMHACE);
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
}
uint16_t PMM_setVCoreUp ( uint8_t level){
uint32_t 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
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
//Disable dedicated Interrupts
//Backup all registers
PMMRIE_backup = HWREG16(PMM_BASE + OFS_PMMRIE);
HWREG16(PMM_BASE + OFS_PMMRIE) &= ~(SVMHVLRPE | SVSHPE | SVMLVLRPE |
SVSLPE | SVMHVLRIE | SVMHIE |
SVSMHDLYIE | SVMLVLRIE | SVMLIE |
SVSMLDLYIE
);
SVSMHCTL_backup = HWREG16(PMM_BASE + OFS_SVSMHCTL);
SVSMLCTL_backup = HWREG16(PMM_BASE + OFS_SVSMLCTL);
//Clear flags
HWREG16(PMM_BASE + OFS_PMMIFG) = 0;
//Set SVM highside to new level and check if a VCore increase is possible
HWREG16(PMM_BASE + OFS_SVSMHCTL) = SVMHE | SVSHE | (SVSMHRRL0 * level);
//Wait until SVM highside is settled
while ((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMHDLYIFG) == 0) ;
//Clear flag
HWREG16(PMM_BASE + OFS_PMMIFG) &= ~SVSMHDLYIFG;
//Check if a VCore increase is possible
if ((HWREG16(PMM_BASE + OFS_PMMIFG) & SVMHIFG) == SVMHIFG){
//-> Vcc is too low for a Vcore increase
//recover the previous settings
HWREG16(PMM_BASE + OFS_PMMIFG) &= ~SVSMHDLYIFG;
HWREG16(PMM_BASE + OFS_SVSMHCTL) = SVSMHCTL_backup;
//Wait until SVM highside is settled
while ((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMHDLYIFG) == 0) ;
//Clear all Flags
HWREG16(PMM_BASE +
OFS_PMMIFG) &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG |
SVMLVLRIFG | SVMLIFG |
SVSMLDLYIFG
);
//Restore PMM interrupt enable register
HWREG16(PMM_BASE + OFS_PMMRIE) = PMMRIE_backup;
//Lock PMM registers for write access
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
//return: voltage not set
return ( STATUS_FAIL) ;
}
//Set also SVS highside to new level
//Vcc is high enough for a Vcore increase
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= (SVSHRVL0 * level);
//Wait until SVM highside is settled
while ((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMHDLYIFG) == 0) ;
//Clear flag
HWREG16(PMM_BASE + OFS_PMMIFG) &= ~SVSMHDLYIFG;
//Set VCore to new level
HWREG8(PMM_BASE + OFS_PMMCTL0_L) = PMMCOREV0 * level;
//Set SVM, SVS low side to new level
HWREG16(PMM_BASE + OFS_SVSMLCTL) = SVMLE | (SVSMLRRL0 * level) |
SVSLE | (SVSLRVL0 * level);
//Wait until SVM, SVS low side is settled
while ((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMLDLYIFG) == 0) ;
//Clear flag
HWREG16(PMM_BASE + OFS_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
HWREG16(PMM_BASE + OFS_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
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= SVSMLCTL_backup;
//Restore High side settings
//Clear all other bits except level settings
HWREG16(PMM_BASE + OFS_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
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= SVSMHCTL_backup;
//Wait until high side, low side settled
while (((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMLDLYIFG) == 0) ||
((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMHDLYIFG) == 0)) ;
//Clear all Flags
HWREG16(PMM_BASE + OFS_PMMIFG) &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG |
SVMLVLRIFG | SVMLIFG | SVSMLDLYIFG
);
//Restore PMM interrupt enable register
HWREG16(PMM_BASE + OFS_PMMRIE) = PMMRIE_backup;
//Lock PMM registers for write access
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
return ( STATUS_SUCCESS) ;
}
uint16_t PMM_setVCoreDown ( uint8_t level){
uint32_t 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
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0xA5;
//Disable dedicated Interrupts
//Backup all registers
PMMRIE_backup = HWREG16(PMM_BASE + OFS_PMMRIE);
HWREG16(PMM_BASE + OFS_PMMRIE) &= ~(SVMHVLRPE | SVSHPE | SVMLVLRPE |
SVSLPE | SVMHVLRIE | SVMHIE |
SVSMHDLYIE | SVMLVLRIE | SVMLIE |
SVSMLDLYIE
);
SVSMHCTL_backup = HWREG16(PMM_BASE + OFS_SVSMHCTL);
SVSMLCTL_backup = HWREG16(PMM_BASE + OFS_SVSMLCTL);
//Clear flags
HWREG16(PMM_BASE + OFS_PMMIFG) &= ~(SVMHIFG | SVSMHDLYIFG |
SVMLIFG | SVSMLDLYIFG
);
//Set SVM, SVS high & low side to new settings in normal mode
HWREG16(PMM_BASE + OFS_SVSMHCTL) = SVMHE | (SVSMHRRL0 * level) |
SVSHE | (SVSHRVL0 * level);
HWREG16(PMM_BASE + OFS_SVSMLCTL) = SVMLE | (SVSMLRRL0 * level) |
SVSLE | (SVSLRVL0 * level);
//Wait until SVM high side and SVM low side is settled
while ((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMHDLYIFG) == 0 ||
(HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMLDLYIFG) == 0) ;
//Clear flags
HWREG16(PMM_BASE + OFS_PMMIFG) &= ~(SVSMHDLYIFG + SVSMLDLYIFG);
//SVS, SVM core and high side are now set to protect for the new core level
//Set VCore to new level
HWREG8(PMM_BASE + OFS_PMMCTL0_L) = PMMCOREV0 * level;
//Restore Low side settings
//Clear all other bits _except_ level settings
HWREG16(PMM_BASE + OFS_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
HWREG16(PMM_BASE + OFS_SVSMLCTL) |= SVSMLCTL_backup;
//Restore High side settings
//Clear all other bits except level settings
HWREG16(PMM_BASE + OFS_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
HWREG16(PMM_BASE + OFS_SVSMHCTL) |= SVSMHCTL_backup;
//Wait until high side, low side settled
while (((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMLDLYIFG) == 0) ||
((HWREG16(PMM_BASE + OFS_PMMIFG) & SVSMHDLYIFG) == 0)) ;
//Clear all Flags
HWREG16(PMM_BASE + OFS_PMMIFG) &= ~(SVMHVLRIFG | SVMHIFG | SVSMHDLYIFG |
SVMLVLRIFG | SVMLIFG | SVSMLDLYIFG
);
//Restore PMM interrupt enable register
HWREG16(PMM_BASE + OFS_PMMRIE) = PMMRIE_backup;
//Lock PMM registers for write access
HWREG8(PMM_BASE + OFS_PMMCTL0_H) = 0x00;
//Return: OK
return ( STATUS_SUCCESS) ;
}
bool PMM_setVCore ( uint8_t level){
uint8_t actlevel;
bool status = STATUS_SUCCESS;
uint16_t interruptState;
//Set Mask for Max. level
level &= PMMCOREV_3;
//Get actual VCore
actlevel = (HWREG16(PMM_BASE + OFS_PMMCTL0) & PMMCOREV_3);
//Disable interrupts because certain peripherals will not
//work during VCORE change
interruptState = __get_interrupt_state();
__disable_interrupt();
__no_operation();
//step by step increase or decrease
while ((level != actlevel) && (status == STATUS_SUCCESS))
{
if (level > actlevel){
status = PMM_setVCoreUp(++actlevel);
} else {
status = PMM_setVCoreDown(--actlevel);
}
}
//Re-enable interrupt state to whatever it was before
if(interruptState & GIE)
{
__enable_interrupt();
}
return ( status) ;
}
uint16_t PMM_getInterruptStatus (uint16_t mask)
{
return ( (HWREG16(PMM_BASE + OFS_PMMIFG)) & mask );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for pmm_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,554 @@
//*****************************************************************************
//
// pmm.h - Driver for the PMM Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_PMM_H__
#define __MSP430WARE_PMM_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_PMM__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the level parameter for
// functions: PMM_setVCoreUp(), PMM_setVCoreDown(), and PMM_setVCore().
//
//*****************************************************************************
#define PMM_CORE_LEVEL_0 PMMCOREV_0
#define PMM_CORE_LEVEL_1 PMMCOREV_1
#define PMM_CORE_LEVEL_2 PMMCOREV_2
#define PMM_CORE_LEVEL_3 PMMCOREV_3
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: PMM_getInterruptStatus() as well as returned by the
// PMM_getInterruptStatus() function.
//
//*****************************************************************************
#define PMM_SVSMLDLYIFG SVSMLDLYIFG
#define PMM_SVMLIFG SVMLIFG
#define PMM_SVMLVLRIFG SVMLVLRIFG
#define PMM_SVSMHDLYIFG SVSMHDLYIFG
#define PMM_SVMHIFG SVMHIFG
#define PMM_SVMHVLRIFG SVMHVLRIFG
#define PMM_PMMBORIFG PMMBORIFG
#define PMM_PMMRSTIFG PMMRSTIFG
#define PMM_PMMPORIFG PMMPORIFG
#define PMM_SVSHIFG SVSHIFG
#define PMM_SVSLIFG SVSLIFG
#define PMM_PMMLPM5IFG PMMLPM5IFG
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Enables the low-side SVS circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsL(void);
//*****************************************************************************
//
//! \brief Disables the low-side SVS circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsL(void);
//*****************************************************************************
//
//! \brief Enables the low-side SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvmL(void);
//*****************************************************************************
//
//! \brief Disables the low-side SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvmL(void);
//*****************************************************************************
//
//! \brief Enables the high-side SVS circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsH(void);
//*****************************************************************************
//
//! \brief Disables the high-side SVS circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsH(void);
//*****************************************************************************
//
//! \brief Enables the high-side SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvmH(void);
//*****************************************************************************
//
//! \brief Disables the high-side SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvmH(void);
//*****************************************************************************
//
//! \brief Enables the low-side SVS and SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsLSvmL(void);
//*****************************************************************************
//
//! \brief Disables the low-side SVS and SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsLSvmL(void);
//*****************************************************************************
//
//! \brief Enables the high-side SVS and SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsHSvmH(void);
//*****************************************************************************
//
//! \brief Disables the high-side SVS and SVM circuitry
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsHSvmH(void);
//*****************************************************************************
//
//! \brief Enables the POR signal generation when a low-voltage event is
//! registered by the low-side SVS
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsLReset(void);
//*****************************************************************************
//
//! \brief Disables the POR signal generation when a low-voltage event is
//! registered by the low-side SVS
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsLReset(void);
//*****************************************************************************
//
//! \brief Enables the interrupt generation when a low-voltage event is
//! registered by the low-side SVM
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvmLInterrupt(void);
//*****************************************************************************
//
//! \brief Disables the interrupt generation when a low-voltage event is
//! registered by the low-side SVM
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvmLInterrupt(void);
//*****************************************************************************
//
//! \brief Enables the POR signal generation when a low-voltage event is
//! registered by the high-side SVS
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsHReset(void);
//*****************************************************************************
//
//! \brief Disables the POR signal generation when a low-voltage event is
//! registered by the high-side SVS
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsHReset(void);
//*****************************************************************************
//
//! \brief Enables the interrupt generation when a low-voltage event is
//! registered by the high-side SVM
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvmHInterrupt(void);
//*****************************************************************************
//
//! \brief Disables the interrupt generation when a low-voltage event is
//! registered by the high-side SVM
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIE register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvmHInterrupt(void);
//*****************************************************************************
//
//! \brief Clear all interrupt flags for the PMM
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b PMMIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_clearPMMIFGS(void);
//*****************************************************************************
//
//! \brief Enables supervisor low side in LPM with twake-up-fast from LPM2,
//! LPM3, and LPM4
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsLInLPMFastWake(void);
//*****************************************************************************
//
//! \brief Enables supervisor low side in LPM with twake-up-slow from LPM2,
//! LPM3, and LPM4
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsLInLPMSlowWake(void);
//*****************************************************************************
//
//! \brief Disables supervisor low side in LPM with twake-up-fast from LPM2,
//! LPM3, and LPM4
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsLInLPMFastWake(void);
//*****************************************************************************
//
//! \brief Disables supervisor low side in LPM with twake-up-slow from LPM2,
//! LPM3, and LPM4
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsLInLPMSlowWake(void);
//*****************************************************************************
//
//! \brief Enables supervisor high side in LPM with tpd = 20 s(1)
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsHInLPMNormPerf(void);
//*****************************************************************************
//
//! \brief Enables supervisor high side in LPM with tpd = 2.5 s(1)
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_enableSvsHInLPMFullPerf(void);
//*****************************************************************************
//
//! \brief Disables supervisor high side in LPM with tpd = 20 s(1)
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsHInLPMNormPerf(void);
//*****************************************************************************
//
//! \brief Disables supervisor high side in LPM with tpd = 2.5 s(1)
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMHCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_disableSvsHInLPMFullPerf(void);
//*****************************************************************************
//
//! \brief Optimized to provide twake-up-fast from LPM2, LPM3, and LPM4 with
//! least power
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_optimizeSvsLInLPMFastWake(void);
//*****************************************************************************
//
//! \brief Optimized to provide tpd = 2.5 s(1) in LPM with least power
//!
//!
//! Modified bits of \b PMMCTL0 register and bits of \b SVSMLCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void PMM_optimizeSvsHInLPMFullPerf(void);
//*****************************************************************************
//
//! \brief Increase Vcore by one level
//!
//! \param level level to which Vcore needs to be increased
//! Valid values are:
//! - \b PMM_CORE_LEVEL_0 [Default]
//! - \b PMM_CORE_LEVEL_1
//! - \b PMM_CORE_LEVEL_2
//! - \b PMM_CORE_LEVEL_3
//!
//! Modified bits of \b PMMCTL0 register, bits of \b PMMIFG register, bits of
//! \b PMMRIE register, bits of \b SVSMHCTL register and bits of \b SVSMLCTL
//! register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern uint16_t PMM_setVCoreUp(uint8_t level);
//*****************************************************************************
//
//! \brief Decrease Vcore by one level
//!
//! \param level level to which Vcore needs to be decreased
//! Valid values are:
//! - \b PMM_CORE_LEVEL_0 [Default]
//! - \b PMM_CORE_LEVEL_1
//! - \b PMM_CORE_LEVEL_2
//! - \b PMM_CORE_LEVEL_3
//!
//! Modified bits of \b PMMCTL0 register, bits of \b PMMIFG register, bits of
//! \b PMMRIE register, bits of \b SVSMHCTL register and bits of \b SVSMLCTL
//! register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern uint16_t PMM_setVCoreDown(uint8_t level);
//*****************************************************************************
//
//! \brief Set Vcore to expected level
//!
//! \param level level to which Vcore needs to be decreased/increased
//! Valid values are:
//! - \b PMM_CORE_LEVEL_0 [Default]
//! - \b PMM_CORE_LEVEL_1
//! - \b PMM_CORE_LEVEL_2
//! - \b PMM_CORE_LEVEL_3
//!
//! Modified bits of \b PMMCTL0 register, bits of \b PMMIFG register, bits of
//! \b PMMRIE register, bits of \b SVSMHCTL register and bits of \b SVSMLCTL
//! register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern bool PMM_setVCore(uint8_t level);
//*****************************************************************************
//
//! \brief Returns interrupt status
//!
//! \param mask is the mask for specifying the required flag
//! Mask value is the logical OR of any of the following:
//! - \b PMM_SVSMLDLYIFG
//! - \b PMM_SVMLIFG
//! - \b PMM_SVMLVLRIFG
//! - \b PMM_SVSMHDLYIFG
//! - \b PMM_SVMHIFG
//! - \b PMM_SVMHVLRIFG
//! - \b PMM_PMMBORIFG
//! - \b PMM_PMMRSTIFG
//! - \b PMM_PMMPORIFG
//! - \b PMM_SVSHIFG
//! - \b PMM_SVSLIFG
//! - \b PMM_PMMLPM5IFG
//!
//! \return Logical OR of any of the following:
//! - \b PMM_SVSMLDLYIFG
//! - \b PMM_SVMLIFG
//! - \b PMM_SVMLVLRIFG
//! - \b PMM_SVSMHDLYIFG
//! - \b PMM_SVMHIFG
//! - \b PMM_SVMHVLRIFG
//! - \b PMM_PMMBORIFG
//! - \b PMM_PMMRSTIFG
//! - \b PMM_PMMPORIFG
//! - \b PMM_SVSHIFG
//! - \b PMM_SVSLIFG
//! - \b PMM_PMMLPM5IFG
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint16_t PMM_getInterruptStatus(uint16_t mask);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_PMM_H__

View File

@@ -0,0 +1,40 @@
//*****************************************************************************
//
// ram.c - Driver for the ram Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup ram_api ram
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_RC__
#include "ram.h"
#include <assert.h>
void RAM_setSectorOff (uint8_t sector
)
{
//Write key to start write to RCCTL0 and sector
HWREG16(RAM_BASE + OFS_RCCTL0) = (RCKEY + sector);
}
uint8_t RAM_getSectorState (uint8_t sector
)
{
return (HWREG8(RAM_BASE + OFS_RCCTL0_L) & sector);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for ram_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,110 @@
//*****************************************************************************
//
// ram.h - Driver for the RAM Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_RAM_H__
#define __MSP430WARE_RAM_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_RC__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the sector parameter for
// functions: RAM_setSectorOff(), and RAM_getSectorState() as well as returned
// by the RAM_getSectorState() function.
//
//*****************************************************************************
#define RAM_SECTOR0 RCRS0OFF
#define RAM_SECTOR1 RCRS1OFF
#define RAM_SECTOR2 RCRS2OFF
#define RAM_SECTOR3 RCRS3OFF
#define RAM_SECTOR4 RCRS4OFF
#define RAM_SECTOR5 RCRS5OFF
#define RAM_SECTOR6 RCRS6OFF
#define RAM_SECTOR7 RCRS7OFF
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Set specified RAM sector off
//!
//! \param sector is specified sector to be set off.
//! Mask value is the logical OR of any of the following:
//! - \b RAM_SECTOR0
//! - \b RAM_SECTOR1
//! - \b RAM_SECTOR2
//! - \b RAM_SECTOR3
//! - \b RAM_SECTOR4
//! - \b RAM_SECTOR5
//! - \b RAM_SECTOR6
//! - \b RAM_SECTOR7
//!
//! Modified bits of \b RCCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void RAM_setSectorOff(uint8_t sector);
//*****************************************************************************
//
//! \brief Get RAM sector ON/OFF status
//!
//! \param sector is specified sector
//! Mask value is the logical OR of any of the following:
//! - \b RAM_SECTOR0
//! - \b RAM_SECTOR1
//! - \b RAM_SECTOR2
//! - \b RAM_SECTOR3
//! - \b RAM_SECTOR4
//! - \b RAM_SECTOR5
//! - \b RAM_SECTOR6
//! - \b RAM_SECTOR7
//!
//! Modified bits of \b RCCTL0 register.
//!
//! \return Logical OR of any of the following:
//! - \b RAM_SECTOR0
//! - \b RAM_SECTOR1
//! - \b RAM_SECTOR2
//! - \b RAM_SECTOR3
//! - \b RAM_SECTOR4
//! - \b RAM_SECTOR5
//! - \b RAM_SECTOR6
//! - \b RAM_SECTOR7
//! \n indicating the status of the masked sectors
//
//*****************************************************************************
extern uint8_t RAM_getSectorState(uint8_t sector);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_RAM_H__

View File

@@ -0,0 +1,93 @@
//*****************************************************************************
//
// ref.c - Driver for the ref Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup ref_api ref
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_REF__
#include "ref.h"
#include <assert.h>
void Ref_setReferenceVoltage (uint16_t baseAddress,
uint8_t referenceVoltageSelect)
{
HWREG8(baseAddress + OFS_REFCTL0_L) &= ~(REFVSEL_3);
HWREG8(baseAddress + OFS_REFCTL0_L) |= referenceVoltageSelect;
}
void Ref_disableTempSensor (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_REFCTL0_L) |= REFTCOFF;
}
void Ref_enableTempSensor (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_REFCTL0_L) &= ~(REFTCOFF);
}
void Ref_enableReferenceVoltageOutput (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_REFCTL0_L) |= REFOUT;
}
void Ref_disableReferenceVoltageOutput (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_REFCTL0_L) &= ~(REFOUT);
}
void Ref_enableReferenceVoltage (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_REFCTL0_L) |= REFON;
}
void Ref_disableReferenceVoltage (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_REFCTL0_L) &= ~(REFON);
}
uint16_t Ref_getBandgapMode (uint16_t baseAddress)
{
return (HWREG16((baseAddress) + OFS_REFCTL0) & BGMODE);
}
bool Ref_isBandgapActive (uint16_t baseAddress)
{
if (HWREG16((baseAddress) + OFS_REFCTL0) & REFBGACT){
return (REF_ACTIVE) ;
} else {
return (REF_INACTIVE) ;
}
}
uint16_t Ref_isRefGenBusy (uint16_t baseAddress)
{
return (HWREG16((baseAddress) + OFS_REFCTL0) & REFGENBUSY);
}
bool Ref_isRefGenActive (uint16_t baseAddress)
{
if (HWREG16((baseAddress) + OFS_REFCTL0) & REFGENACT){
return (REF_ACTIVE) ;
} else {
return (REF_INACTIVE) ;
}
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for ref_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,299 @@
//*****************************************************************************
//
// ref.h - Driver for the REF Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_REF_H__
#define __MSP430WARE_REF_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_REF__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the referenceVoltageSelect
// parameter for functions: Ref_setReferenceVoltage().
//
//*****************************************************************************
#define REF_VREF1_5V (REFVSEL_0)
#define REF_VREF2_0V (REFVSEL_1)
#define REF_VREF2_5V (REFVSEL_2)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the Ref_isBandgapActive() function and the
// Ref_isRefGenActive() function.
//
//*****************************************************************************
#define REF_ACTIVE true
#define REF_INACTIVE false
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the Ref_getBandgapMode() function.
//
//*****************************************************************************
#define REF_STATICMODE 0x00
#define REF_SAMPLEMODE BGMODE
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the Ref_isRefGenBusy() function.
//
//*****************************************************************************
#define REF_NOTBUSY 0x00
#define REF_BUSY REFGENBUSY
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Sets the reference voltage for the voltage generator.
//!
//! This function sets the reference voltage generated by the voltage generator
//! to be used by other peripherals. This reference voltage will only be valid
//! while the Ref module is in control. Please note, if the Ref_isRefGenBusy()
//! returns Ref_BUSY, this function will have no effect.
//!
//! \param baseAddress is the base address of the REF module.
//! \param referenceVoltageSelect is the desired voltage to generate for a
//! reference voltage.
//! Valid values are:
//! - \b REF_VREF1_5V [Default]
//! - \b REF_VREF2_0V
//! - \b REF_VREF2_5V
//! \n Modified bits are \b REFVSEL of \b REFCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void Ref_setReferenceVoltage(uint16_t baseAddress,
uint8_t referenceVoltageSelect);
//*****************************************************************************
//
//! \brief Disables the internal temperature sensor to save power consumption.
//!
//! This function is used to turn off the internal temperature sensor to save
//! on power consumption. The temperature sensor is enabled by default. Please
//! note, that giving ADC12 module control over the Ref module, the state of
//! the temperature sensor is dependent on the controls of the ADC12 module.
//! Please note, if the Ref_isRefGenBusy() returns Ref_BUSY, this function will
//! have no effect.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! Modified bits are \b REFTCOFF of \b REFCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void Ref_disableTempSensor(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables the internal temperature sensor.
//!
//! This function is used to turn on the internal temperature sensor to use by
//! other peripherals. The temperature sensor is enabled by default. Please
//! note, if the Ref_isRefGenBusy() returns Ref_BUSY, this function will have
//! no effect.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! Modified bits are \b REFTCOFF of \b REFCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void Ref_enableTempSensor(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Outputs the reference voltage to an output pin.
//!
//! This function is used to output the reference voltage being generated to an
//! output pin. Please note, the output pin is device specific. Please note,
//! that giving ADC12 module control over the Ref module, the state of the
//! reference voltage as an output to a pin is dependent on the controls of the
//! ADC12 module. If ADC12_A reference burst is disabled or DAC12_A is enabled,
//! this output is available continuously. If ADC12_A reference burst is
//! enabled, this output is available only during an ADC12_A conversion. For
//! devices with CTSD16, Ref_enableReferenceVoltage() needs to be invoked to
//! get VREFBG available continuously. Otherwise, VREFBG is only available
//! externally when a module requests it. Please note, if the
//! Ref_isRefGenBusy() returns Ref_BUSY, this function will have no effect.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! Modified bits are \b REFOUT of \b REFCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void Ref_enableReferenceVoltageOutput(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the reference voltage as an output to a pin.
//!
//! This function is used to disables the reference voltage being generated to
//! be given to an output pin. Please note, if the Ref_isRefGenBusy() returns
//! Ref_BUSY, this function will have no effect.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! Modified bits are \b REFOUT of \b REFCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void Ref_disableReferenceVoltageOutput(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables the reference voltage to be used by peripherals.
//!
//! This function is used to enable the generated reference voltage to be used
//! other peripherals or by an output pin, if enabled. Please note, that giving
//! ADC12 module control over the Ref module, the state of the reference
//! voltage is dependent on the controls of the ADC12 module. Please note,
//! ADC10_A does not support the reference request. If the Ref_isRefGenBusy()
//! returns Ref_BUSY, this function will have no effect.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! Modified bits are \b REFON of \b REFCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void Ref_enableReferenceVoltage(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the reference voltage.
//!
//! This function is used to disable the generated reference voltage. Please
//! note, if the Ref_isRefGenBusy() returns Ref_BUSY, this function will have
//! no effect.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! Modified bits are \b REFON of \b REFCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void Ref_disableReferenceVoltage(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the bandgap mode of the Ref module.
//!
//! This function is used to return the bandgap mode of the Ref module,
//! requested by the peripherals using the bandgap. If a peripheral requests
//! static mode, then the bandgap mode will be static for all modules, whereas
//! if all of the peripherals using the bandgap request sample mode, then that
//! will be the mode returned. Sample mode allows the bandgap to be active only
//! when necessary to save on power consumption, static mode requires the
//! bandgap to be active until no peripherals are using it anymore.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! \return One of the following:
//! - \b REF_STATICMODE if the bandgap is operating in static mode
//! - \b REF_SAMPLEMODE if the bandgap is operating in sample mode
//! \n indicating the bandgap mode of the module
//
//*****************************************************************************
extern uint16_t Ref_getBandgapMode(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the active status of the bandgap in the Ref module.
//!
//! This function is used to return the active status of the bandgap in the Ref
//! module. If the bandgap is in use by a peripheral, then the status will be
//! seen as active.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! \return One of the following:
//! - \b REF_ACTIVE if active
//! - \b REF_INACTIVE if not active
//! \n indicating the bandgap active status of the module
//
//*****************************************************************************
extern bool Ref_isBandgapActive(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the busy status of the reference generator in the Ref
//! module.
//!
//! This function is used to return the busy status of the reference generator
//! in the Ref module. If the ref generator is in use by a peripheral, then the
//! status will be seen as busy.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! \return One of the following:
//! - \b REF_NOTBUSY if the reference generator is not being used
//! - \b REF_BUSY if the reference generator is being used, disallowing
//! changes to be made to the Ref module controls
//! \n indicating the reference generator busy status of the module
//
//*****************************************************************************
extern uint16_t Ref_isRefGenBusy(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the active status of the reference generator in the Ref
//! module.
//!
//! This function is used to return the active status of the reference
//! generator in the Ref module. If the ref generator is on and ready to use,
//! then the status will be seen as active.
//!
//! \param baseAddress is the base address of the REF module.
//!
//! \return One of the following:
//! - \b REF_ACTIVE if active
//! - \b REF_INACTIVE if not active
//! \n indicating the reference generator active status of the module
//
//*****************************************************************************
extern bool Ref_isRefGenActive(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_REF_H__

View File

@@ -0,0 +1,278 @@
//*****************************************************************************
//
// rtc_a.c - Driver for the rtc_a Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup rtc_a_api rtc_a
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_RTC__
#include "rtc_a.h"
#include <assert.h>
void RTC_A_startClock (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_RTCCTL01_H) &= ~(RTCHOLD_H);
}
void RTC_A_holdClock (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_RTCCTL01_H) |= RTCHOLD_H;
}
void RTC_A_setCalibrationFrequency (uint16_t baseAddress,
uint16_t frequencySelect)
{
HWREG16(baseAddress + OFS_RTCCTL23) &= ~(RTCCALF_3);
HWREG16(baseAddress + OFS_RTCCTL23) |= frequencySelect;
}
void RTC_A_setCalibrationData (uint16_t baseAddress,
uint8_t offsetDirection,
uint8_t offsetValue)
{
HWREG8(baseAddress + OFS_RTCCTL23_L) = offsetValue + offsetDirection;
}
void RTC_A_initCounter (uint16_t baseAddress,
uint16_t clockSelect,
uint16_t counterSizeSelect)
{
HWREG8(baseAddress + OFS_RTCCTL01_H) |= RTCHOLD_H;
HWREG8(baseAddress + OFS_RTCCTL01_H) &= ~(RTCMODE_H);
HWREG16(baseAddress + OFS_RTCCTL01) &= 0xF0FF; //~(RTCSSEL_3 + RTCTEV_3);
HWREG16(baseAddress + OFS_RTCCTL01) |= clockSelect + counterSizeSelect;
}
void RTC_A_initCalendar (uint16_t baseAddress,
Calendar *CalendarTime,
uint16_t formatSelect)
{
HWREG8(baseAddress + OFS_RTCCTL01_H) |= RTCMODE_H + RTCHOLD_H;
HWREG16(baseAddress + OFS_RTCCTL01) &= ~(RTCBCD);
HWREG16(baseAddress + OFS_RTCCTL01) |= formatSelect;
HWREG8(baseAddress + OFS_RTCTIM0_L) = CalendarTime->Seconds;
HWREG8(baseAddress + OFS_RTCTIM0_H) = CalendarTime->Minutes;
HWREG8(baseAddress + OFS_RTCTIM1_L) = CalendarTime->Hours;
HWREG8(baseAddress + OFS_RTCTIM1_H) = CalendarTime->DayOfWeek;
HWREG8(baseAddress + OFS_RTCDATE_L) = CalendarTime->DayOfMonth;
HWREG8(baseAddress + OFS_RTCDATE_H) = CalendarTime->Month;
HWREG16(baseAddress + OFS_RTCYEAR) = CalendarTime->Year;
}
Calendar RTC_A_getCalendarTime (uint16_t baseAddress)
{
Calendar tempCal;
while ( !(HWREG16(baseAddress + OFS_RTCCTL01) & RTCRDY) ) ;
tempCal.Seconds = HWREG8(baseAddress + OFS_RTCTIM0_L);
tempCal.Minutes = HWREG8(baseAddress + OFS_RTCTIM0_H);
tempCal.Hours = HWREG8(baseAddress + OFS_RTCTIM1_L);
tempCal.DayOfWeek = HWREG8(baseAddress + OFS_RTCTIM1_H);
tempCal.DayOfMonth = HWREG8(baseAddress + OFS_RTCDATE_L);
tempCal.Month = HWREG8(baseAddress + OFS_RTCDATE_H);
tempCal.Year = HWREG16(baseAddress + OFS_RTCYEAR);
return ( tempCal) ;
}
void RTC_A_configureCalendarAlarm(uint16_t baseAddress,
RTC_A_configureCalendarAlarmParam *param)
{
//Each of these is XORed with 0x80 to turn on if an integer is passed,
//or turn OFF if RTC_A_ALARM_OFF (0x80) is passed.
HWREG8(baseAddress + OFS_RTCAMINHR_L) = (param->minutesAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCAMINHR_H) = (param->hoursAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCADOWDAY_L) = (param->dayOfWeekAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCADOWDAY_H) = (param->dayOfMonthAlarm ^ 0x80);
}
void RTC_A_setCalendarEvent (uint16_t baseAddress,
uint16_t eventSelect)
{
HWREG16(baseAddress + OFS_RTCCTL01) &= ~(RTCTEV_3); //Reset bits
HWREG16(baseAddress + OFS_RTCCTL01) |= eventSelect;
}
uint32_t RTC_A_getCounterValue (uint16_t baseAddress)
{
if ( (HWREG8(baseAddress + OFS_RTCCTL01_H) & RTCHOLD_H)
|| (HWREG8(baseAddress + OFS_RTCPS1CTL) & RT1PSHOLD) ){
return ( 0) ;
}
uint32_t counterValue_L = HWREG16(baseAddress + OFS_RTCTIM0);
uint32_t counterValue_H = HWREG16(baseAddress + OFS_RTCTIM1);
return ( (counterValue_H << 16) + counterValue_L );
}
void RTC_A_setCounterValue (uint16_t baseAddress,
uint32_t counterValue)
{
HWREG16(baseAddress + OFS_RTCTIM0) = counterValue;
HWREG16(baseAddress + OFS_RTCTIM1) = ( counterValue >> 16 );
}
void RTC_A_initCounterPrescale (uint16_t baseAddress,
uint8_t prescaleSelect,
uint16_t prescaleClockSelect,
uint16_t prescaleDivider)
{
//Reset bits and set clock select
HWREG16(baseAddress + OFS_RTCPS0CTL + prescaleSelect) =
prescaleClockSelect + prescaleDivider;
}
void RTC_A_holdCounterPrescale (uint16_t baseAddress,
uint8_t prescaleSelect)
{
HWREG8(baseAddress + OFS_RTCPS0CTL_H + prescaleSelect) |= RT0PSHOLD_H;
}
void RTC_A_startCounterPrescale (uint16_t baseAddress,
uint8_t prescaleSelect)
{
HWREG8(baseAddress + OFS_RTCPS0CTL_H + prescaleSelect) &= ~(RT0PSHOLD_H);
}
void RTC_A_definePrescaleEvent (uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleEventDivider)
{
HWREG8(baseAddress + OFS_RTCPS0CTL_L + prescaleSelect) &= ~(RT0IP_7);
HWREG8(baseAddress + OFS_RTCPS0CTL_L +
prescaleSelect) |= prescaleEventDivider;
}
uint8_t RTC_A_getPrescaleValue (uint16_t baseAddress,
uint8_t prescaleSelect)
{
if (HWREG8(baseAddress + OFS_RTCPS0CTL_H + prescaleSelect) & RT0PSHOLD_H){
return ( 0) ;
}
if (RTC_A_PRESCALE_0 == prescaleSelect){
return ( HWREG8(baseAddress + OFS_RTCPS_L) );
} else if (RTC_A_PRESCALE_1 == prescaleSelect){
return ( HWREG8(baseAddress + OFS_RTCPS_H) );
} else {
return ( 0) ;
}
}
void RTC_A_setPrescaleValue (uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleCounterValue)
{
if (RTC_A_PRESCALE_0 == prescaleSelect){
HWREG8(baseAddress + OFS_RTCPS_L) = prescaleCounterValue;
} else if (RTC_A_PRESCALE_1 == prescaleSelect){
HWREG8(baseAddress + OFS_RTCPS_H) = prescaleCounterValue;
}
}
void RTC_A_enableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
if ( interruptMask & (RTCTEVIE + RTCAIE + RTCRDYIE) ){
HWREG8(baseAddress + OFS_RTCCTL01_L) |=
(interruptMask & (RTCTEVIE + RTCAIE + RTCRDYIE));
}
if (interruptMask & RTC_A_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL) |= RT0PSIE;
}
if (interruptMask & RTC_A_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL) |= RT1PSIE;
}
}
void RTC_A_disableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
if ( interruptMask & ( RTCTEVIE + RTCAIE + RTCRDYIE) ){
HWREG8(baseAddress + OFS_RTCCTL01_L) &=
~(interruptMask & (RTCTEVIE + RTCAIE + RTCRDYIE));
}
if (interruptMask & RTC_A_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL) &= ~(RT0PSIE);
}
if (interruptMask & RTC_A_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL) &= ~(RT1PSIE);
}
}
uint8_t RTC_A_getInterruptStatus (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
uint8_t tempInterruptFlagMask = 0x0000;
tempInterruptFlagMask |= (HWREG8(baseAddress + OFS_RTCCTL01_L)
& ((interruptFlagMask >> 4)
& (
RTCTEVIFG +
RTCAIFG +
RTCRDYIFG)));
tempInterruptFlagMask = tempInterruptFlagMask << 4;
if (interruptFlagMask & RTC_A_PRESCALE_TIMER0_INTERRUPT){
if ( HWREG8(baseAddress + OFS_RTCPS0CTL) & RT0PSIFG){
tempInterruptFlagMask |= RTC_A_PRESCALE_TIMER0_INTERRUPT;
}
}
if (interruptFlagMask & RTC_A_PRESCALE_TIMER1_INTERRUPT){
if ( HWREG8(baseAddress + OFS_RTCPS1CTL) & RT1PSIFG){
tempInterruptFlagMask |= RTC_A_PRESCALE_TIMER1_INTERRUPT;
}
}
return ( tempInterruptFlagMask) ;
}
void RTC_A_clearInterrupt (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
if ( interruptFlagMask & (RTC_A_TIME_EVENT_INTERRUPT +
RTC_A_CLOCK_ALARM_INTERRUPT +
RTC_A_CLOCK_READ_READY_INTERRUPT
) ){
HWREG8(baseAddress + OFS_RTCCTL01_L) &=
~((interruptFlagMask>>4) & (RTCTEVIFG +
RTCAIFG +
RTCRDYIFG));
}
if (interruptFlagMask & RTC_A_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL) &= ~(RT0PSIFG);
}
if (interruptFlagMask & RTC_A_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL) &= ~(RT1PSIFG);
}
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for rtc_a_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,748 @@
//*****************************************************************************
//
// rtc_a.h - Driver for the RTC_A Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_RTC_A_H__
#define __MSP430WARE_RTC_A_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_RTC__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the RTC_A_configureCalendarAlarm() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct RTC_A_configureCalendarAlarmParam {
//! Is the alarm condition for the minutes.
//! \n Valid values are:
//! - \b RTC_A_ALARMCONDITION_OFF [Default]
uint8_t minutesAlarm;
//! Is the alarm condition for the hours.
//! \n Valid values are:
//! - \b RTC_A_ALARMCONDITION_OFF [Default]
uint8_t hoursAlarm;
//! Is the alarm condition for the day of week.
//! \n Valid values are:
//! - \b RTC_A_ALARMCONDITION_OFF [Default]
uint8_t dayOfWeekAlarm;
//! Is the alarm condition for the day of the month.
//! \n Valid values are:
//! - \b RTC_A_ALARMCONDITION_OFF [Default]
uint8_t dayOfMonthAlarm;
} RTC_A_configureCalendarAlarmParam;
//*****************************************************************************
//
//! \brief Used in the RTC_A_initCalendar() function as the CalendarTime
//! parameter.
//
//*****************************************************************************
typedef struct Calendar {
//! Seconds of minute between 0-59
uint8_t Seconds;
//! Minutes of hour between 0-59
uint8_t Minutes;
//! Hour of day between 0-23
uint8_t Hours;
//! Day of week between 0-6
uint8_t DayOfWeek;
//! Day of month between 1-31
uint8_t DayOfMonth;
//! Month between 1-12
uint8_t Month;
//! Year between 0-4095
uint16_t Year;
} Calendar;
//*****************************************************************************
//
// The following are values that can be passed to the frequencySelect parameter
// for functions: RTC_A_setCalibrationFrequency().
//
//*****************************************************************************
#define RTC_A_CALIBRATIONFREQ_OFF (RTCCALF_0)
#define RTC_A_CALIBRATIONFREQ_512HZ (RTCCALF_1)
#define RTC_A_CALIBRATIONFREQ_256HZ (RTCCALF_2)
#define RTC_A_CALIBRATIONFREQ_1HZ (RTCCALF_3)
//*****************************************************************************
//
// The following are values that can be passed to the offsetDirection parameter
// for functions: RTC_A_setCalibrationData().
//
//*****************************************************************************
#define RTC_A_CALIBRATION_DOWN2PPM (!(RTCCALS))
#define RTC_A_CALIBRATION_UP4PPM (RTCCALS)
//*****************************************************************************
//
// The following are values that can be passed to the formatSelect parameter
// for functions: RTC_A_initCalendar().
//
//*****************************************************************************
#define RTC_A_FORMAT_BINARY (!(RTCBCD))
#define RTC_A_FORMAT_BCD (RTCBCD)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: RTC_A_configureCalendarAlarm(), RTC_A_configureCalendarAlarm(),
// RTC_A_configureCalendarAlarm(), and RTC_A_configureCalendarAlarm().
//
//*****************************************************************************
#define RTC_A_ALARMCONDITION_OFF (0x80)
//*****************************************************************************
//
// The following are values that can be passed to the eventSelect parameter for
// functions: RTC_A_setCalendarEvent().
//
//*****************************************************************************
#define RTC_A_CALENDAREVENT_MINUTECHANGE (RTCTEV_0)
#define RTC_A_CALENDAREVENT_HOURCHANGE (RTCTEV_1)
#define RTC_A_CALENDAREVENT_NOON (RTCTEV_2)
#define RTC_A_CALENDAREVENT_MIDNIGHT (RTCTEV_3)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleSelect parameter
// for functions: RTC_A_initCounterPrescale(), RTC_A_holdCounterPrescale(),
// RTC_A_startCounterPrescale(), RTC_A_definePrescaleEvent(),
// RTC_A_getPrescaleValue(), and RTC_A_setPrescaleValue().
//
//*****************************************************************************
#define RTC_A_PRESCALE_0 (0x0)
#define RTC_A_PRESCALE_1 (0x2)
//*****************************************************************************
//
// The following are values that can be passed to the clockSelect parameter for
// functions: RTC_A_initCounter().
//
//*****************************************************************************
#define RTC_A_CLOCKSELECT_ACLK (RTCSSEL_0)
#define RTC_A_CLOCKSELECT_SMCLK (RTCSSEL_1)
#define RTC_A_CLOCKSELECT_RT1PS (RTCSSEL_2)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleClockSelect
// parameter for functions: RTC_A_initCounterPrescale().
//
//*****************************************************************************
#define RTC_A_PSCLOCKSELECT_ACLK (RT1SSEL_0)
#define RTC_A_PSCLOCKSELECT_SMCLK (RT1SSEL_1)
#define RTC_A_PSCLOCKSELECT_RT0PS (RT1SSEL_2)
//*****************************************************************************
//
// The following are values that can be passed to the counterSizeSelect
// parameter for functions: RTC_A_initCounter().
//
//*****************************************************************************
#define RTC_A_COUNTERSIZE_8BIT (RTCTEV_0)
#define RTC_A_COUNTERSIZE_16BIT (RTCTEV_1)
#define RTC_A_COUNTERSIZE_24BIT (RTCTEV_2)
#define RTC_A_COUNTERSIZE_32BIT (RTCTEV_3)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleDivider parameter
// for functions: RTC_A_initCounterPrescale().
//
//*****************************************************************************
#define RTC_A_PSDIVIDER_2 (RT0PSDIV_0)
#define RTC_A_PSDIVIDER_4 (RT0PSDIV_1)
#define RTC_A_PSDIVIDER_8 (RT0PSDIV_2)
#define RTC_A_PSDIVIDER_16 (RT0PSDIV_3)
#define RTC_A_PSDIVIDER_32 (RT0PSDIV_4)
#define RTC_A_PSDIVIDER_64 (RT0PSDIV_5)
#define RTC_A_PSDIVIDER_128 (RT0PSDIV_6)
#define RTC_A_PSDIVIDER_256 (RT0PSDIV_7)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleEventDivider
// parameter for functions: RTC_A_definePrescaleEvent().
//
//*****************************************************************************
#define RTC_A_PSEVENTDIVIDER_2 (RT0IP_0)
#define RTC_A_PSEVENTDIVIDER_4 (RT0IP_1)
#define RTC_A_PSEVENTDIVIDER_8 (RT0IP_2)
#define RTC_A_PSEVENTDIVIDER_16 (RT0IP_3)
#define RTC_A_PSEVENTDIVIDER_32 (RT0IP_4)
#define RTC_A_PSEVENTDIVIDER_64 (RT0IP_5)
#define RTC_A_PSEVENTDIVIDER_128 (RT0IP_6)
#define RTC_A_PSEVENTDIVIDER_256 (RT0IP_7)
//*****************************************************************************
//
// The following are values that can be passed to the interruptMask parameter
// for functions: RTC_A_enableInterrupt(), and RTC_A_disableInterrupt(); the
// interruptFlagMask parameter for functions: RTC_A_getInterruptStatus(), and
// RTC_A_clearInterrupt() as well as returned by the RTC_A_getInterruptStatus()
// function.
//
//*****************************************************************************
#define RTC_A_TIME_EVENT_INTERRUPT RTCTEVIE
#define RTC_A_CLOCK_ALARM_INTERRUPT RTCAIE
#define RTC_A_CLOCK_READ_READY_INTERRUPT RTCRDYIE
#define RTC_A_PRESCALE_TIMER0_INTERRUPT 0x02
#define RTC_A_PRESCALE_TIMER1_INTERRUPT 0x01
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Starts the RTC.
//!
//! This function clears the RTC main hold bit to allow the RTC to function.
//!
//! \param baseAddress is the base address of the RTC_A module.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_startClock(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Holds the RTC.
//!
//! This function sets the RTC main hold bit to disable RTC functionality.
//!
//! \param baseAddress is the base address of the RTC_A module.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_holdClock(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Allows and Sets the frequency output to RTCCLK pin for calibration
//! measurement.
//!
//! This function sets a frequency to measure at the RTCCLK output pin. After
//! testing the set frequency, the calibration could be set accordingly.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param frequencySelect is the frequency output to RTCCLK.
//! Valid values are:
//! - \b RTC_A_CALIBRATIONFREQ_OFF [Default] - turn off calibration
//! output
//! - \b RTC_A_CALIBRATIONFREQ_512HZ - output signal at 512Hz for
//! calibration
//! - \b RTC_A_CALIBRATIONFREQ_256HZ - output signal at 256Hz for
//! calibration
//! - \b RTC_A_CALIBRATIONFREQ_1HZ - output signal at 1Hz for
//! calibration
//! \n Modified bits are \b RTCCALF of \b RTCCTL3 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_setCalibrationFrequency(uint16_t baseAddress,
uint16_t frequencySelect);
//*****************************************************************************
//
//! \brief Sets the specified calibration for the RTC.
//!
//! This function sets the calibration offset to make the RTC as accurate as
//! possible. The offsetDirection can be either +4-ppm or -2-ppm, and the
//! offsetValue should be from 1-63 and is multiplied by the direction setting
//! (i.e. +4-ppm * 8 (offsetValue) = +32-ppm). Please note, when measuring the
//! frequency after setting the calibration, you will only see a change on the
//! 1Hz frequency.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param offsetDirection is the direction that the calibration offset will
//! go.
//! Valid values are:
//! - \b RTC_A_CALIBRATION_DOWN2PPM - calibrate at steps of -2
//! - \b RTC_A_CALIBRATION_UP4PPM - calibrate at steps of +4
//! \n Modified bits are \b RTCCALS of \b RTCCTL2 register.
//! \param offsetValue is the value that the offset will be a factor of; a
//! valid value is any integer from 1-63.
//! \n Modified bits are \b RTCCAL of \b RTCCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_setCalibrationData(uint16_t baseAddress,
uint8_t offsetDirection,
uint8_t offsetValue);
//*****************************************************************************
//
//! \brief Initializes the settings to operate the RTC in Counter mode.
//!
//! This function initializes the Counter mode of the RTC_A. Setting the clock
//! source and counter size will allow an interrupt from the RTCTEVIFG once an
//! overflow to the counter register occurs.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param clockSelect is the selected clock for the counter mode to use.
//! Valid values are:
//! - \b RTC_A_CLOCKSELECT_ACLK [Default]
//! - \b RTC_A_CLOCKSELECT_SMCLK
//! - \b RTC_A_CLOCKSELECT_RT1PS - use Prescaler 1 as source to RTC
//! \n Modified bits are \b RTCSSEL of \b RTCCTL1 register.
//! \param counterSizeSelect is the size of the counter.
//! Valid values are:
//! - \b RTC_A_COUNTERSIZE_8BIT [Default]
//! - \b RTC_A_COUNTERSIZE_16BIT
//! - \b RTC_A_COUNTERSIZE_24BIT
//! - \b RTC_A_COUNTERSIZE_32BIT
//! \n Modified bits are \b RTCTEV of \b RTCCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_initCounter(uint16_t baseAddress,
uint16_t clockSelect,
uint16_t counterSizeSelect);
//*****************************************************************************
//
//! \brief Initializes the settings to operate the RTC in calendar mode
//!
//! This function initializes the Calendar mode of the RTC module. To prevent
//! potential erroneous alarm conditions from occurring, the alarm should be
//! disabled by clearing the RTCAIE, RTCAIFG and AE bits with APIs:
//! RTC_A_disableInterrupt(), RTC_A_clearInterrupt() and
//! RTC_A_configureCalendarAlarm() before calendar initialization.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param CalendarTime is the pointer to the structure containing the values
//! for the Calendar to be initialized to. Valid values should be of
//! type pointer to Calendar and should contain the following members
//! and corresponding values: \n\b Seconds between 0-59 \n\b Minutes
//! between 0-59 \n\b Hours between 0-23 \n\b DayOfWeek between 0-6 \n\b
//! DayOfMonth between 1-31 \n\b Month between 1-12 \n\b Year between
//! 0-4095 \n\b NOTE: Values beyond the ones specified may result in
//! erratic behavior.
//! \param formatSelect is the format for the Calendar registers to use.
//! Valid values are:
//! - \b RTC_A_FORMAT_BINARY [Default]
//! - \b RTC_A_FORMAT_BCD
//! \n Modified bits are \b RTCBCD of \b RTCCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_initCalendar(uint16_t baseAddress,
Calendar *CalendarTime,
uint16_t formatSelect);
//*****************************************************************************
//
//! \brief Returns the Calendar Time stored in the Calendar registers of the
//! RTC.
//!
//! This function returns the current Calendar time in the form of a Calendar
//! structure. The RTCRDY polling is used in this function to prevent reading
//! invalid time.
//!
//! \param baseAddress is the base address of the RTC_A module.
//!
//! \return A Calendar structure containing the current time.
//
//*****************************************************************************
extern Calendar RTC_A_getCalendarTime(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets and Enables the desired Calendar Alarm settings.
//!
//! This function sets a Calendar interrupt condition to assert the RTCAIFG
//! interrupt flag. The condition is a logical and of all of the parameters.
//! For example if the minutes and hours alarm is set, then the interrupt will
//! only assert when the minutes AND the hours change to the specified setting.
//! Use the RTC_A_ALARM_OFF for any alarm settings that should not be apart of
//! the alarm condition.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param param is the pointer to struct for calendar alarm configuration.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_configureCalendarAlarm(uint16_t baseAddress,
RTC_A_configureCalendarAlarmParam *param);
//*****************************************************************************
//
//! \brief Sets a single specified Calendar interrupt condition
//!
//! This function sets a specified event to assert the RTCTEVIFG interrupt.
//! This interrupt is independent from the Calendar alarm interrupt.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param eventSelect is the condition selected.
//! Valid values are:
//! - \b RTC_A_CALENDAREVENT_MINUTECHANGE - assert interrupt on every
//! minute
//! - \b RTC_A_CALENDAREVENT_HOURCHANGE - assert interrupt on every hour
//! - \b RTC_A_CALENDAREVENT_NOON - assert interrupt when hour is 12
//! - \b RTC_A_CALENDAREVENT_MIDNIGHT - assert interrupt when hour is 0
//! \n Modified bits are \b RTCTEV of \b RTCCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_setCalendarEvent(uint16_t baseAddress,
uint16_t eventSelect);
//*****************************************************************************
//
//! \brief Returns the value of the Counter register.
//!
//! This function returns the value of the counter register for the RTC_A
//! module. It will return the 32-bit value no matter the size set during
//! initialization. The RTC should be held before trying to use this function.
//!
//! \param baseAddress is the base address of the RTC_A module.
//!
//! \return The raw value of the full 32-bit Counter Register.
//
//*****************************************************************************
extern uint32_t RTC_A_getCounterValue(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets the value of the Counter register
//!
//! This function sets the counter register of the RTC_A module.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param counterValue is the value to set the Counter register to; a valid
//! value may be any 32-bit integer.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_setCounterValue(uint16_t baseAddress,
uint32_t counterValue);
//*****************************************************************************
//
//! \brief Initializes the Prescaler for Counter mode.
//!
//! This function initializes the selected prescaler for the counter mode in
//! the RTC_A module. If the RTC is initialized in Calendar mode, then these
//! are automatically initialized. The Prescalers can be used to divide a clock
//! source additionally before it gets to the main RTC clock.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param prescaleSelect is the prescaler to initialize.
//! Valid values are:
//! - \b RTC_A_PRESCALE_0
//! - \b RTC_A_PRESCALE_1
//! \param prescaleClockSelect is the clock to drive the selected prescaler.
//! Valid values are:
//! - \b RTC_A_PSCLOCKSELECT_ACLK
//! - \b RTC_A_PSCLOCKSELECT_SMCLK
//! - \b RTC_A_PSCLOCKSELECT_RT0PS - use Prescaler 0 as source to
//! Prescaler 1 (May only be used if prescaleSelect is
//! RTC_A_PRESCALE_1)
//! \n Modified bits are \b RTxSSEL of \b RTCPSxCTL register.
//! \param prescaleDivider is the divider for the selected clock source.
//! Valid values are:
//! - \b RTC_A_PSDIVIDER_2 [Default]
//! - \b RTC_A_PSDIVIDER_4
//! - \b RTC_A_PSDIVIDER_8
//! - \b RTC_A_PSDIVIDER_16
//! - \b RTC_A_PSDIVIDER_32
//! - \b RTC_A_PSDIVIDER_64
//! - \b RTC_A_PSDIVIDER_128
//! - \b RTC_A_PSDIVIDER_256
//! \n Modified bits are \b RTxPSDIV of \b RTCPSxCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_initCounterPrescale(uint16_t baseAddress,
uint8_t prescaleSelect,
uint16_t prescaleClockSelect,
uint16_t prescaleDivider);
//*****************************************************************************
//
//! \brief Holds the selected Prescaler.
//!
//! This function holds the prescale counter from continuing. This will only
//! work in counter mode, in Calendar mode, the RTC_A_holdClock() must be used.
//! In counter mode, if using both prescalers in conjunction with the main RTC
//! counter, then stopping RT0PS will stop RT1PS, but stopping RT1PS will not
//! stop RT0PS.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param prescaleSelect is the prescaler to hold.
//! Valid values are:
//! - \b RTC_A_PRESCALE_0
//! - \b RTC_A_PRESCALE_1
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_holdCounterPrescale(uint16_t baseAddress,
uint8_t prescaleSelect);
//*****************************************************************************
//
//! \brief Starts the selected Prescaler.
//!
//! This function starts the selected prescale counter. This function will only
//! work if the RTC is in counter mode.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param prescaleSelect is the prescaler to start.
//! Valid values are:
//! - \b RTC_A_PRESCALE_0
//! - \b RTC_A_PRESCALE_1
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_startCounterPrescale(uint16_t baseAddress,
uint8_t prescaleSelect);
//*****************************************************************************
//
//! \brief Sets up an interrupt condition for the selected Prescaler.
//!
//! This function sets the condition for an interrupt to assert based on the
//! individual prescalers.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param prescaleSelect is the prescaler to define an interrupt for.
//! Valid values are:
//! - \b RTC_A_PRESCALE_0
//! - \b RTC_A_PRESCALE_1
//! \param prescaleEventDivider is a divider to specify when an interrupt can
//! occur based on the clock source of the selected prescaler. (Does not
//! affect timer of the selected prescaler).
//! Valid values are:
//! - \b RTC_A_PSEVENTDIVIDER_2 [Default]
//! - \b RTC_A_PSEVENTDIVIDER_4
//! - \b RTC_A_PSEVENTDIVIDER_8
//! - \b RTC_A_PSEVENTDIVIDER_16
//! - \b RTC_A_PSEVENTDIVIDER_32
//! - \b RTC_A_PSEVENTDIVIDER_64
//! - \b RTC_A_PSEVENTDIVIDER_128
//! - \b RTC_A_PSEVENTDIVIDER_256
//! \n Modified bits are \b RTxIP of \b RTCPSxCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_definePrescaleEvent(uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleEventDivider);
//*****************************************************************************
//
//! \brief Returns the selected prescaler value.
//!
//! This function returns the value of the selected prescale counter register.
//! Note that the counter value should be held by calling RTC_A_holdClock()
//! before calling this API.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param prescaleSelect is the prescaler to obtain the value of.
//! Valid values are:
//! - \b RTC_A_PRESCALE_0
//! - \b RTC_A_PRESCALE_1
//!
//! \return The value of the specified prescaler count register
//
//*****************************************************************************
extern uint8_t RTC_A_getPrescaleValue(uint16_t baseAddress,
uint8_t prescaleSelect);
//*****************************************************************************
//
//! \brief Sets the selected prescaler value.
//!
//! This function sets the prescale counter value. Before setting the prescale
//! counter, it should be held by calling RTC_A_holdClock().
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param prescaleSelect is the prescaler to set the value for.
//! Valid values are:
//! - \b RTC_A_PRESCALE_0
//! - \b RTC_A_PRESCALE_1
//! \param prescaleCounterValue is the specified value to set the prescaler to.
//! Valid values are any integer between 0-255
//! \n Modified bits are \b RTxPS of \b RTxPS register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_setPrescaleValue(uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleCounterValue);
//*****************************************************************************
//
//! \brief Enables selected RTC interrupt sources.
//!
//! This function enables the selected RTC interrupt source. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param interruptMask is a bit mask of the interrupts to enable.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_A_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_A_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_A_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_A_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_A_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_enableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Disables selected RTC interrupt sources.
//!
//! This function disables the selected RTC interrupt source. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param interruptMask is a bit mask of the interrupts to disable.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_A_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_A_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_A_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_A_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_A_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_disableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Returns the status of the selected interrupts flags.
//!
//! This function returns the status of the interrupt flag for the selected
//! channel.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param interruptFlagMask is a bit mask of the interrupt flags to return the
//! status of.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_A_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_A_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_A_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_A_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_A_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//!
//! \return Logical OR of any of the following:
//! - \b RTC_A_TIME_EVENT_INTERRUPT asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_A_CLOCK_ALARM_INTERRUPT asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_A_CLOCK_READ_READY_INTERRUPT asserts when Calendar
//! registers are settled.
//! - \b RTC_A_PRESCALE_TIMER0_INTERRUPT asserts when Prescaler 0 event
//! condition is met.
//! - \b RTC_A_PRESCALE_TIMER1_INTERRUPT asserts when Prescaler 1 event
//! condition is met.
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t RTC_A_getInterruptStatus(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Clears selected RTC interrupt flags.
//!
//! This function clears the RTC interrupt flag is cleared, so that it no
//! longer asserts.
//!
//! \param baseAddress is the base address of the RTC_A module.
//! \param interruptFlagMask is a bit mask of the interrupt flags to be
//! cleared.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_A_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_A_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_A_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_A_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_A_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_A_clearInterrupt(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_RTC_A_H__

View File

@@ -0,0 +1,237 @@
//*****************************************************************************
//
// rtc_b.c - Driver for the rtc_b Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup rtc_b_api rtc_b
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_RTC_B__
#include "rtc_b.h"
#include <assert.h>
void RTC_B_startClock (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_RTCCTL01_H) &= ~(RTCHOLD_H);
}
void RTC_B_holdClock (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_RTCCTL01_H) |= RTCHOLD_H;
}
void RTC_B_setCalibrationFrequency (uint16_t baseAddress,
uint16_t frequencySelect)
{
HWREG16(baseAddress + OFS_RTCCTL23) &= ~(RTCCALF_3);
HWREG16(baseAddress + OFS_RTCCTL23) |= frequencySelect;
}
void RTC_B_setCalibrationData (uint16_t baseAddress,
uint8_t offsetDirection,
uint8_t offsetValue)
{
HWREG8(baseAddress + OFS_RTCCTL23_L) = offsetValue + offsetDirection;
}
void RTC_B_initCalendar (uint16_t baseAddress,
Calendar *CalendarTime,
uint16_t formatSelect)
{
HWREG8(baseAddress + OFS_RTCCTL01_H) |= RTCHOLD_H;
HWREG16(baseAddress + OFS_RTCCTL01) &= ~(RTCBCD);
HWREG16(baseAddress + OFS_RTCCTL01) |= formatSelect;
HWREG8(baseAddress + OFS_RTCTIM0_L) = CalendarTime->Seconds;
HWREG8(baseAddress + OFS_RTCTIM0_H) = CalendarTime->Minutes;
HWREG8(baseAddress + OFS_RTCTIM1_L) = CalendarTime->Hours;
HWREG8(baseAddress + OFS_RTCTIM1_H) = CalendarTime->DayOfWeek;
HWREG8(baseAddress + OFS_RTCDATE_L) = CalendarTime->DayOfMonth;
HWREG8(baseAddress + OFS_RTCDATE_H) = CalendarTime->Month;
HWREG16(baseAddress + OFS_RTCYEAR) = CalendarTime->Year;
}
Calendar RTC_B_getCalendarTime (uint16_t baseAddress)
{
Calendar tempCal;
while ( !(HWREG16(baseAddress + OFS_RTCCTL01) & RTCRDY) ) ;
tempCal.Seconds = HWREG8(baseAddress + OFS_RTCTIM0_L);
tempCal.Minutes = HWREG8(baseAddress + OFS_RTCTIM0_H);
tempCal.Hours = HWREG8(baseAddress + OFS_RTCTIM1_L);
tempCal.DayOfWeek = HWREG8(baseAddress + OFS_RTCTIM1_H);
tempCal.DayOfMonth = HWREG8(baseAddress + OFS_RTCDATE_L);
tempCal.Month = HWREG8(baseAddress + OFS_RTCDATE_H);
tempCal.Year = HWREG16(baseAddress + OFS_RTCYEAR);
return ( tempCal) ;
}
void RTC_B_configureCalendarAlarm(uint16_t baseAddress,
RTC_B_configureCalendarAlarmParam *param)
{
//Each of these is XORed with 0x80 to turn on if an integer is passed,
//or turn OFF if RTC_B_ALARM_OFF (0x80) is passed.
HWREG8(baseAddress + OFS_RTCAMINHR_L) = (param->minutesAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCAMINHR_H) = (param->hoursAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCADOWDAY_L) = (param->dayOfWeekAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCADOWDAY_H) = (param->dayOfMonthAlarm ^ 0x80);
}
void RTC_B_setCalendarEvent (uint16_t baseAddress,
uint16_t eventSelect)
{
HWREG16(baseAddress + OFS_RTCCTL01) &= ~(RTCTEV_3); //Reset bits
HWREG16(baseAddress + OFS_RTCCTL01) |= eventSelect;
}
void RTC_B_definePrescaleEvent (uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleEventDivider)
{
HWREG8(baseAddress + OFS_RTCPS0CTL_L + prescaleSelect) &= ~(RT0IP_7);
HWREG8(baseAddress + OFS_RTCPS0CTL_L +
prescaleSelect) |= prescaleEventDivider;
}
uint8_t RTC_B_getPrescaleValue (uint16_t baseAddress,
uint8_t prescaleSelect)
{
if (RTC_B_PRESCALE_0 == prescaleSelect){
return ( HWREG8(baseAddress + OFS_RTCPS_L) );
} else if (RTC_B_PRESCALE_1 == prescaleSelect){
return ( HWREG8(baseAddress + OFS_RTCPS_H) );
} else {
return ( 0) ;
}
}
void RTC_B_setPrescaleValue (uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleCounterValue)
{
if (RTC_B_PRESCALE_0 == prescaleSelect){
HWREG8(baseAddress + OFS_RTCPS_L) = prescaleCounterValue;
} else if (RTC_B_PRESCALE_1 == prescaleSelect){
HWREG8(baseAddress + OFS_RTCPS_H) = prescaleCounterValue;
}
}
void RTC_B_enableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
if ( interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE) ){
HWREG8(baseAddress + OFS_RTCCTL01_L) |=
(interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE));
}
if (interruptMask & RTC_B_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL) |= RT0PSIE;
}
if (interruptMask & RTC_B_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL) |= RT1PSIE;
}
}
void RTC_B_disableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
if ( interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE) ){
HWREG8(baseAddress + OFS_RTCCTL01_L) &=
~(interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE));
}
if (interruptMask & RTC_B_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL) &= ~(RT0PSIE);
}
if (interruptMask & RTC_B_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL) &= ~(RT1PSIE);
}
}
uint8_t RTC_B_getInterruptStatus (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
uint8_t tempInterruptFlagMask = 0x0000;
tempInterruptFlagMask |= (HWREG8(baseAddress + OFS_RTCCTL01_L)
& ((interruptFlagMask >> 4)
& (RTCOFIFG +
RTCTEVIFG +
RTCAIFG +
RTCRDYIFG)));
tempInterruptFlagMask = tempInterruptFlagMask << 4;
if (interruptFlagMask & RTC_B_PRESCALE_TIMER0_INTERRUPT){
if ( HWREG8(baseAddress + OFS_RTCPS0CTL) & RT0PSIFG){
tempInterruptFlagMask |= RTC_B_PRESCALE_TIMER0_INTERRUPT;
}
}
if (interruptFlagMask & RTC_B_PRESCALE_TIMER1_INTERRUPT){
if ( HWREG8(baseAddress + OFS_RTCPS1CTL) & RT1PSIFG){
tempInterruptFlagMask |= RTC_B_PRESCALE_TIMER1_INTERRUPT;
}
}
return ( tempInterruptFlagMask) ;
}
void RTC_B_clearInterrupt (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
if ( interruptFlagMask & (RTC_B_TIME_EVENT_INTERRUPT +
RTC_B_CLOCK_ALARM_INTERRUPT +
RTC_B_CLOCK_READ_READY_INTERRUPT +
RTC_B_OSCILLATOR_FAULT_INTERRUPT) ){
HWREG8(baseAddress + OFS_RTCCTL01_L) &=
~((interruptFlagMask>>4) & (RTCOFIFG +
RTCTEVIFG +
RTCAIFG +
RTCRDYIFG));
}
if (interruptFlagMask & RTC_B_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL) &= ~(RT0PSIFG);
}
if (interruptFlagMask & RTC_B_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL) &= ~(RT1PSIFG);
}
}
uint16_t RTC_B_convertBCDToBinary (uint16_t baseAddress,
uint16_t valueToConvert)
{
HWREG16(baseAddress + OFS_BCD2BIN) = valueToConvert;
return ( HWREG16(baseAddress + OFS_BCD2BIN) );
}
uint16_t RTC_B_convertBinaryToBCD (uint16_t baseAddress,
uint16_t valueToConvert)
{
HWREG16(baseAddress + OFS_BIN2BCD) = valueToConvert;
return ( HWREG16(baseAddress + OFS_BIN2BCD) );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for rtc_b_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,602 @@
//*****************************************************************************
//
// rtc_b.h - Driver for the RTC_B Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_RTC_B_H__
#define __MSP430WARE_RTC_B_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_RTC_B__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the RTC_B_initCalendar() function as the CalendarTime
//! parameter.
//
//*****************************************************************************
typedef struct Calendar {
//! Seconds of minute between 0-59
uint8_t Seconds;
//! Minutes of hour between 0-59
uint8_t Minutes;
//! Hour of day between 0-23
uint8_t Hours;
//! Day of week between 0-6
uint8_t DayOfWeek;
//! Day of month between 1-31
uint8_t DayOfMonth;
//! Month between 1-12
uint8_t Month;
//! Year between 0-4095
uint16_t Year;
} Calendar;
//*****************************************************************************
//
//! \brief Used in the RTC_B_configureCalendarAlarm() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct RTC_B_configureCalendarAlarmParam {
//! Is the alarm condition for the minutes.
//! \n Valid values are:
//! - \b RTC_B_ALARMCONDITION_OFF [Default]
uint8_t minutesAlarm;
//! Is the alarm condition for the hours.
//! \n Valid values are:
//! - \b RTC_B_ALARMCONDITION_OFF [Default]
uint8_t hoursAlarm;
//! Is the alarm condition for the day of week.
//! \n Valid values are:
//! - \b RTC_B_ALARMCONDITION_OFF [Default]
uint8_t dayOfWeekAlarm;
//! Is the alarm condition for the day of the month.
//! \n Valid values are:
//! - \b RTC_B_ALARMCONDITION_OFF [Default]
uint8_t dayOfMonthAlarm;
} RTC_B_configureCalendarAlarmParam;
//*****************************************************************************
//
// The following are values that can be passed to the frequencySelect parameter
// for functions: RTC_B_setCalibrationFrequency().
//
//*****************************************************************************
#define RTC_B_CALIBRATIONFREQ_OFF (RTCCALF_0)
#define RTC_B_CALIBRATIONFREQ_512HZ (RTCCALF_1)
#define RTC_B_CALIBRATIONFREQ_256HZ (RTCCALF_2)
#define RTC_B_CALIBRATIONFREQ_1HZ (RTCCALF_3)
//*****************************************************************************
//
// The following are values that can be passed to the offsetDirection parameter
// for functions: RTC_B_setCalibrationData().
//
//*****************************************************************************
#define RTC_B_CALIBRATION_DOWN2PPM (!(RTCCALS))
#define RTC_B_CALIBRATION_UP4PPM (RTCCALS)
//*****************************************************************************
//
// The following are values that can be passed to the formatSelect parameter
// for functions: RTC_B_initCalendar().
//
//*****************************************************************************
#define RTC_B_FORMAT_BINARY (!(RTCBCD))
#define RTC_B_FORMAT_BCD (RTCBCD)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: RTC_B_configureCalendarAlarm(), RTC_B_configureCalendarAlarm(),
// RTC_B_configureCalendarAlarm(), and RTC_B_configureCalendarAlarm().
//
//*****************************************************************************
#define RTC_B_ALARMCONDITION_OFF (0x80)
//*****************************************************************************
//
// The following are values that can be passed to the eventSelect parameter for
// functions: RTC_B_setCalendarEvent().
//
//*****************************************************************************
#define RTC_B_CALENDAREVENT_MINUTECHANGE (RTCTEV_0)
#define RTC_B_CALENDAREVENT_HOURCHANGE (RTCTEV_1)
#define RTC_B_CALENDAREVENT_NOON (RTCTEV_2)
#define RTC_B_CALENDAREVENT_MIDNIGHT (RTCTEV_3)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleEventDivider
// parameter for functions: RTC_B_definePrescaleEvent().
//
//*****************************************************************************
#define RTC_B_PSEVENTDIVIDER_2 (RT0IP_0)
#define RTC_B_PSEVENTDIVIDER_4 (RT0IP_1)
#define RTC_B_PSEVENTDIVIDER_8 (RT0IP_2)
#define RTC_B_PSEVENTDIVIDER_16 (RT0IP_3)
#define RTC_B_PSEVENTDIVIDER_32 (RT0IP_4)
#define RTC_B_PSEVENTDIVIDER_64 (RT0IP_5)
#define RTC_B_PSEVENTDIVIDER_128 (RT0IP_6)
#define RTC_B_PSEVENTDIVIDER_256 (RT0IP_7)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleSelect parameter
// for functions: RTC_B_definePrescaleEvent(), RTC_B_getPrescaleValue(), and
// RTC_B_setPrescaleValue().
//
//*****************************************************************************
#define RTC_B_PRESCALE_0 (0x0)
#define RTC_B_PRESCALE_1 (0x2)
//*****************************************************************************
//
// The following are values that can be passed to the interruptMask parameter
// for functions: RTC_B_enableInterrupt(), and RTC_B_disableInterrupt(); the
// interruptFlagMask parameter for functions: RTC_B_getInterruptStatus(), and
// RTC_B_clearInterrupt() as well as returned by the RTC_B_getInterruptStatus()
// function.
//
//*****************************************************************************
#define RTC_B_TIME_EVENT_INTERRUPT RTCTEVIE
#define RTC_B_CLOCK_ALARM_INTERRUPT RTCAIE
#define RTC_B_CLOCK_READ_READY_INTERRUPT RTCRDYIE
#define RTC_B_PRESCALE_TIMER0_INTERRUPT 0x02
#define RTC_B_PRESCALE_TIMER1_INTERRUPT 0x01
#define RTC_B_OSCILLATOR_FAULT_INTERRUPT RTCOFIE
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Starts the RTC.
//!
//! This function clears the RTC main hold bit to allow the RTC to function.
//!
//! \param baseAddress is the base address of the RTC_B module.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_startClock(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Holds the RTC.
//!
//! This function sets the RTC main hold bit to disable RTC functionality.
//!
//! \param baseAddress is the base address of the RTC_B module.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_holdClock(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Allows and Sets the frequency output to RTCCLK pin for calibration
//! measurement.
//!
//! This function sets a frequency to measure at the RTCCLK output pin. After
//! testing the set frequency, the calibration could be set accordingly.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param frequencySelect is the frequency output to RTCCLK.
//! Valid values are:
//! - \b RTC_B_CALIBRATIONFREQ_OFF [Default] - turn off calibration
//! output
//! - \b RTC_B_CALIBRATIONFREQ_512HZ - output signal at 512Hz for
//! calibration
//! - \b RTC_B_CALIBRATIONFREQ_256HZ - output signal at 256Hz for
//! calibration
//! - \b RTC_B_CALIBRATIONFREQ_1HZ - output signal at 1Hz for
//! calibration
//! \n Modified bits are \b RTCCALF of \b RTCCTL3 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_setCalibrationFrequency(uint16_t baseAddress,
uint16_t frequencySelect);
//*****************************************************************************
//
//! \brief Sets the specified calibration for the RTC.
//!
//! This function sets the calibration offset to make the RTC as accurate as
//! possible. The offsetDirection can be either +4-ppm or -2-ppm, and the
//! offsetValue should be from 1-63 and is multiplied by the direction setting
//! (i.e. +4-ppm * 8 (offsetValue) = +32-ppm). Please note, when measuring the
//! frequency after setting the calibration, you will only see a change on the
//! 1Hz frequency.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param offsetDirection is the direction that the calibration offset will
//! go.
//! Valid values are:
//! - \b RTC_B_CALIBRATION_DOWN2PPM - calibrate at steps of -2
//! - \b RTC_B_CALIBRATION_UP4PPM - calibrate at steps of +4
//! \n Modified bits are \b RTCCALS of \b RTCCTL2 register.
//! \param offsetValue is the value that the offset will be a factor of; a
//! valid value is any integer from 1-63.
//! \n Modified bits are \b RTCCAL of \b RTCCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_setCalibrationData(uint16_t baseAddress,
uint8_t offsetDirection,
uint8_t offsetValue);
//*****************************************************************************
//
//! \brief Initializes the settings to operate the RTC in calendar mode
//!
//! This function initializes the Calendar mode of the RTC module. To prevent
//! potential erroneous alarm conditions from occurring, the alarm should be
//! disabled by clearing the RTCAIE, RTCAIFG and AE bits with APIs:
//! RTC_B_disableInterrupt(), RTC_B_clearInterrupt() and
//! RTC_B_configureCalendarAlarm() before calendar initialization.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param CalendarTime is the pointer to the structure containing the values
//! for the Calendar to be initialized to. Valid values should be of
//! type pointer to Calendar and should contain the following members
//! and corresponding values: \n\b Seconds between 0-59 \n\b Minutes
//! between 0-59 \n\b Hours between 0-23 \n\b DayOfWeek between 0-6 \n\b
//! DayOfMonth between 1-31 \n\b Month between 1-12 \n\b Year between
//! 0-4095 \n\b NOTE: Values beyond the ones specified may result in
//! erratic behavior.
//! \param formatSelect is the format for the Calendar registers to use.
//! Valid values are:
//! - \b RTC_B_FORMAT_BINARY [Default]
//! - \b RTC_B_FORMAT_BCD
//! \n Modified bits are \b RTCBCD of \b RTCCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_initCalendar(uint16_t baseAddress,
Calendar *CalendarTime,
uint16_t formatSelect);
//*****************************************************************************
//
//! \brief Returns the Calendar Time stored in the Calendar registers of the
//! RTC.
//!
//! This function returns the current Calendar time in the form of a Calendar
//! structure. The RTCRDY polling is used in this function to prevent reading
//! invalid time.
//!
//! \param baseAddress is the base address of the RTC_B module.
//!
//! \return A Calendar structure containing the current time.
//
//*****************************************************************************
extern Calendar RTC_B_getCalendarTime(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets and Enables the desired Calendar Alarm settings.
//!
//! This function sets a Calendar interrupt condition to assert the RTCAIFG
//! interrupt flag. The condition is a logical and of all of the parameters.
//! For example if the minutes and hours alarm is set, then the interrupt will
//! only assert when the minutes AND the hours change to the specified setting.
//! Use the RTC_B_ALARM_OFF for any alarm settings that should not be apart of
//! the alarm condition.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param param is the pointer to struct for calendar alarm configuration.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_configureCalendarAlarm(uint16_t baseAddress,
RTC_B_configureCalendarAlarmParam *param);
//*****************************************************************************
//
//! \brief Sets a single specified Calendar interrupt condition
//!
//! This function sets a specified event to assert the RTCTEVIFG interrupt.
//! This interrupt is independent from the Calendar alarm interrupt.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param eventSelect is the condition selected.
//! Valid values are:
//! - \b RTC_B_CALENDAREVENT_MINUTECHANGE - assert interrupt on every
//! minute
//! - \b RTC_B_CALENDAREVENT_HOURCHANGE - assert interrupt on every hour
//! - \b RTC_B_CALENDAREVENT_NOON - assert interrupt when hour is 12
//! - \b RTC_B_CALENDAREVENT_MIDNIGHT - assert interrupt when hour is 0
//! \n Modified bits are \b RTCTEV of \b RTCCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_setCalendarEvent(uint16_t baseAddress,
uint16_t eventSelect);
//*****************************************************************************
//
//! \brief Sets up an interrupt condition for the selected Prescaler.
//!
//! This function sets the condition for an interrupt to assert based on the
//! individual prescalers.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param prescaleSelect is the prescaler to define an interrupt for.
//! Valid values are:
//! - \b RTC_B_PRESCALE_0
//! - \b RTC_B_PRESCALE_1
//! \param prescaleEventDivider is a divider to specify when an interrupt can
//! occur based on the clock source of the selected prescaler. (Does not
//! affect timer of the selected prescaler).
//! Valid values are:
//! - \b RTC_B_PSEVENTDIVIDER_2 [Default]
//! - \b RTC_B_PSEVENTDIVIDER_4
//! - \b RTC_B_PSEVENTDIVIDER_8
//! - \b RTC_B_PSEVENTDIVIDER_16
//! - \b RTC_B_PSEVENTDIVIDER_32
//! - \b RTC_B_PSEVENTDIVIDER_64
//! - \b RTC_B_PSEVENTDIVIDER_128
//! - \b RTC_B_PSEVENTDIVIDER_256
//! \n Modified bits are \b RTxIP of \b RTCPSxCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_definePrescaleEvent(uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleEventDivider);
//*****************************************************************************
//
//! \brief Returns the selected prescaler value.
//!
//! This function returns the value of the selected prescale counter register.
//! Note that the counter value should be held by calling RTC_B_holdClock()
//! before calling this API.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param prescaleSelect is the prescaler to obtain the value of.
//! Valid values are:
//! - \b RTC_B_PRESCALE_0
//! - \b RTC_B_PRESCALE_1
//!
//! \return The value of the specified prescaler count register
//
//*****************************************************************************
extern uint8_t RTC_B_getPrescaleValue(uint16_t baseAddress,
uint8_t prescaleSelect);
//*****************************************************************************
//
//! \brief Sets the selected prescaler value.
//!
//! This function sets the prescale counter value. Before setting the prescale
//! counter, it should be held by calling RTC_B_holdClock().
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param prescaleSelect is the prescaler to set the value for.
//! Valid values are:
//! - \b RTC_B_PRESCALE_0
//! - \b RTC_B_PRESCALE_1
//! \param prescaleCounterValue is the specified value to set the prescaler to.
//! Valid values are any integer between 0-255
//! \n Modified bits are \b RTxPS of \b RTxPS register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_setPrescaleValue(uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleCounterValue);
//*****************************************************************************
//
//! \brief Enables selected RTC interrupt sources.
//!
//! This function enables the selected RTC interrupt source. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param interruptMask is a bit mask of the interrupts to enable.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_B_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_B_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_B_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_B_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_B_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_B_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_enableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Disables selected RTC interrupt sources.
//!
//! This function disables the selected RTC interrupt source. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param interruptMask is a bit mask of the interrupts to disable.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_B_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_B_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_B_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_B_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_B_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_B_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_disableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Returns the status of the selected interrupts flags.
//!
//! This function returns the status of the interrupt flag for the selected
//! channel.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param interruptFlagMask is a bit mask of the interrupt flags to return the
//! status of.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_B_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_B_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_B_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_B_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_B_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_B_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return Logical OR of any of the following:
//! - \b RTC_B_TIME_EVENT_INTERRUPT asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_B_CLOCK_ALARM_INTERRUPT asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_B_CLOCK_READ_READY_INTERRUPT asserts when Calendar
//! registers are settled.
//! - \b RTC_B_PRESCALE_TIMER0_INTERRUPT asserts when Prescaler 0 event
//! condition is met.
//! - \b RTC_B_PRESCALE_TIMER1_INTERRUPT asserts when Prescaler 1 event
//! condition is met.
//! - \b RTC_B_OSCILLATOR_FAULT_INTERRUPT asserts if there is a problem
//! with the 32kHz oscillator, while the RTC is running.
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t RTC_B_getInterruptStatus(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Clears selected RTC interrupt flags.
//!
//! This function clears the RTC interrupt flag is cleared, so that it no
//! longer asserts.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param interruptFlagMask is a bit mask of the interrupt flags to be
//! cleared.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_B_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_B_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_B_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_B_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_B_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_B_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_B_clearInterrupt(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Convert the given BCD value to binary format
//!
//! This function converts BCD values to binary format. This API uses the
//! hardware registers to perform the conversion rather than a software method.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param valueToConvert is the raw value in BCD format to convert to Binary.
//! \n Modified bits are \b BCD2BIN of \b BCD2BIN register.
//!
//! \return The binary version of the input parameter
//
//*****************************************************************************
extern uint16_t RTC_B_convertBCDToBinary(uint16_t baseAddress,
uint16_t valueToConvert);
//*****************************************************************************
//
//! \brief Convert the given binary value to BCD format
//!
//! This function converts binary values to BCD format. This API uses the
//! hardware registers to perform the conversion rather than a software method.
//!
//! \param baseAddress is the base address of the RTC_B module.
//! \param valueToConvert is the raw value in Binary format to convert to BCD.
//! \n Modified bits are \b BIN2BCD of \b BIN2BCD register.
//!
//! \return The BCD version of the valueToConvert parameter
//
//*****************************************************************************
extern uint16_t RTC_B_convertBinaryToBCD(uint16_t baseAddress,
uint16_t valueToConvert);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_RTC_B_H__

View File

@@ -0,0 +1,345 @@
//*****************************************************************************
//
// rtc_c.c - Driver for the rtc_c Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup rtc_c_api rtc_c
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#if defined(__MSP430_HAS_RTC_C__) || defined(__MSP430_HAS_RTC_CE__)
#include "rtc_c.h"
#include <assert.h>
void RTC_C_startClock (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL13_L) &= ~(RTCHOLD);
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
void RTC_C_holdClock (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL13_L) |= RTCHOLD;
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
void RTC_C_setCalibrationFrequency (uint16_t baseAddress,
uint16_t frequencySelect)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG16(baseAddress + OFS_RTCCTL13) &= ~(RTCCALF_3);
HWREG16(baseAddress + OFS_RTCCTL13) |= frequencySelect;
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
void RTC_C_setCalibrationData (uint16_t baseAddress,
uint8_t offsetDirection,
uint8_t offsetValue)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG16(baseAddress + OFS_RTCOCAL) = offsetValue + offsetDirection;
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
void RTC_C_initCounter (uint16_t baseAddress,
uint16_t clockSelect,
uint16_t counterSizeSelect)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL13) |= RTCHOLD;
HWREG8(baseAddress + OFS_RTCCTL13) &= ~(RTCMODE);
HWREG16(baseAddress + OFS_RTCCTL13) &= ~(RTCSSEL_3 | RTCTEV_3 );
HWREG16(baseAddress + OFS_RTCCTL13) |= clockSelect + counterSizeSelect;
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
bool RTC_C_setTemperatureCompensation(uint16_t baseAddress,
uint16_t offsetDirection,
uint8_t offsetValue)
{
while(!(HWREG8(baseAddress + OFS_RTCTCMP_H) & RTCTCRDY_H));
HWREG16(baseAddress + OFS_RTCTCMP) = offsetValue + offsetDirection;
if(HWREG8(baseAddress + OFS_RTCTCMP_H) & RTCTCOK_H) {
return STATUS_SUCCESS;
} else {
return STATUS_FAIL;
}
}
void RTC_C_initCalendar (uint16_t baseAddress,
Calendar *CalendarTime,
uint16_t formatSelect)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL13_L) |= RTCHOLD;
HWREG16(baseAddress + OFS_RTCCTL13_L) &= ~(RTCBCD);
HWREG16(baseAddress + OFS_RTCCTL13_L) |= formatSelect;
HWREG8(baseAddress + OFS_RTCTIM0_L) = CalendarTime->Seconds;
HWREG8(baseAddress + OFS_RTCTIM0_H) = CalendarTime->Minutes;
HWREG8(baseAddress + OFS_RTCTIM1_L) = CalendarTime->Hours;
HWREG8(baseAddress + OFS_RTCTIM1_H) = CalendarTime->DayOfWeek;
HWREG8(baseAddress + OFS_RTCDATE_L) = CalendarTime->DayOfMonth;
HWREG8(baseAddress + OFS_RTCDATE_H) = CalendarTime->Month;
HWREG16(baseAddress + OFS_RTCYEAR) = CalendarTime->Year;
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
Calendar RTC_C_getCalendarTime (uint16_t baseAddress)
{
Calendar tempCal;
while ( !(HWREG8(baseAddress + OFS_RTCCTL13_L) & RTCRDY) ) ;
tempCal.Seconds = HWREG8(baseAddress + OFS_RTCTIM0_L);
tempCal.Minutes = HWREG8(baseAddress + OFS_RTCTIM0_H);
tempCal.Hours = HWREG8(baseAddress + OFS_RTCTIM1_L);
tempCal.DayOfWeek = HWREG8(baseAddress + OFS_RTCTIM1_H);
tempCal.DayOfMonth = HWREG8(baseAddress + OFS_RTCDATE_L);
tempCal.Month = HWREG8(baseAddress + OFS_RTCDATE_H);
tempCal.Year = HWREG16(baseAddress + OFS_RTCYEAR);
return ( tempCal) ;
}
void RTC_C_configureCalendarAlarm(uint16_t baseAddress,
RTC_C_configureCalendarAlarmParam *param)
{
//Each of these is XORed with 0x80 to turn on if an integer is passed,
//or turn OFF if RTC_C_ALARM_OFF (0x80) is passed.
HWREG8(baseAddress + OFS_RTCAMINHR_L) = (param->minutesAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCAMINHR_H) = (param->hoursAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCADOWDAY_L) = (param->dayOfWeekAlarm ^ 0x80);
HWREG8(baseAddress + OFS_RTCADOWDAY_H) = (param->dayOfMonthAlarm ^ 0x80);
}
void RTC_C_setCalendarEvent (uint16_t baseAddress,
uint16_t eventSelect)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL13_L) &= ~(RTCTEV_3); //Reset bits
HWREG8(baseAddress + OFS_RTCCTL13_L) |= eventSelect;
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
uint32_t RTC_C_getCounterValue (uint16_t baseAddress)
{
if ( (HWREG8(baseAddress + OFS_RTCCTL13) & RTCHOLD)
|| (HWREG8(baseAddress + OFS_RTCPS1CTL) & RT1PSHOLD) ){
return ( 0) ;
}
uint32_t counterValue_L = HWREG16(baseAddress + OFS_RTCTIM0);
uint32_t counterValue_H = HWREG16(baseAddress + OFS_RTCTIM1);
return ( (counterValue_H << 16) + counterValue_L );
}
void RTC_C_setCounterValue (uint16_t baseAddress,
uint32_t counterValue)
{
uint16_t mode = HWREG16(baseAddress + OFS_RTCCTL13) & RTCTEV_3;
if(mode == RTC_C_COUNTERSIZE_8BIT && counterValue > UINT8_MAX)
counterValue = UINT8_MAX;
else if(mode == RTC_C_COUNTERSIZE_16BIT && counterValue > UINT16_MAX)
counterValue = UINT16_MAX;
else if(mode == RTC_C_COUNTERSIZE_24BIT && counterValue > 0xFFFFFF)
counterValue = 0xFFFFFF;
HWREG16(baseAddress + OFS_RTCTIM0) = counterValue;
HWREG16(baseAddress + OFS_RTCTIM1) = ( counterValue >> 16 );
}
void RTC_C_initCounterPrescale (uint16_t baseAddress,
uint8_t prescaleSelect,
uint16_t prescaleClockSelect,
uint16_t prescaleDivider)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
//Reset bits and set clock select
HWREG16(baseAddress + OFS_RTCPS0CTL + prescaleSelect) =
prescaleClockSelect + prescaleDivider;
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
void RTC_C_holdCounterPrescale (uint16_t baseAddress,
uint8_t prescaleSelect)
{
HWREG8(baseAddress + OFS_RTCPS0CTL_H + prescaleSelect) |= RT0PSHOLD_H;
}
void RTC_C_startCounterPrescale (uint16_t baseAddress,
uint8_t prescaleSelect)
{
HWREG8(baseAddress + OFS_RTCPS0CTL_H + prescaleSelect) &= ~(RT0PSHOLD_H);
}
void RTC_C_definePrescaleEvent (uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleEventDivider)
{
HWREG8(baseAddress + OFS_RTCPS0CTL_L + prescaleSelect) &= ~(RT0IP_7);
HWREG8(baseAddress + OFS_RTCPS0CTL_L +
prescaleSelect) |= prescaleEventDivider;
}
uint8_t RTC_C_getPrescaleValue (uint16_t baseAddress,
uint8_t prescaleSelect)
{
if (RTC_C_PRESCALE_0 == prescaleSelect){
return ( HWREG8(baseAddress + OFS_RTCPS_L) );
} else if (RTC_C_PRESCALE_1 == prescaleSelect){
return ( HWREG8(baseAddress + OFS_RTCPS_H) );
} else {
return ( 0) ;
}
}
void RTC_C_setPrescaleValue(uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleCounterValue)
{
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
if (RTC_C_PRESCALE_0 == prescaleSelect){
HWREG8(baseAddress + OFS_RTCPS_L) = prescaleCounterValue;
} else if (RTC_C_PRESCALE_1 == prescaleSelect){
HWREG8(baseAddress + OFS_RTCPS_H) = prescaleCounterValue;
}
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
void RTC_C_enableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
if ( interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE) ){
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL0_L) |=
(interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE));
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
if (interruptMask & RTC_C_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL_L) |= RT0PSIE;
}
if (interruptMask & RTC_C_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL_L) |= RT1PSIE;
}
}
void RTC_C_disableInterrupt (uint16_t baseAddress,
uint8_t interruptMask)
{
if ( interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE) ){
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL0_L) &=
~(interruptMask & (RTCOFIE + RTCTEVIE + RTCAIE + RTCRDYIE));
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
if (interruptMask & RTC_C_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL_L) &= ~(RT0PSIE);
}
if (interruptMask & RTC_C_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL_L) &= ~(RT1PSIE);
}
}
uint8_t RTC_C_getInterruptStatus (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
uint8_t tempInterruptFlagMask = 0x0000;
tempInterruptFlagMask |= (HWREG8(baseAddress + OFS_RTCCTL0_L)
& ((interruptFlagMask >> 4)
& (RTCOFIFG +
RTCTEVIFG +
RTCAIFG +
RTCRDYIFG)));
tempInterruptFlagMask = tempInterruptFlagMask << 4;
if (interruptFlagMask & RTC_C_PRESCALE_TIMER0_INTERRUPT){
if ( HWREG8(baseAddress + OFS_RTCPS0CTL_L) & RT0PSIFG){
tempInterruptFlagMask |= RTC_C_PRESCALE_TIMER0_INTERRUPT;
}
}
if (interruptFlagMask & RTC_C_PRESCALE_TIMER1_INTERRUPT){
if ( HWREG8(baseAddress + OFS_RTCPS1CTL_L) & RT1PSIFG){
tempInterruptFlagMask |= RTC_C_PRESCALE_TIMER1_INTERRUPT;
}
}
return ( tempInterruptFlagMask) ;
}
void RTC_C_clearInterrupt (uint16_t baseAddress,
uint8_t interruptFlagMask)
{
if ( interruptFlagMask & (RTC_C_TIME_EVENT_INTERRUPT +
RTC_C_CLOCK_ALARM_INTERRUPT +
RTC_C_CLOCK_READ_READY_INTERRUPT +
RTC_C_OSCILLATOR_FAULT_INTERRUPT) ){
HWREG8(baseAddress + OFS_RTCCTL0_H) = RTCKEY_H;
HWREG8(baseAddress + OFS_RTCCTL0_L) &=
~((interruptFlagMask>>4) & (RTCOFIFG +
RTCTEVIFG +
RTCAIFG +
RTCRDYIFG));
HWREG8(baseAddress + OFS_RTCCTL0_H) = 0x00;
}
if (interruptFlagMask & RTC_C_PRESCALE_TIMER0_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS0CTL_L) &= ~(RT0PSIFG);
}
if (interruptFlagMask & RTC_C_PRESCALE_TIMER1_INTERRUPT){
HWREG8(baseAddress + OFS_RTCPS1CTL_L) &= ~(RT1PSIFG);
}
}
uint16_t RTC_C_convertBCDToBinary (uint16_t baseAddress,
uint16_t valueToConvert)
{
HWREG16(baseAddress + OFS_BCD2BIN) = valueToConvert;
return ( HWREG16(baseAddress + OFS_BCD2BIN) );
}
uint16_t RTC_C_convertBinaryToBCD (uint16_t baseAddress,
uint16_t valueToConvert)
{
HWREG16(baseAddress + OFS_BIN2BCD) = valueToConvert;
return ( HWREG16(baseAddress + OFS_BIN2BCD) );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for rtc_c_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,825 @@
//*****************************************************************************
//
// rtc_c.h - Driver for the RTC_C Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_RTC_C_H__
#define __MSP430WARE_RTC_C_H__
#include "inc/hw_memmap.h"
#if defined(__MSP430_HAS_RTC_C__) || defined(__MSP430_HAS_RTC_CE__)
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the RTC_C_initCalendar() function as the CalendarTime
//! parameter.
//
//*****************************************************************************
typedef struct Calendar {
//! Seconds of minute between 0-59
uint8_t Seconds;
//! Minutes of hour between 0-59
uint8_t Minutes;
//! Hour of day between 0-23
uint8_t Hours;
//! Day of week between 0-6
uint8_t DayOfWeek;
//! Day of month between 1-31
uint8_t DayOfMonth;
//! Month between 1-12
uint8_t Month;
//! Year between 0-4095
uint16_t Year;
} Calendar;
//*****************************************************************************
//
//! \brief Used in the RTC_C_configureCalendarAlarm() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct RTC_C_configureCalendarAlarmParam {
//! Is the alarm condition for the minutes.
//! \n Valid values are:
//! - \b RTC_C_ALARMCONDITION_OFF [Default]
uint8_t minutesAlarm;
//! Is the alarm condition for the hours.
//! \n Valid values are:
//! - \b RTC_C_ALARMCONDITION_OFF [Default]
uint8_t hoursAlarm;
//! Is the alarm condition for the day of week.
//! \n Valid values are:
//! - \b RTC_C_ALARMCONDITION_OFF [Default]
uint8_t dayOfWeekAlarm;
//! Is the alarm condition for the day of the month.
//! \n Valid values are:
//! - \b RTC_C_ALARMCONDITION_OFF [Default]
uint8_t dayOfMonthAlarm;
} RTC_C_configureCalendarAlarmParam;
//*****************************************************************************
//
// The following are values that can be passed to the frequencySelect parameter
// for functions: RTC_C_setCalibrationFrequency().
//
//*****************************************************************************
#define RTC_C_CALIBRATIONFREQ_OFF (RTCCALF_0)
#define RTC_C_CALIBRATIONFREQ_512HZ (RTCCALF_1)
#define RTC_C_CALIBRATIONFREQ_256HZ (RTCCALF_2)
#define RTC_C_CALIBRATIONFREQ_1HZ (RTCCALF_3)
//*****************************************************************************
//
// The following are values that can be passed to the offsetDirection parameter
// for functions: RTC_C_setCalibrationData().
//
//*****************************************************************************
#define RTC_C_CALIBRATION_DOWN1PPM (!(RTCCALS))
#define RTC_C_CALIBRATION_UP1PPM (RTCCALS)
//*****************************************************************************
//
// The following are values that can be passed to the offsetDirection parameter
// for functions: RTC_C_setTemperatureCompensation().
//
//*****************************************************************************
#define RTC_C_COMPENSATION_DOWN1PPM (!(RTCTCMPS))
#define RTC_C_COMPENSATION_UP1PPM (RTCTCMPS)
//*****************************************************************************
//
// The following are values that can be passed to the clockSelect parameter for
// functions: RTC_C_initCounter().
//
//*****************************************************************************
#define RTC_C_CLOCKSELECT_32KHZ_OSC (RTCSSEL_0)
#define RTC_C_CLOCKSELECT_RT1PS (RTCSSEL_2)
//*****************************************************************************
//
// The following are values that can be passed to the counterSizeSelect
// parameter for functions: RTC_C_initCounter().
//
//*****************************************************************************
#define RTC_C_COUNTERSIZE_8BIT (RTCTEV_0)
#define RTC_C_COUNTERSIZE_16BIT (RTCTEV_1)
#define RTC_C_COUNTERSIZE_24BIT (RTCTEV_2)
#define RTC_C_COUNTERSIZE_32BIT (RTCTEV_3)
//*****************************************************************************
//
// The following are values that can be passed to the formatSelect parameter
// for functions: RTC_C_initCalendar().
//
//*****************************************************************************
#define RTC_C_FORMAT_BINARY (!(RTCBCD))
#define RTC_C_FORMAT_BCD (RTCBCD)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: RTC_C_configureCalendarAlarm(), RTC_C_configureCalendarAlarm(),
// RTC_C_configureCalendarAlarm(), and RTC_C_configureCalendarAlarm().
//
//*****************************************************************************
#define RTC_C_ALARMCONDITION_OFF (0x80)
//*****************************************************************************
//
// The following are values that can be passed to the eventSelect parameter for
// functions: RTC_C_setCalendarEvent().
//
//*****************************************************************************
#define RTC_C_CALENDAREVENT_MINUTECHANGE (RTCTEV_0)
#define RTC_C_CALENDAREVENT_HOURCHANGE (RTCTEV_1)
#define RTC_C_CALENDAREVENT_NOON (RTCTEV_2)
#define RTC_C_CALENDAREVENT_MIDNIGHT (RTCTEV_3)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleDivider parameter
// for functions: RTC_C_initCounterPrescale().
//
//*****************************************************************************
#define RTC_C_PSDIVIDER_2 (RT0PSDIV_0)
#define RTC_C_PSDIVIDER_4 (RT0PSDIV_1)
#define RTC_C_PSDIVIDER_8 (RT0PSDIV_2)
#define RTC_C_PSDIVIDER_16 (RT0PSDIV_3)
#define RTC_C_PSDIVIDER_32 (RT0PSDIV_4)
#define RTC_C_PSDIVIDER_64 (RT0PSDIV_5)
#define RTC_C_PSDIVIDER_128 (RT0PSDIV_6)
#define RTC_C_PSDIVIDER_256 (RT0PSDIV_7)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleClockSelect
// parameter for functions: RTC_C_initCounterPrescale().
//
//*****************************************************************************
#define RTC_C_PSCLOCKSELECT_ACLK (RT1SSEL_0)
#define RTC_C_PSCLOCKSELECT_SMCLK (RT1SSEL_1)
#define RTC_C_PSCLOCKSELECT_RT0PS (RT1SSEL_2)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleEventDivider
// parameter for functions: RTC_C_definePrescaleEvent().
//
//*****************************************************************************
#define RTC_C_PSEVENTDIVIDER_2 (RT0IP_0)
#define RTC_C_PSEVENTDIVIDER_4 (RT0IP_1)
#define RTC_C_PSEVENTDIVIDER_8 (RT0IP_2)
#define RTC_C_PSEVENTDIVIDER_16 (RT0IP_3)
#define RTC_C_PSEVENTDIVIDER_32 (RT0IP_4)
#define RTC_C_PSEVENTDIVIDER_64 (RT0IP_5)
#define RTC_C_PSEVENTDIVIDER_128 (RT0IP_6)
#define RTC_C_PSEVENTDIVIDER_256 (RT0IP_7)
//*****************************************************************************
//
// The following are values that can be passed to the prescaleSelect parameter
// for functions: RTC_C_initCounterPrescale(), RTC_C_holdCounterPrescale(),
// RTC_C_startCounterPrescale(), RTC_C_definePrescaleEvent(),
// RTC_C_getPrescaleValue(), and RTC_C_setPrescaleValue().
//
//*****************************************************************************
#define RTC_C_PRESCALE_0 (0x0)
#define RTC_C_PRESCALE_1 (0x2)
//*****************************************************************************
//
// The following are values that can be passed to the interruptMask parameter
// for functions: RTC_C_enableInterrupt(), and RTC_C_disableInterrupt(); the
// interruptFlagMask parameter for functions: RTC_C_getInterruptStatus(), and
// RTC_C_clearInterrupt() as well as returned by the RTC_C_getInterruptStatus()
// function.
//
//*****************************************************************************
#define RTC_C_TIME_EVENT_INTERRUPT RTCTEVIE
#define RTC_C_CLOCK_ALARM_INTERRUPT RTCAIE
#define RTC_C_CLOCK_READ_READY_INTERRUPT RTCRDYIE
#define RTC_C_PRESCALE_TIMER0_INTERRUPT 0x02
#define RTC_C_PRESCALE_TIMER1_INTERRUPT 0x01
#define RTC_C_OSCILLATOR_FAULT_INTERRUPT RTCOFIE
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Starts the RTC.
//!
//! This function clears the RTC main hold bit to allow the RTC to function.
//!
//! \param baseAddress is the base address of the RTC_C module.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_startClock(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Holds the RTC.
//!
//! This function sets the RTC main hold bit to disable RTC functionality.
//!
//! \param baseAddress is the base address of the RTC_C module.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_holdClock(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Allows and Sets the frequency output to RTCCLK pin for calibration
//! measurement.
//!
//! This function sets a frequency to measure at the RTCCLK output pin. After
//! testing the set frequency, the calibration could be set accordingly.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param frequencySelect is the frequency output to RTCCLK.
//! Valid values are:
//! - \b RTC_C_CALIBRATIONFREQ_OFF [Default] - turn off calibration
//! output
//! - \b RTC_C_CALIBRATIONFREQ_512HZ - output signal at 512Hz for
//! calibration
//! - \b RTC_C_CALIBRATIONFREQ_256HZ - output signal at 256Hz for
//! calibration
//! - \b RTC_C_CALIBRATIONFREQ_1HZ - output signal at 1Hz for
//! calibration
//! \n Modified bits are \b RTCCALF of \b RTCCTL3 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_setCalibrationFrequency(uint16_t baseAddress,
uint16_t frequencySelect);
//*****************************************************************************
//
//! \brief Sets the specified calibration for the RTC.
//!
//! This function sets the calibration offset to make the RTC as accurate as
//! possible. The offsetDirection can be either +1-ppm or -1-ppm, and the
//! offsetValue should be from 1-240 and is multiplied by the direction setting
//! (i.e. +1-ppm * 8 (offsetValue) = +8-ppm).
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param offsetDirection is the direction that the calibration offset will
//! go.
//! Valid values are:
//! - \b RTC_C_CALIBRATION_DOWN1PPM - calibrate at steps of -1
//! - \b RTC_C_CALIBRATION_UP1PPM - calibrate at steps of +1
//! \n Modified bits are \b RTC0CALS of \b RTC0CAL register.
//! \param offsetValue is the value that the offset will be a factor of; a
//! valid value is any integer from 1-240.
//! \n Modified bits are \b RTC0CALx of \b RTC0CAL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_setCalibrationData(uint16_t baseAddress,
uint8_t offsetDirection,
uint8_t offsetValue);
//*****************************************************************************
//
//! \brief Initializes the settings to operate the RTC in Counter mode.
//!
//! This function initializes the Counter mode of the RTC_C. Setting the clock
//! source and counter size will allow an interrupt from the RTCTEVIFG once an
//! overflow to the counter register occurs.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param clockSelect is the selected clock for the counter mode to use.
//! Valid values are:
//! - \b RTC_C_CLOCKSELECT_32KHZ_OSC
//! - \b RTC_C_CLOCKSELECT_RT1PS
//! \n Modified bits are \b RTCSSEL of \b RTCCTL1 register.
//! \param counterSizeSelect is the size of the counter.
//! Valid values are:
//! - \b RTC_C_COUNTERSIZE_8BIT [Default]
//! - \b RTC_C_COUNTERSIZE_16BIT
//! - \b RTC_C_COUNTERSIZE_24BIT
//! - \b RTC_C_COUNTERSIZE_32BIT
//! \n Modified bits are \b RTCTEV of \b RTCCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_initCounter(uint16_t baseAddress,
uint16_t clockSelect,
uint16_t counterSizeSelect);
//*****************************************************************************
//
//! \brief Sets the specified temperature compensation for the RTC.
//!
//! This function sets the calibration offset to make the RTC as accurate as
//! possible. The offsetDirection can be either +1-ppm or -1-ppm, and the
//! offsetValue should be from 1-240 and is multiplied by the direction setting
//! (i.e. +1-ppm * 8 (offsetValue) = +8-ppm).
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param offsetDirection is the direction that the calibration offset wil go
//! Valid values are:
//! - \b RTC_C_COMPENSATION_DOWN1PPM
//! - \b RTC_C_COMPENSATION_UP1PPM
//! \n Modified bits are \b RTCTCMPS of \b RTCTCMP register.
//! \param offsetValue is the value that the offset will be a factor of; a
//! valid value is any integer from 1-240.
//! \n Modified bits are \b RTCTCMPx of \b RTCTCMP register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of setting the temperature
//! compensation
//
//*****************************************************************************
extern bool RTC_C_setTemperatureCompensation(uint16_t baseAddress,
uint16_t offsetDirection,
uint8_t offsetValue);
//*****************************************************************************
//
//! \brief Initializes the settings to operate the RTC in calendar mode
//!
//! This function initializes the Calendar mode of the RTC module. To prevent
//! potential erroneous alarm conditions from occurring, the alarm should be
//! disabled by clearing the RTCAIE, RTCAIFG and AE bits with APIs:
//! RTC_C_disableInterrupt(), RTC_C_clearInterrupt() and
//! RTC_C_configureCalendarAlarm() before calendar initialization.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param CalendarTime is the pointer to the structure containing the values
//! for the Calendar to be initialized to. Valid values should be of
//! type pointer to Calendar and should contain the following members
//! and corresponding values: \n\b Seconds between 0-59 \n\b Minutes
//! between 0-59 \n\b Hours between 0-23 \n\b DayOfWeek between 0-6 \n\b
//! DayOfMonth between 1-31 \n\b Month between 1-12 \n\b Year between
//! 0-4095 \n\b NOTE: Values beyond the ones specified may result in
//! erratic behavior.
//! \param formatSelect is the format for the Calendar registers to use.
//! Valid values are:
//! - \b RTC_C_FORMAT_BINARY [Default]
//! - \b RTC_C_FORMAT_BCD
//! \n Modified bits are \b RTCBCD of \b RTCCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_initCalendar(uint16_t baseAddress,
Calendar *CalendarTime,
uint16_t formatSelect);
//*****************************************************************************
//
//! \brief Returns the Calendar Time stored in the Calendar registers of the
//! RTC.
//!
//! This function returns the current Calendar time in the form of a Calendar
//! structure. The RTCRDY polling is used in this function to prevent reading
//! invalid time.
//!
//! \param baseAddress is the base address of the RTC_C module.
//!
//! \return A Calendar structure containing the current time.
//
//*****************************************************************************
extern Calendar RTC_C_getCalendarTime(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets and Enables the desired Calendar Alarm settings.
//!
//! This function sets a Calendar interrupt condition to assert the RTCAIFG
//! interrupt flag. The condition is a logical and of all of the parameters.
//! For example if the minutes and hours alarm is set, then the interrupt will
//! only assert when the minutes AND the hours change to the specified setting.
//! Use the RTC_C_ALARM_OFF for any alarm settings that should not be apart of
//! the alarm condition.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param param is the pointer to struct for calendar alarm configuration.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_configureCalendarAlarm(uint16_t baseAddress,
RTC_C_configureCalendarAlarmParam *param);
//*****************************************************************************
//
//! \brief Sets a single specified Calendar interrupt condition
//!
//! This function sets a specified event to assert the RTCTEVIFG interrupt.
//! This interrupt is independent from the Calendar alarm interrupt.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param eventSelect is the condition selected.
//! Valid values are:
//! - \b RTC_C_CALENDAREVENT_MINUTECHANGE - assert interrupt on every
//! minute
//! - \b RTC_C_CALENDAREVENT_HOURCHANGE - assert interrupt on every hour
//! - \b RTC_C_CALENDAREVENT_NOON - assert interrupt when hour is 12
//! - \b RTC_C_CALENDAREVENT_MIDNIGHT - assert interrupt when hour is 0
//! \n Modified bits are \b RTCTEV of \b RTCCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_setCalendarEvent(uint16_t baseAddress,
uint16_t eventSelect);
//*****************************************************************************
//
//! \brief Returns the value of the Counter register.
//!
//! This function returns the value of the counter register for the RTC_C
//! module. It will return the 32-bit value no matter the size set during
//! initialization. The RTC should be held before trying to use this function.
//!
//! \param baseAddress is the base address of the RTC_C module.
//!
//! \return The raw value of the full 32-bit Counter Register.
//
//*****************************************************************************
extern uint32_t RTC_C_getCounterValue(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets the value of the Counter register
//!
//! This function sets the counter register of the RTC_C module.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param counterValue is the value to set the Counter register to; a valid
//! value may be any 32-bit integer.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_setCounterValue(uint16_t baseAddress,
uint32_t counterValue);
//*****************************************************************************
//
//! \brief Initializes the Prescaler for Counter mode.
//!
//! This function initializes the selected prescaler for the counter mode in
//! the RTC_C module. If the RTC is initialized in Calendar mode, then these
//! are automatically initialized. The Prescalers can be used to divide a clock
//! source additionally before it gets to the main RTC clock.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param prescaleSelect is the prescaler to initialize.
//! Valid values are:
//! - \b RTC_C_PRESCALE_0
//! - \b RTC_C_PRESCALE_1
//! \param prescaleClockSelect is the clock to drive the selected prescaler.
//! Valid values are:
//! - \b RTC_C_PSCLOCKSELECT_ACLK
//! - \b RTC_C_PSCLOCKSELECT_SMCLK
//! - \b RTC_C_PSCLOCKSELECT_RT0PS - use Prescaler 0 as source to
//! Prescaler 1 (May only be used if prescaleSelect is
//! RTC_C_PRESCALE_1)
//! \n Modified bits are \b RTxSSEL of \b RTCPSxCTL register.
//! \param prescaleDivider is the divider for the selected clock source.
//! Valid values are:
//! - \b RTC_C_PSDIVIDER_2 [Default]
//! - \b RTC_C_PSDIVIDER_4
//! - \b RTC_C_PSDIVIDER_8
//! - \b RTC_C_PSDIVIDER_16
//! - \b RTC_C_PSDIVIDER_32
//! - \b RTC_C_PSDIVIDER_64
//! - \b RTC_C_PSDIVIDER_128
//! - \b RTC_C_PSDIVIDER_256
//! \n Modified bits are \b RTxPSDIV of \b RTCPSxCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_initCounterPrescale(uint16_t baseAddress,
uint8_t prescaleSelect,
uint16_t prescaleClockSelect,
uint16_t prescaleDivider);
//*****************************************************************************
//
//! \brief Holds the selected Prescaler.
//!
//! This function holds the prescale counter from continuing. This will only
//! work in counter mode, in Calendar mode, the RTC_C_holdClock() must be used.
//! In counter mode, if using both prescalers in conjunction with the main RTC
//! counter, then stopping RT0PS will stop RT1PS, but stopping RT1PS will not
//! stop RT0PS.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param prescaleSelect is the prescaler to hold.
//! Valid values are:
//! - \b RTC_C_PRESCALE_0
//! - \b RTC_C_PRESCALE_1
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_holdCounterPrescale(uint16_t baseAddress,
uint8_t prescaleSelect);
//*****************************************************************************
//
//! \brief Starts the selected Prescaler.
//!
//! This function starts the selected prescale counter. This function will only
//! work if the RTC is in counter mode.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param prescaleSelect is the prescaler to start.
//! Valid values are:
//! - \b RTC_C_PRESCALE_0
//! - \b RTC_C_PRESCALE_1
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_startCounterPrescale(uint16_t baseAddress,
uint8_t prescaleSelect);
//*****************************************************************************
//
//! \brief Sets up an interrupt condition for the selected Prescaler.
//!
//! This function sets the condition for an interrupt to assert based on the
//! individual prescalers.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param prescaleSelect is the prescaler to define an interrupt for.
//! Valid values are:
//! - \b RTC_C_PRESCALE_0
//! - \b RTC_C_PRESCALE_1
//! \param prescaleEventDivider is a divider to specify when an interrupt can
//! occur based on the clock source of the selected prescaler. (Does not
//! affect timer of the selected prescaler).
//! Valid values are:
//! - \b RTC_C_PSEVENTDIVIDER_2 [Default]
//! - \b RTC_C_PSEVENTDIVIDER_4
//! - \b RTC_C_PSEVENTDIVIDER_8
//! - \b RTC_C_PSEVENTDIVIDER_16
//! - \b RTC_C_PSEVENTDIVIDER_32
//! - \b RTC_C_PSEVENTDIVIDER_64
//! - \b RTC_C_PSEVENTDIVIDER_128
//! - \b RTC_C_PSEVENTDIVIDER_256
//! \n Modified bits are \b RTxIP of \b RTCPSxCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_definePrescaleEvent(uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleEventDivider);
//*****************************************************************************
//
//! \brief Returns the selected prescaler value.
//!
//! This function returns the value of the selected prescale counter register.
//! Note that the counter value should be held by calling RTC_C_holdClock()
//! before calling this API.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param prescaleSelect is the prescaler to obtain the value of.
//! Valid values are:
//! - \b RTC_C_PRESCALE_0
//! - \b RTC_C_PRESCALE_1
//!
//! \return The value of the specified prescaler count register
//
//*****************************************************************************
extern uint8_t RTC_C_getPrescaleValue(uint16_t baseAddress,
uint8_t prescaleSelect);
//*****************************************************************************
//
//! \brief Sets the selected Prescaler value.
//!
//! This function sets the prescale counter value. Before setting the prescale
//! counter, it should be held by calling RTC_C_holdClock().
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param prescaleSelect is the prescaler to set the value for.
//! Valid values are:
//! - \b RTC_C_PRESCALE_0
//! - \b RTC_C_PRESCALE_1
//! \param prescaleCounterValue is the specified value to set the prescaler to.
//! Valid values are any integer between 0-255
//! \n Modified bits are \b RTxPS of \b RTxPS register.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_setPrescaleValue(uint16_t baseAddress,
uint8_t prescaleSelect,
uint8_t prescaleCounterValue);
//*****************************************************************************
//
//! \brief Enables selected RTC interrupt sources.
//!
//! This function enables the selected RTC interrupt source. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param interruptMask is a bit mask of the interrupts to enable.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_C_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_C_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_C_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_C_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_C_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_C_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_enableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Disables selected RTC interrupt sources.
//!
//! This function disables the selected RTC interrupt source. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param interruptMask is a bit mask of the interrupts to disable.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_C_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_C_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_C_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_C_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_C_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_C_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_disableInterrupt(uint16_t baseAddress,
uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Returns the status of the selected interrupts flags.
//!
//! This function returns the status of the interrupt flag for the selected
//! channel.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param interruptFlagMask is a bit mask of the interrupt flags to return the
//! status of.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_C_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_C_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_C_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_C_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_C_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_C_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return Logical OR of any of the following:
//! - \b RTC_C_TIME_EVENT_INTERRUPT asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_C_CLOCK_ALARM_INTERRUPT asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_C_CLOCK_READ_READY_INTERRUPT asserts when Calendar
//! registers are settled.
//! - \b RTC_C_PRESCALE_TIMER0_INTERRUPT asserts when Prescaler 0 event
//! condition is met.
//! - \b RTC_C_PRESCALE_TIMER1_INTERRUPT asserts when Prescaler 1 event
//! condition is met.
//! - \b RTC_C_OSCILLATOR_FAULT_INTERRUPT asserts if there is a problem
//! with the 32kHz oscillator, while the RTC is running.
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t RTC_C_getInterruptStatus(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Clears selected RTC interrupt flags.
//!
//! This function clears the RTC interrupt flag is cleared, so that it no
//! longer asserts.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param interruptFlagMask is a bit mask of the interrupt flags to be
//! cleared.
//! Mask value is the logical OR of any of the following:
//! - \b RTC_C_TIME_EVENT_INTERRUPT - asserts when counter overflows in
//! counter mode or when Calendar event condition defined by
//! defineCalendarEvent() is met.
//! - \b RTC_C_CLOCK_ALARM_INTERRUPT - asserts when alarm condition in
//! Calendar mode is met.
//! - \b RTC_C_CLOCK_READ_READY_INTERRUPT - asserts when Calendar
//! registers are settled.
//! - \b RTC_C_PRESCALE_TIMER0_INTERRUPT - asserts when Prescaler 0
//! event condition is met.
//! - \b RTC_C_PRESCALE_TIMER1_INTERRUPT - asserts when Prescaler 1
//! event condition is met.
//! - \b RTC_C_OSCILLATOR_FAULT_INTERRUPT - asserts if there is a
//! problem with the 32kHz oscillator, while the RTC is running.
//!
//! \return None
//
//*****************************************************************************
extern void RTC_C_clearInterrupt(uint16_t baseAddress,
uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Convert the given BCD value to binary format
//!
//! This function converts BCD values to binary format. This API uses the
//! hardware registers to perform the conversion rather than a software method.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param valueToConvert is the raw value in BCD format to convert to Binary.
//! \n Modified bits are \b BCD2BIN of \b BCD2BIN register.
//!
//! \return The binary version of the input parameter
//
//*****************************************************************************
extern uint16_t RTC_C_convertBCDToBinary(uint16_t baseAddress,
uint16_t valueToConvert);
//*****************************************************************************
//
//! \brief Convert the given binary value to BCD format
//!
//! This function converts binary values to BCD format. This API uses the
//! hardware registers to perform the conversion rather than a software method.
//!
//! \param baseAddress is the base address of the RTC_C module.
//! \param valueToConvert is the raw value in Binary format to convert to BCD.
//! \n Modified bits are \b BIN2BCD of \b BIN2BCD register.
//!
//! \return The BCD version of the valueToConvert parameter
//
//*****************************************************************************
extern uint16_t RTC_C_convertBinaryToBCD(uint16_t baseAddress,
uint16_t valueToConvert);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_RTC_C_H__

View File

@@ -0,0 +1,270 @@
//*****************************************************************************
//
// sd24_b.c - Driver for the sd24_b Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup sd24_b_api sd24_b
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_SD24_B__
#include "sd24_b.h"
#include <assert.h>
void SD24_B_init(uint16_t baseAddress, SD24_B_initParam *param)
{
// Reset all interrupts and flags
HWREG16(baseAddress + OFS_SD24BIE) &= 0x0000; //Reset ALL interrupt enables
HWREG16(baseAddress + OFS_SD24BIFG) &= 0x0000; //Reset ALL interrupt flags
HWREG16(baseAddress + OFS_SD24BTRGCTL) &= ~(SD24TRGIE | SD24TRGIFG);
// Turn off all group conversions
HWREG16(baseAddress + OFS_SD24BCTL1) &= ~(SD24GRP0SC | SD24GRP1SC
| SD24GRP2SC | SD24GRP3SC);
// Configure SD24_B
HWREG16(baseAddress + OFS_SD24BCTL0) &= ~((SD24DIV4 | SD24DIV3 | SD24DIV2
| SD24DIV1 | SD24DIV0) | SD24PDIV_7 | SD24SSEL_3 | SD24REFS);
HWREG16(baseAddress + OFS_SD24BCTL0) |= (param->clockSourceSelect |
param->clockPreDivider | param->clockDivider | param->referenceSelect);
return;
}
void SD24_B_initConverter(uint16_t baseAddress,
SD24_B_initConverterParam *param)
{
uint16_t address = baseAddress + (OFS_SD24BCCTL0 + (param->converter * 0x08));
// Clearing previous settings for configuration
HWREG16(address) &= ~(SD24ALGN | SD24SNGL | SD24SCS__GROUP3);
HWREG16(address) |= (param->alignment | param->startSelect |
(((uint16_t) param->conversionMode) << 8));
}
void SD24_B_initConverterAdvanced(uint16_t baseAddress,
SD24_B_initConverterAdvancedParam *param)
{
// Getting correct SD24BCCTLx register
uint16_t address = baseAddress + (OFS_SD24BCCTL0 + (param->converter * 0x08));
// Clearing previous settings for configuration
HWREG16(address) &= ~(SD24ALGN | SD24SNGL | SD24DF1 | SD24DF0 | SD24SCS__GROUP3 );
HWREG16(address) |= (param->alignment | param->startSelect | param->dataFormat |
(((uint16_t) param->conversionMode) << 8));
// Getting correct SDBINTCTLx register
address = baseAddress + (OFS_SD24BINCTL0 + (param->converter * 0x08));
// Clearing previous settings for configuration
HWREG16(address) &= ~(SD24GAIN_128 | SD24INTDLY_3);
HWREG16(address) |= (param->gain | param->sampleDelay);
// Getting correct SDBOSRx register
address = baseAddress + (OFS_SD24BOSR0 + (param->converter * 0x08));
// Clearing previous settings for configuration
HWREG16(address) &= ~(OSR10 | OSR9 | OSR8 | OSR7 | OSR6 | OSR5 | OSR4 |
OSR3 | OSR2 | OSR1 | OSR0);
HWREG16(address) |= param->oversampleRatio;
}
void SD24_B_setConverterDataFormat(uint16_t baseAddress,
uint8_t converter,
uint8_t dataFormat) {
uint16_t address = baseAddress + (OFS_SD24BCCTL0_L +
(converter * 0x08));
// Clearing previous settings for configuration
HWREG8(address) &= ~(SD24DF0 | SD24DF1);
HWREG8(address) |= dataFormat;
}
void SD24_B_startGroupConversion(uint16_t baseAddress,
uint8_t group)
{
switch(group) {
case SD24_B_GROUP0:
HWREG16(baseAddress + OFS_SD24BCTL1) |= SD24GRP0SC; break;
case SD24_B_GROUP1:
HWREG16(baseAddress + OFS_SD24BCTL1) |= SD24GRP1SC; break;
case SD24_B_GROUP2:
HWREG16(baseAddress + OFS_SD24BCTL1) |= SD24GRP2SC; break;
case SD24_B_GROUP3:
HWREG16(baseAddress + OFS_SD24BCTL1) |= SD24GRP3SC; break;
}
}
void SD24_B_stopGroupConversion(uint16_t baseAddress,
uint8_t group)
{
switch(group) {
case SD24_B_GROUP0:
HWREG16(baseAddress + OFS_SD24BCTL1) &= ~(SD24GRP0SC); break;
case SD24_B_GROUP1:
HWREG16(baseAddress + OFS_SD24BCTL1) &= ~(SD24GRP1SC); break;
case SD24_B_GROUP2:
HWREG16(baseAddress + OFS_SD24BCTL1) &= ~(SD24GRP2SC); break;
case SD24_B_GROUP3:
HWREG16(baseAddress + OFS_SD24BCTL1) &= ~(SD24GRP3SC); break;
}
}
void SD24_B_startConverterConversion(uint16_t baseAddress,
uint8_t converter)
{
uint16_t address = baseAddress + (OFS_SD24BCCTL0 + (converter * 0x08));
// Clearing trigger generation select
HWREG16(address) &= ~(SD24SCS_7);
// Setting SD24SC bit to start conversion
HWREG16(address) |= SD24SC;
}
void SD24_B_stopConverterConversion(uint16_t baseAddress,
uint8_t converter)
{
uint16_t address = baseAddress + (OFS_SD24BCCTL0 + (converter * 0x08));
// Clearing trigger generation select
HWREG16(address) &= ~(SD24SCS_7);
// Setting SD24SC bit to start conversion
HWREG16(address) &= ~(SD24SC);
}
void SD24_B_configureDMATrigger(uint16_t baseAddress,
uint16_t interruptFlag)
{
// Clearing previous settings
HWREG16(baseAddress + OFS_SD24BCTL1) &= ~(SD24DMA3 | SD24DMA2 |
SD24DMA1 | SD24DMA0);
HWREG16(baseAddress + OFS_SD24BCTL1) |= interruptFlag;
}
void SD24_B_setInterruptDelay(uint16_t baseAddress,
uint8_t converter,
uint8_t sampleDelay)
{
uint16_t address = baseAddress + (OFS_SD24BINCTL0 + (converter * 0x08));
// Clear previous settings
HWREG16(address) &= ~(SD24INTDLY_3);
HWREG16(address) |= sampleDelay;
}
void SD24_B_setConversionDelay(uint16_t baseAddress,
uint8_t converter,
uint16_t cycleDelay)
{
uint16_t address = baseAddress + (OFS_SD24BPRE0 + (converter * 0x08));
// Clear previous settings
HWREG16(address) &= ~(0x3FF);
HWREG16(address) |= cycleDelay;
}
void SD24_B_setOversampling(uint16_t baseAddress,
uint8_t converter,
uint16_t oversampleRatio)
{
uint16_t address = baseAddress + (OFS_SD24BOSR0 + (converter * 0x08));
// Clear previous settings
HWREG16(address) &= ~(OSR10 | OSR9 | OSR8 | OSR7 | OSR6 | OSR5 | OSR4 |
OSR3 | OSR2 | OSR1 | OSR0);
HWREG16(address) |= oversampleRatio;
}
void SD24_B_setGain(uint16_t baseAddress,
uint8_t converter,
uint8_t gain)
{
uint16_t address = baseAddress + (OFS_SD24BINCTL0 + (converter * 0x08));
// Clear previous settings
HWREG16(address) &= ~(SD24GAIN_128);
HWREG16(address) |= gain;
}
uint32_t SD24_B_getResults(uint16_t baseAddress,
uint8_t converter)
{
// Calculating address to low word
uint16_t address = baseAddress + (OFS_SD24BMEML0 + (converter * 0x04));
// Getting low word result
uint16_t lowResult = HWREG16(address);
// Getting high word result and concatenate with low word
uint32_t result = (((uint32_t) HWREG16(address + 0x02) ) << 16) + lowResult;
return result;
}
uint16_t SD24_B_getHighWordResults(uint16_t baseAddress,
uint8_t converter)
{
// Calculating address
uint16_t address = baseAddress + (OFS_SD24BMEMH0 + (converter * 0x04));
// Getting high word result
uint16_t result = HWREG16(address);
return result;
}
void SD24_B_enableInterrupt (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
//Enable Interrupt
HWREG16(baseAddress + OFS_SD24BIE) |= (mask << converter);
}
void SD24_B_disableInterrupt (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
HWREG16(baseAddress + OFS_SD24BIE) &= ~(mask << converter);
}
void SD24_B_clearInterrupt (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
HWREG16(baseAddress + OFS_SD24BIFG) &= ~(mask << converter);
}
uint16_t SD24_B_getInterruptStatus (uint16_t baseAddress,
uint8_t converter,
uint16_t mask)
{
return ( HWREG16(baseAddress + OFS_SD24BIFG) & (mask << converter) );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for sd24_b_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,975 @@
//*****************************************************************************
//
// sd24_b.h - Driver for the SD24_B Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_SD24_B_H__
#define __MSP430WARE_SD24_B_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_SD24_B__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the SD24_B_init() function as the param parameter.
//
//*****************************************************************************
typedef struct SD24_B_initParam {
//! Selects the clock that will be used as the SD24_B core
//! \n Valid values are:
//! - \b SD24_B_CLOCKSOURCE_MCLK [Default]
//! - \b SD24_B_CLOCKSOURCE_SMCLK
//! - \b SD24_B_CLOCKSOURCE_ACLK
//! - \b SD24_B_CLOCKSOURCE_SD24CLK
uint16_t clockSourceSelect;
//! Selects the amount that the clock will be predivided
//! \n Valid values are:
//! - \b SD24_B_PRECLOCKDIVIDER_1 [Default]
//! - \b SD24_B_PRECLOCKDIVIDER_2
//! - \b SD24_B_PRECLOCKDIVIDER_4
//! - \b SD24_B_PRECLOCKDIVIDER_8
//! - \b SD24_B_PRECLOCKDIVIDER_16
//! - \b SD24_B_PRECLOCKDIVIDER_32
//! - \b SD24_B_PRECLOCKDIVIDER_64
//! - \b SD24_B_PRECLOCKDIVIDER_128
uint16_t clockPreDivider;
//! Selects the amount that the clock will be divided.
//! \n Valid values are:
//! - \b SD24_B_CLOCKDIVIDER_1 [Default]
//! - \b SD24_B_CLOCKDIVIDER_2
//! - \b SD24_B_CLOCKDIVIDER_3
//! - \b SD24_B_CLOCKDIVIDER_4
//! - \b SD24_B_CLOCKDIVIDER_5
//! - \b SD24_B_CLOCKDIVIDER_6
//! - \b SD24_B_CLOCKDIVIDER_7
//! - \b SD24_B_CLOCKDIVIDER_8
//! - \b SD24_B_CLOCKDIVIDER_9
//! - \b SD24_B_CLOCKDIVIDER_10
//! - \b SD24_B_CLOCKDIVIDER_11
//! - \b SD24_B_CLOCKDIVIDER_12
//! - \b SD24_B_CLOCKDIVIDER_13
//! - \b SD24_B_CLOCKDIVIDER_14
//! - \b SD24_B_CLOCKDIVIDER_15
//! - \b SD24_B_CLOCKDIVIDER_16
//! - \b SD24_B_CLOCKDIVIDER_17
//! - \b SD24_B_CLOCKDIVIDER_18
//! - \b SD24_B_CLOCKDIVIDER_19
//! - \b SD24_B_CLOCKDIVIDER_20
//! - \b SD24_B_CLOCKDIVIDER_21
//! - \b SD24_B_CLOCKDIVIDER_22
//! - \b SD24_B_CLOCKDIVIDER_23
//! - \b SD24_B_CLOCKDIVIDER_24
//! - \b SD24_B_CLOCKDIVIDER_25
//! - \b SD24_B_CLOCKDIVIDER_26
//! - \b SD24_B_CLOCKDIVIDER_27
//! - \b SD24_B_CLOCKDIVIDER_28
//! - \b SD24_B_CLOCKDIVIDER_29
//! - \b SD24_B_CLOCKDIVIDER_30
//! - \b SD24_B_CLOCKDIVIDER_31
//! - \b SD24_B_CLOCKDIVIDER_32
uint16_t clockDivider;
//! Selects the reference source for the SD24_B core
//! \n Valid values are:
//! - \b SD24_B_REF_EXTERNAL [Default]
//! - \b SD24_B_REF_INTERNAL
uint16_t referenceSelect;
} SD24_B_initParam;
//*****************************************************************************
//
//! \brief Used in the SD24_B_initConverter() function as the param parameter.
//
//*****************************************************************************
typedef struct SD24_B_initConverterParam {
//! Selects the converter that will be configured. Check datasheet for
//! available converters on device.
//! \n Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
uint8_t converter;
//! Selects how the data will be aligned in result
//! \n Valid values are:
//! - \b SD24_B_ALIGN_RIGHT [Default]
//! - \b SD24_B_ALIGN_LEFT
uint8_t alignment;
//! Selects what will trigger the start of the converter
//! \n Valid values are:
//! - \b SD24_B_CONVERSION_SELECT_SD24SC [Default]
//! - \b SD24_B_CONVERSION_SELECT_EXT1
//! - \b SD24_B_CONVERSION_SELECT_EXT2
//! - \b SD24_B_CONVERSION_SELECT_EXT3
//! - \b SD24_B_CONVERSION_SELECT_GROUP0
//! - \b SD24_B_CONVERSION_SELECT_GROUP1
//! - \b SD24_B_CONVERSION_SELECT_GROUP2
//! - \b SD24_B_CONVERSION_SELECT_GROUP3
uint8_t startSelect;
//! Determines whether the converter will do continuous samples or a single
//! sample
//! \n Valid values are:
//! - \b SD24_B_CONTINUOUS_MODE [Default]
//! - \b SD24_B_SINGLE_MODE
uint8_t conversionMode;
} SD24_B_initConverterParam;
//*****************************************************************************
//
//! \brief Used in the SD24_B_initConverterAdvanced() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct SD24_B_initConverterAdvancedParam {
//! Selects the converter that will be configured. Check datasheet for
//! available converters on device.
//! \n Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
uint8_t converter;
//! Selects how the data will be aligned in result
//! \n Valid values are:
//! - \b SD24_B_ALIGN_RIGHT [Default]
//! - \b SD24_B_ALIGN_LEFT
uint8_t alignment;
//! Selects what will trigger the start of the converter
//! \n Valid values are:
//! - \b SD24_B_CONVERSION_SELECT_SD24SC [Default]
//! - \b SD24_B_CONVERSION_SELECT_EXT1
//! - \b SD24_B_CONVERSION_SELECT_EXT2
//! - \b SD24_B_CONVERSION_SELECT_EXT3
//! - \b SD24_B_CONVERSION_SELECT_GROUP0
//! - \b SD24_B_CONVERSION_SELECT_GROUP1
//! - \b SD24_B_CONVERSION_SELECT_GROUP2
//! - \b SD24_B_CONVERSION_SELECT_GROUP3
uint8_t startSelect;
//! Determines whether the converter will do continuous samples or a single
//! sample
//! \n Valid values are:
//! - \b SD24_B_CONTINUOUS_MODE [Default]
//! - \b SD24_B_SINGLE_MODE
uint8_t conversionMode;
//! Selects how the data format of the results
//! \n Valid values are:
//! - \b SD24_B_DATA_FORMAT_BINARY [Default]
//! - \b SD24_B_DATA_FORMAT_2COMPLEMENT
uint8_t dataFormat;
//! Selects the delay for the interrupt
//! \n Valid values are:
//! - \b SD24_B_FOURTH_SAMPLE_INTERRUPT [Default]
//! - \b SD24_B_THIRD_SAMPLE_INTERRUPT
//! - \b SD24_B_SECOND_SAMPLE_INTERRUPT
//! - \b SD24_B_FIRST_SAMPLE_INTERRUPT
uint8_t sampleDelay;
//! Selects oversampling ratio for the converter
//! \n Valid values are:
//! - \b SD24_B_OVERSAMPLE_32
//! - \b SD24_B_OVERSAMPLE_64
//! - \b SD24_B_OVERSAMPLE_128
//! - \b SD24_B_OVERSAMPLE_256
//! - \b SD24_B_OVERSAMPLE_512
//! - \b SD24_B_OVERSAMPLE_1024
uint16_t oversampleRatio;
//! Selects the gain for the converter
//! \n Valid values are:
//! - \b SD24_B_GAIN_1 [Default]
//! - \b SD24_B_GAIN_2
//! - \b SD24_B_GAIN_4
//! - \b SD24_B_GAIN_8
//! - \b SD24_B_GAIN_16
//! - \b SD24_B_GAIN_32
//! - \b SD24_B_GAIN_64
//! - \b SD24_B_GAIN_128
uint8_t gain;
} SD24_B_initConverterAdvancedParam;
//*****************************************************************************
//
// The following are values that can be passed to the clockSourceSelect
// parameter for functions: SD24_B_init(); the param parameter for functions:
// SD24_B_init().
//
//*****************************************************************************
#define SD24_B_CLOCKSOURCE_MCLK (SD24SSEL__MCLK)
#define SD24_B_CLOCKSOURCE_SMCLK (SD24SSEL__SMCLK)
#define SD24_B_CLOCKSOURCE_ACLK (SD24SSEL__ACLK)
#define SD24_B_CLOCKSOURCE_SD24CLK (SD24SSEL__SD24CLK)
//*****************************************************************************
//
// The following are values that can be passed to the referenceSelect parameter
// for functions: SD24_B_init(); the param parameter for functions:
// SD24_B_init().
//
//*****************************************************************************
#define SD24_B_REF_EXTERNAL (0x00)
#define SD24_B_REF_INTERNAL (SD24REFS)
//*****************************************************************************
//
// The following are values that can be passed to the clockPreDivider parameter
// for functions: SD24_B_init(); the param parameter for functions:
// SD24_B_init().
//
//*****************************************************************************
#define SD24_B_PRECLOCKDIVIDER_1 (SD24PDIV_0)
#define SD24_B_PRECLOCKDIVIDER_2 (SD24PDIV_1)
#define SD24_B_PRECLOCKDIVIDER_4 (SD24PDIV_2)
#define SD24_B_PRECLOCKDIVIDER_8 (SD24PDIV_3)
#define SD24_B_PRECLOCKDIVIDER_16 (SD24PDIV_4)
#define SD24_B_PRECLOCKDIVIDER_32 (SD24PDIV_5)
#define SD24_B_PRECLOCKDIVIDER_64 (SD24PDIV_6)
#define SD24_B_PRECLOCKDIVIDER_128 (SD24PDIV_7)
//*****************************************************************************
//
// The following are values that can be passed to the clockDivider parameter
// for functions: SD24_B_init(); the param parameter for functions:
// SD24_B_init().
//
//*****************************************************************************
#define SD24_B_CLOCKDIVIDER_1 (0x00)
#define SD24_B_CLOCKDIVIDER_2 (SD24DIV0)
#define SD24_B_CLOCKDIVIDER_3 (SD24DIV1)
#define SD24_B_CLOCKDIVIDER_4 (SD24DIV1 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_5 (SD24DIV2)
#define SD24_B_CLOCKDIVIDER_6 (SD24DIV2 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_7 (SD24DIV2 | SD24DIV1)
#define SD24_B_CLOCKDIVIDER_8 (SD24DIV2 | SD24DIV1 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_9 (SD24DIV3)
#define SD24_B_CLOCKDIVIDER_10 (SD24DIV3 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_11 (SD24DIV3 | SD24DIV1)
#define SD24_B_CLOCKDIVIDER_12 (SD24DIV3 | SD24DIV1 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_13 (SD24DIV3 | SD24DIV2)
#define SD24_B_CLOCKDIVIDER_14 (SD24DIV3 | SD24DIV2 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_15 (SD24DIV3 | SD24DIV2 | SD24DIV1)
#define SD24_B_CLOCKDIVIDER_16 (SD24DIV3 | SD24DIV2 | SD24DIV1 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_17 (SD24DIV4)
#define SD24_B_CLOCKDIVIDER_18 (SD24DIV4 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_19 (SD24DIV4 | SD24DIV1)
#define SD24_B_CLOCKDIVIDER_20 (SD24DIV4 | SD24DIV1 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_21 (SD24DIV4 | SD24DIV2)
#define SD24_B_CLOCKDIVIDER_22 (SD24DIV4 | SD24DIV2 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_23 (SD24DIV4 | SD24DIV2 | SD24DIV1)
#define SD24_B_CLOCKDIVIDER_24 (SD24DIV4 | SD24DIV2 | SD24DIV1 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_25 (SD24DIV4 | SD24DIV3)
#define SD24_B_CLOCKDIVIDER_26 (SD24DIV4 | SD24DIV3 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_27 (SD24DIV4 | SD24DIV3 | SD24DIV1)
#define SD24_B_CLOCKDIVIDER_28 (SD24DIV4 | SD24DIV3 | SD24DIV1 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_29 (SD24DIV4 | SD24DIV3 | SD24DIV2)
#define SD24_B_CLOCKDIVIDER_30 (SD24DIV4 | SD24DIV3 | SD24DIV2 | SD24DIV0)
#define SD24_B_CLOCKDIVIDER_31 (SD24DIV4 | SD24DIV3 | SD24DIV2 | SD24DIV1)
#define SD24_B_CLOCKDIVIDER_32 \
(SD24DIV4 | SD24DIV3 | SD24DIV2 | SD24DIV1 | SD24DIV0)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: SD24_B_initConverter(), and SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_CONTINUOUS_MODE (0x00)
#define SD24_B_SINGLE_MODE (SD24SNGL_H)
//*****************************************************************************
//
// The following are values that can be passed to the converter parameter for
// functions: SD24_B_setConverterDataFormat(),
// SD24_B_startConverterConversion(), SD24_B_stopConverterConversion(),
// SD24_B_setInterruptDelay(), SD24_B_setConversionDelay(),
// SD24_B_setOversampling(), SD24_B_setGain(), SD24_B_getResults(),
// SD24_B_getHighWordResults(), SD24_B_enableInterrupt(),
// SD24_B_disableInterrupt(), SD24_B_clearInterrupt(), and
// SD24_B_getInterruptStatus(); the param parameter for functions:
// SD24_B_initConverter(), and SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_CONVERTER_0 0
#define SD24_B_CONVERTER_1 1
#define SD24_B_CONVERTER_2 2
#define SD24_B_CONVERTER_3 3
#define SD24_B_CONVERTER_4 4
#define SD24_B_CONVERTER_5 5
#define SD24_B_CONVERTER_6 6
#define SD24_B_CONVERTER_7 7
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: SD24_B_initConverter(), and SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_ALIGN_RIGHT (0x00)
#define SD24_B_ALIGN_LEFT (SD24ALGN)
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: SD24_B_initConverter(), and SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_CONVERSION_SELECT_SD24SC (SD24SCS__SD24SC)
#define SD24_B_CONVERSION_SELECT_EXT1 (SD24SCS__EXT1)
#define SD24_B_CONVERSION_SELECT_EXT2 (SD24SCS__EXT2)
#define SD24_B_CONVERSION_SELECT_EXT3 (SD24SCS__EXT3)
#define SD24_B_CONVERSION_SELECT_GROUP0 (SD24SCS__GROUP0)
#define SD24_B_CONVERSION_SELECT_GROUP1 (SD24SCS__GROUP1)
#define SD24_B_CONVERSION_SELECT_GROUP2 (SD24SCS__GROUP2)
#define SD24_B_CONVERSION_SELECT_GROUP3 (SD24SCS__GROUP3)
//*****************************************************************************
//
// The following are values that can be passed to the oversampleRatio parameter
// for functions: SD24_B_setOversampling(); the param parameter for functions:
// SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_OVERSAMPLE_32 (OSR__32)
#define SD24_B_OVERSAMPLE_64 (OSR__64)
#define SD24_B_OVERSAMPLE_128 (OSR__128)
#define SD24_B_OVERSAMPLE_256 (OSR__256)
#define SD24_B_OVERSAMPLE_512 (OSR__512)
#define SD24_B_OVERSAMPLE_1024 (OSR__1024)
//*****************************************************************************
//
// The following are values that can be passed to the dataFormat parameter for
// functions: SD24_B_setConverterDataFormat(); the param parameter for
// functions: SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_DATA_FORMAT_BINARY (SD24DF_0)
#define SD24_B_DATA_FORMAT_2COMPLEMENT (SD24DF_1)
//*****************************************************************************
//
// The following are values that can be passed to the gain parameter for
// functions: SD24_B_setGain(); the param parameter for functions:
// SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_GAIN_1 (SD24GAIN_1)
#define SD24_B_GAIN_2 (SD24GAIN_2)
#define SD24_B_GAIN_4 (SD24GAIN_4)
#define SD24_B_GAIN_8 (SD24GAIN_8)
#define SD24_B_GAIN_16 (SD24GAIN_16)
#define SD24_B_GAIN_32 (SD24GAIN_32)
#define SD24_B_GAIN_64 (SD24GAIN_64)
#define SD24_B_GAIN_128 (SD24GAIN_128)
//*****************************************************************************
//
// The following are values that can be passed to the sampleDelay parameter for
// functions: SD24_B_setInterruptDelay(); the param parameter for functions:
// SD24_B_initConverterAdvanced().
//
//*****************************************************************************
#define SD24_B_FOURTH_SAMPLE_INTERRUPT (SD24INTDLY_0)
#define SD24_B_THIRD_SAMPLE_INTERRUPT (SD24INTDLY_1)
#define SD24_B_SECOND_SAMPLE_INTERRUPT (SD24INTDLY_2)
#define SD24_B_FIRST_SAMPLE_INTERRUPT (SD24INTDLY_3)
//*****************************************************************************
//
// The following are values that can be passed to the group parameter for
// functions: SD24_B_startGroupConversion(), and SD24_B_stopGroupConversion().
//
//*****************************************************************************
#define SD24_B_GROUP0 0
#define SD24_B_GROUP1 1
#define SD24_B_GROUP2 2
#define SD24_B_GROUP3 3
//*****************************************************************************
//
// The following are values that can be passed to the interruptFlag parameter
// for functions: SD24_B_configureDMATrigger().
//
//*****************************************************************************
#define SD24_B_DMA_TRIGGER_IFG0 (SD24DMA_0)
#define SD24_B_DMA_TRIGGER_IFG1 (SD24DMA_1)
#define SD24_B_DMA_TRIGGER_IFG2 (SD24DMA_2)
#define SD24_B_DMA_TRIGGER_IFG3 (SD24DMA_3)
#define SD24_B_DMA_TRIGGER_IFG4 (SD24DMA_4)
#define SD24_B_DMA_TRIGGER_IFG5 (SD24DMA_5)
#define SD24_B_DMA_TRIGGER_IFG6 (SD24DMA_6)
#define SD24_B_DMA_TRIGGER_IFG7 (SD24DMA_7)
#define SD24_B_DMA_TRIGGER_TRGIFG (SD24DMA_8)
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: SD24_B_enableInterrupt(), SD24_B_disableInterrupt(),
// SD24_B_clearInterrupt(), and SD24_B_getInterruptStatus() as well as returned
// by the SD24_B_getInterruptStatus() function.
//
//*****************************************************************************
#define SD24_B_CONVERTER_INTERRUPT SD24IE0
#define SD24_B_CONVERTER_OVERFLOW_INTERRUPT SD24OVIE0
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the SD24_B Module
//!
//! This function initializes the SD24_B module sigma-delta analog-to-digital
//! conversions. Specifically the function sets up the clock source for the
//! SD24_B core to use for conversions. Upon completion of the initialization
//! the SD24_B interrupt registers will be reset and the given parameters will
//! be set. The converter configuration settings are independent of this
//! function. The values you choose for the clock divider and predivider are
//! used to determine the effective clock frequency. The formula used is:
//! f_sd24 = f_clk /(divider * predivider)
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param param is the pointer to struct for initialization.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_init(uint16_t baseAddress,
SD24_B_initParam *param);
//*****************************************************************************
//
//! \brief Configure SD24_B converter
//!
//! This function initializes a converter of the SD24_B module. Upon completion
//! the converter will be ready for a conversion and can be started with the
//! SD24_B_startGroupConversion() or SD24_B_startConverterConversion()
//! depending on the startSelect parameter. Additional configuration such as
//! data format can be configured in SD24_B_setConverterDataFormat().
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param param is the pointer to struct for converter configuration.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_initConverter(uint16_t baseAddress,
SD24_B_initConverterParam *param);
//*****************************************************************************
//
//! \brief Configure SD24_B converter - Advanced Configure
//!
//! This function initializes a converter of the SD24_B module. Upon completion
//! the converter will be ready for a conversion and can be started with the
//! SD24_B_startGroupConversion() or SD24_B_startConverterConversion()
//! depending on the startSelect parameter.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param param is the pointer to struct for converter advanced configuration.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_initConverterAdvanced(uint16_t baseAddress,
SD24_B_initConverterAdvancedParam *param);
//*****************************************************************************
//
//! \brief Set SD24_B converter data format
//!
//! This function sets the converter format so that the resulting data can be
//! viewed in either binary or 2's complement.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter that will be configured. Check
//! datasheet for available converters on device.
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param dataFormat selects how the data format of the results
//! Valid values are:
//! - \b SD24_B_DATA_FORMAT_BINARY [Default]
//! - \b SD24_B_DATA_FORMAT_2COMPLEMENT
//! \n Modified bits are \b SD24DFx of \b SD24BCCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_setConverterDataFormat(uint16_t baseAddress,
uint8_t converter,
uint8_t dataFormat);
//*****************************************************************************
//
//! \brief Start Conversion Group
//!
//! This function starts all the converters that are associated with a group.
//! To set a converter to a group use the SD24_B_configureConverter() function.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param group selects the group that will be started
//! Valid values are:
//! - \b SD24_B_GROUP0
//! - \b SD24_B_GROUP1
//! - \b SD24_B_GROUP2
//! - \b SD24_B_GROUP3
//! \n Modified bits are \b SD24DGRPxSC of \b SD24BCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_startGroupConversion(uint16_t baseAddress,
uint8_t group);
//*****************************************************************************
//
//! \brief Stop Conversion Group
//!
//! This function stops all the converters that are associated with a group. To
//! set a converter to a group use the SD24_B_configureConverter() function.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param group selects the group that will be stopped
//! Valid values are:
//! - \b SD24_B_GROUP0
//! - \b SD24_B_GROUP1
//! - \b SD24_B_GROUP2
//! - \b SD24_B_GROUP3
//! \n Modified bits are \b SD24DGRPxSC of \b SD24BCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_stopGroupConversion(uint16_t baseAddress,
uint8_t group);
//*****************************************************************************
//
//! \brief Start Conversion for Converter
//!
//! This function starts a single converter.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter that will be started
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \n Modified bits are \b SD24SC of \b SD24BCCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_startConverterConversion(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Stop Conversion for Converter
//!
//! This function stops a single converter.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter that will be stopped
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \n Modified bits are \b SD24SC of \b SD24BCCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_stopConverterConversion(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Configures the converter that triggers a DMA transfer
//!
//! This function chooses which interrupt will trigger a DMA transfer.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param interruptFlag selects the converter interrupt that triggers a DMA
//! transfer.
//! Valid values are:
//! - \b SD24_B_DMA_TRIGGER_IFG0
//! - \b SD24_B_DMA_TRIGGER_IFG1
//! - \b SD24_B_DMA_TRIGGER_IFG2
//! - \b SD24_B_DMA_TRIGGER_IFG3
//! - \b SD24_B_DMA_TRIGGER_IFG4
//! - \b SD24_B_DMA_TRIGGER_IFG5
//! - \b SD24_B_DMA_TRIGGER_IFG6
//! - \b SD24_B_DMA_TRIGGER_IFG7
//! - \b SD24_B_DMA_TRIGGER_TRGIFG
//! \n Modified bits are \b SD24DMAx of \b SD24BCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_configureDMATrigger(uint16_t baseAddress,
uint16_t interruptFlag);
//*****************************************************************************
//
//! \brief Configures the delay for an interrupt to trigger
//!
//! This function configures the delay for the first interrupt service request
//! for the corresponding converter. This feature delays the interrupt request
//! for a completed conversion by up to four conversion cycles allowing the
//! digital filter to settle prior to generating an interrupt request.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter that will be stopped
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param sampleDelay selects the delay for the interrupt
//! Valid values are:
//! - \b SD24_B_FOURTH_SAMPLE_INTERRUPT [Default]
//! - \b SD24_B_THIRD_SAMPLE_INTERRUPT
//! - \b SD24_B_SECOND_SAMPLE_INTERRUPT
//! - \b SD24_B_FIRST_SAMPLE_INTERRUPT
//! \n Modified bits are \b SD24INTDLYx of \b SD24INCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_setInterruptDelay(uint16_t baseAddress,
uint8_t converter,
uint8_t sampleDelay);
//*****************************************************************************
//
//! \brief Configures the delay for the conversion start
//!
//! This function configures the delay for the specified converter start.
//! Please note the delay should be written before conversion or after
//! corresponding conversion is completed. If no delay at start of conversion
//! is desired, a previously written non-zero value must be changed to zero
//! before starting the conversion.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter that will be delayed
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param cycleDelay is the clock cycles to delay ranging from 0 to 1023.
//! \n Modified bits are \b SD24PREx of \b SD24BPREx register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_setConversionDelay(uint16_t baseAddress,
uint8_t converter,
uint16_t cycleDelay);
//*****************************************************************************
//
//! \brief Configures the oversampling ratio for a converter
//!
//! This function configures the oversampling ratio for a given converter.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter that will be configured
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param oversampleRatio selects oversampling ratio for the converter
//! Valid values are:
//! - \b SD24_B_OVERSAMPLE_32
//! - \b SD24_B_OVERSAMPLE_64
//! - \b SD24_B_OVERSAMPLE_128
//! - \b SD24_B_OVERSAMPLE_256
//! - \b SD24_B_OVERSAMPLE_512
//! - \b SD24_B_OVERSAMPLE_1024
//! \n Modified bits are \b SD24OSRx of \b SD24BOSRx register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_setOversampling(uint16_t baseAddress,
uint8_t converter,
uint16_t oversampleRatio);
//*****************************************************************************
//
//! \brief Configures the gain for the converter
//!
//! This function configures the gain for a single converter.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter that will be configured
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param gain selects the gain for the converter
//! Valid values are:
//! - \b SD24_B_GAIN_1 [Default]
//! - \b SD24_B_GAIN_2
//! - \b SD24_B_GAIN_4
//! - \b SD24_B_GAIN_8
//! - \b SD24_B_GAIN_16
//! - \b SD24_B_GAIN_32
//! - \b SD24_B_GAIN_64
//! - \b SD24_B_GAIN_128
//! \n Modified bits are \b SD24GAINx of \b SD24BINCTLx register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_setGain(uint16_t baseAddress,
uint8_t converter,
uint8_t gain);
//*****************************************************************************
//
//! \brief Returns the results for a converter
//!
//! This function gets the results from the SD24BMEMLx and SD24MEMHx registers
//! and concatenates them to form a long. The actual result is a maximum 24
//! bits.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter who's results will be returned
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//!
//! \return Result of conversion
//
//*****************************************************************************
extern uint32_t SD24_B_getResults(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Returns the high word results for a converter
//!
//! This function gets the results from the SD24MEMHx register and returns it.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter selects the converter who's results will be returned
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//!
//! \return Result of conversion
//
//*****************************************************************************
extern uint16_t SD24_B_getHighWordResults(uint16_t baseAddress,
uint8_t converter);
//*****************************************************************************
//
//! \brief Enables interrupts for the SD24_B Module
//!
//! This function enables interrupts for the SD24_B module. Does not clear
//! interrupt flags.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param mask is the bit mask of the converter interrupt sources to be
//! enabled.
//! Mask value is the logical OR of any of the following:
//! - \b SD24_B_CONVERTER_INTERRUPT
//! - \b SD24_B_CONVERTER_OVERFLOW_INTERRUPT
//! \n Modified bits are \b SD24OVIEx of \b SD24BIE register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_enableInterrupt(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
//! \brief Disables interrupts for the SD24_B Module
//!
//! This function disables interrupts for the SD24_B module.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param mask is the bit mask of the converter interrupt sources to be
//! disabled.
//! Mask value is the logical OR of any of the following:
//! - \b SD24_B_CONVERTER_INTERRUPT
//! - \b SD24_B_CONVERTER_OVERFLOW_INTERRUPT
//! \n Modified bits are \b SD24OVIEx of \b SD24BIE register.
//!
//! Modified bits of \b SD24BIE register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_disableInterrupt(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
//! \brief Clears interrupts for the SD24_B Module
//!
//! This function clears interrupt flags for the SD24_B module.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param mask is the bit mask of the converter interrupt sources to clear.
//! Mask value is the logical OR of any of the following:
//! - \b SD24_B_CONVERTER_INTERRUPT
//! - \b SD24_B_CONVERTER_OVERFLOW_INTERRUPT
//! \n Modified bits are \b SD24OVIFGx of \b SD24BIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void SD24_B_clearInterrupt(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
//! \brief Returns the interrupt status for the SD24_B Module
//!
//! This function returns interrupt flag statuses for the SD24_B module.
//!
//! \param baseAddress is the base address of the SD24_B module.
//! \param converter is the selected converter.
//! Valid values are:
//! - \b SD24_B_CONVERTER_0
//! - \b SD24_B_CONVERTER_1
//! - \b SD24_B_CONVERTER_2
//! - \b SD24_B_CONVERTER_3
//! - \b SD24_B_CONVERTER_4
//! - \b SD24_B_CONVERTER_5
//! - \b SD24_B_CONVERTER_6
//! - \b SD24_B_CONVERTER_7
//! \param mask is the bit mask of the converter interrupt sources to return.
//! Mask value is the logical OR of any of the following:
//! - \b SD24_B_CONVERTER_INTERRUPT
//! - \b SD24_B_CONVERTER_OVERFLOW_INTERRUPT
//!
//! \return Logical OR of any of the following:
//! - \b SD24_B_CONVERTER_INTERRUPT
//! - \b SD24_B_CONVERTER_OVERFLOW_INTERRUPT
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint16_t SD24_B_getInterruptStatus(uint16_t baseAddress,
uint8_t converter,
uint16_t mask);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_SD24_B_H__

View File

@@ -0,0 +1,65 @@
//*****************************************************************************
//
// sfr.c - Driver for the sfr Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup sfr_api sfr
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_SFR__
#include "sfr.h"
#include <assert.h>
void SFR_enableInterrupt (uint8_t interruptMask)
{
HWREG8(SFR_BASE + OFS_SFRIE1_L) |= interruptMask;
}
void SFR_disableInterrupt (uint8_t interruptMask)
{
HWREG8(SFR_BASE + OFS_SFRIE1_L) &= ~(interruptMask);
}
uint8_t SFR_getInterruptStatus (uint8_t interruptFlagMask)
{
return ( HWREG8(SFR_BASE + OFS_SFRIFG1_L) & interruptFlagMask );
}
void SFR_clearInterrupt (uint8_t interruptFlagMask)
{
HWREG8(SFR_BASE + OFS_SFRIFG1_L) &= ~(interruptFlagMask);
}
void SFR_setResetPinPullResistor (uint16_t pullResistorSetup)
{
HWREG8(SFR_BASE + OFS_SFRRPCR_L) &= ~(SYSRSTRE + SYSRSTUP);
HWREG8(SFR_BASE + OFS_SFRRPCR_L) |= pullResistorSetup;
}
void SFR_setNMIEdge (uint16_t edgeDirection)
{
HWREG8(SFR_BASE + OFS_SFRRPCR_L) &= ~(SYSNMIIES);
HWREG8(SFR_BASE + OFS_SFRRPCR_L) |= edgeDirection;
}
void SFR_setResetNMIPinFunction (uint8_t resetPinFunction)
{
HWREG8(SFR_BASE + OFS_SFRRPCR_L) &= ~(SYSNMI);
HWREG8(SFR_BASE + OFS_SFRRPCR_L) |= resetPinFunction;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for sfr_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,273 @@
//*****************************************************************************
//
// sfr.h - Driver for the SFR Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_SFR_H__
#define __MSP430WARE_SFR_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_SFR__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the interruptMask parameter
// for functions: SFR_enableInterrupt(), and SFR_disableInterrupt(); the
// interruptFlagMask parameter for functions: SFR_getInterruptStatus(), and
// SFR_clearInterrupt() as well as returned by the SFR_getInterruptStatus()
// function.
//
//*****************************************************************************
#define SFR_JTAG_OUTBOX_INTERRUPT JMBOUTIE
#define SFR_JTAG_INBOX_INTERRUPT JMBINIE
#define SFR_NMI_PIN_INTERRUPT NMIIE
#define SFR_VACANT_MEMORY_ACCESS_INTERRUPT VMAIE
#define SFR_OSCILLATOR_FAULT_INTERRUPT OFIE
#define SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT WDTIE
#define SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT ACCVIE
//*****************************************************************************
//
// The following are values that can be passed to the pullResistorSetup
// parameter for functions: SFR_setResetPinPullResistor().
//
//*****************************************************************************
#define SFR_RESISTORDISABLE (!(SYSRSTRE + SYSRSTUP))
#define SFR_RESISTORENABLE_PULLUP (SYSRSTRE + SYSRSTUP)
#define SFR_RESISTORENABLE_PULLDOWN (SYSRSTRE)
//*****************************************************************************
//
// The following are values that can be passed to the edgeDirection parameter
// for functions: SFR_setNMIEdge().
//
//*****************************************************************************
#define SFR_NMI_RISINGEDGE (!(SYSNMIIES))
#define SFR_NMI_FALLINGEDGE (SYSNMIIES)
//*****************************************************************************
//
// The following are values that can be passed to the resetPinFunction
// parameter for functions: SFR_setResetNMIPinFunction().
//
//*****************************************************************************
#define SFR_RESETPINFUNC_RESET (!(SYSNMI))
#define SFR_RESETPINFUNC_NMI (SYSNMI)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Enables selected SFR interrupt sources.
//!
//! This function enables the selected SFR interrupt sources. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor.
//!
//! \param interruptMask is the bit mask of interrupts that will be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable
//! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable
//! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI
//! function is chosen
//! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access
//! interrupt enable
//! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt
//! enable
//! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer
//! interrupt enable
//! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash
//! controller access violation interrupt enable
//!
//! \return None
//
//*****************************************************************************
extern void SFR_enableInterrupt(uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Disables selected SFR interrupt sources.
//!
//! This function disables the selected SFR interrupt sources. Only the sources
//! that are enabled can be reflected to the processor interrupt; disabled
//! sources have no effect on the processor.
//!
//! \param interruptMask is the bit mask of interrupts that will be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable
//! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable
//! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI
//! function is chosen
//! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access
//! interrupt enable
//! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt
//! enable
//! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer
//! interrupt enable
//! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash
//! controller access violation interrupt enable
//!
//! \return None
//
//*****************************************************************************
extern void SFR_disableInterrupt(uint8_t interruptMask);
//*****************************************************************************
//
//! \brief Returns the status of the selected SFR interrupt flags.
//!
//! This function returns the status of the selected SFR interrupt flags in a
//! bit mask format matching that passed into the interruptFlagMask parameter.
//!
//! \param interruptFlagMask is the bit mask of interrupt flags that the status
//! of should be returned.
//! Mask value is the logical OR of any of the following:
//! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable
//! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable
//! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI
//! function is chosen
//! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access
//! interrupt enable
//! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt
//! enable
//! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer
//! interrupt enable
//! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash
//! controller access violation interrupt enable
//!
//! \return Logical OR of any of the following:
//! - \b SFR_JTAG_OUTBOX_INTERRUPT JTAG outbox interrupt enable
//! - \b SFR_JTAG_INBOX_INTERRUPT JTAG inbox interrupt enable
//! - \b SFR_NMI_PIN_INTERRUPT NMI pin interrupt enable, if NMI
//! function is chosen
//! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT Vacant memory access
//! interrupt enable
//! - \b SFR_OSCILLATOR_FAULT_INTERRUPT Oscillator fault interrupt
//! enable
//! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT Watchdog interval timer
//! interrupt enable
//! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT Flash
//! controller access violation interrupt enable
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t SFR_getInterruptStatus(uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Clears the selected SFR interrupt flags.
//!
//! This function clears the status of the selected SFR interrupt flags.
//!
//! \param interruptFlagMask is the bit mask of interrupt flags that should be
//! cleared
//! Mask value is the logical OR of any of the following:
//! - \b SFR_JTAG_OUTBOX_INTERRUPT - JTAG outbox interrupt enable
//! - \b SFR_JTAG_INBOX_INTERRUPT - JTAG inbox interrupt enable
//! - \b SFR_NMI_PIN_INTERRUPT - NMI pin interrupt enable, if NMI
//! function is chosen
//! - \b SFR_VACANT_MEMORY_ACCESS_INTERRUPT - Vacant memory access
//! interrupt enable
//! - \b SFR_OSCILLATOR_FAULT_INTERRUPT - Oscillator fault interrupt
//! enable
//! - \b SFR_WATCHDOG_INTERVAL_TIMER_INTERRUPT - Watchdog interval timer
//! interrupt enable
//! - \b SFR_FLASH_CONTROLLER_ACCESS_VIOLATION_INTERRUPT - Flash
//! controller access violation interrupt enable
//!
//! \return None
//
//*****************************************************************************
extern void SFR_clearInterrupt(uint8_t interruptFlagMask);
//*****************************************************************************
//
//! \brief Sets the pull-up/down resistor on the ~RST/NMI pin.
//!
//! This function sets the pull-up/down resistors on the ~RST/NMI pin to the
//! settings from the pullResistorSetup parameter.
//!
//! \param pullResistorSetup is the selection of how the pull-up/down resistor
//! on the ~RST/NMI pin should be setup or disabled.
//! Valid values are:
//! - \b SFR_RESISTORDISABLE
//! - \b SFR_RESISTORENABLE_PULLUP [Default]
//! - \b SFR_RESISTORENABLE_PULLDOWN
//! \n Modified bits are \b SYSRSTUP of \b SFRRPCR register.
//!
//! \return None
//
//*****************************************************************************
extern void SFR_setResetPinPullResistor(uint16_t pullResistorSetup);
//*****************************************************************************
//
//! \brief Sets the edge direction that will assert an NMI from a signal on the
//! ~RST/NMI pin if NMI function is active.
//!
//! This function sets the edge direction that will assert an NMI from a signal
//! on the ~RST/NMI pin if the NMI function is active. To activate the NMI
//! function of the ~RST/NMI use the SFR_setResetNMIPinFunction() passing
//! SFR_RESETPINFUNC_NMI into the resetPinFunction parameter.
//!
//! \param edgeDirection is the direction that the signal on the ~RST/NMI pin
//! should go to signal an interrupt, if enabled.
//! Valid values are:
//! - \b SFR_NMI_RISINGEDGE [Default]
//! - \b SFR_NMI_FALLINGEDGE
//! \n Modified bits are \b SYSNMIIES of \b SFRRPCR register.
//!
//! \return None
//
//*****************************************************************************
extern void SFR_setNMIEdge(uint16_t edgeDirection);
//*****************************************************************************
//
//! \brief Sets the function of the ~RST/NMI pin.
//!
//! This function sets the functionality of the ~RST/NMI pin, whether in reset
//! mode which will assert a reset if a low signal is observed on that pin, or
//! an NMI which will assert an interrupt from an edge of the signal dependent
//! on the setting of the edgeDirection parameter in SFR_setNMIEdge().
//!
//! \param resetPinFunction is the function that the ~RST/NMI pin should take
//! on.
//! Valid values are:
//! - \b SFR_RESETPINFUNC_RESET [Default]
//! - \b SFR_RESETPINFUNC_NMI
//! \n Modified bits are \b SYSNMI of \b SFRRPCR register.
//!
//! \return None
//
//*****************************************************************************
extern void SFR_setResetNMIPinFunction(uint8_t resetPinFunction);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_SFR_H__

View File

@@ -0,0 +1,132 @@
//*****************************************************************************
//
// sysctl.c - Driver for the sysctl Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup sysctl_api sysctl
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_SYS__
#include "sysctl.h"
#include <assert.h>
void SysCtl_enableDedicatedJTAGPins (void)
{
HWREG8(SYS_BASE + OFS_SYSCTL_L) |= SYSJTAGPIN;
}
uint8_t SysCtl_getBSLEntryIndication (void)
{
if ( HWREG8(SYS_BASE + OFS_SYSCTL_L) & SYSBSLIND){
return (SYSCTL_BSLENTRY_INDICATED) ;
} else {
return (SYSCTL_BSLENTRY_NOTINDICATED) ;
}
}
void SysCtl_enablePMMAccessProtect (void)
{
HWREG8(SYS_BASE + OFS_SYSCTL_L) |= SYSPMMPE;
}
void SysCtl_enableRAMBasedInterruptVectors (void)
{
HWREG8(SYS_BASE + OFS_SYSCTL_L) |= SYSRIVECT;
}
void SysCtl_disableRAMBasedInterruptVectors (void)
{
HWREG8(SYS_BASE + OFS_SYSCTL_L) &= ~(SYSRIVECT);
}
void SysCtl_enableBSLProtect (void)
{
HWREG16(SYS_BASE + OFS_SYSBSLC) |= SYSBSLPE;
}
void SysCtl_disableBSLProtect (void)
{
HWREG16(SYS_BASE + OFS_SYSBSLC) &= ~(SYSBSLPE);
}
void SysCtl_enableBSLMemory (void)
{
HWREG16(SYS_BASE + OFS_SYSBSLC) &= ~(SYSBSLOFF);
}
void SysCtl_disableBSLMemory (void)
{
HWREG16(SYS_BASE + OFS_SYSBSLC) |= SYSBSLOFF;
}
void SysCtl_setRAMAssignedToBSL (uint8_t BSLRAMAssignment)
{
HWREG8(SYS_BASE + OFS_SYSBSLC_L) &= ~(SYSBSLR);
HWREG8(SYS_BASE + OFS_SYSBSLC_L) |= BSLRAMAssignment;
}
void SysCtl_setBSLSize (uint8_t BSLSizeSelect)
{
HWREG8(SYS_BASE + OFS_SYSBSLC_L) &= ~(SYSBSLSIZE0 + SYSBSLSIZE1);
HWREG8(SYS_BASE + OFS_SYSBSLC_L) |= BSLSizeSelect;
}
void SysCtl_initJTAGMailbox (uint8_t mailboxSizeSelect,
uint8_t autoClearInboxFlagSelect)
{
HWREG8(SYS_BASE + OFS_SYSJMBC_L) &= ~(JMBCLR1OFF + JMBCLR0OFF + JMBMODE);
HWREG8(SYS_BASE + OFS_SYSJMBC_L) |=
mailboxSizeSelect + autoClearInboxFlagSelect;
}
uint8_t SysCtl_getJTAGMailboxFlagStatus (uint8_t mailboxFlagMask)
{
return ( HWREG8(SYS_BASE + OFS_SYSJMBC_L) & mailboxFlagMask);
}
void SysCtl_clearJTAGMailboxFlagStatus (uint8_t mailboxFlagMask)
{
HWREG8(SYS_BASE + OFS_SYSJMBC_L) &= ~(mailboxFlagMask);
}
uint16_t SysCtl_getJTAGInboxMessage16Bit (uint8_t inboxSelect)
{
return ( HWREG16(SYS_BASE + OFS_SYSJMBI0 + inboxSelect) );
}
uint32_t SysCtl_getJTAGInboxMessage32Bit (void)
{
uint32_t JTAGInboxMessageLow = HWREG16(SYS_BASE + OFS_SYSJMBI0);
uint32_t JTAGInboxMessageHigh = HWREG16(SYS_BASE + OFS_SYSJMBI1);
return ( (JTAGInboxMessageHigh << 16) + JTAGInboxMessageLow );
}
void SysCtl_setJTAGOutgoingMessage16Bit (uint8_t outboxSelect,
uint16_t outgoingMessage)
{
HWREG16(SYS_BASE + OFS_SYSJMBO0 + outboxSelect) = outgoingMessage;
}
void SysCtl_setJTAGOutgoingMessage32Bit (uint32_t outgoingMessage)
{
HWREG16(SYS_BASE + OFS_SYSJMBO0) = (outgoingMessage);
HWREG16(SYS_BASE + OFS_SYSJMBO1) = (outgoingMessage >> 16);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for sysctl_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,433 @@
//*****************************************************************************
//
// sysctl.h - Driver for the SYSCTL Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_SYSCTL_H__
#define __MSP430WARE_SYSCTL_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_SYS__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the BSLRAMAssignment
// parameter for functions: SysCtl_setRAMAssignedToBSL().
//
//*****************************************************************************
#define SYSCTL_BSLRAMASSIGN_NORAM (!(SYSBSLR))
#define SYSCTL_BSLRAMASSIGN_LOWEST16BYTES (SYSBSLR)
//*****************************************************************************
//
// The following are values that can be passed to the BSLSizeSelect parameter
// for functions: SysCtl_setBSLSize().
//
//*****************************************************************************
#define SYSCTL_BSLSIZE_SEG3 (~(SYSBSLSIZE0 + SYSBSLSIZE1))
#define SYSCTL_BSLSIZE_SEGS23 (SYSBSLSIZE0)
#define SYSCTL_BSLSIZE_SEGS123 (SYSBSLSIZE1)
#define SYSCTL_BSLSIZE_SEGS1234 (SYSBSLSIZE0 + SYSBSLSIZE1)
//*****************************************************************************
//
// The following are values that can be passed to the mailboxSizeSelect
// parameter for functions: SysCtl_initJTAGMailbox().
//
//*****************************************************************************
#define SYSCTL_JTAGMBSIZE_16BIT (!(JMBMODE))
#define SYSCTL_JTAGMBSIZE_32BIT (JMBMODE)
//*****************************************************************************
//
// The following are values that can be passed to the autoClearInboxFlagSelect
// parameter for functions: SysCtl_initJTAGMailbox().
//
//*****************************************************************************
#define SYSCTL_JTAGINBOX0AUTO_JTAGINBOX1AUTO (!(JMBCLR0OFF + JMBCLR1OFF))
#define SYSCTL_JTAGINBOX0AUTO_JTAGINBOX1SW (JMBCLR1OFF)
#define SYSCTL_JTAGINBOX0SW_JTAGINBOX1AUTO (JMBCLR0OFF)
#define SYSCTL_JTAGINBOX0SW_JTAGINBOX1SW (JMBCLR0OFF + JMBCLR1OFF)
//*****************************************************************************
//
// The following are values that can be passed to the mailboxFlagMask parameter
// for functions: SysCtl_getJTAGMailboxFlagStatus(), and
// SysCtl_clearJTAGMailboxFlagStatus().
//
//*****************************************************************************
#define SYSCTL_JTAGOUTBOX_FLAG0 (JMBOUT0FG)
#define SYSCTL_JTAGOUTBOX_FLAG1 (JMBOUT1FG)
#define SYSCTL_JTAGINBOX_FLAG0 (JMBIN0FG)
#define SYSCTL_JTAGINBOX_FLAG1 (JMBIN1FG)
//*****************************************************************************
//
// The following are values that can be passed to the inboxSelect parameter for
// functions: SysCtl_getJTAGInboxMessage16Bit().
//
//*****************************************************************************
#define SYSCTL_JTAGINBOX_0 (0x0)
#define SYSCTL_JTAGINBOX_1 (0x2)
//*****************************************************************************
//
// The following are values that can be passed to the outboxSelect parameter
// for functions: SysCtl_setJTAGOutgoingMessage16Bit().
//
//*****************************************************************************
#define SYSCTL_JTAGOUTBOX_0 (0x0)
#define SYSCTL_JTAGOUTBOX_1 (0x2)
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the SysCtl_getBSLEntryIndication() function.
//
//*****************************************************************************
#define SYSCTL_BSLENTRY_INDICATED (0x1)
#define SYSCTL_BSLENTRY_NOTINDICATED (0x0)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Sets the JTAG pins to be exclusively for JTAG until a BOR occurs.
//!
//! This function sets the JTAG pins to be exclusively used for the JTAG, and
//! not to be shared with the GPIO pins. This setting can only be cleared when
//! a BOR occurs.
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_enableDedicatedJTAGPins(void);
//*****************************************************************************
//
//! \brief Returns the indication of a BSL entry sequence from the Spy-Bi-Wire.
//!
//! This function returns the indication of a BSL entry sequence from the Spy-
//! Bi-Wire.
//!
//!
//! \return One of the following:
//! - \b SYSCTL_BSLENTRY_INDICATED
//! - \b SYSCTL_BSLENTRY_NOTINDICATED
//! \n indicating if a BSL entry sequence was detected
//
//*****************************************************************************
extern uint8_t SysCtl_getBSLEntryIndication(void);
//*****************************************************************************
//
//! \brief Enables PMM Access Protection.
//!
//! This function enables the PMM Access Protection, which will lock any
//! changes on the PMM control registers until a BOR occurs.
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_enablePMMAccessProtect(void);
//*****************************************************************************
//
//! \brief Enables RAM-based Interrupt Vectors.
//!
//! This function enables RAM-base Interrupt Vectors, which means that
//! interrupt vectors are generated with the end address at the top of RAM,
//! instead of the top of the lower 64kB of flash.
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_enableRAMBasedInterruptVectors(void);
//*****************************************************************************
//
//! \brief Disables RAM-based Interrupt Vectors.
//!
//! This function disables the interrupt vectors from being generated at the
//! top of the RAM.
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_disableRAMBasedInterruptVectors(void);
//*****************************************************************************
//
//! \brief Enables BSL memory protection.
//!
//! This function enables protection on the BSL memory, which prevents any
//! reading, programming, or erasing of the BSL memory.
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_enableBSLProtect(void);
//*****************************************************************************
//
//! \brief Disables BSL memory protection.
//!
//! This function disables protection on the BSL memory.
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_disableBSLProtect(void);
//*****************************************************************************
//
//! \brief Enables BSL memory.
//!
//! This function enables BSL memory, which allows BSL memory to be addressed
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_enableBSLMemory(void);
//*****************************************************************************
//
//! \brief Disables BSL memory.
//!
//! This function disables BSL memory, which makes BSL memory act like vacant
//! memory.
//!
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_disableBSLMemory(void);
//*****************************************************************************
//
//! \brief Sets RAM assignment to BSL area.
//!
//! This function allows RAM to be assigned to BSL, based on the selection of
//! the BSLRAMAssignment parameter.
//!
//! \param BSLRAMAssignment is the selection of if the BSL should be placed in
//! RAM or not.
//! Valid values are:
//! - \b SYSCTL_BSLRAMASSIGN_NORAM [Default]
//! - \b SYSCTL_BSLRAMASSIGN_LOWEST16BYTES
//! \n Modified bits are \b SYSBSLR of \b SYSBSLC register.
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_setRAMAssignedToBSL(uint8_t BSLRAMAssignment);
//*****************************************************************************
//
//! \brief Sets the size of the BSL in Flash.
//!
//! This function sets the size of the BSL in Flash memory.
//!
//! \param BSLSizeSelect is the amount of segments the BSL should take.
//! Valid values are:
//! - \b SYSCTL_BSLSIZE_SEG3
//! - \b SYSCTL_BSLSIZE_SEGS23
//! - \b SYSCTL_BSLSIZE_SEGS123
//! - \b SYSCTL_BSLSIZE_SEGS1234 [Default]
//! \n Modified bits are \b SYSBSLSIZE of \b SYSBSLC register.
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_setBSLSize(uint8_t BSLSizeSelect);
//*****************************************************************************
//
//! \brief Initializes JTAG Mailbox with selected properties.
//!
//! This function sets the specified settings for the JTAG Mailbox system. The
//! settings that can be set are the size of the JTAG messages, and the auto-
//! clearing of the inbox flags. If the inbox flags are set to auto-clear, then
//! the inbox flags will be cleared upon reading of the inbox message buffer,
//! otherwise they will have to be reset by software using the
//! SYS_clearJTAGMailboxFlagStatus() function.
//!
//! \param mailboxSizeSelect is the size of the JTAG Mailboxes, whether 16- or
//! 32-bits.
//! Valid values are:
//! - \b SYSCTL_JTAGMBSIZE_16BIT [Default] - the JTAG messages will take
//! up only one JTAG mailbox (i. e. an outgoing message will take up
//! only 1 outbox of the JTAG mailboxes)
//! - \b SYSCTL_JTAGMBSIZE_32BIT - the JTAG messages will be contained
//! within both JTAG mailboxes (i. e. an outgoing message will take
//! up both Outboxes of the JTAG mailboxes)
//! \n Modified bits are \b JMBMODE of \b SYSJMBC register.
//! \param autoClearInboxFlagSelect decides how the JTAG inbox flags should be
//! cleared, whether automatically after the corresponding outbox has
//! been written to, or manually by software.
//! Valid values are:
//! - \b SYSCTL_JTAGINBOX0AUTO_JTAGINBOX1AUTO [Default] - both JTAG
//! inbox flags will be reset automatically when the corresponding
//! inbox is read from.
//! - \b SYSCTL_JTAGINBOX0AUTO_JTAGINBOX1SW - only JTAG inbox 0 flag is
//! reset automatically, while JTAG inbox 1 is reset with the
//! - \b SYSCTL_JTAGINBOX0SW_JTAGINBOX1AUTO - only JTAG inbox 1 flag is
//! reset automatically, while JTAG inbox 0 is reset with the
//! - \b SYSCTL_JTAGINBOX0SW_JTAGINBOX1SW - both JTAG inbox flags will
//! need to be reset manually by the
//! \n Modified bits are \b JMBCLR0OFF and \b JMBCLR1OFF of \b SYSJMBC
//! register.
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_initJTAGMailbox(uint8_t mailboxSizeSelect,
uint8_t autoClearInboxFlagSelect);
//*****************************************************************************
//
//! \brief Returns the status of the selected JTAG Mailbox flags.
//!
//! This function will return the status of the selected JTAG Mailbox flags in
//! bit mask format matching that passed into the mailboxFlagMask parameter.
//!
//! \param mailboxFlagMask is the bit mask of JTAG mailbox flags that the
//! status of should be returned.
//! Mask value is the logical OR of any of the following:
//! - \b SYSCTL_JTAGOUTBOX_FLAG0 - flag for JTAG outbox 0
//! - \b SYSCTL_JTAGOUTBOX_FLAG1 - flag for JTAG outbox 1
//! - \b SYSCTL_JTAGINBOX_FLAG0 - flag for JTAG inbox 0
//! - \b SYSCTL_JTAGINBOX_FLAG1 - flag for JTAG inbox 1
//!
//! \return A bit mask of the status of the selected mailbox flags.
//
//*****************************************************************************
extern uint8_t SysCtl_getJTAGMailboxFlagStatus(uint8_t mailboxFlagMask);
//*****************************************************************************
//
//! \brief Clears the status of the selected JTAG Mailbox flags.
//!
//! This function clears the selected JTAG Mailbox flags.
//!
//! \param mailboxFlagMask is the bit mask of JTAG mailbox flags that the
//! status of should be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b SYSCTL_JTAGOUTBOX_FLAG0 - flag for JTAG outbox 0
//! - \b SYSCTL_JTAGOUTBOX_FLAG1 - flag for JTAG outbox 1
//! - \b SYSCTL_JTAGINBOX_FLAG0 - flag for JTAG inbox 0
//! - \b SYSCTL_JTAGINBOX_FLAG1 - flag for JTAG inbox 1
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_clearJTAGMailboxFlagStatus(uint8_t mailboxFlagMask);
//*****************************************************************************
//
//! \brief Returns the contents of the selected JTAG Inbox in a 16 bit format.
//!
//! This function returns the message contents of the selected JTAG inbox. If
//! the auto clear settings for the Inbox flags were set, then using this
//! function will automatically clear the corresponding JTAG inbox flag.
//!
//! \param inboxSelect is the chosen JTAG inbox that the contents of should be
//! returned
//! Valid values are:
//! - \b SYSCTL_JTAGINBOX_0 - return contents of JTAG inbox 0
//! - \b SYSCTL_JTAGINBOX_1 - return contents of JTAG inbox 1
//!
//! \return The contents of the selected JTAG inbox in a 16 bit format.
//
//*****************************************************************************
extern uint16_t SysCtl_getJTAGInboxMessage16Bit(uint8_t inboxSelect);
//*****************************************************************************
//
//! \brief Returns the contents of JTAG Inboxes in a 32 bit format.
//!
//! This function returns the message contents of both JTAG inboxes in a 32 bit
//! format. This function should be used if 32-bit messaging has been set in
//! the SYS_initJTAGMailbox() function. If the auto clear settings for the
//! Inbox flags were set, then using this function will automatically clear
//! both JTAG inbox flags.
//!
//!
//! \return The contents of both JTAG messages in a 32 bit format.
//
//*****************************************************************************
extern uint32_t SysCtl_getJTAGInboxMessage32Bit(void);
//*****************************************************************************
//
//! \brief Sets a 16 bit outgoing message in to the selected JTAG Outbox.
//!
//! This function sets the outgoing message in the selected JTAG outbox. The
//! corresponding JTAG outbox flag is cleared after this function, and set
//! after the JTAG has read the message.
//!
//! \param outboxSelect is the chosen JTAG outbox that the message should be
//! set it.
//! Valid values are:
//! - \b SYSCTL_JTAGOUTBOX_0 - set the contents of JTAG outbox 0
//! - \b SYSCTL_JTAGOUTBOX_1 - set the contents of JTAG outbox 1
//! \param outgoingMessage is the message to send to the JTAG.
//! \n Modified bits are \b MSGHI and \b MSGLO of \b SYSJMBOx register.
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_setJTAGOutgoingMessage16Bit(uint8_t outboxSelect,
uint16_t outgoingMessage);
//*****************************************************************************
//
//! \brief Sets a 32 bit message in to both JTAG Outboxes.
//!
//! This function sets the 32-bit outgoing message in both JTAG outboxes. The
//! JTAG outbox flags are cleared after this function, and set after the JTAG
//! has read the message.
//!
//! \param outgoingMessage is the message to send to the JTAG.
//! \n Modified bits are \b MSGHI and \b MSGLO of \b SYSJMBOx register.
//!
//! \return None
//
//*****************************************************************************
extern void SysCtl_setJTAGOutgoingMessage32Bit(uint32_t outgoingMessage);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_SYSCTL_H__

View File

@@ -0,0 +1,151 @@
//*****************************************************************************
//
// tec.c - Driver for the tec Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup tec_api tec
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_TEV0__
#include "tec.h"
#include <assert.h>
void TEC_initExternalClearInput (uint16_t baseAddress,
uint8_t signalType,
uint8_t signalHold,
uint8_t polarityBit
)
{
HWREG8(baseAddress + OFS_TEC0XCTL2_L) &= ~(TEC_EXTERNAL_CLEAR_SIGNALTYPE_LEVEL_SENSITIVE +
TEC_EXTERNAL_CLEAR_SIGNAL_HELD +
TEC_EXTERNAL_CLEAR_POLARITY_RISING_EDGE_OR_HIGH_LEVEL
);
HWREG8(baseAddress + OFS_TEC0XCTL2_L) |= (signalType +
signalHold +
polarityBit
);
}
void TEC_initExternalFaultInput(uint16_t baseAddress,
TEC_initExternalFaultInputParam *param)
{
HWREG8(baseAddress + OFS_TEC0XCTL2_L) &= ~((TEC_EXTERNAL_FAULT_SIGNALTYPE_LEVEL_SENSITIVE << param->selectedExternalFault)+
(TEC_EXTERNAL_FAULT_POLARITY_RISING_EDGE_OR_HIGH_LEVEL << param->selectedExternalFault)+
(TEC_EXTERNAL_FAULT_SIGNAL_HELD << param->selectedExternalFault )
);
HWREG8(baseAddress + OFS_TEC0XCTL2_L) |= ((param->signalType << param->selectedExternalFault)+
(param->polarityBit << param->selectedExternalFault) +
(param->signalHold << param->selectedExternalFault )
);
}
void TEC_enableExternalFaultInput (uint16_t baseAddress,
uint8_t channelEventBlock
)
{
HWREG8(baseAddress + OFS_TEC0XCTL0_H) |= (1 << channelEventBlock );
}
void TEC_disableExternalFaultInput (uint16_t baseAddress,
uint8_t channelEventBlock
)
{
HWREG8(baseAddress + OFS_TEC0XCTL0_H) &= ~(1 << channelEventBlock );
}
void TEC_enableExternalClearInput (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_TEC0XCTL2_L) |= TECEXCLREN;
}
void TEC_disableExternalClearInput (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_TEC0XCTL2_L) &= ~TECEXCLREN;
}
void TEC_enableAuxiliaryClearSignal (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_TEC0XCTL2_L) |= TECAXCLREN;
}
void TEC_disableAuxiliaryClearSignal (uint16_t baseAddress )
{
HWREG8(baseAddress + OFS_TEC0XCTL2_L) &= ~TECAXCLREN;
}
void TEC_clearInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_TEC0XINT_L) &= ~mask;
}
uint8_t TEC_getInterruptStatus (uint16_t baseAddress,
uint8_t mask
)
{
//Return the interrupt status of the request masked bit.
return (HWREG8(baseAddress + OFS_TEC0XINT_L) & mask);
}
void TEC_enableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
//Enable the interrupt masked bit
HWREG8(baseAddress + OFS_TEC0XINT_H) |= mask;
}
void TEC_disableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
//Disable the interrupt masked bit
HWREG8(baseAddress + OFS_TEC0XINT_H) &= ~(mask);
}
uint8_t TEC_getExternalFaultStatus (uint16_t baseAddress,
uint8_t mask
)
{
//Return the interrupt status of the request masked bit.
return (HWREG8(baseAddress + OFS_TEC0STA_L) & mask);
}
void TEC_clearExternalFaultStatus (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_TEC0STA_L) &= ~mask;
}
uint8_t TEC_getExternalClearStatus (uint16_t baseAddress)
{
//Return the interrupt status of the request masked bit.
return (HWREG8(baseAddress + OFS_TEC0STA_L) & TECXCLRSTA);
}
void TEC_clearExternalClearStatus (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_TEC0STA_L) &= ~TECXCLRSTA;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for tec_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,497 @@
//*****************************************************************************
//
// tec.h - Driver for the TEC Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_TEC_H__
#define __MSP430WARE_TEC_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_TEV0__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the TEC_initExternalFaultInput() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct TEC_initExternalFaultInputParam {
//! Is the selected external fault
//! \n Valid values are:
//! - \b TEC_EXTERNAL_FAULT_0
//! - \b TEC_EXTERNAL_FAULT_1
//! - \b TEC_EXTERNAL_FAULT_2
//! - \b TEC_EXTERNAL_FAULT_3
//! - \b TEC_EXTERNAL_FAULT_4
//! - \b TEC_EXTERNAL_FAULT_5
//! - \b TEC_EXTERNAL_FAULT_6
uint8_t selectedExternalFault;
//! Is the selected signal type
//! \n Valid values are:
//! - \b TEC_EXTERNAL_FAULT_SIGNALTYPE_EDGE_SENSITIVE [Default]
//! - \b TEC_EXTERNAL_FAULT_SIGNALTYPE_LEVEL_SENSITIVE
uint16_t signalType;
//! Is the selected signal hold
//! \n Valid values are:
//! - \b TEC_EXTERNAL_FAULT_SIGNAL_NOT_HELD [Default]
//! - \b TEC_EXTERNAL_FAULT_SIGNAL_HELD
uint8_t signalHold;
//! Is the selected signal type
//! \n Valid values are:
//! - \b TEC_EXTERNAL_FAULT_POLARITY_FALLING_EDGE_OR_LOW_LEVEL [Default]
//! - \b TEC_EXTERNAL_FAULT_POLARITY_RISING_EDGE_OR_HIGH_LEVEL
uint8_t polarityBit;
} TEC_initExternalFaultInputParam;
//*****************************************************************************
//
// The following are values that can be passed to the signalHold parameter for
// functions: TEC_initExternalClearInput().
//
//*****************************************************************************
#define TEC_EXTERNAL_CLEAR_SIGNAL_NOT_HELD 0x00
#define TEC_EXTERNAL_CLEAR_SIGNAL_HELD TECEXCLRHLD
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: TEC_initExternalFaultInput().
//
//*****************************************************************************
#define TEC_EXTERNAL_FAULT_SIGNAL_NOT_HELD 0x00
#define TEC_EXTERNAL_FAULT_SIGNAL_HELD TECXFLTHLD0
//*****************************************************************************
//
// The following are values that can be passed to the polarityBit parameter for
// functions: TEC_initExternalClearInput().
//
//*****************************************************************************
#define TEC_EXTERNAL_CLEAR_POLARITY_FALLING_EDGE_OR_LOW_LEVEL 0x00
#define TEC_EXTERNAL_CLEAR_POLARITY_RISING_EDGE_OR_HIGH_LEVEL TECEXCLRPOL
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: TEC_initExternalFaultInput().
//
//*****************************************************************************
#define TEC_EXTERNAL_FAULT_POLARITY_FALLING_EDGE_OR_LOW_LEVEL 0x00
#define TEC_EXTERNAL_FAULT_POLARITY_RISING_EDGE_OR_HIGH_LEVEL TECXFLTPOL0
//*****************************************************************************
//
// The following are values that can be passed to the signalType parameter for
// functions: TEC_initExternalClearInput().
//
//*****************************************************************************
#define TEC_EXTERNAL_CLEAR_SIGNALTYPE_EDGE_SENSITIVE 0x00
#define TEC_EXTERNAL_CLEAR_SIGNALTYPE_LEVEL_SENSITIVE TECEXCLRLVS
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: TEC_initExternalFaultInput().
//
//*****************************************************************************
#define TEC_EXTERNAL_FAULT_SIGNALTYPE_EDGE_SENSITIVE 0x00
#define TEC_EXTERNAL_FAULT_SIGNALTYPE_LEVEL_SENSITIVE TECXFLTLVS0
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: TEC_initExternalFaultInput().
//
//*****************************************************************************
#define TEC_EXTERNAL_FAULT_0 0
#define TEC_EXTERNAL_FAULT_1 1
#define TEC_EXTERNAL_FAULT_2 2
#define TEC_EXTERNAL_FAULT_3 3
#define TEC_EXTERNAL_FAULT_4 4
#define TEC_EXTERNAL_FAULT_5 5
#define TEC_EXTERNAL_FAULT_6 6
//*****************************************************************************
//
// The following are values that can be passed to the channelEventBlock
// parameter for functions: TEC_enableExternalFaultInput(), and
// TEC_disableExternalFaultInput(); the mask parameter for functions:
// TEC_clearExternalFaultStatus(), and TEC_getExternalFaultStatus() as well as
// returned by the TEC_getExternalFaultStatus() function.
//
//*****************************************************************************
#define TEC_CE0 TECXFLT0STA
#define TEC_CE1 TECXFLT1STA
#define TEC_CE2 TECXFLT2STA
#define TEC_CE3 TECXFLT3STA
#define TEC_CE4 TECXFLT4STA
#define TEC_CE5 TECXFLT5STA
#define TEC_CE6 TECXFLT6STA
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: TEC_clearInterrupt(), TEC_getInterruptStatus(),
// TEC_enableInterrupt(), and TEC_disableInterrupt() as well as returned by the
// TEC_getInterruptStatus() function.
//
//*****************************************************************************
#define TEC_EXTERNAL_FAULT_INTERRUPT TECXFLTIFG
#define TEC_EXTERNAL_CLEAR_INTERRUPT TECEXCLRIFG
#define TEC_AUXILIARY_CLEAR_INTERRUPT TECAXCLRIFG
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the TEC_getExternalClearStatus() function.
//
//*****************************************************************************
#define TEC_EXTERNAL_CLEAR_DETECTED TECXCLRSTA
#define TEC_EXTERNAL_CLEAR_NOT_DETECTED 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Configures the Timer Event Control External Clear Input
//!
//! \param baseAddress is the base address of the TEC module.
//! \param signalType is the selected signal type
//! Valid values are:
//! - \b TEC_EXTERNAL_CLEAR_SIGNALTYPE_EDGE_SENSITIVE [Default]
//! - \b TEC_EXTERNAL_CLEAR_SIGNALTYPE_LEVEL_SENSITIVE
//! \param signalHold is the selected signal hold
//! Valid values are:
//! - \b TEC_EXTERNAL_CLEAR_SIGNAL_NOT_HELD [Default]
//! - \b TEC_EXTERNAL_CLEAR_SIGNAL_HELD
//! \param polarityBit is the selected signal type
//! Valid values are:
//! - \b TEC_EXTERNAL_CLEAR_POLARITY_FALLING_EDGE_OR_LOW_LEVEL [Default]
//! - \b TEC_EXTERNAL_CLEAR_POLARITY_RISING_EDGE_OR_HIGH_LEVEL
//!
//! Modified bits of \b TECxCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_initExternalClearInput(uint16_t baseAddress,
uint8_t signalType,
uint8_t signalHold,
uint8_t polarityBit);
//*****************************************************************************
//
//! \brief Configures the Timer Event Control External Fault Input
//!
//! \param baseAddress is the base address of the TEC module.
//! \param param is the pointer to struct for external fault input
//! initialization.
//!
//! Modified bits of \b TECxCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_initExternalFaultInput(uint16_t baseAddress,
TEC_initExternalFaultInputParam *param);
//*****************************************************************************
//
//! \brief Enable the Timer Event Control External fault input
//!
//! \param baseAddress is the base address of the TEC module.
//! \param channelEventBlock selects the channel event block
//! Valid values are:
//! - \b TEC_CE0
//! - \b TEC_CE1
//! - \b TEC_CE2
//! - \b TEC_CE3 - (available on TEC5 TEC7)
//! - \b TEC_CE4 - (available on TEC5 TEC7)
//! - \b TEC_CE5 - (only available on TEC7)
//! - \b TEC_CE6 - (only available on TEC7)
//!
//! Modified bits of \b TECxCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_enableExternalFaultInput(uint16_t baseAddress,
uint8_t channelEventBlock);
//*****************************************************************************
//
//! \brief Disable the Timer Event Control External fault input
//!
//! \param baseAddress is the base address of the TEC module.
//! \param channelEventBlock selects the channel event block
//! Valid values are:
//! - \b TEC_CE0
//! - \b TEC_CE1
//! - \b TEC_CE2
//! - \b TEC_CE3 - (available on TEC5 TEC7)
//! - \b TEC_CE4 - (available on TEC5 TEC7)
//! - \b TEC_CE5 - (only available on TEC7)
//! - \b TEC_CE6 - (only available on TEC7)
//!
//! Modified bits of \b TECxCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_disableExternalFaultInput(uint16_t baseAddress,
uint8_t channelEventBlock);
//*****************************************************************************
//
//! \brief Enable the Timer Event Control External Clear Input
//!
//! \param baseAddress is the base address of the TEC module.
//!
//! Modified bits of \b TECxCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_enableExternalClearInput(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disable the Timer Event Control External Clear Input
//!
//! \param baseAddress is the base address of the TEC module.
//!
//! Modified bits of \b TECxCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_disableExternalClearInput(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enable the Timer Event Control Auxiliary Clear Signal
//!
//! \param baseAddress is the base address of the TEC module.
//!
//! Modified bits of \b TECxCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_enableAuxiliaryClearSignal(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disable the Timer Event Control Auxiliary Clear Signal
//!
//! \param baseAddress is the base address of the TEC module.
//!
//! Modified bits of \b TECxCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_disableAuxiliaryClearSignal(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Clears the Timer Event Control Interrupt flag
//!
//! \param baseAddress is the base address of the TEC module.
//! \param mask is the masked interrupt flag to be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b TEC_EXTERNAL_FAULT_INTERRUPT - External fault interrupt flag
//! - \b TEC_EXTERNAL_CLEAR_INTERRUPT - External clear interrupt flag
//! - \b TEC_AUXILIARY_CLEAR_INTERRUPT - Auxiliary clear interrupt flag
//!
//! Modified bits of \b TECxINT register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_clearInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current Timer Event Control interrupt status.
//!
//! This returns the interrupt status for the module based on which flag is
//! passed.
//!
//! \param baseAddress is the base address of the TEC module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b TEC_EXTERNAL_FAULT_INTERRUPT - External fault interrupt flag
//! - \b TEC_EXTERNAL_CLEAR_INTERRUPT - External clear interrupt flag
//! - \b TEC_AUXILIARY_CLEAR_INTERRUPT - Auxiliary clear interrupt flag
//!
//! \return Logical OR of any of the following:
//! - \b TEC_EXTERNAL_FAULT_INTERRUPT External fault interrupt flag
//! - \b TEC_EXTERNAL_CLEAR_INTERRUPT External clear interrupt flag
//! - \b TEC_AUXILIARY_CLEAR_INTERRUPT Auxiliary clear interrupt flag
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t TEC_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Enables individual Timer Event Control interrupt sources.
//!
//! Enables the indicated Timer Event Control interrupt sources. Only the
//! sources that are enabled can be reflected to the processor interrupt;
//! disabled sources have no effect on the processor. Does not clear interrupt
//! flags.
//!
//! \param baseAddress is the base address of the TEC module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b TEC_EXTERNAL_FAULT_INTERRUPT - External fault interrupt flag
//! - \b TEC_EXTERNAL_CLEAR_INTERRUPT - External clear interrupt flag
//! - \b TEC_AUXILIARY_CLEAR_INTERRUPT - Auxiliary clear interrupt flag
//!
//! Modified bits of \b TECxINT register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_enableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Disables individual Timer Event Control interrupt sources.
//!
//! Disables the indicated Timer Event Control interrupt sources. Only the
//! sources that are enabled can be reflected to the processor interrupt;
//! disabled sources have no effect on the processor.
//!
//! \param baseAddress is the base address of the TEC module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b TEC_EXTERNAL_FAULT_INTERRUPT - External fault interrupt flag
//! - \b TEC_EXTERNAL_CLEAR_INTERRUPT - External clear interrupt flag
//! - \b TEC_AUXILIARY_CLEAR_INTERRUPT - Auxiliary clear interrupt flag
//!
//! Modified bits of \b TECxINT register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_disableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current Timer Event Control External Fault Status
//!
//! This returns the Timer Event Control fault status for the module.
//!
//! \param baseAddress is the base address of the TEC module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b TEC_CE0
//! - \b TEC_CE1
//! - \b TEC_CE2
//! - \b TEC_CE3 - (available on TEC5 TEC7)
//! - \b TEC_CE4 - (available on TEC5 TEC7)
//! - \b TEC_CE5 - (only available on TEC7)
//! - \b TEC_CE6 - (only available on TEC7)
//!
//! \return Logical OR of any of the following:
//! - \b TEC_CE0
//! - \b TEC_CE1
//! - \b TEC_CE2
//! - \b TEC_CE3 (available on TEC5 TEC7)
//! - \b TEC_CE4 (available on TEC5 TEC7)
//! - \b TEC_CE5 (only available on TEC7)
//! - \b TEC_CE6 (only available on TEC7)
//! \n indicating the external fault status of the masked channel event
//! blocks
//
//*****************************************************************************
extern uint8_t TEC_getExternalFaultStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears the Timer Event Control External Fault Status
//!
//! \param baseAddress is the base address of the TEC module.
//! \param mask is the masked status flag be cleared
//! Mask value is the logical OR of any of the following:
//! - \b TEC_CE0
//! - \b TEC_CE1
//! - \b TEC_CE2
//! - \b TEC_CE3 - (available on TEC5 TEC7)
//! - \b TEC_CE4 - (available on TEC5 TEC7)
//! - \b TEC_CE5 - (only available on TEC7)
//! - \b TEC_CE6 - (only available on TEC7)
//!
//! Modified bits of \b TECxINT register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_clearExternalFaultStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current Timer Event Control External Clear Status
//!
//! \param baseAddress is the base address of the TEC module.
//!
//! \return One of the following:
//! - \b TEC_EXTERNAL_CLEAR_DETECTED
//! - \b TEC_EXTERNAL_CLEAR_NOT_DETECTED
//! \n indicating the status of the external clear
//
//*****************************************************************************
extern uint8_t TEC_getExternalClearStatus(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Clears the Timer Event Control External Clear Status
//!
//! \param baseAddress is the base address of the TEC module.
//!
//! Modified bits of \b TECxINT register.
//!
//! \return None
//
//*****************************************************************************
extern void TEC_clearExternalClearStatus(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_TEC_H__

View File

@@ -0,0 +1,333 @@
//*****************************************************************************
//
// timer_a.c - Driver for the timer_a Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup timer_a_api timer_a
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_TxA7__
#include "timer_a.h"
#include <assert.h>
void Timer_A_startCounter ( uint16_t baseAddress,
uint16_t timerMode
)
{
HWREG16(baseAddress + OFS_TAxCTL) &= ~MC_3;
HWREG16(baseAddress + OFS_TAxCTL) |= timerMode;
}
void Timer_A_initContinuousMode (uint16_t baseAddress,
Timer_A_initContinuousModeParam *param)
{
HWREG16(baseAddress +
OFS_TAxCTL) &= ~(TIMER_A_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_A_UPDOWN_MODE +
TIMER_A_DO_CLEAR +
TIMER_A_TAIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TAxEX0) &= ~TAIDEX_7;
HWREG16(baseAddress + OFS_TAxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TAxCTL) |= (param->clockSource +
param->timerClear +
param->timerInterruptEnable_TAIE +
((param->clockSourceDivider>>3)<<6));
if(param->startTimer) {
HWREG16(baseAddress + OFS_TAxCTL) |= TIMER_A_CONTINUOUS_MODE;
}
}
void Timer_A_initUpMode (uint16_t baseAddress,
Timer_A_initUpModeParam *param)
{
HWREG16(baseAddress + OFS_TAxCTL) &=
~(TIMER_A_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_A_UPDOWN_MODE +
TIMER_A_DO_CLEAR +
TIMER_A_TAIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TAxEX0) &= ~TAIDEX_7;
HWREG16(baseAddress + OFS_TAxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TAxCTL) |= (param->clockSource +
param->timerClear +
param->timerInterruptEnable_TAIE +
((param->clockSourceDivider>>3)<<6));
if (param->startTimer) {
HWREG16(baseAddress + OFS_TAxCTL) |= TIMER_A_UP_MODE;
}
if (TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE ==
param->captureCompareInterruptEnable_CCR0_CCIE){
HWREG16(baseAddress + OFS_TAxCCTL0) |= TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
} else {
HWREG16(baseAddress + OFS_TAxCCTL0) &= ~TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
}
HWREG16(baseAddress + OFS_TAxCCR0) = param->timerPeriod;
}
void Timer_A_initUpDownMode(uint16_t baseAddress,
Timer_A_initUpDownModeParam *param)
{
HWREG16(baseAddress + OFS_TAxCTL) &=
~(TIMER_A_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_A_UPDOWN_MODE +
TIMER_A_DO_CLEAR +
TIMER_A_TAIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TAxEX0) &= ~TAIDEX_7;
HWREG16(baseAddress + OFS_TAxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TAxCTL) |= (param->clockSource +
param->timerClear +
param->timerInterruptEnable_TAIE +
((param->clockSourceDivider>>3)<<6));
if (param->startTimer) {
HWREG16(baseAddress + OFS_TAxCTL) |= TIMER_A_UPDOWN_MODE;
}
if (TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE ==
param->captureCompareInterruptEnable_CCR0_CCIE){
HWREG16(baseAddress + OFS_TAxCCTL0) |= TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
} else {
HWREG16(baseAddress + OFS_TAxCCTL0) &= ~TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
}
HWREG16(baseAddress + OFS_TAxCCR0) = param->timerPeriod;
}
void Timer_A_initCaptureMode(uint16_t baseAddress,
Timer_A_initCaptureModeParam *param)
{
HWREG16(baseAddress + param->captureRegister ) |= CAP;
HWREG16(baseAddress + param->captureRegister) &=
~(TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE +
TIMER_A_CAPTURE_INPUTSELECT_Vcc +
TIMER_A_CAPTURE_SYNCHRONOUS +
TIMER_A_DO_CLEAR +
TIMER_A_TAIE_INTERRUPT_ENABLE +
CM_3
);
HWREG16(baseAddress + param->captureRegister) |= (param->captureMode +
param->captureInputSelect +
param->synchronizeCaptureSource +
param->captureInterruptEnable +
param->captureOutputMode
);
}
void Timer_A_initCompareMode(uint16_t baseAddress,
Timer_A_initCompareModeParam *param)
{
HWREG16(baseAddress + param->compareRegister ) &= ~CAP;
HWREG16(baseAddress + param->compareRegister) &=
~(TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE +
TIMER_A_OUTPUTMODE_RESET_SET
);
HWREG16(baseAddress + param->compareRegister) |= (param->compareInterruptEnable +
param->compareOutputMode
);
HWREG16(baseAddress + param->compareRegister + OFS_TAxR) = param->compareValue;
}
void Timer_A_enableInterrupt (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TAxCTL) |= TAIE;
}
void Timer_A_disableInterrupt (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TAxCTL) &= ~TAIE;
}
uint32_t Timer_A_getInterruptStatus (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_TAxCTL) & TAIFG );
}
void Timer_A_enableCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) |= CCIE;
}
void Timer_A_disableCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~CCIE;
}
uint32_t Timer_A_getCaptureCompareInterruptStatus (uint16_t baseAddress,
uint16_t captureCompareRegister,
uint16_t mask
)
{
return ( HWREG16(baseAddress + captureCompareRegister) & mask );
}
void Timer_A_clear (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TAxCTL) |= TACLR;
}
uint8_t Timer_A_getSynchronizedCaptureCompareInput
(uint16_t baseAddress,
uint16_t captureCompareRegister,
uint16_t synchronized
)
{
if (HWREG16(baseAddress + captureCompareRegister) & synchronized){
return ( TIMER_A_CAPTURECOMPARE_INPUT_HIGH) ;
} else {
return ( TIMER_A_CAPTURECOMPARE_INPUT_LOW) ;
}
}
uint8_t Timer_A_getOutputForOutputModeOutBitValue
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
if (HWREG16(baseAddress + captureCompareRegister) & OUT){
return ( TIMER_A_OUTPUTMODE_OUTBITVALUE_HIGH) ;
} else {
return ( TIMER_A_OUTPUTMODE_OUTBITVALUE_LOW) ;
}
}
uint16_t Timer_A_getCaptureCompareCount
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
return (HWREG16(baseAddress + OFS_TAxR + captureCompareRegister));
}
void Timer_A_setOutputForOutputModeOutBitValue
(uint16_t baseAddress,
uint16_t captureCompareRegister,
uint8_t outputModeOutBitValue
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~OUT;
HWREG16(baseAddress + captureCompareRegister) |= outputModeOutBitValue;
}
void Timer_A_outputPWM(uint16_t baseAddress, Timer_A_outputPWMParam *param)
{
HWREG16(baseAddress + OFS_TAxCTL) &=
~( TIMER_A_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_A_UPDOWN_MODE + TIMER_A_DO_CLEAR +
TIMER_A_TAIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TAxEX0) &= ~TAIDEX_7;
HWREG16(baseAddress + OFS_TAxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TAxCTL) |= (param->clockSource +
TIMER_A_UP_MODE +
TIMER_A_DO_CLEAR +
((param->clockSourceDivider>>3)<<6));
HWREG16(baseAddress + OFS_TAxCCR0) = param->timerPeriod;
HWREG16(baseAddress + OFS_TAxCCTL0) &=
~(TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE +
TIMER_A_OUTPUTMODE_RESET_SET);
HWREG16(baseAddress + param->compareRegister) |= param->compareOutputMode;
HWREG16(baseAddress + param->compareRegister + OFS_TAxR) = param->dutyCycle;
}
void Timer_A_stop ( uint16_t baseAddress )
{
HWREG16(baseAddress + OFS_TAxCTL) &= ~MC_3;
}
void Timer_A_setCompareValue ( uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareValue
)
{
HWREG16(baseAddress + compareRegister + OFS_TAxR) = compareValue;
}
void Timer_A_setOutputMode(uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareOutputMode)
{
uint16_t temp = HWREG16(baseAddress + compareRegister);
HWREG16(baseAddress + compareRegister) = temp & ~(OUTMOD_7) | compareOutputMode;
}
void Timer_A_clearTimerInterrupt (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TAxCTL) &= ~TAIFG;
}
void Timer_A_clearCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~CCIFG;
}
uint16_t Timer_A_getCounterValue (uint16_t baseAddress)
{
uint16_t voteOne, voteTwo, res;
voteTwo = HWREG16(baseAddress + OFS_TAxR);
do
{
voteOne = voteTwo;
voteTwo = HWREG16(baseAddress + OFS_TAxR);
if(voteTwo > voteOne) {
res = voteTwo - voteOne;
} else if(voteOne > voteTwo) {
res = voteOne - voteTwo;
} else{
res = 0;
}
} while ( res > TIMER_A_THRESHOLD);
return voteTwo;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for timer_a_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,367 @@
//*****************************************************************************
//
// timer_b.c - Driver for the timer_b Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup timer_b_api timer_b
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_TxB7__
#include "timer_b.h"
#include <assert.h>
void Timer_B_startCounter ( uint16_t baseAddress,
uint16_t timerMode
)
{
HWREG16(baseAddress + OFS_TBxCTL) |= timerMode;
}
void Timer_B_initContinuousMode(uint16_t baseAddress,
Timer_B_initContinuousModeParam *param)
{
HWREG16(baseAddress +
OFS_TBxCTL) &= ~(TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_B_UPDOWN_MODE +
TIMER_B_DO_CLEAR +
TIMER_B_TBIE_INTERRUPT_ENABLE +
CNTL_3 +
ID__8
);
HWREG16(baseAddress + OFS_TBxEX0) &= ~TBIDEX_7;
HWREG16(baseAddress + OFS_TBxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TBxCTL) |= (param->clockSource +
param->timerClear +
param->timerInterruptEnable_TBIE +
((param->clockSourceDivider>>3)<<6));
if(param->startTimer) {
HWREG16(baseAddress + OFS_TBxCTL) |= TIMER_B_CONTINUOUS_MODE;
}
}
void Timer_B_initUpMode (uint16_t baseAddress,
Timer_B_initUpModeParam *param)
{
HWREG16(baseAddress + OFS_TBxCTL) &=
~(TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_B_UPDOWN_MODE +
TIMER_B_DO_CLEAR +
TIMER_B_TBIE_INTERRUPT_ENABLE +
CNTL_3
);
HWREG16(baseAddress + OFS_TBxEX0) &= ~TBIDEX_7;
HWREG16(baseAddress + OFS_TBxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TBxCTL) |= (param->clockSource +
param->timerClear +
param->timerInterruptEnable_TBIE +
((param->clockSourceDivider>>3)<<6));
if (param->startTimer) {
HWREG16(baseAddress + OFS_TBxCTL) |= TIMER_B_UP_MODE;
}
if (TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE ==
param->captureCompareInterruptEnable_CCR0_CCIE){
HWREG16(baseAddress + OFS_TBxCCTL0) |= TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
} else {
HWREG16(baseAddress + OFS_TBxCCTL0) &= ~TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
}
HWREG16(baseAddress + OFS_TBxCCR0) = param->timerPeriod;
}
void Timer_B_initUpDownMode(uint16_t baseAddress,
Timer_B_initUpDownModeParam *param)
{
HWREG16(baseAddress + OFS_TBxCTL) &=
~(TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_B_UPDOWN_MODE +
TIMER_B_DO_CLEAR +
TIMER_B_TBIE_INTERRUPT_ENABLE +
CNTL_3
);
HWREG16(baseAddress + OFS_TBxEX0) &= ~TBIDEX_7;
HWREG16(baseAddress + OFS_TBxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TBxCTL) |= (param->clockSource +
TIMER_B_STOP_MODE +
param->timerClear +
param->timerInterruptEnable_TBIE +
((param->clockSourceDivider>>3)<<6));
if (param->startTimer) {
HWREG16(baseAddress + OFS_TBxCTL) |= TIMER_B_UPDOWN_MODE;
}
if (TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE ==
param->captureCompareInterruptEnable_CCR0_CCIE){
HWREG16(baseAddress + OFS_TBxCCTL0) |= TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
} else {
HWREG16(baseAddress + OFS_TBxCCTL0) &= ~TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE;
}
HWREG16(baseAddress + OFS_TBxCCR0) = param->timerPeriod;
}
void Timer_B_initCaptureMode(uint16_t baseAddress,
Timer_B_initCaptureModeParam *param)
{
HWREG16(baseAddress + param->captureRegister ) |= CAP;
HWREG16(baseAddress + param->captureRegister) &=
~(TIMER_B_CAPTUREMODE_RISING_AND_FALLING_EDGE +
TIMER_B_CAPTURE_INPUTSELECT_Vcc +
TIMER_B_CAPTURE_SYNCHRONOUS +
TIMER_B_DO_CLEAR +
TIMER_B_TBIE_INTERRUPT_ENABLE +
CM_3
);
HWREG16(baseAddress + param->captureRegister) |= (param->captureMode +
param->captureInputSelect +
param->synchronizeCaptureSource +
param->captureInterruptEnable +
param->captureOutputMode
);
}
void Timer_B_initCompareMode(uint16_t baseAddress,
Timer_B_initCompareModeParam *param)
{
HWREG16(baseAddress + param->compareRegister ) &= ~CAP;
HWREG16(baseAddress + param->compareRegister) &=
~(TIMER_B_CAPTURECOMPARE_INTERRUPT_ENABLE +
TIMER_B_OUTPUTMODE_RESET_SET
);
HWREG16(baseAddress + param->compareRegister) |= (param->compareInterruptEnable +
param->compareOutputMode
);
HWREG16(baseAddress + param->compareRegister + OFS_TBxR) = param->compareValue;
}
void Timer_B_enableInterrupt (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TBxCTL) |= TBIE;
}
void Timer_B_disableInterrupt (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TBxCTL) &= ~TBIE;
}
uint32_t Timer_B_getInterruptStatus (uint16_t baseAddress)
{
return ( HWREG16(baseAddress + OFS_TBxCTL) & TBIFG );
}
void Timer_B_enableCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) |= CCIE;
}
void Timer_B_disableCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~CCIE;
}
uint32_t Timer_B_getCaptureCompareInterruptStatus (uint16_t baseAddress,
uint16_t captureCompareRegister,
uint16_t mask
)
{
return ( HWREG16(baseAddress + captureCompareRegister) & mask );
}
void Timer_B_clear (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TBxCTL) |= TBCLR;
}
uint8_t Timer_B_getSynchronizedCaptureCompareInput
(uint16_t baseAddress,
uint16_t captureCompareRegister,
uint16_t synchronized
)
{
if (HWREG16(baseAddress + captureCompareRegister) & synchronized){
return ( TIMER_B_CAPTURECOMPARE_INPUT_HIGH) ;
} else {
return ( TIMER_B_CAPTURECOMPARE_INPUT_LOW) ;
}
}
uint8_t Timer_B_getOutputForOutputModeOutBitValue
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
if (HWREG16(baseAddress + captureCompareRegister) & OUT){
return ( TIMER_B_OUTPUTMODE_OUTBITVALUE_HIGH) ;
} else {
return ( TIMER_B_OUTPUTMODE_OUTBITVALUE_LOW) ;
}
}
uint16_t Timer_B_getCaptureCompareCount
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
return (HWREG16(baseAddress + OFS_TBxR + captureCompareRegister));
}
void Timer_B_setOutputForOutputModeOutBitValue
(uint16_t baseAddress,
uint16_t captureCompareRegister,
uint16_t outputModeOutBitValue
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~OUT;
HWREG16(baseAddress + captureCompareRegister) |= outputModeOutBitValue;
}
void Timer_B_outputPWM(uint16_t baseAddress, Timer_B_outputPWMParam *param)
{
HWREG16(baseAddress + OFS_TBxCTL) &=
~( TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLK +
TIMER_B_UPDOWN_MODE + TIMER_B_DO_CLEAR +
TIMER_B_TBIE_INTERRUPT_ENABLE
);
HWREG16(baseAddress + OFS_TBxEX0) &= ~TBIDEX_7;
HWREG16(baseAddress + OFS_TBxEX0) |= param->clockSourceDivider&0x7;
HWREG16(baseAddress + OFS_TBxCTL) |= (param->clockSource +
TIMER_B_UP_MODE +
TIMER_B_DO_CLEAR +
((param->clockSourceDivider>>3)<<6));
HWREG16(baseAddress + OFS_TBxCCR0) = param->timerPeriod;
HWREG16(baseAddress + OFS_TBxCCTL0) &=
~(TIMER_B_CAPTURECOMPARE_INTERRUPT_ENABLE +
TIMER_B_OUTPUTMODE_RESET_SET
);
HWREG16(baseAddress + param->compareRegister) |= param->compareOutputMode;
HWREG16(baseAddress + param->compareRegister + OFS_TBxR) = param->dutyCycle;
}
void Timer_B_stop ( uint16_t baseAddress )
{
HWREG16(baseAddress + OFS_TBxCTL) &= ~MC_3;
}
void Timer_B_setCompareValue ( uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareValue
)
{
HWREG16(baseAddress + compareRegister + OFS_TBxR) = compareValue;
}
void Timer_B_clearTimerInterrupt (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TBxCTL) &= ~TBIFG;
}
void Timer_B_clearCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~CCIFG;
}
void Timer_B_selectCounterLength (uint16_t baseAddress,
uint16_t counterLength
)
{
HWREG16(baseAddress + OFS_TBxCTL) &= ~CNTL_3;
HWREG16(baseAddress + OFS_TBxCTL) |= counterLength;
}
void Timer_B_selectLatchingGroup(uint16_t baseAddress,
uint16_t groupLatch)
{
HWREG16(baseAddress + OFS_TBxCTL) &= ~TBCLGRP_3;
HWREG16(baseAddress + OFS_TBxCTL) |= groupLatch;
}
void Timer_B_initCompareLatchLoadEvent(uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareLatchLoadEvent
)
{
HWREG16(baseAddress + compareRegister) &= ~CLLD_3;
HWREG16(baseAddress + compareRegister) |= compareLatchLoadEvent;
}
uint16_t Timer_B_getCounterValue (uint16_t baseAddress)
{
uint16_t voteOne, voteTwo, res;
voteTwo = HWREG16(baseAddress + OFS_TBxR);
do
{
voteOne = voteTwo;
voteTwo = HWREG16(baseAddress + OFS_TBxR);
if(voteTwo > voteOne) {
res = voteTwo - voteOne;
} else if(voteOne > voteTwo) {
res = voteOne - voteTwo;
} else{
res = 0;
}
} while ( res > TIMER_B_THRESHOLD);
return voteTwo;
}
void Timer_B_setOutputMode(uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareOutputMode)
{
uint16_t temp = HWREG16(baseAddress + compareRegister);
HWREG16(baseAddress + compareRegister) = temp & ~(OUTMOD_7) | compareOutputMode;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for timer_b_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,551 @@
//*****************************************************************************
//
// timer_d.c - Driver for the timer_d Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup timer_d_api timer_d
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_TxD7__
#include "timer_d.h"
#include <assert.h>
#include "tlv.h"
void Timer_D_startCounter ( uint16_t baseAddress,
uint16_t timerMode
)
{
HWREG16(baseAddress + OFS_TDxCTL0) |= timerMode;
}
void Timer_D_initContinuousMode(uint16_t baseAddress,
Timer_D_initContinuousModeParam *param)
{
HWREG16(baseAddress +
OFS_TDxCTL0) &= ~(TIMER_D_CLOCKSOURCE_INVERTED_EXTERNAL_TDCLK +
TIMER_D_UPDOWN_MODE +
TIMER_D_DO_CLEAR +
TIMER_D_TDIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TDxCTL1) &= ~(TDCLKM0 + TDCLKM1 + TDIDEX_7);
HWREG16(baseAddress + OFS_TDxCTL0) |= param->clockSource;
HWREG16(baseAddress + OFS_TDxCTL1) |= (param->clockingMode +
((param->clockSourceDivider&0x7)<<8));
HWREG16(baseAddress + OFS_TDxCTL0) |= (param->timerClear +
param->timerInterruptEnable_TDIE +
((param->clockSourceDivider>>3)<<6));
}
void Timer_D_initUpMode(uint16_t baseAddress, Timer_D_initUpModeParam *param)
{
HWREG16(baseAddress + OFS_TDxCTL0) &=
~(TIMER_D_CLOCKSOURCE_INVERTED_EXTERNAL_TDCLK +
TIMER_D_UPDOWN_MODE +
TIMER_D_DO_CLEAR +
TIMER_D_TDIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TDxCTL1) &= ~(TDCLKM0 + TDCLKM1 + TDIDEX_7);
HWREG16(baseAddress + OFS_TDxCTL0) |= param->clockSource;
HWREG16(baseAddress + OFS_TDxCTL1) |= (param->clockingMode +
((param->clockSourceDivider&0x7)<<8));
HWREG16(baseAddress + OFS_TDxCTL0) |= (TIMER_D_STOP_MODE +
param->timerClear +
param->timerInterruptEnable_TDIE +
((param->clockSourceDivider>>3)<<6));
if (TIMER_D_CCIE_CCR0_INTERRUPT_ENABLE ==
param->captureCompareInterruptEnable_CCR0_CCIE){
HWREG16(baseAddress + OFS_TDxCCTL0) |= TIMER_D_CCIE_CCR0_INTERRUPT_ENABLE;
} else {
HWREG16(baseAddress + OFS_TDxCCTL0) &= ~TIMER_D_CCIE_CCR0_INTERRUPT_ENABLE;
}
HWREG16(baseAddress + OFS_TDxCCR0) = param->timerPeriod;
}
void Timer_D_initUpDownMode(uint16_t baseAddress,
Timer_D_initUpDownModeParam *param)
{
HWREG16(baseAddress + OFS_TDxCTL0) &=
~(TIMER_D_CLOCKSOURCE_INVERTED_EXTERNAL_TDCLK +
TIMER_D_UPDOWN_MODE +
TIMER_D_DO_CLEAR +
TIMER_D_TDIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TDxCTL1) &= ~(TDCLKM0 + TDCLKM1 + TDIDEX_7);
HWREG16(baseAddress + OFS_TDxCTL0) |= param->clockSource;
HWREG16(baseAddress + OFS_TDxCTL1) |= (param->clockingMode +
((param->clockSourceDivider&0x7)<<8));
HWREG16(baseAddress + OFS_TDxCTL0) |= (TIMER_D_STOP_MODE +
param->timerClear +
param->timerInterruptEnable_TDIE +
((param->clockSourceDivider>>3)<<6));
if (TIMER_D_CCIE_CCR0_INTERRUPT_ENABLE ==
param->captureCompareInterruptEnable_CCR0_CCIE){
HWREG16(baseAddress + OFS_TDxCCTL0) |= TIMER_D_CCIE_CCR0_INTERRUPT_ENABLE;
} else {
HWREG16(baseAddress + OFS_TDxCCTL0) &= ~TIMER_D_CCIE_CCR0_INTERRUPT_ENABLE;
}
HWREG16(baseAddress + OFS_TDxCCR0) = param->timerPeriod;
}
void Timer_D_initCaptureMode(uint16_t baseAddress,
Timer_D_initCaptureModeParam *param)
{
HWREG16(baseAddress + param->captureRegister ) |= CAP;
HWREG8(baseAddress + OFS_TDxCTL2) |=
(param->channelCaptureMode << ((param->captureRegister - TIMER_D_CAPTURECOMPARE_REGISTER_0)/6));
HWREG16(baseAddress + param->captureRegister) &=
~(TIMER_D_CAPTUREMODE_RISING_AND_FALLING_EDGE +
TIMER_D_CAPTURE_INPUTSELECT_Vcc +
TIMER_D_CAPTURE_SYNCHRONOUS +
TIMER_D_DO_CLEAR +
TIMER_D_TDIE_INTERRUPT_ENABLE +
CM_3
);
HWREG16(baseAddress + param->captureRegister) |= (param->captureMode +
param->captureInputSelect +
param->synchronizeCaptureSource +
param->captureInterruptEnable +
param->captureOutputMode
);
}
void Timer_D_initCompareMode(uint16_t baseAddress,
Timer_D_initCompareModeParam *param)
{
HWREG16(baseAddress + param->compareRegister ) &= ~CAP;
HWREG16(baseAddress + param->compareRegister) &=
~(TIMER_D_CAPTURECOMPARE_INTERRUPT_ENABLE +
TIMER_D_OUTPUTMODE_RESET_SET
);
HWREG16(baseAddress + param->compareRegister) |= (param->compareInterruptEnable +
param->compareOutputMode
);
HWREG16(baseAddress + param->compareRegister + 2) = param->compareValue;
}
void Timer_D_enableTimerInterrupt (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_TDxCTL0) &= ~TDIFG;
HWREG8(baseAddress + OFS_TDxCTL0) |= TDIE;
}
void Timer_D_enableHighResInterrupt (uint16_t baseAddress,
uint16_t mask)
{
HWREG16(baseAddress + OFS_TDxHINT) &= ~(mask >> 8);
HWREG16(baseAddress + OFS_TDxHINT) |= mask;
}
void Timer_D_disableTimerInterrupt (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_TDxCTL0) &= ~TDIE;
}
void Timer_D_disableHighResInterrupt (uint16_t baseAddress,
uint16_t mask)
{
HWREG16(baseAddress + OFS_TDxHINT) &= ~mask;
}
uint32_t Timer_D_getTimerInterruptStatus (uint16_t baseAddress)
{
return (HWREG8(baseAddress + OFS_TDxCTL0) & TDIFG);
}
void Timer_D_enableCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG8(baseAddress + captureCompareRegister) &= ~CCIFG;
HWREG16(baseAddress + captureCompareRegister) |= CCIE;
}
void Timer_D_disableCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~CCIE;
}
uint32_t Timer_D_getCaptureCompareInterruptStatus (uint16_t baseAddress,
uint16_t captureCompareRegister,
uint16_t mask
)
{
return ( HWREG16(baseAddress + captureCompareRegister) & mask );
}
uint16_t Timer_D_getHighResInterruptStatus (uint16_t baseAddress,
uint16_t mask)
{
mask = (mask >> 8);
return ( (HWREG16(baseAddress + OFS_TDxHINT) & mask) << 8 );
}
void Timer_D_clear (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxCTL0) |= TDCLR;
}
void Timer_D_clearHighResInterrupt (uint16_t baseAddress,
uint16_t mask)
{
mask = (mask >> 8);
HWREG16(baseAddress + OFS_TDxHINT) &= ~mask;
}
uint8_t Timer_D_getSynchronizedCaptureCompareInput
(uint16_t baseAddress,
uint16_t captureCompareRegister,
uint16_t synchronized
)
{
if (HWREG16(baseAddress + captureCompareRegister) & synchronized){
return ( TIMER_D_CAPTURECOMPARE_INPUT_HIGH) ;
} else {
return ( TIMER_D_CAPTURECOMPARE_INPUT_LOW) ;
}
}
uint8_t Timer_D_getOutputForOutputModeOutBitValue
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
if (HWREG16(baseAddress + captureCompareRegister) & OUT){
return ( TIMER_D_OUTPUTMODE_OUTBITVALUE_HIGH) ;
} else {
return ( TIMER_D_OUTPUTMODE_OUTBITVALUE_LOW) ;
}
}
uint16_t Timer_D_getCaptureCompareCount
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
return (HWREG16(baseAddress + captureCompareRegister + 2));
}
uint16_t Timer_D_getCaptureCompareLatchCount
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
return (HWREG16(baseAddress + captureCompareRegister + 4));
}
uint8_t Timer_D_getCaptureCompareInputSignal
(uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
return ((HWREG8(baseAddress + captureCompareRegister) & CCI));
}
void Timer_D_setOutputForOutputModeOutBitValue
(uint16_t baseAddress,
uint16_t captureCompareRegister,
uint8_t outputModeOutBitValue
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~OUT;
HWREG16(baseAddress + captureCompareRegister) |= outputModeOutBitValue;
}
void Timer_D_outputPWM(uint16_t baseAddress, Timer_D_outputPWMParam *param)
{
HWREG16(baseAddress + OFS_TDxCTL1) &= ~(TDCLKM0 + TDCLKM1 + TDIDEX_7);
HWREG16(baseAddress + OFS_TDxCTL0) &=
~(TIMER_D_CLOCKSOURCE_INVERTED_EXTERNAL_TDCLK +
TIMER_D_UPDOWN_MODE + TIMER_D_DO_CLEAR +
TIMER_D_TDIE_INTERRUPT_ENABLE +
ID__8
);
HWREG16(baseAddress + OFS_TDxCTL0) |= param->clockSource;
HWREG16(baseAddress + OFS_TDxCTL1) |= (param->clockingMode +
((param->clockSourceDivider&0x7)<<8));
HWREG16(baseAddress + OFS_TDxCTL0) |= (TIMER_D_UP_MODE +
TIMER_D_DO_CLEAR +
((param->clockSourceDivider>>3)<<6));
HWREG16(baseAddress + OFS_TDxCCR0) = param->timerPeriod;
HWREG16(baseAddress + OFS_TDxCCTL0) &=
~(TIMER_D_CAPTURECOMPARE_INTERRUPT_ENABLE +
TIMER_D_OUTPUTMODE_RESET_SET
);
HWREG16(baseAddress + param->compareRegister) |= param->compareOutputMode;
HWREG16(baseAddress + param->compareRegister + 2) = param->dutyCycle;
}
void Timer_D_stop ( uint16_t baseAddress )
{
HWREG16(baseAddress + OFS_TDxCTL0) &= ~MC_3;
}
void Timer_D_setCompareValue ( uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareValue
)
{
HWREG16(baseAddress + compareRegister + 0x02) = compareValue;
}
void Timer_D_clearTimerInterrupt (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxCTL0) &= ~TDIFG;
}
void Timer_D_clearCaptureCompareInterrupt (uint16_t baseAddress,
uint16_t captureCompareRegister
)
{
HWREG16(baseAddress + captureCompareRegister) &= ~CCIFG;
}
uint8_t Timer_D_initHighResGeneratorInFreeRunningMode
(uint16_t baseAddress,
uint8_t desiredHighResFrequency
)
{
struct s_TLV_Timer_D_Cal_Data * pTD0CAL;
uint8_t TD0CAL_bytes;
// Read the TimerD TLV Data
TLV_getInfo(TLV_TAG_TIMER_D_CAL,
0,
&TD0CAL_bytes,
(uint16_t **)&pTD0CAL
);
if(0x00 == TD0CAL_bytes)
{
// No TimerD free running cal data found
return STATUS_FAIL;
}
HWREG16(baseAddress + OFS_TDxHCTL1) = TDHCLKTRIM6;
HWREG16(baseAddress + OFS_TDxCTL1) = 0x00;
HWREG16(baseAddress + OFS_TDxHCTL0) = 0x00;
switch( desiredHighResFrequency )
{
case TIMER_D_HIGHRES_64MHZ:
HWREG16(baseAddress + OFS_TDxHCTL1) = pTD0CAL->TDH0CTL1_64;
break;
case TIMER_D_HIGHRES_128MHZ:
HWREG16(baseAddress + OFS_TDxHCTL1) = pTD0CAL->TDH0CTL1_128;
break;
case TIMER_D_HIGHRES_200MHZ:
HWREG16(baseAddress + OFS_TDxHCTL1) = pTD0CAL->TDH0CTL1_200;
break;
case TIMER_D_HIGHRES_256MHZ:
HWREG16(baseAddress + OFS_TDxHCTL1) = pTD0CAL->TDH0CTL1_256;
break;
}
// Select Hi-res local clock
HWREG16(baseAddress + OFS_TDxCTL1) |= TDCLKM_1;
// CALEN=0 => free running mode; enable Hi-res mode
if(TIMER_D_HIGHRES_256MHZ == desiredHighResFrequency)
HWREG16(baseAddress + OFS_TDxHCTL0) |= TDHM_1;
HWREG16(baseAddress + OFS_TDxHCTL0) |= TDHEN;
return STATUS_SUCCESS;
}
void Timer_D_initHighResGeneratorInRegulatedMode(uint16_t baseAddress,
Timer_D_initHighResGeneratorInRegulatedModeParam *param)
{
HWREG16(baseAddress + OFS_TDxCTL0) &= ~(TDSSEL_3 + TDHD_3 + TDCLR + ID__8);
HWREG16(baseAddress + OFS_TDxCTL1) &= ~(TDCLKM0 + TDCLKM1 + TDIDEX_7);
HWREG16(baseAddress + OFS_TDxCTL0) |= (param->clockSource +
((param->clockSourceDivider>>3)<<6));
HWREG16(baseAddress + OFS_TDxCTL1) |= (param->clockingMode +
((param->clockSourceDivider&0x7)<<8));
// Select Hi-res local clock
// Calibration and Hi-res mode enable
HWREG16(baseAddress + OFS_TDxCTL1) |= TDCLKM_1;
// Select Hi-res local clock
HWREG16(baseAddress + OFS_TDxHCTL0) = TDHREGEN + TDHEN ;
HWREG16(baseAddress + OFS_TDxHCTL0) |= param->highResClockMultiplyFactor +
param->highResClockDivider;
}
void Timer_D_combineTDCCRToOutputPWM(uint16_t baseAddress,
Timer_D_combineTDCCRToOutputPWMParam *param)
{
HWREG16(baseAddress + OFS_TDxCCTL2) &= ~OUTMOD_7;
HWREG16(baseAddress + OFS_TDxCCTL2) |= param->compareOutputMode;
HWREG16(baseAddress + OFS_TDxCCR0) = param->timerPeriod;
HWREG16(baseAddress + OFS_TDxCCR1 + (0x05 *
(param->combineCCRRegistersCombination - TIMER_D_COMBINE_CCR1_CCR2))) = param->dutyCycle1;
HWREG16(baseAddress + OFS_TDxCCR2 + (0x05 *
(param->combineCCRRegistersCombination - TIMER_D_COMBINE_CCR1_CCR2))) = param->dutyCycle2;
HWREG16(baseAddress + OFS_TDxCTL0) &= ~ID__8;
HWREG16(baseAddress + OFS_TDxCTL1) &= ~(TDCLKM0 + TDCLKM1 + TDIDEX_7);
HWREG16(baseAddress + OFS_TDxCTL0) |= (param->clockSource +
((param->clockSourceDivider>>3)<<6));
HWREG16(baseAddress + OFS_TDxCTL1) |= (param->clockingMode +
((param->clockSourceDivider&0x7)<<8));
HWREG16(baseAddress + OFS_TDxCTL1) |=
(TD2CMB << (param->combineCCRRegistersCombination - TIMER_D_COMBINE_CCR1_CCR2));
}
void Timer_D_selectLatchingGroup(uint16_t baseAddress,
uint16_t groupLatch)
{
HWREG16(baseAddress + OFS_TDxCTL0) &= ~TDCLGRP_3;
HWREG16(baseAddress + OFS_TDxCTL0) |= groupLatch;
}
void Timer_D_selectCounterLength (uint16_t baseAddress,
uint16_t counterLength
)
{
HWREG16(baseAddress + OFS_TDxCTL0) &= ~CNTL_3;
HWREG16(baseAddress + OFS_TDxCTL0) |= counterLength;
}
void Timer_D_initCompareLatchLoadEvent(uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareLatchLoadEvent
)
{
HWREG16(baseAddress + compareRegister) &= ~CLLD_3;
HWREG16(baseAddress + compareRegister) |= compareLatchLoadEvent;
}
void Timer_D_disableHighResFastWakeup (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxHCTL0) &= ~TDHFW;
}
void Timer_D_enableHighResFastWakeup (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxHCTL0) |= TDHFW;
}
void Timer_D_disableHighResClockEnhancedAccuracy (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxHCTL0) &= ~TDHEAEN;
}
void Timer_D_enableHighResClockEnhancedAccuracy (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxHCTL0) |= TDHEAEN;
}
void Timer_D_disableHighResGeneratorForceON (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxHCTL0) &= ~TDHRON;
}
void Timer_D_enableHighResGeneratorForceON (uint16_t baseAddress)
{
HWREG16(baseAddress + OFS_TDxHCTL0) |= TDHRON;
}
void Timer_D_selectHighResCoarseClockRange (uint16_t baseAddress,
uint16_t highResCoarseClockRange
)
{
HWREG16(baseAddress + OFS_TDxHCTL1) &= ~TDHCLKCR;
HWREG16(baseAddress + OFS_TDxHCTL1) |= highResCoarseClockRange;
}
void Timer_D_selectHighResClockRange (uint16_t baseAddress,
uint16_t highResClockRange
)
{
HWREG16(baseAddress + OFS_TDxHCTL1) &= ~TDHCLKCR;
HWREG16(baseAddress + OFS_TDxHCTL1) |= highResClockRange;
}
uint16_t Timer_D_getCounterValue (uint16_t baseAddress)
{
uint16_t voteOne, voteTwo, res;
voteTwo = HWREG16(baseAddress + OFS_TDxR);
do
{
voteOne = voteTwo;
voteTwo = HWREG16(baseAddress + OFS_TDxR);
if(voteTwo > voteOne) {
res = voteTwo - voteOne;
} else if(voteOne > voteTwo) {
res = voteOne - voteTwo;
} else{
res = 0;
}
} while ( res > TIMER_D_THRESHOLD);
return voteTwo;
}
void Timer_D_setOutputMode(uint16_t baseAddress,
uint16_t compareRegister,
uint16_t compareOutputMode)
{
uint16_t temp = HWREG16(baseAddress + compareRegister);
HWREG16(baseAddress + compareRegister) = temp & ~(OUTMOD_7) | compareOutputMode;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for timer_d_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,216 @@
//*****************************************************************************
//
// tlv.c - Driver for the tlv Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup tlv_api tlv
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_TLV__
#include "tlv.h"
#include <assert.h>
void TLV_getInfo(uint8_t tag,
uint8_t instance,
uint8_t *length,
uint16_t **data_address
)
{
// TLV Structure Start Address
char *TLV_address = (char *)TLV_START;
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)
{
// repeat till requested instance is reached
instance--;
}
// add (Current TAG address + LENGTH) + 2
TLV_address += *(TLV_address + 1) + 2;
}
// Check if Tag match happened..
if (*TLV_address == tag)
{
// Return length = Address + 1
*length = *(TLV_address + 1);
// Return address of first data/value info = Address + 2
*data_address = (uint16_t *)(TLV_address + 2);
}
// If there was no tag match and the end of TLV structure was reached..
else
{
// Return 0 for TAG not found
*length = 0;
// Return 0 for TAG not found
*data_address = 0;
}
}
uint16_t TLV_getDeviceType()
{
uint16_t *pDeviceType = (uint16_t *)TLV_DEVICE_ID_0;
// Return Value from TLV Table
return pDeviceType[0];
}
uint16_t TLV_getMemory(uint8_t instance)
{
uint8_t *pPDTAG;
uint8_t bPDTAG_bytes;
uint16_t count;
// set tag for word access comparison
instance *= 2;
// TLV access Function Call
// Get Peripheral data pointer
TLV_getInfo(TLV_PDTAG,
0,
&bPDTAG_bytes,
(uint16_t **)&pPDTAG
);
if (pPDTAG != 0)
{
for (count = 0; count <= instance; count += 2)
{
if (pPDTAG[count] == 0)
{
// Return 0 if end reached
return 0;
}
if (count == instance)
{
return (pPDTAG[count] | pPDTAG[count+1]<<8);
}
} // for count
} // pPDTAG != 0
// Return 0: not found
return 0;
}
uint16_t TLV_getPeripheral(uint8_t tag,
uint8_t instance
)
{
uint8_t *pPDTAG;
uint8_t bPDTAG_bytes;
uint16_t count = 0;
uint16_t pcount = 0;
// Get Peripheral data pointer
TLV_getInfo(TLV_PDTAG,
0,
&bPDTAG_bytes,
(uint16_t **)&pPDTAG
);
if (pPDTAG != 0)
{
// read memory configuration from TLV to get offset for Peripherals
while (TLV_getMemory(count))
{
count++;
}
// get number of Peripheral entries
pcount = pPDTAG[count * 2 + 1];
// inc count to first Periperal
count++;
// adjust point to first address of Peripheral
pPDTAG += count*2;
// set counter back to 0
count = 0;
// align pcount for work comparision
pcount *= 2;
// 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 found data
return (pPDTAG[count] | pPDTAG[count + 1] << 8);
}
} // pPDTAG[count+1] == tag
} // for count
} // pPDTAG != 0
// Return 0: not found
return 0;
}
uint8_t TLV_getInterrupt(uint8_t tag)
{
uint8_t *pPDTAG;
uint8_t bPDTAG_bytes;
uint16_t count = 0;
uint16_t pcount = 0;
// Get Peripheral data pointer
TLV_getInfo(TLV_PDTAG,
0,
&bPDTAG_bytes,
(uint16_t **)&pPDTAG
);
if (pPDTAG != 0)
{
// read memory configuration from TLV to get offset for Peripherals
while (TLV_getMemory(count))
{
count++;
}
pcount = pPDTAG[count * 2 + 1];
// inc count to first Periperal
count++;
// adjust point to first address of Peripheral
pPDTAG += (pcount + count) * 2;
// set counter back to 0
count = 0;
// TLV access Function Call
for (count = 0; count <= tag; count += 2)
{
if (pPDTAG[count] == 0)
{
// Return 0: not found/end of table
return 0;
}
if (count == tag)
{
// Return found data
return (pPDTAG[count]);
}
} // for count
} // pPDTAG != 0
// Return 0: not found
return 0;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for tlv_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,405 @@
//*****************************************************************************
//
// tlv.h - Driver for the TLV Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_TLV_H__
#define __MSP430WARE_TLV_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_TLV__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//******************************************************************************
//
// TLV Data Types
//
//******************************************************************************
struct s_TLV_Die_Record {
uint32_t wafer_id;
uint16_t die_x_position;
uint16_t die_y_position;
uint16_t test_results;
};
struct s_TLV_ADC_Cal_Data {
uint16_t adc_gain_factor;
int16_t adc_offset;
uint16_t adc_ref15_30_temp;
uint16_t adc_ref15_85_temp;
uint16_t adc_ref20_30_temp;
uint16_t adc_ref20_85_temp;
uint16_t adc_ref25_30_temp;
uint16_t adc_ref25_85_temp;
};
struct s_TLV_Timer_D_Cal_Data {
uint16_t TDH0CTL1_64;
uint16_t TDH0CTL1_128;
uint16_t TDH0CTL1_200;
uint16_t TDH0CTL1_256;
};
struct s_TLV_REF_Cal_Data {
uint16_t ref_ref15;
uint16_t ref_ref20;
uint16_t ref_ref25;
};
struct s_Peripheral_Memory_Data {
uint16_t memory_1;
uint16_t memory_2;
uint16_t memory_3;
uint16_t memory_4;
};
//*****************************************************************************
//
// The following are values that can be passed to the tag parameter for
// functions: TLV_getInfo().
//
//*****************************************************************************
#define TLV_TAG_LDTAG TLV_LDTAG
#define TLV_TAG_PDTAG TLV_PDTAG
#define TLV_TAG_Reserved3 TLV_Reserved3
#define TLV_TAG_Reserved4 TLV_Reserved4
#define TLV_TAG_BLANK TLV_BLANK
#define TLV_TAG_Reserved6 TLV_Reserved6
#define TLV_TAG_Reserved7 TLV_Reserved7
#define TLV_TAG_TAGEND TLV_TAGEND
#define TLV_TAG_TAGEXT TLV_TAGEXT
#define TLV_TAG_TIMER_D_CAL TLV_TIMERDCAL
#define TLV_DEVICE_ID_0 0x1A04
#define TLV_DEVICE_ID_1 0x1A05
#define TLV_TAG_DIERECORD TLV_DIERECORD
#define TLV_TAG_ADCCAL TLV_ADCCAL
#define TLV_TAG_ADC12CAL TLV_ADC12CAL
#define TLV_TAG_ADC10CAL TLV_ADC10CAL
#define TLV_TAG_REFCAL TLV_REFCAL
#define TLV_TAG_CTSD16CAL 0x1D
//*****************************************************************************
//
// The following are values that can be passed to the tag parameter for
// functions: TLV_getPeripheral().
//
//*****************************************************************************
#define TLV_PID_NO_MODULE (0x00)
#define TLV_PID_PORTMAPPING (0x10)
#define TLV_PID_MSP430CPUXV2 (0x23)
#define TLV_PID_JTAG (0x09)
#define TLV_PID_SBW (0x0F)
#define TLV_PID_EEM_XS (0x02)
#define TLV_PID_EEM_S (0x03)
#define TLV_PID_EEM_M (0x04)
#define TLV_PID_EEM_L (0x05)
#define TLV_PID_PMM (0x30)
#define TLV_PID_PMM_FR (0x32)
#define TLV_PID_FCTL (0x39)
#define TLV_PID_CRC16 (0x3C)
#define TLV_PID_CRC16_RB (0x3D)
#define TLV_PID_WDT_A (0x40)
#define TLV_PID_SFR (0x41)
#define TLV_PID_SYS (0x42)
#define TLV_PID_RAMCTL (0x44)
#define TLV_PID_DMA_1 (0x46)
#define TLV_PID_DMA_3 (0x47)
#define TLV_PID_UCS (0x48)
#define TLV_PID_DMA_6 (0x4A)
#define TLV_PID_DMA_2 (0x4B)
#define TLV_PID_PORT1_2 (0x51)
#define TLV_PID_PORT3_4 (0x52)
#define TLV_PID_PORT5_6 (0x53)
#define TLV_PID_PORT7_8 (0x54)
#define TLV_PID_PORT9_10 (0x55)
#define TLV_PID_PORT11_12 (0x56)
#define TLV_PID_PORTU (0x5E)
#define TLV_PID_PORTJ (0x5F)
#define TLV_PID_TA2 (0x60)
#define TLV_PID_TA3 (0x61)
#define TLV_PID_TA5 (0x62)
#define TLV_PID_TA7 (0x63)
#define TLV_PID_TB3 (0x65)
#define TLV_PID_TB5 (0x66)
#define TLV_PID_TB7 (0x67)
#define TLV_PID_RTC (0x68)
#define TLV_PID_BT_RTC (0x69)
#define TLV_PID_BBS (0x6A)
#define TLV_PID_RTC_B (0x6B)
#define TLV_PID_TD2 (0x6C)
#define TLV_PID_TD3 (0x6D)
#define TLV_PID_TD5 (0x6E)
#define TLV_PID_TD7 (0x6F)
#define TLV_PID_TEC (0x70)
#define TLV_PID_RTC_C (0x71)
#define TLV_PID_AES (0x80)
#define TLV_PID_MPY16 (0x84)
#define TLV_PID_MPY32 (0x85)
#define TLV_PID_MPU (0x86)
#define TLV_PID_USCI_AB (0x90)
#define TLV_PID_USCI_A (0x91)
#define TLV_PID_USCI_B (0x92)
#define TLV_PID_EUSCI_A (0x94)
#define TLV_PID_EUSCI_B (0x95)
#define TLV_PID_REF (0xA0)
#define TLV_PID_COMP_B (0xA8)
#define TLV_PID_COMP_D (0xA9)
#define TLV_PID_USB (0x98)
#define TLV_PID_LCD_B (0xB1)
#define TLV_PID_LCD_C (0xB2)
#define TLV_PID_DAC12_A (0xC0)
#define TLV_PID_SD16_B_1 (0xC8)
#define TLV_PID_SD16_B_2 (0xC9)
#define TLV_PID_SD16_B_3 (0xCA)
#define TLV_PID_SD16_B_4 (0xCB)
#define TLV_PID_SD16_B_5 (0xCC)
#define TLV_PID_SD16_B_6 (0xCD)
#define TLV_PID_SD16_B_7 (0xCE)
#define TLV_PID_SD16_B_8 (0xCF)
#define TLV_PID_ADC12_A (0xD1)
#define TLV_PID_ADC10_A (0xD3)
#define TLV_PID_ADC10_B (0xD4)
#define TLV_PID_SD16_A (0xD8)
#define TLV_PID_TI_BSL (0xFC)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Gets TLV Info
//!
//! The TLV structure uses a tag or base address to identify segments of the
//! table where information is stored. Some examples of TLV tags are Peripheral
//! Descriptor, Interrupts, Info Block and Die Record. This function retrieves
//! the value of a tag and the length of the tag.
//!
//! \param tag represents the tag for which the information needs to be
//! retrieved.
//! Valid values are:
//! - \b TLV_TAG_LDTAG
//! - \b TLV_TAG_PDTAG
//! - \b TLV_TAG_Reserved3
//! - \b TLV_TAG_Reserved4
//! - \b TLV_TAG_BLANK
//! - \b TLV_TAG_Reserved6
//! - \b TLV_TAG_Reserved7
//! - \b TLV_TAG_TAGEND
//! - \b TLV_TAG_TAGEXT
//! - \b TLV_TAG_TIMER_D_CAL
//! - \b TLV_DEVICE_ID_0
//! - \b TLV_DEVICE_ID_1
//! - \b TLV_TAG_DIERECORD
//! - \b TLV_TAG_ADCCAL
//! - \b TLV_TAG_ADC12CAL
//! - \b TLV_TAG_ADC10CAL
//! - \b TLV_TAG_REFCAL
//! - \b TLV_TAG_CTSD16CAL
//! \param instance In some cases a specific tag may have more than one
//! instance. For example there may be multiple instances of timer
//! calibration data present under a single Timer Cal tag. This variable
//! specifies the instance for which information is to be retrieved (0,
//! 1, etc.). When only one instance exists; 0 is passed.
//! \param length Acts as a return through indirect reference. The function
//! retrieves the value of the TLV tag length. This value is pointed to
//! by *length and can be used by the application level once the
//! function is called. If the specified tag is not found then the
//! pointer is null 0.
//! \param data_address acts as a return through indirect reference. Once the
//! function is called data_address points to the pointer that holds the
//! value retrieved from the specified TLV tag. If the specified tag is
//! not found then the pointer is null 0.
//!
//! \return None
//
//*****************************************************************************
extern void TLV_getInfo(uint8_t tag,
uint8_t instance,
uint8_t *length,
uint16_t **data_address);
//*****************************************************************************
//
//! \brief Retrieves the unique device ID from the TLV structure.
//!
//!
//! \return The device ID is returned as type uint16_t.
//
//*****************************************************************************
extern uint16_t TLV_getDeviceType(void);
//*****************************************************************************
//
//! \brief Gets memory information
//!
//! The Peripheral Descriptor tag is split into two portions a list of the
//! available flash memory blocks followed by a list of available peripherals.
//! This function is used to parse through the first portion and calculate the
//! total flash memory available in a device. The typical usage is to call the
//! TLV_getMemory which returns a non-zero value until the entire memory list
//! has been parsed. When a zero is returned, it indicates that all the memory
//! blocks have been counted and the next address holds the beginning of the
//! device peripheral list.
//!
//! \param instance In some cases a specific tag may have more than one
//! instance. This variable specifies the instance for which information
//! is to be retrieved (0, 1 etc). When only one instance exists; 0 is
//! passed.
//!
//! \return The returned value is zero if the end of the memory list is
//! reached.
//
//*****************************************************************************
extern uint16_t TLV_getMemory(uint8_t instance);
//*****************************************************************************
//
//! \brief Gets peripheral information from the TLV
//!
//! he Peripheral Descriptor tag is split into two portions a list of the
//! available flash memory blocks followed by a list of available peripherals.
//! This function is used to parse through the second portion and can be used
//! to check if a specific peripheral is present in a device. The function
//! calls TLV_getPeripheral() recursively until the end of the memory list and
//! consequently the beginning of the peripheral list is reached. <
//!
//! \param tag represents represents the tag for a specific peripheral for
//! which the information needs to be retrieved. In the header file tlv.
//! h specific peripheral tags are pre-defined, for example USCIA_B and
//! TA0 are defined as TLV_PID_USCI_AB and TLV_PID_TA2 respectively.
//! Valid values are:
//! - \b TLV_PID_NO_MODULE - No Module
//! - \b TLV_PID_PORTMAPPING - Port Mapping
//! - \b TLV_PID_MSP430CPUXV2 - MSP430CPUXV2
//! - \b TLV_PID_JTAG - JTAG
//! - \b TLV_PID_SBW - SBW
//! - \b TLV_PID_EEM_XS - EEM X-Small
//! - \b TLV_PID_EEM_S - EEM Small
//! - \b TLV_PID_EEM_M - EEM Medium
//! - \b TLV_PID_EEM_L - EEM Large
//! - \b TLV_PID_PMM - PMM
//! - \b TLV_PID_PMM_FR - PMM FRAM
//! - \b TLV_PID_FCTL - Flash
//! - \b TLV_PID_CRC16 - CRC16
//! - \b TLV_PID_CRC16_RB - CRC16 Reverse
//! - \b TLV_PID_WDT_A - WDT_A
//! - \b TLV_PID_SFR - SFR
//! - \b TLV_PID_SYS - SYS
//! - \b TLV_PID_RAMCTL - RAMCTL
//! - \b TLV_PID_DMA_1 - DMA 1
//! - \b TLV_PID_DMA_3 - DMA 3
//! - \b TLV_PID_UCS - UCS
//! - \b TLV_PID_DMA_6 - DMA 6
//! - \b TLV_PID_DMA_2 - DMA 2
//! - \b TLV_PID_PORT1_2 - Port 1 + 2 / A
//! - \b TLV_PID_PORT3_4 - Port 3 + 4 / B
//! - \b TLV_PID_PORT5_6 - Port 5 + 6 / C
//! - \b TLV_PID_PORT7_8 - Port 7 + 8 / D
//! - \b TLV_PID_PORT9_10 - Port 9 + 10 / E
//! - \b TLV_PID_PORT11_12 - Port 11 + 12 / F
//! - \b TLV_PID_PORTU - Port U
//! - \b TLV_PID_PORTJ - Port J
//! - \b TLV_PID_TA2 - Timer A2
//! - \b TLV_PID_TA3 - Timer A1
//! - \b TLV_PID_TA5 - Timer A5
//! - \b TLV_PID_TA7 - Timer A7
//! - \b TLV_PID_TB3 - Timer B3
//! - \b TLV_PID_TB5 - Timer B5
//! - \b TLV_PID_TB7 - Timer B7
//! - \b TLV_PID_RTC - RTC
//! - \b TLV_PID_BT_RTC - BT + RTC
//! - \b TLV_PID_BBS - Battery Backup Switch
//! - \b TLV_PID_RTC_B - RTC_B
//! - \b TLV_PID_TD2 - Timer D2
//! - \b TLV_PID_TD3 - Timer D1
//! - \b TLV_PID_TD5 - Timer D5
//! - \b TLV_PID_TD7 - Timer D7
//! - \b TLV_PID_TEC - Timer Event Control
//! - \b TLV_PID_RTC_C - RTC_C
//! - \b TLV_PID_AES - AES
//! - \b TLV_PID_MPY16 - MPY16
//! - \b TLV_PID_MPY32 - MPY32
//! - \b TLV_PID_MPU - MPU
//! - \b TLV_PID_USCI_AB - USCI_AB
//! - \b TLV_PID_USCI_A - USCI_A
//! - \b TLV_PID_USCI_B - USCI_B
//! - \b TLV_PID_EUSCI_A - eUSCI_A
//! - \b TLV_PID_EUSCI_B - eUSCI_B
//! - \b TLV_PID_REF - Shared Reference
//! - \b TLV_PID_COMP_B - COMP_B
//! - \b TLV_PID_COMP_D - COMP_D
//! - \b TLV_PID_USB - USB
//! - \b TLV_PID_LCD_B - LCD_B
//! - \b TLV_PID_LCD_C - LCD_C
//! - \b TLV_PID_DAC12_A - DAC12_A
//! - \b TLV_PID_SD16_B_1 - SD16_B 1 Channel
//! - \b TLV_PID_SD16_B_2 - SD16_B 2 Channel
//! - \b TLV_PID_SD16_B_3 - SD16_B 3 Channel
//! - \b TLV_PID_SD16_B_4 - SD16_B 4 Channel
//! - \b TLV_PID_SD16_B_5 - SD16_B 5 Channel
//! - \b TLV_PID_SD16_B_6 - SD16_B 6 Channel
//! - \b TLV_PID_SD16_B_7 - SD16_B 7 Channel
//! - \b TLV_PID_SD16_B_8 - SD16_B 8 Channel
//! - \b TLV_PID_ADC12_A - ADC12_A
//! - \b TLV_PID_ADC10_A - ADC10_A
//! - \b TLV_PID_ADC10_B - ADC10_B
//! - \b TLV_PID_SD16_A - SD16_A
//! - \b TLV_PID_TI_BSL - BSL
//! \param instance In some cases a specific tag may have more than one
//! instance. For example a device may have more than a single USCI
//! module, each of which is defined by an instance number 0, 1, 2, etc.
//! When only one instance exists; 0 is passed.
//!
//! \return The returned value is zero if the specified tag value (peripheral)
//! is not available in the device.
//
//*****************************************************************************
extern uint16_t TLV_getPeripheral(uint8_t tag,
uint8_t instance);
//*****************************************************************************
//
//! \brief Get interrupt information from the TLV
//!
//! This function is used to retrieve information on available interrupt
//! vectors. It allows the user to check if a specific interrupt vector is
//! defined in a given device.
//!
//! \param tag represents the tag for the interrupt vector. Interrupt vector
//! tags number from 0 to N depending on the number of available
//! interrupts. Refer to the device datasheet for a list of available
//! interrupts.
//!
//! \return The returned value is zero is the specified interrupt vector is not
//! defined.
//
//*****************************************************************************
extern uint8_t TLV_getInterrupt(uint8_t tag);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_TLV_H__

View File

@@ -0,0 +1,931 @@
//*****************************************************************************
//
// ucs.c - Driver for the ucs Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup ucs_api ucs
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#if defined(__MSP430_HAS_UCS__) || defined(__MSP430_HAS_UCS_RF__)
#include "ucs.h"
#include <assert.h>
#ifdef __GNUC__
#define __extension__(x)
__extension__(#define __delay_cycles(x) \
({ \
volatile unsigned int j; \
for (j=0;j<x;j++) \
{ \
__no_operation(); \
} \
})
);
#endif
#define CC430_DEVICE (defined (__CC430F5133__) || defined(__CC430F5135__) || defined(__CC430F5137__) || \
defined(__CC430F6125__) || defined(__CC430F6126__) || defined(__CC430F6127__) || \
defined(__CC430F6135__) || defined(__CC430F6137__) || defined(__CC430F5123__) || \
defined(__CC430F5125__) || defined(__CC430F5143__) || defined(__CC430F5145__) || \
defined(__CC430F5147__) || defined(__CC430F6143__) || defined(__CC430F6145__) || \
defined(__CC430F6147__))
#define NOT_CC430_DEVICE (!defined (__CC430F5133__) && !defined(__CC430F5135__) && !defined(__CC430F5137__) && \
!defined(__CC430F6125__) && !defined(__CC430F6126__) && !defined(__CC430F6127__) && \
!defined(__CC430F6135__) && !defined(__CC430F6137__) && !defined(__CC430F5123__) && \
!defined(__CC430F5125__) && !defined(__CC430F5143__) && !defined(__CC430F5145__) && \
!defined(__CC430F5147__) && !defined(__CC430F6143__) && !defined(__CC430F6145__) && \
!defined(__CC430F6147__))
//******************************************************************************
//
// The XT1 crystal frequency. Should be set with
// UCS_setExternalClockSource if XT1 is used and user intends to
// invoke UCS_getSMCLK, UCS_getMCLK or UCS_getACLK
//
//******************************************************************************
static uint32_t privateXT1ClockFrequency = 0;
//******************************************************************************
//
// The XT2 crystal frequency. Should be set with
// UCS_setExternalClockSource if XT1 is used and user intends to invoke
// UCS_getSMCLK, UCS_getMCLK or UCS_getACLK
//
//******************************************************************************
static uint32_t privateXT2ClockFrequency = 0;
static uint32_t privateUCSSourceClockFromDCO (uint16_t FLLRefCLKSource
)
{
assert((SELM__DCOCLKDIV == FLLRefCLKSource) ||
(SELM__DCOCLK == FLLRefCLKSource)
);
uint16_t D_value = 1;
uint16_t N_value;
uint16_t n_value = 1;
uint32_t Fref_value;
uint8_t i;
N_value = (HWREG16(UCS_BASE + OFS_UCSCTL2)) & 0x03FF;
uint16_t tempDivider = HWREG8(UCS_BASE + OFS_UCSCTL3) & FLLREFDIV_7;
if (tempDivider < 4) {
n_value <<= tempDivider;
}
else if (tempDivider == 4) {
n_value = 12;
}
else if (tempDivider == 5) {
n_value = 16;
}
switch ( (HWREG8(UCS_BASE + OFS_UCSCTL3)) & SELREF_7){
case SELREF__XT1CLK:
Fref_value = privateXT1ClockFrequency;
if(XTS != (HWREG16(UCS_BASE + OFS_UCSCTL6) & XTS)) {
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1LFOFFG){
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1LFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1LFOFFG){
Fref_value = UCS_REFOCLK_FREQUENCY;
}
}
}
else {
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1HFOFFG){
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1HFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1HFOFFG){
Fref_value = UCS_REFOCLK_FREQUENCY;
}
}
}
break;
case SELREF__REFOCLK:
Fref_value = UCS_REFOCLK_FREQUENCY;
break;
case SELREF__XT2CLK:
Fref_value = privateXT2ClockFrequency;
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG){
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT2OFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG){
Fref_value = UCS_REFOCLK_FREQUENCY;
}
}
break;
default: assert(0);
}
uint32_t CLKFrequency = Fref_value * ( N_value + 1) / n_value;
if (SELM__DCOCLK == FLLRefCLKSource){
tempDivider = (HWREG16(UCS_BASE + OFS_UCSCTL2)) & FLLD_7;
tempDivider = tempDivider >> 12;
for (i = 0; i < tempDivider; i++){
D_value = D_value * 2;
}
CLKFrequency *= D_value;
}
return ( CLKFrequency) ;
}
static uint32_t privateUCSComputeCLKFrequency (uint16_t CLKSource,
uint16_t CLKSourceDivider
)
{
uint32_t CLKFrequency;
uint8_t CLKSourceFrequencyDivider = 1;
uint8_t i = 0;
for ( i = 0; i < CLKSourceDivider; i++){
CLKSourceFrequencyDivider *= 2;
}
switch (CLKSource){
case SELM__XT1CLK:
CLKFrequency = (privateXT1ClockFrequency /
CLKSourceFrequencyDivider);
if(XTS != (HWREG16(UCS_BASE + OFS_UCSCTL6) & XTS)) {
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1LFOFFG){
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1LFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1LFOFFG){
CLKFrequency = UCS_REFOCLK_FREQUENCY;
}
}
}
else {
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1HFOFFG){
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1HFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1HFOFFG){
CLKFrequency = UCS_REFOCLK_FREQUENCY;
}
}
}
break;
case SELM__VLOCLK:
CLKFrequency =
(UCS_VLOCLK_FREQUENCY / CLKSourceFrequencyDivider);
break;
case SELM__REFOCLK:
CLKFrequency =
(UCS_REFOCLK_FREQUENCY / CLKSourceFrequencyDivider);
break;
case SELM__XT2CLK:
CLKFrequency =
(privateXT2ClockFrequency / CLKSourceFrequencyDivider);
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG){
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~XT2OFFG;
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
if (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG){
CLKFrequency =
privateUCSSourceClockFromDCO( SELM__DCOCLKDIV);
}
break;
case SELM__DCOCLK:
case SELM__DCOCLKDIV:
CLKFrequency = privateUCSSourceClockFromDCO(
CLKSource) / CLKSourceFrequencyDivider;
break;
}
return ( CLKFrequency) ;
}
void UCS_setExternalClockSource (uint32_t XT1CLK_frequency,
uint32_t XT2CLK_frequency
)
{
privateXT1ClockFrequency = XT1CLK_frequency;
privateXT2ClockFrequency = XT2CLK_frequency;
}
void UCS_initClockSignal (uint8_t selectedClockSignal,
uint16_t clockSource,
uint16_t clockSourceDivider
)
{
assert(
(UCS_XT1CLK_SELECT == clockSource) ||
(UCS_VLOCLK_SELECT == clockSource) ||
(UCS_REFOCLK_SELECT == clockSource) ||
(UCS_DCOCLK_SELECT == clockSource) ||
(UCS_DCOCLKDIV_SELECT == clockSource) ||
(UCS_XT2CLK_SELECT == clockSource)
);
assert(
(UCS_CLOCK_DIVIDER_1 == clockSourceDivider) ||
(UCS_CLOCK_DIVIDER_2 == clockSourceDivider) ||
(UCS_CLOCK_DIVIDER_4 == clockSourceDivider) ||
(UCS_CLOCK_DIVIDER_8 == clockSourceDivider) ||
(UCS_CLOCK_DIVIDER_16 == clockSourceDivider) ||
(UCS_CLOCK_DIVIDER_32 == clockSourceDivider)
);
uint16_t temp = HWREG16(UCS_BASE + OFS_UCSCTL5);
switch (selectedClockSignal){
case UCS_ACLK:
HWREG16(UCS_BASE + OFS_UCSCTL4) &= ~(SELA_7);
clockSource = clockSource << 8;
HWREG16(UCS_BASE + OFS_UCSCTL4) |= (clockSource);
clockSourceDivider = clockSourceDivider << 8;
HWREG16(UCS_BASE + OFS_UCSCTL5) = temp & ~(DIVA_7) | clockSourceDivider;
break;
case UCS_SMCLK:
HWREG16(UCS_BASE + OFS_UCSCTL4) &= ~(SELS_7);
clockSource = clockSource << 4;
HWREG16(UCS_BASE + OFS_UCSCTL4) |= (clockSource);
clockSourceDivider = clockSourceDivider << 4;
HWREG16(UCS_BASE + OFS_UCSCTL5) = temp & ~(DIVS_7) | clockSourceDivider;
break;
case UCS_MCLK:
HWREG16(UCS_BASE + OFS_UCSCTL4) &= ~(SELM_7);
HWREG16(UCS_BASE + OFS_UCSCTL4) |= (clockSource);
HWREG16(UCS_BASE + OFS_UCSCTL5) = temp & ~(DIVM_7) | clockSourceDivider;
break;
case UCS_FLLREF:
assert(clockSource <= SELA_5);
HWREG8(UCS_BASE + OFS_UCSCTL3) &= ~(SELREF_7);
clockSource = clockSource << 4;
HWREG8(UCS_BASE + OFS_UCSCTL3) |= (clockSource);
temp = HWREG8(UCS_BASE + OFS_UCSCTL3) & 0x00FF;
//Note that dividers for FLLREF are slightly different
//Hence handled differently from other CLK signals
switch(clockSourceDivider)
{
case UCS_CLOCK_DIVIDER_12:
HWREG8(UCS_BASE + OFS_UCSCTL3) = temp & ~(FLLREFDIV_7) | FLLREFDIV__12;
break;
case UCS_CLOCK_DIVIDER_16:
HWREG8(UCS_BASE + OFS_UCSCTL3) = temp & ~(FLLREFDIV_7) | FLLREFDIV__16;
break;
default:
HWREG8(UCS_BASE + OFS_UCSCTL3) = temp & ~(FLLREFDIV_7) | clockSourceDivider;
break;
}
break;
}
}
void UCS_turnOnLFXT1 (uint16_t xt1drive,
uint8_t xcap
)
{
assert((xcap == UCS_XCAP_0) ||
(xcap == UCS_XCAP_1) ||
(xcap == UCS_XCAP_2) ||
(xcap == UCS_XCAP_3) );
assert((xt1drive == UCS_XT1_DRIVE_0 ) ||
(xt1drive == UCS_XT1_DRIVE_1 ) ||
(xt1drive == UCS_XT1_DRIVE_2 ) ||
(xt1drive == UCS_XT1_DRIVE_3 ));
//Switch ON XT1 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1OFF;
//Highest drive setting for XT1startup
HWREG16(UCS_BASE + OFS_UCSCTL6_L) |= XT1DRIVE1_L + XT1DRIVE0_L;
//Enable LF mode and clear xcap and bypass
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~(XTS + XCAP_3 + XT1BYPASS);
HWREG16(UCS_BASE + OFS_UCSCTL6) |= xcap;
while (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1LFOFFG)
{
//Clear OSC flaut Flags fault flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1LFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
//set requested Drive mode
HWREG16(UCS_BASE + OFS_UCSCTL6) = ( HWREG16(UCS_BASE + OFS_UCSCTL6) &
~(XT1DRIVE_3)
) |
(xt1drive);
}
void UCS_turnOnHFXT1(uint16_t xt1drive
)
{
//Switch ON XT1 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1OFF;
//Check if drive value is the expected one
if ((HWREG16(UCS_BASE + OFS_UCSCTL6) & XT1DRIVE_3) != xt1drive){
//Clear XT1drive field
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1DRIVE_3;
//Set requested value
HWREG16(UCS_BASE + OFS_UCSCTL6) |= xt1drive;
}
//Enable HF mode
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XTS;
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1BYPASS;
// Check XT1 fault flags
while((HWREG8(UCS_BASE + OFS_UCSCTL7) & (XT1HFOFFG))){
//Clear OSC flaut Flags fault flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1HFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
}
void UCS_bypassXT1 (uint8_t highOrLowFrequency
)
{
assert((UCS_XT1_LOW_FREQUENCY == highOrLowFrequency) ||
(UCS_XT1_HIGH_FREQUENCY == highOrLowFrequency )
);
//Enable HF/LF mode
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XTS;
HWREG16(UCS_BASE + OFS_UCSCTL6) |= highOrLowFrequency;
//Switch OFF XT1 oscillator and enable BYPASS mode
HWREG16(UCS_BASE + OFS_UCSCTL6) |= (XT1BYPASS + XT1OFF);
if (UCS_XT1_LOW_FREQUENCY == highOrLowFrequency){
while (HWREG8(UCS_BASE + OFS_UCSCTL7) & (XT1LFOFFG)) {
//Clear OSC flaut Flags fault flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1LFOFFG);
// Clear the global fault flag. In case the XT1 caused the global fault
// flag to get set this will clear the global error condition. If any
// error condition persists, global flag will get again.
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
} else {
while (HWREG8(UCS_BASE + OFS_UCSCTL7) & (XT1HFOFFG)) {
//Clear OSC flaut Flags fault flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1HFOFFG);
//Clear the global fault flag. In case the XT1 caused the global fault
//flag to get set this will clear the global error condition. If any
//error condition persists, global flag will get again.
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
}
}
bool UCS_turnOnLFXT1WithTimeout(uint16_t xt1drive,
uint8_t xcap,
uint16_t timeout
)
{
assert((xcap == UCS_XCAP_0) ||
(xcap == UCS_XCAP_1) ||
(xcap == UCS_XCAP_2) ||
(xcap == UCS_XCAP_3) );
assert((xt1drive == UCS_XT1_DRIVE_0 ) ||
(xt1drive == UCS_XT1_DRIVE_1 ) ||
(xt1drive == UCS_XT1_DRIVE_2 ) ||
(xt1drive == UCS_XT1_DRIVE_3 ));
assert(timeout > 0);
//Switch ON XT1 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1OFF;
//Highest drive setting for XT1startup
HWREG16(UCS_BASE + OFS_UCSCTL6_L) |= XT1DRIVE1_L + XT1DRIVE0_L;
//Enable LF mode and clear xcap and bypass
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~(XTS + XCAP_3 + XT1BYPASS);
HWREG16(UCS_BASE + OFS_UCSCTL6) |= xcap;
do
{
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1LFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}while ((HWREG8(UCS_BASE + OFS_UCSCTL7) & XT1LFOFFG) && --timeout);
if (timeout){
//set requested Drive mode
HWREG16(UCS_BASE + OFS_UCSCTL6) = ( HWREG16(UCS_BASE + OFS_UCSCTL6) &
~(XT1DRIVE_3)
) |
(xt1drive);
return (STATUS_SUCCESS);
} else {
return (STATUS_FAIL);
}
}
bool UCS_turnOnHFXT1WithTimeout (uint16_t xt1drive,
uint16_t timeout
)
{
assert((xt1drive == UCS_XT1_DRIVE_0 ) ||
(xt1drive == UCS_XT1_DRIVE_1 ) ||
(xt1drive == UCS_XT1_DRIVE_2 ) ||
(xt1drive == UCS_XT1_DRIVE_3 ));
assert(timeout > 0);
//Switch ON XT1 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1OFF;
//Check if drive value is the expected one
if ((HWREG16(UCS_BASE + OFS_UCSCTL6) & XT1DRIVE_3) != xt1drive){
//Clear XT1drive field
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1DRIVE_3;
//Set requested value
HWREG16(UCS_BASE + OFS_UCSCTL6) |= xt1drive;
}
//Enable HF mode
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XTS;
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT1BYPASS;
// Check XT1 fault flags
do
{
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1HFOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}while ((HWREG8(UCS_BASE + OFS_UCSCTL7) & ( XT1HFOFFG))
&& --timeout);
if (timeout){
return (STATUS_SUCCESS);
} else {
return (STATUS_FAIL);
}
}
bool UCS_bypassXT1WithTimeout (uint8_t highOrLowFrequency,
uint16_t timeout
)
{
assert((UCS_XT1_LOW_FREQUENCY == highOrLowFrequency) ||
(UCS_XT1_HIGH_FREQUENCY == highOrLowFrequency )
);
assert(timeout > 0);
//Enable HF/LF mode
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XTS;
HWREG16(UCS_BASE + OFS_UCSCTL6) |= highOrLowFrequency;
//Switch OFF XT1 oscillator and enable bypass
HWREG16(UCS_BASE + OFS_UCSCTL6) |= (XT1BYPASS + XT1OFF);
if (UCS_XT1_LOW_FREQUENCY == highOrLowFrequency){
do {
//Clear OSC flaut Flags fault flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1LFOFFG);
// Clear the global fault flag. In case the XT1 caused the global fault
// flag to get set this will clear the global error condition. If any
// error condition persists, global flag will get again.
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}while ((HWREG8(UCS_BASE + OFS_UCSCTL7) & (XT1LFOFFG)) && --timeout);
} else {
do {
//Clear OSC flaut Flags fault flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT1HFOFFG);
//Clear the global fault flag. In case the XT1 caused the global fault
//flag to get set this will clear the global error condition. If any
//error condition persists, global flag will get again.
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}while ((HWREG8(UCS_BASE + OFS_UCSCTL7) & (XT1HFOFFG))&& --timeout);
}
if (timeout){
return (STATUS_SUCCESS);
} else {
return (STATUS_FAIL);
}
}
void UCS_turnOffXT1 (void)
{
//Switch off XT1 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XT1OFF;
}
void UCS_turnOnXT2 (uint16_t xt2drive
)
{
#if NOT_CC430_DEVICE
//Check if drive value is the expected one
if ((HWREG16(UCS_BASE + OFS_UCSCTL6) & XT2DRIVE_3) != xt2drive){
//Clear XT2drive field
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT2DRIVE_3;
//Set requested value
HWREG16(UCS_BASE + OFS_UCSCTL6) |= xt2drive;
}
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT2BYPASS;
#endif
//Enable XT2 and Switch on XT2 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT2OFF;
while (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG){
//Clear OSC flaut Flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT2OFFG);
#if CC430_DEVICE
// CC430 uses a different fault mechanism. It requires 3 VLO clock
// cycles delay.If 20MHz CPU, 5000 clock cycles are required in worst
// case.
__delay_cycles(5000);
#endif
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
}
void UCS_bypassXT2 (void)
{
//Switch on XT2 oscillator
#if NOT_CC430_DEVICE
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XT2BYPASS;
#endif
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XT2OFF;
while (HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG){
//Clear OSC flaut Flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT2OFFG);
#if CC430_DEVICE
// CC430 uses a different fault mechanism. It requires 3 VLO clock
// cycles delay.If 20MHz CPU, 5000 clock cycles are required in worst
// case.
__delay_cycles(5000);
#endif
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
}
bool UCS_turnOnXT2WithTimeout (uint16_t xt2drive,
uint16_t timeout
)
{
assert(timeout > 0);
#if NOT_CC430_DEVICE
//Check if drive value is the expected one
if ((HWREG16(UCS_BASE + OFS_UCSCTL6) & XT2DRIVE_3) != xt2drive){
//Clear XT2drive field
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT2DRIVE_3;
//Set requested value
HWREG16(UCS_BASE + OFS_UCSCTL6) |= xt2drive;
}
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT2BYPASS;
#endif
//Switch on XT2 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~XT2OFF;
do{
//Clear OSC flaut Flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT2OFFG);
#if CC430_DEVICE
// CC430 uses a different fault mechanism. It requires 3 VLO clock
// cycles delay.If 20MHz CPU, 5000 clock cycles are required in worst
// case.
__delay_cycles(5000);
#endif
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}while ((HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG) && --timeout);
if (timeout){
return (STATUS_SUCCESS);
} else {
return (STATUS_FAIL);
}
}
bool UCS_bypassXT2WithTimeout (uint16_t timeout
)
{
assert(timeout > 0);
//Switch off XT2 oscillator and enable BYPASS mode
#if NOT_CC430_DEVICE
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XT2BYPASS;
#endif
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XT2OFF;
do{
//Clear OSC flaut Flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(XT2OFFG);
#if CC430_DEVICE
// CC430 uses a different fault mechanism. It requires 3 VLO clock
// cycles delay.If 20MHz CPU, 5000 clock cycles are required in worst
// case.
__delay_cycles(5000);
#endif
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}while ((HWREG8(UCS_BASE + OFS_UCSCTL7) & XT2OFFG) && --timeout);
if (timeout){
return (STATUS_SUCCESS);
} else {
return (STATUS_FAIL);
}
}
void UCS_turnOffXT2 (void)
{
//Switch off XT2 oscillator
HWREG16(UCS_BASE + OFS_UCSCTL6) |= XT2OFF;
}
void UCS_initFLLSettle (uint16_t fsystem,
uint16_t ratio
)
{
volatile uint16_t x = ratio * 32;
UCS_initFLL(fsystem, ratio);
while (x--)
{
__delay_cycles(30);
}
}
void UCS_initFLL (uint16_t fsystem,
uint16_t ratio
)
{
uint16_t d, dco_div_bits;
uint16_t mode = 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.
uint16_t srRegisterState = __get_SR_register() & SCG0;
d = ratio;
//Have at least a divider of 2
dco_div_bits = FLLD__2;
if (fsystem > 16000){
d >>= 1 ;
mode = 1;
} else {
//fsystem = fsystem * 2
fsystem <<= 1;
}
while (d > 512)
{
//Set next higher div level
dco_div_bits = dco_div_bits + FLLD0;
d >>= 1;
}
// Disable FLL
__bis_SR_register(SCG0);
//Set DCO to lowest Tap
HWREG8(UCS_BASE + OFS_UCSCTL0_H) = 0x0000;
//Reset FN bits
HWREG16(UCS_BASE + OFS_UCSCTL2) &= ~(0x03FF);
HWREG16(UCS_BASE + OFS_UCSCTL2) = dco_div_bits | (d - 1);
if (fsystem <= 630){ //fsystem < 0.63MHz
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_0;
} else if (fsystem < 1250){ //0.63MHz < fsystem < 1.25MHz
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_1;
} else if (fsystem < 2500){ //1.25MHz < fsystem < 2.5MHz
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_2;
} else if (fsystem < 5000){ //2.5MHz < fsystem < 5MHz
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_3;
} else if (fsystem < 10000){ //5MHz < fsystem < 10MHz
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_4;
} else if (fsystem < 20000){ //10MHz < fsystem < 20MHz
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_5;
} else if (fsystem < 40000){ //20MHz < fsystem < 40MHz
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_6;
} else {
HWREG8(UCS_BASE + OFS_UCSCTL1) = DCORSEL_7;
}
// Re-enable FLL
__bic_SR_register(SCG0);
while (HWREG8(UCS_BASE + OFS_UCSCTL7_L) & DCOFFG)
{
//Clear OSC flaut Flags
HWREG8(UCS_BASE + OFS_UCSCTL7_L) &= ~(DCOFFG);
//Clear OFIFG fault flag
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
}
// Restore previous SCG0
__bis_SR_register(srRegisterState);
if (mode == 1){
//fsystem > 16000
//Select DCOCLK
HWREG16(UCS_BASE + OFS_UCSCTL4) &= ~(SELM_7 + SELS_7);
HWREG16(UCS_BASE + OFS_UCSCTL4) |= SELM__DCOCLK + SELS__DCOCLK;
} else {
//Select DCODIVCLK
HWREG16(UCS_BASE + OFS_UCSCTL4) &= ~(SELM_7 + SELS_7);
HWREG16(UCS_BASE + OFS_UCSCTL4) |= SELM__DCOCLKDIV + SELS__DCOCLKDIV;
}
}
void UCS_enableClockRequest (uint8_t selectClock
)
{
HWREG8(UCS_BASE + OFS_UCSCTL8) |= selectClock;
}
void UCS_disableClockRequest (uint8_t selectClock
)
{
HWREG8(UCS_BASE + OFS_UCSCTL8) &= ~selectClock;
}
uint8_t UCS_getFaultFlagStatus (uint8_t mask
)
{
assert(mask <= UCS_XT2OFFG );
return (HWREG8(UCS_BASE + OFS_UCSCTL7) & mask);
}
void UCS_clearFaultFlag (uint8_t mask
)
{
assert(mask <= UCS_XT2OFFG );
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~mask;
}
void UCS_turnOffSMCLK (void)
{
HWREG16(UCS_BASE + OFS_UCSCTL6) |= SMCLKOFF;
}
void UCS_turnOnSMCLK (void)
{
HWREG16(UCS_BASE + OFS_UCSCTL6) &= ~SMCLKOFF;
}
uint32_t UCS_getACLK (void)
{
//Find ACLK source
uint16_t ACLKSource = (HWREG16(UCS_BASE + OFS_UCSCTL4) & SELA_7);
ACLKSource = ACLKSource >> 8;
uint16_t ACLKSourceDivider = HWREG16(UCS_BASE + OFS_UCSCTL5) & DIVA_7;
ACLKSourceDivider = ACLKSourceDivider >> 8;
return (privateUCSComputeCLKFrequency(
ACLKSource,
ACLKSourceDivider
));
}
uint32_t UCS_getSMCLK (void)
{
uint16_t SMCLKSource = HWREG8(UCS_BASE + OFS_UCSCTL4_L) & SELS_7;
SMCLKSource = SMCLKSource >> 4;
uint16_t SMCLKSourceDivider =
HWREG16(UCS_BASE + OFS_UCSCTL5) & DIVS_7;
SMCLKSourceDivider = SMCLKSourceDivider >> 4;
return (privateUCSComputeCLKFrequency(
SMCLKSource,
SMCLKSourceDivider )
);
}
uint32_t UCS_getMCLK (void)
{
//Find AMCLK source
uint16_t MCLKSource = (HWREG16(UCS_BASE + OFS_UCSCTL4) & SELM_7);
uint16_t MCLKSourceDivider = HWREG16(UCS_BASE + OFS_UCSCTL5) & DIVM_7;
return (privateUCSComputeCLKFrequency(
MCLKSource,
MCLKSourceDivider )
);
}
uint16_t UCS_clearAllOscFlagsWithTimeout(uint16_t timeout
)
{
assert(timeout > 0);
do {
// Clear all osc fault flags
HWREG8(UCS_BASE + OFS_UCSCTL7) &= ~(DCOFFG +
XT1LFOFFG +
XT1HFOFFG +
XT2OFFG
);
#if CC430_DEVICE
// CC430 uses a different fault mechanism. It requires 3 VLO clock
// cycles delay.If 20MHz CPU, 5000 clock cycles are required in worst
// case.
__delay_cycles(5000);
#endif
// Clear the global osc fault flag.
HWREG8(SFR_BASE + OFS_SFRIFG1) &= ~OFIFG;
// Check XT1 fault flags
} while ((HWREG8(SFR_BASE + OFS_SFRIFG1) & OFIFG) && --timeout);
return (HWREG8(UCS_BASE + OFS_UCSCTL7) & (DCOFFG +
XT1LFOFFG +
XT1HFOFFG +
XT2OFFG)
);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for ucs_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,724 @@
//*****************************************************************************
//
// ucs.h - Driver for the UCS Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_UCS_H__
#define __MSP430WARE_UCS_H__
#include "inc/hw_memmap.h"
#if defined(__MSP430_HAS_UCS__) || defined(__MSP430_HAS_UCS_RF__)
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// Internal very low power VLOCLK, low frequency oscillator with 10 kHz typical
// frequency
//
//*****************************************************************************
#define UCS_VLOCLK_FREQUENCY 10000
//*****************************************************************************
//
// Internal, trimmed, low-frequency oscillator with 32768 Hz typical frequency
//
//*****************************************************************************
#define UCS_REFOCLK_FREQUENCY 32768
//*****************************************************************************
//
// The following are values that can be passed to the clockSourceDivider
// parameter for functions: UCS_initClockSignal().
//
//*****************************************************************************
#define UCS_CLOCK_DIVIDER_1 DIVM__1
#define UCS_CLOCK_DIVIDER_2 DIVM__2
#define UCS_CLOCK_DIVIDER_4 DIVM__4
#define UCS_CLOCK_DIVIDER_8 DIVM__8
#define UCS_CLOCK_DIVIDER_12 DIVM__32
#define UCS_CLOCK_DIVIDER_16 DIVM__16
#define UCS_CLOCK_DIVIDER_32 DIVM__32
//*****************************************************************************
//
// The following are values that can be passed to the selectedClockSignal
// parameter for functions: UCS_initClockSignal().
//
//*****************************************************************************
#define UCS_ACLK 0x01
#define UCS_MCLK 0x02
#define UCS_SMCLK 0x04
#define UCS_FLLREF 0x08
//*****************************************************************************
//
// The following are values that can be passed to the clockSource parameter for
// functions: UCS_initClockSignal().
//
//*****************************************************************************
#define UCS_XT1CLK_SELECT SELM__XT1CLK
#define UCS_VLOCLK_SELECT SELM__VLOCLK
#define UCS_REFOCLK_SELECT SELM__REFOCLK
#define UCS_DCOCLK_SELECT SELM__DCOCLK
#define UCS_DCOCLKDIV_SELECT SELM__DCOCLKDIV
#define UCS_XT2CLK_SELECT SELM__XT2CLK
//*****************************************************************************
//
// The following are values that can be passed to the xcap parameter for
// functions: UCS_turnOnLFXT1(), and UCS_turnOnLFXT1WithTimeout().
//
//*****************************************************************************
#define UCS_XCAP_0 XCAP_0
#define UCS_XCAP_1 XCAP_1
#define UCS_XCAP_2 XCAP_2
#define UCS_XCAP_3 XCAP_3
//*****************************************************************************
//
// The following are values that can be passed to the xt1drive parameter for
// functions: UCS_turnOnLFXT1(), UCS_turnOnHFXT1(),
// UCS_turnOnLFXT1WithTimeout(), and UCS_turnOnHFXT1WithTimeout().
//
//*****************************************************************************
#define UCS_XT1_DRIVE_0 XT1DRIVE_0
#define UCS_XT1_DRIVE_1 XT1DRIVE_1
#define UCS_XT1_DRIVE_2 XT1DRIVE_2
#define UCS_XT1_DRIVE_3 XT1DRIVE_3
//*****************************************************************************
//
// The following are values that can be passed to the highOrLowFrequency
// parameter for functions: UCS_bypassXT1(), and UCS_bypassXT1WithTimeout().
//
//*****************************************************************************
#define UCS_XT1_HIGH_FREQUENCY XTS
#define UCS_XT1_LOW_FREQUENCY 0x00
//*****************************************************************************
//
// The following are values that can be passed to the xt2drive parameter for
// functions: UCS_turnOnXT2(), and UCS_turnOnXT2WithTimeout().
//
//*****************************************************************************
#define UCS_XT2_DRIVE_4MHZ_8MHZ XT2DRIVE_0
#define UCS_XT2_DRIVE_8MHZ_16MHZ XT2DRIVE_1
#define UCS_XT2_DRIVE_16MHZ_24MHZ XT2DRIVE_2
#define UCS_XT2_DRIVE_24MHZ_32MHZ XT2DRIVE_3
//*****************************************************************************
//
// The following are values that can be passed to the selectClock parameter for
// functions: UCS_enableClockRequest(), and UCS_disableClockRequest().
//
//*****************************************************************************
#define UCS_ACLK 0x01
#define UCS_SMCLK 0x04
#define UCS_MCLK 0x02
#define UCS_MODOSC MODOSCREQEN
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: UCS_getFaultFlagStatus(), and UCS_clearFaultFlag() as well as
// returned by the UCS_clearAllOscFlagsWithTimeout() function.
//
//*****************************************************************************
#define UCS_XT2OFFG XT2OFFG
#define UCS_XT1HFOFFG XT1HFOFFG
#define UCS_XT1LFOFFG XT1LFOFFG
#define UCS_DCOFFG DCOFFG
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Sets the external clock source
//!
//! This function sets the external clock sources XT1 and XT2 crystal
//! oscillator frequency values. This function must be called if an external
//! crystal XT1 or XT2 is used and the user intends to call UCS_getMCLK,
//! UCS_getSMCLK or UCS_getACLK APIs. If not, it is not necessary to invoke
//! this API.
//!
//! \param XT1CLK_frequency is the XT1 crystal frequencies in Hz
//! \param XT2CLK_frequency is the XT2 crystal frequencies in Hz
//!
//! \return None
//
//*****************************************************************************
extern void UCS_setExternalClockSource(uint32_t XT1CLK_frequency,
uint32_t XT2CLK_frequency);
//*****************************************************************************
//
//! \brief Initializes a clock signal
//!
//! This function initializes each of the clock signals. The user must ensure
//! that this function is called for each clock signal. If not, the default
//! state is assumed for the particular clock signal. Refer MSP430Ware
//! documentation for UCS module or Device Family User's Guide for details of
//! default clock signal states.
//!
//! \param selectedClockSignal selected clock signal
//! Valid values are:
//! - \b UCS_ACLK
//! - \b UCS_MCLK
//! - \b UCS_SMCLK
//! - \b UCS_FLLREF
//! \param clockSource is clock source for the selectedClockSignal
//! Valid values are:
//! - \b UCS_XT1CLK_SELECT
//! - \b UCS_VLOCLK_SELECT
//! - \b UCS_REFOCLK_SELECT
//! - \b UCS_DCOCLK_SELECT
//! - \b UCS_DCOCLKDIV_SELECT
//! - \b UCS_XT2CLK_SELECT
//! \param clockSourceDivider selected the clock divider to calculate
//! clocksignal from clock source.
//! Valid values are:
//! - \b UCS_CLOCK_DIVIDER_1 [Default]
//! - \b UCS_CLOCK_DIVIDER_2
//! - \b UCS_CLOCK_DIVIDER_4
//! - \b UCS_CLOCK_DIVIDER_8
//! - \b UCS_CLOCK_DIVIDER_12 - [Valid only for UCS_FLLREF]
//! - \b UCS_CLOCK_DIVIDER_16
//! - \b UCS_CLOCK_DIVIDER_32 - [Not valid for UCS_FLLREF]
//!
//! Modified bits of \b UCSCTL5 register, bits of \b UCSCTL4 register and bits
//! of \b UCSCTL3 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_initClockSignal(uint8_t selectedClockSignal,
uint16_t clockSource,
uint16_t clockSourceDivider);
//*****************************************************************************
//
//! \brief Initializes the XT1 crystal oscillator in low frequency mode
//!
//! Initializes the XT1 crystal oscillator in low frequency mode. Loops until
//! all oscillator fault flags are cleared, with no timeout. See the device-
//! specific data sheet for appropriate drive settings.
//!
//! \param xt1drive is the target drive strength for the XT1 crystal
//! oscillator.
//! Valid values are:
//! - \b UCS_XT1_DRIVE_0
//! - \b UCS_XT1_DRIVE_1
//! - \b UCS_XT1_DRIVE_2
//! - \b UCS_XT1_DRIVE_3 [Default]
//! \n Modified bits are \b XT1DRIVE of \b UCSCTL6 register.
//! \param xcap is the selected capacitor value. This parameter selects the
//! capacitors applied to the LF crystal (XT1) or resonator in the LF
//! mode. The effective capacitance (seen by the crystal) is Ceff. (CXIN
//! + 2 pF)/2. It is assumed that CXIN = CXOUT and that a parasitic
//! capacitance of 2 pF is added by the package and the printed circuit
//! board. For details about the typical internal and the effective
//! capacitors, refer to the device-specific data sheet.
//! Valid values are:
//! - \b UCS_XCAP_0
//! - \b UCS_XCAP_1
//! - \b UCS_XCAP_2
//! - \b UCS_XCAP_3 [Default]
//!
//! Modified bits are \b XCAP of \b UCSCTL6 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_turnOnLFXT1(uint16_t xt1drive,
uint8_t xcap);
//*****************************************************************************
//
//! \brief Initializes the XT1 crystal oscillator in high frequency mode
//!
//! Initializes the XT1 crystal oscillator in high frequency mode. Loops until
//! all oscillator fault flags are cleared, with no timeout. See the device-
//! specific data sheet for appropriate drive settings.
//!
//! \param xt1drive is the target drive strength for the XT1 crystal
//! oscillator.
//! Valid values are:
//! - \b UCS_XT1_DRIVE_0
//! - \b UCS_XT1_DRIVE_1
//! - \b UCS_XT1_DRIVE_2
//! - \b UCS_XT1_DRIVE_3 [Default]
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_turnOnHFXT1(uint16_t xt1drive);
//*****************************************************************************
//
//! \brief Bypass the XT1 crystal oscillator
//!
//! Bypasses the XT1 crystal oscillator. Loops until all oscillator fault flags
//! are cleared, with no timeout.
//!
//! \param highOrLowFrequency selects high frequency or low frequency mode for
//! XT1.
//! Valid values are:
//! - \b UCS_XT1_HIGH_FREQUENCY
//! - \b UCS_XT1_LOW_FREQUENCY [Default]
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_bypassXT1(uint8_t highOrLowFrequency);
//*****************************************************************************
//
//! \brief Initializes the XT1 crystal oscillator in low frequency mode with
//! timeout
//!
//! Initializes the XT1 crystal oscillator in low frequency mode with timeout.
//! Loops until all oscillator fault flags are cleared or until a timeout
//! counter is decremented and equals to zero. See the device-specific
//! datasheet for appropriate drive settings.
//!
//! \param xt1drive is the target drive strength for the XT1 crystal
//! oscillator.
//! Valid values are:
//! - \b UCS_XT1_DRIVE_0
//! - \b UCS_XT1_DRIVE_1
//! - \b UCS_XT1_DRIVE_2
//! - \b UCS_XT1_DRIVE_3 [Default]
//! \param xcap is the selected capacitor value. This parameter selects the
//! capacitors applied to the LF crystal (XT1) or resonator in the LF
//! mode. The effective capacitance (seen by the crystal) is Ceff. (CXIN
//! + 2 pF)/2. It is assumed that CXIN = CXOUT and that a parasitic
//! capacitance of 2 pF is added by the package and the printed circuit
//! board. For details about the typical internal and the effective
//! capacitors, refer to the device-specific data sheet.
//! Valid values are:
//! - \b UCS_XCAP_0
//! - \b UCS_XCAP_1
//! - \b UCS_XCAP_2
//! - \b UCS_XCAP_3 [Default]
//! \param timeout is the count value that gets decremented every time the loop
//! that clears oscillator fault flags gets executed.
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern bool UCS_turnOnLFXT1WithTimeout(uint16_t xt1drive,
uint8_t xcap,
uint16_t timeout);
//*****************************************************************************
//
//! \brief Initializes the XT1 crystal oscillator in high frequency mode with
//! timeout
//!
//! Initializes the XT1 crystal oscillator in high frequency mode with timeout.
//! Loops until all oscillator fault flags are cleared or until a timeout
//! counter is decremented and equals to zero. See the device-specific data
//! sheet for appropriate drive settings.
//!
//! \param xt1drive is the target drive strength for the XT1 crystal
//! oscillator.
//! Valid values are:
//! - \b UCS_XT1_DRIVE_0
//! - \b UCS_XT1_DRIVE_1
//! - \b UCS_XT1_DRIVE_2
//! - \b UCS_XT1_DRIVE_3 [Default]
//! \param timeout is the count value that gets decremented every time the loop
//! that clears oscillator fault flags gets executed.
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern bool UCS_turnOnHFXT1WithTimeout(uint16_t xt1drive,
uint16_t timeout);
//*****************************************************************************
//
//! \brief Bypasses the XT1 crystal oscillator with time out
//!
//! Bypasses the XT1 crystal oscillator with time out. Loops until all
//! oscillator fault flags are cleared or until a timeout counter is
//! decremented and equals to zero.
//!
//! \param highOrLowFrequency selects high frequency or low frequency mode for
//! XT1.
//! Valid values are:
//! - \b UCS_XT1_HIGH_FREQUENCY
//! - \b UCS_XT1_LOW_FREQUENCY [Default]
//! \param timeout is the count value that gets decremented every time the loop
//! that clears oscillator fault flags gets executed.
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern bool UCS_bypassXT1WithTimeout(uint8_t highOrLowFrequency,
uint16_t timeout);
//*****************************************************************************
//
//! \brief Stops the XT1 oscillator using the XT1OFF bit.
//!
//!
//! \return None
//
//*****************************************************************************
extern void UCS_turnOffXT1(void);
//*****************************************************************************
//
//! \brief Initializes the XT2 crystal oscillator
//!
//! Initializes the XT2 crystal oscillator, which supports crystal frequencies
//! between 4 MHz and 32 MHz, depending on the selected drive strength. Loops
//! until all oscillator fault flags are cleared, with no timeout. See the
//! device-specific data sheet for appropriate drive settings.
//!
//! \param xt2drive is the target drive strength for the XT2 crystal
//! oscillator.
//! Valid values are:
//! - \b UCS_XT2_DRIVE_4MHZ_8MHZ
//! - \b UCS_XT2_DRIVE_8MHZ_16MHZ
//! - \b UCS_XT2_DRIVE_16MHZ_24MHZ
//! - \b UCS_XT2_DRIVE_24MHZ_32MHZ [Default]
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_turnOnXT2(uint16_t xt2drive);
//*****************************************************************************
//
//! \brief Bypasses the XT2 crystal oscillator
//!
//! Bypasses the XT2 crystal oscillator, which supports crystal frequencies
//! between 4 MHz and 32 MHz. Loops until all oscillator fault flags are
//! cleared, with no timeout.
//!
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_bypassXT2(void);
//*****************************************************************************
//
//! \brief Initializes the XT2 crystal oscillator with timeout
//!
//! Initializes the XT2 crystal oscillator, which supports crystal frequencies
//! between 4 MHz and 32 MHz, depending on the selected drive strength. Loops
//! until all oscillator fault flags are cleared or until a timeout counter is
//! decremented and equals to zero. See the device-specific data sheet for
//! appropriate drive settings.
//!
//! \param xt2drive is the target drive strength for the XT2 crystal
//! oscillator.
//! Valid values are:
//! - \b UCS_XT2_DRIVE_4MHZ_8MHZ
//! - \b UCS_XT2_DRIVE_8MHZ_16MHZ
//! - \b UCS_XT2_DRIVE_16MHZ_24MHZ
//! - \b UCS_XT2_DRIVE_24MHZ_32MHZ [Default]
//! \param timeout is the count value that gets decremented every time the loop
//! that clears oscillator fault flags gets executed.
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern bool UCS_turnOnXT2WithTimeout(uint16_t xt2drive,
uint16_t timeout);
//*****************************************************************************
//
//! \brief Bypasses the XT2 crystal oscillator with timeout
//!
//! Bypasses the XT2 crystal oscillator, which supports crystal frequencies
//! between 4 MHz and 32 MHz. Loops until all oscillator fault flags are
//! cleared or until a timeout counter is decremented and equals to zero.
//!
//! \param timeout is the count value that gets decremented every time the loop
//! that clears oscillator fault flags gets executed.
//!
//! Modified bits of \b UCSCTL7 register, bits of \b UCSCTL6 register and bits
//! of \b SFRIFG register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL
//
//*****************************************************************************
extern bool UCS_bypassXT2WithTimeout(uint16_t timeout);
//*****************************************************************************
//
//! \brief Stops the XT2 oscillator using the XT2OFF bit.
//!
//!
//! Modified bits of \b UCSCTL6 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_turnOffXT2(void);
//*****************************************************************************
//
//! \brief Initializes the DCO to operate a frequency that is a multiple of the
//! reference frequency into the FLL
//!
//! Initializes the DCO to operate a frequency that is a multiple of the
//! reference frequency into the FLL. Loops until all oscillator fault flags
//! are cleared, with a timeout. If the frequency is greater than 16 MHz, the
//! function sets the MCLK and SMCLK source to the undivided DCO frequency.
//! Otherwise, the function sets the MCLK and SMCLK source to the DCOCLKDIV
//! frequency. This function executes a software delay that is proportional in
//! length to the ratio of the target FLL frequency and the FLL reference. The
//! function PMM_setVCore() is required to call first if the target frequency
//! is beyond current Vcore supported frequency range.
//!
//! \param fsystem is the target frequency for MCLK in kHz
//! \param ratio is the ratio x/y, where x = fsystem and y = FLL reference
//! frequency.
//!
//! Modified bits of \b UCSCTL0 register, bits of \b UCSCTL4 register, bits of
//! \b UCSCTL7 register, bits of \b UCSCTL1 register, bits of \b SFRIFG1
//! register and bits of \b UCSCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_initFLLSettle(uint16_t fsystem,
uint16_t ratio);
//*****************************************************************************
//
//! \brief Initializes the DCO to operate a frequency that is a multiple of the
//! reference frequency into the FLL
//!
//! Initializes the DCO to operate a frequency that is a multiple of the
//! reference frequency into the FLL. Loops until all oscillator fault flags
//! are cleared, with no timeout. If the frequency is greater than 16 MHz, the
//! function sets the MCLK and SMCLK source to the undivided DCO frequency.
//! Otherwise, the function sets the MCLK and SMCLK source to the DCOCLKDIV
//! frequency. The function PMM_setVCore() is required to call first if the
//! target frequency is beyond current Vcore supported frequency range.
//!
//! \param fsystem is the target frequency for MCLK in kHz
//! \param ratio is the ratio x/y, where x = fsystem and y = FLL reference
//! frequency.
//!
//! Modified bits of \b UCSCTL0 register, bits of \b UCSCTL4 register, bits of
//! \b UCSCTL7 register, bits of \b UCSCTL1 register, bits of \b SFRIFG1
//! register and bits of \b UCSCTL2 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_initFLL(uint16_t fsystem,
uint16_t ratio);
//*****************************************************************************
//
//! \brief Enables conditional module requests
//!
//! \param selectClock selects specific request enables
//! Valid values are:
//! - \b UCS_ACLK
//! - \b UCS_SMCLK
//! - \b UCS_MCLK
//! - \b UCS_MODOSC
//!
//! Modified bits of \b UCSCTL8 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_enableClockRequest(uint8_t selectClock);
//*****************************************************************************
//
//! \brief Disables conditional module requests
//!
//! \param selectClock selects specific request disable
//! Valid values are:
//! - \b UCS_ACLK
//! - \b UCS_SMCLK
//! - \b UCS_MCLK
//! - \b UCS_MODOSC
//!
//! Modified bits of \b UCSCTL8 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_disableClockRequest(uint8_t selectClock);
//*****************************************************************************
//
//! \brief Gets the current UCS fault flag status.
//!
//! \param mask is the masked interrupt flag status to be returned. Mask
//! parameter can be either any of the following selection.
//! Valid values are:
//! - \b UCS_XT2OFFG - XT2 oscillator fault flag
//! - \b UCS_XT1HFOFFG - XT1 oscillator fault flag (HF mode)
//! - \b UCS_XT1LFOFFG - XT1 oscillator fault flag (LF mode)
//! - \b UCS_DCOFFG - DCO fault flag
//!
//
//*****************************************************************************
extern uint8_t UCS_getFaultFlagStatus(uint8_t mask);
//*****************************************************************************
//
//! \brief Clears the current UCS fault flag status for the masked bit.
//!
//! \param mask is the masked interrupt flag status to be returned. mask
//! parameter can be any one of the following
//! Valid values are:
//! - \b UCS_XT2OFFG - XT2 oscillator fault flag
//! - \b UCS_XT1HFOFFG - XT1 oscillator fault flag (HF mode)
//! - \b UCS_XT1LFOFFG - XT1 oscillator fault flag (LF mode)
//! - \b UCS_DCOFFG - DCO fault flag
//!
//! Modified bits of \b UCSCTL7 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_clearFaultFlag(uint8_t mask);
//*****************************************************************************
//
//! \brief Turns off SMCLK using the SMCLKOFF bit
//!
//!
//! Modified bits of \b UCSCTL6 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_turnOffSMCLK(void);
//*****************************************************************************
//
//! \brief Turns ON SMCLK using the SMCLKOFF bit
//!
//!
//! Modified bits of \b UCSCTL6 register.
//!
//! \return None
//
//*****************************************************************************
extern void UCS_turnOnSMCLK(void);
//*****************************************************************************
//
//! \brief Get the current ACLK frequency
//!
//! Get the current ACLK frequency. The user of this API must ensure that
//! UCS_setExternalClockSource API was invoked before in case XT1 or XT2 is
//! being used.
//!
//!
//! \return Current ACLK frequency in Hz
//
//*****************************************************************************
extern uint32_t UCS_getACLK(void);
//*****************************************************************************
//
//! \brief Get the current SMCLK frequency
//!
//! Get the current SMCLK frequency. The user of this API must ensure that
//! UCS_setExternalClockSource API was invoked before in case XT1 or XT2 is
//! being used.
//!
//!
//! \return Current SMCLK frequency in Hz
//
//*****************************************************************************
extern uint32_t UCS_getSMCLK(void);
//*****************************************************************************
//
//! \brief Get the current MCLK frequency
//!
//! Get the current MCLK frequency. The user of this API must ensure that
//! UCS_setExternalClockSource API was invoked before in case XT1 or XT2 is
//! being used.
//!
//!
//! \return Current MCLK frequency in Hz
//
//*****************************************************************************
extern uint32_t UCS_getMCLK(void);
//*****************************************************************************
//
//! \brief Clears all the Oscillator Flags
//!
//! \param timeout is the count value that gets decremented every time the loop
//! that clears oscillator fault flags gets executed.
//!
//! \return Logical OR of any of the following:
//! - \b UCS_XT2OFFG XT2 oscillator fault flag
//! - \b UCS_XT1HFOFFG XT1 oscillator fault flag (HF mode)
//! - \b UCS_XT1LFOFFG XT1 oscillator fault flag (LF mode)
//! - \b UCS_DCOFFG DCO fault flag
//! \n indicating the status of the oscillator fault flags
//
//*****************************************************************************
extern uint16_t UCS_clearAllOscFlagsWithTimeout(uint16_t timeout);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_UCS_H__

View File

@@ -0,0 +1,197 @@
//*****************************************************************************
//
// usci_a_spi.c - Driver for the usci_a_spi Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup usci_a_spi_api usci_a_spi
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Ax__
#include "usci_a_spi.h"
#include <assert.h>
bool USCI_A_SPI_initMaster(uint16_t baseAddress, USCI_A_SPI_initMasterParam *param)
{
//Disable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCSWRST;
//Reset OFS_UCAxCTL0 values
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~(UCCKPH + UCCKPL + UC7BIT + UCMSB +
UCMST + UCMODE_3 + UCSYNC);
//Reset OFS_UCAxCTL1 values
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~(UCSSEL_3);
//Select Clock
HWREG8(baseAddress + OFS_UCAxCTL1) |= param->selectClockSource;
HWREG16(baseAddress + OFS_UCAxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
/*
* Configure as SPI master mode.
* Clock phase select, polarity, msb
* UCMST = Master mode
* UCSYNC = Synchronous mode
* UCMODE_0 = 3-pin SPI
*/
HWREG8(baseAddress + OFS_UCAxCTL0) |= (
param->msbFirst +
param->clockPhase +
param->clockPolarity +
UCMST +
UCSYNC +
UCMODE_0
);
//No modulation
HWREG8(baseAddress + OFS_UCAxMCTL) = 0;
return ( STATUS_SUCCESS) ;
}
void USCI_A_SPI_changeMasterClock(uint16_t baseAddress,
USCI_A_SPI_changeMasterClockParam *param)
{
//Disable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCSWRST;
HWREG8(baseAddress + OFS_UCAxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~(UCSWRST);
}
bool USCI_A_SPI_initSlave (uint16_t baseAddress,
uint8_t msbFirst,
uint8_t clockPhase,
uint8_t clockPolarity
)
{
//Disable USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCSWRST;
//Reset OFS_UCAxCTL0 register
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~(UCMSB +
UC7BIT +
UCMST +
UCCKPL +
UCCKPH +
UCMODE_3
);
//Clock polarity, phase select, msbFirst, SYNC, Mode0
HWREG8(baseAddress + OFS_UCAxCTL0) |= (clockPhase +
clockPolarity +
msbFirst +
UCSYNC +
UCMODE_0
);
return ( STATUS_SUCCESS) ;
}
void USCI_A_SPI_changeClockPhasePolarity (uint16_t baseAddress,
uint8_t clockPhase,
uint8_t clockPolarity
)
{
//Disable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCSWRST;
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~(UCCKPH + UCCKPL);
HWREG8(baseAddress + OFS_UCAxCTL0) |= (
clockPhase +
clockPolarity
);
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~(UCSWRST);
}
void USCI_A_SPI_transmitData ( uint16_t baseAddress,
uint8_t transmitData
)
{
HWREG8(baseAddress + OFS_UCAxTXBUF) = transmitData;
}
uint8_t USCI_A_SPI_receiveData (uint16_t baseAddress)
{
return ( HWREG8(baseAddress + OFS_UCAxRXBUF)) ;
}
void USCI_A_SPI_enableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_UCAxIE) |= mask;
}
void USCI_A_SPI_disableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_UCAxIE) &= ~mask;
}
uint8_t USCI_A_SPI_getInterruptStatus (uint16_t baseAddress,
uint8_t mask
)
{
return ( HWREG8(baseAddress + OFS_UCAxIFG) & mask );
}
void USCI_A_SPI_clearInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_UCAxIFG) &= ~mask;
}
void USCI_A_SPI_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~(UCSWRST);
}
void USCI_A_SPI_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCSWRST;
}
uint32_t USCI_A_SPI_getReceiveBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxRXBUF );
}
uint32_t USCI_A_SPI_getTransmitBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxTXBUF );
}
uint8_t USCI_A_SPI_isBusy (uint16_t baseAddress)
{
//Return the bus busy status.
return (HWREG8(baseAddress + OFS_UCAxSTAT) & UCBUSY);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for usci_a_spi_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,436 @@
//*****************************************************************************
//
// usci_a_spi.h - Driver for the USCI_A_SPI Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_USCI_A_SPI_H__
#define __MSP430WARE_USCI_A_SPI_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Ax__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the USCI_A_SPI_initMaster() function as the param parameter.
//
//*****************************************************************************
typedef struct USCI_A_SPI_initMasterParam {
//! Selects Clock source.
//! \n Valid values are:
//! - \b USCI_A_SPI_CLOCKSOURCE_ACLK
//! - \b USCI_A_SPI_CLOCKSOURCE_SMCLK
uint8_t selectClockSource;
//! Is the frequency of the selected clock source
uint32_t clockSourceFrequency;
//! Is the desired clock rate for SPI communication
uint32_t desiredSpiClock;
//! Controls the direction of the receive and transmit shift register.
//! \n Valid values are:
//! - \b USCI_A_SPI_MSB_FIRST
//! - \b USCI_A_SPI_LSB_FIRST [Default]
uint8_t msbFirst;
//! Is clock phase select.
//! \n Valid values are:
//! - \b USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
//! - \b USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
uint8_t clockPhase;
//! \n Valid values are:
//! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
uint8_t clockPolarity;
} USCI_A_SPI_initMasterParam;
//*****************************************************************************
//
//! \brief Used in the USCI_A_SPI_changeMasterClock() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct USCI_A_SPI_changeMasterClockParam {
//! Is the frequency of the selected clock source
uint32_t clockSourceFrequency;
//! Is the desired clock rate for SPI communication
uint32_t desiredSpiClock;
} USCI_A_SPI_changeMasterClockParam;
//*****************************************************************************
//
// The following are values that can be passed to the clockPhase parameter for
// functions: USCI_A_SPI_initSlave(), and
// USCI_A_SPI_changeClockPhasePolarity(); the param parameter for functions:
// USCI_A_SPI_initMaster().
//
//*****************************************************************************
#define USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT 0x00
#define USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT UCCKPH
//*****************************************************************************
//
// The following are values that can be passed to the msbFirst parameter for
// functions: USCI_A_SPI_initSlave(); the param parameter for functions:
// USCI_A_SPI_initMaster().
//
//*****************************************************************************
#define USCI_A_SPI_MSB_FIRST UCMSB
#define USCI_A_SPI_LSB_FIRST 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_SPI_initMaster(); the clockPolarity parameter for
// functions: USCI_A_SPI_initSlave(), and
// USCI_A_SPI_changeClockPhasePolarity().
//
//*****************************************************************************
#define USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH UCCKPL
#define USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_SPI_initMaster().
//
//*****************************************************************************
#define USCI_A_SPI_CLOCKSOURCE_ACLK UCSSEL__ACLK
#define USCI_A_SPI_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: USCI_A_SPI_enableInterrupt(), USCI_A_SPI_disableInterrupt(),
// USCI_A_SPI_getInterruptStatus(), and USCI_A_SPI_clearInterrupt() as well as
// returned by the USCI_A_SPI_getInterruptStatus() function.
//
//*****************************************************************************
#define USCI_A_SPI_TRANSMIT_INTERRUPT UCTXIE
#define USCI_A_SPI_RECEIVE_INTERRUPT UCRXIE
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the USCI_A_SPI_isBusy() function.
//
//*****************************************************************************
#define USCI_A_SPI_BUSY UCBUSY
#define USCI_A_SPI_NOT_BUSY 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the SPI Master block.
//!
//! Upon successful initialization of the SPI master block, this function will
//! have set the bus speed for the master, but the SPI Master block still
//! remains disabled and must be enabled with USCI_A_SPI_enable()
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param param is the pointer to struct for master initialization.
//!
//! Modified bits are \b UCCKPH, \b UCCKPL, \b UC7BIT and \b UCMSB of \b
//! UCAxCTL0 register; bits \b UCSSELx and \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern bool USCI_A_SPI_initMaster(uint16_t baseAddress,
USCI_A_SPI_initMasterParam *param);
//*****************************************************************************
//
//! \brief Initializes the SPI Master clock.At the end of this function call,
//! SPI module is left enabled.
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param param is the pointer to struct for master clock setting.
//!
//! Modified bits of \b UCAxBRW register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_changeMasterClock(uint16_t baseAddress,
USCI_A_SPI_changeMasterClockParam *param);
//*****************************************************************************
//
//! \brief Initializes the SPI Slave block.
//!
//! Upon successful initialization of the SPI slave block, this function will
//! have initialized the slave block, but the SPI Slave block still remains
//! disabled and must be enabled with USCI_A_SPI_enable()
//!
//! \param baseAddress is the base address of the SPI Slave module.
//! \param msbFirst controls the direction of the receive and transmit shift
//! register.
//! Valid values are:
//! - \b USCI_A_SPI_MSB_FIRST
//! - \b USCI_A_SPI_LSB_FIRST [Default]
//! \param clockPhase is clock phase select.
//! Valid values are:
//! - \b USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
//! [Default]
//! - \b USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
//! \param clockPolarity
//! Valid values are:
//! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
//!
//! Modified bits are \b UCMSB, \b UCMST, \b UC7BIT, \b UCCKPL, \b UCCKPH and
//! \b UCMODE of \b UCAxCTL0 register; bits \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern bool USCI_A_SPI_initSlave(uint16_t baseAddress,
uint8_t msbFirst,
uint8_t clockPhase,
uint8_t clockPolarity);
//*****************************************************************************
//
//! \brief Changes the SPI clock phase and polarity.At the end of this function
//! call, SPI module is left enabled.
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param clockPhase is clock phase select.
//! Valid values are:
//! - \b USCI_A_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
//! [Default]
//! - \b USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
//! \param clockPolarity
//! Valid values are:
//! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
//!
//! Modified bits are \b UCCKPL and \b UCCKPH of \b UCAxCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_changeClockPhasePolarity(uint16_t baseAddress,
uint8_t clockPhase,
uint8_t clockPolarity);
//*****************************************************************************
//
//! \brief Transmits a byte from the SPI Module.
//!
//! This function will place the supplied data into SPI transmit data register
//! to start transmission
//!
//! \param baseAddress is the base address of the SPI module.
//! \param transmitData data to be transmitted from the SPI module
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_transmitData(uint16_t baseAddress,
uint8_t transmitData);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the SPI Module.
//!
//! This function reads a byte of data from the SPI receive data Register.
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return Returns the byte received from by the SPI module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t USCI_A_SPI_receiveData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables individual SPI interrupt sources.
//!
//! Enables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_A_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_enableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Disables individual SPI interrupt sources.
//!
//! Disables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_A_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_disableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current SPI interrupt status.
//!
//! This returns the interrupt status for the SPI module based on which flag is
//! passed.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_A_SPI_RECEIVE_INTERRUPT
//!
//! \return The current interrupt status as the mask of the set flags
//! Return Logical OR of any of the following:
//! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_A_SPI_RECEIVE_INTERRUPT
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t USCI_A_SPI_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears the selected SPI interrupt status flag.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the masked interrupt flag to be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_A_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCAxIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_clearInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Enables the SPI block.
//!
//! This will enable operation of the SPI block.
//!
//! \param baseAddress is the base address of the USCI SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the SPI block.
//!
//! This will disable operation of the SPI block.
//!
//! \param baseAddress is the base address of the USCI SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_SPI_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the RX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI RX Buffer. This can be used in conjunction
//! with the DMA to store the received data directly to memory.
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return the address of the RX Buffer
//
//*****************************************************************************
extern uint32_t USCI_A_SPI_getReceiveBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the TX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI TX Buffer. This can be used in conjunction
//! with the DMA to obtain transmitted data directly from memory.
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return the address of the TX Buffer
//
//*****************************************************************************
extern uint32_t USCI_A_SPI_getTransmitBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Indicates whether or not the SPI bus is busy.
//!
//! This function returns an indication of whether or not the SPI bus is
//! busy.This function checks the status of the bus via UCBBUSY bit
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return USCI_A_SPI_BUSY if the SPI module transmitting or receiving is
//! busy; otherwise, returns USCI_A_SPI_NOT_BUSY.
//! Return one of the following:
//! - \b USCI_A_SPI_BUSY
//! - \b USCI_A_SPI_NOT_BUSY
//! \n indicating if the USCI_A_SPI is busy
//
//*****************************************************************************
extern uint8_t USCI_A_SPI_isBusy(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_USCI_A_SPI_H__

View File

@@ -0,0 +1,225 @@
//*****************************************************************************
//
// usci_a_uart.c - Driver for the usci_a_uart Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup usci_a_uart_api usci_a_uart
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Ax__
#include "usci_a_uart.h"
#include <assert.h>
bool USCI_A_UART_init(uint16_t baseAddress, USCI_A_UART_initParam *param)
{
bool retVal = STATUS_SUCCESS;
//Disable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCSWRST;
//Clock source select
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~UCSSEL_3;
HWREG8(baseAddress + OFS_UCAxCTL1) |= param->selectClockSource;
//MSB, LSB select
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~UCMSB;
HWREG8(baseAddress + OFS_UCAxCTL0) |= param->msborLsbFirst;
//UCSPB = 0(1 stop bit) OR 1(2 stop bits)
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~UCSPB;
HWREG8(baseAddress + OFS_UCAxCTL0) |= param->numberofStopBits;
//Parity
switch (param->parity){
case USCI_A_UART_NO_PARITY:
//No Parity
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~UCPEN;
break;
case USCI_A_UART_ODD_PARITY:
//Odd Parity
HWREG8(baseAddress + OFS_UCAxCTL0) |= UCPEN;
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~UCPAR;
break;
case USCI_A_UART_EVEN_PARITY:
//Even Parity
HWREG8(baseAddress + OFS_UCAxCTL0) |= UCPEN;
HWREG8(baseAddress + OFS_UCAxCTL0) |= UCPAR;
break;
}
//Modulation Control Registers
HWREG16(baseAddress + OFS_UCAxBRW ) = param->clockPrescalar;
HWREG8(baseAddress + OFS_UCAxMCTL) = ((param->firstModReg<<4) +
(param->secondModReg <<1) +
param->overSampling );
//Asynchronous mode & 8 bit character select & clear mode
HWREG8(baseAddress + OFS_UCAxCTL0) &= ~(UCSYNC +
UC7BIT +
UCMODE_3
);
//Configure UART mode.
HWREG8(baseAddress + OFS_UCAxCTL0) |= param->uartMode ;
//Reset UCRXIE, UCBRKIE, UCDORM, UCTXADDR, UCTXBRK
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~(UCRXEIE + UCBRKIE + UCDORM +
UCTXADDR + UCTXBRK
);
return (retVal) ;
}
void USCI_A_UART_transmitData ( uint16_t baseAddress,
uint8_t transmitData
)
{
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCAxIE) & UCTXIE)){
//Poll for transmit interrupt flag
while (!(HWREG8(baseAddress + OFS_UCAxIFG) & UCTXIFG));
}
HWREG8(baseAddress + OFS_UCAxTXBUF) = transmitData;
}
uint8_t USCI_A_UART_receiveData (uint16_t baseAddress)
{
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCAxIE) & UCRXIE)){
//Poll for receive interrupt flag
while (!(HWREG8(baseAddress + OFS_UCAxIFG) & UCRXIFG));
}
return ( HWREG8(baseAddress + OFS_UCAxRXBUF)) ;
}
void USCI_A_UART_enableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
uint8_t locMask;
locMask = (mask & (USCI_A_UART_RECEIVE_INTERRUPT
| USCI_A_UART_TRANSMIT_INTERRUPT));
HWREG8(baseAddress + OFS_UCAxIE) |= locMask;
locMask = (mask & (USCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT
| USCI_A_UART_BREAKCHAR_INTERRUPT));
HWREG8(baseAddress + OFS_UCAxCTL1) |= locMask;
}
void USCI_A_UART_disableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
uint8_t locMask;
if(locMask = (mask & (USCI_A_UART_RECEIVE_INTERRUPT
| USCI_A_UART_TRANSMIT_INTERRUPT))) {
HWREG8(baseAddress + OFS_UCAxIE) &= ~locMask;
}
if(locMask = (mask & (USCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT
| USCI_A_UART_BREAKCHAR_INTERRUPT))) {
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~locMask;
}
}
uint8_t USCI_A_UART_getInterruptStatus (uint16_t baseAddress,
uint8_t mask)
{
return ( HWREG8(baseAddress + OFS_UCAxIFG) & mask );
}
void USCI_A_UART_clearInterrupt (uint16_t baseAddress, uint8_t mask)
{
//Clear the UART interrupt source.
HWREG8(baseAddress + OFS_UCAxIFG) &= ~(mask);
}
void USCI_A_UART_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~(UCSWRST);
}
void USCI_A_UART_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCSWRST;
}
uint8_t USCI_A_UART_queryStatusFlags (uint16_t baseAddress,
uint8_t mask)
{
return ( HWREG8(baseAddress + OFS_UCAxSTAT) & mask );
}
void USCI_A_UART_setDormant (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCDORM;
}
void USCI_A_UART_resetDormant (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_UCAxCTL1) &= ~UCDORM;
}
void USCI_A_UART_transmitAddress (uint16_t baseAddress,
uint8_t transmitAddress)
{
//Set UCTXADDR bit
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCTXADDR;
//Place next byte to be sent into the transmit buffer
HWREG8(baseAddress + OFS_UCAxTXBUF) = transmitAddress;
}
void USCI_A_UART_transmitBreak (uint16_t baseAddress)
{
//Set UCTXADDR bit
HWREG8(baseAddress + OFS_UCAxCTL1) |= UCTXBRK;
//If current mode is automatic baud-rate detection
if (USCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE ==
(HWREG8(baseAddress + OFS_UCAxCTL0) &
USCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE)){
HWREG8(baseAddress + OFS_UCAxTXBUF) = USCI_A_UART_AUTOMATICBAUDRATE_SYNC;
} else {
HWREG8(baseAddress + OFS_UCAxTXBUF) = DEFAULT_SYNC;
}
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCAxIE) & UCTXIE)){
//Poll for transmit interrupt flag
while (!(HWREG8(baseAddress + OFS_UCAxIFG) & UCTXIFG));
}
}
uint32_t USCI_A_UART_getReceiveBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxRXBUF );
}
uint32_t USCI_A_UART_getTransmitBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCAxTXBUF );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for usci_a_uart_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,523 @@
//*****************************************************************************
//
// usci_a_uart.h - Driver for the USCI_A_UART Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_USCI_A_UART_H__
#define __MSP430WARE_USCI_A_UART_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Ax__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
// The following values are the sync characters possible
//
//*****************************************************************************
#define DEFAULT_SYNC 0x00
#define USCI_A_UART_AUTOMATICBAUDRATE_SYNC 0x55
//*****************************************************************************
//
//! \brief Used in the USCI_A_UART_init() function as the param parameter.
//
//*****************************************************************************
typedef struct USCI_A_UART_initParam {
//! Selects Clock source.
//! \n Valid values are:
//! - \b USCI_A_UART_CLOCKSOURCE_SMCLK
//! - \b USCI_A_UART_CLOCKSOURCE_ACLK
uint8_t selectClockSource;
//! Is the value to be written into UCBRx bits
uint16_t clockPrescalar;
//! Is First modulation stage register setting. This value is a pre-
//! calculated value which can be obtained from the Device Users Guide.
//! This value is written into UCBRFx bits of UCAxMCTLW.
uint8_t firstModReg;
//! Is Second modulation stage register setting. This value is a pre-
//! calculated value which can be obtained from the Device Users Guide.
//! This value is written into UCBRSx bits of UCAxMCTLW.
uint8_t secondModReg;
//! Is the desired parity.
//! \n Valid values are:
//! - \b USCI_A_UART_NO_PARITY [Default]
//! - \b USCI_A_UART_ODD_PARITY
//! - \b USCI_A_UART_EVEN_PARITY
uint8_t parity;
//! Controls direction of receive and transmit shift register.
//! \n Valid values are:
//! - \b USCI_A_UART_MSB_FIRST
//! - \b USCI_A_UART_LSB_FIRST [Default]
uint8_t msborLsbFirst;
//! Indicates one/two STOP bits
//! \n Valid values are:
//! - \b USCI_A_UART_ONE_STOP_BIT [Default]
//! - \b USCI_A_UART_TWO_STOP_BITS
uint8_t numberofStopBits;
//! Selects the mode of operation
//! \n Valid values are:
//! - \b USCI_A_UART_MODE [Default]
//! - \b USCI_A_UART_IDLE_LINE_MULTI_PROCESSOR_MODE
//! - \b USCI_A_UART_ADDRESS_BIT_MULTI_PROCESSOR_MODE
//! - \b USCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE
uint8_t uartMode;
//! Indicates low frequency or oversampling baud generation
//! \n Valid values are:
//! - \b USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION
//! - \b USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION
uint8_t overSampling;
} USCI_A_UART_initParam;
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_UART_init().
//
//*****************************************************************************
#define USCI_A_UART_NO_PARITY 0x00
#define USCI_A_UART_ODD_PARITY 0x01
#define USCI_A_UART_EVEN_PARITY 0x02
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_UART_init().
//
//*****************************************************************************
#define USCI_A_UART_MSB_FIRST UCMSB
#define USCI_A_UART_LSB_FIRST 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_UART_init().
//
//*****************************************************************************
#define USCI_A_UART_MODE UCMODE_0
#define USCI_A_UART_IDLE_LINE_MULTI_PROCESSOR_MODE UCMODE_1
#define USCI_A_UART_ADDRESS_BIT_MULTI_PROCESSOR_MODE UCMODE_2
#define USCI_A_UART_AUTOMATIC_BAUDRATE_DETECTION_MODE UCMODE_3
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_UART_init().
//
//*****************************************************************************
#define USCI_A_UART_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
#define USCI_A_UART_CLOCKSOURCE_ACLK UCSSEL__ACLK
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_UART_init().
//
//*****************************************************************************
#define USCI_A_UART_ONE_STOP_BIT 0x00
#define USCI_A_UART_TWO_STOP_BITS UCSPB
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_A_UART_init().
//
//*****************************************************************************
#define USCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION 0x01
#define USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION 0x00
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: USCI_A_UART_enableInterrupt(), and
// USCI_A_UART_disableInterrupt().
//
//*****************************************************************************
#define USCI_A_UART_RECEIVE_INTERRUPT UCRXIE
#define USCI_A_UART_TRANSMIT_INTERRUPT UCTXIE
#define USCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT UCRXEIE
#define USCI_A_UART_BREAKCHAR_INTERRUPT UCBRKIE
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: USCI_A_UART_getInterruptStatus(), and
// USCI_A_UART_clearInterrupt() as well as returned by the
// USCI_A_UART_getInterruptStatus() function.
//
//*****************************************************************************
#define USCI_A_UART_RECEIVE_INTERRUPT_FLAG UCRXIFG
#define USCI_A_UART_TRANSMIT_INTERRUPT_FLAG UCTXIFG
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: USCI_A_UART_queryStatusFlags() as well as returned by the
// USCI_A_UART_queryStatusFlags() function.
//
//*****************************************************************************
#define USCI_A_UART_LISTEN_ENABLE UCLISTEN
#define USCI_A_UART_FRAMING_ERROR UCFE
#define USCI_A_UART_OVERRUN_ERROR UCOE
#define USCI_A_UART_PARITY_ERROR UCPE
#define USCI_A_UART_BREAK_DETECT UCBRK
#define USCI_A_UART_RECEIVE_ERROR UCRXERR
#define USCI_A_UART_ADDRESS_RECEIVED UCADDR
#define USCI_A_UART_IDLELINE UCIDLE
#define USCI_A_UART_BUSY UCBUSY
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Advanced initialization routine for the UART block. The values to be
//! written into the clockPrescalar, firstModReg, secondModReg and overSampling
//! parameters should be pre-computed and passed into the initialization
//! function.
//!
//! Upon successful initialization of the UART block, this function will have
//! initialized the module, but the UART block still remains disabled and must
//! be enabled with USCI_A_UART_enable(). To calculate values for
//! clockPrescalar, firstModReg, secondModReg and overSampling please use the
//! link below.
//!
//! http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430BaudRateConverter/index.html
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param param is the pointer to struct for initialization.
//!
//! Modified bits are \b UCPEN, \b UCPAR, \b UCMSB, \b UC7BIT, \b UCSPB, \b
//! UCMODEx and \b UCSYNC of \b UCAxCTL0 register; bits \b UCSSELx and \b
//! UCSWRST of \b UCAxCTL1 register.
//!
//! \return STATUS_SUCCESS or STATUS_FAIL of the initialization process
//
//*****************************************************************************
extern bool USCI_A_UART_init(uint16_t baseAddress,
USCI_A_UART_initParam *param);
//*****************************************************************************
//
//! \brief Transmits a byte from the UART Module.
//!
//! This function will place the supplied data into UART transmit data register
//! to start transmission
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param transmitData data to be transmitted from the UART module
//!
//! Modified bits of \b UCAxTXBUF register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_transmitData(uint16_t baseAddress,
uint8_t transmitData);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the UART Module.
//!
//! This function reads a byte of data from the UART receive data Register.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! Modified bits of \b UCAxRXBUF register.
//!
//! \return Returns the byte received from by the UART module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t USCI_A_UART_receiveData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables individual UART interrupt sources.
//!
//! Enables the indicated UART interrupt sources. The interrupt flag is first
//! and then the corresponding interrupt is enabled. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_UART_RECEIVE_INTERRUPT - Receive interrupt
//! - \b USCI_A_UART_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b USCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT - Receive
//! erroneous-character interrupt enable
//! - \b USCI_A_UART_BREAKCHAR_INTERRUPT - Receive break character
//! interrupt enable
//!
//! Modified bits of \b UCAxCTL1 register and bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_enableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Disables individual UART interrupt sources.
//!
//! Disables the indicated UART interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_UART_RECEIVE_INTERRUPT - Receive interrupt
//! - \b USCI_A_UART_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b USCI_A_UART_RECEIVE_ERRONEOUSCHAR_INTERRUPT - Receive
//! erroneous-character interrupt enable
//! - \b USCI_A_UART_BREAKCHAR_INTERRUPT - Receive break character
//! interrupt enable
//!
//! Modified bits of \b UCAxCTL1 register and bits of \b UCAxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_disableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current UART interrupt status.
//!
//! This returns the interrupt status for the UART module based on which flag
//! is passed.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_UART_RECEIVE_INTERRUPT_FLAG - Receive interrupt flag
//! - \b USCI_A_UART_TRANSMIT_INTERRUPT_FLAG - Transmit interrupt flag
//!
//! Modified bits of \b UCAxIFG register.
//!
//! \return Logical OR of any of the following:
//! - \b USCI_A_UART_RECEIVE_INTERRUPT_FLAG Receive interrupt flag
//! - \b USCI_A_UART_TRANSMIT_INTERRUPT_FLAG Transmit interrupt flag
//! \n indicating the status of the masked flags
//
//*****************************************************************************
extern uint8_t USCI_A_UART_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears UART interrupt sources.
//!
//! The UART interrupt source is cleared, so that it no longer asserts. The
//! highest interrupt flag is automatically cleared when an interrupt vector
//! generator is used.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param mask is a bit mask of the interrupt sources to be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_UART_RECEIVE_INTERRUPT_FLAG - Receive interrupt flag
//! - \b USCI_A_UART_TRANSMIT_INTERRUPT_FLAG - Transmit interrupt flag
//!
//! Modified bits of \b UCAxIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_clearInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Enables the UART block.
//!
//! This will enable operation of the UART block.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the UART block.
//!
//! This will disable operation of the UART block.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! Modified bits are \b UCSWRST of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Gets the current UART status flags.
//!
//! This returns the status for the UART module based on which flag is passed.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_A_UART_LISTEN_ENABLE
//! - \b USCI_A_UART_FRAMING_ERROR
//! - \b USCI_A_UART_OVERRUN_ERROR
//! - \b USCI_A_UART_PARITY_ERROR
//! - \b USCI_A_UART_BREAK_DETECT
//! - \b USCI_A_UART_RECEIVE_ERROR
//! - \b USCI_A_UART_ADDRESS_RECEIVED
//! - \b USCI_A_UART_IDLELINE
//! - \b USCI_A_UART_BUSY
//!
//! Modified bits of \b UCAxSTAT register.
//!
//! \return Logical OR of any of the following:
//! - \b USCI_A_UART_LISTEN_ENABLE
//! - \b USCI_A_UART_FRAMING_ERROR
//! - \b USCI_A_UART_OVERRUN_ERROR
//! - \b USCI_A_UART_PARITY_ERROR
//! - \b USCI_A_UART_BREAK_DETECT
//! - \b USCI_A_UART_RECEIVE_ERROR
//! - \b USCI_A_UART_ADDRESS_RECEIVED
//! - \b USCI_A_UART_IDLELINE
//! - \b USCI_A_UART_BUSY
//! \n indicating the status of the masked interrupt flags
//
//*****************************************************************************
extern uint8_t USCI_A_UART_queryStatusFlags(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Sets the UART module in dormant mode
//!
//! Puts USCI in sleep mode. Only characters that are preceded by an idle-line
//! or with address bit set UCRXIFG. In UART mode with automatic baud-rate
//! detection, only the combination of a break and sync field sets UCRXIFG.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! Modified bits of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_setDormant(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Re-enables UART module from dormant mode
//!
//! Not dormant. All received characters set UCRXIFG.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! Modified bits are \b UCDORM of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_resetDormant(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Transmits the next byte to be transmitted marked as address
//! depending on selected multiprocessor mode
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//! \param transmitAddress is the next byte to be transmitted
//!
//! Modified bits of \b UCAxTXBUF register and bits of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_transmitAddress(uint16_t baseAddress,
uint8_t transmitAddress);
//*****************************************************************************
//
//! \brief Transmit break.
//!
//! Transmits a break with the next write to the transmit buffer. In UART mode
//! with automatic baud-rate detection,
//! USCI_A_UART_AUTOMATICBAUDRATE_SYNC(0x55) must be written into UCAxTXBUF to
//! generate the required break/sync fields. Otherwise, DEFAULT_SYNC(0x00) must
//! be written into the transmit buffer. Also ensures module is ready for
//! transmitting the next data.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! Modified bits of \b UCAxTXBUF register and bits of \b UCAxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_A_UART_transmitBreak(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the RX Buffer of the UART for the DMA module.
//!
//! Returns the address of the UART RX Buffer. This can be used in conjunction
//! with the DMA to store the received data directly to memory.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! \return Address of RX Buffer
//
//*****************************************************************************
extern uint32_t USCI_A_UART_getReceiveBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the TX Buffer of the UART for the DMA module.
//!
//! Returns the address of the UART TX Buffer. This can be used in conjunction
//! with the DMA to obtain transmitted data directly from memory.
//!
//! \param baseAddress is the base address of the USCI_A_UART module.
//!
//! \return Address of TX Buffer
//
//*****************************************************************************
extern uint32_t USCI_A_UART_getTransmitBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_USCI_A_UART_H__

View File

@@ -0,0 +1,592 @@
//*****************************************************************************
//
// usci_b_i2c.c - Driver for the usci_b_i2c Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup usci_b_i2c_api usci_b_i2c
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Bx__
#include "usci_b_i2c.h"
#include <assert.h>
void USCI_B_I2C_initMaster(uint16_t baseAddress, USCI_B_I2C_initMasterParam *param)
{
uint16_t preScalarValue;
//Disable the USCI module and clears the other bits of control register
HWREG8(baseAddress + OFS_UCBxCTL1) = UCSWRST;
/*
* Configure as I2C master mode.
* UCMST = Master mode
* UCMODE_3 = I2C mode
* UCSYNC = Synchronous mode
*/
HWREG8(baseAddress + OFS_UCBxCTL0) = UCMST + UCMODE_3 + UCSYNC;
//Configure I2C clock source
HWREG8(baseAddress + OFS_UCBxCTL1) = (param->selectClockSource + UCSWRST );
/*
* Compute the clock divider that achieves the fastest speed less than or
* equal to the desired speed. The numerator is biased to favor a larger
* clock divider so that the resulting clock is always less than or equal
* to the desired clock, never greater.
*/
preScalarValue = (unsigned short)(param->i2cClk / param->dataRate);
HWREG16(baseAddress + OFS_UCBxBRW) = preScalarValue;
}
void USCI_B_I2C_initSlave (uint16_t baseAddress,
uint8_t slaveAddress
)
{
//Disable the USCI module
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCSWRST;
//Clear USCI master mode
HWREG8(baseAddress + OFS_UCBxCTL0) &= ~UCMST;
//Confiugre I2C as Slave and Synchronous mode
HWREG8(baseAddress + OFS_UCBxCTL0) = UCMODE_3 + UCSYNC;
//Set up the slave address.
HWREG16(baseAddress + OFS_UCBxI2COA) = slaveAddress;
}
void USCI_B_I2C_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~(UCSWRST);
}
void USCI_B_I2C_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCSWRST;
}
void USCI_B_I2C_setSlaveAddress (uint16_t baseAddress,
uint8_t slaveAddress
)
{
//Set the address of the slave with which the master will communicate.
HWREG16(baseAddress + OFS_UCBxI2CSA) = (slaveAddress);
}
void USCI_B_I2C_setMode (uint16_t baseAddress,
uint8_t mode
)
{
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~USCI_B_I2C_TRANSMIT_MODE;
HWREG8(baseAddress + OFS_UCBxCTL1) |= mode;
}
void USCI_B_I2C_slavePutData (uint16_t baseAddress,
uint8_t transmitData
)
{
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = transmitData;
}
uint8_t USCI_B_I2C_slaveGetData (uint16_t baseAddress)
{
//Read a byte.
return (HWREG8(baseAddress + OFS_UCBxRXBUF));
}
uint8_t USCI_B_I2C_isBusBusy (uint16_t baseAddress)
{
//Return the bus busy status.
return (HWREG8(baseAddress + OFS_UCBxSTAT) & UCBBUSY);
}
uint8_t USCI_B_I2C_isBusy (uint16_t baseAddress)
{
//Return the busy status.
if ((HWREG8(baseAddress + OFS_UCBxIFG) & (UCTXIFG + UCRXIFG))){
return (USCI_B_I2C_BUS_BUSY);
} else {
return (USCI_B_I2C_BUS_NOT_BUSY);
}
}
uint8_t USCI_B_I2C_masterIsStopSent (uint16_t baseAddress)
{
//Return the bus busy status.
return (HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTP);
}
uint8_t USCI_B_I2C_masterIsStartSent (uint16_t baseAddress)
{
//Return if master has sent start
return (HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTT);
}
void USCI_B_I2C_masterSendStart (uint16_t baseAddress)
{
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTT;
}
void USCI_B_I2C_enableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
//Enable the interrupt masked bit
HWREG8(baseAddress + OFS_UCBxIE) |= mask;
}
void USCI_B_I2C_disableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
//Disable the interrupt masked bit
HWREG8(baseAddress + OFS_UCBxIE) &= ~(mask);
}
void USCI_B_I2C_clearInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
//Clear the I2C interrupt source.
HWREG8(baseAddress + OFS_UCBxIFG) &= ~(mask);
}
uint8_t USCI_B_I2C_getInterruptStatus (uint16_t baseAddress,
uint8_t mask
)
{
//Return the interrupt status of the request masked bit.
return (HWREG8(baseAddress + OFS_UCBxIFG) & mask);
}
void USCI_B_I2C_masterSendSingleByte (uint16_t baseAddress,
uint8_t txData
)
{
//Store current TXIE status
uint8_t txieStatus = HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Clear transmit interrupt flag before enabling interrupt again
HWREG8(baseAddress + OFS_UCBxIFG) &= ~(UCTXIFG);
//Reinstate transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) |= txieStatus;
}
bool USCI_B_I2C_masterSendSingleByteWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
// Creating variable for second timeout scenario
uint32_t timeout2 = timeout;
//Store current TXIE status
uint8_t txieStatus = HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout) ;
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout2) ;
//Check if transfer timed out
if (timeout2 == 0){
return (STATUS_FAIL);
}
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Clear transmit interrupt flag before enabling interrupt again
HWREG8(baseAddress + OFS_UCBxIFG) &= ~(UCTXIFG);
//Reinstate transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) |= txieStatus;
return (STATUS_SUCCESS);
}
void USCI_B_I2C_masterSendMultiByteStart (uint16_t baseAddress,
uint8_t txData
)
{
//Store current transmit interrupt enable
uint8_t txieStatus = HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
//Reinstate transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) |= txieStatus;
}
bool USCI_B_I2C_masterSendMultiByteStartWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
//Store current transmit interrupt enable
uint8_t txieStatus = HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout) ;
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
//Reinstate transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) |= txieStatus;
return(STATUS_SUCCESS);
}
void USCI_B_I2C_masterSendMultiByteNext (uint16_t baseAddress,
uint8_t txData
)
{
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
}
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
}
bool USCI_B_I2C_masterSendMultiByteNextWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout);
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
}
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
return(STATUS_SUCCESS);
}
void USCI_B_I2C_masterSendMultiByteFinish (uint16_t baseAddress,
uint8_t txData
)
{
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
}
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
}
bool USCI_B_I2C_masterSendMultiByteFinishWithTimeout (uint16_t baseAddress,
uint8_t txData,
uint32_t timeout
)
{
uint32_t timeout2 = timeout;
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout) ;
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
}
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout2) ;
//Check if transfer timed out
if (timeout2 == 0){
return (STATUS_FAIL);
}
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
return(STATUS_SUCCESS);
}
void USCI_B_I2C_masterSendMultiByteStop (uint16_t baseAddress)
{
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;
}
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
}
bool USCI_B_I2C_masterSendMultiByteStopWithTimeout (uint16_t baseAddress,
uint32_t timeout)
{
//If interrupts are not used, poll for flags
if (!(HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE)){
//Poll for transmit interrupt flag.
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) && --timeout) ;
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
}
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
return (STATUS_SUCCESS);
}
void USCI_B_I2C_masterReceiveMultiByteStart (uint16_t baseAddress)
{
//Set USCI in Receive mode
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~UCTR;
//Send start
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTT;
}
uint8_t USCI_B_I2C_masterReceiveMultiByteNext (uint16_t baseAddress)
{
return (HWREG8(baseAddress + OFS_UCBxRXBUF));
}
uint8_t USCI_B_I2C_masterReceiveMultiByteFinish (uint16_t baseAddress)
{
uint8_t receiveData;
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Capture data from receive buffer after setting stop bit due to
//MSP430 I2C critical timing.
receiveData = HWREG8(baseAddress + OFS_UCBxRXBUF);
//Wait for Stop to finish
while (HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTP);
//Wait for RX buffer
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCRXIFG));
return receiveData;
}
bool USCI_B_I2C_masterReceiveMultiByteFinishWithTimeout (uint16_t baseAddress,
uint8_t *rxData,
uint32_t timeout
)
{
uint32_t timeout2 = timeout;
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Capture data from receive buffer after setting stop bit due to
//MSP430 I2C critical timing.
*rxData = (HWREG8(baseAddress + OFS_UCBxRXBUF));
//Wait for Stop to finish
while ((HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTP) && --timeout);
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
// Wait for RX buffer
while ((!(HWREG8(baseAddress + OFS_UCBxIFG) & UCRXIFG)) && --timeout2) ;
//Check if transfer timed out
if (timeout2 == 0){
return (STATUS_FAIL);
}
return (STATUS_SUCCESS);
}
void USCI_B_I2C_masterReceiveMultiByteStop (uint16_t baseAddress)
{
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
}
void USCI_B_I2C_masterReceiveSingleStart (uint16_t baseAddress)
{
//local variable to store GIE status
uint16_t gieStatus;
//Store current SR register
gieStatus = __get_SR_register() & GIE;
//Disable global interrupt
__disable_interrupt();
//Set USCI in Receive mode
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~UCTR;
//Send start condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTT;
//Poll for Start bit to complete
while (HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTT) ;
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Reinstate SR register
__bis_SR_register(gieStatus);
}
bool USCI_B_I2C_masterReceiveSingleStartWithTimeout (uint16_t baseAddress,
uint32_t timeout
)
{
//local variable to store GIE status
uint16_t gieStatus;
//Store current SR register
gieStatus = __get_SR_register() & GIE;
//Disable global interrupt
__disable_interrupt();
//Set USCI in Receive mode
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~UCTR;
//Send start condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTT;
//Poll for Start bit to complete
while (((HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTT)) && --timeout);
//Check if transfer timed out
if (timeout == 0){
return (STATUS_FAIL);
}
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Reinstate SR register
__bis_SR_register(gieStatus);
return (STATUS_SUCCESS);
}
uint8_t USCI_B_I2C_masterReceiveSingle (uint16_t baseAddress)
{
//Polling RXIFG0 if RXIE is not enabled
if(!(HWREG8(baseAddress + OFS_UCBxIE) & UCRXIE)) {
while(!(HWREG8(baseAddress + OFS_UCBxIFG) & UCRXIFG));
}
//Read a byte.
return (HWREG8(baseAddress + OFS_UCBxRXBUF));
}
uint32_t USCI_B_I2C_getReceiveBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxRXBUF );
}
uint32_t USCI_B_I2C_getTransmitBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxTXBUF );
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for usci_b_i2c_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,848 @@
//*****************************************************************************
//
// usci_b_i2c.h - Driver for the USCI_B_I2C Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_USCI_B_I2C_H__
#define __MSP430WARE_USCI_B_I2C_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Bx__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the USCI_B_I2C_initMaster() function as the param parameter.
//
//*****************************************************************************
typedef struct USCI_B_I2C_initMasterParam {
//! Is the clocksource.
//! \n Valid values are:
//! - \b USCI_B_I2C_CLOCKSOURCE_ACLK
//! - \b USCI_B_I2C_CLOCKSOURCE_SMCLK
uint8_t selectClockSource;
//! Is the rate of the clock supplied to the I2C module.
uint32_t i2cClk;
//! Set up for selecting data transfer rate.
//! \n Valid values are:
//! - \b USCI_B_I2C_SET_DATA_RATE_400KBPS
//! - \b USCI_B_I2C_SET_DATA_RATE_100KBPS
uint32_t dataRate;
} USCI_B_I2C_initMasterParam;
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_B_I2C_initMaster().
//
//*****************************************************************************
#define USCI_B_I2C_CLOCKSOURCE_ACLK UCSSEL__ACLK
#define USCI_B_I2C_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_B_I2C_initMaster().
//
//*****************************************************************************
#define USCI_B_I2C_SET_DATA_RATE_400KBPS 400000
#define USCI_B_I2C_SET_DATA_RATE_100KBPS 100000
//*****************************************************************************
//
// The following are values that can be passed to the mode parameter for
// functions: USCI_B_I2C_setMode().
//
//*****************************************************************************
#define USCI_B_I2C_TRANSMIT_MODE UCTR
#define USCI_B_I2C_RECEIVE_MODE 0x00
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: USCI_B_I2C_enableInterrupt(), USCI_B_I2C_disableInterrupt(),
// USCI_B_I2C_clearInterrupt(), and USCI_B_I2C_getInterruptStatus() as well as
// returned by the USCI_B_I2C_getInterruptStatus() function.
//
//*****************************************************************************
#define USCI_B_I2C_STOP_INTERRUPT UCSTPIE
#define USCI_B_I2C_START_INTERRUPT UCSTTIE
#define USCI_B_I2C_RECEIVE_INTERRUPT UCRXIE
#define USCI_B_I2C_TRANSMIT_INTERRUPT UCTXIE
#define USCI_B_I2C_NAK_INTERRUPT UCNACKIE
#define USCI_B_I2C_ARBITRATIONLOST_INTERRUPT UCALIE
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the USCI_B_I2C_isBusy() function and the
// USCI_B_I2C_isBusBusy() function.
//
//*****************************************************************************
#define USCI_B_I2C_BUS_BUSY UCBBUSY
#define USCI_B_I2C_BUS_NOT_BUSY 0x00
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the USCI_B_I2C_masterIsStartSent() function.
//
//*****************************************************************************
#define USCI_B_I2C_SENDING_START UCTXSTT
#define USCI_B_I2C_START_SEND_COMPLETE 0x00
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the USCI_B_I2C_masterIsStopSent() function.
//
//*****************************************************************************
#define USCI_B_I2C_SENDING_STOP UCTXSTP
#define USCI_B_I2C_STOP_SEND_COMPLETE 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the I2C Master block.
//!
//! This function initializes operation of the I2C Master block. Upon
//! successful initialization of the I2C block, this function will have set the
//! bus speed for the master; however I2C module is still disabled till
//! USCI_B_I2C_enable is invoked. If the parameter \e dataRate is
//! USCI_B_I2C_SET_DATA_RATE_400KBPS, then the master block will be set up to
//! transfer data at 400 kbps; otherwise, it will be set up to transfer data at
//! 100 kbps.
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param param is the pointe to struct for master initialization.
//!
//! Modified bits are \b UCBxBR0 of \b UCBxBR1 register; bits \b UCSSELx and \b
//! UCSWRST of \b UCBxCTL1 register; bits \b UCMST, \b UCMODE_3 and \b UCSYNC
//! of \b UCBxCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_initMaster(uint16_t baseAddress,
USCI_B_I2C_initMasterParam *param);
//*****************************************************************************
//
//! \brief Initializes the I2C Slave block.
//!
//! This function initializes operation of the I2C as a Slave mode. Upon
//! successful initialization of the I2C blocks, this function will have set
//! the slave address but the I2C module is still disabled till
//! USCI_B_I2C_enable is invoked.
//!
//! \param baseAddress is the base address of the I2C Slave module.
//! \param slaveAddress 7-bit slave address
//!
//! Modified bits of \b UCBxI2COA register; bits \b UCSWRST of \b UCBxCTL1
//! register; bits \b UCMODE_3 and \b UCSYNC of \b UCBxCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_initSlave(uint16_t baseAddress,
uint8_t slaveAddress);
//*****************************************************************************
//
//! \brief Enables the I2C block.
//!
//! This will enable operation of the I2C block.
//!
//! \param baseAddress is the base address of the USCI I2C module.
//!
//! Modified bits are \b UCSWRST of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the I2C block.
//!
//! This will disable operation of the I2C block.
//!
//! \param baseAddress is the base address of the USCI I2C module.
//!
//! Modified bits are \b UCSWRST of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets the address that the I2C Master will place on the bus.
//!
//! This function will set the address that the I2C Master will place on the
//! bus when initiating a transaction.
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param slaveAddress 7-bit slave address
//!
//! Modified bits of \b UCBxI2CSA register; bits \b UCSWRST of \b UCBxCTL1
//! register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_setSlaveAddress(uint16_t baseAddress,
uint8_t slaveAddress);
//*****************************************************************************
//
//! \brief Sets the mode of the I2C device
//!
//! When the receive parameter is set to USCI_B_I2C_TRANSMIT_MODE, the address
//! will indicate that the I2C module is in receive mode; otherwise, the I2C
//! module is in send mode.
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param mode indicates whether module is in transmit/receive mode
//! Valid values are:
//! - \b USCI_B_I2C_TRANSMIT_MODE
//! - \b USCI_B_I2C_RECEIVE_MODE [Default]
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_setMode(uint16_t baseAddress,
uint8_t mode);
//*****************************************************************************
//
//! \brief Transmits a byte from the I2C Module.
//!
//! This function will place the supplied data into I2C transmit data register
//! to start transmission Modified bit is UCBxTXBUF register
//!
//! \param baseAddress is the base address of the I2C module.
//! \param transmitData data to be transmitted from the I2C module
//!
//! Modified bits of \b UCBxTXBUF register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_slavePutData(uint16_t baseAddress,
uint8_t transmitData);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the I2C Module.
//!
//! This function reads a byte of data from the I2C receive data Register.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return Returns the byte received from by the I2C module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_slaveGetData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Indicates whether or not the I2C bus is busy.
//!
//! This function returns an indication of whether or not the I2C bus is
//! busy.This function checks the status of the bus via UCBBUSY bit in UCBxSTAT
//! register.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return Returns USCI_B_I2C_BUS_BUSY if the I2C Master is busy; otherwise,
//! returns USCI_B_I2C_BUS_NOT_BUSY.
//! Return one of the following:
//! - \b USCI_B_I2C_BUS_BUSY
//! - \b USCI_B_I2C_BUS_NOT_BUSY
//! \n indicating if the USCI_B_I2C is busy
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_isBusBusy(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief DEPRECATED - Function may be removed in future release. Indicates
//! whether or not the I2C module is busy.
//!
//! This function returns an indication of whether or not the I2C module is
//! busy transmitting or receiving data. This function checks if the Transmit
//! or receive flag is set.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return Returns USCI_B_I2C_BUS_BUSY if the I2C module is busy; otherwise,
//! returns USCI_B_I2C_BUS_NOT_BUSY.
//! Return one of the following:
//! - \b USCI_B_I2C_BUS_BUSY
//! - \b USCI_B_I2C_BUS_NOT_BUSY
//! \n indicating if the USCI_B_I2C is busy
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_isBusy(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Indicates whether STOP got sent.
//!
//! This function returns an indication of whether or not STOP got sent This
//! function checks the status of the bus via UCTXSTP bit in UCBxCTL1 register.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return Returns USCI_B_I2C_STOP_SEND_COMPLETE if the I2C Master finished
//! sending STOP; otherwise, returns USCI_B_I2C_SENDING_STOP.
//! Return one of the following:
//! - \b USCI_B_I2C_SENDING_STOP
//! - \b USCI_B_I2C_STOP_SEND_COMPLETE
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_masterIsStopSent(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Indicates whether START got sent.
//!
//! This function returns an indication of whether or not START got sent This
//! function checks the status of the bus via UCTXSTT bit in UCBxCTL1 register.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return Returns USCI_B_I2C_START_SEND_COMPLETE if the I2C Master finished
//! sending START; otherwise, returns USCI_B_I2C_SENDING_START.
//! Return one of the following:
//! - \b USCI_B_I2C_SENDING_START
//! - \b USCI_B_I2C_START_SEND_COMPLETE
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_masterIsStartSent(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief This function is used by the Master module to initiate START
//!
//! This function is used by the Master module to initiate STOP
//!
//! \param baseAddress is the base address of the I2C Master module.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterSendStart(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables individual I2C interrupt sources.
//!
//! Enables the indicated I2C interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the I2C module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
//! - \b USCI_B_I2C_START_INTERRUPT - START condition interrupt
//! - \b USCI_B_I2C_RECEIVE_INTERRUPT - Receive interrupt
//! - \b USCI_B_I2C_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b USCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
//! - \b USCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
//! interrupt
//!
//! Modified bits of \b UCBxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_enableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Disables individual I2C interrupt sources.
//!
//! Disables the indicated I2C interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the I2C module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
//! - \b USCI_B_I2C_START_INTERRUPT - START condition interrupt
//! - \b USCI_B_I2C_RECEIVE_INTERRUPT - Receive interrupt
//! - \b USCI_B_I2C_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b USCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
//! - \b USCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
//! interrupt
//!
//! Modified bits of \b UCBxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_disableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears I2C interrupt sources.
//!
//! The I2C interrupt source is cleared, so that it no longer asserts. The
//! highest interrupt flag is automatically cleared when an interrupt vector
//! generator is used.
//!
//! \param baseAddress is the base address of the I2C Slave module.
//! \param mask is a bit mask of the interrupt sources to be cleared.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
//! - \b USCI_B_I2C_START_INTERRUPT - START condition interrupt
//! - \b USCI_B_I2C_RECEIVE_INTERRUPT - Receive interrupt
//! - \b USCI_B_I2C_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b USCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
//! - \b USCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
//! interrupt
//!
//! Modified bits of \b UCBxIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_clearInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current I2C interrupt status.
//!
//! This returns the interrupt status for the I2C module based on which flag is
//! passed. mask parameter can be logic OR of any of the following selection.
//!
//! \param baseAddress is the base address of the I2C module.
//! \param mask is the masked interrupt flag status to be returned.
//! Mask value is the logical OR of any of the following:
//! - \b USCI_B_I2C_STOP_INTERRUPT - STOP condition interrupt
//! - \b USCI_B_I2C_START_INTERRUPT - START condition interrupt
//! - \b USCI_B_I2C_RECEIVE_INTERRUPT - Receive interrupt
//! - \b USCI_B_I2C_TRANSMIT_INTERRUPT - Transmit interrupt
//! - \b USCI_B_I2C_NAK_INTERRUPT - Not-acknowledge interrupt
//! - \b USCI_B_I2C_ARBITRATIONLOST_INTERRUPT - Arbitration lost
//! interrupt
//!
//! \return the masked status of the interrupt flag
//! Return Logical OR of any of the following:
//! - \b USCI_B_I2C_STOP_INTERRUPT STOP condition interrupt
//! - \b USCI_B_I2C_START_INTERRUPT START condition interrupt
//! - \b USCI_B_I2C_RECEIVE_INTERRUPT Receive interrupt
//! - \b USCI_B_I2C_TRANSMIT_INTERRUPT Transmit interrupt
//! - \b USCI_B_I2C_NAK_INTERRUPT Not-acknowledge interrupt
//! - \b USCI_B_I2C_ARBITRATIONLOST_INTERRUPT Arbitration lost
//! interrupt
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Does single byte transmission from Master to Slave
//!
//! This function is used by the Master module to send a single byte.This
//! function does the following: - Sends START; - Transmits the byte to the
//! Slave; - Sends STOP
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the data byte to be transmitted
//!
//! Modified bits of \b UCBxTXBUF register, bits of \b UCBxIFG register, bits
//! of \b UCBxCTL1 register and bits of \b UCBxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterSendSingleByte(uint16_t baseAddress,
uint8_t txData);
//*****************************************************************************
//
//! \brief Does single byte transmission from Master to Slave with timeout
//!
//! This function is used by the Master module to send a single byte. This
//! function does the following: - Sends START; - Transmits the byte to the
//! Slave; - Sends STOP
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the data byte to be transmitted
//! \param timeout is the amount of time to wait until giving up
//!
//! Modified bits of \b UCBxTXBUF register, bits of \b UCBxIFG register, bits
//! of \b UCBxCTL1 register and bits of \b UCBxIE register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
//
//*****************************************************************************
extern bool USCI_B_I2C_masterSendSingleByteWithTimeout(uint16_t baseAddress,
uint8_t txData,
uint32_t timeout);
//*****************************************************************************
//
//! \brief Starts multi-byte transmission from Master to Slave
//!
//! This function is used by the Master module to send a single byte. This
//! function does the following: - Sends START; - Transmits the first data byte
//! of a multi-byte transmission to the Slave
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the first data byte to be transmitted
//!
//! Modified bits of \b UCBxTXBUF register, bits of \b UCBxIFG register, bits
//! of \b UCBxCTL1 register and bits of \b UCBxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterSendMultiByteStart(uint16_t baseAddress,
uint8_t txData);
//*****************************************************************************
//
//! \brief Starts multi-byte transmission from Master to Slave with timeout
//!
//! This function is used by the Master module to send a single byte. This
//! function does the following: - Sends START; - Transmits the first data byte
//! of a multi-byte transmission to the Slave
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the first data byte to be transmitted
//! \param timeout is the amount of time to wait until giving up
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
//
//*****************************************************************************
extern bool USCI_B_I2C_masterSendMultiByteStartWithTimeout(uint16_t baseAddress,
uint8_t txData,
uint32_t timeout);
//*****************************************************************************
//
//! \brief Continues multi-byte transmission from Master to Slave
//!
//! This function is used by the Master module continue each byte of a multi-
//! byte transmission. This function does the following: -Transmits each data
//! byte of a multi-byte transmission to the Slave
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the next data byte to be transmitted
//!
//! Modified bits of \b UCBxTXBUF register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterSendMultiByteNext(uint16_t baseAddress,
uint8_t txData);
//*****************************************************************************
//
//! \brief Continues multi-byte transmission from Master to Slave with timeout
//!
//! This function is used by the Master module continue each byte of a multi-
//! byte transmission. This function does the following: -Transmits each data
//! byte of a multi-byte transmission to the Slave
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the next data byte to be transmitted
//! \param timeout is the amount of time to wait until giving up
//!
//! Modified bits of \b UCBxTXBUF register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
//
//*****************************************************************************
extern bool USCI_B_I2C_masterSendMultiByteNextWithTimeout(uint16_t baseAddress,
uint8_t txData,
uint32_t timeout);
//*****************************************************************************
//
//! \brief Finishes multi-byte transmission from Master to Slave
//!
//! This function is used by the Master module to send the last byte and STOP.
//! This function does the following: - Transmits the last data byte of a
//! multi-byte transmission to the Slave; - Sends STOP
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the last data byte to be transmitted in a multi-byte
//! transmission
//!
//! Modified bits of \b UCBxTXBUF register and bits of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterSendMultiByteFinish(uint16_t baseAddress,
uint8_t txData);
//*****************************************************************************
//
//! \brief Finishes multi-byte transmission from Master to Slave with timeout
//!
//! This function is used by the Master module to send the last byte and STOP.
//! This function does the following: - Transmits the last data byte of a
//! multi-byte transmission to the Slave; - Sends STOP
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param txData is the last data byte to be transmitted in a multi-byte
//! transmission
//! \param timeout is the amount of time to wait until giving up
//!
//! Modified bits of \b UCBxTXBUF register and bits of \b UCBxCTL1 register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
//
//*****************************************************************************
extern bool USCI_B_I2C_masterSendMultiByteFinishWithTimeout(uint16_t baseAddress,
uint8_t txData,
uint32_t timeout);
//*****************************************************************************
//
//! \brief Send STOP byte at the end of a multi-byte transmission from Master
//! to Slave
//!
//! This function is used by the Master module send STOP at the end of a multi-
//! byte transmission. This function does the following: - Sends a STOP after
//! current transmission is complete
//!
//! \param baseAddress is the base address of the I2C Master module.
//!
//! Modified bits are \b UCTXSTP of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterSendMultiByteStop(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Send STOP byte at the end of a multi-byte transmission from Master
//! to Slave with timeout
//!
//! This function is used by the Master module send STOP at the end of a multi-
//! byte transmission. This function does the following: - Sends a STOP after
//! current transmission is complete
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param timeout is the amount of time to wait until giving up
//!
//! Modified bits are \b UCTXSTP of \b UCBxCTL1 register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
//
//*****************************************************************************
extern bool USCI_B_I2C_masterSendMultiByteStopWithTimeout(uint16_t baseAddress,
uint32_t timeout);
//*****************************************************************************
//
//! \brief Starts multi-byte reception at the Master end
//!
//! This function is used by the Master module initiate reception of a single
//! byte. This function does the following: - Sends START
//!
//! \param baseAddress is the base address of the I2C Master module.
//!
//! Modified bits are \b UCTXSTT of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterReceiveMultiByteStart(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Starts multi-byte reception at the Master end one byte at a time
//!
//! This function is used by the Master module to receive each byte of a multi-
//! byte reception. This function reads currently received byte
//!
//! \param baseAddress is the base address of the I2C Master module.
//!
//! \return Received byte at Master end.
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_masterReceiveMultiByteNext(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Finishes multi-byte reception at the Master end
//!
//! This function is used by the Master module to initiate completion of a
//! multi-byte reception. This function does the following: - Receives the
//! current byte and initiates the STOP from Master to Slave
//!
//! \param baseAddress is the base address of the I2C Master module.
//!
//! Modified bits are \b UCTXSTP of \b UCBxCTL1 register.
//!
//! \return Received byte at Master end.
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_masterReceiveMultiByteFinish(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Finishes multi-byte reception at the Master end with timeout
//!
//! This function is used by the Master module to initiate completion of a
//! multi-byte reception. This function does the following: - Receives the
//! current byte and initiates the STOP from Master to Slave
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param rxData is a pointer to the location to store the received byte at
//! master end
//! \param timeout is the amount of time to wait until giving up
//!
//! Modified bits are \b UCTXSTP of \b UCBxCTL1 register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
//
//*****************************************************************************
extern bool USCI_B_I2C_masterReceiveMultiByteFinishWithTimeout(uint16_t baseAddress,
uint8_t *rxData,
uint32_t timeout);
//*****************************************************************************
//
//! \brief Sends the STOP at the end of a multi-byte reception at the Master
//! end
//!
//! This function is used by the Master module to initiate STOP
//!
//! \param baseAddress is the base address of the I2C Master module.
//!
//! Modified bits are \b UCTXSTP of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterReceiveMultiByteStop(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Initiates a single byte Reception at the Master End
//!
//! This function sends a START and STOP immediately to indicate Single byte
//! reception
//!
//! \param baseAddress is the base address of the I2C Master module.
//!
//! Modified bits are \b GIE of \b SR register; bits \b UCTXSTT and \b UCTXSTP
//! of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_I2C_masterReceiveSingleStart(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Initiates a single byte Reception at the Master End with timeout
//!
//! This function sends a START and STOP immediately to indicate Single byte
//! reception
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param timeout is the amount of time to wait until giving up
//!
//! Modified bits are \b GIE of \b SR register; bits \b UCTXSTT and \b UCTXSTP
//! of \b UCBxCTL1 register.
//!
//! \return STATUS_SUCCESS or STATUS_FAILURE of the transmission process.
//
//*****************************************************************************
extern bool USCI_B_I2C_masterReceiveSingleStartWithTimeout(uint16_t baseAddress,
uint32_t timeout);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the I2C Master Module.
//!
//! This function reads a byte of data from the I2C receive data Register.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return Returns the byte received from by the I2C module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t USCI_B_I2C_masterReceiveSingle(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the RX Buffer of the I2C for the DMA module.
//!
//! Returns the address of the I2C RX Buffer. This can be used in conjunction
//! with the DMA to store the received data directly to memory.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return the address of the RX Buffer
//
//*****************************************************************************
extern uint32_t USCI_B_I2C_getReceiveBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the TX Buffer of the I2C for the DMA module.
//!
//! Returns the address of the I2C TX Buffer. This can be used in conjunction
//! with the DMA to obtain transmitted data directly from memory.
//!
//! \param baseAddress is the base address of the I2C module.
//!
//! \return the address of the TX Buffer
//
//*****************************************************************************
extern uint32_t USCI_B_I2C_getTransmitBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_USCI_B_I2C_H__

View File

@@ -0,0 +1,194 @@
//*****************************************************************************
//
// usci_b_spi.c - Driver for the usci_b_spi Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup usci_b_spi_api usci_b_spi
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Bx__
#include "usci_b_spi.h"
#include <assert.h>
bool USCI_B_SPI_initMaster(uint16_t baseAddress, USCI_B_SPI_initMasterParam *param)
{
//Disable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCSWRST;
//Reset OFS_UCBxCTL0 values
HWREG8(baseAddress + OFS_UCBxCTL0) &= ~(UCCKPH + UCCKPL + UC7BIT + UCMSB +
UCMST + UCMODE_3 + UCSYNC);
//Reset OFS_UCBxCTL1 values
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~(UCSSEL_3);
//Select Clock
HWREG8(baseAddress + OFS_UCBxCTL1) |= param->selectClockSource;
HWREG16(baseAddress + OFS_UCBxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
/*
* Configure as SPI master mode.
* Clock phase select, polarity, msb
* UCMST = Master mode
* UCSYNC = Synchronous mode
* UCMODE_0 = 3-pin SPI
*/
HWREG8(baseAddress + OFS_UCBxCTL0) |= (
param->msbFirst +
param->clockPhase +
param->clockPolarity +
UCMST +
UCSYNC +
UCMODE_0
);
return ( STATUS_SUCCESS) ;
}
void USCI_B_SPI_changeMasterClock(uint16_t baseAddress,
USCI_B_SPI_changeMasterClockParam *param)
{
//Disable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCSWRST;
HWREG8(baseAddress + OFS_UCBxBRW) =
(uint16_t)(param->clockSourceFrequency / param->desiredSpiClock);
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~(UCSWRST);
}
bool USCI_B_SPI_initSlave (uint16_t baseAddress,
uint8_t msbFirst,
uint8_t clockPhase,
uint8_t clockPolarity
)
{
//Disable USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCSWRST;
//Reset OFS_UCBxCTL0 register
HWREG8(baseAddress + OFS_UCBxCTL0) &= ~(UCMSB +
UC7BIT +
UCMST +
UCCKPL +
UCCKPH +
UCMODE_3
);
//Clock polarity, phase select, msbFirst, SYNC, Mode0
HWREG8(baseAddress + OFS_UCBxCTL0) |= ( clockPhase +
clockPolarity +
msbFirst +
UCSYNC +
UCMODE_0
);
return ( STATUS_SUCCESS) ;
}
void USCI_B_SPI_changeClockPhasePolarity (uint16_t baseAddress,
uint8_t clockPhase,
uint8_t clockPolarity
)
{
//Disable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCSWRST;
HWREG8(baseAddress + OFS_UCBxCTL0) &= ~(UCCKPH + UCCKPL);
HWREG8(baseAddress + OFS_UCBxCTL0) |= (
clockPhase +
clockPolarity
);
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~(UCSWRST);
}
void USCI_B_SPI_transmitData ( uint16_t baseAddress,
uint8_t transmitData
)
{
HWREG8(baseAddress + OFS_UCBxTXBUF) = transmitData;
}
uint8_t USCI_B_SPI_receiveData (uint16_t baseAddress)
{
return ( HWREG8(baseAddress + OFS_UCBxRXBUF)) ;
}
void USCI_B_SPI_enableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_UCBxIE) |= mask;
}
void USCI_B_SPI_disableInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_UCBxIE) &= ~mask;
}
uint8_t USCI_B_SPI_getInterruptStatus (uint16_t baseAddress,
uint8_t mask
)
{
return ( HWREG8(baseAddress + OFS_UCBxIFG) & mask );
}
void USCI_B_SPI_clearInterrupt (uint16_t baseAddress,
uint8_t mask
)
{
HWREG8(baseAddress + OFS_UCBxIFG) &= ~mask;
}
void USCI_B_SPI_enable (uint16_t baseAddress)
{
//Reset the UCSWRST bit to enable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~(UCSWRST);
}
void USCI_B_SPI_disable (uint16_t baseAddress)
{
//Set the UCSWRST bit to disable the USCI Module
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCSWRST;
}
uint32_t USCI_B_SPI_getReceiveBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxRXBUF );
}
uint32_t USCI_B_SPI_getTransmitBufferAddressForDMA (uint16_t baseAddress)
{
return ( baseAddress + OFS_UCBxTXBUF );
}
uint8_t USCI_B_SPI_isBusy (uint16_t baseAddress)
{
//Return the bus busy status.
return (HWREG8(baseAddress + OFS_UCBxSTAT) & UCBUSY);
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for usci_b_spi_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,437 @@
//*****************************************************************************
//
// usci_b_spi.h - Driver for the USCI_B_SPI Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_USCI_B_SPI_H__
#define __MSP430WARE_USCI_B_SPI_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_USCI_Bx__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include "inc/hw_memmap.h"
//*****************************************************************************
//
//! \brief Used in the USCI_B_SPI_initMaster() function as the param parameter.
//
//*****************************************************************************
typedef struct USCI_B_SPI_initMasterParam {
//! Selects Clock source.
//! \n Valid values are:
//! - \b USCI_B_SPI_CLOCKSOURCE_ACLK
//! - \b USCI_B_SPI_CLOCKSOURCE_SMCLK
uint8_t selectClockSource;
//! Is the frequency of the selected clock source
uint32_t clockSourceFrequency;
//! Is the desired clock rate for SPI communication
uint32_t desiredSpiClock;
//! Controls the direction of the receive and transmit shift register.
//! \n Valid values are:
//! - \b USCI_B_SPI_MSB_FIRST
//! - \b USCI_B_SPI_LSB_FIRST [Default]
uint8_t msbFirst;
//! Is clock phase select.
//! \n Valid values are:
//! - \b USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT [Default]
//! - \b USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
uint8_t clockPhase;
//! \n Valid values are:
//! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
uint8_t clockPolarity;
} USCI_B_SPI_initMasterParam;
//*****************************************************************************
//
//! \brief Used in the USCI_B_SPI_changeMasterClock() function as the param
//! parameter.
//
//*****************************************************************************
typedef struct USCI_B_SPI_changeMasterClockParam {
//! Is the frequency of the selected clock source
uint32_t clockSourceFrequency;
//! Is the desired clock rate for SPI communication
uint32_t desiredSpiClock;
} USCI_B_SPI_changeMasterClockParam;
//*****************************************************************************
//
// The following are values that can be passed to the clockPhase parameter for
// functions: USCI_B_SPI_initSlave(), and
// USCI_B_SPI_changeClockPhasePolarity(); the param parameter for functions:
// USCI_B_SPI_initMaster().
//
//*****************************************************************************
#define USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT 0x00
#define USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT UCCKPH
//*****************************************************************************
//
// The following are values that can be passed to the msbFirst parameter for
// functions: USCI_B_SPI_initSlave(); the param parameter for functions:
// USCI_B_SPI_initMaster().
//
//*****************************************************************************
#define USCI_B_SPI_MSB_FIRST UCMSB
#define USCI_B_SPI_LSB_FIRST 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_B_SPI_initMaster(); the clockPolarity parameter for
// functions: USCI_B_SPI_initSlave(), and
// USCI_B_SPI_changeClockPhasePolarity().
//
//*****************************************************************************
#define USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH UCCKPL
#define USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW 0x00
//*****************************************************************************
//
// The following are values that can be passed to the param parameter for
// functions: USCI_B_SPI_initMaster().
//
//*****************************************************************************
#define USCI_B_SPI_CLOCKSOURCE_ACLK UCSSEL__ACLK
#define USCI_B_SPI_CLOCKSOURCE_SMCLK UCSSEL__SMCLK
//*****************************************************************************
//
// The following are values that can be passed to the mask parameter for
// functions: USCI_B_SPI_enableInterrupt(), USCI_B_SPI_disableInterrupt(),
// USCI_B_SPI_getInterruptStatus(), and USCI_B_SPI_clearInterrupt() as well as
// returned by the USCI_B_SPI_getInterruptStatus() function.
//
//*****************************************************************************
#define USCI_B_SPI_TRANSMIT_INTERRUPT UCTXIE
#define USCI_B_SPI_RECEIVE_INTERRUPT UCRXIE
//*****************************************************************************
//
// The following are values that can be passed toThe following are values that
// can be returned by the USCI_B_SPI_isBusy() function.
//
//*****************************************************************************
#define USCI_B_SPI_BUSY UCBUSY
#define USCI_B_SPI_NOT_BUSY 0x00
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Initializes the SPI Master block.
//!
//! Upon successful initialization of the SPI master block, this function will
//! have set the bus speed for the master, but the SPI Master block still
//! remains disabled and must be enabled with USCI_B_SPI_enable()
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param param is the pointer to struct for master initialization.
//!
//! Modified bits are \b UCSSELx and \b UCSWRST of \b UCBxCTL1 register; bits
//! \b UCCKPH, \b UCCKPL, \b UC7BIT and \b UCMSB of \b UCBxCTL0 register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern bool USCI_B_SPI_initMaster(uint16_t baseAddress,
USCI_B_SPI_initMasterParam *param);
//*****************************************************************************
//
//! \brief Initializes the SPI Master clock.At the end of this function call,
//! SPI module is left enabled.
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param param is the pointer to struct for master clock setting.
//!
//! Modified bits of \b UCAxBRW register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_changeMasterClock(uint16_t baseAddress,
USCI_B_SPI_changeMasterClockParam *param);
//*****************************************************************************
//
//! \brief Initializes the SPI Slave block.
//!
//! Upon successful initialization of the SPI slave block, this function will
//! have initialized the slave block, but the SPI Slave block still remains
//! disabled and must be enabled with USCI_B_SPI_enable()
//!
//! \param baseAddress is the base address of the SPI Slave module.
//! \param msbFirst controls the direction of the receive and transmit shift
//! register.
//! Valid values are:
//! - \b USCI_B_SPI_MSB_FIRST
//! - \b USCI_B_SPI_LSB_FIRST [Default]
//! \param clockPhase is clock phase select.
//! Valid values are:
//! - \b USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
//! [Default]
//! - \b USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
//! \param clockPolarity
//! Valid values are:
//! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
//!
//! Modified bits are \b UCSWRST of \b UCBxCTL1 register; bits \b UCMSB, \b
//! UCMST, \b UC7BIT, \b UCCKPL, \b UCCKPH and \b UCMODE of \b UCBxCTL0
//! register.
//!
//! \return STATUS_SUCCESS
//
//*****************************************************************************
extern bool USCI_B_SPI_initSlave(uint16_t baseAddress,
uint8_t msbFirst,
uint8_t clockPhase,
uint8_t clockPolarity);
//*****************************************************************************
//
//! \brief Changes the SPI clock phase and polarity.At the end of this function
//! call, SPI module is left enabled.
//!
//! \param baseAddress is the base address of the I2C Master module.
//! \param clockPhase is clock phase select.
//! Valid values are:
//! - \b USCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
//! [Default]
//! - \b USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT
//! \param clockPolarity
//! Valid values are:
//! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH
//! - \b USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW [Default]
//!
//! Modified bits are \b UCCKPL and \b UCCKPH of \b UCAxCTL0 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_changeClockPhasePolarity(uint16_t baseAddress,
uint8_t clockPhase,
uint8_t clockPolarity);
//*****************************************************************************
//
//! \brief Transmits a byte from the SPI Module.
//!
//! This function will place the supplied data into SPI transmit data register
//! to start transmission
//!
//! \param baseAddress is the base address of the SPI module.
//! \param transmitData data to be transmitted from the SPI module
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_transmitData(uint16_t baseAddress,
uint8_t transmitData);
//*****************************************************************************
//
//! \brief Receives a byte that has been sent to the SPI Module.
//!
//! This function reads a byte of data from the SPI receive data Register.
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return Returns the byte received from by the SPI module, cast as an
//! uint8_t.
//
//*****************************************************************************
extern uint8_t USCI_B_SPI_receiveData(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Enables individual SPI interrupt sources.
//!
//! Enables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor. <b>Does not clear interrupt flags.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the bit mask of the interrupt sources to be enabled.
//! Valid values are:
//! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_B_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCBxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_enableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Disables individual SPI interrupt sources.
//!
//! Disables the indicated SPI interrupt sources. Only the sources that are
//! enabled can be reflected to the processor interrupt; disabled sources have
//! no effect on the processor.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the bit mask of the interrupt sources to be disabled.
//! Valid values are:
//! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_B_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCBxIE register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_disableInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Gets the current SPI interrupt status.
//!
//! This returns the interrupt status for the SPI module based on which flag is
//! passed.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the masked interrupt flag status to be returned.
//! Valid values are:
//! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_B_SPI_RECEIVE_INTERRUPT
//!
//! \return The current interrupt status as the mask of the set flags
//! Return Logical OR of any of the following:
//! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_B_SPI_RECEIVE_INTERRUPT
//! \n indicating the status of the masked interrupts
//
//*****************************************************************************
extern uint8_t USCI_B_SPI_getInterruptStatus(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Clears the selected SPI interrupt status flag.
//!
//! \param baseAddress is the base address of the SPI module.
//! \param mask is the masked interrupt flag to be cleared.
//! Valid values are:
//! - \b USCI_B_SPI_TRANSMIT_INTERRUPT
//! - \b USCI_B_SPI_RECEIVE_INTERRUPT
//!
//! Modified bits of \b UCBxIFG register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_clearInterrupt(uint16_t baseAddress,
uint8_t mask);
//*****************************************************************************
//
//! \brief Enables the SPI block.
//!
//! This will enable operation of the SPI block.
//!
//! \param baseAddress is the base address of the USCI SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_enable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Disables the SPI block.
//!
//! This will disable operation of the SPI block.
//!
//! \param baseAddress is the base address of the USCI SPI module.
//!
//! Modified bits are \b UCSWRST of \b UCBxCTL1 register.
//!
//! \return None
//
//*****************************************************************************
extern void USCI_B_SPI_disable(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the RX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI RX Buffer. This can be used in conjunction
//! with the DMA to store the received data directly to memory.
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return The address of the SPI RX buffer
//
//*****************************************************************************
extern uint32_t USCI_B_SPI_getReceiveBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Returns the address of the TX Buffer of the SPI for the DMA module.
//!
//! Returns the address of the SPI TX Buffer. This can be used in conjunction
//! with the DMA to obtain transmitted data directly from memory.
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return The address of the SPI TX buffer
//
//*****************************************************************************
extern uint32_t USCI_B_SPI_getTransmitBufferAddressForDMA(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Indicates whether or not the SPI bus is busy.
//!
//! This function returns an indication of whether or not the SPI bus is
//! busy.This function checks the status of the bus via UCBBUSY bit
//!
//! \param baseAddress is the base address of the SPI module.
//!
//! \return USCI_B_SPI_BUSY if the SPI module transmitting or receiving is
//! busy; otherwise, returns USCI_B_SPI_NOT_BUSY.
//! Return one of the following:
//! - \b USCI_B_SPI_BUSY
//! - \b USCI_B_SPI_NOT_BUSY
//! \n indicating if the USCI_B_SPI is busy
//
//*****************************************************************************
extern uint8_t USCI_B_SPI_isBusy(uint16_t baseAddress);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_USCI_B_SPI_H__

View File

@@ -0,0 +1,71 @@
//*****************************************************************************
//
// wdt_a.c - Driver for the wdt_a Module.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup wdt_a_api wdt_a
//! @{
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_WDT_A__
#include "wdt_a.h"
#include <assert.h>
void WDT_A_hold (uint16_t baseAddress)
{
// Set Hold bit
uint8_t newWDTStatus =
((HWREG16(baseAddress + OFS_WDTCTL) & 0x00FF) | WDTHOLD);
HWREG16(baseAddress + OFS_WDTCTL) = WDTPW + newWDTStatus;
}
void WDT_A_start (uint16_t baseAddress)
{
// Reset Hold bit
uint8_t newWDTStatus =
((HWREG16(baseAddress + OFS_WDTCTL) & 0x00FF) & ~(WDTHOLD));
HWREG16(baseAddress + OFS_WDTCTL) = WDTPW + newWDTStatus;
}
void WDT_A_resetTimer (uint16_t baseAddress)
{
// Set Counter Clear bit
uint8_t newWDTStatus =
((HWREG16(baseAddress + OFS_WDTCTL) & 0x00FF) | WDTCNTCL);
HWREG16(baseAddress + OFS_WDTCTL) = WDTPW + newWDTStatus;
}
void WDT_A_initWatchdogTimer (uint16_t baseAddress,
uint8_t clockSelect,
uint8_t clockDivider)
{
HWREG16(baseAddress + OFS_WDTCTL) =
WDTPW + WDTCNTCL + WDTHOLD + clockSelect + clockDivider;
}
void WDT_A_initIntervalTimer (uint16_t baseAddress,
uint8_t clockSelect,
uint8_t clockDivider)
{
HWREG16(baseAddress + OFS_WDTCTL) =
WDTPW + WDTCNTCL + WDTHOLD + WDTTMSEL + clockSelect + clockDivider;
}
#endif
//*****************************************************************************
//
//! Close the doxygen group for wdt_a_api
//! @}
//
//*****************************************************************************

View File

@@ -0,0 +1,179 @@
//*****************************************************************************
//
// wdt_a.h - Driver for the WDT_A Module.
//
//*****************************************************************************
#ifndef __MSP430WARE_WDT_A_H__
#define __MSP430WARE_WDT_A_H__
#include "inc/hw_memmap.h"
#ifdef __MSP430_HAS_WDT_A__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// The following are values that can be passed to the clockSelect parameter for
// functions: WDT_A_initWatchdogTimer(), and WDT_A_initIntervalTimer().
//
//*****************************************************************************
#define WDT_A_CLOCKSOURCE_SMCLK (WDTSSEL_0)
#define WDT_A_CLOCKSOURCE_ACLK (WDTSSEL_1)
#define WDT_A_CLOCKSOURCE_VLOCLK (WDTSSEL_2)
#define WDT_A_CLOCKSOURCE_XCLK (WDTSSEL_3)
//*****************************************************************************
//
// The following are values that can be passed to the clockDivider parameter
// for functions: WDT_A_initWatchdogTimer(), and WDT_A_initIntervalTimer().
//
//*****************************************************************************
#define WDT_A_CLOCKDIVIDER_2G (WDTIS_0)
#define WDT_A_CLOCKDIVIDER_128M (WDTIS_1)
#define WDT_A_CLOCKDIVIDER_8192K (WDTIS_2)
#define WDT_A_CLOCKDIVIDER_512K (WDTIS_3)
#define WDT_A_CLOCKDIVIDER_32K (WDTIS_4)
#define WDT_A_CLOCKDIVIDER_8192 (WDTIS_5)
#define WDT_A_CLOCKDIVIDER_512 (WDTIS_6)
#define WDT_A_CLOCKDIVIDER_64 (WDTIS_7)
//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Holds the Watchdog Timer.
//!
//! This function stops the watchdog timer from running, that way no interrupt
//! or PUC is asserted.
//!
//! \param baseAddress is the base address of the WDT_A module.
//!
//! \return None
//
//*****************************************************************************
extern void WDT_A_hold(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Starts the Watchdog Timer.
//!
//! This function starts the watchdog timer functionality to start counting
//! again.
//!
//! \param baseAddress is the base address of the WDT_A module.
//!
//! \return None
//
//*****************************************************************************
extern void WDT_A_start(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Resets the timer counter of the Watchdog Timer.
//!
//! This function resets the watchdog timer to 0x0000h.
//!
//! \param baseAddress is the base address of the WDT_A module.
//!
//! \return None
//
//*****************************************************************************
extern void WDT_A_resetTimer(uint16_t baseAddress);
//*****************************************************************************
//
//! \brief Sets the clock source for the Watchdog Timer in watchdog mode.
//!
//! This function sets the watchdog timer in watchdog mode, which will cause a
//! PUC when the timer overflows. When in the mode, a PUC can be avoided with a
//! call to WDT_A_resetTimer() before the timer runs out.
//!
//! \param baseAddress is the base address of the WDT_A module.
//! \param clockSelect is the clock source that the watchdog timer will use.
//! Valid values are:
//! - \b WDT_A_CLOCKSOURCE_SMCLK [Default]
//! - \b WDT_A_CLOCKSOURCE_ACLK
//! - \b WDT_A_CLOCKSOURCE_VLOCLK
//! - \b WDT_A_CLOCKSOURCE_XCLK
//! \n Modified bits are \b WDTSSEL of \b WDTCTL register.
//! \param clockDivider is the divider of the clock source, in turn setting the
//! watchdog timer interval.
//! Valid values are:
//! - \b WDT_A_CLOCKDIVIDER_2G
//! - \b WDT_A_CLOCKDIVIDER_128M
//! - \b WDT_A_CLOCKDIVIDER_8192K
//! - \b WDT_A_CLOCKDIVIDER_512K
//! - \b WDT_A_CLOCKDIVIDER_32K [Default]
//! - \b WDT_A_CLOCKDIVIDER_8192
//! - \b WDT_A_CLOCKDIVIDER_512
//! - \b WDT_A_CLOCKDIVIDER_64
//! \n Modified bits are \b WDTIS and \b WDTHOLD of \b WDTCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void WDT_A_initWatchdogTimer(uint16_t baseAddress,
uint8_t clockSelect,
uint8_t clockDivider);
//*****************************************************************************
//
//! \brief Sets the clock source for the Watchdog Timer in timer interval mode.
//!
//! This function sets the watchdog timer as timer interval mode, which will
//! assert an interrupt without causing a PUC.
//!
//! \param baseAddress is the base address of the WDT_A module.
//! \param clockSelect is the clock source that the watchdog timer will use.
//! Valid values are:
//! - \b WDT_A_CLOCKSOURCE_SMCLK [Default]
//! - \b WDT_A_CLOCKSOURCE_ACLK
//! - \b WDT_A_CLOCKSOURCE_VLOCLK
//! - \b WDT_A_CLOCKSOURCE_XCLK
//! \n Modified bits are \b WDTSSEL of \b WDTCTL register.
//! \param clockDivider is the divider of the clock source, in turn setting the
//! watchdog timer interval.
//! Valid values are:
//! - \b WDT_A_CLOCKDIVIDER_2G
//! - \b WDT_A_CLOCKDIVIDER_128M
//! - \b WDT_A_CLOCKDIVIDER_8192K
//! - \b WDT_A_CLOCKDIVIDER_512K
//! - \b WDT_A_CLOCKDIVIDER_32K [Default]
//! - \b WDT_A_CLOCKDIVIDER_8192
//! - \b WDT_A_CLOCKDIVIDER_512
//! - \b WDT_A_CLOCKDIVIDER_64
//! \n Modified bits are \b WDTIS and \b WDTHOLD of \b WDTCTL register.
//!
//! \return None
//
//*****************************************************************************
extern void WDT_A_initIntervalTimer(uint16_t baseAddress,
uint8_t clockSelect,
uint8_t clockDivider);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif
#endif // __MSP430WARE_WDT_A_H__