Sfoglia il codice sorgente

Repository angelegt.

Rind 5 anni fa
commit
227b493a8b
39 ha cambiato i file con 4107 aggiunte e 0 eliminazioni
  1. 15 0
      DemoSlave/.ccsproject
  2. 182 0
      DemoSlave/.cproject
  3. 14 0
      DemoSlave/.gitignore
  4. 14 0
      DemoSlave/.launches/DemoSlave.launch
  5. 27 0
      DemoSlave/.project
  6. 3 0
      DemoSlave/.settings/org.eclipse.cdt.codan.core.prefs
  7. 2 0
      DemoSlave/.settings/org.eclipse.cdt.debug.core.prefs
  8. 6 0
      DemoSlave/.settings/org.eclipse.core.resources.prefs
  9. 213 0
      DemoSlave/eav1v.h
  10. 60 0
      DemoSlave/main.c
  11. 164 0
      DemoSlave/mbslvapp.c
  12. 37 0
      DemoSlave/mbslvapp.h
  13. 213 0
      DemoSlave/ols1v.h
  14. 45 0
      DemoSlave/tm4c1231e6pz.cmd
  15. 300 0
      DemoSlave/tm4c1231e6pz_startup_ccs.c
  16. 14 0
      gfamodbusrtucom/.ccsproject
  17. 143 0
      gfamodbusrtucom/.cproject
  18. 14 0
      gfamodbusrtucom/.gitignore
  19. 28 0
      gfamodbusrtucom/.project
  20. 3 0
      gfamodbusrtucom/.settings/org.eclipse.cdt.codan.core.prefs
  21. 2 0
      gfamodbusrtucom/.settings/org.eclipse.cdt.debug.core.prefs
  22. 7 0
      gfamodbusrtucom/.settings/org.eclipse.core.resources.prefs
  23. 175 0
      gfamodbusrtucom/buffer.c
  24. 32 0
      gfamodbusrtucom/distribute.cmd
  25. 483 0
      gfamodbusrtucom/fifo.c
  26. 294 0
      gfamodbusrtucom/gfambrtucom.h
  27. 478 0
      gfamodbusrtucom/mbuart.c
  28. 14 0
      gfamodbusrtuslv/.ccsproject
  29. 136 0
      gfamodbusrtuslv/.cproject
  30. 14 0
      gfamodbusrtuslv/.gitignore
  31. 27 0
      gfamodbusrtuslv/.project
  32. 3 0
      gfamodbusrtuslv/.settings/org.eclipse.cdt.codan.core.prefs
  33. 2 0
      gfamodbusrtuslv/.settings/org.eclipse.cdt.debug.core.prefs
  34. 6 0
      gfamodbusrtuslv/.settings/org.eclipse.core.resources.prefs
  35. 36 0
      gfamodbusrtuslv/defines.h
  36. 32 0
      gfamodbusrtuslv/distribute.cmd
  37. 163 0
      gfamodbusrtuslv/gfambrtuslv.h
  38. 394 0
      gfamodbusrtuslv/mbreq.c
  39. 312 0
      gfamodbusrtuslv/mbrtuslv.c

+ 15 - 0
DemoSlave/.ccsproject

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<?ccsproject version="1.0"?>
+<projectOptions>
+	<ccsVersion value="8.3.0"/>
+	<deviceVariant value="Cortex M.TM4C1231E6PZ"/>
+	<deviceFamily value="TMS470"/>
+	<deviceEndianness value="little"/>
+	<codegenToolVersion value="18.1.6.LTS"/>
+	<isElfFormat value="true"/>
+	<linkerCommandFile value="tm4c1231e6pz.cmd"/>
+	<rts value="libc.a"/>
+	<createSlaveProjects value=""/>
+	<templateProperties value="id=com.ti.common.project.core.emptyProjectWithMainTemplate"/>
+	<filesToOpen value="main.c"/>
+</projectOptions>

+ 182 - 0
DemoSlave/.cproject

@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+	<storageModule configRelations="2" moduleId="org.eclipse.cdt.core.settings">
+		<cconfiguration id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1546360525">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1546360525" moduleId="org.eclipse.cdt.core.settings" name="Debug">
+				<macros>
+					<stringMacro name="TW_ROOT" type="VALUE_TEXT" value="C:\CCS\TivaWare_C_Series-2.1.4.178"/>
+				</macros>
+				<externalSettings/>
+				<extensions>
+					<extension id="com.ti.ccstudio.binaryparser.CoffParser" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.CoffErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.AsmErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.LinkErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactExtension="out" artifactName="${ProjName}" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1546360525" name="Debug" parent="com.ti.ccstudio.buildDefinitions.TMS470.Debug">
+					<folderInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1546360525." name="/" resourcePath="">
+						<toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.DebugToolchain.1208027939" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.DebugToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerDebug.1030918387">
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.1379166674" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
+								<listOptionValue builtIn="false" value="DEVICE_CONFIGURATION_ID=Cortex M.TM4C1231E6PZ"/>
+								<listOptionValue builtIn="false" value="DEVICE_ENDIANNESS=little"/>
+								<listOptionValue builtIn="false" value="OUTPUT_FORMAT=ELF"/>
+								<listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/>
+								<listOptionValue builtIn="false" value="LINKER_COMMAND_FILE=tm4c1231e6pz.cmd"/>
+								<listOptionValue builtIn="false" value="RUNTIME_SUPPORT_LIBRARY=libc.a"/>
+								<listOptionValue builtIn="false" value="OUTPUT_TYPE=executable"/>
+							</option>
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.1581287893" name="Compiler version" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.6.LTS" valueType="string"/>
+							<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.targetPlatformDebug.1564638287" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.targetPlatformDebug"/>
+							<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderDebug.1745139177" keepEnvironmentInBuildfile="false" name="GNU Make" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderDebug"/>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.compilerDebug.1371267134" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.compilerDebug">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.1816690551" name="Target processor version (--silicon_version, -mv)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M4" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.1430355923" name="Designate code state, 16-bit (thumb) or 32-bit (--code_state)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.1571085814" name="Application binary interface. (--abi)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.2028106960" name="Specify floating point support (--float_support)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.FPv4SPD16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.789351869" name="Enable support for GCC extensions (DEPRECATED) (--gcc)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.1557894508" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
+									<listOptionValue builtIn="false" value="ccs=&quot;ccs&quot;"/>
+									<listOptionValue builtIn="false" value="PART_TM4C1231E6PZ"/>
+									<listOptionValue builtIn="false" value="__TI_TIME_USES_64=1"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.985929533" name="Debugging model" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.SYMDEBUG__DWARF" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.1412777174" name="Treat diagnostic &lt;id&gt; as warning (--diag_warning, -pdsw)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
+									<listOptionValue builtIn="false" value="225"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.1891018026" name="Emit diagnostic identifier numbers (--display_error_number, -pden)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.884486624" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.137379891" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
+									<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+									<listOptionValue builtIn="false" value="${TW_ROOT}"/>
+									<listOptionValue builtIn="false" value="${GfATivaLibsRoot}\include"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.1395856809" name="Little endian code [See 'General' page to edit] (--little_endian, -me)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS.1692012442" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS.790517919" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS.1780199930" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS.406222324" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerDebug.1030918387" name="ARM Linker" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerDebug">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE.2045068222" name="Link information (map) listed into &lt;file&gt; (--map_file, -m)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE" useByScannerDiscovery="false" value="${ProjName}.map" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE.1889016264" name="Set C system stack size (--stack_size, -stack)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE" useByScannerDiscovery="false" value="512" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE.186385383" name="Heap size for C/C++ dynamic memory allocation (--heap_size, -heap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE" useByScannerDiscovery="false" value="0" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE.1272923142" name="Specify output file name (--output_file, -o)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE" useByScannerDiscovery="false" value="${ProjName}.out" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO.1381837185" name="Detailed link information data-base into &lt;file&gt; (--xml_link_info, -xml_link_info)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO" useByScannerDiscovery="false" value="${ProjName}_linkInfo.xml" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER.1537510343" name="Emit diagnostic identifier numbers (--display_error_number)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.462551080" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH.972879845" name="Add &lt;dir&gt; to library search path (--search_path, -i)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH" valueType="libPaths">
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/lib"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+									<listOptionValue builtIn="false" value="${TW_ROOT}\driverlib\ccs\Debug"/>
+									<listOptionValue builtIn="false" value="${GfATivaLibsRoot}\gfautils.1.0\lib\ccs\Debug"/>
+									<listOptionValue builtIn="false" value="${GfATivaLibsRoot}\gfambrtucom.1.0\lib\ccs\Debug"/>
+									<listOptionValue builtIn="false" value="${GfATivaLibsRoot}\gfambrtuslv.1.0\lib\ccs\Debug"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY.1824240122" name="Include library file or command file as input (--library, -l)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY" useByScannerDiscovery="false" valueType="libs">
+									<listOptionValue builtIn="false" value="gfautils.lib"/>
+									<listOptionValue builtIn="false" value="gfambrtucom.lib"/>
+									<listOptionValue builtIn="false" value="gfambrtuslv.lib"/>
+									<listOptionValue builtIn="false" value="driverlib.lib"/>
+									<listOptionValue builtIn="false" value="libc.a"/>
+								</option>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD_SRCS.523368235" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD2_SRCS.1994087219" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD2_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__GEN_CMDS.1163468241" name="Generated Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__GEN_CMDS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.1558575738" name="ARM Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex"/>
+						</toolChain>
+					</folderInfo>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+		<cconfiguration id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1265851161">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1265851161" moduleId="org.eclipse.cdt.core.settings" name="Release">
+				<externalSettings/>
+				<extensions>
+					<extension id="com.ti.ccstudio.binaryparser.CoffParser" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.CoffErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.AsmErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.LinkErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactExtension="out" artifactName="${ProjName}" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1265851161" name="Release" parent="com.ti.ccstudio.buildDefinitions.TMS470.Release">
+					<folderInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1265851161." name="/" resourcePath="">
+						<toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.ReleaseToolchain.2019898707" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.ReleaseToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerRelease.980915238">
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.1684295648" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
+								<listOptionValue builtIn="false" value="DEVICE_CONFIGURATION_ID=Cortex M.TM4C1231E6PZ"/>
+								<listOptionValue builtIn="false" value="DEVICE_ENDIANNESS=little"/>
+								<listOptionValue builtIn="false" value="OUTPUT_FORMAT=ELF"/>
+								<listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/>
+								<listOptionValue builtIn="false" value="LINKER_COMMAND_FILE=tm4c1231e6pz.cmd"/>
+								<listOptionValue builtIn="false" value="RUNTIME_SUPPORT_LIBRARY=libc.a"/>
+								<listOptionValue builtIn="false" value="OUTPUT_TYPE=executable"/>
+							</option>
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.176023259" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.6.LTS" valueType="string"/>
+							<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.targetPlatformRelease.1646315847" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.targetPlatformRelease"/>
+							<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderRelease.396369174" name="GNU Make.Release" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderRelease"/>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.compilerRelease.699467272" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.compilerRelease">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.38871720" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M4" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.1366158911" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.2102761705" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.1187931951" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.FPv4SPD16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.1301542184" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.603449445" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
+									<listOptionValue builtIn="false" value="ccs=&quot;ccs&quot;"/>
+									<listOptionValue builtIn="false" value="PART_TM4C1231E6PZ"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.776383380" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
+									<listOptionValue builtIn="false" value="225"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.571373090" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.777637402" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.1563604395" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
+									<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.561117630" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS.1189693056" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS.943164838" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS.202330547" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS.105538938" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerRelease.980915238" name="ARM Linker" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerRelease">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE.138680687" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE" useByScannerDiscovery="false" value="${ProjName}.map" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE.85932142" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE" useByScannerDiscovery="false" value="512" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE.1094413452" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE" useByScannerDiscovery="false" value="0" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE.897514933" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE" useByScannerDiscovery="false" value="${ProjName}.out" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO.1803961784" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO" useByScannerDiscovery="false" value="${ProjName}_linkInfo.xml" valueType="string"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER.2130128817" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.871986850" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH.874248052" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH" valueType="libPaths">
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/lib"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY.1531074580" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY" useByScannerDiscovery="false" valueType="libs">
+									<listOptionValue builtIn="false" value="libc.a"/>
+								</option>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD_SRCS.519500247" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD2_SRCS.986891227" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD2_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__GEN_CMDS.233184503" name="Generated Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__GEN_CMDS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.2060620058" name="ARM Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex"/>
+						</toolChain>
+					</folderInfo>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+		<project id="DemoSlave.com.ti.ccstudio.buildDefinitions.TMS470.ProjectType.71323369" name="TMS470" projectType="com.ti.ccstudio.buildDefinitions.TMS470.ProjectType"/>
+	</storageModule>
+	<storageModule moduleId="scannerConfiguration"/>
+	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
+</cproject>

+ 14 - 0
DemoSlave/.gitignore

@@ -0,0 +1,14 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
+
+rtf/
+latex/
+html/
+*.bak
+*.tmp
+/Debug/
+/Release/

File diff suppressed because it is too large
+ 14 - 0
DemoSlave/.launches/DemoSlave.launch


+ 27 - 0
DemoSlave/.project

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>DemoSlave</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+			<triggers>full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.ti.ccstudio.core.ccsNature</nature>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+	</natures>
+</projectDescription>

+ 3 - 0
DemoSlave/.settings/org.eclipse.cdt.codan.core.prefs

@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+inEditor=false
+onBuild=false

+ 2 - 0
DemoSlave/.settings/org.eclipse.cdt.debug.core.prefs

@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker

+ 6 - 0
DemoSlave/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+encoding//Debug/makefile=UTF-8
+encoding//Debug/objects.mk=UTF-8
+encoding//Debug/sources.mk=UTF-8
+encoding//Debug/subdir_rules.mk=UTF-8
+encoding//Debug/subdir_vars.mk=UTF-8

+ 213 - 0
DemoSlave/eav1v.h

@@ -0,0 +1,213 @@
+// eav1v.h :
+//
+
+#if !defined(AGD_PINS_H__9F94DC4E_A195_4754_9727_7DAF2FFB0DE2__INCLUDED_)
+#define AGD_PINS_H__9F94DC4E_A195_4754_9727_7DAF2FFB0DE2__INCLUDED_
+
+#ifdef __cplusplus
+extern "C" {
+#endif	//	__cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// pins.h - Declarations:
+
+//
+// GPIO PORTA is used for
+//
+#define PA0__RX_UART0		GPIO_PIN_0		// PA0	RX_UART0		(UART input)
+#define PA1__TX_UART0		GPIO_PIN_1		// PA1	TX_UART0		(UART output)
+#define PA2__LED3			GPIO_PIN_2		// PA2	LED3			(digital output)
+#define PA3__LED4			GPIO_PIN_3		// PA3	LED4			(digital output)
+#define PA4__LED5			GPIO_PIN_4		// PA4	LED5			(digital output)
+#define PA5__LED6			GPIO_PIN_5		// PA5	LED6			(digital output)
+#define PA6__5V_UART0		GPIO_PIN_6		// PA6	5V_UART0		(digital input)
+#define PA7__				GPIO_PIN_7		// PA7					(unused)
+
+//
+// GPIO PORTB is used for
+//
+#define PB0__RX_485_1		GPIO_PIN_0		// PB0	RX_485_1		(UART input)
+#define PB1__TX_485_1		GPIO_PIN_1		// PB1	TX_485_1		(UART output)
+#define PB2__I2C_WIFI_SCL	GPIO_PIN_2		// PB2	I2C_WIFI_SCL	(I2C interface)
+#define PB3__I2C_WIFI_SDA	GPIO_PIN_3		// PB3	I2C_WIFI_SDA	(I2C interface)
+#define PB4__DIGOUT1		GPIO_PIN_4		// PB4	DIGOUT1			(digital output)
+#define PB5__DIGOUT2		GPIO_PIN_5		// PB5	DIGOUT2			(digital output)
+
+#define PB0__LS_ON_ZI3		GPIO_PIN_0		// PB0	LS_ON_ZI3		(digital output)
+#define PB1__LS_ON_ZI2		GPIO_PIN_1		// PB1	LS_ON_ZI2		(digital output)
+#define PB2__Z_IN1_SCL3		GPIO_PIN_2		// PB2	Z_IN1_SCL3		(TIMER input, I2C interface)
+#define PB3__AN_CLK_SDA3	GPIO_PIN_3		// PB3	AN_CLK_SDA3		(TIMER input, I2C interface)
+#define PB4__ANIN1			GPIO_PIN_4		// PB4	ANIN1			(analog input)
+#define PB5__U_24V_IO		GPIO_PIN_5		// PB5	U_24V_IO		(analog input)
+
+//
+// GPIO PORTC is used for
+//
+#define PC0__				GPIO_PIN_0		// PC0					(JTAG TCK)
+#define PC1__				GPIO_PIN_1		// PC1					(JTAG TMS)
+#define PC2__				GPIO_PIN_2		// PC2					(JTAG TDI)
+#define PC3__				GPIO_PIN_3		// PC3					(JTAG TDO)
+#define PC4__				GPIO_PIN_4		// PC4					(unused)
+#define PC5__TASTE			GPIO_PIN_5		// PC5	TASTE			(digital input)
+#define PC6__VREF_ZIN_H		GPIO_PIN_6		// PC6	VREF_ZIN_H		(analog comparator reference)
+#define PC7__ZIN1			GPIO_PIN_7		// PC7	ZIN1			(analog comparator input)
+
+#define PC0__				GPIO_PIN_0		// PC0					(JTAG TCK)
+#define PC1__				GPIO_PIN_1		// PC1					(JTAG TMS)
+#define PC2__				GPIO_PIN_2		// PC2					(JTAG TDI)
+#define PC3__				GPIO_PIN_3		// PC3					(JTAG TDO)
+#define PC4__Z_IN2			GPIO_PIN_4		// PC4	Z_IN2			(analog comparator input)
+#define PC5__LED_BUS		GPIO_PIN_5		// PC5	LED_BUS			(digital output)
+#define PC6__VREF_ZIN_H		GPIO_PIN_6		// PC6	VREF_ZIN_H		(analog comparator reference)
+#define PC7__Z_IN3			GPIO_PIN_7		// PC7	Z_IN3			(analog comparator input)
+
+//
+// GPIO PORTD is used for
+//
+#define PD0__ANIN_OUT1		GPIO_PIN_0		// PD0	ANIN_OUT1		(analog input)
+#define PD1__ANIN4			GPIO_PIN_1		// PD1	ANIN4			(analog input)
+#define PD2__ANIN3			GPIO_PIN_2		// PD2	ANIN3			(analog input)
+#define PD3__ANIN0			GPIO_PIN_3		// PD3	ANIN0			(analog input)
+#define PD4__MP				GPIO_PIN_4		// PD4	MP				(UART input)
+#define PD5__MP				GPIO_PIN_5		// PD4	MP				(UART output)
+#define PD6__ACT_POS		GPIO_PIN_6		// PD4	ACT_POS			(analog input)
+#define PD7__RESTARTB		GPIO_PIN_7		// PD4	RESTARTB		(digital input)
+
+#define PD0__ANIN_OUT1		GPIO_PIN_0		// PD0	ANIN_OUT1		(analog input)
+#define PD1__ANIN_OUT2		GPIO_PIN_1		// PD1	ANIN_OUT2		(analog input)
+#define PD2__ANIN_OUT3		GPIO_PIN_2		// PD2	ANIN_OUT3		(analog input)
+#define PD3__ANIN_OUT4		GPIO_PIN_3		// PD3	ANIN_OUT4		(analog input)
+#define PD4__ANIN4			GPIO_PIN_4		// PD4	ANIN4			(analog input)
+#define PD5__ANIN5			GPIO_PIN_5		// PD4	ANIN5			(analog input)
+#define PD6__ANIN6			GPIO_PIN_6		// PD4	ANIN6			(analog input)
+#define PD7__ANIN0			GPIO_PIN_7		// PD4	ANIN0			(analog input)
+
+//
+// GPIO PORTE is used for
+//
+#define PE0__RX_WIFI2		GPIO_PIN_0		// PE0	RX_WIFI2		(UART input)
+#define PE1__TX_WIFI2		GPIO_PIN_1		// PE1	TX_WIFI2		(UART output)
+#define PE2__LS_ON_ZI1		GPIO_PIN_2		// PE2	LS_ON_ZI1		(digital output)
+#define PE3__				GPIO_PIN_3		// PE3					(unused)
+#define PE4__RX_485_2		GPIO_PIN_4		// PE4	RX_485_2		(UART input)
+#define PE5__TX_485_2		GPIO_PIN_5		// PE5	TX_485_2		(UART output)
+#define PE6__EN_485_2		GPIO_PIN_6		// PE6	EN_485_2		(digital output)
+#define PE7__EN_485_1		GPIO_PIN_7		// PE6	EN_485_1		(digital output)
+
+#define PE0__RX_485_1		GPIO_PIN_0		// PE0	RX_485_1		(UART input)
+#define PE1__TX_485_1		GPIO_PIN_1		// PE1	TX_485_1		(UART output)
+#define PE2__LED_ERR		GPIO_PIN_2		// PE2	LED_ERR			(digital output)
+#define PE3__Z_IN4			GPIO_PIN_3		// PE3	Z_IN4			(analog input)
+#define PE4__ANIN2			GPIO_PIN_4		// PE4	ANIN2			(analog input)
+#define PE5__ANIN3			GPIO_PIN_5		// PE5	ANIN3			(analog input)
+#define PE6__U_VERS			GPIO_PIN_6		// PE6	U_VERS			(analog input)
+#define PE7__U_V15V			GPIO_PIN_7		// PE6	U_V15V			(analog input)
+
+//
+// GPIO PORTF is used for
+//
+#define PF0__ANZ1_A			GPIO_PIN_0		// PF0	ANZ1_A			(digital output)
+#define PF1__ANZ1_B			GPIO_PIN_1		// PF1	ANZ1_B			(digital output)
+#define PF2__ANZ1_C			GPIO_PIN_2		// PF2	ANZ1_C			(digital output)
+#define PF3__ANZ1_D			GPIO_PIN_3		// PF3	ANZ1_D			(digital output)
+#define PF4__ANZ1_E			GPIO_PIN_4		// PF4	ANZ1_E			(digital output)
+#define PF5__ANZ1_F			GPIO_PIN_5		// PF5	ANZ1_F			(digital output)
+#define PF6__ANZ1_G			GPIO_PIN_6		// PF6	ANZ1_G			(digital output)
+#define PF7__ANZ1_DP		GPIO_PIN_7		// PF7	ANZ1_DP			(digital output)
+
+#define PF0__nCS_REL		GPIO_PIN_0		// PF0	nCS_REL			(digital input)
+#define PF1__nCS_DA1		GPIO_PIN_1		// PF1	nCS_DA1			(digital input)
+#define PF2__nCS_DA2		GPIO_PIN_2		// PF2	nCS_DA2			(digital input)
+#define PF3__PWM_CPU		GPIO_PIN_3		// PF3	PWM_CPU			(digital input)
+#define PF4__100Hz			GPIO_PIN_4		// PF4	100Hz			(TIMER output)
+#define PF5__nRES_PER		GPIO_PIN_5		// PF5	nRES_PER		(digital input)
+#define PF6__LED_BETR		GPIO_PIN_6		// PF6	LED_BETR		(digital output)
+#define PF7__LS_ON_ZI4		GPIO_PIN_7		// PF7	LS_ON_ZI3		(digital output)
+
+//
+// GPIO PORTG is used for
+//
+#define PG0__ANZ2_A			GPIO_PIN_0		// PG0	ANZ1_A			(digital output)
+#define PG1__ANZ2_B			GPIO_PIN_1		// PG1	ANZ1_B			(digital output)
+#define PG2__ANZ2_C			GPIO_PIN_2		// PG2	ANZ1_C			(digital output)
+#define PG3__ANZ2_D			GPIO_PIN_3		// PG3	ANZ1_D			(digital output)
+#define PG4__ANZ2_E			GPIO_PIN_4		// PG4	ANZ1_E			(digital output)
+#define PG5__ANZ2_F			GPIO_PIN_5		// PG5	ANZ1_F			(digital output)
+#define PG6__ANZ2_G			GPIO_PIN_6		// PG6	ANZ1_G			(digital output)
+#define PG7__ANZ2_DP		GPIO_PIN_7		// PG7	ANZ1_DP			(digital output)
+
+#define PG0__REL1			GPIO_PIN_0		// PG0	REL1			(digital output)
+#define PG1__REL2			GPIO_PIN_1		// PG1	REL2			(digital output)
+#define PG2__REL3			GPIO_PIN_2		// PG2	REL3			(digital output)
+#define PG3__REL4			GPIO_PIN_3		// PG3	REL4			(digital output)
+#define PG4__PWM_TRIAC		GPIO_PIN_4		// PG4	PWM_TRIAC		(PWM output)
+#define PG5__LS_ON_ZI1		GPIO_PIN_5		// PG5	LS_ON_ZI1		(digital output)
+#define PG6__NULLDURCH		GPIO_PIN_6		// PG6  NULLDURCH		(TIMER input)
+#define PG7__Z_IN1			GPIO_PIN_7		// PG7	Z_IN1			(analog comparator input)
+
+//
+// GPIO PORTH is used for
+//
+#define PH0__ANIN2			GPIO_PIN_0		// PH0	ANIN2			(analog input)
+#define PH1__ANIN1			GPIO_PIN_1		// PH1	ANIN1			(analog input)
+#define PH2__U_DIG_OUT2		GPIO_PIN_2		// PH2	U_DIG_OUT2		(analog input)
+#define PH3__U_VERS			GPIO_PIN_3		// PH3	U_VERS			(analog input)
+#define PH4__ST_DO1			GPIO_PIN_4		// PH4	ST_DO1			(digital input)
+#define PH5__ST_DO2			GPIO_PIN_5		// PH5	ST_DO2			(digital input)
+#define PH6__				GPIO_PIN_6		// PH6					(unused)
+#define PH7__PWM_AN1		GPIO_PIN_7		// PH7	PWM_AN1			(PWM output)
+
+#define PH0__LED_IN1		GPIO_PIN_0		// PH0	LED_IN1			(digital output)
+#define PH1__LED_IN2		GPIO_PIN_1		// PH1	LED_IN2			(digital output)
+#define PH2__LED_IN3		GPIO_PIN_2		// PH2	LED_IN3			(digital output)
+#define PH3__LED_IN4		GPIO_PIN_3		// PH3	LED_IN4			(digital output)
+#define PH4__PWM4			GPIO_PIN_4		// PG4	PWM4			(PWM output)
+#define PH5__PWM3			GPIO_PIN_5		// PG5	PWM3			(PWM output)
+#define PH6__PWM2			GPIO_PIN_6		// PG6	PWM2			(PWM output)
+#define PH7__PWM1			GPIO_PIN_7		// PG7	PWM1			(PWM output)
+
+//
+// GPIO PORTJ is used for
+//
+#define PJ0__RX_WIFI1		GPIO_PIN_0		// PJ0	RX_WIFI1		(UART input)
+#define PJ1__TX_WIFI1		GPIO_PIN_1		// PJ1	TX_WIFI1		(UART output)
+#define PJ2__EN_WIFI		GPIO_PIN_2		// PJ2	EN_WIFI			(digital output)
+
+#define PJ0__EN_V15V		GPIO_PIN_0		// PJ0	EN_V15V			(digital output)
+#define PJ1__EN_V24V_IO		GPIO_PIN_1		// PJ1	EN_V24V_IO		(digital output)
+#define PJ2__EN_485_1		GPIO_PIN_2		// PJ2	EN_485_1		(digital output)
+
+//
+// GPIO PORTK is used for
+//
+#define PK0__SPI_WIFI_CLK	GPIO_PIN_0		// PK0	SPI_WIFI_CLK	(SPI output)
+#define PK1__SPI_WIFI_CS	GPIO_PIN_1		// PK1	SPI_WIFI_CS		(SPI output)
+#define PK2__SPI_WIFI_MISO	GPIO_PIN_2		// PK2	SPI_WIFI_MISO	(SPI input)
+#define PK3__SPI_WIFI_MOSI	GPIO_PIN_3		// PK3	SPI_WIFI_MOSI	(SPI output)
+
+#define PK0__AN_A0			GPIO_PIN_0		// PK0	AN_A0			(digital input)
+#define PK1__AN_A1			GPIO_PIN_1		// PK1	AN_A1			(digital input)
+#define PK2__AN_A2			GPIO_PIN_2		// PK2	AN_A2			(digital input)
+#define PK3__nAB_DA			GPIO_PIN_3		// PK3	nA/B_DA			(digital input)
+
+/////////////////////////////////////////////////////////////////////////////
+// UART / RS485 / Timer
+
+#define UART_PORT_SYSCTL	SYSCTL_PERIPH_GPIOE
+#define UART_PORT			GPIO_PORTE_BASE
+#define UART_BASE_SYSCTL	SYSCTL_PERIPH_UART5
+#define UART_BASE			UART5_BASE
+#define UART_INT			INT_UART5
+#define UART_RX_PIN			PE4__RX_485_1
+#define UART_TX_PIN			PE5__TX_485_1
+#define UART_RX_PIN_MUX     GPIO_PE4_U5RX
+#define UART_TX_PIN_MUX     GPIO_PE5_U5TX
+#define EN_485_PORT_SYSCTL	SYSCTL_PERIPH_GPIOJ
+#define EN_485_PORT			GPIO_PORTJ_BASE
+#define EN_485_PIN			PJ2__EN_485_1
+
+/////////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+}
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_PINS_H__9F94DC4E_A195_4754_9727_7DAF2FFB0DE2__INCLUDED_)

+ 60 - 0
DemoSlave/main.c

@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <gfambrtuslv.h>
+#include "mbslvapp.h"
+#include "inc/tm4c1231e6pz.h"
+#include "driverlib/sysctl.h"
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
+// fake implementation for demo purposes
+// usually the time will be retrieved from a realtime clock
+
+static int32_t _GetRTCTDateTimeTZ(struct tm *ptm)
+{
+	if(!ptm)
+		return -1;
+
+	memset(ptm, 0, sizeof(struct tm));
+
+	ptm->tm_year	= 119;
+	ptm->tm_mon		= 8;
+	ptm->tm_mday	= 17;
+	ptm->tm_hour	= 17;
+	ptm->tm_min		= 40;
+
+	return 2;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+int main(void)
+{
+	struct tm utc;
+	int32_t nTzIndex;
+
+	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
+    GfaUtilsInit();
+
+    if((nTzIndex = _GetRTCTDateTimeTZ(&utc)) < 0)
+    	return 1;
+
+	if(!GfaTimeSetUTCDateTimeTimezone(&utc, nTzIndex))
+    	return 1;
+
+	if(!GfaInitModbusSlaveApp())
+    	return 1;
+
+    while(true)
+    {
+    	GfaDoModbusSlaveApp();
+    }
+}

+ 164 - 0
DemoSlave/mbslvapp.c

@@ -0,0 +1,164 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <limits.h>
+#include <gfambrtuslv.h>
+#include <mbslvapp.h>
+#include "inc/hw_memmap.h"
+#include "inc/hw_gpio.h"
+#include "inc/hw_uart.h"
+#include "inc/hw_ints.h"
+#include "driverlib/gpio.h"
+#include "driverlib/uart.h"
+#include "driverlib/sysctl.h"
+#include "driverlib/pin_map.h"
+
+#if HW_PLATFORM == HW_PLATFORM_OLS1V
+#include "ols1v.h"
+#elif HW_PLATFORM == HW_PLATFORM_EAV1V
+#include "eav1v.h"
+#else
+#error Unknown hardware platform!
+#endif	//	HW_PLATFORM
+
+/////////////////////////////////////////////////////////////////////////////
+
+static uint16_t g_mbRegs[MODBUS_WORD_REGISTER_COUNT];
+static HMBRTUSLV g_hMbSlv;
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void _OnSlaveStateChanged(GFA_MODBUS_RTU_SLV_STATES newState, GFA_MODBUS_RTU_SLV_STATES oldState)
+{
+	switch(newState)
+	{
+	case MB_RTU_SLV_Idle:
+//		OlsClearLeds(OLS_LED_MASK);
+		break;
+
+	case MB_RTU_SLV_RxSlvID:
+//		OlsSetLeds(OLS_LED_GREEN_RIGHT);
+		break;
+
+	case MB_RTU_SLV_RxComplete:
+//		OlsClearLeds(OLS_LED_GREEN_RIGHT);
+		break;
+
+	case MB_RTU_SLV_TxStart:
+//		OlsSetLeds(OLS_LED_GREEN_LEFT);
+		break;
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// maps a modbus register address to a physical register address.
+// if not implemented the modbus address is interpreted as physical address.
+
+static uint16_t _MapRegisterAddress(uint16_t nAddr)
+{
+	if(nAddr >= MODBUS_WORD_REGISTER_COUNT)
+		return (uint16_t)-1;
+	return nAddr;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void _PreReadRegisters(uint8_t func, uint16_t nRegStart, uint16_t nRegCount)
+{
+	float f1 = GfaBufGetUnaligned_float(&g_mbRegs[0]);
+	float f2 = GfaBufGetUnaligned_float(&g_mbRegs[1]);
+
+	GfaBufSetUnaligned_float(&g_mbRegs[0], ++f1);
+	GfaBufSetUnaligned_float(&g_mbRegs[1], --f2);
+}
+
+static void _PostReadRegisters(uint8_t func, uint16_t nRegStart, uint16_t nRegCount)
+{
+}
+
+static void _PreWriteRegisters(uint8_t func, uint16_t nRegStart, uint16_t nRegCount)
+{
+}
+
+static void _PostWriteRegisters(uint8_t func, uint16_t nRegStart, uint16_t nRegCount)
+{
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void _InitUARTConfig(LPUART_CONFIG puc)
+{
+	memset(puc, 0, sizeof(LPUART_CONFIG));
+
+	puc->P_UART_BASE		  = UART_BASE;
+	puc->P_UART_BASE_SYSCTL   = UART_BASE_SYSCTL;
+	puc->P_UART_PORT          = UART_PORT;
+	puc->P_UART_PORT_SYSCTL   = UART_PORT_SYSCTL;
+	puc->P_UART_RX_PIN        = UART_RX_PIN;
+	puc->P_UART_RX_PIN_MUX    = UART_RX_PIN_MUX;
+	puc->P_UART_TX_PIN        = UART_TX_PIN;
+	puc->P_UART_TX_PIN_MUX    = UART_TX_PIN_MUX;
+	puc->P_UART_INT           = UART_INT;
+	puc->P_UART_INT_PRIORITY  = MODBUS_RTU_UART_INT_PRIORITY;
+	puc->P_EN_485_PORT_SYSCTL = EN_485_PORT_SYSCTL;
+	puc->P_EN_485_PORT        = EN_485_PORT;
+	puc->P_EN_485_PIN         = EN_485_PIN;
+	puc->nBaud                = MODBUS_RTU_BAUDRATE;
+	puc->nDatabits            = MODBUS_RTU_DATABITS;
+	puc->nStopbits            = MODBUS_RTU_STOPBITS;
+	puc->parity               = MODBUS_RTU_PARITY;
+	puc->nFifoIndexRx         = 0;
+	puc->nFifoIndexTx         = 1;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+bool GfaInitModbusSlaveApp(void)
+{
+	UART_CONFIG uartParams;
+	g_hMbSlv = NULL;
+	_InitUARTConfig(&uartParams);
+
+	if(MB_UART_Init(&uartParams))
+	{
+		GFA_MODBUS_RTU_SLAVE_PARAMETERS slvParams;
+		memset(&slvParams, 0, sizeof(slvParams));
+
+		slvParams.slaveID					= MODBUS_SLAVE_ID;
+		slvParams.hFifoRX					= MB_UART_GetRxFifo();
+		slvParams.hFifoTX					= MB_UART_GetTxFifo();
+
+		slvParams.regMap.pRegs				= g_mbRegs;
+		slvParams.regMap.nCountRegs 		= _countof(g_mbRegs);
+
+		slvParams.appItf.pfnMapRegAddr		= _MapRegisterAddress;
+		slvParams.appItf.pfnPreRead			= _PreReadRegisters;
+		slvParams.appItf.pfnPostRead		= _PostReadRegisters;
+		slvParams.appItf.pfnPreWrite		= _PreWriteRegisters;
+		slvParams.appItf.pfnPostWrite		= _PostWriteRegisters;
+		slvParams.appItf.pfnStateChanged	= _OnSlaveStateChanged;
+
+		slvParams.appItf.pfnPreTransmit		= NULL;
+		slvParams.appItf.pfnPostTransmit	= NULL;
+
+		if(!(g_hMbSlv = GfaModbusRTUSlvCreate(&slvParams)))
+			MB_UART_Release();
+	}
+
+	return !!g_hMbSlv;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void GfaDoModbusSlaveApp(void)
+{
+	GfaModbusRTUSlvStateMachine(g_hMbSlv);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+

+ 37 - 0
DemoSlave/mbslvapp.h

@@ -0,0 +1,37 @@
+// mbapp.h :
+//
+
+#if !defined(AGD_MBAPP_H__45B5FF25_C1D8_4196_97EF_0101C487A999__INCLUDED_)
+#define AGD_MBAPP_H__45B5FF25_C1D8_4196_97EF_0101C487A999__INCLUDED_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif	//	__cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// mbapp.h - Declarations:
+
+#define HW_PLATFORM_OLS1V									1
+#define HW_PLATFORM_EAV1V									2
+#define HW_PLATFORM											HW_PLATFORM_OLS1V
+
+#define MODBUS_SLAVE_ID										100
+#define MODBUS_WORD_REGISTER_COUNT							50
+
+#define MODBUS_RTU_UART_INT_PRIORITY						(1 << 5)
+#define MODBUS_RTU_BAUDRATE									9600
+#define MODBUS_RTU_DATABITS									8
+#define MODBUS_RTU_STOPBITS									1
+#define MODBUS_RTU_PARITY									P_Even
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool GfaInitModbusSlaveApp(void);
+void GfaDoModbusSlaveApp(void);
+
+/////////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+}
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_MBAPP_H__45B5FF25_C1D8_4196_97EF_0101C487A999__INCLUDED_)

+ 213 - 0
DemoSlave/ols1v.h

@@ -0,0 +1,213 @@
+// eav1v.h :
+//
+
+#if !defined(AGD_PINS_H__9F94DC4E_A195_4754_9727_7DAF2FFB0DE2__INCLUDED_)
+#define AGD_PINS_H__9F94DC4E_A195_4754_9727_7DAF2FFB0DE2__INCLUDED_
+
+#ifdef __cplusplus
+extern "C" {
+#endif	//	__cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// pins.h - Declarations:
+
+//
+// GPIO PORTA is used for
+//
+#define PA0__RX_UART0		GPIO_PIN_0		// PA0	RX_UART0		(UART input)
+#define PA1__TX_UART0		GPIO_PIN_1		// PA1	TX_UART0		(UART output)
+#define PA2__LED3			GPIO_PIN_2		// PA2	LED3			(digital output)
+#define PA3__LED4			GPIO_PIN_3		// PA3	LED4			(digital output)
+#define PA4__LED5			GPIO_PIN_4		// PA4	LED5			(digital output)
+#define PA5__LED6			GPIO_PIN_5		// PA5	LED6			(digital output)
+#define PA6__5V_UART0		GPIO_PIN_6		// PA6	5V_UART0		(digital input)
+#define PA7__				GPIO_PIN_7		// PA7					(unused)
+
+//
+// GPIO PORTB is used for
+//
+#define PB0__RX_485_1		GPIO_PIN_0		// PB0	RX_485_1		(UART input)
+#define PB1__TX_485_1		GPIO_PIN_1		// PB1	TX_485_1		(UART output)
+#define PB2__I2C_WIFI_SCL	GPIO_PIN_2		// PB2	I2C_WIFI_SCL	(I2C interface)
+#define PB3__I2C_WIFI_SDA	GPIO_PIN_3		// PB3	I2C_WIFI_SDA	(I2C interface)
+#define PB4__DIGOUT1		GPIO_PIN_4		// PB4	DIGOUT1			(digital output)
+#define PB5__DIGOUT2		GPIO_PIN_5		// PB5	DIGOUT2			(digital output)
+
+#define PB0__LS_ON_ZI3		GPIO_PIN_0		// PB0	LS_ON_ZI3		(digital output)
+#define PB1__LS_ON_ZI2		GPIO_PIN_1		// PB1	LS_ON_ZI2		(digital output)
+#define PB2__Z_IN1_SCL3		GPIO_PIN_2		// PB2	Z_IN1_SCL3		(TIMER input, I2C interface)
+#define PB3__AN_CLK_SDA3	GPIO_PIN_3		// PB3	AN_CLK_SDA3		(TIMER input, I2C interface)
+#define PB4__ANIN1			GPIO_PIN_4		// PB4	ANIN1			(analog input)
+#define PB5__U_24V_IO		GPIO_PIN_5		// PB5	U_24V_IO		(analog input)
+
+//
+// GPIO PORTC is used for
+//
+#define PC0__				GPIO_PIN_0		// PC0					(JTAG TCK)
+#define PC1__				GPIO_PIN_1		// PC1					(JTAG TMS)
+#define PC2__				GPIO_PIN_2		// PC2					(JTAG TDI)
+#define PC3__				GPIO_PIN_3		// PC3					(JTAG TDO)
+#define PC4__				GPIO_PIN_4		// PC4					(unused)
+#define PC5__TASTE			GPIO_PIN_5		// PC5	TASTE			(digital input)
+#define PC6__VREF_ZIN_H		GPIO_PIN_6		// PC6	VREF_ZIN_H		(analog comparator reference)
+#define PC7__ZIN1			GPIO_PIN_7		// PC7	ZIN1			(analog comparator input)
+
+#define PC0__				GPIO_PIN_0		// PC0					(JTAG TCK)
+#define PC1__				GPIO_PIN_1		// PC1					(JTAG TMS)
+#define PC2__				GPIO_PIN_2		// PC2					(JTAG TDI)
+#define PC3__				GPIO_PIN_3		// PC3					(JTAG TDO)
+#define PC4__Z_IN2			GPIO_PIN_4		// PC4	Z_IN2			(analog comparator input)
+#define PC5__LED_BUS		GPIO_PIN_5		// PC5	LED_BUS			(digital output)
+#define PC6__VREF_ZIN_H		GPIO_PIN_6		// PC6	VREF_ZIN_H		(analog comparator reference)
+#define PC7__Z_IN3			GPIO_PIN_7		// PC7	Z_IN3			(analog comparator input)
+
+//
+// GPIO PORTD is used for
+//
+#define PD0__ANIN_OUT1		GPIO_PIN_0		// PD0	ANIN_OUT1		(analog input)
+#define PD1__ANIN4			GPIO_PIN_1		// PD1	ANIN4			(analog input)
+#define PD2__ANIN3			GPIO_PIN_2		// PD2	ANIN3			(analog input)
+#define PD3__ANIN0			GPIO_PIN_3		// PD3	ANIN0			(analog input)
+#define PD4__MP				GPIO_PIN_4		// PD4	MP				(UART input)
+#define PD5__MP				GPIO_PIN_5		// PD4	MP				(UART output)
+#define PD6__ACT_POS		GPIO_PIN_6		// PD4	ACT_POS			(analog input)
+#define PD7__RESTARTB		GPIO_PIN_7		// PD4	RESTARTB		(digital input)
+
+#define PD0__ANIN_OUT1		GPIO_PIN_0		// PD0	ANIN_OUT1		(analog input)
+#define PD1__ANIN_OUT2		GPIO_PIN_1		// PD1	ANIN_OUT2		(analog input)
+#define PD2__ANIN_OUT3		GPIO_PIN_2		// PD2	ANIN_OUT3		(analog input)
+#define PD3__ANIN_OUT4		GPIO_PIN_3		// PD3	ANIN_OUT4		(analog input)
+#define PD4__ANIN4			GPIO_PIN_4		// PD4	ANIN4			(analog input)
+#define PD5__ANIN5			GPIO_PIN_5		// PD4	ANIN5			(analog input)
+#define PD6__ANIN6			GPIO_PIN_6		// PD4	ANIN6			(analog input)
+#define PD7__ANIN0			GPIO_PIN_7		// PD4	ANIN0			(analog input)
+
+//
+// GPIO PORTE is used for
+//
+#define PE0__RX_WIFI2		GPIO_PIN_0		// PE0	RX_WIFI2		(UART input)
+#define PE1__TX_WIFI2		GPIO_PIN_1		// PE1	TX_WIFI2		(UART output)
+#define PE2__LS_ON_ZI1		GPIO_PIN_2		// PE2	LS_ON_ZI1		(digital output)
+#define PE3__				GPIO_PIN_3		// PE3					(unused)
+#define PE4__RX_485_2		GPIO_PIN_4		// PE4	RX_485_2		(UART input)
+#define PE5__TX_485_2		GPIO_PIN_5		// PE5	TX_485_2		(UART output)
+#define PE6__EN_485_2		GPIO_PIN_6		// PE6	EN_485_2		(digital output)
+#define PE7__EN_485_1		GPIO_PIN_7		// PE6	EN_485_1		(digital output)
+
+#define PE0__RX_485_1		GPIO_PIN_0		// PE0	RX_485_1		(UART input)
+#define PE1__TX_485_1		GPIO_PIN_1		// PE1	TX_485_1		(UART output)
+#define PE2__LED_ERR		GPIO_PIN_2		// PE2	LED_ERR			(digital output)
+#define PE3__Z_IN4			GPIO_PIN_3		// PE3	Z_IN4			(analog input)
+#define PE4__ANIN2			GPIO_PIN_4		// PE4	ANIN2			(analog input)
+#define PE5__ANIN3			GPIO_PIN_5		// PE5	ANIN3			(analog input)
+#define PE6__U_VERS			GPIO_PIN_6		// PE6	U_VERS			(analog input)
+#define PE7__U_V15V			GPIO_PIN_7		// PE6	U_V15V			(analog input)
+
+//
+// GPIO PORTF is used for
+//
+#define PF0__ANZ1_A			GPIO_PIN_0		// PF0	ANZ1_A			(digital output)
+#define PF1__ANZ1_B			GPIO_PIN_1		// PF1	ANZ1_B			(digital output)
+#define PF2__ANZ1_C			GPIO_PIN_2		// PF2	ANZ1_C			(digital output)
+#define PF3__ANZ1_D			GPIO_PIN_3		// PF3	ANZ1_D			(digital output)
+#define PF4__ANZ1_E			GPIO_PIN_4		// PF4	ANZ1_E			(digital output)
+#define PF5__ANZ1_F			GPIO_PIN_5		// PF5	ANZ1_F			(digital output)
+#define PF6__ANZ1_G			GPIO_PIN_6		// PF6	ANZ1_G			(digital output)
+#define PF7__ANZ1_DP		GPIO_PIN_7		// PF7	ANZ1_DP			(digital output)
+
+#define PF0__nCS_REL		GPIO_PIN_0		// PF0	nCS_REL			(digital input)
+#define PF1__nCS_DA1		GPIO_PIN_1		// PF1	nCS_DA1			(digital input)
+#define PF2__nCS_DA2		GPIO_PIN_2		// PF2	nCS_DA2			(digital input)
+#define PF3__PWM_CPU		GPIO_PIN_3		// PF3	PWM_CPU			(digital input)
+#define PF4__100Hz			GPIO_PIN_4		// PF4	100Hz			(TIMER output)
+#define PF5__nRES_PER		GPIO_PIN_5		// PF5	nRES_PER		(digital input)
+#define PF6__LED_BETR		GPIO_PIN_6		// PF6	LED_BETR		(digital output)
+#define PF7__LS_ON_ZI4		GPIO_PIN_7		// PF7	LS_ON_ZI3		(digital output)
+
+//
+// GPIO PORTG is used for
+//
+#define PG0__ANZ2_A			GPIO_PIN_0		// PG0	ANZ1_A			(digital output)
+#define PG1__ANZ2_B			GPIO_PIN_1		// PG1	ANZ1_B			(digital output)
+#define PG2__ANZ2_C			GPIO_PIN_2		// PG2	ANZ1_C			(digital output)
+#define PG3__ANZ2_D			GPIO_PIN_3		// PG3	ANZ1_D			(digital output)
+#define PG4__ANZ2_E			GPIO_PIN_4		// PG4	ANZ1_E			(digital output)
+#define PG5__ANZ2_F			GPIO_PIN_5		// PG5	ANZ1_F			(digital output)
+#define PG6__ANZ2_G			GPIO_PIN_6		// PG6	ANZ1_G			(digital output)
+#define PG7__ANZ2_DP		GPIO_PIN_7		// PG7	ANZ1_DP			(digital output)
+
+#define PG0__REL1			GPIO_PIN_0		// PG0	REL1			(digital output)
+#define PG1__REL2			GPIO_PIN_1		// PG1	REL2			(digital output)
+#define PG2__REL3			GPIO_PIN_2		// PG2	REL3			(digital output)
+#define PG3__REL4			GPIO_PIN_3		// PG3	REL4			(digital output)
+#define PG4__PWM_TRIAC		GPIO_PIN_4		// PG4	PWM_TRIAC		(PWM output)
+#define PG5__LS_ON_ZI1		GPIO_PIN_5		// PG5	LS_ON_ZI1		(digital output)
+#define PG6__NULLDURCH		GPIO_PIN_6		// PG6  NULLDURCH		(TIMER input)
+#define PG7__Z_IN1			GPIO_PIN_7		// PG7	Z_IN1			(analog comparator input)
+
+//
+// GPIO PORTH is used for
+//
+#define PH0__ANIN2			GPIO_PIN_0		// PH0	ANIN2			(analog input)
+#define PH1__ANIN1			GPIO_PIN_1		// PH1	ANIN1			(analog input)
+#define PH2__U_DIG_OUT2		GPIO_PIN_2		// PH2	U_DIG_OUT2		(analog input)
+#define PH3__U_VERS			GPIO_PIN_3		// PH3	U_VERS			(analog input)
+#define PH4__ST_DO1			GPIO_PIN_4		// PH4	ST_DO1			(digital input)
+#define PH5__ST_DO2			GPIO_PIN_5		// PH5	ST_DO2			(digital input)
+#define PH6__				GPIO_PIN_6		// PH6					(unused)
+#define PH7__PWM_AN1		GPIO_PIN_7		// PH7	PWM_AN1			(PWM output)
+
+#define PH0__LED_IN1		GPIO_PIN_0		// PH0	LED_IN1			(digital output)
+#define PH1__LED_IN2		GPIO_PIN_1		// PH1	LED_IN2			(digital output)
+#define PH2__LED_IN3		GPIO_PIN_2		// PH2	LED_IN3			(digital output)
+#define PH3__LED_IN4		GPIO_PIN_3		// PH3	LED_IN4			(digital output)
+#define PH4__PWM4			GPIO_PIN_4		// PG4	PWM4			(PWM output)
+#define PH5__PWM3			GPIO_PIN_5		// PG5	PWM3			(PWM output)
+#define PH6__PWM2			GPIO_PIN_6		// PG6	PWM2			(PWM output)
+#define PH7__PWM1			GPIO_PIN_7		// PG7	PWM1			(PWM output)
+
+//
+// GPIO PORTJ is used for
+//
+#define PJ0__RX_WIFI1		GPIO_PIN_0		// PJ0	RX_WIFI1		(UART input)
+#define PJ1__TX_WIFI1		GPIO_PIN_1		// PJ1	TX_WIFI1		(UART output)
+#define PJ2__EN_WIFI		GPIO_PIN_2		// PJ2	EN_WIFI			(digital output)
+
+#define PJ0__EN_V15V		GPIO_PIN_0		// PJ0	EN_V15V			(digital output)
+#define PJ1__EN_V24V_IO		GPIO_PIN_1		// PJ1	EN_V24V_IO		(digital output)
+#define PJ2__EN_485_1		GPIO_PIN_2		// PJ2	EN_485_1		(digital output)
+
+//
+// GPIO PORTK is used for
+//
+#define PK0__SPI_WIFI_CLK	GPIO_PIN_0		// PK0	SPI_WIFI_CLK	(SPI output)
+#define PK1__SPI_WIFI_CS	GPIO_PIN_1		// PK1	SPI_WIFI_CS		(SPI output)
+#define PK2__SPI_WIFI_MISO	GPIO_PIN_2		// PK2	SPI_WIFI_MISO	(SPI input)
+#define PK3__SPI_WIFI_MOSI	GPIO_PIN_3		// PK3	SPI_WIFI_MOSI	(SPI output)
+
+#define PK0__AN_A0			GPIO_PIN_0		// PK0	AN_A0			(digital input)
+#define PK1__AN_A1			GPIO_PIN_1		// PK1	AN_A1			(digital input)
+#define PK2__AN_A2			GPIO_PIN_2		// PK2	AN_A2			(digital input)
+#define PK3__nAB_DA			GPIO_PIN_3		// PK3	nA/B_DA			(digital input)
+
+/////////////////////////////////////////////////////////////////////////////
+// UART / RS485 / Timer
+
+#define UART_PORT_SYSCTL	SYSCTL_PERIPH_GPIOB
+#define UART_PORT			GPIO_PORTB_BASE
+#define UART_BASE_SYSCTL	SYSCTL_PERIPH_UART1
+#define UART_BASE			UART1_BASE
+#define UART_INT			INT_UART1
+#define UART_RX_PIN         PB0__RX_485_1
+#define UART_TX_PIN         PB1__TX_485_1
+#define UART_RX_PIN_MUX     GPIO_PB0_U1RX
+#define UART_TX_PIN_MUX     GPIO_PB1_U1TX
+#define EN_485_PORT_SYSCTL	SYSCTL_PERIPH_GPIOE
+#define EN_485_PORT			GPIO_PORTE_BASE
+#define EN_485_PIN			PE7__EN_485_1
+
+/////////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+}
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_PINS_H__9F94DC4E_A195_4754_9727_7DAF2FFB0DE2__INCLUDED_)

+ 45 - 0
DemoSlave/tm4c1231e6pz.cmd

@@ -0,0 +1,45 @@
+/******************************************************************************
+ *
+ * Default Linker Command file for the Texas Instruments TM4C1231E6PZ
+ *
+ * This is derived from revision 15071 of the TivaWare Library.
+ *
+ *****************************************************************************/
+
+--retain=g_pfnVectors
+
+MEMORY
+{
+    FLASH (RX) : origin = 0x00000000, length = 0x00020000
+    SRAM (RWX) : origin = 0x20000000, length = 0x00008000
+}
+
+/* The following command line options are set as part of the CCS project.    */
+/* If you are building using the command line, or for some reason want to    */
+/* define them here, you can uncomment and modify these lines as needed.     */
+/* If you are using CCS for building, it is probably better to make any such */
+/* modifications in your CCS project and leave this file alone.              */
+/*                                                                           */
+/* --heap_size=0                                                             */
+/* --stack_size=256                                                          */
+/* --library=rtsv7M4_T_le_eabi.lib                                           */
+
+/* Section allocation in memory */
+
+SECTIONS
+{
+    .intvecs:   > 0x00000000
+    .text   :   > FLASH
+    .const  :   > FLASH
+    .cinit  :   > FLASH
+    .pinit  :   > FLASH
+    .init_array : > FLASH
+
+    .vtable :   > 0x20000000
+    .data   :   > SRAM
+    .bss    :   > SRAM
+    .sysmem :   > SRAM
+    .stack  :   > SRAM
+}
+
+__STACK_TOP = __stack + 512;

+ 300 - 0
DemoSlave/tm4c1231e6pz_startup_ccs.c

@@ -0,0 +1,300 @@
+//*****************************************************************************
+//
+// Startup code for use with TI's Code Composer Studio.
+//
+// Copyright (c) 2011-2014 Texas Instruments Incorporated.  All rights reserved.
+// Software License Agreement
+// 
+// Software License Agreement
+//
+// Texas Instruments (TI) is supplying this software for use solely and
+// exclusively on TI's microcontroller products. The software is owned by
+// TI and/or its suppliers, and is protected under applicable copyright
+// laws. You may not combine this software with "viral" open-source
+// software in order to form a larger program.
+//
+// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
+// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
+// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
+// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
+// DAMAGES, FOR ANY REASON WHATSOEVER.
+//
+//*****************************************************************************
+
+#include <stdint.h>
+
+//*****************************************************************************
+//
+// Forward declaration of the default fault handlers.
+//
+//*****************************************************************************
+void ResetISR(void);
+static void NmiSR(void);
+static void FaultISR(void);
+static void IntDefaultHandler(void);
+
+//*****************************************************************************
+//
+// External declaration for the reset handler that is to be called when the
+// processor is started
+//
+//*****************************************************************************
+extern void _c_int00(void);
+
+//*****************************************************************************
+//
+// Linker variable that marks the top of the stack.
+//
+//*****************************************************************************
+extern uint32_t __STACK_TOP;
+
+//*****************************************************************************
+//
+// External declarations for the interrupt handlers used by the application.
+//
+//*****************************************************************************
+// To be added by user
+
+//*****************************************************************************
+//
+// The vector table.  Note that the proper constructs must be placed on this to
+// ensure that it ends up at physical address 0x0000.0000 or at the start of
+// the program if located at a start address other than 0.
+//
+//*****************************************************************************
+#pragma DATA_SECTION(g_pfnVectors, ".intvecs")
+void (* const g_pfnVectors[])(void) =
+{
+    (void (*)(void))((uint32_t)&__STACK_TOP),
+                                            // The initial stack pointer
+    ResetISR,                               // The reset handler
+    NmiSR,                                  // The NMI handler
+    FaultISR,                               // The hard fault handler
+    IntDefaultHandler,                      // The MPU fault handler
+    IntDefaultHandler,                      // The bus fault handler
+    IntDefaultHandler,                      // The usage fault handler
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    IntDefaultHandler,                      // SVCall handler
+    IntDefaultHandler,                      // Debug monitor handler
+    0,                                      // Reserved
+    IntDefaultHandler,                      // The PendSV handler
+    IntDefaultHandler,                      // The SysTick handler
+    IntDefaultHandler,                      // GPIO Port A
+    IntDefaultHandler,                      // GPIO Port B
+    IntDefaultHandler,                      // GPIO Port C
+    IntDefaultHandler,                      // GPIO Port D
+    IntDefaultHandler,                      // GPIO Port E
+    IntDefaultHandler,                      // UART0 Rx and Tx
+    IntDefaultHandler,                      // UART1 Rx and Tx
+    IntDefaultHandler,                      // SSI0 Rx and Tx
+    IntDefaultHandler,                      // I2C0 Master and Slave
+    IntDefaultHandler,                      // PWM Fault
+    IntDefaultHandler,                      // PWM Generator 0
+    IntDefaultHandler,                      // PWM Generator 1
+    IntDefaultHandler,                      // PWM Generator 2
+    IntDefaultHandler,                      // Quadrature Encoder 0
+    IntDefaultHandler,                      // ADC Sequence 0
+    IntDefaultHandler,                      // ADC Sequence 1
+    IntDefaultHandler,                      // ADC Sequence 2
+    IntDefaultHandler,                      // ADC Sequence 3
+    IntDefaultHandler,                      // Watchdog timer
+    IntDefaultHandler,                      // Timer 0 subtimer A
+    IntDefaultHandler,                      // Timer 0 subtimer B
+    IntDefaultHandler,                      // Timer 1 subtimer A
+    IntDefaultHandler,                      // Timer 1 subtimer B
+    IntDefaultHandler,                      // Timer 2 subtimer A
+    IntDefaultHandler,                      // Timer 2 subtimer B
+    IntDefaultHandler,                      // Analog Comparator 0
+    IntDefaultHandler,                      // Analog Comparator 1
+    IntDefaultHandler,                      // Analog Comparator 2
+    IntDefaultHandler,                      // System Control (PLL, OSC, BO)
+    IntDefaultHandler,                      // FLASH Control
+    IntDefaultHandler,                      // GPIO Port F
+    IntDefaultHandler,                      // GPIO Port G
+    IntDefaultHandler,                      // GPIO Port H
+    IntDefaultHandler,                      // UART2 Rx and Tx
+    IntDefaultHandler,                      // SSI1 Rx and Tx
+    IntDefaultHandler,                      // Timer 3 subtimer A
+    IntDefaultHandler,                      // Timer 3 subtimer B
+    IntDefaultHandler,                      // I2C1 Master and Slave
+    IntDefaultHandler,                      // Quadrature Encoder 1
+    IntDefaultHandler,                      // CAN0
+    IntDefaultHandler,                      // CAN1
+    0,                                      // Reserved
+    0,                                      // Reserved
+    IntDefaultHandler,                      // Hibernate
+    IntDefaultHandler,                      // USB0
+    IntDefaultHandler,                      // PWM Generator 3
+    IntDefaultHandler,                      // uDMA Software Transfer
+    IntDefaultHandler,                      // uDMA Error
+    IntDefaultHandler,                      // ADC1 Sequence 0
+    IntDefaultHandler,                      // ADC1 Sequence 1
+    IntDefaultHandler,                      // ADC1 Sequence 2
+    IntDefaultHandler,                      // ADC1 Sequence 3
+    0,                                      // Reserved
+    0,                                      // Reserved
+    IntDefaultHandler,                      // GPIO Port J
+    IntDefaultHandler,                      // GPIO Port K
+    IntDefaultHandler,                      // GPIO Port L
+    IntDefaultHandler,                      // SSI2 Rx and Tx
+    IntDefaultHandler,                      // SSI3 Rx and Tx
+    IntDefaultHandler,                      // UART3 Rx and Tx
+    IntDefaultHandler,                      // UART4 Rx and Tx
+    IntDefaultHandler,                      // UART5 Rx and Tx
+    IntDefaultHandler,                      // UART6 Rx and Tx
+    IntDefaultHandler,                      // UART7 Rx and Tx
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    IntDefaultHandler,                      // I2C2 Master and Slave
+    IntDefaultHandler,                      // I2C3 Master and Slave
+    IntDefaultHandler,                      // Timer 4 subtimer A
+    IntDefaultHandler,                      // Timer 4 subtimer B
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    0,                                      // Reserved
+    IntDefaultHandler,                      // Timer 5 subtimer A
+    IntDefaultHandler,                      // Timer 5 subtimer B
+    IntDefaultHandler,                      // Wide Timer 0 subtimer A
+    IntDefaultHandler,                      // Wide Timer 0 subtimer B
+    IntDefaultHandler,                      // Wide Timer 1 subtimer A
+    IntDefaultHandler,                      // Wide Timer 1 subtimer B
+    IntDefaultHandler,                      // Wide Timer 2 subtimer A
+    IntDefaultHandler,                      // Wide Timer 2 subtimer B
+    IntDefaultHandler,                      // Wide Timer 3 subtimer A
+    IntDefaultHandler,                      // Wide Timer 3 subtimer B
+    IntDefaultHandler,                      // Wide Timer 4 subtimer A
+    IntDefaultHandler,                      // Wide Timer 4 subtimer B
+    IntDefaultHandler,                      // Wide Timer 5 subtimer A
+    IntDefaultHandler,                      // Wide Timer 5 subtimer B
+    IntDefaultHandler,                      // FPU
+    0,                                      // Reserved
+    0,                                      // Reserved
+    IntDefaultHandler,                      // I2C4 Master and Slave
+    IntDefaultHandler,                      // I2C5 Master and Slave
+    IntDefaultHandler,                      // GPIO Port M
+    IntDefaultHandler,                      // GPIO Port N
+    IntDefaultHandler,                      // Quadrature Encoder 2
+    0,                                      // Reserved
+    0,                                      // Reserved
+    IntDefaultHandler,                      // GPIO Port P (Summary or P0)
+    IntDefaultHandler,                      // GPIO Port P1
+    IntDefaultHandler,                      // GPIO Port P2
+    IntDefaultHandler,                      // GPIO Port P3
+    IntDefaultHandler,                      // GPIO Port P4
+    IntDefaultHandler,                      // GPIO Port P5
+    IntDefaultHandler,                      // GPIO Port P6
+    IntDefaultHandler,                      // GPIO Port P7
+    IntDefaultHandler,                      // GPIO Port Q (Summary or Q0)
+    IntDefaultHandler,                      // GPIO Port Q1
+    IntDefaultHandler,                      // GPIO Port Q2
+    IntDefaultHandler,                      // GPIO Port Q3
+    IntDefaultHandler,                      // GPIO Port Q4
+    IntDefaultHandler,                      // GPIO Port Q5
+    IntDefaultHandler,                      // GPIO Port Q6
+    IntDefaultHandler,                      // GPIO Port Q7
+    IntDefaultHandler,                      // GPIO Port R
+    IntDefaultHandler,                      // GPIO Port S
+    IntDefaultHandler,                      // PWM 1 Generator 0
+    IntDefaultHandler,                      // PWM 1 Generator 1
+    IntDefaultHandler,                      // PWM 1 Generator 2
+    IntDefaultHandler,                      // PWM 1 Generator 3
+    IntDefaultHandler                       // PWM 1 Fault
+};
+
+//*****************************************************************************
+//
+// This is the code that gets called when the processor first starts execution
+// following a reset event.  Only the absolutely necessary set is performed,
+// after which the application supplied entry() routine is called.  Any fancy
+// actions (such as making decisions based on the reset cause register, and
+// resetting the bits in that register) are left solely in the hands of the
+// application.
+//
+//*****************************************************************************
+void
+ResetISR(void)
+{
+    //
+    // Jump to the CCS C initialization routine.  This will enable the
+    // floating-point unit as well, so that does not need to be done here.
+    //
+    __asm("    .global _c_int00\n"
+          "    b.w     _c_int00");
+}
+
+//*****************************************************************************
+//
+// This is the code that gets called when the processor receives a NMI.  This
+// simply enters an infinite loop, preserving the system state for examination
+// by a debugger.
+//
+//*****************************************************************************
+static void
+NmiSR(void)
+{
+    //
+    // Enter an infinite loop.
+    //
+    while(1)
+    {
+    }
+}
+
+//*****************************************************************************
+//
+// This is the code that gets called when the processor receives a fault
+// interrupt.  This simply enters an infinite loop, preserving the system state
+// for examination by a debugger.
+//
+//*****************************************************************************
+static void
+FaultISR(void)
+{
+    //
+    // Enter an infinite loop.
+    //
+    while(1)
+    {
+    }
+}
+
+//*****************************************************************************
+//
+// This is the code that gets called when the processor receives an unexpected
+// interrupt.  This simply enters an infinite loop, preserving the system state
+// for examination by a debugger.
+//
+//*****************************************************************************
+static void
+IntDefaultHandler(void)
+{
+    //
+    // Go into an infinite loop.
+    //
+    while(1)
+    {
+    }
+}

+ 14 - 0
gfamodbusrtucom/.ccsproject

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<?ccsproject version="1.0"?>
+<projectOptions>
+	<ccsVersion value="8.3.0"/>
+	<deviceVariant value="Cortex M.TM4C1231E6PZ"/>
+	<deviceFamily value="TMS470"/>
+	<deviceEndianness value="little"/>
+	<codegenToolVersion value="18.1.6.LTS"/>
+	<isElfFormat value="true"/>
+	<createSlaveProjects value=""/>
+	<templateProperties value="id=com.ti.common.project.core.emptyProjectTemplate"/>
+	<filesToOpen value=""/>
+	<isTargetManual value="false"/>
+</projectOptions>

+ 143 - 0
gfamodbusrtucom/.cproject

@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+	<storageModule configRelations="2" moduleId="org.eclipse.cdt.core.settings">
+		<cconfiguration id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1834508296">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1834508296" moduleId="org.eclipse.cdt.core.settings" name="Debug">
+				<macros>
+					<stringMacro name="TW_ROOT" type="VALUE_TEXT" value="C:\CCS\TivaWare_C_Series-2.1.4.178"/>
+				</macros>
+				<externalSettings/>
+				<extensions>
+					<extension id="com.ti.ccstudio.binaryparser.CoffParser" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.CoffErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.AsmErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.LinkErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactExtension="lib" artifactName="gfambrtucom" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1834508296" name="Debug" parent="com.ti.ccstudio.buildDefinitions.TMS470.Debug" postbuildStep="@${PWD}\..\distribute.cmd Debug;">
+					<folderInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.1834508296." name="/" resourcePath="">
+						<toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.libraryDebugToolchain.1985702589" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.libraryDebugToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianDebug.1390798588">
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.24834988" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
+								<listOptionValue builtIn="false" value="DEVICE_CONFIGURATION_ID=Cortex M.TM4C1231E6PZ"/>
+								<listOptionValue builtIn="false" value="DEVICE_ENDIANNESS=little"/>
+								<listOptionValue builtIn="false" value="OUTPUT_FORMAT=ELF"/>
+								<listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/>
+								<listOptionValue builtIn="false" value="OUTPUT_TYPE=staticLibrary"/>
+							</option>
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.1567240236" name="Compiler version" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.6.LTS" valueType="string"/>
+							<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformDebug.890146735" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformDebug"/>
+							<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderDebug.2072575191" keepEnvironmentInBuildfile="false" name="GNU Make" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderDebug"/>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerDebug.685076172" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerDebug">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.989426582" name="Target processor version (--silicon_version, -mv)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M4" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.238881608" name="Designate code state, 16-bit (thumb) or 32-bit (--code_state)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.193145920" name="Application binary interface. (--abi)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.818005934" name="Specify floating point support (--float_support)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.FPv4SPD16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.2146929024" name="Enable support for GCC extensions (DEPRECATED) (--gcc)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.1248305755" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
+									<listOptionValue builtIn="false" value="ccs=&quot;ccs&quot;"/>
+									<listOptionValue builtIn="false" value="PART_TM4C1231E6PZ"/>
+									<listOptionValue builtIn="false" value="__TI_TIME_USES_64=1"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.1550118654" name="Debugging model" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.SYMDEBUG__DWARF" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.1716702900" name="Treat diagnostic &lt;id&gt; as warning (--diag_warning, -pdsw)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
+									<listOptionValue builtIn="false" value="225"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.1532758638" name="Emit diagnostic identifier numbers (--display_error_number, -pden)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.1494354789" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.801316456" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
+									<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+									<listOptionValue builtIn="false" value="${TW_ROOT}"/>
+									<listOptionValue builtIn="false" value="${GfATivaLibsRoot}\include"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.344002907" name="Little endian code [See 'General' page to edit] (--little_endian, -me)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS.1099556141" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS.1367370785" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS.1229044283" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS.1932422669" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianDebug.1390798588" name="ARM Archiver" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianDebug">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE.202181711" name="Output file" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE" useByScannerDiscovery="false" value="gfambrtucom.lib" valueType="string"/>
+							</tool>
+						</toolChain>
+					</folderInfo>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings">
+				<externalSettings containerId="gfautils;com.ti.ccstudio.buildDefinitions.TMS470.Debug.1783940538" factoryId="org.eclipse.cdt.core.cfg.export.settings.sipplier"/>
+			</storageModule>
+		</cconfiguration>
+		<cconfiguration id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1687442145">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1687442145" moduleId="org.eclipse.cdt.core.settings" name="Release">
+				<macros>
+					<stringMacro name="TW_ROOT" type="VALUE_TEXT" value="C:\CCS\TivaWare_C_Series-2.1.4.178"/>
+				</macros>
+				<externalSettings/>
+				<extensions>
+					<extension id="com.ti.ccstudio.binaryparser.CoffParser" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.CoffErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.AsmErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.LinkErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactExtension="lib" artifactName="${ProjName}" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1687442145" name="Release" parent="com.ti.ccstudio.buildDefinitions.TMS470.Release">
+					<folderInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1687442145." name="/" resourcePath="">
+						<toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.ReleaseToolchain.1237848428" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.ReleaseToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianRelease.481153697">
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.1104851411" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
+								<listOptionValue builtIn="false" value="DEVICE_CONFIGURATION_ID=Cortex M.TM4C1231E6PZ"/>
+								<listOptionValue builtIn="false" value="DEVICE_ENDIANNESS=little"/>
+								<listOptionValue builtIn="false" value="OUTPUT_FORMAT=ELF"/>
+								<listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/>
+								<listOptionValue builtIn="false" value="OUTPUT_TYPE=staticLibrary"/>
+							</option>
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.299476252" name="Compiler version" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.6.LTS" valueType="string"/>
+							<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformRelease.121680417" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformRelease"/>
+							<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderRelease.1209867043" keepEnvironmentInBuildfile="false" name="GNU Make" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderRelease"/>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerRelease.918962375" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerRelease">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.1544422795" name="Target processor version (--silicon_version, -mv)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M4" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.94072186" name="Designate code state, 16-bit (thumb) or 32-bit (--code_state)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.1502256660" name="Application binary interface. (--abi)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.488363273" name="Specify floating point support (--float_support)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.FPv4SPD16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.1007708791" name="Enable support for GCC extensions (DEPRECATED) (--gcc)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.1886905451" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
+									<listOptionValue builtIn="false" value="ccs=&quot;ccs&quot;"/>
+									<listOptionValue builtIn="false" value="PART_TM4C1231E6PZ"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.1458303467" name="Treat diagnostic &lt;id&gt; as warning (--diag_warning, -pdsw)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
+									<listOptionValue builtIn="false" value="225"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.723373842" name="Emit diagnostic identifier numbers (--display_error_number, -pden)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.1106675768" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.902338841" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
+									<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.2055320295" name="Little endian code [See 'General' page to edit] (--little_endian, -me)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS.1996552574" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS.508333933" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS.1981432493" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS.423759603" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianRelease.481153697" name="ARM Archiver" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianRelease">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE.1743742172" name="Output file" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE" useByScannerDiscovery="false" value="${ProjName}.lib" valueType="string"/>
+							</tool>
+						</toolChain>
+					</folderInfo>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings">
+				<externalSettings containerId="gfautils;com.ti.ccstudio.buildDefinitions.TMS470.Release.1116559040" factoryId="org.eclipse.cdt.core.cfg.export.settings.sipplier"/>
+			</storageModule>
+		</cconfiguration>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+		<project id="ModbusRTU_common.com.ti.ccstudio.buildDefinitions.TMS470.ProjectType.442592349" name="TMS470" projectType="com.ti.ccstudio.buildDefinitions.TMS470.ProjectType"/>
+	</storageModule>
+	<storageModule moduleId="scannerConfiguration"/>
+	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
+</cproject>

+ 14 - 0
gfamodbusrtucom/.gitignore

@@ -0,0 +1,14 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
+
+rtf/
+latex/
+html/
+*.bak
+*.tmp
+/Debug/
+/Release/

+ 28 - 0
gfamodbusrtucom/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>gfambrtucommon</name>
+	<comment></comment>
+	<projects>
+		<project>gfautils</project>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+			<triggers>full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.ti.ccstudio.core.ccsNature</nature>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+	</natures>
+</projectDescription>

+ 3 - 0
gfamodbusrtucom/.settings/org.eclipse.cdt.codan.core.prefs

@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+inEditor=false
+onBuild=false

+ 2 - 0
gfamodbusrtucom/.settings/org.eclipse.cdt.debug.core.prefs

@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker

+ 7 - 0
gfamodbusrtucom/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+encoding//Debug/makefile=UTF-8
+encoding//Debug/objects.mk=UTF-8
+encoding//Debug/sources.mk=UTF-8
+encoding//Debug/subdir_rules.mk=UTF-8
+encoding//Debug/subdir_vars.mk=UTF-8
+encoding/mbuart.c=UTF-8

+ 175 - 0
gfamodbusrtucom/buffer.c

@@ -0,0 +1,175 @@
+#include <gfambrtucom.h>
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+void GfaBufCpyUnaligned_uint16_LE(void *pTo, const void *pFrom, size_t nCntWords)
+{
+	size_t i, j;
+	uint8_t *p1 = (uint8_t*)pTo;
+	const uint8_t *p2 = (const uint8_t*)pFrom;
+	for(i = 0; i < nCntWords; i++)
+	{
+		p2 += sizeof(uint16_t);
+		for(j = 0; j < sizeof(uint16_t); j++)
+		{
+			*p1++ = *--p2;
+		}
+		p2 += sizeof(uint16_t);
+	}
+}
+
+void GfaBufCpyUnaligned_uint16_BE(void *pTo, const void *pFrom, size_t nCntWords)
+{
+	size_t i, j;
+	uint8_t *p1 = (uint8_t*)pTo;
+	const uint8_t *p2 = (const uint8_t*)pFrom;
+	for(i = 0; i < nCntWords; i++)
+	{
+		for(j = 0; j < sizeof(uint16_t); j++)
+		{
+			*p1++ = *p2++;
+		}
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void GfaBufCpyUnaligned_uint32_LE(void *pTo, const void *pFrom, size_t nCntDWords)
+{
+	size_t i, j;
+	uint8_t *p1 = (uint8_t*)pTo;
+	const uint8_t *p2 = (const uint8_t*)pFrom;
+	for(i = 0; i < nCntDWords; i++)
+	{
+		p2 += sizeof(uint32_t);
+		for(j = 0; j < sizeof(uint32_t); j++)
+		{
+			*p1++ = *--p2;
+		}
+		p2 += sizeof(uint32_t);
+	}
+}
+
+void GfaBufCpyUnaligned_uint32_BE(void *pTo, const void *pFrom, size_t nCntDWords)
+{
+	size_t i, j;
+	uint8_t *p1 = (uint8_t*)pTo;
+	const uint8_t *p2 = (const uint8_t*)pFrom;
+	for(i = 0; i < nCntDWords; i++)
+	{
+		for(j = 0; j < sizeof(uint32_t); j++)
+		{
+			*p1++ = *p2++;
+		}
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+uint16_t GfaBufGetUnaligned_uint16_LE(const void *pData)
+{
+	uint16_t nRet;
+	GfaBufCpyUnaligned_uint16_LE(&nRet, pData, 1);
+	return nRet;
+}
+
+uint16_t GfaBufGetUnaligned_uint16_BE(const void *pData)
+{
+	uint16_t nRet;
+	GfaBufCpyUnaligned_uint16_BE(&nRet, pData, 1);
+	return nRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void GfaBufSetUnaligned_uint16_LE(void *pData, uint16_t nVal)
+{
+	GfaBufCpyUnaligned_uint16_LE(pData, &nVal, 1);
+}
+
+void GfaBufSetUnaligned_uint16_BE(void *pData, uint16_t nVal)
+{
+	GfaBufCpyUnaligned_uint16_BE(pData, &nVal, 1);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+uint32_t GfaBufGetUnaligned_uint32_LE(const void *pData)
+{
+	uint32_t nRet;
+	GfaBufCpyUnaligned_uint32_LE(&nRet, pData, 1);
+	return nRet;
+}
+
+uint32_t GfaBufGetUnaligned_uint32_BE(const void *pData)
+{
+	uint32_t nRet;
+	GfaBufCpyUnaligned_uint32_BE(&nRet, pData, 1);
+	return nRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void GfaBufSetUnaligned_uint32_LE(void *pData, uint16_t nVal)
+{
+	GfaBufCpyUnaligned_uint32_LE(pData, &nVal, 1);
+}
+
+void GfaBufSetUnaligned_uint32_BE(void *pData, uint16_t nVal)
+{
+	GfaBufCpyUnaligned_uint32_BE(pData, &nVal, 1);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+float GfaBufGetUnaligned_float(const void *pData)
+{
+	float fVal;
+	uint8_t *p1 = (uint8_t*)pData;
+	uint8_t *p2 = (uint8_t*)&fVal;
+	memcpy(p2, p1, sizeof(float));
+	return fVal;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+void GfaBufSetUnaligned_float(void *pData, float fVal)
+{
+	uint8_t *p1 = (uint8_t*)pData;
+	uint8_t *p2 = (uint8_t*)&fVal;
+	memcpy(p1, p2, sizeof(float));
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+double GfaBufGetUnaligned_double(const void *pData)
+{
+	double fVal;
+	uint8_t *p1 = (uint8_t*)pData;
+	uint8_t *p2 = (uint8_t*)&fVal;
+	memcpy(p2, p1, sizeof(double));
+	return fVal;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+void GfaBufSetUnaligned_double(void *pData, double fVal)
+{
+	uint8_t *p1 = (uint8_t*)pData;
+	uint8_t *p2 = (uint8_t*)&fVal;
+	memcpy(p1, p2, sizeof(double));
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 32 - 0
gfamodbusrtucom/distribute.cmd

@@ -0,0 +1,32 @@
+@echo off
+set PRJDIR=%~dp0
+set CONFIG=%1
+set LIBMAJOR=1
+set LIBMINOR=0
+set LIBBASENAME=gfambrtucom
+set GFALIBS=%GfATivaLibsRoot%
+set LIBNAME=%LIBBASENAME%.%LIBMAJOR%.%LIBMINOR%
+set LIBDIR=%GFALIBS%\%LIBNAME%\lib\ccs\%CONFIG%
+set INCDIR=%GFALIBS%\include
+set SRCDIR=%GFALIBS%\%LIBNAME%\src
+set OUTDIR=%PRJDIR%%CONFIG%
+
+mkdir "%LIBDIR%" 1>nul 2>&1
+mkdir "%INCDIR%" 1>nul 2>&1
+mkdir "%SRCDIR%" 1>nul 2>&1
+
+copy /Y "%OUTDIR%\%LIBBASENAME%.lib" "%LIBDIR%"
+copy /Y "%PRJDIR%%LIBBASENAME%.h" "%INCDIR%"
+copy /Y "%PRJDIR%*.c" "%SRCDIR%"
+
+set PRJDIR=
+set CONFIG=
+set LIBMAJOR=
+set LIBMINOR=
+set LIBBASENAME=
+set LIBNAME=
+set GFALIBS=
+set INCDIR=
+set SRCDIR=
+set LIBDIR=
+set OUTDIR=

+ 483 - 0
gfamodbusrtucom/fifo.c

@@ -0,0 +1,483 @@
+#include <string.h>
+#include <gfambrtucom.h>
+#include "driverlib/sw_crc.h"
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define FIFO_COUNT								2
+#define FIFO_BUFFER_SIZE						256
+#define FIFO_BUFFER_MASK						(FIFO_BUFFER_SIZE - 1)
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _FIFOHDR
+{
+	volatile size_t nReadPtr;
+	volatile size_t nWritePtr;
+	volatile size_t nCbData;
+	size_t nCbSize;
+	size_t nBufferMask;
+	volatile uint32_t nFlags;
+	FIFO_BACKEND backend;
+}FIFOHDR, *LPFIFOHDR;
+typedef const FIFOHDR *LPCFIFOHDR;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _FIFO
+{
+	FIFOHDR hdr;
+	uint8_t fifo[FIFO_BUFFER_SIZE];
+}FIFO, *LPFIFO;
+typedef const FIFO *LPCFIFO;
+
+/////////////////////////////////////////////////////////////////////////////
+
+static FIFO g_fifo[FIFO_COUNT];
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+static int _IsPowerOf2(size_t x)
+{
+	return x && !(x & (x - 1));
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+HFIFO FifoCreate(int nFifoIndex, LPCFIFO_BACKEND pBackend)
+{
+	LPFIFO p;
+	if((nFifoIndex <  0) || (nFifoIndex >= FIFO_COUNT))
+		return NULL;
+	if(!_IsPowerOf2(FIFO_BUFFER_SIZE))
+		return NULL;
+	p = &g_fifo[nFifoIndex];
+	memset(p, 0, sizeof(FIFO));
+	p->hdr.nCbSize		= FIFO_BUFFER_SIZE;
+	p->hdr.nBufferMask	= FIFO_BUFFER_MASK;
+
+	memcpy(&p->hdr.backend, pBackend, sizeof(FIFO_BACKEND));
+	return (HFIFO)p;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void FifoRelease(HFIFO hFifo)
+{
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void FifoReset(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+	pf->hdr.nReadPtr	= 0;
+	pf->hdr.nWritePtr	= 0;
+	pf->hdr.nCbData		= 0;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		(*pf->hdr.backend.pfnLockBackend)(bPrevLocked);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t FifoRead(HFIFO hFifo, void *pData, size_t nCbData, bool bLock)
+{
+	size_t nToRead;
+	uint8_t *pByte = (uint8_t*)pData;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		(*pf->hdr.backend.pfnLockBackend)(false);
+
+	for(nToRead = nCbData; nCbData; --nCbData)
+	{
+		if((pf->hdr.nWritePtr == pf->hdr.nReadPtr) && !pf->hdr.nCbData)
+			break;
+		*pByte++ = pf->fifo[pf->hdr.nReadPtr++];
+		pf->hdr.nReadPtr &= pf->hdr.nBufferMask;
+		pf->hdr.nCbData--;
+	}
+
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		(*pf->hdr.backend.pfnLockBackend)(true);
+
+	return nToRead - nCbData;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t FifoWrite(HFIFO hFifo, const void *pData, size_t nCbData, bool bLock)
+{
+	size_t nToWrite;
+	const uint8_t *pByte = (const uint8_t*)pData;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		(*pf->hdr.backend.pfnLockBackend)(false);
+
+	for(nToWrite = nCbData; nCbData; --nCbData)
+	{
+		if((pf->hdr.nCbData == pf->hdr.nCbSize))
+			break;
+		pf->fifo[pf->hdr.nWritePtr++] = *pByte++;
+		pf->hdr.nWritePtr &= pf->hdr.nBufferMask;
+		pf->hdr.nCbData++;
+	}
+
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		(*pf->hdr.backend.pfnLockBackend)(true);
+
+	return nToWrite - nCbData;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoPop(HFIFO hFifo, uint8_t *b, bool bLock)
+{
+	bool bRet;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		(*pf->hdr.backend.pfnLockBackend)(false);
+
+		if((bRet = !!pf->hdr.nCbData))
+		{
+			*b = pf->fifo[pf->hdr.nReadPtr++];
+			pf->hdr.nReadPtr &= pf->hdr.nBufferMask;
+			pf->hdr.nCbData--;
+		}
+
+		(*pf->hdr.backend.pfnLockBackend)(true);
+	}
+	else
+	{
+		if((bRet = !!pf->hdr.nCbData))
+		{
+			*b = pf->fifo[pf->hdr.nReadPtr++];
+			pf->hdr.nReadPtr &= pf->hdr.nBufferMask;
+			pf->hdr.nCbData--;
+		}
+	}
+
+	return bRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoPush(HFIFO hFifo, uint8_t b, bool bLock)
+{
+	bool bRet;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		(*pf->hdr.backend.pfnLockBackend)(false);
+
+		if((bRet = (pf->hdr.nCbData < pf->hdr.nCbSize)))
+		{
+			pf->fifo[pf->hdr.nWritePtr++] = b;
+			pf->hdr.nWritePtr &= pf->hdr.nBufferMask;
+			pf->hdr.nCbData++;
+		}
+
+		(*pf->hdr.backend.pfnLockBackend)(true);
+	}
+	else
+	{
+		if((bRet = (pf->hdr.nCbData < pf->hdr.nCbSize)))
+		{
+			pf->fifo[pf->hdr.nWritePtr++] = b;
+			pf->hdr.nWritePtr &= pf->hdr.nBufferMask;
+			pf->hdr.nCbData++;
+		}
+	}
+
+	return bRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t FifoPeek(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked;
+	size_t nAvail;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+		nAvail = pf->hdr.nCbData;
+		if(bPrevLocked)
+			(*pf->hdr.backend.pfnLockBackend)(true);
+		return nAvail;
+	}
+	else
+		return pf->hdr.nCbData;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoCanWrite(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked, bCanWrite;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+		bCanWrite = (pf->hdr.nWritePtr != pf->hdr.nReadPtr) || !pf->hdr.nCbData;
+		if(bPrevLocked)
+			(*pf->hdr.backend.pfnLockBackend)(true);
+		return bCanWrite;
+	}
+	else
+		return (pf->hdr.nWritePtr != pf->hdr.nReadPtr) || !pf->hdr.nCbData;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoEmpty(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked, bEmpty;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+		bEmpty = !pf->hdr.nCbData;
+		if(bPrevLocked)
+			(*pf->hdr.backend.pfnLockBackend)(true);
+		return bEmpty;
+	}
+	else
+		return !pf->hdr.nCbData;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoRxPrepare(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked, bRet = false;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(pf->hdr.backend.pfnRxPrepare)
+	{
+		if(bLock && pf->hdr.backend.pfnLockBackend)
+		{
+			bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+			bRet = (*pf->hdr.backend.pfnRxPrepare)();
+			if(bPrevLocked)
+				(*pf->hdr.backend.pfnLockBackend)(true);
+		}
+		else
+			bRet = (*pf->hdr.backend.pfnRxPrepare)();
+	}
+
+	return bRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void FifoRxStart(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(pf->hdr.backend.pfnRxStart)
+	{
+		if(bLock && pf->hdr.backend.pfnLockBackend)
+		{
+			bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+			(*pf->hdr.backend.pfnRxStart)();
+			if(bPrevLocked)
+				(*pf->hdr.backend.pfnLockBackend)(true);
+		}
+		else
+			(*pf->hdr.backend.pfnRxStart)();
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoRxFinalize(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked, bRet = false;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(pf->hdr.backend.pfnRxFinalize)
+	{
+		if(bLock && pf->hdr.backend.pfnLockBackend)
+		{
+			bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+			bRet = (*pf->hdr.backend.pfnRxFinalize)();
+			if(bPrevLocked)
+				(*pf->hdr.backend.pfnLockBackend)(true);
+		}
+		else
+			bRet = (*pf->hdr.backend.pfnRxFinalize)();
+	}
+
+	return bRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoTxPrepare(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked, bRet = false;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(pf->hdr.backend.pfnTxPrepare)
+	{
+		if(bLock && pf->hdr.backend.pfnLockBackend)
+		{
+			bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+			bRet = (*pf->hdr.backend.pfnTxPrepare)();
+			if(bPrevLocked)
+				(*pf->hdr.backend.pfnLockBackend)(true);
+		}
+		else
+			bRet = (*pf->hdr.backend.pfnTxPrepare)();
+	}
+
+	return bRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void FifoTxStart(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(pf->hdr.backend.pfnTxStart)
+	{
+		if(bLock && pf->hdr.backend.pfnLockBackend)
+		{
+			bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+			(*pf->hdr.backend.pfnTxStart)();
+			if(bPrevLocked)
+				(*pf->hdr.backend.pfnLockBackend)(true);
+		}
+		else
+			(*pf->hdr.backend.pfnTxStart)();
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool FifoTxFinalize(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked, bRet = false;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(pf->hdr.backend.pfnTxFinalize)
+	{
+		if(bLock && pf->hdr.backend.pfnLockBackend)
+		{
+			bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+			bRet = (*pf->hdr.backend.pfnTxFinalize)();
+			if(bPrevLocked)
+				(*pf->hdr.backend.pfnLockBackend)(true);
+		}
+		else
+			bRet = (*pf->hdr.backend.pfnTxFinalize)();
+	}
+
+	return bRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void FifoSetFlags(HFIFO hFifo, uint32_t nFlags, bool bLock)
+{
+	bool bPrevLocked;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+		pf->hdr.nFlags |= nFlags;
+		if(bPrevLocked)
+			(*pf->hdr.backend.pfnLockBackend)(true);
+	}
+	else
+		pf->hdr.nFlags |= nFlags;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void FifoClearFlags(HFIFO hFifo, uint32_t nFlags, bool bLock)
+{
+	bool bPrevLocked;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+		pf->hdr.nFlags &= ~nFlags;
+		if(bPrevLocked)
+			(*pf->hdr.backend.pfnLockBackend)(true);
+	}
+	else
+		pf->hdr.nFlags &= ~nFlags;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+uint32_t FifoGetFlags(HFIFO hFifo, bool bLock)
+{
+	uint32_t nFlags;
+	bool bPrevLocked;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+		nFlags = pf->hdr.nFlags;
+		if(bPrevLocked)
+			(*pf->hdr.backend.pfnLockBackend)(true);
+		return nFlags;
+	}
+	else
+		return pf->hdr.nFlags;
+}
+
+bool FifoMatchFlags(HFIFO hFifo, uint32_t nFlags, bool bLock)
+{
+	bool bMatch;
+	bool bPrevLocked;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+	{
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+		bMatch = (pf->hdr.nFlags & nFlags) == nFlags;
+		if(bPrevLocked)
+			(*pf->hdr.backend.pfnLockBackend)(true);
+		return bMatch;
+	}
+	else
+		return (pf->hdr.nFlags & nFlags) == nFlags;
+}
+
+uint16_t FifoCalcCRC(HFIFO hFifo, bool bLock)
+{
+	bool bPrevLocked = false;
+	register LPFIFO pf = (LPFIFO)hFifo;
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		bPrevLocked = (*pf->hdr.backend.pfnLockBackend)(false);
+
+	if(!pf->hdr.nCbData)
+	{
+		if(bLock && pf->hdr.backend.pfnLockBackend)
+			(*pf->hdr.backend.pfnLockBackend)(bPrevLocked);
+		return 0;
+	}
+
+	size_t nCbData	= pf->hdr.nCbData;
+	size_t nReadPtr	= pf->hdr.nReadPtr;
+	uint8_t b;
+	uint16_t nCrcSw = 0xFFFF;
+
+	while(nCbData--)			// calculate the CRC
+	{
+		b = pf->fifo[nReadPtr++];
+		nReadPtr &= pf->hdr.nBufferMask;
+		nCrcSw = Crc16(nCrcSw, &b, 1);
+	}
+
+	if(bLock && pf->hdr.backend.pfnLockBackend)
+		(*pf->hdr.backend.pfnLockBackend)(bPrevLocked);
+
+	return nCrcSw;
+}

+ 294 - 0
gfamodbusrtucom/gfambrtucom.h

@@ -0,0 +1,294 @@
+// gfambrtucom.h :
+//
+
+#if !defined(AGD_GFAMODBUS_H__C0642473_3513_4FB4_9D7B_F81E8ACC2C34__INCLUDED_)
+#define AGD_GFAMODBUS_H__C0642473_3513_4FB4_9D7B_F81E8ACC2C34__INCLUDED_
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif	//	__cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// gfambrtucom.h - Declarations:
+
+#ifndef __BYTE_ORDER__
+	#define __ORDER_LITTLE_ENDIAN__			1234
+	#define __ORDER_BIG_ENDIAN__			4321
+	#define __ORDER_PDP_ENDIAN__			3412
+
+	#if defined(__little_endian__)
+		#define __BYTE_ORDER__				__ORDER_LITTLE_ENDIAN__
+	#elif defined(__big_endian__)
+		#define __BYTE_ORDER__				__ORDER_BIG_ENDIAN__
+	#else
+		#error No endianess defined!
+	#endif	//	__LITTLE_ENDIAN__
+#endif	//	__BYTE_ORDER__
+
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _countof
+#define _countof(a)							(sizeof(a) / sizeof(*a))
+#endif	//	_countof
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Modbus RTU common defines
+
+#define MB_FUNC_READ_COIL_STATUS						((uint8_t)0x01)
+#define MB_FUNC_READ_INPUT_STATUS						((uint8_t)0x02)
+#define MB_FUNC_READ_HOLDING_REGISTERS					((uint8_t)0x03)
+#define MB_FUNC_READ_INPUT_REGISTERS					((uint8_t)0x04)
+#define MB_FUNC_FORCE_SINGLE_COIL						((uint8_t)0x05)
+#define MB_FUNC_PRESET_SINGLE_REGISTER					((uint8_t)0x06)
+#define MB_FUNC_READ_EXCEPTION_STATUS					((uint8_t)0x07)
+#define MB_FUNC_DIAGNOSTIC								((uint8_t)0x08)
+#define MB_FUNC_FETCH_COMM_EVENT_CTR					((uint8_t)0x0B)
+#define MB_FUNC_FETCH_COMM_EVENT_LOG					((uint8_t)0x0C)
+#define MB_FUNC_FORCE_MULTIPLE_COILS					((uint8_t)0x0F)
+#define MB_FUNC_WRITE_MULTIPLE_REGISTERS				((uint8_t)0x10)
+#define MB_FUNC_REPORT_SLAVE_ID							((uint8_t)0x11)
+#define MB_FUNC_READ_GENERAL_REFERENCE					((uint8_t)0x14)
+#define MB_FUNC_WRITE_GENERAL_REFERENCE					((uint8_t)0x15)
+#define MB_FUNC_MASK_WRITE_4X_REGISTER					((uint8_t)0x16)
+#define MB_FUNC_READ_WRITE_4X_REGISTERS					((uint8_t)0x17)
+#define MB_FUNC_READ_FIFO_QUEUE							((uint8_t)0x18)
+
+#define MB_FUNC_ERROR_FLAG								((uint8_t)0x80)
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define MB_SUBFUNC_RETURN_QUERY_DATA					((uint16_t)0x00)
+#define MB_SUBFUNC_RESTART_COMM_OPTION					((uint16_t)0x01)
+#define MB_SUBFUNC_RETURN_DIAGNOSTIC_REGISTER			((uint16_t)0x02)
+#define MB_SUBFUNC_FORCE_LISTEN_ONLY_MODE				((uint16_t)0x04)
+#define MB_SUBFUNC_CLEAR_CTRS_AND_DIAGNOSTIC_REG		((uint16_t)0x0A)
+#define MB_SUBFUNC_RETURN_BUS_MESSAGE_COUNT				((uint16_t)0x0B)
+#define MB_SUBFUNC_RETURN_BUS_COMM_ERROR_COUNT			((uint16_t)0x0C)
+#define MB_SUBFUNC_RETURN_BUS_EXCEPTION_ERROR_COUNT		((uint16_t)0x0D)
+#define MB_SUBFUNC_RETURN_SLAVE_MESSAGE_COUNT			((uint16_t)0x0E)
+#define MB_SUBFUNC_RETURN_SLAVE_NO_RESPONSE_COUNT		((uint16_t)0x0F)
+#define MB_SUBFUNC_RETURN_SLAVE_NAK_COUNT				((uint16_t)0x10)
+#define MB_SUBFUNC_RETURN_SLAVE_BUSY_COUNT				((uint16_t)0x11)
+#define MB_SUBFUNC_RETURN_BUS_CHAR_OVERRUN_COUNT		((uint16_t)0x12)
+#define MB_SUBFUNC_RETURN_OVERRUN_ERROR_COUNT			((uint16_t)0x13)
+#define MB_SUBFUNC_CLEAR_OVERRUN_COUNTER_AND_FLAG		((uint16_t)0x14)
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define MB_ERROR_ILLEGAL_FUNCTION						((uint8_t)0x01)
+#define MB_ERROR_ILLEGAL_DATA_ADDRESS					((uint8_t)0x02)
+#define MB_ERROR_ILLEGAL_DATA_VALUE						((uint8_t)0x03)
+#define MB_ERROR_SLAVE_DEVICE_FAILURE					((uint8_t)0x04)
+#define MB_ERROR_ACKNOWLEDGE							((uint8_t)0x05)
+#define MB_ERROR_SLAVE_DEVICE_BUSY						((uint8_t)0x06)
+#define MB_ERROR_NEGATIVE_ACKNOWLEDGE					((uint8_t)0x07)
+#define MB_ERROR_MEMORY_PARITY_ERROR					((uint8_t)0x08)
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define MODBUS_BROADCAST_ADDRESS						0
+#define MODBUS_MAX_SLAVE_ID								247
+
+#define MODBUS_MAX_READ_BITS							2000
+#define MODBUS_MAX_WRITE_BITS							1968
+#define MODBUS_MAX_READ_REGISTERS						125
+#define MODBUS_MAX_WRITE_REGISTERS						123
+#define MODBUS_MAX_RW_WRITE_REGISTERS					121
+#define MODBUS_MAX_DATA_PAYLOAD							252
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _MODBUS_RTU_PDU
+{
+	uint8_t func;
+	union
+	{
+		uint8_t  b[254];
+		uint16_t w[127];
+	};
+}__attribute__ ((__packed__)) MODBUS_RTU_PDU, *LPMODBUS_RTU_PDU;
+typedef const MODBUS_RTU_PDU *LPCMODBUS_RTU_PDU;
+
+typedef struct _MODBUS_RTU_ADU
+{
+	uint8_t slaveID;
+	MODBUS_RTU_PDU pdu;
+}__attribute__ ((__aligned__(2),__packed__)) MODBUS_RTU_ADU, *LPMODBUS_RTU_ADU;
+typedef const MODBUS_RTU_ADU *LPCMODBUS_RTU_ADU;
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Fifo
+
+typedef void									*HFIFO;
+typedef bool (*PFN_INT_ENABLE)(bool);
+typedef bool (*PFN_RX_PREPARE)(void);
+typedef void (*PFN_RX_START)(void);
+typedef bool (*PFN_RX_FINALIZE)(void);
+typedef bool (*PFN_TX_PREPARE)(void);
+typedef void (*PFN_TX_START)(void);
+typedef bool (*PFN_TX_FINALIZE)(void);
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _FIFO_BACKEND
+{
+	PFN_INT_ENABLE	pfnLockBackend;
+	PFN_RX_PREPARE	pfnRxPrepare;
+	PFN_RX_START	pfnRxStart;
+	PFN_RX_FINALIZE	pfnRxFinalize;
+	PFN_TX_PREPARE	pfnTxPrepare;
+	PFN_TX_START	pfnTxStart;
+	PFN_TX_FINALIZE	pfnTxFinalize;
+}FIFO_BACKEND, *LPFIFO_BACKEND;
+typedef const FIFO_BACKEND *LPCFIFO_BACKEND;
+
+/////////////////////////////////////////////////////////////////////////////
+
+HFIFO		FifoCreate(int nFifoIndex, LPCFIFO_BACKEND pBackend);
+void		FifoRelease(HFIFO hFifo);
+void		FifoReset(HFIFO hFifo, bool bLock);
+size_t		FifoRead(HFIFO hFifo, void *pData, size_t nCbData, bool bLock);
+size_t		FifoWrite(HFIFO hFifo, const void *pData, size_t nCbData, bool bLock);
+bool		FifoPop(HFIFO hFifo, uint8_t *b, bool bLock);
+bool		FifoPush(HFIFO hFifo, uint8_t b, bool bLock);
+size_t		FifoPeek(HFIFO hFifo, bool bLock);
+bool		FifoCanWrite(HFIFO hFifo, bool bLock);
+bool		FifoEmpty(HFIFO hFifo, bool bLock);
+void		FifoSetFlags(HFIFO hFifo, uint32_t nFlags, bool bLock);
+void		FifoClearFlags(HFIFO hFifo, uint32_t nFlags, bool bLock);
+uint32_t	FifoGetFlags(HFIFO hFifo, bool bLock);
+bool		FifoMatchFlags(HFIFO hFifo, uint32_t nFlags, bool bLock);
+bool		FifoRxPrepare(HFIFO hFifo, bool bLock);
+void		FifoRxStart(HFIFO hFifo, bool bLock);
+bool		FifoRxFinalize(HFIFO hFifo, bool bLock);
+bool		FifoTxPrepare(HFIFO hFifo, bool bLock);
+void		FifoTxStart(HFIFO hFifo, bool bLock);
+bool		FifoTxFinalize(HFIFO hFifo, bool bLock);
+uint16_t	FifoCalcCRC(HFIFO hFifo, bool bLock);
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// UART
+
+typedef enum _UART_Parity
+{
+	P_None,
+	P_Even,
+	P_Odd,
+	P_Zero,
+	P_One
+}UART_Parity;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _UART_CONFIG
+{
+	uint32_t	P_UART_BASE;
+	uint32_t	P_UART_BASE_SYSCTL;
+	uint32_t	P_UART_PORT;
+	uint32_t	P_UART_PORT_SYSCTL;
+	uint32_t	P_UART_RX_PIN;
+	uint32_t	P_UART_RX_PIN_MUX;
+	uint32_t	P_UART_TX_PIN;
+	uint32_t	P_UART_TX_PIN_MUX;
+	uint32_t	P_UART_INT;
+	uint8_t		P_UART_INT_PRIORITY;
+	uint32_t	P_EN_485_PORT_SYSCTL;
+	uint32_t	P_EN_485_PORT;
+	uint32_t	P_EN_485_PIN;
+	uint32_t	nBaud;
+	int			nDatabits;
+	int			nStopbits;
+	UART_Parity	parity;
+	int			nFifoIndexRx;
+	int			nFifoIndexTx;
+}UART_CONFIG, *LPUART_CONFIG;
+typedef const UART_CONFIG *LPCUART_CONFIG;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _UART_STATUS_COUNTERS
+{
+	uint64_t nCharsReceived;
+	uint64_t nCharsTransmitted;
+	uint32_t nOverrunErrors;
+	uint32_t nBreakErrors;
+	uint32_t nParityErrors;
+	uint32_t nFramingErrors;
+}UART_STATUS_COUNTERS, *LPUART_STATUS_COUNTERS;
+typedef const UART_STATUS_COUNTERS *LPCUART_STATUS_COUNTERS;
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define MB_RTU_FLAG_FRAME_GAP_DETECT							0x00000001
+#define MB_RTU_FLAG_TRANSMIT_IN_PROGRESS						0x00000002
+#define MB_RTU_FLAG_TRANSMIT_END								0x00000004
+#define MB_RTU_FLAG_IGNORE_FRAME								0x00000008
+#define MB_RTU_FLAG_OVERRUN_ERROR								0x00000010
+#define MB_RTU_FLAG_BREAK_ERROR									0x00000020
+#define MB_RTU_FLAG_PARITY_ERROR								0x00000040
+#define MB_RTU_FLAG_FRAMING_ERROR								0x00000080
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool	MB_UART_Init(LPCUART_CONFIG pCfg);
+void	MB_UART_Release(void);
+HFIFO	MB_UART_GetRxFifo(void);
+HFIFO	MB_UART_GetTxFifo(void);
+void	MB_UART_GetStatusCounters(LPUART_STATUS_COUNTERS pSc);
+void	MB_UART_ResetStatusCounters(void);
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// Buffer helper functions
+
+void		GfaBufCpyUnaligned_uint16_LE(void *pTo, const void *pFrom, size_t nCntWords);
+void		GfaBufCpyUnaligned_uint16_BE(void *pTo, const void *pFrom, size_t nCntWords);
+void		GfaBufCpyUnaligned_uint32_LE(void *pTo, const void *pFrom, size_t nCntDWords);
+void		GfaBufCpyUnaligned_uint32_BE(void *pTo, const void *pFrom, size_t nCntDWords);
+uint16_t	GfaBufGetUnaligned_uint16_LE(const void *pData);
+uint16_t	GfaBufGetUnaligned_uint16_BE(const void *pData);
+void		GfaBufSetUnaligned_uint16_LE(void *pData, uint16_t nVal);
+void		GfaBufSetUnaligned_uint16_BE(void *pData, uint16_t nVal);
+uint32_t	GfaBufGetUnaligned_uint32_LE(const void *pData);
+uint32_t	GfaBufGetUnaligned_uint32_BE(const void *pData);
+void		GfaBufSetUnaligned_uint32_LE(void *pData, uint16_t nVal);
+void		GfaBufSetUnaligned_uint32_BE(void *pData, uint16_t nVal);
+float		GfaBufGetUnaligned_float(const void *pData);
+void		GfaBufSetUnaligned_float(void *pData, float fVal);
+double		GfaBufGetUnaligned_double(const void *pData);
+void		GfaBufSetUnaligned_double(void *pData, double fVal);
+
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define GfaBufCpyUnaligned_uint16		GfaBufCpyUnaligned_uint16_LE
+#define GfaBufCpyUnaligned_uint32		GfaBufCpyUnaligned_uint32_LE
+#define GfaBufGetUnaligned_uint16		GfaBufGetUnaligned_uint16_LE
+#define GfaBufSetUnaligned_uint16		GfaBufSetUnaligned_uint16_LE
+#define GfaBufGetUnaligned_uint32		GfaBufGetUnaligned_uint32_LE
+#define GfaBufSetUnaligned_uint32		GfaBufSetUnaligned_uint32_LE
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define GfaBufCpyUnaligned_uint16		GfaBufCpyUnaligned_uint16_BE
+#define GfaBufCpyUnaligned_uint32		GfaBufCpyUnaligned_uint32_BE
+#define GfaBufGetUnaligned_uint16		GfaBufGetUnaligned_uint16_BE
+#define GfaBufSetUnaligned_uint16		GfaBufSetUnaligned_uint16_BE
+#define GfaBufGetUnaligned_uint32		GfaBufGetUnaligned_uint32_BE
+#define GfaBufSetUnaligned_uint32		GfaBufSetUnaligned_uint32_BE
+#endif	//	__BYTE_ORDER__
+
+
+/////////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+}
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_GFAMODBUS_H__C0642473_3513_4FB4_9D7B_F81E8ACC2C34__INCLUDED_)

+ 478 - 0
gfamodbusrtucom/mbuart.c

@@ -0,0 +1,478 @@
+#include <stdio.h>
+#include <string.h>
+#include <gfambrtucom.h>
+#include "inc/hw_types.h"
+#include "inc/hw_uart.h"
+#include "driverlib/interrupt.h"
+#include "driverlib/sysctl.h"
+#include "driverlib/gpio.h"
+#include "driverlib/uart.h"
+#include <gfautils.h>
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+static HFIFO					g_hFifoTX = NULL, g_hFifoRX = NULL;
+static volatile uint32_t		g_nTxEchoCount	= 0;
+static volatile uint64_t		g_nTimerTick	= 0;
+static UART_STATUS_COUNTERS		g_statCnt	= {0};
+static UART_CONFIG				g_uartCfg = {0};
+static uint64_t					g_MODBUS_RTU_FRAME_TIMEOUT_US = 0;
+static uint64_t					g_MODBUS_RTU_CHAR_TIMEOUT_US = 0;
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define UART_BASE							g_uartCfg.P_UART_BASE
+#define UART_BASE_SYSCTL					g_uartCfg.P_UART_BASE_SYSCTL
+#define UART_PORT							g_uartCfg.P_UART_PORT
+#define UART_PORT_SYSCTL					g_uartCfg.P_UART_PORT_SYSCTL
+#define UART_RX_PIN							g_uartCfg.P_UART_RX_PIN
+#define UART_RX_PIN_MUX						g_uartCfg.P_UART_RX_PIN_MUX
+#define UART_TX_PIN							g_uartCfg.P_UART_TX_PIN
+#define UART_TX_PIN_MUX						g_uartCfg.P_UART_TX_PIN_MUX
+#define UART_INT							g_uartCfg.P_UART_INT
+#define EN_485_PORT_SYSCTL					g_uartCfg.P_EN_485_PORT_SYSCTL
+#define EN_485_PORT							g_uartCfg.P_EN_485_PORT
+#define EN_485_PIN							g_uartCfg.P_EN_485_PIN
+#define MODBUS_RTU_UART_INT_PRIORITY		g_uartCfg.P_UART_INT_PRIORITY
+
+#define MODBUS_RTU_FRAME_TIMEOUT_US			g_MODBUS_RTU_FRAME_TIMEOUT_US;
+#define MODBUS_RTU_CHAR_TIMEOUT_US			g_MODBUS_RTU_CHAR_TIMEOUT_US;
+
+#define IS_INT_ENABLED(f)					!!(HWREG(UART_BASE + UART_O_IM) & (f))
+#define INT_MASK_REGISTER					HWREG(UART_BASE + UART_O_IM)
+
+/////////////////////////////////////////////////////////////////////////////
+
+static bool _TimerElapsed(void)
+{
+	struct timeval tv;
+	return g_nTimerTick < GfaSystickTimeval2Us(GfaSystickGetUsClock(&tv));
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void _FrameTimerStart(void)
+{
+	struct timeval tv;
+	g_nTimerTick = GfaSystickTimeval2Us(GfaSystickGetUsClock(&tv)) + MODBUS_RTU_FRAME_TIMEOUT_US;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void _CharTimerStart(void)
+{
+	struct timeval tv;
+	g_nTimerTick = GfaSystickTimeval2Us(GfaSystickGetUsClock(&tv)) + MODBUS_RTU_CHAR_TIMEOUT_US;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static bool _OnRxFinalize(void)
+{
+	_FrameTimerStart();
+	return true;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static bool _OnTxPrepare(void)
+{
+	return _TimerElapsed();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void _OnTxStart(void)
+{
+	uint8_t b;
+
+	if(!UARTBusy(UART_BASE) && FifoPop(g_hFifoTX, &b, false))
+	{
+		g_nTxEchoCount++;
+		GPIOPinWrite(EN_485_PORT, EN_485_PIN, EN_485_PIN); // enable the bus
+		UARTIntEnable(UART_BASE, UART_INT_TX);
+		++g_statCnt.nCharsTransmitted;
+		UARTCharPutNonBlocking(UART_BASE, b);
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static bool _OnTxFinalize(void)
+{
+	return !UARTBusy(UART_BASE) && _TimerElapsed();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void UART_RX_ISR(void)
+{
+	uint8_t b;
+
+	if(g_nTxEchoCount)
+	{
+		UARTCharGetNonBlocking(UART_BASE);	// discard transmit echo chars
+		_FrameTimerStart();
+		--g_nTxEchoCount;
+		return;
+	}
+
+	++g_statCnt.nCharsReceived;
+
+	if(_TimerElapsed()) // check, if the time since the last character was received, is greater than 3.5/1.5 characters
+	{
+		FifoReset(g_hFifoRX, false);
+		FifoSetFlags(g_hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, false);
+		if(FifoMatchFlags(g_hFifoRX, MB_RTU_FLAG_IGNORE_FRAME, false))
+		{
+			FifoClearFlags(g_hFifoRX, MB_RTU_FLAG_IGNORE_FRAME, false);
+		}
+		FifoClearFlags(g_hFifoTX, MB_RTU_FLAG_TRANSMIT_END, false);
+	}
+	else if(FifoMatchFlags(g_hFifoRX, MB_RTU_FLAG_IGNORE_FRAME, false))
+	{
+		UARTCharGetNonBlocking(UART_BASE);	// discard chars
+		_FrameTimerStart();
+		return;
+	}
+	else if(FifoMatchFlags(g_hFifoTX, MB_RTU_FLAG_TRANSMIT_END, false))
+	{
+		UARTCharGetNonBlocking(UART_BASE);	// discard chars
+		FifoReset(g_hFifoRX, false);
+		return;
+	}
+
+	b = (uint8_t)UARTCharGetNonBlocking(UART_BASE);
+	FifoPush(g_hFifoRX, b, false);
+	_CharTimerStart();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void UART_TX_ISR(void)
+{
+	uint8_t b;
+
+	if(FifoPop(g_hFifoTX, &b, false))
+	{
+		++g_nTxEchoCount;
+		UARTCharPutNonBlocking(UART_BASE, b);
+		++g_statCnt.nCharsTransmitted;
+	}
+	else
+	{
+		UARTIntDisable(UART_BASE, UART_INT_TX);
+		GPIOPinWrite(EN_485_PORT, EN_485_PIN, 0); // disable the bus
+		FifoClearFlags(g_hFifoTX, MB_RTU_FLAG_TRANSMIT_IN_PROGRESS, false);
+		FifoSetFlags(g_hFifoTX, MB_RTU_FLAG_TRANSMIT_END, false);
+		_FrameTimerStart();
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void UART_OE_ISR(void)
+{
+	++g_statCnt.nOverrunErrors;
+	FifoSetFlags(g_hFifoRX, MB_RTU_FLAG_OVERRUN_ERROR, false);
+}
+
+static void UART_BE_ISR(void)
+{
+	++g_statCnt.nBreakErrors;
+	FifoSetFlags(g_hFifoRX, MB_RTU_FLAG_BREAK_ERROR, false);
+}
+
+static void UART_PE_ISR(void)
+{
+	++g_statCnt.nParityErrors;
+	FifoSetFlags(g_hFifoRX, MB_RTU_FLAG_PARITY_ERROR, false);
+}
+
+static void UART_FE_ISR(void)
+{
+	++g_statCnt.nFramingErrors;
+	FifoSetFlags(g_hFifoRX, MB_RTU_FLAG_FRAMING_ERROR, false);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static void UART_ISR(void)
+{
+	uint32_t nStatus = UARTIntStatus(UART_BASE, true);	// Get the interrrupt status.
+    UARTIntClear(UART_BASE, nStatus);					// Clear the asserted interrupts.
+
+    if(nStatus & UART_INT_TX)
+    	UART_TX_ISR();
+    if(nStatus & UART_INT_RX)
+    	UART_RX_ISR();
+	if(nStatus & UART_INT_OE)	// UART Overrun Error
+		UART_OE_ISR();
+	if(nStatus & UART_INT_BE)	// UART Break Error
+		UART_BE_ISR();
+	if(nStatus & UART_INT_PE)	// UART Parity Error
+		UART_PE_ISR();
+	if(nStatus & UART_INT_FE)	// UART Framing Error
+		UART_FE_ISR();
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static bool EnableRxInt(bool bEnable)
+{
+	bool bIsEnabled = IS_INT_ENABLED(UART_INT_RX);
+	if(bEnable && !bIsEnabled)
+		UARTIntEnable(UART_BASE, UART_INT_RX);
+	else if(!bEnable && bIsEnabled)
+		UARTIntDisable(UART_BASE, UART_INT_RX);
+	return bIsEnabled;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static bool EnableTxInt(bool bEnable)
+{
+	bool bIsEnabled = IS_INT_ENABLED(UART_INT_TX);
+	if(bEnable && !bIsEnabled)
+		UARTIntEnable(UART_BASE, UART_INT_TX);
+	else if(!bEnable && bIsEnabled)
+		UARTIntDisable(UART_BASE, UART_INT_TX);
+	return bIsEnabled;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static uint32_t _GetDatabits(int nDatabits)
+{
+	switch(nDatabits)
+	{
+	case 5:
+		return UART_CONFIG_WLEN_5;
+	case 6:
+		return UART_CONFIG_WLEN_6;
+	case 7:
+		return UART_CONFIG_WLEN_7;
+	case 8:
+		return UART_CONFIG_WLEN_8;
+	default:
+		return (uint32_t)-1;
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static uint32_t _GetStopbits(int nStopbits)
+{
+	switch(nStopbits)
+	{
+	case 1:
+		return UART_CONFIG_STOP_ONE;
+	case 2:
+		return UART_CONFIG_STOP_TWO;
+	default:
+		return (uint32_t)-1;
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+static uint32_t _GetParity(UART_Parity parity)
+{
+	switch(parity)
+	{
+	case P_None:
+		return UART_CONFIG_PAR_NONE;
+	case P_Even:
+		return UART_CONFIG_PAR_EVEN;
+	case P_Odd:
+		return UART_CONFIG_PAR_ODD;
+	case P_Zero:
+		return UART_CONFIG_PAR_ZERO;
+	case P_One:
+		return UART_CONFIG_PAR_ONE;
+	default:
+		return (uint32_t)-1;
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+bool MB_UART_Init(LPCUART_CONFIG pCfg)
+{
+	uint32_t nData, nStop, nPar;
+
+	if(!pCfg)
+		return false;
+	memcpy(&g_uartCfg, pCfg, sizeof(g_uartCfg));
+
+	/////////////////////////////////////////////////////////////////////////
+	// validate parameters
+
+	if((nData = _GetDatabits(pCfg->nDatabits)) == (uint32_t)-1)
+		return false;
+	if((nStop = _GetStopbits(pCfg->nStopbits)) == (uint32_t)-1)
+		return false;
+	if((nPar = _GetParity(pCfg->parity)) == (uint32_t)-1)
+		return false;
+
+	/////////////////////////////////////////////////////////////////////////
+	// Fifos
+
+	FIFO_BACKEND backend;
+
+	memset(&backend, 0, sizeof(backend));
+	backend.pfnLockBackend	= EnableTxInt;
+	backend.pfnTxPrepare	= _OnTxPrepare;
+	backend.pfnTxStart		= _OnTxStart;
+	backend.pfnTxFinalize	= _OnTxFinalize;
+
+	if(!(g_hFifoTX = FifoCreate(pCfg->nFifoIndexTx, &backend)))
+		return false;
+
+	memset(&backend, 0, sizeof(backend));
+	backend.pfnLockBackend	= EnableRxInt;
+	backend.pfnRxFinalize	= _OnRxFinalize;
+
+	if(!(g_hFifoRX = FifoCreate(pCfg->nFifoIndexRx, &backend)))
+	{
+		FifoRelease(g_hFifoTX);
+		g_hFifoTX = NULL;
+		return false;
+	}
+
+	/////////////////////////////////////////////////////////////////////////
+	// Timer tick
+
+	g_nTimerTick = 0;
+
+	/////////////////////////////////////////////////////////////////////////
+	// UART
+
+	if(pCfg->nBaud)
+	{
+		g_MODBUS_RTU_FRAME_TIMEOUT_US	= (350000000 / pCfg->nBaud + 5) / 10;
+		g_MODBUS_RTU_CHAR_TIMEOUT_US	= (150000000 / pCfg->nBaud + 5) / 10;
+	}
+	else
+	{
+		// For baud rates greater than 19200 the t1.5 and t3.5 timers are implemented
+		// using fixed values, for t1.5 that is 750μs, for t3.5 1.750ms
+		g_MODBUS_RTU_FRAME_TIMEOUT_US	= 1750;
+		g_MODBUS_RTU_CHAR_TIMEOUT_US	= 750;
+	}
+
+    // Enable and setup the PORT that is used for the UART
+    SysCtlPeripheralEnable(UART_PORT_SYSCTL);
+    while(!SysCtlPeripheralReady(UART_PORT_SYSCTL))
+    	;
+
+    // Enable and setup the PORT that is used for EN_485
+    SysCtlPeripheralEnable(EN_485_PORT_SYSCTL);
+    while(!SysCtlPeripheralReady(EN_485_PORT_SYSCTL))
+    	;
+
+    GPIOPinTypeGPIOOutput(EN_485_PORT, EN_485_PIN);
+
+    // Enable the uart used for RS485 interface
+	SysCtlPeripheralEnable(UART_BASE_SYSCTL);
+    while(!SysCtlPeripheralReady(UART_BASE_SYSCTL))
+    	;
+
+	// Configure the UART pins
+	GPIOPinConfigure(UART_RX_PIN_MUX);
+	GPIOPinConfigure(UART_TX_PIN_MUX);
+	GPIOPinTypeUART(UART_PORT, UART_RX_PIN | UART_TX_PIN);
+
+	// Initialize the UART. Set the baud rate, number of data bits, turn off
+	// parity, number of stop bits, and stick mode.
+	UARTConfigSetExpClk(UART_BASE, SysCtlClockGet(), pCfg->nBaud, nData | nStop | nPar);
+
+	// transmit interrupt is asserted when the transmitter is completely idle
+	UARTTxIntModeSet(UART_BASE, UART_TXINT_MODE_EOT);
+
+	// Enable the UART interrupt.
+	IntPrioritySet(UART_INT, MODBUS_RTU_UART_INT_PRIORITY); // priority must be lower than system tick
+	UARTIntRegister(UART_BASE, UART_ISR);
+	UARTIntEnable(UART_BASE, (UART_INT_RX | UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE));
+
+	// Enable the UART.
+	UARTEnable(UART_BASE);
+	UARTFIFODisable(UART_BASE);
+
+	return true;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void MB_UART_Release(void)
+{
+	UARTIntDisable(UART_BASE, UART_INT_RX | UART_INT_TX | UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE);
+
+	UARTIntUnregister(UART_BASE);
+	UARTDisable(UART_BASE);
+
+	SysCtlPeripheralDisable(UART_BASE_SYSCTL);
+	SysCtlPeripheralDisable(EN_485_PORT_SYSCTL);
+	SysCtlPeripheralDisable(UART_PORT_SYSCTL);
+
+	if(g_hFifoRX)
+	{
+		FifoRelease(g_hFifoRX);
+		g_hFifoRX = NULL;
+	}
+
+	if(g_hFifoTX)
+	{
+		FifoRelease(g_hFifoTX);
+		g_hFifoTX = NULL;
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+HFIFO MB_UART_GetRxFifo(void)
+{
+	return g_hFifoRX;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+HFIFO MB_UART_GetTxFifo(void)
+{
+	return g_hFifoTX;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void MB_UART_GetStatusCounters(LPUART_STATUS_COUNTERS pSc)
+{
+	if(pSc)
+	{
+		uint32_t nIrMask = INT_MASK_REGISTER;
+		UARTIntDisable(UART_BASE, nIrMask);
+		memcpy(pSc, &g_statCnt, sizeof(g_statCnt));
+		UARTIntEnable(UART_BASE, nIrMask);
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void MB_UART_ResetStatusCounters(void)
+{
+	uint32_t nIrMask = INT_MASK_REGISTER;
+	UARTIntDisable(UART_BASE, nIrMask);
+	memset(&g_statCnt, 0, sizeof(g_statCnt));
+	UARTIntEnable(UART_BASE, nIrMask);
+}
+
+
+
+
+
+
+
+
+
+

+ 14 - 0
gfamodbusrtuslv/.ccsproject

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<?ccsproject version="1.0"?>
+<projectOptions>
+	<ccsVersion value="8.3.0"/>
+	<deviceVariant value="Cortex M.TM4C1231E6PZ"/>
+	<deviceFamily value="TMS470"/>
+	<deviceEndianness value="little"/>
+	<codegenToolVersion value="18.1.6.LTS"/>
+	<isElfFormat value="true"/>
+	<createSlaveProjects value=""/>
+	<templateProperties value="id=com.ti.common.project.core.emptyProjectWithMainTemplate"/>
+	<filesToOpen value="main.c"/>
+	<isTargetManual value="false"/>
+</projectOptions>

+ 136 - 0
gfamodbusrtuslv/.cproject

@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+	<storageModule configRelations="2" moduleId="org.eclipse.cdt.core.settings">
+		<cconfiguration id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.925991756">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.925991756" moduleId="org.eclipse.cdt.core.settings" name="Debug">
+				<macros>
+					<stringMacro name="TW_ROOT" type="VALUE_TEXT" value="C:\CCS\TivaWare_C_Series-2.1.4.178"/>
+				</macros>
+				<externalSettings/>
+				<extensions>
+					<extension id="com.ti.ccstudio.binaryparser.CoffParser" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.CoffErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.AsmErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.LinkErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactExtension="lib" artifactName="gfambrtuslv" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.925991756" name="Debug" parent="com.ti.ccstudio.buildDefinitions.TMS470.Debug" postbuildStep="@${PWD}\..\distribute.cmd Debug">
+					<folderInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.925991756." name="/" resourcePath="">
+						<toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.libraryDebugToolchain.1317890125" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.libraryDebugToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianDebug.128108874">
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.1166895921" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
+								<listOptionValue builtIn="false" value="DEVICE_CONFIGURATION_ID=Cortex M.TM4C1231E6PZ"/>
+								<listOptionValue builtIn="false" value="DEVICE_ENDIANNESS=little"/>
+								<listOptionValue builtIn="false" value="OUTPUT_FORMAT=ELF"/>
+								<listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/>
+								<listOptionValue builtIn="false" value="OUTPUT_TYPE=staticLibrary"/>
+							</option>
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.1786982371" name="Compiler version" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.6.LTS" valueType="string"/>
+							<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformDebug.101944179" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformDebug"/>
+							<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderDebug.1162837150" keepEnvironmentInBuildfile="false" name="GNU Make" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderDebug"/>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerDebug.259329704" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerDebug">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.1515815322" name="Target processor version (--silicon_version, -mv)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M4" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.279750028" name="Designate code state, 16-bit (thumb) or 32-bit (--code_state)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.1370130618" name="Application binary interface. (--abi)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.234464" name="Specify floating point support (--float_support)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.FPv4SPD16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.320642850" name="Enable support for GCC extensions (DEPRECATED) (--gcc)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.351454384" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
+									<listOptionValue builtIn="false" value="ccs=&quot;ccs&quot;"/>
+									<listOptionValue builtIn="false" value="PART_TM4C1231E6PZ"/>
+									<listOptionValue builtIn="false" value="__TI_TIME_USES_64=1"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.500055137" name="Debugging model" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.SYMDEBUG__DWARF" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.1735810948" name="Treat diagnostic &lt;id&gt; as warning (--diag_warning, -pdsw)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
+									<listOptionValue builtIn="false" value="225"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.1724475483" name="Emit diagnostic identifier numbers (--display_error_number, -pden)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.1064794425" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.1041753599" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
+									<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+									<listOptionValue builtIn="false" value="${TW_ROOT}"/>
+									<listOptionValue builtIn="false" value="${GfATivaLibsRoot}\include"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.1535779563" name="Little endian code [See 'General' page to edit] (--little_endian, -me)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS.2103499450" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS.115492979" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS.464675680" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS.2018086958" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianDebug.128108874" name="ARM Archiver" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianDebug">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE.691138323" name="Output file" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE" useByScannerDiscovery="false" value="gfambrtuslv.lib" valueType="string"/>
+							</tool>
+						</toolChain>
+					</folderInfo>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+		<cconfiguration id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1938272569">
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1938272569" moduleId="org.eclipse.cdt.core.settings" name="Release">
+				<externalSettings/>
+				<extensions>
+					<extension id="com.ti.ccstudio.binaryparser.CoffParser" point="org.eclipse.cdt.core.BinaryParser"/>
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.CoffErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.AsmErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+					<extension id="com.ti.ccstudio.errorparser.LinkErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+				</extensions>
+			</storageModule>
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+				<configuration artifactExtension="lib" artifactName="${ProjName}" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1938272569" name="Release" parent="com.ti.ccstudio.buildDefinitions.TMS470.Release">
+					<folderInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Release.1938272569." name="/" resourcePath="">
+						<toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.ReleaseToolchain.1146122476" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.ReleaseToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianRelease.1724120075">
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.832970303" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
+								<listOptionValue builtIn="false" value="DEVICE_CONFIGURATION_ID=Cortex M.TM4C1231E6PZ"/>
+								<listOptionValue builtIn="false" value="DEVICE_ENDIANNESS=little"/>
+								<listOptionValue builtIn="false" value="OUTPUT_FORMAT=ELF"/>
+								<listOptionValue builtIn="false" value="CCS_MBS_VERSION=6.1.3"/>
+								<listOptionValue builtIn="false" value="OUTPUT_TYPE=staticLibrary"/>
+							</option>
+							<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.1137298660" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.6.LTS" valueType="string"/>
+							<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformRelease.843360228" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.targetPlatformRelease"/>
+							<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderRelease.270557209" name="GNU Make.Release" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.builderRelease"/>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerRelease.134789695" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.compilerRelease">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.108806280" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M4" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.337939802" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.599497023" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.748588784" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.FLOAT_SUPPORT.FPv4SPD16" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.538410133" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.1959750724" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
+									<listOptionValue builtIn="false" value="ccs=&quot;ccs&quot;"/>
+									<listOptionValue builtIn="false" value="PART_TM4C1231E6PZ"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.800756828" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" useByScannerDiscovery="false" valueType="stringList">
+									<listOptionValue builtIn="false" value="225"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.874602580" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.959663238" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" useByScannerDiscovery="false" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.944620688" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
+									<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
+									<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
+								</option>
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.653474827" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" useByScannerDiscovery="false" value="true" valueType="boolean"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS.1748619592" name="C Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__C_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS.1956837659" name="C++ Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__CPP_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS.2034492048" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM_SRCS"/>
+								<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS.1470926887" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS"/>
+							</tool>
+							<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianRelease.1724120075" name="ARM Archiver" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.library.librarianRelease">
+								<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE.1625963599" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.archiverID.OUTPUT_FILE" useByScannerDiscovery="false" value="${ProjName}.lib" valueType="string"/>
+							</tool>
+						</toolChain>
+					</folderInfo>
+				</configuration>
+			</storageModule>
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+		</cconfiguration>
+	</storageModule>
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
+		<project id="gfambrtuslave.com.ti.ccstudio.buildDefinitions.TMS470.ProjectType.1019892626" name="TMS470" projectType="com.ti.ccstudio.buildDefinitions.TMS470.ProjectType"/>
+	</storageModule>
+	<storageModule moduleId="scannerConfiguration"/>
+	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
+</cproject>

+ 14 - 0
gfamodbusrtuslv/.gitignore

@@ -0,0 +1,14 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
+
+rtf/
+latex/
+html/
+*.bak
+*.tmp
+/Debug/
+/Release/

+ 27 - 0
gfamodbusrtuslv/.project

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>gfambrtuslave</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+			<triggers>full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.ti.ccstudio.core.ccsNature</nature>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+	</natures>
+</projectDescription>

+ 3 - 0
gfamodbusrtuslv/.settings/org.eclipse.cdt.codan.core.prefs

@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+inEditor=false
+onBuild=false

+ 2 - 0
gfamodbusrtuslv/.settings/org.eclipse.cdt.debug.core.prefs

@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+org.eclipse.cdt.debug.core.toggleBreakpointModel=com.ti.ccstudio.debug.CCSBreakpointMarker

+ 6 - 0
gfamodbusrtuslv/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+encoding//Debug/makefile=UTF-8
+encoding//Debug/objects.mk=UTF-8
+encoding//Debug/sources.mk=UTF-8
+encoding//Debug/subdir_rules.mk=UTF-8
+encoding//Debug/subdir_vars.mk=UTF-8

+ 36 - 0
gfamodbusrtuslv/defines.h

@@ -0,0 +1,36 @@
+// defines.h :
+//
+
+#if !defined(AGD_DEFINES_H__696CD137_18F3_4D4B_BB90_9D540DD8DF8A__INCLUDED_)
+#define AGD_DEFINES_H__696CD137_18F3_4D4B_BB90_9D540DD8DF8A__INCLUDED_
+
+#ifdef __cplusplus
+extern "C" {
+#endif	//	__cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// defines.h - Declarations:
+
+#ifndef __BYTE_ORDER__
+	#define __ORDER_LITTLE_ENDIAN__			1234
+	#define __ORDER_BIG_ENDIAN__			4321
+	#define __ORDER_PDP_ENDIAN__			3412
+
+	#if defined(__little_endian__)
+		#define __BYTE_ORDER__				__ORDER_LITTLE_ENDIAN__
+	#elif defined(__big_endian__)
+		#define __BYTE_ORDER__				__ORDER_BIG_ENDIAN__
+	#else
+		#error No endianess defined!
+	#endif	//	__LITTLE_ENDIAN__
+#endif	//	__BYTE_ORDER__
+
+/////////////////////////////////////////////////////////////////////////////
+
+#define _countof(a)							(sizeof(a) / sizeof(*a))
+
+/////////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+}
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_DEFINES_H__696CD137_18F3_4D4B_BB90_9D540DD8DF8A__INCLUDED_)

+ 32 - 0
gfamodbusrtuslv/distribute.cmd

@@ -0,0 +1,32 @@
+@echo off
+set PRJDIR=%~dp0
+set CONFIG=%1
+set LIBMAJOR=1
+set LIBMINOR=0
+set LIBBASENAME=gfambrtuslv
+set GFALIBS=%GfATivaLibsRoot%
+set LIBNAME=%LIBBASENAME%.%LIBMAJOR%.%LIBMINOR%
+set LIBDIR=%GFALIBS%\%LIBNAME%\lib\ccs\%CONFIG%
+set INCDIR=%GFALIBS%\include
+set SRCDIR=%GFALIBS%\%LIBNAME%\src
+set OUTDIR=%PRJDIR%%CONFIG%
+
+mkdir "%LIBDIR%" 1>nul 2>&1
+mkdir "%INCDIR%" 1>nul 2>&1
+mkdir "%SRCDIR%" 1>nul 2>&1
+
+copy /Y "%OUTDIR%\%LIBBASENAME%.lib" "%LIBDIR%"
+copy /Y "%PRJDIR%%LIBBASENAME%.h" "%INCDIR%"
+copy /Y "%PRJDIR%*.c" "%SRCDIR%"
+
+set PRJDIR=
+set CONFIG=
+set LIBMAJOR=
+set LIBMINOR=
+set LIBBASENAME=
+set LIBNAME=
+set GFALIBS=
+set INCDIR=
+set SRCDIR=
+set LIBDIR=
+set OUTDIR=

+ 163 - 0
gfamodbusrtuslv/gfambrtuslv.h

@@ -0,0 +1,163 @@
+// gfambrtuslv.h :
+//
+
+#if !defined(AGD_MBRTUSLV_H__84F27BE0_71CA_4910_8631_B0EEA21DC84A__INCLUDED_)
+#define AGD_MBRTUSLV_H__84F27BE0_71CA_4910_8631_B0EEA21DC84A__INCLUDED_
+
+#include <gfautils.h>
+#include <gfambrtucom.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif	//	__cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// mbrtuslv.h - Declarations:
+
+typedef void											*HMBRTUSLV;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef enum _GFA_MODBUS_RTU_SLV_STATES
+{
+	MB_RTU_SLV_Void = -1,
+	MB_RTU_SLV_Idle,
+	MB_RTU_SLV_RxSlvID,
+	MB_RTU_SLV_RxFunc,
+	MB_RTU_SLV_RxDataInfo,
+	MB_RTU_SLV_RxDataPayload,
+	MB_RTU_SLV_RxCRC,
+	MB_RTU_SLV_RxComplete,
+	MB_RTU_SLV_TxStart,
+	MB_RTU_SLV_TxWaitEnd
+}GFA_MODBUS_RTU_SLV_STATES;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _GFA_MODBUS_RTU_SLV_DIAGNOSIS
+{
+	uint64_t nBusMsgCount;	// Total bus message count
+	uint64_t nSlvMsgCount;	// Total slave message count
+	uint32_t nCrcErrCount;	// CRC errors
+	uint32_t nExcErrCount;	// Exception errors
+}GFA_MODBUS_RTU_SLV_DIAGNOSIS, *LPGFA_MODBUS_RTU_SLV_DIAGNOSIS;
+typedef const GFA_MODBUS_RTU_SLV_DIAGNOSIS *LPCGFA_MODBUS_RTU_SLV_DIAGNOSIS;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef void (*PFN_PRE_READ_REGISTERS)	(uint8_t, uint16_t, uint16_t);
+typedef void (*PFN_POST_READ_REGISTERS)	(uint8_t, uint16_t, uint16_t);
+typedef void (*PFN_PRE_WRITE_REGISTERS)	(uint8_t, uint16_t, uint16_t);
+typedef void (*PFN_POST_WRITE_REGISTERS)(uint8_t, uint16_t, uint16_t);
+typedef void (*PFN_PRE_TRANSMIT)		(LPMODBUS_RTU_ADU);
+typedef void (*PFN_POST_TRANSMIT)		(LPMODBUS_RTU_ADU);
+typedef uint16_t (*PFN_MAP_REG_ADDR)	(uint16_t);
+typedef void (*PFN_SLAVE_STATE_CHANGED)	(GFA_MODBUS_RTU_SLV_STATES newState, GFA_MODBUS_RTU_SLV_STATES oldState);
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _GFA_MODBUS_REGISTER
+{
+	volatile uint16_t *pRegs;
+	size_t nCountRegs;
+}GFA_MODBUS_REGISTER, *LPGFA_MODBUS_REGISTER;
+typedef const GFA_MODBUS_REGISTER *LPCGFA_MODBUS_REGISTER;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _GFA_MODBUS_SLAVE_APP_INTERFACE
+{
+	PFN_MAP_REG_ADDR			pfnMapRegAddr;
+	PFN_PRE_READ_REGISTERS		pfnPreRead;
+	PFN_POST_READ_REGISTERS		pfnPostRead;
+	PFN_PRE_WRITE_REGISTERS		pfnPreWrite;
+	PFN_POST_WRITE_REGISTERS	pfnPostWrite;
+	PFN_PRE_TRANSMIT			pfnPreTransmit;
+	PFN_POST_TRANSMIT			pfnPostTransmit;
+	PFN_SLAVE_STATE_CHANGED		pfnStateChanged;
+}GFA_MODBUS_SLAVE_APP_INTERFACE, *LPGFA_MODBUS_SLAVE_APP_INTERFACE;
+typedef const GFA_MODBUS_SLAVE_APP_INTERFACE *LPCGFA_MODBUS_SLAVE_APP_INTERFACE;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _GFA_MODBUS_RTU_SLAVE_PARAMETERS
+{
+	uint8_t slaveID;
+	HFIFO hFifoRX;
+	HFIFO hFifoTX;
+	GFA_MODBUS_REGISTER regMap;
+	GFA_MODBUS_SLAVE_APP_INTERFACE appItf;
+}GFA_MODBUS_RTU_SLAVE_PARAMETERS, *LPGFA_MODBUS_RTU_SLAVE_PARAMETERS;
+typedef const GFA_MODBUS_RTU_SLAVE_PARAMETERS *LPCGFA_MODBUS_RTU_SLAVE_PARAMETERS;
+
+/////////////////////////////////////////////////////////////////////////////
+
+typedef struct _GFA_MODBUS_RTU_SLAVE
+{
+	uint8_t slaveID;
+	uint8_t newSlaveID;
+	uint16_t nSubFunc;
+	HFIFO hFifoRX;
+	HFIFO hFifoTX;
+	size_t nCbToRead;
+	size_t nCbToWrite;
+	size_t nDataPtr;
+	int nMaxReEnterSTM;
+	bool bCRCOk;
+	GFA_MODBUS_RTU_SLV_STATES state;
+	GFA_MODBUS_RTU_SLV_STATES oldstate;
+	GFA_MODBUS_REGISTER regMap;
+	GFA_MODBUS_SLAVE_APP_INTERFACE appItf;
+	GFA_MODBUS_RTU_SLV_DIAGNOSIS diag;
+	MODBUS_RTU_ADU adu;
+}GFA_MODBUS_RTU_SLAVE, *LPGFA_MODBUS_RTU_SLAVE;
+typedef const GFA_MODBUS_RTU_SLAVE *LPCGFA_MODBUS_RTU_SLAVE;
+
+/////////////////////////////////////////////////////////////////////////////
+
+HMBRTUSLV	GfaModbusRTUSlvCreate(LPCGFA_MODBUS_RTU_SLAVE_PARAMETERS pslp);
+void		GfaModbusRTUSlvRelease(HMBRTUSLV hMbSlv);
+bool		GfaModbusRTUSlvStateMachine(HMBRTUSLV hMbSlv);
+bool		GfaModbusRTUSlvSetID(HMBRTUSLV hMbSlv, uint8_t newID);
+
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+size_t		GfaModbusRequestGetDataInfoLength(LPCGFA_MODBUS_RTU_SLAVE pSlv);
+size_t		GfaModbusRequestGetDataPayloadLength(LPCGFA_MODBUS_RTU_SLAVE pSlv);
+bool		GfaModbusRequestFunctionKnown(uint8_t func);
+bool		GfaModbusRequestSubFunctionKnown(uint16_t subfunc);
+bool		GfaModbusRequestVerifyCRC(const void *pData, size_t nCbData, const void *pCRC);
+void		GfaModbusRequestSetCRC(const void *pData, size_t nCbData, void *pCRC);
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t		GfaModbusRequestReadRegisters(uint8_t func, LPGFA_MODBUS_REGISTER pRegMap, LPGFA_MODBUS_SLAVE_APP_INTERFACE pAppItf, void *pBuf, uint8_t *pnCbWritten);
+size_t		GfaModbusRequestWriteRegisters(uint8_t func, LPGFA_MODBUS_REGISTER pRegMap, LPGFA_MODBUS_SLAVE_APP_INTERFACE pAppItf, void *pBuf, uint8_t *pnCbWritten);
+size_t		GfaModbusRequestWriteSingleRegister(uint8_t func, LPGFA_MODBUS_REGISTER pRegMap, LPGFA_MODBUS_SLAVE_APP_INTERFACE pAppItf, void *pBuf, uint8_t *pnCbWritten);
+size_t		GfaModbusRequestDiagnostic(LPGFA_MODBUS_RTU_SLAVE pSlv, uint8_t *pnCbWritten);
+size_t		GfaModbusRequestCreateExceptionResponse(LPMODBUS_RTU_PDU pPdu, uint8_t nExceptionCode);
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool		GfaModbusRequestHandler(LPGFA_MODBUS_RTU_SLAVE pSlv, size_t *pnCbData, bool *pbIsException);
+
+/////////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+}
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_MBRTUSLV_H__84F27BE0_71CA_4910_8631_B0EEA21DC84A__INCLUDED_)
+
+
+
+
+
+
+
+
+
+
+
+

+ 394 - 0
gfamodbusrtuslv/mbreq.c

@@ -0,0 +1,394 @@
+#include <string.h>
+#include "gfambrtuslv.h"
+#include "driverlib/sw_crc.h"
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+size_t GfaModbusRequestGetDataInfoLength(LPCGFA_MODBUS_RTU_SLAVE pSlv)
+{
+	size_t nRet;
+
+	switch(pSlv->adu.pdu.func)
+	{
+	case MB_FUNC_READ_HOLDING_REGISTERS:
+	case MB_FUNC_READ_INPUT_REGISTERS:
+		nRet = 4;
+		break;
+
+	case MB_FUNC_PRESET_SINGLE_REGISTER:
+		nRet = 2;
+		break;
+
+	case MB_FUNC_WRITE_MULTIPLE_REGISTERS:
+		nRet = 5;
+		break;
+
+	case MB_FUNC_DIAGNOSTIC:
+		nRet = 2;
+		break;
+
+	default:
+		nRet = 0;
+		break;
+	}
+
+	return nRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t GfaModbusRequestGetDataPayloadLength(LPCGFA_MODBUS_RTU_SLAVE pSlv)
+{
+	size_t nRet;
+
+	switch(pSlv->adu.pdu.func)
+	{
+	case MB_FUNC_READ_HOLDING_REGISTERS:
+	case MB_FUNC_READ_INPUT_REGISTERS:
+		nRet = 0;
+		break;
+
+	case MB_FUNC_PRESET_SINGLE_REGISTER:
+		nRet = 2;
+		break;
+
+	case MB_FUNC_WRITE_MULTIPLE_REGISTERS:
+		nRet = (size_t)pSlv->adu.pdu.b[4];
+		break;
+
+	case MB_FUNC_DIAGNOSTIC:
+		nRet = 2;
+		break;
+
+	default:
+		nRet = 0;
+		break;
+	}
+
+	return nRet;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool GfaModbusRequestFunctionKnown(uint8_t func)
+{
+	switch(func)
+	{
+	case MB_FUNC_READ_HOLDING_REGISTERS:
+	case MB_FUNC_READ_INPUT_REGISTERS:
+	case MB_FUNC_PRESET_SINGLE_REGISTER:
+	case MB_FUNC_WRITE_MULTIPLE_REGISTERS:
+	case MB_FUNC_DIAGNOSTIC:
+		return true;
+	default:
+		return false;
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool GfaModbusRequestSubFunctionKnown(uint16_t subfunc)
+{
+	switch(subfunc)
+	{
+	case MB_SUBFUNC_RETURN_QUERY_DATA:
+	case MB_SUBFUNC_CLEAR_CTRS_AND_DIAGNOSTIC_REG:
+	case MB_SUBFUNC_RETURN_BUS_MESSAGE_COUNT:
+	case MB_SUBFUNC_RETURN_BUS_COMM_ERROR_COUNT:
+	case MB_SUBFUNC_RETURN_BUS_EXCEPTION_ERROR_COUNT:
+	case MB_SUBFUNC_RETURN_SLAVE_MESSAGE_COUNT:
+		return true;
+	default:
+		return false;
+	}
+}
+
+bool GfaModbusRequestVerifyCRC(const void *pData, size_t nCbData, const void *pCRC)
+{
+	uint16_t nCrc = Crc16(0xFFFF, (const uint8_t*)pData, nCbData);
+	const uint8_t *pCrc	= (const uint8_t*)pCRC;
+	return ((pCrc[0] == (uint8_t)(nCrc &  0xff)) &&
+			(pCrc[1] == (uint8_t)(nCrc >> 8)));
+}
+
+void GfaModbusRequestSetCRC(const void *pData, size_t nCbData, void *pCRC)
+{
+	uint16_t nCrc = Crc16(0xFFFF, (const uint8_t*)pData, nCbData);
+	uint8_t *pCrc	= (uint8_t*)pCRC;
+	pCrc[0]			= (uint8_t)(nCrc &  0xff);
+	pCrc[1]			= (uint8_t)(nCrc >> 8);
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t GfaModbusRequestReadRegisters(uint8_t func, LPGFA_MODBUS_REGISTER pRegMap, LPGFA_MODBUS_SLAVE_APP_INTERFACE pAppItf, void *pBuf, uint8_t *pnCbWritten)
+{
+	uint8_t *p = (uint8_t*)pBuf;
+	uint16_t nRegsRead = 0, nPhyStart;
+	uint16_t nRegStart	= GfaBufGetUnaligned_uint16(&p[0]);
+	uint16_t nRegCount	= GfaBufGetUnaligned_uint16(&p[2]);
+
+	if(pAppItf->pfnMapRegAddr)
+	{
+		if((nPhyStart = (*pAppItf->pfnMapRegAddr)(nRegStart)) == (uint16_t)-1)
+		{
+			*p				= MB_ERROR_ILLEGAL_DATA_ADDRESS;
+			*pnCbWritten	= 1;
+			return 0;
+		}
+	}
+	else
+	{
+		nPhyStart = nRegStart;
+	}
+
+	if(nRegCount > MODBUS_MAX_READ_REGISTERS)
+	{
+		*p				= MB_ERROR_ILLEGAL_DATA_VALUE;
+		*pnCbWritten	= 1;
+		return 0;
+	}
+
+	if((nPhyStart + nRegCount) > pRegMap->nCountRegs)
+		nRegCount = pRegMap->nCountRegs - nPhyStart;
+
+	*p++ = nRegCount * sizeof(uint16_t);
+
+	if(pAppItf->pfnPreRead)
+		(*pAppItf->pfnPreRead)(func, nPhyStart, nRegCount);
+
+	for(nRegsRead = 0; nRegsRead < nRegCount; nRegsRead++, nPhyStart++)
+	{
+		GfaBufSetUnaligned_uint16(p, pRegMap->pRegs[nPhyStart]);
+		p += sizeof(uint16_t);
+	}
+
+	if(pAppItf->pfnPostRead)
+		(*pAppItf->pfnPostRead)(func, nPhyStart, nRegsRead);
+
+	*pnCbWritten = 1 + nRegsRead * sizeof(uint16_t);
+	return nRegsRead;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t GfaModbusRequestWriteRegisters(uint8_t func, LPGFA_MODBUS_REGISTER pRegMap, LPGFA_MODBUS_SLAVE_APP_INTERFACE pAppItf, void *pBuf, uint8_t *pnCbWritten)
+{
+	uint8_t *p = (uint8_t*)pBuf;
+	uint16_t nRegsWritten = 0, nPhyStart;
+	uint16_t nRegStart	= GfaBufGetUnaligned_uint16(&p[0]);
+	uint16_t nRegCount	= GfaBufGetUnaligned_uint16(&p[2]);
+	uint16_t nCbToWrite	= (uint16_t)p[4];
+
+	if(pAppItf->pfnMapRegAddr)
+	{
+		if((nPhyStart = (*pAppItf->pfnMapRegAddr)(nRegStart)) == (uint16_t)-1)
+		{
+			*p				= MB_ERROR_ILLEGAL_DATA_ADDRESS;
+			*pnCbWritten	= 1;
+			return 0;
+		}
+	}
+	else
+	{
+		nPhyStart = nRegStart;
+	}
+
+	if(nRegCount > MODBUS_MAX_READ_REGISTERS)
+	{
+		*p				= MB_ERROR_ILLEGAL_DATA_VALUE;
+		*pnCbWritten	= 1;
+		return 0;
+	}
+	else if(nRegCount != nCbToWrite / sizeof(uint16_t))
+	{
+		*p				= MB_ERROR_ILLEGAL_DATA_VALUE;
+		*pnCbWritten	= 1;
+		return 0;
+	}
+
+	p += 1 + 2 * sizeof(uint16_t);
+
+	if((nPhyStart + nRegCount) > pRegMap->nCountRegs)
+		nRegCount = pRegMap->nCountRegs - nPhyStart;
+
+	if(pAppItf->pfnPreWrite)
+		(*pAppItf->pfnPreWrite)(func, nPhyStart, nRegCount);
+
+	for(nRegsWritten = 0; nRegsWritten < nRegCount; nRegsWritten++, nPhyStart++)
+	{
+		pRegMap->pRegs[nPhyStart] = GfaBufGetUnaligned_uint16(p);
+		p += sizeof(uint16_t);
+	}
+
+	if(pAppItf->pfnPostWrite)
+		(*pAppItf->pfnPostWrite)(func, nPhyStart, nRegsWritten);
+
+	p = (uint8_t*)pBuf;
+	GfaBufSetUnaligned_uint16(p, nRegStart);
+	p += sizeof(uint16_t);
+	GfaBufSetUnaligned_uint16(p, nRegCount);
+	p += sizeof(uint16_t);
+
+	*pnCbWritten = 2 * sizeof(uint16_t);
+	return nRegsWritten;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t GfaModbusRequestWriteSingleRegister(uint8_t func, LPGFA_MODBUS_REGISTER pRegMap, LPGFA_MODBUS_SLAVE_APP_INTERFACE pAppItf, void *pBuf, uint8_t *pnCbWritten)
+{
+	uint8_t *p = (uint8_t*)pBuf;
+	uint16_t nPhyStart, nRegAddr = GfaBufGetUnaligned_uint16(&p[0]);
+
+	if(pAppItf->pfnMapRegAddr)
+	{
+		if((nPhyStart = (*pAppItf->pfnMapRegAddr)(nRegAddr)) == (uint16_t)-1)
+		{
+			*p				= MB_ERROR_ILLEGAL_DATA_ADDRESS;
+			*pnCbWritten	= 1;
+			return 0;
+		}
+	}
+	else
+	{
+		nPhyStart = nRegAddr;
+	}
+
+	if(nPhyStart >= pRegMap->nCountRegs)
+	{
+		*p				= MB_ERROR_ILLEGAL_DATA_ADDRESS;
+		*pnCbWritten	= 1;
+		return 0;
+	}
+
+	p += sizeof(uint16_t);
+	if(pAppItf->pfnPreWrite)
+		(*pAppItf->pfnPreWrite)(func, nPhyStart, 1);
+	pRegMap->pRegs[nPhyStart] = GfaBufGetUnaligned_uint16(p);
+	if(pAppItf->pfnPostWrite)
+		(*pAppItf->pfnPostWrite)(func, nPhyStart, 1);
+	*pnCbWritten = 2 * sizeof(uint16_t);
+	return 1;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t GfaModbusRequestDiagnostic(LPGFA_MODBUS_RTU_SLAVE pSlv, uint8_t *pnCbWritten)
+{
+	uint8_t *p = pSlv->adu.pdu.b;
+	uint16_t nVal, nSubFunc = GfaBufGetUnaligned_uint16(p);
+	p += sizeof(uint16_t);
+
+	switch(nSubFunc)
+	{
+	case MB_SUBFUNC_RETURN_QUERY_DATA:
+		*pnCbWritten = 2 * sizeof(uint16_t);	// Echo Request Data
+		break;
+
+	case MB_SUBFUNC_CLEAR_CTRS_AND_DIAGNOSTIC_REG:
+		memset(&pSlv->diag, 0, sizeof(pSlv->diag));
+		*pnCbWritten = 2 * sizeof(uint16_t);	// Echo Request Data
+		break;
+
+	case MB_SUBFUNC_RETURN_BUS_MESSAGE_COUNT:
+		nVal = (uint16_t)(pSlv->diag.nBusMsgCount & 0xFFFF);
+		GfaBufSetUnaligned_uint16(p, nVal);
+		*pnCbWritten = 2 * sizeof(uint16_t);
+		break;
+
+	case MB_SUBFUNC_RETURN_BUS_COMM_ERROR_COUNT:
+		nVal = (uint16_t)(pSlv->diag.nCrcErrCount & 0xFFFF);
+		GfaBufSetUnaligned_uint16(p, nVal);
+		*pnCbWritten = 2 * sizeof(uint16_t);
+		break;
+
+	case MB_SUBFUNC_RETURN_BUS_EXCEPTION_ERROR_COUNT:
+		nVal = (uint16_t)(pSlv->diag.nExcErrCount & 0xFFFF);
+		GfaBufSetUnaligned_uint16(p, nVal);
+		*pnCbWritten = 2 * sizeof(uint16_t);
+		break;
+
+	case MB_SUBFUNC_RETURN_SLAVE_MESSAGE_COUNT:
+		nVal = (uint16_t)(pSlv->diag.nSlvMsgCount & 0xFFFF);
+		GfaBufSetUnaligned_uint16(p, nVal);
+		*pnCbWritten = 2 * sizeof(uint16_t);
+		break;
+
+	default:
+		pSlv->adu.pdu.b[0]	= MB_ERROR_ILLEGAL_FUNCTION;
+		*pnCbWritten		= 1;
+		break;
+	}
+
+	return *pnCbWritten;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+size_t GfaModbusRequestCreateExceptionResponse(LPMODBUS_RTU_PDU pPdu, uint8_t nExceptionCode)
+{
+	pPdu->func |= MB_FUNC_ERROR_FLAG;
+	pPdu->b[0] = nExceptionCode;
+	return 1;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+bool GfaModbusRequestHandler(LPGFA_MODBUS_RTU_SLAVE pSlv, size_t *pnCbData, bool *pbIsException)
+{
+	uint8_t nCbWritten;
+	bool bSendResponse = true;
+	*pnCbData = 0;
+	*pbIsException = false;
+
+	switch(pSlv->adu.pdu.func)
+	{
+	case MB_FUNC_READ_HOLDING_REGISTERS:
+		if(!GfaModbusRequestReadRegisters(pSlv->adu.pdu.func, &pSlv->regMap, &pSlv->appItf, pSlv->adu.pdu.b, &nCbWritten))
+		{
+			pSlv->adu.pdu.func |= MB_FUNC_ERROR_FLAG;
+			*pbIsException = true;
+		}
+		*pnCbData = nCbWritten;
+		break;
+
+	case MB_FUNC_PRESET_SINGLE_REGISTER:
+		if(!GfaModbusRequestWriteSingleRegister(pSlv->adu.pdu.func, &pSlv->regMap, &pSlv->appItf, pSlv->adu.pdu.b, &nCbWritten))
+		{
+			pSlv->adu.pdu.func |= MB_FUNC_ERROR_FLAG;
+			*pbIsException = true;
+		}
+		*pnCbData = nCbWritten;
+		break;
+
+	case MB_FUNC_WRITE_MULTIPLE_REGISTERS:
+		if(!GfaModbusRequestWriteRegisters(pSlv->adu.pdu.func, &pSlv->regMap, &pSlv->appItf, pSlv->adu.pdu.b, &nCbWritten))
+		{
+			pSlv->adu.pdu.func |= MB_FUNC_ERROR_FLAG;
+			*pbIsException = true;
+		}
+		*pnCbData = nCbWritten;
+		break;
+
+	case MB_FUNC_DIAGNOSTIC:
+		if(!GfaModbusRequestDiagnostic(pSlv, &nCbWritten))
+		{
+			pSlv->adu.pdu.func |= MB_FUNC_ERROR_FLAG;
+			*pbIsException = true;
+		}
+		*pnCbData = nCbWritten;
+		break;
+
+	default:
+		*pnCbData = GfaModbusRequestCreateExceptionResponse(&pSlv->adu.pdu, MB_ERROR_ILLEGAL_FUNCTION);
+		*pbIsException = true;
+		break;
+	}
+
+	return bSendResponse;
+}

+ 312 - 0
gfamodbusrtuslv/mbrtuslv.c

@@ -0,0 +1,312 @@
+#include <stdlib.h>
+#include <string.h>
+#include "gfambrtuslv.h"
+#include "driverlib/sw_crc.h"
+#include "inc/hw_memmap.h"
+
+/////////////////////////////////////////////////////////////////////////////
+
+static GFA_MODBUS_RTU_SLAVE g_mbSlv;
+
+/////////////////////////////////////////////////////////////////////////////
+
+static bool _PeekStateChange(LPGFA_MODBUS_RTU_SLAVE pSlv)
+{
+	if(pSlv->oldstate != pSlv->state)
+	{
+		if(pSlv->appItf.pfnStateChanged)
+			(*pSlv->appItf.pfnStateChanged)(pSlv->state, pSlv->oldstate);
+		pSlv->oldstate = pSlv->state;
+		return true;
+	}
+	return false;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+HMBRTUSLV GfaModbusRTUSlvCreate(LPCGFA_MODBUS_RTU_SLAVE_PARAMETERS pslp)
+{
+	if(!pslp)
+		return NULL;
+	if(!pslp->slaveID || pslp->slaveID > MODBUS_MAX_SLAVE_ID)
+		return NULL;
+	if(!pslp->hFifoRX || !pslp->hFifoTX || !pslp->regMap.pRegs || !pslp->regMap.nCountRegs)
+		return NULL;
+
+	LPGFA_MODBUS_RTU_SLAVE pSlv = &g_mbSlv;
+	memset(pSlv, 0, sizeof(GFA_MODBUS_RTU_SLAVE));
+
+	pSlv->state		= MB_RTU_SLV_Idle;
+	pSlv->oldstate	= MB_RTU_SLV_Void;
+	pSlv->slaveID	= pslp->slaveID;
+	pSlv->hFifoRX	= pslp->hFifoRX;
+	pSlv->hFifoTX	= pslp->hFifoTX;
+
+	memcpy(&pSlv->regMap, &pslp->regMap, sizeof(GFA_MODBUS_REGISTER));
+	memcpy(&pSlv->appItf, &pslp->appItf, sizeof(GFA_MODBUS_SLAVE_APP_INTERFACE));
+	return (HMBRTUSLV)pSlv;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void GfaModbusRTUSlvRelease(HMBRTUSLV hMbSlv)
+{
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool GfaModbusRTUSlvSetID(HMBRTUSLV hMbSlv, uint8_t newID)
+{
+	LPGFA_MODBUS_RTU_SLAVE pSlv = (LPGFA_MODBUS_RTU_SLAVE)hMbSlv;
+
+	if(!newID || newID > MODBUS_MAX_SLAVE_ID)
+		return false;
+
+	if(pSlv->newSlaveID != newID)
+		pSlv->newSlaveID = newID;
+
+	return true;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+bool GfaModbusRTUSlvStateMachine(HMBRTUSLV hMbSlv)
+{
+	static int nReEnterSTM = 0;
+	uint8_t b;
+	size_t nRead;
+	LPGFA_MODBUS_RTU_SLAVE pSlv = (LPGFA_MODBUS_RTU_SLAVE)hMbSlv;
+
+	++nReEnterSTM;
+
+	switch(pSlv->state)
+	{
+	case MB_RTU_SLV_Idle:
+		nReEnterSTM = 0;
+		_PeekStateChange(pSlv);
+		if(pSlv->newSlaveID)
+		{
+			pSlv->slaveID = pSlv->newSlaveID;
+			pSlv->newSlaveID = 0;
+		}
+		if(!FifoMatchFlags(pSlv->hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, true))
+			break;
+		pSlv->state			= MB_RTU_SLV_RxSlvID;
+		pSlv->nCbToRead		= 0;
+		pSlv->nCbToWrite	= 0;
+		pSlv->nDataPtr		= 0;
+		pSlv->bCRCOk		= false;
+		FifoClearFlags(pSlv->hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, true);
+		// fall through
+
+	case MB_RTU_SLV_RxSlvID:
+		_PeekStateChange(pSlv);
+		if(!FifoPop(pSlv->hFifoRX, &b, true))
+		{
+			if(FifoMatchFlags(pSlv->hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, true))
+				pSlv->state	= MB_RTU_SLV_Idle;
+			break;
+		}
+		if(pSlv->slaveID != b) // ignore broadcasts as well
+		{
+			FifoSetFlags(pSlv->hFifoRX, MB_RTU_FLAG_IGNORE_FRAME, true);
+			FifoReset(pSlv->hFifoRX, true);
+			pSlv->state		= MB_RTU_SLV_Idle;
+			++pSlv->diag.nBusMsgCount;
+			break;
+		}
+		pSlv->adu.slaveID	= b;
+		pSlv->state			= MB_RTU_SLV_RxFunc;
+		++pSlv->diag.nBusMsgCount;
+		// fall through
+
+	case MB_RTU_SLV_RxFunc:
+		_PeekStateChange(pSlv);
+		if(!FifoPop(pSlv->hFifoRX, &b, true))
+		{
+			if(FifoMatchFlags(pSlv->hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, true))
+				pSlv->state	= MB_RTU_SLV_Idle;
+			break;
+		}
+		else if(!GfaModbusRequestFunctionKnown(b))
+		{
+			pSlv->adu.pdu.func = b;
+			FifoSetFlags(pSlv->hFifoRX, MB_RTU_FLAG_IGNORE_FRAME, true);
+			FifoReset(pSlv->hFifoRX, true);
+			GfaModbusRequestCreateExceptionResponse(&pSlv->adu.pdu, MB_ERROR_ILLEGAL_FUNCTION);
+			GfaModbusRequestSetCRC(&pSlv->adu, 3, &pSlv->adu.pdu.b[1]);
+			pSlv->nCbToWrite = 5;
+			pSlv->state	= MB_RTU_SLV_TxStart;
+			++pSlv->diag.nExcErrCount;
+			break;
+		}
+		pSlv->adu.pdu.func	= b;
+		pSlv->state			= MB_RTU_SLV_RxDataInfo;
+		pSlv->nCbToRead		= GfaModbusRequestGetDataInfoLength(pSlv);
+		// fall through
+
+	case MB_RTU_SLV_RxDataInfo:
+		_PeekStateChange(pSlv);
+		if(pSlv->nCbToRead)
+		{
+			if(!(nRead = FifoRead(pSlv->hFifoRX, &pSlv->adu.pdu.b[pSlv->nDataPtr], pSlv->nCbToRead, true)))
+			{
+				if(FifoMatchFlags(pSlv->hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, true))
+					pSlv->state	= MB_RTU_SLV_Idle;
+				break;
+			}
+			pSlv->nDataPtr	+= nRead;
+			pSlv->nCbToRead	-= nRead;
+		}
+
+		if(pSlv->nCbToRead)
+			break;
+		else
+		{
+			if(pSlv->adu.pdu.func == MB_FUNC_DIAGNOSTIC)
+			{
+				pSlv->nSubFunc = GfaBufGetUnaligned_uint16(pSlv->adu.pdu.b);
+
+				if(!GfaModbusRequestSubFunctionKnown(pSlv->nSubFunc))
+				{
+					pSlv->adu.pdu.func = b;
+					FifoSetFlags(pSlv->hFifoRX, MB_RTU_FLAG_IGNORE_FRAME, true);
+					FifoReset(pSlv->hFifoRX, true);
+					GfaModbusRequestCreateExceptionResponse(&pSlv->adu.pdu, MB_ERROR_ILLEGAL_FUNCTION);
+					GfaModbusRequestSetCRC(&pSlv->adu, 3, &pSlv->adu.pdu.b[1]);
+					pSlv->nCbToWrite = 5;
+					pSlv->state	= MB_RTU_SLV_TxStart;
+					++pSlv->diag.nExcErrCount;
+					break;
+				}
+			}
+			pSlv->state		= MB_RTU_SLV_RxDataPayload;
+			pSlv->nCbToRead	= GfaModbusRequestGetDataPayloadLength(pSlv);
+			// fall through
+		}
+
+	case MB_RTU_SLV_RxDataPayload:
+		_PeekStateChange(pSlv);
+		if(pSlv->nCbToRead)
+		{
+			if(!(nRead = FifoRead(pSlv->hFifoRX, &pSlv->adu.pdu.b[pSlv->nDataPtr], pSlv->nCbToRead, true)))
+			{
+				if(FifoMatchFlags(pSlv->hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, true))
+					pSlv->state	= MB_RTU_SLV_Idle;
+				break;
+			}
+			pSlv->nDataPtr	+= nRead;
+			pSlv->nCbToRead	-= nRead;
+		}
+
+		if(pSlv->nCbToRead)
+			break;
+		else
+		{
+			pSlv->state		= MB_RTU_SLV_RxCRC;
+			pSlv->nCbToRead	= 2;
+			// fall through
+		}
+
+	case MB_RTU_SLV_RxCRC:
+		_PeekStateChange(pSlv);
+		if(pSlv->nCbToRead)
+		{
+			if(!(nRead = FifoRead(pSlv->hFifoRX, &pSlv->adu.pdu.b[pSlv->nDataPtr], pSlv->nCbToRead, true)))
+			{
+				if(FifoMatchFlags(pSlv->hFifoRX, MB_RTU_FLAG_FRAME_GAP_DETECT, true))
+					pSlv->state	= MB_RTU_SLV_Idle;
+				break;
+			}
+			pSlv->nDataPtr	+= nRead;
+			pSlv->nCbToRead	-= nRead;
+		}
+
+		if(pSlv->nCbToRead)
+			break;
+		else
+		{
+			pSlv->bCRCOk	= GfaModbusRequestVerifyCRC(&pSlv->adu, pSlv->nDataPtr, &pSlv->adu.pdu.b[pSlv->nDataPtr - 2]);
+			pSlv->state		= MB_RTU_SLV_RxComplete;
+			// fall through
+		}
+
+	case MB_RTU_SLV_RxComplete:
+		_PeekStateChange(pSlv);
+		if(pSlv->bCRCOk)
+		{
+			bool bIsExeption;
+			size_t nCbData = 0;
+			++pSlv->diag.nSlvMsgCount;
+
+			if(GfaModbusRequestHandler(pSlv, &nCbData, &bIsExeption))
+			{
+				GfaModbusRequestSetCRC(&pSlv->adu, nCbData + 2, &pSlv->adu.pdu.b[nCbData]);
+				pSlv->nCbToWrite	= nCbData + 4;
+				pSlv->state			= MB_RTU_SLV_TxStart;
+				if(bIsExeption)
+					++pSlv->diag.nExcErrCount;
+				FifoRxFinalize(pSlv->hFifoRX, true);
+				// fall through
+			}
+			else
+			{
+				pSlv->state = MB_RTU_SLV_Idle;	// nothing to send
+				break;
+			}
+		}
+		else
+		{
+			++pSlv->diag.nCrcErrCount;		// CRC Error!!!
+			pSlv->state = MB_RTU_SLV_Idle;	// silently ignore frame
+			break;
+		}
+
+	case MB_RTU_SLV_TxStart:
+		_PeekStateChange(pSlv);
+		if(	FifoEmpty(pSlv->hFifoTX, true) &&
+			FifoTxPrepare(pSlv->hFifoTX, true))
+		{
+			FifoSetFlags(pSlv->hFifoTX, MB_RTU_FLAG_TRANSMIT_IN_PROGRESS, true);
+			FifoWrite(pSlv->hFifoTX, &pSlv->adu, pSlv->nCbToWrite, true);
+
+			if(pSlv->appItf.pfnPreTransmit)
+				(*pSlv->appItf.pfnPreTransmit)(&pSlv->adu);
+			FifoTxStart(pSlv->hFifoTX, false);
+			pSlv->state = MB_RTU_SLV_TxWaitEnd;
+			// fall through
+		}
+		else
+			break;
+
+	case MB_RTU_SLV_TxWaitEnd:
+		_PeekStateChange(pSlv);
+		if(!FifoMatchFlags(pSlv->hFifoTX, MB_RTU_FLAG_TRANSMIT_IN_PROGRESS, true))
+		{
+			if(pSlv->appItf.pfnPostTransmit)
+				(*pSlv->appItf.pfnPostTransmit)(&pSlv->adu);
+			pSlv->state = MB_RTU_SLV_Idle;
+		}
+		break;
+
+	default:
+		return false;
+	}
+
+	if(pSlv->nMaxReEnterSTM < nReEnterSTM)
+		pSlv->nMaxReEnterSTM = nReEnterSTM;
+	return true;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+

Some files were not shown because too many files changed in this diff